graphic-pixi/lib/message/MessageBroker.d.ts
2023-12-14 13:07:43 +08:00

147 lines
4.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import EventEmitter from 'eventemitter3';
import { IGraphicScene } from '../app';
import { GraphicQueryStore, GraphicState, JlGraphic } from '../core';
import { IMessageHandler, MessageClientEvents } from './BasicMessageClient';
export declare enum ClientEngine {
Stomp = 0,
MQTT = 1
}
export interface MessageCliOption {
/**
* 客户端引擎
*/
engine?: ClientEngine;
/**
* 消息协议,默认protobuf
*/
protocol?: 'json' | 'protobuf';
/**
* websocket url地址
*/
wsUrl: string;
/**
* 认证token
*/
token?: string;
/**
* 项目名称(可用于订阅客户端识别)
*/
clientName?: string;
/**
* 连接超时,默认30秒,ms
*/
connectTimeout?: number;
/**
* 心跳发送间隔,默认60秒,s
*/
heartbeat?: number;
/**
* 重试间隔,默认2秒,ms
*/
retryPeriod?: number;
/**
* 重试次数,默认100次
*/
retryTimes?: number;
}
export interface CompleteMessageCliOption extends MessageCliOption {
protocol: 'json' | 'protobuf';
connectTimeout: number;
heartbeat: number;
retryPeriod: number;
retryTimes: number;
}
export interface IMessageClient extends EventEmitter<MessageClientEvents> {
/**
* 添加订阅
* @param destination
* @param handler
*/
addSubscription(destination: string, handler: IMessageHandler): void;
/**
* 移除订阅
* @param destination
* @param handler
*/
removeSubscription(destination: string, handler: IMessageHandler): void;
/**
* 是否已经连接
*/
get connected(): boolean;
/**
* 关闭连接
*/
close(): void;
}
export declare class WsMsgCli {
private static client;
private static options;
private static appMsgBroker;
static new(options: MessageCliOption): void;
static isInitiated(): boolean;
static emitConnectStateChangeEvent(connected: boolean): void;
static isConnected(): boolean;
static registerSubscription(destination: string, handler: IMessageHandler): void;
static unregisterSubscription(destination: string, handler: IMessageHandler): void;
static registerAppMsgBroker(broker: AppWsMsgBroker): void;
static removeAppMsgBroker(broker: AppWsMsgBroker): void;
static hasAppMsgBroker(): boolean;
/**
* 关闭websocket连接
*/
static close(): void;
}
export type GraphicStateMessageConvert = (message: Uint8Array) => GraphicState[];
export type GraphicQuery = (state: GraphicState, store: GraphicQueryStore) => JlGraphic | undefined;
export type SubscriptionMessageHandle = (message: Uint8Array) => void;
export interface ICreateOnNotFound {
graphicTypes?: string[];
}
export interface AppStateSubscription {
/**
* 订阅路径
*/
destination: string;
/**
* 图形状态消息转换
*/
messageConverter?: GraphicStateMessageConvert;
/**
* 根据状态查询图形对象,默认为根据code和type查询图形对象
*/
graphicQueryer?: GraphicQuery;
/**
* 当未根据状态找到图形对象时是否创建新对象
* 值为设备类型列表
*/
createOnNotFound?: ICreateOnNotFound;
/**
* 订阅消息处理
*/
messageHandle?: SubscriptionMessageHandle;
}
declare class AppMessageHandler implements IMessageHandler {
app: IGraphicScene;
sub: AppStateSubscription;
constructor(app: IGraphicScene, subOptions: AppStateSubscription);
get App(): IGraphicScene;
handle(data: any): void;
}
/**
* 图形APP的websocket消息代理
*/
export declare class AppWsMsgBroker {
app: IGraphicScene;
subscriptions: Map<string, AppMessageHandler>;
constructor(app: IGraphicScene);
subscribe(sub: AppStateSubscription): void;
unsbuscribe(destination: string): void;
unsubscribeAll(): void;
resubscribeAll(): void;
/**
* 取消所有订阅从通用Stomp客户端移除此消息代理
*/
close(): void;
}
export {};
//# sourceMappingURL=MessageBroker.d.ts.map