UNPKG

@comapeo/ipc

Version:
39 lines (38 loc) 1.38 kB
export const MAPEO_RPC_ID: "@@mapeo-rpc"; export const MANAGER_CHANNEL_ID: "@@manager"; /** * @typedef {Object} Events * @property {(message: any) => void} message */ /** * Node's built-in types for MessagePort are misleading so we opt for this limited type definition * that fits our usage and works in both Node and browser contexts * @typedef {Pick<EventTarget, 'addEventListener' | 'removeEventListener'> & { postMessage: (message: any) => void }} MessagePortLike */ export class SubChannel extends EventEmitter<string | symbol, any> { /** * @param {MessagePortLike} messagePort Parent channel to add namespace to * @param {string} id ID for the subchannel */ constructor(messagePort: MessagePortLike, id: string); get id(): string; /** * Send messages with the subchannel's ID * @param {any} message */ postMessage(message: any): void; start(): void; close(): void; #private; } export type Events = { message: (message: any) => void; }; /** * Node's built-in types for MessagePort are misleading so we opt for this limited type definition * that fits our usage and works in both Node and browser contexts */ export type MessagePortLike = Pick<EventTarget, "addEventListener" | "removeEventListener"> & { postMessage: (message: any) => void; }; import { EventEmitter } from 'eventemitter3';