|
@@ -13,7 +13,9 @@ const useMessageStore = defineStore('message', {
|
|
|
timerHeart: undefined,
|
|
|
timerServerHeart: undefined,
|
|
|
handClose: false,
|
|
|
- messageCount: 0
|
|
|
+ messageCount: 0,
|
|
|
+ id: undefined,
|
|
|
+ token: token
|
|
|
}),
|
|
|
actions: {
|
|
|
getMessageNum(message) {
|
|
@@ -35,12 +37,15 @@ const useMessageStore = defineStore('message', {
|
|
|
// console.log(id, wsUrl, token)
|
|
|
try {
|
|
|
this.ws = new WebSocket(wsUrl + id, [token])
|
|
|
+ this.initWebsocket()
|
|
|
} catch (e) {
|
|
|
// console.log(e)
|
|
|
this.reconnection(id, token)
|
|
|
}
|
|
|
},
|
|
|
async connection(id, token) {
|
|
|
+ this.id = id
|
|
|
+ this.token = token
|
|
|
// this.getMessageNum('1')
|
|
|
// console.log(id, wsUrl, token)
|
|
|
// console.log(window)
|
|
@@ -62,12 +67,12 @@ const useMessageStore = defineStore('message', {
|
|
|
}
|
|
|
this.ws.onerror = (e) => {
|
|
|
console.log('链接失败')
|
|
|
- this.reconnection()
|
|
|
+ this.reconnection(this.id, this.token)
|
|
|
}
|
|
|
this.ws.onclose = (e) => {
|
|
|
console.log("关闭连接")
|
|
|
if (!this.handClose) {
|
|
|
- this.reconnection()
|
|
|
+ this.reconnection(this.id, this.token)
|
|
|
}
|
|
|
}
|
|
|
},
|
|
@@ -83,7 +88,7 @@ const useMessageStore = defineStore('message', {
|
|
|
}
|
|
|
this.lockReconnect = true
|
|
|
if (this.timerReconnect) {
|
|
|
- this.clearTimer(timerReconnect)
|
|
|
+ this.clearTimer(this.timerReconnect)
|
|
|
}
|
|
|
//没连上会一直重连, 设置迟延,避免请求过多
|
|
|
this.timerReconnect = setTimeout(() => {
|