od-support-chat 1.0.25 → 1.0.27

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/README.md CHANGED
@@ -90,7 +90,11 @@ Finally you can use the Chat client for Origin Detector (OD) customer support to
90
90
 
91
91
 
92
92
  ```typescript
93
- <Chat meetingLinkKey={meetingLinkKey} customerSupportKey={customerSupportKey}/>
93
+ <Chat meetingLinkKey={meetingLinkKey}
94
+ customerSupportKey={customerSupportKey}
95
+ title='OD Customer Support'
96
+ welcomeMessage='Welsome to OD, how can we help you today?'
97
+ supportEmail='support@origindetector.com' />
94
98
  ```
95
99
 
96
100
  ## Chat window for your customer on your website
@@ -4,6 +4,9 @@ import { FC } from "react";
4
4
  interface ChatProps {
5
5
  meetingLinkKey: string;
6
6
  customerSupportKey: string;
7
+ title: string;
8
+ supportEmail: string;
9
+ welcomeMessage: string;
7
10
  }
8
11
  declare const Chat: FC<ChatProps>;
9
12
  //#endregion
@@ -230,4 +230,4 @@ import{__toESM as e}from"../../_virtual/_rolldown/runtime.mjs";import{require_al
230
230
  `,E=s.i`
231
231
  width: 25px;
232
232
  font-size: calc(5px + 1vmin);
233
- `;var D,O,k;const A=`optimizetalk.com:8443`,j=e=>{let t=a(null),[n]=o(window.innerWidth<window.innerHeight&&window.innerWidth<=900),[s]=o(n?100:15),[c,p]=o([]),m=a(),[j,M]=o(!0),[N,P]=o(!1),[F,I]=o(!1),[L,R]=o(null),[z,B]=o(null),[V,H]=o(),[U,W]=o(),[G,K]=o(!1),[q,J]=o(``),ae=a(null),Y=a(null),oe=()=>{let e=1e4,t=Math.floor(Math.random()*(9e4-e+1))+e;return console.log(`Random number: `+t),t},se=(e,t)=>{D=new WebSocket(`wss://`+A+`/signal`),D.onopen=function(){console.log(`Websocket connection established`),fe(),le(e,t),$({from:{userName:e,audio:!0,video:!0},type:`text`,data:`ping from `+e}),O=setInterval(()=>{$({from:{userName:e,audio:!0,video:!0},type:`text`,data:`ping from `+e})},45e3),Z(e,t),console.log(`WebSocket connection opened to chat room `+q)}},ce=(e,t)=>{I(!0),R(t),console.log(`Params guestName:`+e+`, guestEmail:`+t);var n=z?e:`Guest-`+oe()+`: `+e;B(n),console.log(`Joining : `+n),se(n,t)};function X(){console.log(`Close the socket`),D!=null&&(console.log(`Send 'leave' message to server for session `+V+` accessToken: `+U),$({from:{userName:z,sessionKey:V,audio:!0,video:!0},accessToken:U,type:`leave`,data:e.meetingLinkKey}),D.close())}function le(e,t){D.onmessage=function(n){let r=JSON.parse(n.data);switch(console.log(`Room received type: `+r.type),r.type){case`text`:console.log(`Text message from `+r.from.userName+` received: `+r.data);break;case`join_meeting`:console.log(`Main message `+r.data),r.data&&r.data===`busy`?(console.log(`Customer support is busy`),K(!0),k||ue(e,t)):r.data&&r.data===`valid`&&(clearInterval(k),console.log(`Session key `+r.referenceUsers[0].sessionKey),H(r.referenceUsers[0].sessionKey),console.log(`Session accessToken `+r.accessToken),W(r.accessToken),console.log(`Joined to room `+r.roomDetails.roomName),J(r.roomDetails.roomName));break;case`message`:console.log(`Chat message received from `+r.from.userName),console.log(`Chat message `+r.data),de(),p(e=>[...e,{sender:r.from.userName,msg:r.data}]),Q();break;case`session_expired`:console.log(`Chat session expired!`),I(!1),H(null),W(null),K(!1),X();break;default:console.log(`Room ignoring message type `+r.type)}}}let ue=(e,t)=>{k=setInterval(()=>{console.log(`Trying to connect customer support team ...`),Z(e,t)},1e4)},Z=(t,n)=>{$({from:{userName:t,email:n,audio:!1,video:!1},type:`join_meeting`,roomDetails:{roomLinkKey:e.meetingLinkKey},data:e.customerSupportKey}),console.log(`Meeting join request sent for guest `+t+`, meetingLinkKey: `+e.meetingLinkKey+`, customerSupportKey: `+e.customerSupportKey)},de=()=>{Y.current.play()};function fe(){D.addEventListener(`close`,e=>{console.log(`websocket connection closed: `,e),clearInterval(O)}),D.onerror=function(e){console.log(`Error: `+e)}}let Q=()=>{t.current?.scrollIntoView({behavior:`smooth`})},pe=e=>{if(e.key===`Enter`){let t=e.target.value;t&&(console.log(`Send 'message' message to server for session `+V+` accessToken: `+U),$({from:{userName:z,sessionKey:V,audio:!0,video:!0},accessToken:U,type:`message`,data:t}),console.log(`Chat message sent `+t),p(e=>[...e,{sender:z,msg:t}]),m.current.value=``)}},me=()=>{let e=m.current.value;e&&(console.log(`Send 'message' message to server for session `+V+` accessToken: `+U),$({from:{userName:z,sessionKey:V,audio:!0,video:!0},accessToken:U,type:`message`,data:e}),console.log(`Chat message sent `+e),p(t=>[...t,{sender:z,msg:e}]),m.current.value=``,Q())};function $(e){let t=JSON.stringify(e);D.send(t)}function he(){X(),M(!1),P(!0),H(null),W(null),K(!1)}function ge(){D=new WebSocket(`wss://`+A+`/signal`),H(null),W(null),M(!0),P(!1),I(!1),K(!1),R(null),B(null),p([])}return i(()=>{Q()},[c,V]),d(`div`,{children:[!N&&d(h,{displayChat:j,maxWidth:s,children:[d(_,{children:[u(v,{children:`OD Customer Support`}),u(y,{onClick:()=>he(),className:`text-gray-700`,children:u(`svg`,{width:`60%`,height:`60%`,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:u(`path`,{d:`M18 6L6 18M6 6L18 18`,stroke:`orange`,"stroke-width":`4`,"stroke-linecap":`round`,"stroke-linejoin":`round`})})})]}),!F&&!V&&!G&&u(r,{startGuestChat:ce,guestEmail:L}),F&&!V&&!G&&u(l,{children:d(T,{children:[u(`div`,{className:`text-center mt-5`,children:`Please wait, connecting`}),d(`div`,{className:`flex flex-col items-center `,children:[u(`div`,{children:u(`img`,{className:`mt-5`,src:`/connecting_customer_support.gif`,width:`80`})}),u(`div`,{className:`absolute text-center bottom-6 font-sm text-sky-400`,children:`contact us at`}),u(`div`,{className:`absolute text-center bottom-0 font-sm text-sky-400`,children:`support@origindetector.com.`})]})]})}),F&&!V&&G&&u(l,{children:d(T,{children:[u(`div`,{className:`text-center text-sm`,children:`Our customer support team helping other customers, please wait.`}),u(`div`,{className:`text-center mt-5`,children:`connecting`}),d(`div`,{className:`flex flex-col items-center `,children:[u(`div`,{children:u(`img`,{className:`mt-5`,src:`/connecting_customer_support.gif`,width:`80`})}),u(`div`,{className:`absolute text-center bottom-6 font-sm text-sky-400`,children:`contact us at`}),u(`div`,{className:`absolute text-center bottom-0 font-sm text-sky-400`,children:`support@origindetector.com`})]})]})}),F&&V&&d(`div`,{children:[u(te,{children:`Live Chat`}),u(x,{children:d(ne,{children:[c&&c.length==0&&u(`div`,{className:`ml-2 text-sm`,children:` You are connected to our customer support team, how can we help you today? `}),c&&c.length>0&&d(`div`,{children:[c&&c.map(({sender:e,msg:t},n)=>e===z?d(C,{children:[u(`strong`,{children:z}),u(`p`,{children:t})]},n):d(S,{children:[u(`strong`,{children:e}),u(`p`,{children:t})]},n)),u(`div`,{style:{float:`left`,clear:`both`},ref:t})]})]})}),d(w,{children:[u(re,{ref:m,onKeyUp:pe,placeholder:`Enter your message`}),d(ie,{onClick:me,children:[u(E,{className:`fas fa-paper-plane`}),`Send`]})]})]}),u(`audio`,{ref:ae,src:f.default}),u(`audio`,{ref:Y,src:ee.default})]}),N&&u(g,{className:`cursor-pointer`,onClick:()=>ge(),displayChat:j,maxWidth:s,children:d(b,{children:[u(`i`,{className:`bx bx-chat`}),`Live Chat`]})})]})};export{j as default};
233
+ `;var D,O,k;const A=`optimizetalk.com:8443`,j=e=>{let t=a(null),[n]=o(window.innerWidth<window.innerHeight&&window.innerWidth<=900),[s]=o(n?100:15),[c,p]=o([]),m=a(),[j,M]=o(!0),[N,P]=o(!1),[F,I]=o(!1),[L,R]=o(null),[z,B]=o(null),[V,H]=o(),[U,W]=o(),[G,K]=o(!1),[q,J]=o(``),ae=a(null),Y=a(null),oe=()=>{let e=1e4,t=Math.floor(Math.random()*(9e4-e+1))+e;return console.log(`Random number: `+t),t},se=(e,t)=>{D=new WebSocket(`wss://`+A+`/signal`),D.onopen=function(){console.log(`Websocket connection established`),fe(),le(e,t),$({from:{userName:e,audio:!0,video:!0},type:`text`,data:`ping from `+e}),O=setInterval(()=>{$({from:{userName:e,audio:!0,video:!0},type:`text`,data:`ping from `+e})},45e3),Z(e,t),console.log(`WebSocket connection opened to chat room `+q)}},ce=(e,t)=>{I(!0),R(t),console.log(`Params guestName:`+e+`, guestEmail:`+t);var n=z?e:`Guest-`+oe()+`: `+e;B(n),console.log(`Joining : `+n),se(n,t)};function X(){console.log(`Close the socket`),D!=null&&(console.log(`Send 'leave' message to server for session `+V+` accessToken: `+U),$({from:{userName:z,sessionKey:V,audio:!0,video:!0},accessToken:U,type:`leave`,data:e.meetingLinkKey}),D.close())}function le(e,t){D.onmessage=function(n){let r=JSON.parse(n.data);switch(console.log(`Room received type: `+r.type),r.type){case`text`:console.log(`Text message from `+r.from.userName+` received: `+r.data);break;case`join_meeting`:console.log(`Main message `+r.data),r.data&&r.data===`busy`?(console.log(`Customer support is busy`),K(!0),k||ue(e,t)):r.data&&r.data===`valid`&&(clearInterval(k),console.log(`Session key `+r.referenceUsers[0].sessionKey),H(r.referenceUsers[0].sessionKey),console.log(`Session accessToken `+r.accessToken),W(r.accessToken),console.log(`Joined to room `+r.roomDetails.roomName),J(r.roomDetails.roomName));break;case`message`:console.log(`Chat message received from `+r.from.userName),console.log(`Chat message `+r.data),de(),p(e=>[...e,{sender:r.from.userName,msg:r.data}]),Q();break;case`session_expired`:console.log(`Chat session expired!`),I(!1),H(null),W(null),K(!1),X();break;default:console.log(`Room ignoring message type `+r.type)}}}let ue=(e,t)=>{k=setInterval(()=>{console.log(`Trying to connect customer support team ...`),Z(e,t)},1e4)},Z=(t,n)=>{$({from:{userName:t,email:n,audio:!1,video:!1},type:`join_meeting`,roomDetails:{roomLinkKey:e.meetingLinkKey},data:e.customerSupportKey}),console.log(`Meeting join request sent for guest `+t+`, meetingLinkKey: `+e.meetingLinkKey+`, customerSupportKey: `+e.customerSupportKey)},de=()=>{Y.current.play()};function fe(){D.addEventListener(`close`,e=>{console.log(`websocket connection closed: `,e),clearInterval(O)}),D.onerror=function(e){console.log(`Error: `+e)}}let Q=()=>{t.current?.scrollIntoView({behavior:`smooth`})},pe=e=>{if(e.key===`Enter`){let t=e.target.value;t&&(console.log(`Send 'message' message to server for session `+V+` accessToken: `+U),$({from:{userName:z,sessionKey:V,audio:!0,video:!0},accessToken:U,type:`message`,data:t}),console.log(`Chat message sent `+t),p(e=>[...e,{sender:z,msg:t}]),m.current.value=``)}},me=()=>{let e=m.current.value;e&&(console.log(`Send 'message' message to server for session `+V+` accessToken: `+U),$({from:{userName:z,sessionKey:V,audio:!0,video:!0},accessToken:U,type:`message`,data:e}),console.log(`Chat message sent `+e),p(t=>[...t,{sender:z,msg:e}]),m.current.value=``,Q())};function $(e){let t=JSON.stringify(e);D.send(t)}function he(){X(),M(!1),P(!0),H(null),W(null),K(!1)}function ge(){D=new WebSocket(`wss://`+A+`/signal`),H(null),W(null),M(!0),P(!1),I(!1),K(!1),R(null),B(null),p([])}return i(()=>{Q()},[c,V]),d(`div`,{children:[!N&&d(h,{displayChat:j,maxWidth:s,children:[d(_,{children:[u(v,{children:e.title}),u(y,{onClick:()=>he(),className:`text-gray-700`,children:u(`svg`,{width:`60%`,height:`60%`,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:u(`path`,{d:`M18 6L6 18M6 6L18 18`,stroke:`orange`,"stroke-width":`4`,"stroke-linecap":`round`,"stroke-linejoin":`round`})})})]}),!F&&!V&&!G&&u(r,{startGuestChat:ce,guestEmail:L}),F&&!V&&!G&&u(l,{children:d(T,{children:[u(`div`,{className:`text-center mt-5`,children:`Please wait, connecting`}),d(`div`,{className:`flex flex-col items-center `,children:[u(`div`,{children:u(`img`,{className:`mt-1`,src:`/connecting_customer_support.gif`,width:`80`})}),u(`div`,{className:`mt-5 text-center bottom-6 font-sm text-sky-400`,children:`contact us at`}),u(`div`,{className:`text-center bottom-0 font-sm text-sky-400`,children:e.supportEmail})]})]})}),F&&!V&&G&&u(l,{children:d(T,{children:[u(`div`,{className:`text-center text-sm`,children:`Our customer support team helping other customers, please wait.`}),u(`div`,{className:`text-center mt-5`,children:`connecting`}),d(`div`,{className:`flex flex-col items-center `,children:[u(`div`,{children:u(`img`,{className:`mt-1`,src:`/connecting_customer_support.gif`,width:`80`})}),u(`div`,{className:`mt-5 text-center bottom-6 font-sm text-sky-400`,children:`contact us at`}),u(`div`,{className:`text-center bottom-0 font-sm text-sky-400`,children:e.supportEmail})]})]})}),F&&V&&d(`div`,{children:[u(te,{children:`Live Chat`}),u(x,{children:d(ne,{children:[c&&c.length==0&&d(`div`,{className:`ml-2 text-sm`,children:[` You are connected to our customer support team,`,e.welcomeMessage,` `]}),c&&c.length>0&&d(`div`,{children:[c&&c.map(({sender:e,msg:t},n)=>e===z?d(C,{children:[u(`strong`,{children:z}),u(`p`,{children:t})]},n):d(S,{children:[u(`strong`,{children:e}),u(`p`,{children:t})]},n)),u(`div`,{style:{float:`left`,clear:`both`},ref:t})]})]})}),d(w,{children:[u(re,{ref:m,onKeyUp:pe,placeholder:`Enter your message`}),d(ie,{onClick:me,children:[u(E,{className:`fas fa-paper-plane`}),`Send`]})]})]}),u(`audio`,{ref:ae,src:f.default}),u(`audio`,{ref:Y,src:ee.default})]}),N&&u(g,{className:`cursor-pointer`,onClick:()=>ge(),displayChat:j,maxWidth:s,children:d(b,{children:[u(`i`,{className:`bx bx-chat`}),`Live Chat`]})})]})};export{j as default};
@@ -4,6 +4,9 @@ import { FC } from "react";
4
4
  interface ChatProps {
5
5
  meetingLinkKey: string;
6
6
  customerSupportKey: string;
7
+ title: string;
8
+ supportEmail: string;
9
+ welcomeMessage: string;
7
10
  }
8
11
  declare const ChatMobile: FC<ChatProps>;
9
12
  //#endregion
@@ -230,4 +230,4 @@ import{__toESM as e}from"../../_virtual/_rolldown/runtime.mjs";import t from"./i
230
230
  `,E=s.i`
231
231
  width: 25px;
232
232
  font-size: calc(5px + 1vmin);
233
- `;var D,O,k;const A=`optimizetalk.com:8443`,j=e=>{let n=a(null),[r]=o(window.innerWidth<window.innerHeight&&window.innerWidth<=900),[s]=o(r?80:20),[c,p]=o([]),m=a(),[j,M]=o(!0),[N,P]=o(!1),[F,I]=o(!1),[L,R]=o(null),[z,B]=o(null),[V,H]=o(),[U,W]=o(),[G,K]=o(!1),[q,J]=o(``),ae=a(null),Y=a(null),oe=()=>{let e=1e4,t=Math.floor(Math.random()*(9e4-e+1))+e;return console.log(`Random number: `+t),t},se=(e,t)=>{D=new WebSocket(`wss://`+A+`/signal`),D.onopen=function(){console.log(`Websocket connection established`),fe(),le(e,t),$({from:{userName:e,audio:!0,video:!0},type:`text`,data:`ping from `+e}),O=setInterval(()=>{$({from:{userName:e,audio:!0,video:!0},type:`text`,data:`ping from `+e})},45e3),Z(e,t),console.log(`WebSocket connection opened to chat room `+q)}},ce=(e,t)=>{I(!0),R(t),console.log(`Params guestName:`+e+`, guestEmail:`+t);var n=z?e:`Guest-`+oe()+`: `+e;B(n),console.log(`Joining : `+n),se(n,t)};function X(){console.log(`Close the socket`),D!=null&&(console.log(`Send 'leave' message to server for session `+V+` accessToken: `+U),$({from:{userName:z,sessionKey:V,audio:!0,video:!0},accessToken:U,type:`leave`,data:e.meetingLinkKey}),D.close())}function le(e,t){D.onmessage=function(n){let r=JSON.parse(n.data);switch(console.log(`Room received type: `+r.type),r.type){case`text`:console.log(`Text message from `+r.from.userName+` received: `+r.data);break;case`join_meeting`:console.log(`Main message `+r.data),r.data&&r.data===`busy`?(console.log(`Customer support is busy`),K(!0),k||ue(e,t)):r.data&&r.data===`valid`&&(clearInterval(k),console.log(`Session key `+r.referenceUsers[0].sessionKey),H(r.referenceUsers[0].sessionKey),console.log(`Session accessToken `+r.accessToken),W(r.accessToken),console.log(`Joined to room `+r.roomDetails.roomName),J(r.roomDetails.roomName));break;case`message`:console.log(`Chat message received from `+r.from.userName),console.log(`Chat message `+r.data),de(),p(e=>[...e,{sender:r.from.userName,msg:r.data}]),Q();break;case`session_expired`:console.log(`Chat session expired!`),I(!1),H(null),W(null),K(!1),X();break;default:console.log(`Room ignoring message type `+r.type)}}}let ue=(e,t)=>{k=setInterval(()=>{console.log(`Trying to connect customer support team ...`),Z(e,t)},1e4)},Z=(t,n)=>{$({from:{userName:t,email:n,audio:!1,video:!1},type:`join_meeting`,roomDetails:{roomLinkKey:e.meetingLinkKey},data:e.customerSupportKey}),console.log(`Meeting join request sent for guest `+t+`, meetingLinkKey: `+e.meetingLinkKey+`, customerSupportKey: `+e.customerSupportKey)},de=()=>{Y.current.play()};function fe(){D.addEventListener(`close`,e=>{console.log(`websocket connection closed: `,e),clearInterval(O)}),D.onerror=function(e){console.log(`Error: `+e)}}let Q=()=>{n.current?.scrollIntoView({behavior:`smooth`})},pe=e=>{if(e.key===`Enter`){let t=e.target.value;t&&(console.log(`Send 'message' message to server for session `+V+` accessToken: `+U),$({from:{userName:z,sessionKey:V,audio:!0,video:!0},accessToken:U,type:`message`,data:t}),console.log(`Chat message sent `+t),p(e=>[...e,{sender:z,msg:t}]),m.current.value=``)}},me=()=>{let e=m.current.value;e&&(console.log(`Send 'message' message to server for session `+V+` accessToken: `+U),$({from:{userName:z,sessionKey:V,audio:!0,video:!0},accessToken:U,type:`message`,data:e}),console.log(`Chat message sent `+e),p(t=>[...t,{sender:z,msg:e}]),m.current.value=``,Q())};function $(e){let t=JSON.stringify(e);D.send(t)}function he(){X(),M(!1),P(!0),H(null),W(null),K(!1)}function ge(){D=new WebSocket(`wss://`+A+`/signal`),H(null),W(null),M(!0),P(!1),I(!1),K(!1),R(null),B(null),p([])}return i(()=>{Q()},[c,V]),d(`div`,{children:[!N&&d(h,{displayChat:j,maxWidth:s,children:[d(_,{children:[u(v,{children:`OD Customer Support`}),u(y,{onClick:()=>he(),className:`text-gray-700`,children:u(`svg`,{width:`60%`,height:`60%`,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:u(`path`,{d:`M18 6L6 18M6 6L18 18`,stroke:`orange`,"stroke-width":`4`,"stroke-linecap":`round`,"stroke-linejoin":`round`})})})]}),!F&&!V&&!G&&u(t,{startGuestChat:ce,guestEmail:L}),F&&!V&&!G&&u(l,{children:d(T,{children:[u(`div`,{className:`text-center mt-5`,children:`Please wait, connecting`}),d(`div`,{className:`flex flex-col items-center `,children:[u(`div`,{children:u(`img`,{className:`mt-5`,src:`/connecting_customer_support.gif`,width:`80`})}),u(`div`,{className:`absolute text-center bottom-6 font-sx text-sky-400`,children:`contact us at`}),u(`div`,{className:`absolute text-center bottom-0 font-sx text-sky-400`,children:`support@origindetector.com.`})]})]})}),F&&!V&&G&&u(l,{children:d(T,{children:[u(`div`,{className:`text-center`,children:`Our customer support team helping other customers, please wait.`}),u(`div`,{className:`text-center mt-5`,children:`connecting`}),d(`div`,{className:`flex flex-col items-center `,children:[u(`div`,{children:u(`img`,{className:`mt-5`,src:`/connecting_customer_support.gif`,width:`80`})}),u(`div`,{className:`absolute text-center bottom-6 font-sx text-sky-400`,children:`contact us at`}),u(`div`,{className:`absolute text-center bottom-0 font-sx text-sky-400`,children:`support@origindetector.com.`})]})]})}),F&&V&&d(`div`,{children:[u(te,{children:`Live Chat`}),u(x,{children:d(ne,{children:[c&&c.length==0&&u(`div`,{className:`ml-2`,children:` You are connected to our customer support team, how can we help you today? `}),c&&c.length>0&&d(`div`,{children:[c&&c.map(({sender:e,msg:t},n)=>e===z?d(C,{children:[u(`strong`,{children:z}),u(`p`,{children:t})]},n):d(S,{children:[u(`strong`,{children:e}),u(`p`,{children:t})]},n)),u(`div`,{style:{float:`left`,clear:`both`},ref:n})]})]})}),d(w,{children:[u(re,{ref:m,onKeyUp:pe,placeholder:`Enter your message`}),d(ie,{onClick:me,children:[u(E,{className:`fas fa-paper-plane`}),`Send`]})]})]}),u(`audio`,{ref:ae,src:f.default}),u(`audio`,{ref:Y,src:ee.default})]}),N&&u(g,{className:`cursor-pointer`,onClick:()=>ge(),displayChat:j,maxWidth:s,children:u(b,{children:u(`i`,{className:`bx bx-chat`})})})]})};export{j as default};
233
+ `;var D,O,k;const A=`optimizetalk.com:8443`,j=e=>{let n=a(null),[r]=o(window.innerWidth<window.innerHeight&&window.innerWidth<=900),[s]=o(r?80:20),[c,p]=o([]),m=a(),[j,M]=o(!0),[N,P]=o(!1),[F,I]=o(!1),[L,R]=o(null),[z,B]=o(null),[V,H]=o(),[U,W]=o(),[G,K]=o(!1),[q,J]=o(``),ae=a(null),Y=a(null),oe=()=>{let e=1e4,t=Math.floor(Math.random()*(9e4-e+1))+e;return console.log(`Random number: `+t),t},se=(e,t)=>{D=new WebSocket(`wss://`+A+`/signal`),D.onopen=function(){console.log(`Websocket connection established`),fe(),le(e,t),$({from:{userName:e,audio:!0,video:!0},type:`text`,data:`ping from `+e}),O=setInterval(()=>{$({from:{userName:e,audio:!0,video:!0},type:`text`,data:`ping from `+e})},45e3),Z(e,t),console.log(`WebSocket connection opened to chat room `+q)}},ce=(e,t)=>{I(!0),R(t),console.log(`Params guestName:`+e+`, guestEmail:`+t);var n=z?e:`Guest-`+oe()+`: `+e;B(n),console.log(`Joining : `+n),se(n,t)};function X(){console.log(`Close the socket`),D!=null&&(console.log(`Send 'leave' message to server for session `+V+` accessToken: `+U),$({from:{userName:z,sessionKey:V,audio:!0,video:!0},accessToken:U,type:`leave`,data:e.meetingLinkKey}),D.close())}function le(e,t){D.onmessage=function(n){let r=JSON.parse(n.data);switch(console.log(`Room received type: `+r.type),r.type){case`text`:console.log(`Text message from `+r.from.userName+` received: `+r.data);break;case`join_meeting`:console.log(`Main message `+r.data),r.data&&r.data===`busy`?(console.log(`Customer support is busy`),K(!0),k||ue(e,t)):r.data&&r.data===`valid`&&(clearInterval(k),console.log(`Session key `+r.referenceUsers[0].sessionKey),H(r.referenceUsers[0].sessionKey),console.log(`Session accessToken `+r.accessToken),W(r.accessToken),console.log(`Joined to room `+r.roomDetails.roomName),J(r.roomDetails.roomName));break;case`message`:console.log(`Chat message received from `+r.from.userName),console.log(`Chat message `+r.data),de(),p(e=>[...e,{sender:r.from.userName,msg:r.data}]),Q();break;case`session_expired`:console.log(`Chat session expired!`),I(!1),H(null),W(null),K(!1),X();break;default:console.log(`Room ignoring message type `+r.type)}}}let ue=(e,t)=>{k=setInterval(()=>{console.log(`Trying to connect customer support team ...`),Z(e,t)},1e4)},Z=(t,n)=>{$({from:{userName:t,email:n,audio:!1,video:!1},type:`join_meeting`,roomDetails:{roomLinkKey:e.meetingLinkKey},data:e.customerSupportKey}),console.log(`Meeting join request sent for guest `+t+`, meetingLinkKey: `+e.meetingLinkKey+`, customerSupportKey: `+e.customerSupportKey)},de=()=>{Y.current.play()};function fe(){D.addEventListener(`close`,e=>{console.log(`websocket connection closed: `,e),clearInterval(O)}),D.onerror=function(e){console.log(`Error: `+e)}}let Q=()=>{n.current?.scrollIntoView({behavior:`smooth`})},pe=e=>{if(e.key===`Enter`){let t=e.target.value;t&&(console.log(`Send 'message' message to server for session `+V+` accessToken: `+U),$({from:{userName:z,sessionKey:V,audio:!0,video:!0},accessToken:U,type:`message`,data:t}),console.log(`Chat message sent `+t),p(e=>[...e,{sender:z,msg:t}]),m.current.value=``)}},me=()=>{let e=m.current.value;e&&(console.log(`Send 'message' message to server for session `+V+` accessToken: `+U),$({from:{userName:z,sessionKey:V,audio:!0,video:!0},accessToken:U,type:`message`,data:e}),console.log(`Chat message sent `+e),p(t=>[...t,{sender:z,msg:e}]),m.current.value=``,Q())};function $(e){let t=JSON.stringify(e);D.send(t)}function he(){X(),M(!1),P(!0),H(null),W(null),K(!1)}function ge(){D=new WebSocket(`wss://`+A+`/signal`),H(null),W(null),M(!0),P(!1),I(!1),K(!1),R(null),B(null),p([])}return i(()=>{Q()},[c,V]),d(`div`,{children:[!N&&d(h,{displayChat:j,maxWidth:s,children:[d(_,{children:[u(v,{children:e.title}),u(y,{onClick:()=>he(),className:`text-gray-700`,children:u(`svg`,{width:`60%`,height:`60%`,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:u(`path`,{d:`M18 6L6 18M6 6L18 18`,stroke:`orange`,"stroke-width":`4`,"stroke-linecap":`round`,"stroke-linejoin":`round`})})})]}),!F&&!V&&!G&&u(t,{startGuestChat:ce,guestEmail:L}),F&&!V&&!G&&u(l,{children:d(T,{children:[u(`div`,{className:`text-center mt-5`,children:`Please wait, connecting`}),d(`div`,{className:`flex flex-col items-center `,children:[u(`div`,{children:u(`img`,{className:`mt-5`,src:`/connecting_customer_support.gif`,width:`80`})}),u(`div`,{className:`absolute text-center bottom-6 font-sx text-sky-400`,children:`contact us at`}),u(`div`,{className:`absolute text-center bottom-0 font-sx text-sky-400`,children:e.supportEmail})]})]})}),F&&!V&&G&&u(l,{children:d(T,{children:[u(`div`,{className:`text-center`,children:`Our customer support team helping other customers, please wait.`}),u(`div`,{className:`text-center mt-5`,children:`connecting`}),d(`div`,{className:`flex flex-col items-center `,children:[u(`div`,{children:u(`img`,{className:`mt-1`,src:`/connecting_customer_support.gif`,width:`80`})}),u(`div`,{className:`mt-5 text-center bottom-6 font-sx text-sky-400`,children:`contact us at`}),u(`div`,{className:`text-center bottom-0 font-sx text-sky-400`,children:e.supportEmail})]})]})}),F&&V&&d(`div`,{children:[u(te,{children:`Live Chat`}),u(x,{children:d(ne,{children:[c&&c.length==0&&d(`div`,{className:`ml-2`,children:[` You are connected to our customer support team,`,e.welcomeMessage,` `]}),c&&c.length>0&&d(`div`,{children:[c&&c.map(({sender:e,msg:t},n)=>e===z?d(C,{children:[u(`strong`,{children:z}),u(`p`,{children:t})]},n):d(S,{children:[u(`strong`,{children:e}),u(`p`,{children:t})]},n)),u(`div`,{style:{float:`left`,clear:`both`},ref:n})]})]})}),d(w,{children:[u(re,{ref:m,onKeyUp:pe,placeholder:`Enter your message`}),d(ie,{onClick:me,children:[u(E,{className:`fas fa-paper-plane`}),`Send`]})]})]}),u(`audio`,{ref:ae,src:f.default}),u(`audio`,{ref:Y,src:ee.default})]}),N&&u(g,{className:`cursor-pointer`,onClick:()=>ge(),displayChat:j,maxWidth:s,children:u(b,{children:u(`i`,{className:`bx bx-chat`})})})]})};export{j as default};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "od-support-chat",
3
3
  "private": false,
4
- "version": "1.0.25",
4
+ "version": "1.0.27",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "exports": {