UNPKG

1.41 kBTypeScriptView Raw
1export declare type ChannelHandler = (event: ChannelEvent) => void;
2export interface ChannelTransport {
3 send(event: ChannelEvent, options?: any): void;
4 setHandler(handler: ChannelHandler): void;
5}
6export interface ChannelEvent {
7 type: string;
8 from: string;
9 args: any[];
10}
11export interface Listener {
12 (...args: any[]): void;
13}
14interface ChannelArgs {
15 transport?: ChannelTransport;
16 async?: boolean;
17}
18export declare class Channel {
19 readonly isAsync: boolean;
20 private sender;
21 private events;
22 private data;
23 private readonly transport;
24 constructor({ transport, async }?: ChannelArgs);
25 readonly hasTransport: boolean;
26 addListener(eventName: string, listener: Listener): void;
27 addPeerListener: (eventName: string, listener: Listener) => void;
28 emit(eventName: string, ...args: any): void;
29 last(eventName: string): any;
30 eventNames(): string[];
31 listenerCount(eventName: string): number;
32 listeners(eventName: string): Listener[] | undefined;
33 once(eventName: string, listener: Listener): void;
34 removeAllListeners(eventName?: string): void;
35 removeListener(eventName: string, listener: Listener): void;
36 on(eventName: string, listener: Listener): void;
37 off(eventName: string, listener: Listener): void;
38 private handleEvent;
39 private onceListener;
40}
41export default Channel;