crosstalk-comments-livechat-sdk 0.0.6-beta.1 → 0.0.6-beta.3
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/CrossTalkLiveChatEmbed.d.ts +0 -1
- package/dist/CrossTalkLiveChatEmbed.js +21 -21
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/types.d.ts +4 -1
- package/package.json +1 -1
|
@@ -7,16 +7,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
function buildIframeUrl(config) {
|
|
10
|
+
function buildIframeUrl(config, wp, theme) {
|
|
11
11
|
const baseUrl = 'https://widgets.crosstalk.cc/chat';
|
|
12
12
|
const params = new URLSearchParams();
|
|
13
|
-
params.append('wp',
|
|
13
|
+
params.append('wp', wp);
|
|
14
14
|
if (config.url)
|
|
15
15
|
params.append('url', config.url);
|
|
16
16
|
else if (config.pageID)
|
|
17
17
|
params.append('pageID', config.pageID);
|
|
18
|
-
if (
|
|
19
|
-
params.append('theme',
|
|
18
|
+
if (theme)
|
|
19
|
+
params.append('theme', theme);
|
|
20
20
|
return `${baseUrl}?${params.toString()}`;
|
|
21
21
|
}
|
|
22
22
|
function createHash(input) {
|
|
@@ -30,11 +30,11 @@ function createHash(input) {
|
|
|
30
30
|
}
|
|
31
31
|
return hash.toString(16);
|
|
32
32
|
}
|
|
33
|
-
function periodicChecks(obj, btnID, isEntity) {
|
|
33
|
+
function periodicChecks(obj, btnID, isEntity, wp) {
|
|
34
34
|
const btn = document.getElementById(btnID);
|
|
35
35
|
if (isEntity)
|
|
36
36
|
setInterval(() => {
|
|
37
|
-
fetch(`https://crosstalk.cc/api/chat/numberOfUsersForEntity?wpName=${
|
|
37
|
+
fetch(`https://crosstalk.cc/api/chat/numberOfUsersForEntity?wpName=${wp}&entity=${obj.pageID}`).then((v) => __awaiter(this, void 0, void 0, function* () {
|
|
38
38
|
if (v.ok) {
|
|
39
39
|
const data = yield v.json();
|
|
40
40
|
btn.innerHTML = `<b class='crosstalk_btnTxt'>(${data}) ${obj.title}</b>`;
|
|
@@ -43,7 +43,7 @@ function periodicChecks(obj, btnID, isEntity) {
|
|
|
43
43
|
}, 7000);
|
|
44
44
|
else
|
|
45
45
|
setInterval(() => {
|
|
46
|
-
fetch(`https://crosstalk.cc/api/chat/numberOfUsersForURL?wpName=${
|
|
46
|
+
fetch(`https://crosstalk.cc/api/chat/numberOfUsersForURL?wpName=${wp}&url=${obj.url}`).then((v) => __awaiter(this, void 0, void 0, function* () {
|
|
47
47
|
if (v.ok) {
|
|
48
48
|
const data = yield v.json();
|
|
49
49
|
btn.innerHTML = `<b class='crosstalk_btnTxt'>(${data}) ${obj.title}</b>`;
|
|
@@ -51,7 +51,7 @@ function periodicChecks(obj, btnID, isEntity) {
|
|
|
51
51
|
}));
|
|
52
52
|
}, 7000);
|
|
53
53
|
}
|
|
54
|
-
function newGChat(obj, parentDiv) {
|
|
54
|
+
function newGChat(obj, parentDiv, wp, theme) {
|
|
55
55
|
const chatHolder = document.createElement("div");
|
|
56
56
|
chatHolder.setAttribute("style", "margin-right: 5px");
|
|
57
57
|
let pageHash = "";
|
|
@@ -63,15 +63,15 @@ function newGChat(obj, parentDiv) {
|
|
|
63
63
|
else if (obj.url != null && obj.url != undefined && obj.url != "")
|
|
64
64
|
pageHash = createHash(obj.url);
|
|
65
65
|
const iframe = document.createElement("iframe");
|
|
66
|
-
const mainChatID = `id_${
|
|
66
|
+
const mainChatID = `id_${wp}_${pageHash}`;
|
|
67
67
|
iframe.id = mainChatID;
|
|
68
|
-
iframe.src = buildIframeUrl(obj);
|
|
68
|
+
iframe.src = buildIframeUrl(obj, wp, theme);
|
|
69
69
|
iframe.setAttribute("class", "crosstalk_frame");
|
|
70
70
|
iframe.sandbox = "allow-storage-access-by-user-activation allow-scripts allow-same-origin allow-popups";
|
|
71
71
|
iframe.setAttribute("scrolling", "auto");
|
|
72
72
|
chatHolder.appendChild(iframe);
|
|
73
73
|
const chatShowHideButton = document.createElement("span");
|
|
74
|
-
if (
|
|
74
|
+
if (theme == 'light')
|
|
75
75
|
chatShowHideButton.setAttribute("class", "crosstalk_btn");
|
|
76
76
|
else
|
|
77
77
|
chatShowHideButton.setAttribute("class", "crosstalk_btn dark");
|
|
@@ -81,7 +81,7 @@ function newGChat(obj, parentDiv) {
|
|
|
81
81
|
chatShowHideButton.appendChild(onlineSpan);
|
|
82
82
|
const buttonName = document.createElement("span");
|
|
83
83
|
buttonName.innerHTML = `<b class='crosstalk_btnTxt'>${obj.title}</b>`;
|
|
84
|
-
buttonName.id = `online_${
|
|
84
|
+
buttonName.id = `online_${wp}_${pageHash}`;
|
|
85
85
|
chatShowHideButton.onclick = function (ev) {
|
|
86
86
|
const mainIframe = document.getElementById(mainChatID);
|
|
87
87
|
if (mainIframe.style.display === "block") {
|
|
@@ -114,25 +114,25 @@ function newGChat(obj, parentDiv) {
|
|
|
114
114
|
chatShowHideButton.style.borderTopRightRadius = "5px";
|
|
115
115
|
}, 3000);
|
|
116
116
|
}
|
|
117
|
-
periodicChecks(obj, `online_${
|
|
117
|
+
periodicChecks(obj, `online_${wp}_${pageHash}`, isEntity, wp);
|
|
118
118
|
}
|
|
119
119
|
export class CrossTalkChatEmbed {
|
|
120
120
|
render() {
|
|
121
121
|
document.head.insertAdjacentHTML('beforebegin', '<link rel="stylesheet" href="https://widgets.crosstalk.cc/tab_livechat.css" />');
|
|
122
|
-
|
|
123
|
-
if (!
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
document.body.appendChild(
|
|
122
|
+
var parentDiv = document.getElementById("crosstalkChatHolder");
|
|
123
|
+
if (!parentDiv) {
|
|
124
|
+
parentDiv = document.createElement("div");
|
|
125
|
+
parentDiv.id = "crosstalkChatHolder";
|
|
126
|
+
document.body.appendChild(parentDiv);
|
|
127
127
|
}
|
|
128
|
+
if (!this.config.theme)
|
|
129
|
+
this.config.theme = "light";
|
|
128
130
|
this.config.pageIDs.forEach(pageID => {
|
|
129
|
-
pageID
|
|
130
|
-
newGChat(pageID, this.parentDiv);
|
|
131
|
+
newGChat(pageID, parentDiv, this.config.wp, this.config.theme);
|
|
131
132
|
});
|
|
132
133
|
}
|
|
133
134
|
constructor(config) {
|
|
134
135
|
this.config = config;
|
|
135
|
-
this.parentDiv = undefined;
|
|
136
136
|
this.render();
|
|
137
137
|
}
|
|
138
138
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export { CrossTalkCommentsEmbed, initComments } from './CrossTalkCommentsEmbed';
|
|
|
2
2
|
export { CrossTalkVideoPlayerEmbed, initPlayer } from './CrossTalkVideoPlayerEmbed';
|
|
3
3
|
export { CrossTalkPollEmbed, initPoll } from './CrossTalkPollEmbed';
|
|
4
4
|
export { CrossTalkAISummaryEmbed, initAISummary } from './CrossTalkAISummaryEmbed';
|
|
5
|
-
export
|
|
5
|
+
export { CrossTalkChatEmbed, initChats } from './CrossTalkLiveChatEmbed';
|
|
6
|
+
export type { CommentsEmbedOptions, VideoPlayerEmbedOptions, PollEmbedOptions, AISummaryOptions, ChatOptions, ChatPageOptions } from './types';
|
package/dist/index.js
CHANGED
|
@@ -3,3 +3,4 @@ export { CrossTalkCommentsEmbed, initComments } from './CrossTalkCommentsEmbed';
|
|
|
3
3
|
export { CrossTalkVideoPlayerEmbed, initPlayer } from './CrossTalkVideoPlayerEmbed';
|
|
4
4
|
export { CrossTalkPollEmbed, initPoll } from './CrossTalkPollEmbed';
|
|
5
5
|
export { CrossTalkAISummaryEmbed, initAISummary } from './CrossTalkAISummaryEmbed';
|
|
6
|
+
export { CrossTalkChatEmbed, initChats } from './CrossTalkLiveChatEmbed';
|
package/dist/types.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ interface BaseOptions {
|
|
|
4
4
|
pageID?: string;
|
|
5
5
|
theme?: string;
|
|
6
6
|
}
|
|
7
|
-
export interface ChatPageOptions
|
|
7
|
+
export interface ChatPageOptions {
|
|
8
|
+
url?: string;
|
|
9
|
+
pageID?: string;
|
|
8
10
|
collapsed?: boolean;
|
|
9
11
|
title?: string;
|
|
10
12
|
}
|
|
@@ -29,6 +31,7 @@ export interface AISummaryOptions {
|
|
|
29
31
|
theme?: string;
|
|
30
32
|
}
|
|
31
33
|
export interface ChatOptions {
|
|
34
|
+
wp?: string;
|
|
32
35
|
theme?: string;
|
|
33
36
|
pageIDs?: ChatPageOptions[];
|
|
34
37
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crosstalk-comments-livechat-sdk",
|
|
3
|
-
"version": "0.0.6-beta.
|
|
3
|
+
"version": "0.0.6-beta.3",
|
|
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",
|