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

53 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-12-12 17:31:07 +08:00
import EventEmitter from 'eventemitter3';
import { IGraphicScene } from '../app';
import { CompleteMessageCliOption, IMessageClient } from './MessageBroker';
export interface MessageClientEvents {
connected: [ctx: any];
disconnected: [ctx: any];
error: [err: any];
}
export type HandleMessage = (data: any) => void;
export interface IMessageHandler {
/**
* id
*/
get App(): IGraphicScene;
/**
*
* @param data
*/
handle(data: any): void;
}
export declare abstract class MessageClient extends EventEmitter<MessageClientEvents> implements IMessageClient {
options: CompleteMessageCliOption;
subClients: SubscriptionClient[];
constructor(options: CompleteMessageCliOption);
/**
*
* @param destination
* @param handle
*/
abstract subscribe(destination: string, handle: HandleMessage): boolean;
unsubscribe(destination: string): void;
abstract unsubscribe0(destination: string): void;
getOrNewSubClient(destination: string): SubscriptionClient;
addSubscription(destination: string, handler: IMessageHandler): void;
removeSubscription(destination: string, handle: IMessageHandler): void;
abstract get connected(): boolean;
abstract close(): void;
}
export declare class SubscriptionClient {
mc: MessageClient;
destination: string;
protocol: 'json' | 'protobuf';
handlers: IMessageHandler[];
subscripted: boolean;
constructor(mc: MessageClient, destination: string, protocal: 'json' | 'protobuf');
addHandler(handler: IMessageHandler): void;
removeHandler(handler: IMessageHandler): void;
trySubscribe(): void;
unsubscribe(): void;
handleMessage(data: any): void;
onDisconnect(): void;
}