iframe.io 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +66 -11
- package/dist/index.js +435 -72
- package/package.json +1 -1
- package/src/index.ts +515 -90
package/dist/index.d.ts
CHANGED
|
@@ -1,39 +1,94 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
export type PeerType = 'WINDOW' | 'IFRAME';
|
|
2
|
+
export type AckFunction = (error: boolean | string, ...args: any[]) => void;
|
|
3
|
+
export type Listener = (payload?: any, ack?: AckFunction) => void;
|
|
4
|
+
export type Options = {
|
|
5
5
|
type?: PeerType;
|
|
6
|
+
debug?: boolean;
|
|
7
|
+
heartbeatInterval?: number;
|
|
8
|
+
connectionTimeout?: number;
|
|
9
|
+
maxMessageSize?: number;
|
|
10
|
+
maxMessagesPerSecond?: number;
|
|
11
|
+
autoReconnect?: boolean;
|
|
12
|
+
messageQueueSize?: number;
|
|
6
13
|
};
|
|
7
14
|
export interface RegisteredEvents {
|
|
8
15
|
[index: string]: Listener[];
|
|
9
16
|
}
|
|
10
|
-
export
|
|
17
|
+
export type Peer = {
|
|
11
18
|
type: PeerType;
|
|
12
19
|
source?: Window;
|
|
13
20
|
origin?: string;
|
|
21
|
+
connected?: boolean;
|
|
22
|
+
lastHeartbeat?: number;
|
|
14
23
|
};
|
|
15
|
-
export
|
|
24
|
+
export type MessageData = {
|
|
16
25
|
_event: string;
|
|
17
26
|
payload: any;
|
|
18
|
-
cid:
|
|
27
|
+
cid: string | undefined;
|
|
28
|
+
timestamp?: number;
|
|
29
|
+
size?: number;
|
|
19
30
|
};
|
|
20
|
-
export
|
|
31
|
+
export type Message = {
|
|
21
32
|
origin: string;
|
|
22
33
|
data: MessageData;
|
|
23
34
|
source: Window;
|
|
24
35
|
};
|
|
36
|
+
export type QueuedMessage = {
|
|
37
|
+
_event: string;
|
|
38
|
+
payload: any;
|
|
39
|
+
fn?: AckFunction;
|
|
40
|
+
timestamp: number;
|
|
41
|
+
};
|
|
25
42
|
export default class IOF {
|
|
26
43
|
Events: RegisteredEvents;
|
|
27
44
|
peer: Peer;
|
|
28
45
|
options: Options;
|
|
29
|
-
|
|
46
|
+
private messageListener?;
|
|
47
|
+
private heartbeatTimer?;
|
|
48
|
+
private reconnectTimer?;
|
|
49
|
+
private messageQueue;
|
|
50
|
+
private messageRateTracker;
|
|
51
|
+
private reconnectAttempts;
|
|
52
|
+
private maxReconnectAttempts;
|
|
53
|
+
constructor(options?: Options);
|
|
30
54
|
debug(...args: any[]): void;
|
|
55
|
+
isConnected(): boolean;
|
|
56
|
+
private startHeartbeat;
|
|
57
|
+
private stopHeartbeat;
|
|
58
|
+
private handleConnectionLoss;
|
|
59
|
+
private attemptReconnection;
|
|
60
|
+
private checkRateLimit;
|
|
61
|
+
private queueMessage;
|
|
62
|
+
private processMessageQueue;
|
|
63
|
+
/**
|
|
64
|
+
* Establish a connection with an iframe containing
|
|
65
|
+
* in the current window
|
|
66
|
+
*/
|
|
31
67
|
initiate(contentWindow: MessageEventSource, iframeOrigin: string): this;
|
|
68
|
+
/**
|
|
69
|
+
* Listening to connection from the content window
|
|
70
|
+
*/
|
|
32
71
|
listen(hostOrigin?: string): this;
|
|
33
|
-
fire(_event: string, payload?: MessageData['payload'], cid?:
|
|
34
|
-
emit(_event: string, payload?:
|
|
72
|
+
fire(_event: string, payload?: MessageData['payload'], cid?: string): void;
|
|
73
|
+
emit<T = any>(_event: string, payload?: T | AckFunction, fn?: AckFunction): this;
|
|
35
74
|
on(_event: string, fn: Listener): this;
|
|
36
75
|
once(_event: string, fn: Listener): this;
|
|
37
76
|
off(_event: string, fn?: Listener): this;
|
|
38
77
|
removeListeners(fn?: Listener): this;
|
|
78
|
+
emitAsync<T = any, R = any>(_event: string, payload?: T): Promise<R>;
|
|
79
|
+
onceAsync<T = any>(_event: string): Promise<T>;
|
|
80
|
+
connectAsync(timeout?: number): Promise<void>;
|
|
81
|
+
private cleanup;
|
|
82
|
+
disconnect(fn?: () => void): this;
|
|
83
|
+
getStats(): {
|
|
84
|
+
connected: boolean;
|
|
85
|
+
peerType: PeerType;
|
|
86
|
+
origin: string | undefined;
|
|
87
|
+
lastHeartbeat: number | undefined;
|
|
88
|
+
queuedMessages: number;
|
|
89
|
+
reconnectAttempts: number;
|
|
90
|
+
activeListeners: number;
|
|
91
|
+
messageRate: number;
|
|
92
|
+
};
|
|
93
|
+
clearQueue(): this;
|
|
39
94
|
}
|