From 811a63997b2df609186c66519b7460d519737ff4 Mon Sep 17 00:00:00 2001 From: peierlong Date: Tue, 3 Dec 2019 16:32:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=AB=AF=E5=85=B3=E9=97=AD=E5=90=8E=EF=BC=8C=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8=E5=8D=A1=E6=AD=BB=EF=BC=8CCPU=E5=8D=A0=E7=94=A8?= =?UTF-8?q?=E7=8E=87=E9=AB=98=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/static/js/ws_chat.js | 40 +++++++++++++++---------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/main/resources/static/js/ws_chat.js b/src/main/resources/static/js/ws_chat.js index 7d413d8..12822a0 100644 --- a/src/main/resources/static/js/ws_chat.js +++ b/src/main/resources/static/js/ws_chat.js @@ -66,25 +66,33 @@ var onmsg = function (event) { }; function reconnect() { - websocket = new WebSocket("ws://127.0.0.1:8080"); - $("#ws_status").text("重新上线"); - websocket.onmessage = function (event) { - onmsg(event); - }; - - websocket.onopen = function () { - bind(); - heartBeat.start(); - } + var isReconnect = false; + setTimeout(function () { + websocket = new WebSocket("ws://127.0.0.1:8080"); + $("#ws_status").text("重新上线"); + websocket.onmessage = function (event) { + onmsg(event); + }; - websocket.onclose = function () { - reconnect(); - }; + websocket.onopen = function () { + bind(); + heartBeat.start(); + } - websocket.onerror = function () { - reconnect(); - }; + websocket.onclose = function () { + if (!isReconnect) { + reconnect(); + isReconnect = true; + } + }; + websocket.onerror = function () { + if (!isReconnect) { + reconnect(); + isReconnect = true; + } + }; + }, 5000); } function sendMsg(event) {