diff --git a/.env.dev b/.env.dev index 926a368f..2d87170d 100644 --- a/.env.dev +++ b/.env.dev @@ -6,7 +6,7 @@ NODE_ENV = 'development' VUE_APP_BASE_URL = 'https://develop.api.aida.com.hk' # VUE_APP_BASE_URL = 'https://www.api.aida.com.hk' # 佩佩 -# VUE_APP_BASE_URL = 'http://192.168.1.4:5567' +VUE_APP_BASE_URL = 'http://192.168.1.4:5567' # 海波 # VUE_APP_BASE_URL = 'http://192.168.1.9:5567' diff --git a/src/tool/webSocket.js b/src/tool/webSocket.js index da80c80b..156ac99b 100644 --- a/src/tool/webSocket.js +++ b/src/tool/webSocket.js @@ -8,6 +8,7 @@ class MyWs { this.messageUrl = http+'/notification' this.wsUrl = '' this.reconnectionTime = null + this.sendPINGTime = null } linkWs(url) { if(!(JSON.parse(getCookie("userInfo"))))return @@ -16,25 +17,29 @@ class MyWs { this.ws = new WebSocket(this.wsUrl) this.ws.onmessage = (e)=>{ try { - MyWs.receiveText(JSON.parse(e.data)) + let rv = JSON.parse(e.data) + if(rv == "PONG")return + MyWs.receiveText(rv) } catch (error) { console.error('websocket',error) } } + clearInterval(this.sendPINGTime) + this.sendPINGTime = setInterval(()=>{ + this.send({text:'PING'}) + // },1000) + },1000*60*2) this.ws.onclose = (e)=>{ - console.log('',e); - console.log('错误'); this.reconnection() } this.ws.onerror = (e)=>{ - console.log('失败',e); this.reconnection() } } reconnection(){ clearTimeout(this.reconnectionTime) + clearInterval(this.sendPINGTime) this.reconnectionTime = setTimeout(()=>{ - this.wsUrl = url +`/${JSON.parse(getCookie("userInfo")).userId}` this.linkWs(this.wsUrl) },1000) } diff --git a/src/views/HomeMain.vue b/src/views/HomeMain.vue index eac3e53c..1d5190dd 100644 --- a/src/views/HomeMain.vue +++ b/src/views/HomeMain.vue @@ -238,8 +238,9 @@ export default defineComponent({ } }) } + MyWs.close() // MyWs.linkWs("wss://"+MyWs.messageUrl,'message') - MyWs.linkWs("wss://"+MyWs.messageUrl,'message') + MyWs.linkWs("ws://"+MyWs.messageUrl,'message') let getWsMessage = (data)=>{ let userInfo = ['followeeCount','followerCount'] let obj = {}