新增signalR自动重连
This commit is contained in:
parent
77c57dc459
commit
6a3547dad2
@ -13,16 +13,19 @@ export default {
|
|||||||
init(url) {
|
init(url) {
|
||||||
const connection = new signalR.HubConnectionBuilder()
|
const connection = new signalR.HubConnectionBuilder()
|
||||||
.withUrl(url, { accessTokenFactory: () => getToken() })
|
.withUrl(url, { accessTokenFactory: () => getToken() })
|
||||||
|
.withAutomaticReconnect()//自动重新连接
|
||||||
.build();
|
.build();
|
||||||
this.SR = connection;
|
this.SR = connection;
|
||||||
// 断线重连
|
// 断线重连
|
||||||
connection.onclose(async () => {
|
connection.onclose(async () => {
|
||||||
console.log('断开连接了')
|
console.log('断开连接了')
|
||||||
|
console.assert(connection.state === signalR.HubConnectionState.Disconnected);
|
||||||
|
// 建议用户重新刷新浏览器
|
||||||
await this.start();
|
await this.start();
|
||||||
})
|
})
|
||||||
|
|
||||||
connection.onreconnected(() => {
|
connection.onreconnected(() => {
|
||||||
console.log('断线重连')
|
console.log('断线重新连接成功')
|
||||||
})
|
})
|
||||||
this.receiveMsg(connection);
|
this.receiveMsg(connection);
|
||||||
// 启动
|
// 启动
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user