UNPKG

@toruslabs/broadcast-channel

Version:

A BroadcastChannel that works in New Browsers, Old Browsers, WebWorkers

32 lines (31 loc) 1.2 kB
import { AddEventListeners, EventType, IBroadcastChannel, Method, MethodType, Options as BroadcastChannelOptions } from "./types"; export declare function enforceOptions(options: BroadcastChannelOptions): void; /** * Contains all open channels, * used in tests to ensure everything is closed. */ export declare const OPEN_BROADCAST_CHANNELS: Set<BroadcastChannel<unknown>>; export declare class BroadcastChannel<T = any> implements IBroadcastChannel<T> { static _pubkey: boolean; id: number; name: string; options: BroadcastChannelOptions; method: Method; closed: boolean; _addEL: AddEventListeners; _prepP: Promise<unknown> | null; _state: unknown; _uMP: Set<Promise<T>>; _iL: boolean; private _onML; private _befC; constructor(name: string, options?: BroadcastChannelOptions); get type(): MethodType; get isClosed(): boolean; set onmessage(fn: ((data: T) => void) | null); postMessage(msg: T): Promise<T>; postInternal(msg: unknown): Promise<unknown>; addEventListener(type: EventType, fn: (data: T) => void): void; removeEventListener(type: EventType, fn: (data: T) => void): void; close(): Promise<void>; }