From a3e71253a9396106a967c25a045a4e70bdbc1667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=90=8C=E6=B5=B7?= <963808678@qq.com> Date: Thu, 11 May 2023 15:33:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=20socket=20=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/socket.js | 78 ++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/utils/socket.js b/src/utils/socket.js index ad653bc..7be065f 100644 --- a/src/utils/socket.js +++ b/src/utils/socket.js @@ -46,45 +46,45 @@ class SocketConnection extends EventEmitter { } } - // async start(token) { - // // 组件重新加载时, 如果 socket 存在, 不需要新建 - // if (!this.socket) { - // this.socket = new SignalR.HubConnectionBuilder() - // .configureLogging(SignalR.LogLevel.Information) - // .withUrl( - // `/hubs/chathub`, { - // accessTokenFactory: () => token, - // skipNegotiation: true, - // transport: SignalR.HttpTransportType.WebSockets - // } - // ) - // .build() - - // this.socket.on('ForceExist', () => { //可以做相关业务逻辑 - // store.dispatch("Logout").then(()=>{ - // window.location.reload() - // }).catch(err=>{ - // this.$message.error({ - // title: '错误', - // description: err.message - // }) - // }) - // }) - - // this.socket.on('AppendNotice', (notice) => { - // store.commit("APPEND_NOTICE",notice) - // }) - - // this.socket.onclose(async () => { - // this.offline = true - // this.emit('onclose') - // await this._initialize() - // }) - - // await this._initialize() - - // } - // } + async start(token) { + // 组件重新加载时, 如果 socket 存在, 不需要新建 + if (!this.socket) { + console.log(this.socket) + // this.socket = new SignalR.HubConnectionBuilder() + // .configureLogging(SignalR.LogLevel.Information) + // .withUrl( + // `/hubs/chathub`, { + // accessTokenFactory: () => token, + // skipNegotiation: true, + // transport: SignalR.HttpTransportType.WebSockets + // } + // ) + // .build() + this.socket.on('ForceExist', () => { + //可以做相关业务逻辑 + store + .dispatch('Logout') + .then(() => { + window.location.reload() + }) + .catch(err => { + this.$message.error({ + title: '错误', + description: err.message + }) + }) + }) + this.socket.on('AppendNotice', notice => { + store.commit('APPEND_NOTICE', notice) + }) + this.socket.onclose(async () => { + this.offline = true + this.emit('onclose') + await this._initialize() + }) + await this._initialize() + } + } async authenticate(token) { await this.start(token)