graphic-pixi/lib/message/MessageBroker.d.ts

147 lines
4.0 KiB
TypeScript
Raw Normal View History

2023-12-12 17:31:07 +08:00
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 {};