obi-sdk 0.3.7 → 0.3.9

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.
@@ -491,7 +491,7 @@ a=extmap-allow-mixed`)!==-1){const r=i.sdp.split(`
491
491
  font-weight: 500;
492
492
  font-size: 14px;
493
493
  }
494
- `,customElements.get("obi-searching-loader")||customElements.define("obi-searching-loader",Yh);var hU=Object.defineProperty,fU=Object.getOwnPropertyDescriptor,hA=(t,e,A,n)=>{for(var i=n>1?void 0:n?fU(e,A):e,r=t.length-1,s;r>=0;r--)(s=t[r])&&(i=(n?s(e,A,i):s(i))||i);return n&&i&&hU(e,A,i),i};const qh="49206C6F7665204F6269_session";class xe extends _.LitElement{constructor(){super(),this.apiKey="",this.isActive=!0,this.position="bottom-right",this.user=null,this.state=O.READY,this.storedActiveState=void 0,this.showCourseModal=!1,this.isHovering=!1,this.navVisible=!1,this.activeSession=null,this.volume={speaker:"ASSISTANT",volume:0,spectrum:[]},this.sessionToken=null,this.roomToken=null,this.roomUrl=null,this.boundSaveSessionData=null,this.closeNavTimeoutRef=null,this.updateFromConfig();const e=()=>{this.activeSession&&this.sessionToken&&this.roomToken&&this.roomUrl&&this.saveSessionData()};window.addEventListener("beforeunload",e),window.addEventListener("pagehide",e)}updateFromConfig(){var e,A;window.obiWidgetConfig&&(this.apiKey=window.obiWidgetConfig.apiKey||this.apiKey,this.position=window.obiWidgetConfig.position||this.position,this.user=window.obiWidgetConfig.user||this.user,window.obiWidgetConfig.isActive!==void 0&&(this.isActive=window.obiWidgetConfig.isActive),this.style.setProperty("--obi-primary",((e=window.obiWidgetConfig)==null?void 0:e.primaryColor)||"#9500ff"),this.style.setProperty("--obi-secondary",((A=window.obiWidgetConfig)==null?void 0:A.secondaryColor)||"#c4b5fd"))}removeSessionFromUrl(){const e=new URL(window.location.href);e.searchParams.delete(qh),window.history.replaceState({},"",e.toString())}async connectObi(e){if(this.activeSession){console.log("Connection already exists");return}try{const A=new wu({sessionId:e,apiBaseUrl:qr});if(!A){console.error("Failed to create session"),this.state=O.ERROR,this.activeSession=null,this.removeSessionFromUrl();return}A.on("stateChanged",i=>{this.state=i,i!==O.READY&&(this.storedActiveState=i)}),A.on("volume",({speaker:i,spectrum:r,volume:s})=>{this.volume={speaker:i,spectrum:r,volume:s}}),A.on("screenCaptureRequested",async()=>{try{const r=(await fb(document.documentElement,{useCORS:!0,allowTaint:!0,foreignObjectRendering:!0})).toDataURL("image/png");this.activeSession.emit("screenCaptureComplete",r)}catch(i){console.error("[obi] error capturing screen:",i),this.activeSession.emit("screenCaptureComplete","error")}}),A.on("error",i=>{console.error("Session error:",i),this.state=O.ERROR,this.activeSession=null,this.removeSessionFromUrl()});const n=await A.connect();n&&(this.sessionToken=e,this.roomToken=n.token,this.roomUrl=n.url,this.removeSessionFromUrl()),this.activeSession=A}catch(A){console.error("Failed to start session:",A),this.state=O.ERROR,this.activeSession=null,this.removeSessionFromUrl()}}async handleSessionStart(e){if(this.activeSession){console.log("Connection already in progress or active session exists");return}this.showCourseModal=!1,this.state=O.LOADING,await this.connectObi(e)}async checkExistingSession(){try{const e=JSON.parse(Qa.getItem(Ua.SESSION_DATA)||"{}"),{sessionToken:A,roomToken:n,roomUrl:i,sessionExpiry:r,obiState:s}=e;if(!A||!n||!i)return;if(r&&new Date(r)<new Date){this.clearSessionStorage();return}this.state=O.LOADING;const o=new wu({sessionId:A,apiBaseUrl:qr});if(!o){console.error("Failed to create session"),this.state=O.ERROR,this.clearSessionStorage();return}o.on("stateChanged",c=>{this.state=c,c!==O.READY&&(this.storedActiveState=c)}),o.on("volume",({speaker:c,spectrum:l,volume:u})=>{this.volume={speaker:c,spectrum:l,volume:u}}),o.on("error",c=>{console.error("Session error:",c),this.state=O.ERROR,this.activeSession=null,this.clearSessionStorage()}),await o.reconnect(i,n,s)?(this.activeSession=o,this.sessionToken=A,this.roomToken=n,this.roomUrl=i,this.state=s,this.storedActiveState=s):this.clearSessionStorage()}catch(e){console.error("Error reconnecting to session:",e),this.state=O.ERROR,this.clearSessionStorage()}}clearSessionStorage(){Qa.removeItem(Ua.SESSION_DATA)}saveSessionData(){if(this.activeSession&&this.sessionToken&&this.roomToken&&this.roomUrl){const e=new Date;e.setMinutes(e.getMinutes()+5);const A={sessionToken:this.sessionToken,roomToken:this.roomToken,roomUrl:this.roomUrl,obiState:this.storedActiveState??this.state,sessionExpiry:e.toISOString()};Qa.setItem(Ua.SESSION_DATA,JSON.stringify(A))}}async sessionConnectionCheck(){if(await this.checkExistingSession(),!this.activeSession){const A=new URLSearchParams(window.location.search).get(qh);A&&this.handleSessionStart(A)}}connectedCallback(){super.connectedCallback(),this.updateFromConfig(),this.setAttribute("position",this.position),this.boundSaveSessionData=this.saveSessionData.bind(this),window.addEventListener("beforeunload",this.boundSaveSessionData),window.addEventListener("pagehide",this.boundSaveSessionData),this.sessionConnectionCheck()}disconnectedCallback(){this.closeNavTimeoutRef!==null&&window.clearTimeout(this.closeNavTimeoutRef),this.boundSaveSessionData&&(window.removeEventListener("beforeunload",this.boundSaveSessionData),window.removeEventListener("pagehide",this.boundSaveSessionData)),this.removeSessionFromUrl(),super.disconnectedCallback()}handleMouseEnter(){this.isHovering=!0,this.navVisible=!0}handleMouseLeave(){this.isHovering=!1,this.closeNavTimeoutRef!==null&&window.clearTimeout(this.closeNavTimeoutRef),this.closeNavTimeoutRef=window.setTimeout(()=>{this.isHovering||(this.navVisible=!1),this.closeNavTimeoutRef=null},300)}terminateSession(){this.clearSessionStorage(),this.sessionToken=null,this.roomToken=null,this.roomUrl=null,this.activeSession&&(this.activeSession.disconnect(),this.activeSession=null),this.state=O.READY}handleItemSelect(e,A){if(e==="experiences"){this.showCourseModal=!0;return}Ki([e,A]).with(["pause",!0],()=>{var n;(n=this.activeSession)==null||n.pauseRecording()}).with(["pause",!1],()=>{var n;(n=this.activeSession)==null||n.resumeRecording()}).with(["activate",!1],()=>{this.terminateSession()}).otherwise(()=>{})}render(){if(this.updateFromConfig(),!this.isActive)return _.nothing;const e=Ki(this.state).with(O.LOADING,()=>_.html`<obi-dot-loader></obi-dot-loader>`).with(O.RESEARCHING,()=>_.html`<obi-searching-loader></obi-searching-loader>`).with(Wm.union(O.USER_SPEAKING,O.AGENT_SPEAKING),()=>_.html`<obi-audio-equalizer .volume=${this.volume}></obi-audio-equalizer>`).with(O.PAUSED,()=>_h).otherwise(()=>_h);return _.html`
494
+ `,customElements.get("obi-searching-loader")||customElements.define("obi-searching-loader",Yh);var hU=Object.defineProperty,fU=Object.getOwnPropertyDescriptor,hA=(t,e,A,n)=>{for(var i=n>1?void 0:n?fU(e,A):e,r=t.length-1,s;r>=0;r--)(s=t[r])&&(i=(n?s(e,A,i):s(i))||i);return n&&i&&hU(e,A,i),i};const qh="49206C6F7665204F6269_session";class xe extends _.LitElement{constructor(){super(),this.apiKey="",this.isActive=!0,this.position="bottom-right",this.user=null,this.state=O.READY,this.storedActiveState=void 0,this.showCourseModal=!1,this.isHovering=!1,this.navVisible=!1,this.activeSession=null,this.volume={speaker:"ASSISTANT",volume:0,spectrum:[]},this.sessionToken=null,this.roomToken=null,this.roomUrl=null,this.boundSaveSessionData=null,this.closeNavTimeoutRef=null;const e=()=>{this.activeSession&&this.sessionToken&&this.roomToken&&this.roomUrl&&this.saveSessionData()};window.addEventListener("beforeunload",e),window.addEventListener("pagehide",e)}updateFromConfig(){var e,A;window.obiWidgetConfig&&(this.apiKey=window.obiWidgetConfig.apiKey||this.apiKey,this.position=window.obiWidgetConfig.position||this.position,this.user=window.obiWidgetConfig.user||this.user,window.obiWidgetConfig.isActive!==void 0&&(this.isActive=window.obiWidgetConfig.isActive),this.style.setProperty("--obi-primary",((e=window.obiWidgetConfig)==null?void 0:e.primaryColor)||"#9500ff"),this.style.setProperty("--obi-secondary",((A=window.obiWidgetConfig)==null?void 0:A.secondaryColor)||"#c4b5fd"))}removeSessionFromUrl(){const e=new URL(window.location.href);e.searchParams.delete(qh),window.history.replaceState({},"",e.toString())}async connectObi(e){if(this.activeSession){console.log("Connection already exists");return}try{const A=new wu({sessionId:e,apiBaseUrl:qr});if(!A){console.error("Failed to create session"),this.state=O.ERROR,this.activeSession=null,this.removeSessionFromUrl();return}A.on("stateChanged",i=>{this.state=i,i!==O.READY&&(this.storedActiveState=i)}),A.on("volume",({speaker:i,spectrum:r,volume:s})=>{this.volume={speaker:i,spectrum:r,volume:s}}),A.on("screenCaptureRequested",async()=>{try{const r=(await fb(document.documentElement,{useCORS:!0,allowTaint:!0,foreignObjectRendering:!0})).toDataURL("image/png");this.activeSession.emit("screenCaptureComplete",r)}catch(i){console.error("[obi] error capturing screen:",i),this.activeSession.emit("screenCaptureComplete","error")}}),A.on("error",i=>{console.error("Session error:",i),this.state=O.ERROR,this.activeSession=null,this.removeSessionFromUrl()});const n=await A.connect();n&&(this.sessionToken=e,this.roomToken=n.token,this.roomUrl=n.url,this.removeSessionFromUrl()),this.activeSession=A}catch(A){console.error("Failed to start session:",A),this.state=O.ERROR,this.activeSession=null,this.removeSessionFromUrl()}}async handleSessionStart(e){if(this.activeSession){console.log("Connection already in progress or active session exists");return}this.showCourseModal=!1,this.state=O.LOADING,await this.connectObi(e)}async checkExistingSession(){try{const e=JSON.parse(Qa.getItem(Ua.SESSION_DATA)||"{}"),{sessionToken:A,roomToken:n,roomUrl:i,sessionExpiry:r,obiState:s}=e;if(!A||!n||!i)return;if(r&&new Date(r)<new Date){this.clearSessionStorage();return}this.state=O.LOADING;const o=new wu({sessionId:A,apiBaseUrl:qr});if(!o){console.error("Failed to create session"),this.state=O.ERROR,this.clearSessionStorage();return}o.on("stateChanged",c=>{this.state=c,c!==O.READY&&(this.storedActiveState=c)}),o.on("volume",({speaker:c,spectrum:l,volume:u})=>{this.volume={speaker:c,spectrum:l,volume:u}}),o.on("error",c=>{console.error("Session error:",c),this.state=O.ERROR,this.activeSession=null,this.clearSessionStorage()}),await o.reconnect(i,n,s)?(this.activeSession=o,this.sessionToken=A,this.roomToken=n,this.roomUrl=i,this.state=s,this.storedActiveState=s):this.clearSessionStorage()}catch(e){console.error("Error reconnecting to session:",e),this.state=O.ERROR,this.clearSessionStorage()}}clearSessionStorage(){Qa.removeItem(Ua.SESSION_DATA)}saveSessionData(){if(this.activeSession&&this.sessionToken&&this.roomToken&&this.roomUrl){const e=new Date;e.setMinutes(e.getMinutes()+5);const A={sessionToken:this.sessionToken,roomToken:this.roomToken,roomUrl:this.roomUrl,obiState:this.storedActiveState??this.state,sessionExpiry:e.toISOString()};Qa.setItem(Ua.SESSION_DATA,JSON.stringify(A))}}async sessionConnectionCheck(){if(await this.checkExistingSession(),!this.activeSession){const A=new URLSearchParams(window.location.search).get(qh);A&&this.handleSessionStart(A)}}connectedCallback(){super.connectedCallback(),this.updateFromConfig(),this.setAttribute("position",this.position),this.boundSaveSessionData=this.saveSessionData.bind(this),window.addEventListener("beforeunload",this.boundSaveSessionData),window.addEventListener("pagehide",this.boundSaveSessionData),this.sessionConnectionCheck()}disconnectedCallback(){this.closeNavTimeoutRef!==null&&window.clearTimeout(this.closeNavTimeoutRef),this.boundSaveSessionData&&(window.removeEventListener("beforeunload",this.boundSaveSessionData),window.removeEventListener("pagehide",this.boundSaveSessionData)),this.removeSessionFromUrl(),super.disconnectedCallback()}handleMouseEnter(){this.isHovering=!0,this.navVisible=!0}handleMouseLeave(){this.isHovering=!1,this.closeNavTimeoutRef!==null&&window.clearTimeout(this.closeNavTimeoutRef),this.closeNavTimeoutRef=window.setTimeout(()=>{this.isHovering||(this.navVisible=!1),this.closeNavTimeoutRef=null},300)}terminateSession(){this.clearSessionStorage(),this.sessionToken=null,this.roomToken=null,this.roomUrl=null,this.activeSession&&(this.activeSession.disconnect(),this.activeSession=null),this.state=O.READY}handleItemSelect(e,A){if(e==="experiences"){this.showCourseModal=!0;return}Ki([e,A]).with(["pause",!0],()=>{var n;(n=this.activeSession)==null||n.pauseRecording()}).with(["pause",!1],()=>{var n;(n=this.activeSession)==null||n.resumeRecording()}).with(["activate",!1],()=>{this.terminateSession()}).otherwise(()=>{})}render(){if(!this.isActive)return _.nothing;const e=Ki(this.state).with(O.LOADING,()=>_.html`<obi-dot-loader></obi-dot-loader>`).with(O.RESEARCHING,()=>_.html`<obi-searching-loader></obi-searching-loader>`).with(Wm.union(O.USER_SPEAKING,O.AGENT_SPEAKING),()=>_.html`<obi-audio-equalizer .volume=${this.volume}></obi-audio-equalizer>`).with(O.PAUSED,()=>_h).otherwise(()=>_h);return _.html`
495
495
  <div
496
496
  class="widget-container ${this.state===O.USER_SPEAKING||this.state===O.AGENT_SPEAKING?"pulse":""} ${this.state!==O.READY||this.navVisible?"rounded":""} ${this.state===O.RESEARCHING?"researching":""} ${this.state===O.USER_SPEAKING?"user-speaking":""}"
497
497
  @mouseenter=${this.handleMouseEnter}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "obi-sdk",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "description": "JavaScript SDK for Obi",
5
5
  "type": "module",
6
6
  "main": "dist/obi-sdk.umd.js",