/** * This module establishes a simple protocol for creating a MessageChannel between two * realms, as follows: * 1. The sending realm asserts that the receiving realm is ready to receive messages, * either by creating the realm itself (for example, by appending an iframe to the DOM), * or via some other means. * 2. The receiving realm calls `receiveMessagePort()` on startup in one of its scripts. * The script element in question should not have the `async` attribute. * 3. The sending realm calls `initializeMessageChannel()` which sends a message port to * the receiving realm. When the returned promise resolves, the sending realm and the * receiving realm have established a message channel. * * @module MessageChannel utilities */ export declare const MessageType: { readonly Initialize: "INIT_MESSAGE_CHANNEL"; readonly Acknowledge: "ACK_MESSAGE_CHANNEL"; }; /** * Creates a message channel and sends one of the ports to the receiving realm. The * realm must be loaded, and it must have called {@link receiveMessagePort} to * receive the remote message port. Rejects if the first message received over the * channel is not an {@link AcknowledgeMessage}. * * A `portHandler` function can be specified to synchronously perform any work with * the local message port before the promise resolves. * * @param postMessage - A bound method for posting a message to the receiving realm. * Must be able to transfer a message port. * @param portHandler - A function that receives the local message port and returns a * value. Returns the local message port by default. * @returns A promise that resolves with the value returned by `portHandler`. */ export declare function initializeMessageChannel(postMessage: (message: unknown, transfer: Transferable[]) => void, portHandler?: (port: MessagePort) => Result): Promise; type Listener = (message: MessageEvent) => void; /** * Receives a message port from the sending realm, and sends an {@link AcknowledgeMessage} * over the port. Should be called in a script _without_ the `async` attribute on startup. * The sending realm must call {@link initializeMessageChannel} to send the message port * after this realm has loaded. Ignores any message events dispatched on the local * realm that are not an {@link InitializeMessage}. * * A `portHandler` function can be specified to synchronously perform any work with the * received port before the promise resolves. * * @param addListener - A bound method to add a message event listener to the sending * realm. * @param removeListener - A bound method to remove a message event listener from the * sending realm. * @param portHandler - A function that receives the message port and returns a value. * Returns the message port by default. * @returns A promise that resolves with the value returned by `portHandler`. */ export declare function receiveMessagePort(addListener: (listener: Listener) => void, removeListener: (listener: Listener) => void, portHandler?: (port: MessagePort) => Result): Promise; export {}; //# sourceMappingURL=message-channel.d.cts.map