@telperion/messenger 7.6.1 → 7.6.2
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/iframe/iframe.type.d.ts +1 -1
- package/iframe/iframe.type.js.map +1 -1
- package/iframe/message-client.cjs +10 -8
- package/iframe/message-client.d.ts +5 -1
- package/iframe/message-client.js +10 -8
- package/iframe/message-client.js.map +1 -1
- package/iframe/message-host.cjs +19 -15
- package/iframe/message-host.d.ts +9 -0
- package/iframe/message-host.js +19 -15
- package/iframe/message-host.js.map +1 -1
- package/iframe/message-service.d.ts +1 -1
- package/package.json +1 -1
package/iframe/iframe.type.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type IFrame = HTMLIFrameElement | (() => HTMLIFrameElement);
|
|
1
|
+
export type IFrame = HTMLIFrameElement | (() => HTMLIFrameElement | undefined) | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../libs/messenger/src/iframe/iframe.type.ts"],"names":[],"mappings":"","file":"iframe.type.js","sourcesContent":["export type IFrame = HTMLIFrameElement | (() => HTMLIFrameElement)
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/messenger/src/iframe/iframe.type.ts"],"names":[],"mappings":"","file":"iframe.type.js","sourcesContent":["export type IFrame = HTMLIFrameElement | (() => HTMLIFrameElement | undefined) | undefined;\r\n"]}
|
|
@@ -7,21 +7,23 @@ const message_client_1 = require("../message-client");
|
|
|
7
7
|
const selectors_1 = require("../selectors");
|
|
8
8
|
const channel_path_splitter_1 = require("./channel-path-splitter");
|
|
9
9
|
const default_channel_name_1 = require("./default-channel-name");
|
|
10
|
+
const TARGET_FRAME = Symbol('IframeMessageClient Target Frame');
|
|
11
|
+
const OPTION_TARGET_FRAME = Symbol('IframeMessageClient Option Target Frame');
|
|
10
12
|
class IframeMessageClient extends message_client_1.MessageClient {
|
|
11
13
|
channelName;
|
|
12
14
|
[selectors_1.RESPONSES$] = new rxjs_1.Subject();
|
|
13
|
-
|
|
14
|
-
get
|
|
15
|
-
return typeof this
|
|
16
|
-
? this
|
|
17
|
-
: this
|
|
15
|
+
[OPTION_TARGET_FRAME];
|
|
16
|
+
get [TARGET_FRAME]() {
|
|
17
|
+
return typeof this[OPTION_TARGET_FRAME] === 'function'
|
|
18
|
+
? this[OPTION_TARGET_FRAME]() ?? null
|
|
19
|
+
: this[OPTION_TARGET_FRAME] ?? null;
|
|
18
20
|
}
|
|
19
21
|
constructor(channelName = default_channel_name_1.DEFAULT_CHANNEL_NAME, targetFrame) {
|
|
20
22
|
super();
|
|
21
23
|
this.channelName = channelName;
|
|
22
|
-
this
|
|
24
|
+
this[OPTION_TARGET_FRAME] = targetFrame;
|
|
23
25
|
window.addEventListener('message', ({ data, source }) => {
|
|
24
|
-
const target = this
|
|
26
|
+
const target = this[TARGET_FRAME];
|
|
25
27
|
if (target && source !== target.contentWindow)
|
|
26
28
|
return;
|
|
27
29
|
if (!data
|
|
@@ -35,7 +37,7 @@ class IframeMessageClient extends message_client_1.MessageClient {
|
|
|
35
37
|
}
|
|
36
38
|
[selectors_1.SEND](message) {
|
|
37
39
|
message = { ...message, path: `${this.channelName}${channel_path_splitter_1.CHANNEL_PATH_SPLITTER}${message.path}` };
|
|
38
|
-
const target = this
|
|
40
|
+
const target = this[TARGET_FRAME];
|
|
39
41
|
if (target) {
|
|
40
42
|
target.contentWindow.postMessage(message, '*');
|
|
41
43
|
}
|
|
@@ -4,11 +4,15 @@ import { MessageResponse } from '../message-response.type';
|
|
|
4
4
|
import { Message } from '../message.interface';
|
|
5
5
|
import { GET_NEW_ID, RESPONSES$, SEND } from '../selectors';
|
|
6
6
|
import { IFrame } from './iframe.type';
|
|
7
|
+
declare const TARGET_FRAME: unique symbol;
|
|
8
|
+
declare const OPTION_TARGET_FRAME: unique symbol;
|
|
7
9
|
export declare class IframeMessageClient extends MessageClient {
|
|
8
|
-
#private;
|
|
9
10
|
private channelName;
|
|
10
11
|
[RESPONSES$]: Subject<MessageResponse>;
|
|
12
|
+
private [OPTION_TARGET_FRAME];
|
|
13
|
+
private get [TARGET_FRAME]();
|
|
11
14
|
constructor(channelName?: string, targetFrame?: IFrame);
|
|
12
15
|
[SEND]<T>(message: Message<T>): void;
|
|
13
16
|
protected [GET_NEW_ID](): string;
|
|
14
17
|
}
|
|
18
|
+
export {};
|
package/iframe/message-client.js
CHANGED
|
@@ -4,21 +4,23 @@ import { MessageClient } from '../message-client';
|
|
|
4
4
|
import { GET_NEW_ID, RESPONSES$, SEND } from '../selectors';
|
|
5
5
|
import { CHANNEL_PATH_SPLITTER } from './channel-path-splitter';
|
|
6
6
|
import { DEFAULT_CHANNEL_NAME } from './default-channel-name';
|
|
7
|
+
const TARGET_FRAME = Symbol('IframeMessageClient Target Frame');
|
|
8
|
+
const OPTION_TARGET_FRAME = Symbol('IframeMessageClient Option Target Frame');
|
|
7
9
|
export class IframeMessageClient extends MessageClient {
|
|
8
10
|
channelName;
|
|
9
11
|
[RESPONSES$] = new Subject();
|
|
10
|
-
|
|
11
|
-
get
|
|
12
|
-
return typeof this
|
|
13
|
-
? this
|
|
14
|
-
: this
|
|
12
|
+
[OPTION_TARGET_FRAME];
|
|
13
|
+
get [TARGET_FRAME]() {
|
|
14
|
+
return typeof this[OPTION_TARGET_FRAME] === 'function'
|
|
15
|
+
? this[OPTION_TARGET_FRAME]() ?? null
|
|
16
|
+
: this[OPTION_TARGET_FRAME] ?? null;
|
|
15
17
|
}
|
|
16
18
|
constructor(channelName = DEFAULT_CHANNEL_NAME, targetFrame) {
|
|
17
19
|
super();
|
|
18
20
|
this.channelName = channelName;
|
|
19
|
-
this
|
|
21
|
+
this[OPTION_TARGET_FRAME] = targetFrame;
|
|
20
22
|
window.addEventListener('message', ({ data, source }) => {
|
|
21
|
-
const target = this
|
|
23
|
+
const target = this[TARGET_FRAME];
|
|
22
24
|
if (target && source !== target.contentWindow)
|
|
23
25
|
return;
|
|
24
26
|
if (!data
|
|
@@ -32,7 +34,7 @@ export class IframeMessageClient extends MessageClient {
|
|
|
32
34
|
}
|
|
33
35
|
[SEND](message) {
|
|
34
36
|
message = { ...message, path: `${this.channelName}${CHANNEL_PATH_SPLITTER}${message.path}` };
|
|
35
|
-
const target = this
|
|
37
|
+
const target = this[TARGET_FRAME];
|
|
36
38
|
if (target) {
|
|
37
39
|
target.contentWindow.postMessage(message, '*');
|
|
38
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../libs/messenger/src/iframe/message-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,MAAM,OAAO,mBAAoB,SAAQ,aAAa;IAW1C;IAVH,CAAC,UAAU,CAAC,GAAG,IAAI,OAAO,EAAmB,CAAC;
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/messenger/src/iframe/message-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,MAAM,YAAY,GAAG,MAAM,CAAC,kCAAkC,CAAC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,EAAE,EAAE,CAAC;QAE7F,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;QAElC,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,CAAC,aAAc,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAClD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IAES,CAAC,UAAU,CAAC;QACpB,OAAO,QAAQ,CAAC,0BAA0B,CAAW,CAAC;IACxD,CAAC;CACF","file":"message-client.js","sourcesContent":["import { uniqueId } from '@telperion/js-utils';\nimport { Subject } from 'rxjs';\nimport { MessageClient } from '../message-client';\nimport { MessageResponse, SuccessfulMessageResponse } from '../message-response.type';\nimport { Message } from '../message.interface';\nimport { GET_NEW_ID, RESPONSES$, SEND } from '../selectors';\nimport { CHANNEL_PATH_SPLITTER } from './channel-path-splitter';\nimport { DEFAULT_CHANNEL_NAME } from './default-channel-name';\nimport { IFrame } from './iframe.type';\n\nconst TARGET_FRAME = Symbol('IframeMessageClient Target Frame');\nconst OPTION_TARGET_FRAME = Symbol('IframeMessageClient Option Target Frame');\n\nexport class IframeMessageClient extends MessageClient {\n public [RESPONSES$] = new Subject<MessageResponse>();\n private [OPTION_TARGET_FRAME]: IFrame;\n\n private get [TARGET_FRAME](): null | HTMLIFrameElement {\n return typeof this[OPTION_TARGET_FRAME] === 'function'\n ? (this[OPTION_TARGET_FRAME] as () => HTMLIFrameElement | undefined)() ?? null\n : this[OPTION_TARGET_FRAME] as HTMLIFrameElement ?? null;\n }\n\n constructor(\n private channelName = DEFAULT_CHANNEL_NAME,\n targetFrame?: IFrame\n ) {\n super();\n\n this[OPTION_TARGET_FRAME] = targetFrame;\n\n window.addEventListener('message', ({ data, source }: MessageEvent<SuccessfulMessageResponse>) => {\n const target = this[TARGET_FRAME];\n\n if (target && source !== target.contentWindow) return;\n\n if (!data\n || typeof data !== 'object'\n || typeof data.id === 'undefined'\n || typeof data.completed === 'undefined'\n ) {\n return;\n }\n\n this[RESPONSES$].next(data);\n });\n }\n\n public [SEND]<T>(message: Message<T>) {\n message = { ...message, path: `${this.channelName}${CHANNEL_PATH_SPLITTER}${message.path}` };\n\n const target = this[TARGET_FRAME];\n\n if (target) {\n target.contentWindow!.postMessage(message, '*');\n } else {\n window.parent.postMessage(message, '*');\n }\n }\n\n protected [GET_NEW_ID](): string {\n return uniqueId('messenger-iframe-message') as string;\n }\n}\n"]}
|
package/iframe/message-host.cjs
CHANGED
|
@@ -8,29 +8,33 @@ const channel_path_splitter_1 = require("./channel-path-splitter");
|
|
|
8
8
|
const default_channel_name_1 = require("./default-channel-name");
|
|
9
9
|
const source_id_splitter_1 = require("./source-id-splitter");
|
|
10
10
|
const selectors_1 = require("../selectors");
|
|
11
|
+
const OPTIONS_TARGET_FRAME = Symbol('IframeMessageHost Option Target Frame');
|
|
12
|
+
const TARGET_FRAME = Symbol('IframeMessageHost Target Frame');
|
|
13
|
+
const REQUESTS = Symbol('IframeMessageHost Requests');
|
|
14
|
+
const SOURCES = Symbol('IframeMessageHost Sources');
|
|
11
15
|
class IframeMessageHost extends message_host_1.MessageHost {
|
|
12
16
|
channelName;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
get
|
|
17
|
-
return typeof this
|
|
18
|
-
? this
|
|
19
|
-
: this
|
|
17
|
+
[REQUESTS] = new rxjs_1.Subject();
|
|
18
|
+
[SOURCES] = [];
|
|
19
|
+
[OPTIONS_TARGET_FRAME] = undefined;
|
|
20
|
+
get [TARGET_FRAME]() {
|
|
21
|
+
return typeof this[OPTIONS_TARGET_FRAME] === 'function'
|
|
22
|
+
? this[OPTIONS_TARGET_FRAME]() ?? null
|
|
23
|
+
: this[OPTIONS_TARGET_FRAME] ?? null;
|
|
20
24
|
}
|
|
21
25
|
constructor(channelName = default_channel_name_1.DEFAULT_CHANNEL_NAME, targetFrame) {
|
|
22
26
|
super();
|
|
23
27
|
this.channelName = channelName;
|
|
24
|
-
this
|
|
28
|
+
this[OPTIONS_TARGET_FRAME] = targetFrame;
|
|
25
29
|
window.addEventListener('message', this.#handler);
|
|
26
|
-
this[selectors_1.LISTEN](this
|
|
30
|
+
this[selectors_1.LISTEN](this[REQUESTS]);
|
|
27
31
|
}
|
|
28
32
|
terminate() {
|
|
29
33
|
window.removeEventListener('message', this.#handler);
|
|
30
34
|
}
|
|
31
35
|
[selectors_1.RESPONSE](message) {
|
|
32
36
|
const [sourceId, messageId] = message.id.split(source_id_splitter_1.SOURCE_ID_SPLITTER);
|
|
33
|
-
const [, source] = this
|
|
37
|
+
const [, source] = this[SOURCES].find(([sId]) => sId === sourceId);
|
|
34
38
|
message = {
|
|
35
39
|
...message,
|
|
36
40
|
id: messageId,
|
|
@@ -41,7 +45,7 @@ class IframeMessageHost extends message_host_1.MessageHost {
|
|
|
41
45
|
if (!data || typeof data !== 'object' || !data.path || typeof data.id === 'undefined') {
|
|
42
46
|
return;
|
|
43
47
|
}
|
|
44
|
-
const targetFrame = this
|
|
48
|
+
const targetFrame = this[TARGET_FRAME];
|
|
45
49
|
if (targetFrame && targetFrame.contentWindow !== source) {
|
|
46
50
|
return;
|
|
47
51
|
}
|
|
@@ -49,11 +53,11 @@ class IframeMessageHost extends message_host_1.MessageHost {
|
|
|
49
53
|
if (channel !== this.channelName) {
|
|
50
54
|
return;
|
|
51
55
|
}
|
|
52
|
-
if (!this
|
|
53
|
-
this
|
|
56
|
+
if (!this[SOURCES].some(([, s]) => s === source)) {
|
|
57
|
+
this[SOURCES].push([(0, js_utils_1.uniqueId)('messenger-iframe-source'), source]);
|
|
54
58
|
}
|
|
55
|
-
const [sourceId] = this
|
|
56
|
-
this
|
|
59
|
+
const [sourceId] = this[SOURCES].find(([, s]) => s === source);
|
|
60
|
+
this[REQUESTS].next({
|
|
57
61
|
body: targetFrame ? data.body : { data: data.body, sender: source },
|
|
58
62
|
id: `${sourceId}${source_id_splitter_1.SOURCE_ID_SPLITTER}${data.id}`,
|
|
59
63
|
path,
|
package/iframe/message-host.d.ts
CHANGED
|
@@ -2,10 +2,19 @@ import { MessageHost } from '../message-host';
|
|
|
2
2
|
import { SuccessfulMessageResponse } from '../message-response.type';
|
|
3
3
|
import { IFrame } from './iframe.type';
|
|
4
4
|
import { RESPONSE } from '../selectors';
|
|
5
|
+
declare const OPTIONS_TARGET_FRAME: unique symbol;
|
|
6
|
+
declare const TARGET_FRAME: unique symbol;
|
|
7
|
+
declare const REQUESTS: unique symbol;
|
|
8
|
+
declare const SOURCES: unique symbol;
|
|
5
9
|
export declare class IframeMessageHost extends MessageHost {
|
|
6
10
|
#private;
|
|
7
11
|
private channelName;
|
|
12
|
+
private [REQUESTS];
|
|
13
|
+
private [SOURCES];
|
|
14
|
+
private [OPTIONS_TARGET_FRAME];
|
|
15
|
+
private get [TARGET_FRAME]();
|
|
8
16
|
constructor(channelName?: string, targetFrame?: IFrame);
|
|
9
17
|
terminate(): void;
|
|
10
18
|
protected [RESPONSE](message: SuccessfulMessageResponse): void;
|
|
11
19
|
}
|
|
20
|
+
export {};
|
package/iframe/message-host.js
CHANGED
|
@@ -5,29 +5,33 @@ import { CHANNEL_PATH_SPLITTER } from './channel-path-splitter';
|
|
|
5
5
|
import { DEFAULT_CHANNEL_NAME } from './default-channel-name';
|
|
6
6
|
import { SOURCE_ID_SPLITTER } from './source-id-splitter';
|
|
7
7
|
import { LISTEN, RESPONSE } from '../selectors';
|
|
8
|
+
const OPTIONS_TARGET_FRAME = Symbol('IframeMessageHost Option Target Frame');
|
|
9
|
+
const TARGET_FRAME = Symbol('IframeMessageHost Target Frame');
|
|
10
|
+
const REQUESTS = Symbol('IframeMessageHost Requests');
|
|
11
|
+
const SOURCES = Symbol('IframeMessageHost Sources');
|
|
8
12
|
export class IframeMessageHost extends MessageHost {
|
|
9
13
|
channelName;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
get
|
|
14
|
-
return typeof this
|
|
15
|
-
? this
|
|
16
|
-
: this
|
|
14
|
+
[REQUESTS] = new Subject();
|
|
15
|
+
[SOURCES] = [];
|
|
16
|
+
[OPTIONS_TARGET_FRAME] = undefined;
|
|
17
|
+
get [TARGET_FRAME]() {
|
|
18
|
+
return typeof this[OPTIONS_TARGET_FRAME] === 'function'
|
|
19
|
+
? this[OPTIONS_TARGET_FRAME]() ?? null
|
|
20
|
+
: this[OPTIONS_TARGET_FRAME] ?? null;
|
|
17
21
|
}
|
|
18
22
|
constructor(channelName = DEFAULT_CHANNEL_NAME, targetFrame) {
|
|
19
23
|
super();
|
|
20
24
|
this.channelName = channelName;
|
|
21
|
-
this
|
|
25
|
+
this[OPTIONS_TARGET_FRAME] = targetFrame;
|
|
22
26
|
window.addEventListener('message', this.#handler);
|
|
23
|
-
this[LISTEN](this
|
|
27
|
+
this[LISTEN](this[REQUESTS]);
|
|
24
28
|
}
|
|
25
29
|
terminate() {
|
|
26
30
|
window.removeEventListener('message', this.#handler);
|
|
27
31
|
}
|
|
28
32
|
[RESPONSE](message) {
|
|
29
33
|
const [sourceId, messageId] = message.id.split(SOURCE_ID_SPLITTER);
|
|
30
|
-
const [, source] = this
|
|
34
|
+
const [, source] = this[SOURCES].find(([sId]) => sId === sourceId);
|
|
31
35
|
message = {
|
|
32
36
|
...message,
|
|
33
37
|
id: messageId,
|
|
@@ -38,7 +42,7 @@ export class IframeMessageHost extends MessageHost {
|
|
|
38
42
|
if (!data || typeof data !== 'object' || !data.path || typeof data.id === 'undefined') {
|
|
39
43
|
return;
|
|
40
44
|
}
|
|
41
|
-
const targetFrame = this
|
|
45
|
+
const targetFrame = this[TARGET_FRAME];
|
|
42
46
|
if (targetFrame && targetFrame.contentWindow !== source) {
|
|
43
47
|
return;
|
|
44
48
|
}
|
|
@@ -46,11 +50,11 @@ export class IframeMessageHost extends MessageHost {
|
|
|
46
50
|
if (channel !== this.channelName) {
|
|
47
51
|
return;
|
|
48
52
|
}
|
|
49
|
-
if (!this
|
|
50
|
-
this
|
|
53
|
+
if (!this[SOURCES].some(([, s]) => s === source)) {
|
|
54
|
+
this[SOURCES].push([uniqueId('messenger-iframe-source'), source]);
|
|
51
55
|
}
|
|
52
|
-
const [sourceId] = this
|
|
53
|
-
this
|
|
56
|
+
const [sourceId] = this[SOURCES].find(([, s]) => s === source);
|
|
57
|
+
this[REQUESTS].next({
|
|
54
58
|
body: targetFrame ? data.body : { data: data.body, sender: source },
|
|
55
59
|
id: `${sourceId}${SOURCE_ID_SPLITTER}${data.id}`,
|
|
56
60
|
path,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../libs/messenger/src/iframe/message-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,OAAO,iBAAkB,SAAQ,WAAW;IAYtC;
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/messenger/src/iframe/message-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,M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,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,MAAM,CAAE,CAAC;QAChE,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC;YAClB,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE;YACnE,EAAE,EAAE,GAAG,QAAQ,GAAG,kBAAkB,GAAG,IAAI,CAAC,EAAE,EAAE;YAChD,IAAI;SACL,CAAC,CAAC;IACL,CAAC,CAAC;CACH","file":"message-host.js","sourcesContent":["import { uniqueId } from '@telperion/js-utils';\nimport { Subject } from 'rxjs';\nimport { MessageHost } from '../message-host';\nimport { SuccessfulMessageResponse } from '../message-response.type';\nimport { Message } from '../message.interface';\nimport { CHANNEL_PATH_SPLITTER } from './channel-path-splitter';\nimport { DEFAULT_CHANNEL_NAME } from './default-channel-name';\nimport { SOURCE_ID_SPLITTER } from './source-id-splitter';\nimport { IFrame } from './iframe.type';\nimport { LISTEN, RESPONSE } from '../selectors';\n\nconst OPTIONS_TARGET_FRAME = Symbol('IframeMessageHost Option Target Frame');\nconst TARGET_FRAME = Symbol('IframeMessageHost Target Frame');\nconst REQUESTS = Symbol('IframeMessageHost Requests');\nconst SOURCES = Symbol('IframeMessageHost Sources');\n\nexport class IframeMessageHost extends MessageHost {\n private [REQUESTS] = new Subject<Message>();\n private [SOURCES]: Array<[string, MessageEventSource]> = [];\n private [OPTIONS_TARGET_FRAME]: IFrame = undefined;\n\n private get [TARGET_FRAME](): null | HTMLIFrameElement {\n return typeof this[OPTIONS_TARGET_FRAME] === 'function'\n ? (this[OPTIONS_TARGET_FRAME] as () => HTMLIFrameElement | undefined)() ?? null\n : this[OPTIONS_TARGET_FRAME] as HTMLIFrameElement ?? null;\n }\n\n constructor(\n private channelName = DEFAULT_CHANNEL_NAME,\n targetFrame?: IFrame\n ) {\n super();\n\n this[OPTIONS_TARGET_FRAME] = targetFrame;\n\n window.addEventListener('message', this.#handler);\n\n this[LISTEN](this[REQUESTS]);\n }\n\n public terminate(): void {\n window.removeEventListener('message', this.#handler);\n }\n\n protected [RESPONSE](message: SuccessfulMessageResponse): void {\n const [sourceId, messageId] = message.id.split(SOURCE_ID_SPLITTER);\n const [, source] = this[SOURCES].find(([sId]) => sId === sourceId)!;\n\n message = {\n ...message,\n id: messageId,\n };\n\n (source as any).postMessage(message);\n }\n\n #handler = ({ data, source }: MessageEvent<Message>) => {\n if (!data || typeof data !== 'object' || !data.path || typeof data.id === 'undefined') {\n return;\n }\n\n const targetFrame = this[TARGET_FRAME];\n\n if (targetFrame && targetFrame.contentWindow !== source) {\n return;\n }\n\n const [channel, path] = data.path.split(CHANNEL_PATH_SPLITTER);\n\n if (channel !== this.channelName) {\n return;\n }\n\n if (!this[SOURCES].some(([, s]) => s === source)) {\n this[SOURCES].push([uniqueId('messenger-iframe-source') as string, source!]);\n }\n\n const [sourceId] = this[SOURCES].find(([, s]) => s === source)!;\n this[REQUESTS].next({\n body: targetFrame ? data.body : { data: data.body, sender: source },\n id: `${sourceId}${SOURCE_ID_SPLITTER}${data.id}`,\n path,\n });\n };\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IframeMessageClient } from "./message-client";
|
|
2
2
|
import { IFrame } from "./iframe.type";
|
|
3
|
-
declare const IframeMessageService_base: new (args_0: [channelName?: string | undefined, targetFrame?: IFrame
|
|
3
|
+
declare const IframeMessageService_base: new (args_0: [channelName?: string | undefined, targetFrame?: IFrame], args_1: [channelName?: string | undefined, targetFrame?: IFrame]) => {
|
|
4
4
|
terminate: () => void;
|
|
5
5
|
} & IframeMessageClient;
|
|
6
6
|
export declare class IframeMessageService extends IframeMessageService_base {
|