UNPKG

@readium/navigator-html-injectables

Version:

An embeddable solution for connecting frames of HTML publications with a Readium Navigator

41 lines (40 loc) 1.32 kB
import { ReadiumWindow } from "../helpers/dom"; import { CommsEventKey, CommsCommandKey } from "./keys"; export declare const COMMS_VERSION = 1; export interface CommsMessage { _readium: number; _channel: string; id?: string; strict?: boolean; key: CommsEventKey | CommsCommandKey; data: unknown; } export interface Registrant { module: string; cb: CommsCallback; } export type CommsAck = (ok: boolean) => void; export type CommsCallback = (data: unknown, ack: CommsAck) => void; /** * Comms is basically a wrapper around window.postMessage that * adds structure to the messages and lets modules register callbacks. */ export declare class Comms { private readonly wnd; private destination; private registrar; private origin; private channelId; constructor(wnd: ReadiumWindow); private receive; private receiver; private handle; register(key: CommsCommandKey | CommsCommandKey[], module: string, callback: CommsCallback): void; unregister(key: CommsCommandKey | CommsCommandKey[], module: string): void; unregisterAll(module: string): void; private preLog; log(...data: any[]): void; get ready(): boolean; destroy(): void; send(key: CommsEventKey, data: unknown, id?: unknown, transfer?: Transferable[]): void; }