rx-postmessenger
Version:
Minimal RxJS adapter for the window.postMessage API for request-response streams and notification streams across frame windows.
30 lines (29 loc) • 1.39 kB
TypeScript
import type { AnyMessage, IMessageValidator, IOwnMessageEvent } from './types';
export declare class MessageValidator implements IMessageValidator {
protected acceptedSource: Window;
protected acceptedOrigin: string;
constructor(acceptedSource: Window, acceptedOrigin: string);
/**
* Validates the identity of the message's sender and the format of the message's data.
*
* Checks whether the remoteOrigin location matches any allowed origins.
* Separate assertion of the remoteOrigin allows for cross-domain navigation
* within this.frame, and still treating inbound messages from the
* frame as being equal.
*
* Checks whether the source Window object equals the remoteWindow object.
* This check allows for implementation of multiple i-frames that share the
* same remoteOrigin, and still being able to distinguish between messages from
* such frames.
*/
validate(message: MessageEvent): message is IOwnMessageEvent<AnyMessage>;
/**
* Tests whether the data sent through postMessage is a well-formed message
* object. This serves as runtime data format validation. If messages do not
* comply to the AnyMessage compound interface, the entire event is ignored.
*
* @param {*} message
* @return {boolean}
*/
isWellFormedMessage(message: any): message is AnyMessage;
}