-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandshake.d.ts
52 lines (52 loc) · 1.77 KB
/
handshake.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
type ReadyEvent = {
emit: (key: string, value: any) => void;
on: (key: string, callback: (value: any) => void) => void;
revert: () => void;
};
type MESSAGE_TYPES = "handshake" | "handshake-reply" | "event";
declare abstract class BaseChannel {
protected _Promise: Promise<this>;
protected _PromiseResolver: (value: this | PromiseLike<this>) => void;
protected _PromiseRejecter: (reason?: any) => void;
protected _handlers: {
[key: string]: Array<(value: any) => void>;
};
protected _targetWindow?: Window | null;
protected _targetOrigin?: string;
protected _bindedOnMessage: (e: MessageEvent) => void;
constructor(opt?: {
targetWindow?: Window;
targetOrigin?: string;
});
protected _sendMessage(msg: any): void;
protected _trigger(key: string, value: any): void;
ready(callback: (event: ReadyEvent) => void): void;
emit(key: string, value: any): void;
on(key: string, callback: (value: any) => void): void;
revert(): void;
protected abstract _onMessage(event: MessageEvent): void;
protected _handleOnMessage(e: MessageEvent, type: MESSAGE_TYPES, callback: () => void): void;
}
export declare class Parent extends BaseChannel {
container: HTMLElement;
iframe: HTMLIFrameElement;
protected _handshakeInterval?: number;
constructor(opt: {
container: string;
url: string;
});
revert(): void;
ready(callback: (event: {
iframe: HTMLIFrameElement;
container: HTMLElement;
} & ReadyEvent) => void): void;
private _startHandshake;
protected _onMessage(e: MessageEvent): void;
}
export declare class Child extends BaseChannel {
constructor(opt: {
url: string;
});
protected _onMessage(e: MessageEvent): void;
}
export {};