UNPKG

1.55 kBTypeScriptView Raw
1import { AnyAction } from './actions/types';
2import { TransportDispatch } from './client';
3declare global {
4 interface Window {
5 SmartWebView: {
6 handleMessage: (message: String, data?: String) => void;
7 };
8 }
9}
10export declare enum Context {
11 Modal = "Modal",
12 Main = "Main"
13}
14/**
15 * @deprecated Not to be used, use regular `MessageEvent` instead.
16 * @internal
17 */
18export declare type HandlerData = {
19 data: AnyAction;
20};
21/**
22 * @internal
23 */
24export declare type Handler = (event: MessageEvent) => void;
25/**
26 * @internal
27 */
28export interface MessageTransport {
29 dispatch(message: TransportDispatch): void;
30 hostFrame: Window;
31 localOrigin: string;
32 subscribe(handler: Handler): () => void;
33}
34export interface ContextualMessageTransport extends MessageTransport {
35 context: Context;
36 frameWindow: Window | null;
37 dispatch(message: any): void;
38}
39/**
40 * Create a MessageTransport from an IFrame.
41 * @remarks
42 * Used on the host-side to create a postMessage MessageTransport.
43 * @beta
44 */
45export declare function fromFrame(frame: HTMLIFrameElement, localOrigin: string, context: Context): ContextualMessageTransport;
46/**
47 * Create a MessageTransport from a parent window.
48 * @remarks
49 * Used on the client-side to create a postMessage MessageTransport.
50 * @internalremarks
51 * In frameless mode, message should be dispatched via SmartWebView.handleMessage instead of postMessage.
52 * @beta
53 */
54export declare function fromWindow(contentWindow: Window, localOrigin: string): MessageTransport;