From 017017d1700bc88112e8d103e0ab00a7c2ec6ea1 Mon Sep 17 00:00:00 2001 From: whyczyk <525500596@qq.com> Date: 星期一, 28 二月 2022 11:10:52 +0800 Subject: [PATCH] fix socket bug --- src/assets/js/socket.js | 32 ++------------------------------ 1 files changed, 2 insertions(+), 30 deletions(-) diff --git a/src/assets/js/socket.js b/src/assets/js/socket.js index aa68e6f..871f9a5 100644 --- a/src/assets/js/socket.js +++ b/src/assets/js/socket.js @@ -17,21 +17,14 @@ this.ws = new WebSocket(this.wsUrl); this.ws.onopen = () => { this.status = 'open'; - this.heartCheck(); if (data) { this.ws.send(data) } }; this.ws.onmessage = e => { - if (e.data === 'pong') { - this.pingPong = 'pong' - } else { - this.msgCallback(JSON.parse(e.data)); - } + this.msgCallback(JSON.parse(e.data)); }; this.ws.onclose = () => { - clearInterval(this.pingInterval); - clearInterval(this.pongInterval) if (this.status === 'close') { //console.log(鈥樻墜鍔ㄥ叧闂垚鍔熲��,new Date()) } else { @@ -45,39 +38,18 @@ return false } - heartCheck() {// 蹇冭烦 - this.pingPong = 'ping'; - let timer = this.time + 1000 - this.pingInterval = setInterval(() => { - if (this.ws.readyState === 1) { - this.ws.send('ping') - } - }, this.time); - this.pongInterval = setInterval(() => { - if (this.pingPong === 'ping') { - clearInterval(this.pingInterval); - clearInterval(this.pongInterval) - this.ws.close() - } else { - this.pingPong = 'ping' - } - }, timer) - } - sendHandle(data) { return this.ws.send(data); } relink() { - if (this.status == 'open' && this.readyState == 1) { //杩炴帴姝e父 + if (this.status == 'open') { //杩炴帴姝e父 return } if (this.initTimeOut) { //瀹氭椂鍣ㄥ凡缁忓惎鍔� return; } this.initTimeOut = setTimeout(() => { - clearInterval(this.pingInterval); - clearInterval(this.pongInterval); this.initTimeOut = null; this.init(); }, this.initTime) -- Gitblit v1.9.1