socket断链提示

This commit is contained in:
fan 2023-07-26 09:57:12 +08:00
parent 0d64cc8185
commit f598db1dd6
4 changed files with 22 additions and 10 deletions

@ -1 +1 @@
Subproject commit 0a08789fbdda1083005835e3bbd9a58bccbc167c
Subproject commit 7fe73a8334f36cf917255a99d75c454abcb96d79

View File

@ -68,6 +68,7 @@ import {
} from './graphics/SectionLinkInteraction';
import { AxleCountingSectionData } from './graphics/AxleCountingSectionInteraction';
import { LogicSectionData } from './graphics/LogicSectionInteraction';
import { Notify, QNotifyUpdateOptions } from 'quasar';
let lineApp: GraphicApp | null = null;
let msgBroker: AppWsMsgBroker | null = null;
@ -331,6 +332,19 @@ export async function loadLineDatas(app: GraphicApp) {
return states;
},
});
let msgNotify: null | ((props?: QNotifyUpdateOptions | undefined) => void) =
null;
app.on('websocket-connect-state-change', (connected) => {
if (!connected && !msgNotify) {
msgNotify = Notify.create({
type: 'negative',
timeout: 0,
message: '通信链接已断开!',
});
} else if (msgNotify && connected) {
msgNotify();
}
});
} else {
app.loadGraphic([]);
}

View File

@ -288,7 +288,7 @@ export interface GraphicAppEvents extends GlobalMixins.GraphicAppEvents {
drag_op_end: [event: AppDragEvent];
'pre-menu-handle': [menu: MenuItemOptions];
'post-menu-handle': [menu: MenuItemOptions];
'websocket-state-change': [app: GraphicApp, connected: boolean];
'websocket-connect-state-change': [connected: boolean];
destroy: [app: GraphicApp];
}

View File

@ -65,8 +65,7 @@ export class StompCli {
StompCli.client.onConnect = () => {
// console.log('websocket连接(重连),重新订阅', StompCli.appMsgBroker.length)
StompCli.connected = true;
StompCli.emitConnectStateChangeEvent();
StompCli.emitConnectStateChangeEvent(true);
StompCli.appMsgBroker.forEach((broker) => {
broker.resubscribe();
});
@ -87,13 +86,11 @@ export class StompCli {
StompCli.client.onDisconnect = (frame: Frame) => {
console.log('Stomp 断开连接', frame);
StompCli.connected = false;
StompCli.emitConnectStateChangeEvent();
StompCli.emitConnectStateChangeEvent(false);
};
StompCli.client.onWebSocketClose = (evt: CloseEvent) => {
console.log('websocket 关闭', evt);
StompCli.connected = false;
StompCli.emitConnectStateChangeEvent();
StompCli.emitConnectStateChangeEvent(false);
};
// websocket错误处理
StompCli.client.onWebSocketError = (err: Event) => {
@ -103,9 +100,10 @@ export class StompCli {
StompCli.client.activate();
}
static emitConnectStateChangeEvent() {
static emitConnectStateChangeEvent(connected: boolean) {
StompCli.connected = connected;
StompCli.appMsgBroker.forEach((broker) => {
broker.app.emit('websocket-state-change', broker.app, StompCli.connected);
broker.app.emit('websocket-connect-state-change', connected);
});
}