crosstalk-comments-livechat-sdk 0.0.5-beta.3 → 0.0.6-beta.1

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.
@@ -1,4 +1,4 @@
1
- import { AISummaryOptions } from './types';
1
+ import type { AISummaryOptions } from './types';
2
2
  export declare class CrossTalkAISummaryEmbed {
3
3
  private container;
4
4
  private config;
@@ -1,4 +1,4 @@
1
- import { CommentsEmbedOptions } from './types';
1
+ import type { CommentsEmbedOptions } from './types';
2
2
  export declare class CrossTalkCommentsEmbed {
3
3
  private container;
4
4
  private config;
@@ -0,0 +1,8 @@
1
+ import type { ChatOptions } from './types';
2
+ export declare class CrossTalkChatEmbed {
3
+ private config;
4
+ parentDiv: HTMLElement;
5
+ render(): void;
6
+ constructor(config: ChatOptions);
7
+ }
8
+ export declare function initChats(config: ChatOptions): CrossTalkChatEmbed;
@@ -0,0 +1,141 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ function buildIframeUrl(config) {
11
+ const baseUrl = 'https://widgets.crosstalk.cc/chat';
12
+ const params = new URLSearchParams();
13
+ params.append('wp', config.wp);
14
+ if (config.url)
15
+ params.append('url', config.url);
16
+ else if (config.pageID)
17
+ params.append('pageID', config.pageID);
18
+ if (config.theme)
19
+ params.append('theme', config.theme);
20
+ return `${baseUrl}?${params.toString()}`;
21
+ }
22
+ function createHash(input) {
23
+ if (input.length === 0)
24
+ return "0";
25
+ let hash = 0;
26
+ for (let i = 0; i < input.length; i++) {
27
+ const char = input.charCodeAt(i);
28
+ hash = (hash << 5) - hash + char;
29
+ hash = hash & hash;
30
+ }
31
+ return hash.toString(16);
32
+ }
33
+ function periodicChecks(obj, btnID, isEntity) {
34
+ const btn = document.getElementById(btnID);
35
+ if (isEntity)
36
+ setInterval(() => {
37
+ fetch(`https://crosstalk.cc/api/chat/numberOfUsersForEntity?wpName=${obj.wp}&entity=${obj.pageID}`).then((v) => __awaiter(this, void 0, void 0, function* () {
38
+ if (v.ok) {
39
+ const data = yield v.json();
40
+ btn.innerHTML = `<b class='crosstalk_btnTxt'>(${data}) ${obj.title}</b>`;
41
+ }
42
+ }));
43
+ }, 7000);
44
+ else
45
+ setInterval(() => {
46
+ fetch(`https://crosstalk.cc/api/chat/numberOfUsersForURL?wpName=${obj.wp}&url=${obj.url}`).then((v) => __awaiter(this, void 0, void 0, function* () {
47
+ if (v.ok) {
48
+ const data = yield v.json();
49
+ btn.innerHTML = `<b class='crosstalk_btnTxt'>(${data}) ${obj.title}</b>`;
50
+ }
51
+ }));
52
+ }, 7000);
53
+ }
54
+ function newGChat(obj, parentDiv) {
55
+ const chatHolder = document.createElement("div");
56
+ chatHolder.setAttribute("style", "margin-right: 5px");
57
+ let pageHash = "";
58
+ let isEntity = false;
59
+ if (obj.pageID != null && obj.pageID != undefined && obj.pageID != "") {
60
+ isEntity = true;
61
+ pageHash = createHash(obj.pageID);
62
+ }
63
+ else if (obj.url != null && obj.url != undefined && obj.url != "")
64
+ pageHash = createHash(obj.url);
65
+ const iframe = document.createElement("iframe");
66
+ const mainChatID = `id_${obj.wp}_${pageHash}`;
67
+ iframe.id = mainChatID;
68
+ iframe.src = buildIframeUrl(obj);
69
+ iframe.setAttribute("class", "crosstalk_frame");
70
+ iframe.sandbox = "allow-storage-access-by-user-activation allow-scripts allow-same-origin allow-popups";
71
+ iframe.setAttribute("scrolling", "auto");
72
+ chatHolder.appendChild(iframe);
73
+ const chatShowHideButton = document.createElement("span");
74
+ if (obj.theme == 'light')
75
+ chatShowHideButton.setAttribute("class", "crosstalk_btn");
76
+ else
77
+ chatShowHideButton.setAttribute("class", "crosstalk_btn dark");
78
+ const onlineSpan = document.createElement("span");
79
+ onlineSpan.setAttribute("class", "crosstalk_online");
80
+ onlineSpan.innerText = "●";
81
+ chatShowHideButton.appendChild(onlineSpan);
82
+ const buttonName = document.createElement("span");
83
+ buttonName.innerHTML = `<b class='crosstalk_btnTxt'>${obj.title}</b>`;
84
+ buttonName.id = `online_${obj.wp}_${pageHash}`;
85
+ chatShowHideButton.onclick = function (ev) {
86
+ const mainIframe = document.getElementById(mainChatID);
87
+ if (mainIframe.style.display === "block") {
88
+ mainIframe.style.display = "none";
89
+ chatShowHideButton.style.width = "200px";
90
+ chatShowHideButton.style.borderTopLeftRadius = "5px";
91
+ chatShowHideButton.style.borderTopRightRadius = "5px";
92
+ }
93
+ else {
94
+ mainIframe.style.display = "block";
95
+ chatShowHideButton.style.width = "400px";
96
+ chatShowHideButton.style.borderTopLeftRadius = "0px";
97
+ chatShowHideButton.style.borderTopRightRadius = "0px";
98
+ }
99
+ };
100
+ chatShowHideButton.appendChild(buttonName);
101
+ chatShowHideButton.id = `button_${mainChatID}`;
102
+ chatHolder.appendChild(chatShowHideButton);
103
+ parentDiv.appendChild(chatHolder);
104
+ if (obj.collapsed == true) {
105
+ const mainIframe = document.getElementById(mainChatID);
106
+ mainIframe.style.visibility = "hidden";
107
+ mainIframe.style.pointerEvents = "none";
108
+ setTimeout(() => {
109
+ mainIframe.style.display = "none";
110
+ mainIframe.style.visibility = "visible";
111
+ mainIframe.style.pointerEvents = "auto";
112
+ chatShowHideButton.style.width = "200px";
113
+ chatShowHideButton.style.borderTopLeftRadius = "5px";
114
+ chatShowHideButton.style.borderTopRightRadius = "5px";
115
+ }, 3000);
116
+ }
117
+ periodicChecks(obj, `online_${obj.wp}_${pageHash}`, isEntity);
118
+ }
119
+ export class CrossTalkChatEmbed {
120
+ render() {
121
+ document.head.insertAdjacentHTML('beforebegin', '<link rel="stylesheet" href="https://widgets.crosstalk.cc/tab_livechat.css" />');
122
+ this.parentDiv = document.getElementById("crosstalkChatHolder");
123
+ if (!this.parentDiv) {
124
+ this.parentDiv = document.createElement("div");
125
+ this.parentDiv.id = "crosstalkChatHolder";
126
+ document.body.appendChild(this.parentDiv);
127
+ }
128
+ this.config.pageIDs.forEach(pageID => {
129
+ pageID.theme = this.config.theme;
130
+ newGChat(pageID, this.parentDiv);
131
+ });
132
+ }
133
+ constructor(config) {
134
+ this.config = config;
135
+ this.parentDiv = undefined;
136
+ this.render();
137
+ }
138
+ }
139
+ export function initChats(config) {
140
+ return new CrossTalkChatEmbed(config);
141
+ }
@@ -1,4 +1,4 @@
1
- import { PollEmbedOptions } from './types';
1
+ import type { PollEmbedOptions } from './types';
2
2
  export declare class CrossTalkPollEmbed {
3
3
  private container;
4
4
  private config;
@@ -1,4 +1,4 @@
1
- import { VideoPlayerEmbedOptions } from './types';
1
+ import type { VideoPlayerEmbedOptions } from './types';
2
2
  export declare class CrossTalkVideoPlayerEmbed {
3
3
  private container;
4
4
  private config;
package/dist/types.d.ts CHANGED
@@ -1,15 +1,17 @@
1
- export interface CommentsEmbedOptions {
1
+ interface BaseOptions {
2
2
  wp?: string;
3
3
  url?: string;
4
4
  pageID?: string;
5
5
  theme?: string;
6
+ }
7
+ export interface ChatPageOptions extends BaseOptions {
8
+ collapsed?: boolean;
9
+ title?: string;
10
+ }
11
+ export interface CommentsEmbedOptions extends BaseOptions {
6
12
  reactions?: boolean;
7
13
  }
8
- export interface VideoPlayerEmbedOptions {
9
- wp?: string;
10
- url?: string;
11
- pageID?: string;
12
- theme?: string;
14
+ export interface VideoPlayerEmbedOptions extends BaseOptions {
13
15
  src?: string;
14
16
  srcType?: string;
15
17
  ytvid?: string;
@@ -18,11 +20,7 @@ export interface VideoPlayerEmbedOptions {
18
20
  vklive?: string;
19
21
  vimeoid?: string;
20
22
  }
21
- export interface PollEmbedOptions {
22
- wp?: string;
23
- url?: string;
24
- pageID?: string;
25
- theme?: string;
23
+ export interface PollEmbedOptions extends BaseOptions {
26
24
  pollID?: string;
27
25
  }
28
26
  export interface AISummaryOptions {
@@ -30,3 +28,8 @@ export interface AISummaryOptions {
30
28
  url?: string;
31
29
  theme?: string;
32
30
  }
31
+ export interface ChatOptions {
32
+ theme?: string;
33
+ pageIDs?: ChatPageOptions[];
34
+ }
35
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crosstalk-comments-livechat-sdk",
3
- "version": "0.0.5-beta.3",
3
+ "version": "0.0.6-beta.1",
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": ["comments", "live chat", "crosstalk", "hyvor talk", "audience Engagement", "disqus", "video player"],
13
+ "keywords": ["comments", "live chat", "crosstalk", "hyvor talk", "audience Engagement", "disqus", "video player", "polls", "ai summary", "ai"],
14
14
  "author": "CrossTalk Audience Engagement Platform",
15
15
  "license": "ISC",
16
16
  "devDependencies": {