调整websocket连接状态事件发布

This commit is contained in:
walker 2023-07-25 15:37:41 +08:00
parent 0a08789fbd
commit 7fe73a8334
2 changed files with 7 additions and 9 deletions

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);
});
}