调整ws bug
This commit is contained in:
2
.env.dev
2
.env.dev
@@ -6,7 +6,7 @@ NODE_ENV = 'development'
|
|||||||
VUE_APP_BASE_URL = 'https://develop.api.aida.com.hk'
|
VUE_APP_BASE_URL = 'https://develop.api.aida.com.hk'
|
||||||
# VUE_APP_BASE_URL = 'https://www.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'
|
# VUE_APP_BASE_URL = 'http://192.168.1.9:5567'
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class MyWs {
|
|||||||
this.messageUrl = http+'/notification'
|
this.messageUrl = http+'/notification'
|
||||||
this.wsUrl = ''
|
this.wsUrl = ''
|
||||||
this.reconnectionTime = null
|
this.reconnectionTime = null
|
||||||
|
this.sendPINGTime = null
|
||||||
}
|
}
|
||||||
linkWs(url) {
|
linkWs(url) {
|
||||||
if(!(JSON.parse(getCookie("userInfo"))))return
|
if(!(JSON.parse(getCookie("userInfo"))))return
|
||||||
@@ -16,25 +17,29 @@ class MyWs {
|
|||||||
this.ws = new WebSocket(this.wsUrl)
|
this.ws = new WebSocket(this.wsUrl)
|
||||||
this.ws.onmessage = (e)=>{
|
this.ws.onmessage = (e)=>{
|
||||||
try {
|
try {
|
||||||
MyWs.receiveText(JSON.parse(e.data))
|
let rv = JSON.parse(e.data)
|
||||||
|
if(rv == "PONG")return
|
||||||
|
MyWs.receiveText(rv)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('websocket',error)
|
console.error('websocket',error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
clearInterval(this.sendPINGTime)
|
||||||
|
this.sendPINGTime = setInterval(()=>{
|
||||||
|
this.send({text:'PING'})
|
||||||
|
// },1000)
|
||||||
|
},1000*60*2)
|
||||||
this.ws.onclose = (e)=>{
|
this.ws.onclose = (e)=>{
|
||||||
console.log('',e);
|
|
||||||
console.log('错误');
|
|
||||||
this.reconnection()
|
this.reconnection()
|
||||||
}
|
}
|
||||||
this.ws.onerror = (e)=>{
|
this.ws.onerror = (e)=>{
|
||||||
console.log('失败',e);
|
|
||||||
this.reconnection()
|
this.reconnection()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reconnection(){
|
reconnection(){
|
||||||
clearTimeout(this.reconnectionTime)
|
clearTimeout(this.reconnectionTime)
|
||||||
|
clearInterval(this.sendPINGTime)
|
||||||
this.reconnectionTime = setTimeout(()=>{
|
this.reconnectionTime = setTimeout(()=>{
|
||||||
this.wsUrl = url +`/${JSON.parse(getCookie("userInfo")).userId}`
|
|
||||||
this.linkWs(this.wsUrl)
|
this.linkWs(this.wsUrl)
|
||||||
},1000)
|
},1000)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -238,8 +238,9 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
MyWs.close()
|
||||||
// MyWs.linkWs("wss://"+MyWs.messageUrl,'message')
|
// MyWs.linkWs("wss://"+MyWs.messageUrl,'message')
|
||||||
MyWs.linkWs("wss://"+MyWs.messageUrl,'message')
|
MyWs.linkWs("ws://"+MyWs.messageUrl,'message')
|
||||||
let getWsMessage = (data)=>{
|
let getWsMessage = (data)=>{
|
||||||
let userInfo = ['followeeCount','followerCount']
|
let userInfo = ['followeeCount','followerCount']
|
||||||
let obj = {}
|
let obj = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user