fix
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { setCookie, getCookie, WriteCookie,clonAllCookie } from "@/tool/cookie";
|
||||
import MyEvent from "@/tool/myEvents";
|
||||
class MyWs {
|
||||
constructor() {
|
||||
@@ -5,10 +6,13 @@ class MyWs {
|
||||
// this.ws = new WebSocket();
|
||||
let http = process.env.VUE_APP_BASE_URL.replace(/^https?:\/\//, '')
|
||||
this.messageUrl = http+'/notification'
|
||||
this.wsUrl = ''
|
||||
this.reconnectionTime = null
|
||||
}
|
||||
linkWs(url) {
|
||||
if (this.ws && this.ws.readyState == 1) return
|
||||
this.ws = new WebSocket(url)
|
||||
if(!this.wsUrl)this.wsUrl = url +`/${JSON.parse(getCookie("userInfo")).userId}`
|
||||
this.ws = new WebSocket(this.wsUrl)
|
||||
this.ws.onmessage = (e)=>{
|
||||
try {
|
||||
MyWs.receiveText(JSON.parse(e.data))
|
||||
@@ -16,6 +20,18 @@ class MyWs {
|
||||
console.error('websocket',error)
|
||||
}
|
||||
}
|
||||
this.ws.onclose = (e)=>{
|
||||
reconnection()
|
||||
}
|
||||
this.ws.onerror = (e)=>{
|
||||
reconnection()
|
||||
}
|
||||
}
|
||||
reconnection(){
|
||||
clearTimeout(this.reconnectionTime)
|
||||
this.reconnectionTime = setTimeout(()=>{
|
||||
this.linkWs(this.wsUrl)
|
||||
},1000)
|
||||
}
|
||||
static receiveText(data,call){
|
||||
MyEvent.emit('getMessage',data)
|
||||
|
||||
Reference in New Issue
Block a user