调整ws bug

This commit is contained in:
X1627315083
2024-11-11 17:22:52 +08:00
parent 674fc59d30
commit 89c1dafd41
3 changed files with 13 additions and 7 deletions

View File

@@ -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'

View File

@@ -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)
}

View File

@@ -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 = {}