crosstalk-comments-livechat-sdk 0.0.1 → 0.0.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.
|
@@ -3,7 +3,9 @@ export declare class CrossTalkCommentsEmbed {
|
|
|
3
3
|
private container;
|
|
4
4
|
private config;
|
|
5
5
|
private iframe;
|
|
6
|
+
private messageHandler;
|
|
6
7
|
constructor(container: HTMLElement, config: CommentsEmbedOptions);
|
|
8
|
+
private setupMessageListener;
|
|
7
9
|
render(): void;
|
|
8
10
|
update(config: Partial<CommentsEmbedOptions>): void;
|
|
9
11
|
destroy(): void;
|
|
@@ -17,8 +17,32 @@ export class CrossTalkCommentsEmbed {
|
|
|
17
17
|
this.container = container;
|
|
18
18
|
this.config = config;
|
|
19
19
|
this.iframe = null;
|
|
20
|
+
this.messageHandler = null;
|
|
20
21
|
this.render();
|
|
21
22
|
}
|
|
23
|
+
setupMessageListener() {
|
|
24
|
+
// Remove existing listener if any
|
|
25
|
+
if (this.messageHandler) {
|
|
26
|
+
window.removeEventListener('message', this.messageHandler);
|
|
27
|
+
}
|
|
28
|
+
this.messageHandler = (event) => {
|
|
29
|
+
// Basic security check - verify the message is from our iframe
|
|
30
|
+
if (this.iframe && event.source !== this.iframe.contentWindow) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (event.origin.includes('.crosstalk.cc')) {
|
|
34
|
+
try {
|
|
35
|
+
const msg = JSON.parse(event.data);
|
|
36
|
+
if (msg.csize)
|
|
37
|
+
this.iframe.style.height = `${msg.csize}px`;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.warn('Invalid message received:', error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
window.addEventListener('message', this.messageHandler);
|
|
45
|
+
}
|
|
22
46
|
render() {
|
|
23
47
|
this.container.innerHTML = '';
|
|
24
48
|
this.iframe = document.createElement('iframe');
|
|
@@ -29,12 +53,17 @@ export class CrossTalkCommentsEmbed {
|
|
|
29
53
|
this.iframe.sandbox = "allow-storage-access-by-user-activation allow-scripts allow-same-origin allow-popups";
|
|
30
54
|
this.iframe.scrolling = "no";
|
|
31
55
|
this.container.appendChild(this.iframe);
|
|
56
|
+
this.setupMessageListener();
|
|
32
57
|
}
|
|
33
58
|
update(config) {
|
|
34
59
|
this.config = Object.assign(Object.assign({}, this.config), config);
|
|
35
60
|
this.render();
|
|
36
61
|
}
|
|
37
62
|
destroy() {
|
|
63
|
+
if (this.messageHandler) {
|
|
64
|
+
window.removeEventListener('message', this.messageHandler);
|
|
65
|
+
this.messageHandler = null;
|
|
66
|
+
}
|
|
38
67
|
if (this.iframe && this.iframe.parentNode) {
|
|
39
68
|
this.iframe.parentNode.removeChild(this.iframe);
|
|
40
69
|
this.iframe = null;
|
|
@@ -3,7 +3,9 @@ export declare class CrossTalkVideoPlayerEmbed {
|
|
|
3
3
|
private container;
|
|
4
4
|
private config;
|
|
5
5
|
private iframe;
|
|
6
|
+
private messageHandler;
|
|
6
7
|
constructor(container: HTMLElement, config: VideoPlayerEmbedOptions);
|
|
8
|
+
private setupMessageListener;
|
|
7
9
|
render(): void;
|
|
8
10
|
update(config: Partial<VideoPlayerEmbedOptions>): void;
|
|
9
11
|
destroy(): void;
|
|
@@ -29,8 +29,32 @@ export class CrossTalkVideoPlayerEmbed {
|
|
|
29
29
|
this.container = container;
|
|
30
30
|
this.config = config;
|
|
31
31
|
this.iframe = null;
|
|
32
|
+
this.messageHandler = null;
|
|
32
33
|
this.render();
|
|
33
34
|
}
|
|
35
|
+
setupMessageListener() {
|
|
36
|
+
// Remove existing listener if any
|
|
37
|
+
if (this.messageHandler) {
|
|
38
|
+
window.removeEventListener('message', this.messageHandler);
|
|
39
|
+
}
|
|
40
|
+
this.messageHandler = (event) => {
|
|
41
|
+
// Basic security check - verify the message is from our iframe
|
|
42
|
+
if (this.iframe && event.source !== this.iframe.contentWindow) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (event.origin.includes('.crosstalk.cc')) {
|
|
46
|
+
try {
|
|
47
|
+
const msg = JSON.parse(event.data);
|
|
48
|
+
if (msg.vsize)
|
|
49
|
+
this.iframe.style.height = `${msg.vsize}px`;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
console.warn('Invalid message received:', error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
window.addEventListener('message', this.messageHandler);
|
|
57
|
+
}
|
|
34
58
|
render() {
|
|
35
59
|
this.container.innerHTML = '';
|
|
36
60
|
this.iframe = document.createElement('iframe');
|
|
@@ -41,13 +65,17 @@ export class CrossTalkVideoPlayerEmbed {
|
|
|
41
65
|
this.iframe.sandbox = "allow-storage-access-by-user-activation allow-scripts allow-same-origin allow-popups";
|
|
42
66
|
this.iframe.scrolling = "auto";
|
|
43
67
|
this.container.appendChild(this.iframe);
|
|
44
|
-
this.
|
|
68
|
+
this.setupMessageListener();
|
|
45
69
|
}
|
|
46
70
|
update(config) {
|
|
47
71
|
this.config = Object.assign(Object.assign({}, this.config), config);
|
|
48
72
|
this.render();
|
|
49
73
|
}
|
|
50
74
|
destroy() {
|
|
75
|
+
if (this.messageHandler) {
|
|
76
|
+
window.removeEventListener('message', this.messageHandler);
|
|
77
|
+
this.messageHandler = null;
|
|
78
|
+
}
|
|
51
79
|
if (this.iframe && this.iframe.parentNode) {
|
|
52
80
|
this.iframe.parentNode.removeChild(this.iframe);
|
|
53
81
|
this.iframe = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crosstalk-comments-livechat-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Add Comments, Live Chat, and Video Player Embeds to your website with CrossTalk Comments and Live Chat!",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"build": "tsc",
|
|
11
11
|
"prepublishOnly": "npm run build"
|
|
12
12
|
},
|
|
13
|
-
"keywords": ["
|
|
13
|
+
"keywords": ["comments", "live chat", "crosstalk", "hyvor talk", "audience Engagement", "disqus", "video player"],
|
|
14
14
|
"author": "CrossTalk Audience Engagement Platform",
|
|
15
15
|
"license": "ISC",
|
|
16
16
|
"devDependencies": {
|