|
@@ -1,8 +1,8 @@
|
|
|
// 官方文档:https://docs.microsoft.com/zh-cn/aspnet/core/signalr/javascript-client?view=aspnetcore-6.0&viewFallbackFrom=aspnetcore-2.2&tabs=visual-studio
|
|
|
import * as signalR from '@microsoft/signalr';
|
|
|
import { Cookie, Local } from '@/utils/storage';
|
|
|
-import { submitLog } from "@/api/public/log";
|
|
|
-import { getNowDateTime } from "@/utils/constants";
|
|
|
+import { submitLog } from '@/api/public/log';
|
|
|
+import { getNowDateTime } from '@/utils/constants';
|
|
|
// 记录日志
|
|
|
const submitLogFn = async (request: any) => {
|
|
|
try {
|
|
@@ -37,7 +37,7 @@ export default {
|
|
|
executeUrl: import.meta.env.VITE_API_SOCKET_URL,
|
|
|
};
|
|
|
await submitLogFn(request);
|
|
|
- console.log('业务系统signal当前链接状态:', connection.state,getNowDateTime());
|
|
|
+ console.log('业务系统signal当前链接状态:', connection.state, getNowDateTime());
|
|
|
// 建议用户重新刷新浏览器
|
|
|
await this.start();
|
|
|
});
|
|
@@ -51,7 +51,7 @@ export default {
|
|
|
executeUrl: import.meta.env.VITE_API_SOCKET_URL,
|
|
|
};
|
|
|
await submitLogFn(request);
|
|
|
- console.log('业务系统signal断线重连成功',getNowDateTime());
|
|
|
+ console.log('业务系统signal断线重连成功', getNowDateTime());
|
|
|
// location.reload();
|
|
|
/*ElNotification({
|
|
|
type: 'success',
|
|
@@ -61,15 +61,15 @@ export default {
|
|
|
});
|
|
|
// 服务端推送消息
|
|
|
connection.on('Send', (message: any) => {
|
|
|
- console.log(`有用户加入分组:${message}`,getNowDateTime());
|
|
|
+ console.log(`有用户加入分组:${message}`, getNowDateTime());
|
|
|
});
|
|
|
// 服务端推送消息
|
|
|
connection.on('CircularRecord', (message: any) => {
|
|
|
- console.log(`小红点消息:${message}`,getNowDateTime());
|
|
|
+ console.log(`小红点消息:${message}`, getNowDateTime());
|
|
|
});
|
|
|
// 服务端推送消息
|
|
|
connection.on('SeatState', (message: any) => {
|
|
|
- console.log(`座席状态:${JSON.stringify(message)}`,getNowDateTime());
|
|
|
+ console.log(`座席状态:${JSON.stringify(message)}`, getNowDateTime());
|
|
|
});
|
|
|
// 服务端推送消息
|
|
|
connection.on('RestApplyPass', (message: any) => {
|
|
@@ -101,7 +101,7 @@ export default {
|
|
|
try {
|
|
|
//使用async和await 或 promise的then 和catch 处理来自服务端的异常
|
|
|
await this.SR.start();
|
|
|
- console.log('业务系统signal当前链接状态:', this.SR.state,getNowDateTime());
|
|
|
+ console.log('业务系统signal当前链接状态:', this.SR.state, getNowDateTime());
|
|
|
const name: string = `业务系统的websocket链接成功`;
|
|
|
const remark: string = `业务系统的websocket断开链接`;
|
|
|
const request = {
|
|
@@ -140,22 +140,14 @@ export default {
|
|
|
// 判断是否已经建立链接 如果没有 先链接
|
|
|
await this.SR.invoke('JoinGroupAsync', { GroupName: groupName });
|
|
|
} else {
|
|
|
- // 等待链接成功再发送
|
|
|
- if (this.SR?.state === 'Connecting') {
|
|
|
+ try {
|
|
|
+ await this.start();
|
|
|
setTimeout(async () => {
|
|
|
- await this.SR.invoke('JoinGroupAsync', { GroupName: groupName });
|
|
|
+ await this.SR?.invoke('JoinGroupAsync', { GroupName: groupName });
|
|
|
}, 500);
|
|
|
- return;
|
|
|
+ } catch (err) {
|
|
|
+ console.log(err);
|
|
|
}
|
|
|
- await this.start()
|
|
|
- .then(async () => {
|
|
|
- setTimeout(async () => {
|
|
|
- await this.SR?.invoke('JoinGroupAsync', { GroupName: groupName });
|
|
|
- }, 500);
|
|
|
- })
|
|
|
- .catch((err) => {
|
|
|
- console.log(err);
|
|
|
- });
|
|
|
}
|
|
|
},
|
|
|
/**
|
|
@@ -197,7 +189,7 @@ export default {
|
|
|
try {
|
|
|
//使用async和await 或 promise的then 和catch 处理来自服务端的异常
|
|
|
await this.SR.stop();
|
|
|
- console.log(this.SR.state, '断开链接',getNowDateTime());
|
|
|
+ console.log(this.SR.state, '断开链接', getNowDateTime());
|
|
|
} catch (error) {
|
|
|
console.log('signalR', error);
|
|
|
}
|
|
@@ -210,11 +202,10 @@ export default {
|
|
|
try {
|
|
|
const telStatusInfo = Local.get('telStatusInfo');
|
|
|
//使用async和await 或 promise的then 和catch 处理来自服务端的异常
|
|
|
- this.SR?.invoke('SendSeatState', { telNo: telStatusInfo?.telStatusInfo?.telsNo ?? '', state: 'logout' });
|
|
|
await this.leaveGroup('CallCenter');
|
|
|
await this.leaveGroup('BigScreen-SeatState');
|
|
|
await this.stop();
|
|
|
- console.log(this.SR.state, '断开链接',getNowDateTime());
|
|
|
+ console.log(this.SR.state, '断开链接', getNowDateTime());
|
|
|
} catch (error) {
|
|
|
console.log('signalR', error);
|
|
|
}
|