iframe.io 0.0.9 → 0.0.10
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 +40 -0
- package/dist/index.js +13 -13
- package/package.json +2 -2
- package/src/index.ts +32 -11
- package/src/types/index.d.ts +0 -52
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare type PeerType = 'WINDOW' | 'IFRAME';
|
|
2
|
+
export declare type CallbackFunction = (error: boolean | string, ...args: any[]) => void;
|
|
3
|
+
export declare type Listener = (payload?: any, callback?: CallbackFunction) => void;
|
|
4
|
+
export declare type Options = {
|
|
5
|
+
type?: PeerType;
|
|
6
|
+
debug?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export interface RegisteredEvents {
|
|
9
|
+
[index: string]: Listener[];
|
|
10
|
+
}
|
|
11
|
+
export declare type Peer = {
|
|
12
|
+
type: PeerType;
|
|
13
|
+
source?: Window;
|
|
14
|
+
origin?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare type MessageData = {
|
|
17
|
+
_event: string;
|
|
18
|
+
payload: any;
|
|
19
|
+
callback: boolean;
|
|
20
|
+
};
|
|
21
|
+
export declare type Message = {
|
|
22
|
+
origin: string;
|
|
23
|
+
data: MessageData;
|
|
24
|
+
source: Window;
|
|
25
|
+
};
|
|
26
|
+
export default class IOF {
|
|
27
|
+
Events: RegisteredEvents;
|
|
28
|
+
peer: Peer;
|
|
29
|
+
options: Options;
|
|
30
|
+
constructor(options: Options);
|
|
31
|
+
debug(...args: any[]): void;
|
|
32
|
+
initiate(contentWindow: MessageEventSource, iframeOrigin: string): this;
|
|
33
|
+
listen(hostOrigin?: string): this;
|
|
34
|
+
fire(_event: string, payload?: MessageData['payload'], callback?: boolean): void;
|
|
35
|
+
emit(_event: string, payload?: MessageData['payload'], fn?: Listener): this;
|
|
36
|
+
on(_event: string, fn: Listener): this;
|
|
37
|
+
once(_event: string, fn: Listener): this;
|
|
38
|
+
off(_event: string, fn: Listener): this;
|
|
39
|
+
removeListeners(fn: Listener): this;
|
|
40
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -23,8 +23,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
23
23
|
function newObject(data) {
|
|
24
24
|
return JSON.parse(JSON.stringify(data));
|
|
25
25
|
}
|
|
26
|
-
var
|
|
27
|
-
function
|
|
26
|
+
var IOF = /** @class */ (function () {
|
|
27
|
+
function IOF(options) {
|
|
28
28
|
if (options && typeof options !== 'object')
|
|
29
29
|
throw new Error('Invalid Options');
|
|
30
30
|
this.options = options;
|
|
@@ -33,14 +33,14 @@ var IFrameIO = /** @class */ (function () {
|
|
|
33
33
|
if (options.type)
|
|
34
34
|
this.peer.type = options.type.toUpperCase();
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
IOF.prototype.debug = function () {
|
|
37
37
|
var args = [];
|
|
38
38
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
39
39
|
args[_i] = arguments[_i];
|
|
40
40
|
}
|
|
41
41
|
this.options && this.options.debug && console.log.apply(console, args);
|
|
42
42
|
};
|
|
43
|
-
|
|
43
|
+
IOF.prototype.initiate = function (contentWindow, iframeOrigin) {
|
|
44
44
|
var _this = this;
|
|
45
45
|
// Establish a connection with an iframe containing in the current window
|
|
46
46
|
if (!contentWindow || !iframeOrigin)
|
|
@@ -72,7 +72,7 @@ var IFrameIO = /** @class */ (function () {
|
|
|
72
72
|
this.emit('ping');
|
|
73
73
|
return this;
|
|
74
74
|
};
|
|
75
|
-
|
|
75
|
+
IOF.prototype.listen = function (hostOrigin) {
|
|
76
76
|
// Listening to connection from the content window
|
|
77
77
|
var _this = this;
|
|
78
78
|
this.peer.type = 'IFRAME'; // iframe.io connection listener is automatically set as IFRAME
|
|
@@ -109,7 +109,7 @@ var IFrameIO = /** @class */ (function () {
|
|
|
109
109
|
}, false);
|
|
110
110
|
return this;
|
|
111
111
|
};
|
|
112
|
-
|
|
112
|
+
IOF.prototype.fire = function (_event, payload, callback) {
|
|
113
113
|
var _this = this;
|
|
114
114
|
// Volatile event
|
|
115
115
|
if (!this.Events[_event]
|
|
@@ -137,7 +137,7 @@ var IFrameIO = /** @class */ (function () {
|
|
|
137
137
|
// Fire listeners
|
|
138
138
|
listeners.map(function (fn) { return payload ? fn(payload, callbackFn) : fn(callbackFn); });
|
|
139
139
|
};
|
|
140
|
-
|
|
140
|
+
IOF.prototype.emit = function (_event, payload, fn) {
|
|
141
141
|
if (!this.peer.source)
|
|
142
142
|
throw new Error('No Connection initiated');
|
|
143
143
|
if (typeof payload == 'function') {
|
|
@@ -157,7 +157,7 @@ var IFrameIO = /** @class */ (function () {
|
|
|
157
157
|
this.peer.source.postMessage(newObject({ _event: _event, payload: payload, callback: hasCallback }), this.peer.origin);
|
|
158
158
|
return this;
|
|
159
159
|
};
|
|
160
|
-
|
|
160
|
+
IOF.prototype.on = function (_event, fn) {
|
|
161
161
|
// Add Event listener
|
|
162
162
|
if (!this.Events[_event])
|
|
163
163
|
this.Events[_event] = [];
|
|
@@ -165,7 +165,7 @@ var IFrameIO = /** @class */ (function () {
|
|
|
165
165
|
this.debug("[".concat(this.peer.type, "] New <").concat(_event, "> listener on"));
|
|
166
166
|
return this;
|
|
167
167
|
};
|
|
168
|
-
|
|
168
|
+
IOF.prototype.once = function (_event, fn) {
|
|
169
169
|
// Add Once Event listener
|
|
170
170
|
_event += '--@once';
|
|
171
171
|
if (!this.Events[_event])
|
|
@@ -174,20 +174,20 @@ var IFrameIO = /** @class */ (function () {
|
|
|
174
174
|
this.debug("[".concat(this.peer.type, "] New <").concat(_event, " once> listener on"));
|
|
175
175
|
return this;
|
|
176
176
|
};
|
|
177
|
-
|
|
177
|
+
IOF.prototype.off = function (_event, fn) {
|
|
178
178
|
// Remove Event listener
|
|
179
179
|
delete this.Events[_event];
|
|
180
180
|
typeof fn == 'function' && fn();
|
|
181
181
|
this.debug("[".concat(this.peer.type, "] <").concat(_event, "> listener off"));
|
|
182
182
|
return this;
|
|
183
183
|
};
|
|
184
|
-
|
|
184
|
+
IOF.prototype.removeListeners = function (fn) {
|
|
185
185
|
// Clear all event listeners
|
|
186
186
|
this.Events = {};
|
|
187
187
|
typeof fn == 'function' && fn();
|
|
188
188
|
this.debug("[".concat(this.peer.type, "] All listeners removed"));
|
|
189
189
|
return this;
|
|
190
190
|
};
|
|
191
|
-
return
|
|
191
|
+
return IOF;
|
|
192
192
|
}());
|
|
193
|
-
exports.default =
|
|
193
|
+
exports.default = IOF;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iframe.io",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "Easy and friendly API to connect and interact between content window and its containing iframe",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
|
-
"types": "./
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
7
|
"private": false,
|
|
8
8
|
"scripts": {
|
|
9
9
|
"compile": "rimraf ./dist && tsc",
|
package/src/index.ts
CHANGED
|
@@ -1,20 +1,41 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
export type PeerType = 'WINDOW' | 'IFRAME'
|
|
3
|
+
|
|
4
|
+
export type CallbackFunction = ( error: boolean | string, ...args: any[] ) => void
|
|
5
|
+
export type Listener = ( payload?: any, callback?: CallbackFunction ) => void
|
|
6
|
+
|
|
7
|
+
export type Options = {
|
|
8
|
+
type?: PeerType
|
|
9
|
+
debug?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface RegisteredEvents {
|
|
13
|
+
[index: string]: Listener[]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type Peer = {
|
|
17
|
+
type: PeerType
|
|
18
|
+
source?: Window
|
|
19
|
+
origin?: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type MessageData = {
|
|
23
|
+
_event: string
|
|
24
|
+
payload: any
|
|
25
|
+
callback: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type Message = {
|
|
29
|
+
origin: string
|
|
30
|
+
data: MessageData,
|
|
31
|
+
source: Window
|
|
32
|
+
}
|
|
12
33
|
|
|
13
34
|
function newObject( data: object ){
|
|
14
35
|
return JSON.parse( JSON.stringify( data ) )
|
|
15
36
|
}
|
|
16
37
|
|
|
17
|
-
export default class
|
|
38
|
+
export default class IOF {
|
|
18
39
|
|
|
19
40
|
Events: RegisteredEvents
|
|
20
41
|
peer: Peer
|
package/src/types/index.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export type * as IFrameIOTop from '..'
|
|
3
|
-
|
|
4
|
-
export type PeerType = 'WINDOW' | 'IFRAME'
|
|
5
|
-
|
|
6
|
-
export type CallbackFunction = ( error: boolean | string, ...args: any[] ) => void
|
|
7
|
-
export type Listener = ( payload?: any, callback?: CallbackFunction ) => void
|
|
8
|
-
|
|
9
|
-
export type Options = {
|
|
10
|
-
type?: PeerType
|
|
11
|
-
debug?: boolean
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface RegisteredEvents {
|
|
15
|
-
[index: string]: Listener[]
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type Peer = {
|
|
19
|
-
type: PeerType
|
|
20
|
-
source?: Window
|
|
21
|
-
origin?: string
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type MessageData = {
|
|
25
|
-
_event: string
|
|
26
|
-
payload: any
|
|
27
|
-
callback: boolean
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type Message = {
|
|
31
|
-
origin: string
|
|
32
|
-
data: MessageData,
|
|
33
|
-
source: Window
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export interface IFrameIOClass {
|
|
38
|
-
Events: RegisteredEvents
|
|
39
|
-
peer: Peer
|
|
40
|
-
options: Options
|
|
41
|
-
|
|
42
|
-
// constructor: ( options: Options ) => void
|
|
43
|
-
debug: ( ...args: any[] ) => void
|
|
44
|
-
initiate: ( contentWindow: MessageEventSource, iframeOrigin: string ) => this
|
|
45
|
-
listen: ( hostOrigin?: string ) => this
|
|
46
|
-
fire: ( _event: string, payload?: MessageData['payload'], callback?: boolean ) => void
|
|
47
|
-
emit: ( _event: string, payload?: MessageData['payload'], fn?: Listener ) => void
|
|
48
|
-
on: ( _event: string, fn: Listener ) => void
|
|
49
|
-
once: ( _event: string, fn: Listener ) => void
|
|
50
|
-
off: ( _event: string, fn: Listener ) => void
|
|
51
|
-
removeListeners: ( fn: Listener ) => void
|
|
52
|
-
}
|