UNPKG

@moveo-ai/web-client

Version:

Client side library to load the moveo chat widget and connect it with your agent

2 lines 1.96 kB
/*! For license information please see 929.min.js.LICENSE.txt */ "use strict";(this.webpackChunkMoveoAI=this.webpackChunkMoveoAI||[]).push([[929],{7929:function(e,t,r){r.r(t),r.d(t,{buildWebVoiceWsUrl:function(){return o},fetchWebVoiceConfig:function(){return i}});var n=r(6845);const o=(e,t)=>e.replace(/^https:/,"wss:").replace(/^http:/,"ws:")+`/v1/webvoice/${encodeURIComponent(t)}/rtc`,s=async(e,t)=>{const r=new AbortController,o=setTimeout(()=>r.abort(),1e4);let s;try{s=await fetch(((e,t)=>`${e}/v1/webvoice/${encodeURIComponent(t)}/config`)(e,t),{method:"GET",signal:r.signal})}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)throw new Error("Config request timed out.");throw e}finally{clearTimeout(o)}if(!s.ok){if(404===s.status)throw new Error(`Integration ID "${t}" was not found.`);if(403===s.status)throw new n.Xq("Voice calling is currently unavailable.");if(429===s.status)throw new n.TM;if(503===s.status){let e;try{e=(await s.json()).error_code}catch(e){}if("turn_unavailable"===e||"signing_unavailable"===e)throw new n.Xq("Voice calling is unavailable on this deployment.");if("server_busy"===e)throw new n.PA}throw new Error(`Unable to fetch config (status ${s.status} ${s.statusText}).`)}const i=await s.json();if(!i.iceServers||!i.sessionToken)throw new Error("Invalid config response: missing iceServers or sessionToken");return i},i=async(e,t)=>{let r=0;for(;;)try{return await s(e,t)}catch(e){if(e instanceof n.PA&&r<2){r++,await new Promise(e=>setTimeout(e,500*r));continue}throw e}}},6845:function(e,t,r){r.d(t,{PA:function(){return n},TM:function(){return s},Xq:function(){return o}});class n extends Error{constructor(e="Voice service is busy, please try again."){super(e),this.name="ServerBusyError"}}class o extends Error{constructor(e){super(e),this.name="ConfigUnavailableError"}}class s extends Error{constructor(e="Too many attempts. Please try again in a moment."){super(e),this.name="RateLimitedError"}}}}]);