export type OnLeadership = (relinquish: Unsubscribe) => any; export type Unsubscribe = () => void; export type OnReceive = (msg: any) => void; export type OnState = (state: T) => void; export interface TabOptions { /** * How long a call waits for a return before rejecting with `Error('Call timed out')`. * Default 30s. */ callTimeout?: number; } export declare enum To { All = "all", Others = "others", Leader = "leader" } export interface TabEventMap { leadershipchange: Event; message: MessageEvent; state: MessageEvent; } export interface Tab { addEventListener(type: K, listener: (this: BroadcastChannel, ev: TabEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: BroadcastChannel, ev: TabEventMap[K]) => any, options?: boolean | EventListenerOptions): void; removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; } /** * A Tab is an interfaces to synchronize state and messages between tabs. It uses BroadcastChannel and the Lock API. * This is a simplified version of the original implementation. */ export declare class Tab> extends EventTarget implements Tab { relinquishLeadership: () => void; private _name; private _id; private _hasLeaderCache; private _hasLeaderChecking; private _callerId; private _callDeferreds; private _queuedCalls; private _channel; private _isLeader; private _isLeaderReady; private _state; private _callCount; private _api; private _sentCalls; private _callTimeout; private _closeAbort; private _closed; constructor(name?: string, options?: TabOptions); get id(): string; get name(): string; get isLeader(): boolean; hasLeader(): Promise; getCurrentCallerId(): string; getState(): T; setState(state: T): void; waitForLeadership(onLeadership: OnLeadership, options?: { steal?: boolean; }): Promise; call(name: string, ...rest: any[]): Promise; /** * Post a call to the leader, re-posting every 500ms until the leader acks it * with `callReceived` (a leader that never acks is assumed dead — the resend * reaches its successor). */ private _sendCall; /** Settle one of this tab's own pending calls with an error, mirroring `_onReturn`'s cleanup. */ private _failCall; private _clearSentCall; send(data: any, to?: string | Set): void; close(): void; _isToMe(to: string | Set, sending?: boolean): boolean; _createChannel(): void; _postMessage(to: string | Set, name: string, ...rest: any[]): void; _onMessage(event: MessageEvent): void; _onCall(id: string, callNumber: number, name: string, ...rest: any[]): Promise; _callReceived(callNumber: number): void; _onReturn(callNumber: number, error: any, results: any): void; _onState(data: T): void; _onSend(data: any): void; _onSendState(id: string): void; _onLeader(state: T): void; }