jibtalk-core 1.0.1 → 1.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.
package/dist/jibtalk-core.js
CHANGED
|
@@ -1505,10 +1505,10 @@ var Q = "\n#jibtalk-sdk-root {\n position: fixed;\n z-index: 9999;\n font-fam
|
|
|
1505
1505
|
this.isOpen && (this.isOpen = !1, this.emitStateChange(), this.emit("conversationClosed", this.currentConversation));
|
|
1506
1506
|
}
|
|
1507
1507
|
toggle() {
|
|
1508
|
-
this.isOpen ? this.close() : this.open();
|
|
1508
|
+
console.log("Core SDK: toggle() called. Current isOpen status:", this.isOpen), this.isOpen ? this.close() : this.open();
|
|
1509
1509
|
}
|
|
1510
1510
|
destroy() {
|
|
1511
|
-
this.close(), this.socket &&= (this.socket.disconnect(), null), this.listeners.clear(), this.isConnected = !1, this.emitStateChange(), $ === this && ($ = null);
|
|
1511
|
+
console.log("Core SDK: destroy() called."), this.close(), this.socket &&= (this.socket.disconnect(), null), this.listeners.clear(), this.isConnected = !1, this.emitStateChange(), $ === this && ($ = null);
|
|
1512
1512
|
}
|
|
1513
1513
|
identify(e, t, n) {
|
|
1514
1514
|
typeof window > "u" || (this.visitorId = e.id || this.visitorId, this.optionsCustomer = e, t && (this.optionsTimestamp = t), n && (this.optionsSignature = n), this.initWidget(e));
|
|
@@ -1547,22 +1547,22 @@ var Q = "\n#jibtalk-sdk-root {\n position: fixed;\n z-index: 9999;\n font-fam
|
|
|
1547
1547
|
});
|
|
1548
1548
|
}
|
|
1549
1549
|
on(e, t) {
|
|
1550
|
-
this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(t);
|
|
1550
|
+
this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(t), console.log(`Core SDK: Listener added for event "${e}". Current count:`, this.listeners.get(e)?.size);
|
|
1551
1551
|
}
|
|
1552
1552
|
off(e, t) {
|
|
1553
|
-
this.listeners.has(e) && this.listeners.get(e).delete(t);
|
|
1553
|
+
this.listeners.has(e) && (this.listeners.get(e).delete(t), console.log(`Core SDK: Listener removed for event "${e}". Current count:`, this.listeners.get(e)?.size));
|
|
1554
1554
|
}
|
|
1555
1555
|
emit(e, ...t) {
|
|
1556
|
-
this.listeners.has(e)
|
|
1556
|
+
this.listeners.has(e) ? (console.log(`Core SDK: Emitting event "${e}" to`, this.listeners.get(e).size, "listeners."), this.listeners.get(e).forEach((n) => {
|
|
1557
1557
|
try {
|
|
1558
1558
|
n(...t);
|
|
1559
1559
|
} catch (t) {
|
|
1560
1560
|
console.error(`Error in event listener for ${e}:`, t);
|
|
1561
1561
|
}
|
|
1562
|
-
});
|
|
1562
|
+
})) : console.log(`Core SDK: Emitting event "${e}" but no listeners exist.`);
|
|
1563
1563
|
}
|
|
1564
1564
|
emitStateChange() {
|
|
1565
|
-
this.emit("stateChange", {
|
|
1565
|
+
console.log("Core SDK: emitStateChange() triggered. isOpen:", this.isOpen, "isConnected:", this.isConnected), this.emit("stateChange", {
|
|
1566
1566
|
isOpen: this.isOpen,
|
|
1567
1567
|
isConnected: this.isConnected,
|
|
1568
1568
|
unreadCount: this.unreadCount,
|
|
@@ -574,4 +574,4 @@
|
|
|
574
574
|
text-overflow: ellipsis;
|
|
575
575
|
white-space: nowrap;
|
|
576
576
|
}
|
|
577
|
-
`,Ye=()=>{if(typeof document>`u`)return;let e=`jibtalk-sdk-styles`;if(!document.getElementById(e)){let t=document.createElement(`style`);t.id=e,t.textContent=Je,document.head.appendChild(t)}},Xe=class{socket=null;apiKey;backendUrl;visitorId;listeners=new Map;isOpen=!1;isConnected=!1;unreadCount=0;currentConversation=null;messages=[];workspaceName=``;workspaceSlug=``;theme=`dark`;position=`bottom-right`;primaryColor=`#26A17B`;locale=`en`;constructor(e){this.apiKey=e.apiKey,this.backendUrl=typeof globalThis<`u`&&globalThis.process?.env?.NEXT_PUBLIC_JIBTALK_BACKEND_URL||typeof window<`u`&&window.JIBTALK_BACKEND_URL||`http://localhost:7000`,this.theme=e.theme||`dark`,this.position=e.position||`bottom-right`,this.primaryColor=e.primaryColor||`#26A17B`,this.locale=e.locale||`en`,this.optionsCustomer=e.customer,this.optionsConvId=e.conversationId,this.optionsTimestamp=e.timestamp,this.optionsSignature=e.signature;let t=typeof window<`u`?localStorage.getItem(`jibtalk_conversation_id`):null;this.currentConversation=t?{id:t}:null,this.visitorId=e.customer?.id||this.getVisitorId(),this.connect()}getVisitorId(){if(typeof window>`u`)return``;let e=localStorage.getItem(`jibtalk_visitor_id`);return e||=localStorage.getItem(`vyou_visitor_id`),e||(e=`v_`+Math.random().toString(36).substring(2,11),localStorage.setItem(`jibtalk_visitor_id`,e)),e}connect(){typeof window>`u`||(this.socket&&this.socket.disconnect(),this.socket=Q(this.backendUrl),this.socket.on(`connect`,()=>{this.isConnected=!0,this.emit(`connected`),this.emitStateChange();let e=this.optionsCustomer,t=this.optionsConvId;this.initWidget(e,t)}),this.socket.on(`disconnect`,()=>{this.isConnected=!1,this.emit(`disconnected`),this.emitStateChange()}),this.socket.on(`session_ready`,e=>{this.currentConversation=e,this.messages=e.messages||[],this.workspaceName=e.workspaceName||``,this.workspaceSlug=e.workspaceSlug||``,typeof window<`u`&&(e.id&&localStorage.setItem(`jibtalk_conversation_id`,e.id),e.sessionToken&&localStorage.setItem(`jibtalk_session_token`,e.sessionToken)),this.emit(`conversationOpened`,e),this.emitStateChange()}),this.socket.on(`widget_ready`,e=>{this.workspaceName=e.workspaceName||``,this.workspaceSlug=e.workspaceSlug||``,this.currentConversation=null,this.messages=[],e.sessionExpired&&typeof window<`u`&&(localStorage.removeItem(`jibtalk_conversation_id`),localStorage.removeItem(`jibtalk_session_token`)),this.emitStateChange()}),this.socket.on(`receive_message`,e=>{this.messages.push(e),e.sender===`visitor`?this.emit(`messageSent`,e):(this.isOpen||this.unreadCount++,this.emit(`messageReceived`,e)),this.emitStateChange()}),this.socket.on(`typing_started`,e=>{this.emit(`typingStarted`,e)}),this.socket.on(`typing_stopped`,e=>{this.emit(`typingStopped`,e)}),this.socket.on(`error`,e=>{console.error(`JibTalk Socket error:`,e.message||e)}))}initWidget(e,t){if(!this.socket)return;let n={apiKey:this.apiKey},r=t||this.currentConversation?.id;if(r&&(n.conversationId=r,typeof window<`u`&&!e)){let e=localStorage.getItem(`jibtalk_session_token`);e&&(n.sessionToken=e)}e?(n.customer={id:e.id,name:e.name,email:e.email,avatar:e.avatar,metadata:e.metadata},this.optionsTimestamp&&(n.timestamp=this.optionsTimestamp),this.optionsSignature&&(n.signature=this.optionsSignature)):n.visitorId=this.visitorId,this.socket.emit(`init_widget`,n)}open(e){this.isOpen||(this.isOpen=!0,this.unreadCount=0,e&&(e.customer&&(this.visitorId=e.customer.id||this.visitorId,this.optionsCustomer=e.customer),e.conversationId&&(this.optionsConvId=e.conversationId),e.timestamp&&(this.optionsTimestamp=e.timestamp),e.signature&&(this.optionsSignature=e.signature),this.initWidget(e.customer,e.conversationId)),this.emitStateChange())}close(){this.isOpen&&(this.isOpen=!1,this.emitStateChange(),this.emit(`conversationClosed`,this.currentConversation))}toggle(){this.isOpen?this.close():this.open()}destroy(){this.close(),this.socket&&=(this.socket.disconnect(),null),this.listeners.clear(),this.isConnected=!1,this.emitStateChange(),$===this&&($=null)}identify(e,t,n){typeof window>`u`||(this.visitorId=e.id||this.visitorId,this.optionsCustomer=e,t&&(this.optionsTimestamp=t),n&&(this.optionsSignature=n),this.initWidget(e))}setUser(e,t,n){this.identify(e,t,n)}logout(){typeof window>`u`||(this.close(),localStorage.removeItem(`jibtalk_visitor_id`),localStorage.removeItem(`vyou_visitor_id`),localStorage.removeItem(`jibtalk_conversation_id`),localStorage.removeItem(`jibtalk_session_token`),this.optionsCustomer=void 0,this.optionsConvId=void 0,this.optionsTimestamp=void 0,this.optionsSignature=void 0,this.visitorId=this.getVisitorId(),this.currentConversation=null,this.messages=[],this.unreadCount=0,this.connect())}sendMessage(e,t,n){!e.trim()&&!n||!this.currentConversation||!this.socket||this.socket.emit(`send_message`,{sessionId:this.currentConversation.id,content:e,sender:`visitor`,visitorId:this.visitorId,parentMessageId:t,file:n})}startConversation(){this.socket&&this.socket.emit(`start_conversation`)}startTyping(){!this.socket||!this.currentConversation||this.socket.emit(`typing_started`,{sessionId:this.currentConversation.id,sender:`visitor`,visitorId:this.visitorId})}stopTyping(){!this.socket||!this.currentConversation||this.socket.emit(`typing_stopped`,{sessionId:this.currentConversation.id,sender:`visitor`,visitorId:this.visitorId})}on(e,t){this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t)}off(e,t){this.listeners.has(e)&&this.listeners.get(e).delete(t)}emit(e,...t){this.listeners.has(e)
|
|
577
|
+
`,Ye=()=>{if(typeof document>`u`)return;let e=`jibtalk-sdk-styles`;if(!document.getElementById(e)){let t=document.createElement(`style`);t.id=e,t.textContent=Je,document.head.appendChild(t)}},Xe=class{socket=null;apiKey;backendUrl;visitorId;listeners=new Map;isOpen=!1;isConnected=!1;unreadCount=0;currentConversation=null;messages=[];workspaceName=``;workspaceSlug=``;theme=`dark`;position=`bottom-right`;primaryColor=`#26A17B`;locale=`en`;constructor(e){this.apiKey=e.apiKey,this.backendUrl=typeof globalThis<`u`&&globalThis.process?.env?.NEXT_PUBLIC_JIBTALK_BACKEND_URL||typeof window<`u`&&window.JIBTALK_BACKEND_URL||`http://localhost:7000`,this.theme=e.theme||`dark`,this.position=e.position||`bottom-right`,this.primaryColor=e.primaryColor||`#26A17B`,this.locale=e.locale||`en`,this.optionsCustomer=e.customer,this.optionsConvId=e.conversationId,this.optionsTimestamp=e.timestamp,this.optionsSignature=e.signature;let t=typeof window<`u`?localStorage.getItem(`jibtalk_conversation_id`):null;this.currentConversation=t?{id:t}:null,this.visitorId=e.customer?.id||this.getVisitorId(),this.connect()}getVisitorId(){if(typeof window>`u`)return``;let e=localStorage.getItem(`jibtalk_visitor_id`);return e||=localStorage.getItem(`vyou_visitor_id`),e||(e=`v_`+Math.random().toString(36).substring(2,11),localStorage.setItem(`jibtalk_visitor_id`,e)),e}connect(){typeof window>`u`||(this.socket&&this.socket.disconnect(),this.socket=Q(this.backendUrl),this.socket.on(`connect`,()=>{this.isConnected=!0,this.emit(`connected`),this.emitStateChange();let e=this.optionsCustomer,t=this.optionsConvId;this.initWidget(e,t)}),this.socket.on(`disconnect`,()=>{this.isConnected=!1,this.emit(`disconnected`),this.emitStateChange()}),this.socket.on(`session_ready`,e=>{this.currentConversation=e,this.messages=e.messages||[],this.workspaceName=e.workspaceName||``,this.workspaceSlug=e.workspaceSlug||``,typeof window<`u`&&(e.id&&localStorage.setItem(`jibtalk_conversation_id`,e.id),e.sessionToken&&localStorage.setItem(`jibtalk_session_token`,e.sessionToken)),this.emit(`conversationOpened`,e),this.emitStateChange()}),this.socket.on(`widget_ready`,e=>{this.workspaceName=e.workspaceName||``,this.workspaceSlug=e.workspaceSlug||``,this.currentConversation=null,this.messages=[],e.sessionExpired&&typeof window<`u`&&(localStorage.removeItem(`jibtalk_conversation_id`),localStorage.removeItem(`jibtalk_session_token`)),this.emitStateChange()}),this.socket.on(`receive_message`,e=>{this.messages.push(e),e.sender===`visitor`?this.emit(`messageSent`,e):(this.isOpen||this.unreadCount++,this.emit(`messageReceived`,e)),this.emitStateChange()}),this.socket.on(`typing_started`,e=>{this.emit(`typingStarted`,e)}),this.socket.on(`typing_stopped`,e=>{this.emit(`typingStopped`,e)}),this.socket.on(`error`,e=>{console.error(`JibTalk Socket error:`,e.message||e)}))}initWidget(e,t){if(!this.socket)return;let n={apiKey:this.apiKey},r=t||this.currentConversation?.id;if(r&&(n.conversationId=r,typeof window<`u`&&!e)){let e=localStorage.getItem(`jibtalk_session_token`);e&&(n.sessionToken=e)}e?(n.customer={id:e.id,name:e.name,email:e.email,avatar:e.avatar,metadata:e.metadata},this.optionsTimestamp&&(n.timestamp=this.optionsTimestamp),this.optionsSignature&&(n.signature=this.optionsSignature)):n.visitorId=this.visitorId,this.socket.emit(`init_widget`,n)}open(e){this.isOpen||(this.isOpen=!0,this.unreadCount=0,e&&(e.customer&&(this.visitorId=e.customer.id||this.visitorId,this.optionsCustomer=e.customer),e.conversationId&&(this.optionsConvId=e.conversationId),e.timestamp&&(this.optionsTimestamp=e.timestamp),e.signature&&(this.optionsSignature=e.signature),this.initWidget(e.customer,e.conversationId)),this.emitStateChange())}close(){this.isOpen&&(this.isOpen=!1,this.emitStateChange(),this.emit(`conversationClosed`,this.currentConversation))}toggle(){console.log(`Core SDK: toggle() called. Current isOpen status:`,this.isOpen),this.isOpen?this.close():this.open()}destroy(){console.log(`Core SDK: destroy() called.`),this.close(),this.socket&&=(this.socket.disconnect(),null),this.listeners.clear(),this.isConnected=!1,this.emitStateChange(),$===this&&($=null)}identify(e,t,n){typeof window>`u`||(this.visitorId=e.id||this.visitorId,this.optionsCustomer=e,t&&(this.optionsTimestamp=t),n&&(this.optionsSignature=n),this.initWidget(e))}setUser(e,t,n){this.identify(e,t,n)}logout(){typeof window>`u`||(this.close(),localStorage.removeItem(`jibtalk_visitor_id`),localStorage.removeItem(`vyou_visitor_id`),localStorage.removeItem(`jibtalk_conversation_id`),localStorage.removeItem(`jibtalk_session_token`),this.optionsCustomer=void 0,this.optionsConvId=void 0,this.optionsTimestamp=void 0,this.optionsSignature=void 0,this.visitorId=this.getVisitorId(),this.currentConversation=null,this.messages=[],this.unreadCount=0,this.connect())}sendMessage(e,t,n){!e.trim()&&!n||!this.currentConversation||!this.socket||this.socket.emit(`send_message`,{sessionId:this.currentConversation.id,content:e,sender:`visitor`,visitorId:this.visitorId,parentMessageId:t,file:n})}startConversation(){this.socket&&this.socket.emit(`start_conversation`)}startTyping(){!this.socket||!this.currentConversation||this.socket.emit(`typing_started`,{sessionId:this.currentConversation.id,sender:`visitor`,visitorId:this.visitorId})}stopTyping(){!this.socket||!this.currentConversation||this.socket.emit(`typing_stopped`,{sessionId:this.currentConversation.id,sender:`visitor`,visitorId:this.visitorId})}on(e,t){this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),console.log(`Core SDK: Listener added for event "${e}". Current count:`,this.listeners.get(e)?.size)}off(e,t){this.listeners.has(e)&&(this.listeners.get(e).delete(t),console.log(`Core SDK: Listener removed for event "${e}". Current count:`,this.listeners.get(e)?.size))}emit(e,...t){this.listeners.has(e)?(console.log(`Core SDK: Emitting event "${e}" to`,this.listeners.get(e).size,`listeners.`),this.listeners.get(e).forEach(n=>{try{n(...t)}catch(t){console.error(`Error in event listener for ${e}:`,t)}})):console.log(`Core SDK: Emitting event "${e}" but no listeners exist.`)}emitStateChange(){console.log(`Core SDK: emitStateChange() triggered. isOpen:`,this.isOpen,`isConnected:`,this.isConnected),this.emit(`stateChange`,{isOpen:this.isOpen,isConnected:this.isConnected,unreadCount:this.unreadCount,currentConversation:this.currentConversation,messages:this.messages,theme:this.theme,position:this.position,primaryColor:this.primaryColor,locale:this.locale,workspaceName:this.workspaceName,workspaceSlug:this.workspaceSlug})}updateOptions(e){e.theme&&(this.theme=e.theme),e.position&&(this.position=e.position),e.primaryColor&&(this.primaryColor=e.primaryColor),e.locale&&(this.locale=e.locale),e.customer&&(this.visitorId=e.customer.id||this.visitorId,this.optionsCustomer=e.customer),e.conversationId&&(this.optionsConvId=e.conversationId),e.timestamp&&(this.optionsTimestamp=e.timestamp),e.signature&&(this.optionsSignature=e.signature),this.emitStateChange()}},$=null;e.JibTalkCore=Xe,e.STYLES_CSS=Je,e.getJibTalkInstance=e=>typeof window>`u`?null:(!$&&e?$=new Xe(e):$&&e&&$.updateOptions(e),$),e.injectStyles=Ye});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jibtalk-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "vite build && tsc --declaration --emitDeclarationOnly --noEmit false --outDir dist --rootDir src"
|
|
20
|
+
"build": "vite build && tsc --declaration --emitDeclarationOnly --noEmit false --outDir dist --rootDir src",
|
|
21
|
+
"dev": "vite build --watch"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
24
|
"socket.io-client": "^4.8.3"
|