import { Protoframe, ProtoframeMessageType, ProtoframeMessageResponse, ProtoframeMessageBody, ProtoframeDescriptor } from './types'; interface Connector { /** Destroy the connector and all resources/listeners being held. */ destroy(): void; } interface AbstractProtoframeSubscriber

extends Connector { /** * Handle a message that was sent with the [[ProtoframePublisher.tell]] * function. * * @param type The message type being handled * @param handler The handler function for the message */ handleTell, _R extends ProtoframeMessageResponse & undefined>(type: T, handler: (body: ProtoframeMessageBody) => void): void; } interface AbstractProtoframePublisher

extends Connector { /** * Send a message to a receiving connector. This is a fire-and-forget emitter * that does not accept a response. If you want a request-response workflow, * use [[ProtoframePubsub.ask]]. * * @param type The message type being sent * @param body The body of the message to send */ tell, _R extends ProtoframeMessageResponse & undefined>(type: T, body: ProtoframeMessageBody): void; } interface AbstractProtoframePubsub

extends AbstractProtoframeSubscriber

, AbstractProtoframePublisher

{ /** * Send an "ask" message to the receiving connector. On the other end, a * connector would have invoked `handleAsk` in order to receive this message * and issue a response. * * The promise returned by this call will resolve when a response as been * received from the target connector, or if the timeout has been exceeded * * @param type The message type being asked * @param body The body of the ask message * @param timeout How long to wait for a response before the resulting promise * is rejected with a timeout error. */ ask, B extends ProtoframeMessageBody, R extends ProtoframeMessageResponse & Record>(type: T, body: B, timeout?: number): Promise; /** * Handle an "ask" message and provide a response. This is invoked when the * asking connector has invoked the `ask` method of the pubsub connector. * * @param type The message type being listened to * @param handler The message handler that eventually returns a response */ handleAsk, R extends ProtoframeMessageResponse & Record>(type: T, handler: (body: ProtoframeMessageBody) => Promise): void; } export declare class ProtoframeSubscriber

implements AbstractProtoframeSubscriber

{ private readonly protocol; private readonly thisWindow; constructor(protocol: ProtoframeDescriptor

, thisWindow?: Window); private listeners; handleTell, _R extends ProtoframeMessageResponse & undefined>(type: T, handler: (body: ProtoframeMessageBody) => void): void; destroy(): void; } export declare class ProtoframePublisher

implements AbstractProtoframePublisher

{ private readonly protocol; private readonly targetWindow; private readonly targetOrigin; /** * We are a "parent" page that is embedding an iframe, and we wish to connect * to that iframe in order to publish messages. * * @param protocol The protocol this connector will communicate with * @param iframe The target iframe HTML element we are connecting to * @param targetOrigin The target scheme and host we expect the receiver to be */ static parent

(protocol: ProtoframeDescriptor

, iframe: HTMLIFrameElement, targetOrigin?: string): ProtoframePublisher

; /** * We are an "iframe" page that will be embedded, and we wish to connect to a * parent page in order to publish messages. * * @param protocol The protocol this connector will communicate with * @param targetOrigin The target scheme and host we expect the receiver to be * @param targetWindow The window of the parent frame. This should normally be * the `window.parent` */ static iframe

(protocol: ProtoframeDescriptor

, targetOrigin?: string, targetWindow?: Window): ProtoframePublisher

; private listeners; constructor(protocol: ProtoframeDescriptor

, targetWindow: Window, targetOrigin?: string); tell, _R extends undefined>(type: T, body: P[T]['body']): void; destroy(): void; } export declare class ProtoframePubsub

implements AbstractProtoframePubsub

{ private readonly protocol; private readonly targetWindow; private readonly thisWindow; private readonly targetOrigin; /** * Connect to the target configured in the supplied pubsub connector by * sending ping requests over and over until we get a response. * * @param pubsub The pubsub connector to wait until is "connected" to its * target * @param retries How many times to retry and ping the target. By default, * this will retry 50 times (thus waiting 25 seconds total) * @param timeout How long to wait for a response from the target before * retrying. By default the timeout is 500ms (thus waiting 25 seconds total) */ static connect

(pubsub: ProtoframePubsub

, retries?: number, timeout?: number): Promise>; /** * We are a "parent" page that is embedding an iframe, and we wish to connect * to that iframe for communication. * * @param protocol The protocol this connector will communicate with * @param iframe The target iframe HTML element we are connecting to * @param targetOrigin The target scheme and host we expect the receiver to be * @param thisWindow The parent window (our window). This should normally be * the current `window` */ static parent

(protocol: ProtoframeDescriptor

, iframe: HTMLIFrameElement, targetOrigin?: string, thisWindow?: Window): ProtoframePubsub

; /** * We are an "iframe" page that will be embedded, and we wish to connect to a * parent page for communication. * * @param protocol The protocol this connector will communicate with * @param targetOrigin The target scheme and host we expect the receiver to be * @param thisWindow The window of the current iframe. This should normally be * the current `window` * @param targetWindow The window of the parent frame. This should normally be * the `window.parent` */ static iframe

(protocol: ProtoframeDescriptor

, targetOrigin?: string, { thisWindow, targetWindow, }?: { thisWindow?: Window; targetWindow?: Window; }): ProtoframePubsub

; private systemProtocol; private listeners; constructor(protocol: ProtoframeDescriptor

, targetWindow: Window, thisWindow?: Window, targetOrigin?: string); /** * Send a 'ping' request to check if there is a listener open at the target * window. If this times out, then it means no listener was available *at the * time the ping request was sent*. Since requests are not buffered, then this * should be retried if we're waiting for some target iframe to start up and * load its assets. See `ProtoframePubsub.connect` as an implementation of * this functionality. * * @param timeout How long to wait for the reply before resulting in an error */ ping({ timeout }: { timeout?: number; }): Promise; handleTell, _R extends ProtoframeMessageResponse & undefined>(type: T, handler: (body: ProtoframeMessageBody) => void): void; tell, _R extends undefined>(type: T, body: P[T]['body']): void; handleAsk, R extends P[T]['response'] & Record>(type: T, handler: (body: P[T]['body']) => Promise): void; ask, B extends P[T]['body'], R extends P[T]['response'] & Record>(type: T, body: B, timeout?: number): Promise; destroy(): void; } export {};