@o3r/third-party
Version:
This module provides a bridge to communicate with third parties via an iFrame solution.
39 lines • 1.79 kB
TypeScript
import { Observable } from 'rxjs';
import { IFrameBridgeOptions, IframeMessage, InternalIframeMessage } from './contracts';
/**
* Bridge that exposes an easy abstraction layer to communicate between a Host and an IFrame using the
* postMessage API.
*/
export declare class IframeBridge {
private readonly child;
/** ID used to ensure that the Bridge only processes messages meant for this instance, since postMessage is global to the window. */
private readonly channelId;
/** Observable that emits all the messages received from the IFrame. */
private readonly internalMessages$;
/** Promise that will resolve once the handshake has been completed, undefined if it's already done. */
private readonly handshakePromise?;
/** Options to configure the behaviour of the Bridge. */
private readonly options;
/**
* Observable that emits all the messages received from the IFrame and that are
* not a direct response to a request.
*/
readonly messages$: Observable<InternalIframeMessage>;
constructor(parent: Window, child: HTMLIFrameElement, options?: Partial<IFrameBridgeOptions>);
private handshake;
private _sendMessage;
private _sendMessageAndWaitForResponse;
/**
* Method to send a message to the script run in the iframe
* @param message message object
* @param messageId message identifier
*/
sendMessage(message: IframeMessage, messageId?: string): Promise<void>;
/**
* Method to send a message to the script run in the iframe and wait for an answer
* @param message
* @param timeoutMilliseconds
*/
sendMessageAndWaitForResponse(message: IframeMessage, timeoutMilliseconds?: number): Promise<InternalIframeMessage>;
}
//# sourceMappingURL=bridge.d.ts.map