From 9a706820f9022c0b5545ac263ea95850e35eb7c9 Mon Sep 17 00:00:00 2001 From: fan Date: Fri, 30 Jun 2023 17:00:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- graphic-pixi | 2 +- src/drawApp/lineNetApp.ts | 1 + src/jl-graphic/message/WsMsgBroker.ts | 38 +++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/graphic-pixi b/graphic-pixi index 6626ad5..7e4eaed 160000 --- a/graphic-pixi +++ b/graphic-pixi @@ -1 +1 @@ -Subproject commit 6626ad51140f611fa8583895c27c6a788fca1d7f +Subproject commit 7e4eaed0cf06d68c75cb51c30329eff5fe4d1e3f diff --git a/src/drawApp/lineNetApp.ts b/src/drawApp/lineNetApp.ts index bef7ee5..1b950dd 100644 --- a/src/drawApp/lineNetApp.ts +++ b/src/drawApp/lineNetApp.ts @@ -119,6 +119,7 @@ export async function loadLineNetDatas(app: GraphicApp) { destination: '/queue/lineNet', messageConverter: (message: Uint8Array) => { const storage = state.WsLineNetMessage.deserialize(message); + console.log(storage, 'storage'); storage.offset.forEach((item) => { states.push(new TrainLineState(item)); }); diff --git a/src/jl-graphic/message/WsMsgBroker.ts b/src/jl-graphic/message/WsMsgBroker.ts index 940b11a..52d561a 100644 --- a/src/jl-graphic/message/WsMsgBroker.ts +++ b/src/jl-graphic/message/WsMsgBroker.ts @@ -152,12 +152,32 @@ export class StompCli { } // 状态订阅消息转换器 -export type MessageConverter = (message: Uint8Array) => GraphicState[]; +export type GraphicStateMessageConvert = ( + message: Uint8Array +) => GraphicState[]; + +// 订阅消息处理器 +export type SubscriptionMessageHandle = (message: Uint8Array) => void; + // 图形app状态订阅 export interface AppStateSubscription { + /** + * 订阅路径 + */ destination: string; - messageConverter: MessageConverter; - subscription?: StompSubscription; // 订阅成功对象,用于取消订阅 + /** + * 图形状态消息转换 + */ + messageConverter?: GraphicStateMessageConvert; + /** + * 订阅消息处理 + */ + messageHandle?: SubscriptionMessageHandle; + /** + * 订阅成功对象,用于取消订阅 + * 非客户端使用 + */ + subscription?: StompSubscription; } /** @@ -180,8 +200,16 @@ export class AppWsMsgBroker { sub.subscription = StompCli.trySubscribe( sub.destination, (message: Message) => { - const graphicStates = sub.messageConverter(message.binaryBody); - this.app.handleGraphicStates(graphicStates); + if (sub.messageConverter) { + const graphicStates = sub.messageConverter(message.binaryBody); + this.app.handleGraphicStates(graphicStates); + } else if (sub.messageHandle) { + sub.messageHandle(message.binaryBody); + } else { + console.error( + `订阅destination:${sub.destination}没有消息处理器或图形状态消息转换器` + ); + } } ); // console.log('代理订阅结果', sub.subscription)