代码同步

This commit is contained in:
fan 2023-06-30 17:00:02 +08:00
parent 7aa731d9f8
commit 9a706820f9
3 changed files with 35 additions and 6 deletions

@ -1 +1 @@
Subproject commit 6626ad51140f611fa8583895c27c6a788fca1d7f
Subproject commit 7e4eaed0cf06d68c75cb51c30329eff5fe4d1e3f

View File

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

View File

@ -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)