@94ai/softphone 6.0.2 → 6.0.4

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 +1 @@
1
- import e from"@babel/runtime-corejs3/helpers/esm/classCallCheck";import t from"@babel/runtime-corejs3/helpers/esm/createClass";import{UserAgent as n,SessionState as i,Inviter as r,Registerer as s}from"sip.js";export{Inviter,Registerer,SessionState,URI,UserAgent}from"sip.js";export{SimpleUser}from"sip.js/lib/platform/web/index.js";import a from"on-change";export{default as onChange}from"on-change";import o from"@babel/runtime-corejs3/helpers/esm/typeof";import c from"@babel/runtime-corejs3/regenerator";import l from"@babel/runtime-corejs3/core-js/json/stringify";import u from"@babel/runtime-corejs3/core-js/object/define-property";import h from"@babel/runtime-corejs3/core-js/date/now";import f from"@babel/runtime-corejs3/core-js/instance/for-each";import d from"@babel/runtime-corejs3/core-js/set-timeout";import v from"@babel/runtime-corejs3/core-js/set-interval";import p from"@babel/runtime-corejs3/core-js/promise";import g from"@babel/runtime-corejs3/core-js/object/assign";import m from"@babel/runtime-corejs3/core-js/instance/concat";import b from"@babel/runtime-corejs3/core-js/instance/map";import w from"@babel/runtime-corejs3/core-js/instance/index-of";import y from"@babel/runtime-corejs3/core-js/instance/filter";import k from"@babel/runtime-corejs3/core-js/weak-map";import x from"@babel/runtime-corejs3/core-js/weak-set";import S from"@babel/runtime-corejs3/core-js/object/keys";import T from"@babel/runtime-corejs3/core-js/instance/pad-start";import R from"@babel/runtime-corejs3/core-js/instance/slice";import C from"crypto-js";import I from"@fingerprintjs/fingerprintjs";import A from"@babel/runtime-corejs3/core-js/instance/trim";function D(e,t,n,i){return new(n||(n=Promise))(function(r,s){function a(e){try{c(i.next(e))}catch(e){s(e)}}function o(e){try{c(i.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,o)}c((i=i.apply(e,t||[])).next())})}function E(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)}function M(e,t,n,i,r){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?r.call(e,n):r?r.value=n:t.set(e,n),n}var P,O;"function"==typeof SuppressedError&&SuppressedError;var j,N,B,q,F=m(P="sip:".concat("","@")).call(P,""),H=m(O="".concat("","://")).call(O,""),W={authorizationPassword:"",authorizationUsername:"",viaHost:"",uri:n.makeURI(F),logLevel:"error",transportOptions:{server:H},contactName:""},L={connectStatus:!1,registerStatus:!1,invitatingStatus:!1,incomingStatus:!1,answerStatus:!1,reconnectStatus:!1};function U(e){return document.getElementById(e)}function G(e){if(e&&e.getTracks)try{var t=e.getTracks();f(t).call(t,function(e){try{e.stop()}catch(e){}})}catch(e){}}function z(e){return navigator.mediaDevices.getUserMedia(e).then(function(e){return e?(G(e),!0):p.reject(new Error("EmptyStreamError"))}).catch(function(e){return(!e||"NotAllowedError"!==e.name)&&p.reject(e)})}function X(){try{var e;if(-1===w(e=navigator.userAgent).call(e,"Firefox"))return z({video:!1,audio:!0}).catch(function(){return!0})}catch(e){console.log(e)}}function V(e){var t=U(e);t&&(t.currentTime=0,t.play())}function _(e){var t=U(e);t&&(t.currentTime=0,t.pause())}function Y(e){var t=U(e);t&&(t.srcObject=null,t.pause())}!function(e){e.NO="0",e.YES="1"}(j||(j={})),function(e){e.NO="0",e.YES="1"}(N||(N={})),function(e){e.MULTI_AI="1",e.MULTI_VOICE_NOTIFY="2",e.MULTI_PRETEST="3",e.LABOUR="4",e.AI="5",e.NEW_VOICE_NOTIFY="6"}(B||(B={})),function(e){e.DIRECT_ANSWER="1",e.LISTEN_FIRST_AND_THEN_ANSWER_MANUALLY="2"}(q||(q={}));var J=function(e){var t,n,i;return T(t=e.getHours().toString()).call(t,2,"0")+":"+T(n=e.getMinutes().toString()).call(n,2,"0")+":"+T(i=e.getSeconds().toString()).call(i,2,"0")},K=function(){return new Date(new Date((new Date).toLocaleDateString()).getTime())},$=function(e){return new Date(e.setSeconds(e.getSeconds()+1))};function Z(e){var t=K();e(J(t));var n=v(function(){var n=$(t),i=J(n);e(i)},1e3);return function(){clearInterval(n),n=null}}function Q(e,t,n){var i=window.XMLHttpRequest?new window.XMLHttpRequest:window.ActiveXObject?new window.ActiveXObject("Microsoft.XMLHTTP"):void 0;i||t(new Error("Your Browser does not support ajax")),i.onreadystatechange=function(){if(4==i.readyState){var n=i.response||i.responseText;if(200==i.status){var r=i.getResponseHeader("Content-Type");-1!=w(r).call(r,"json")?e(JSON.parse(i.responseText)):-1!=w(r).call(r,"xml")?e(i.responseXML):e(i.responseText)}else t(n)}};var r=n.url,s=n.data,a=n.type,o=n.contentType,c=a||"POST",u=r,h=null;return s&&("GET"===c?u=u+"?"+function(e){var t=[];for(var n in e)t.push(n+"="+e[n]);return t.join("&")}(s):"POST"===c&&(h=l(s))),i.open(c,u,!0),{xhr:i,ajaxData:h,contentType:o}}var ee,te,ne,ie,re,se,ae,oe,ce,le,ue,he,fe,de,ve,pe,ge,me,be,we,ye,ke,xe,Se,Te,Re,Ce,Ie,Ae,De,Ee,Me,Pe,Oe,je,Ne,Be,qe,Fe,He,We,Le,Ue,Ge,ze,Xe,Ve,_e,Ye,Je,Ke,$e,Ze,Qe,et,tt,nt,it,rt,st,at,ot,ct,lt,ut,ht,ft,dt,vt,pt,gt,mt,bt,wt,yt,kt,xt,St,Tt,Rt,Ct,It,At,Dt,Et,Mt,Pt,Ot,jt,Nt,Bt,qt,Ft,Ht,Wt,Lt,Ut,Gt,zt,Xt,Vt,_t,Yt,Jt,Kt,$t,Zt,Qt,en,tn,nn,rn,sn,an,on,cn,ln,un,hn,fn,dn,vn,pn,gn,mn,bn,wn=function(){return t(function t(n){var r,s,a,o,c,l,f,v,p,g,m,b,w,y,k,x,S,T,R,C=this,I=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,t),u(this,"session",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),u(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),u(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:"idle"}),u(this,"destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),u(this,"bound",{enumerable:!0,configurable:!0,writable:!0,value:!1}),u(this,"hardFailed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),u(this,"retryCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),u(this,"signalingBusyCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),u(this,"disconnectedTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),u(this,"retryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),u(this,"signalingBusyTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),u(this,"negotiationTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),u(this,"iceRecoveryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),u(this,"rtpStatsTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),u(this,"onlineTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),u(this,"transportRecoveryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),u(this,"transportWaitStartedAt",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),u(this,"pendingTransportRecoveryReason",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),u(this,"lastRtpSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),u(this,"lastRtpProgressAt",{enumerable:!0,configurable:!0,writable:!0,value:h()}),u(this,"lastRtpRecoveryAt",{enumerable:!0,configurable:!0,writable:!0,value:0}),u(this,"recoveryGeneration",{enumerable:!0,configurable:!0,writable:!0,value:0}),u(this,"handleSessionStateChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e){switch(C.logInfo("SIP session state:",e),e){case i.Established:C.handleEstablished();break;case i.Terminating:case i.Terminated:C.destroy()}}}),u(this,"handleOffline",{enumerable:!0,configurable:!0,writable:!0,value:function(){C.destroyed||C.hardFailed||(C.logInfo("browser offline"),C.clearDisconnectedTimer(),C.clearRetryTimer(),C.clearSignalingBusyTimer(),C.clearIceRecoveryTimer(),C.clearTransportRecoveryTimer(),"sending-reinvite"!==C.state&&(C.state="idle"))}}),u(this,"handleOnline",{enumerable:!0,configurable:!0,writable:!0,value:function(){C.destroyed||C.hardFailed||(C.logInfo("browser online"),C.onlineTimer&&clearTimeout(C.onlineTimer),C.onlineTimer=d(function(){if(C.onlineTimer=void 0,!C.destroyed&&!C.hardFailed&&C.session.state===i.Established)if(C.isTransportAvailable()){var e=C.getPeerConnection();if(e)if("stable"===e.signalingState)switch(e.iceConnectionState){case"failed":case"disconnected":C.state="idle",C.recover("network-online")}else C.scheduleSignalingBusyRetry("network-online:".concat(e.signalingState))}else C.waitForTransport("network-online")},C.options.onlineRecoveryDelayMs))}}),this.session=n,this.options={disconnectedTimeoutMs:null!==(r=I.disconnectedTimeoutMs)&&void 0!==r?r:3e3,negotiationTimeoutMs:null!==(s=I.negotiationTimeoutMs)&&void 0!==s?s:1e4,iceRecoveryTimeoutMs:null!==(a=I.iceRecoveryTimeoutMs)&&void 0!==a?a:1e4,iceGatheringTimeoutMs:null!==(o=I.iceGatheringTimeoutMs)&&void 0!==o?o:5e3,maxRetries:null!==(c=I.maxRetries)&&void 0!==c?c:3,retryBaseDelayMs:null!==(l=I.retryBaseDelayMs)&&void 0!==l?l:1e3,retryMaxDelayMs:null!==(f=I.retryMaxDelayMs)&&void 0!==f?f:1e4,maxSignalingBusyRetries:null!==(v=I.maxSignalingBusyRetries)&&void 0!==v?v:3,signalingBusyRetryDelayMs:null!==(p=I.signalingBusyRetryDelayMs)&&void 0!==p?p:1e3,enableRtpWatchdog:null===(g=I.enableRtpWatchdog)||void 0===g||g,rtpStatsIntervalMs:null!==(m=I.rtpStatsIntervalMs)&&void 0!==m?m:1e3,rtpStallTimeoutMs:null!==(b=I.rtpStallTimeoutMs)&&void 0!==b?b:8e3,recoverOnRtpStallWhenIceConnected:null===(w=I.recoverOnRtpStallWhenIceConnected)||void 0===w||w,rtpRecoveryCooldownMs:null!==(y=I.rtpRecoveryCooldownMs)&&void 0!==y?y:1e4,onlineRecoveryDelayMs:null!==(k=I.onlineRecoveryDelayMs)&&void 0!==k?k:800,transportRecoveryPollMs:null!==(x=I.transportRecoveryPollMs)&&void 0!==x?x:1e3,transportRecoveryTimeoutMs:null!==(S=I.transportRecoveryTimeoutMs)&&void 0!==S?S:3e4,debugIceCredentials:null!==(T=I.debugIceCredentials)&&void 0!==T&&T,isSignalingAvailable:I.isSignalingAvailable,logger:null!==(R=I.logger)&&void 0!==R?R:console,onRecoveryStart:I.onRecoveryStart,onRecovered:I.onRecovered,onRecoveryFailed:I.onRecoveryFailed}},[{key:"start",value:function(){this.destroyed||this.hardFailed||(this.logInfo("start"),this.session.stateChange.addListener(this.handleSessionStateChange),"undefined"!=typeof window&&(window.addEventListener("online",this.handleOnline),window.addEventListener("offline",this.handleOffline)),this.session.state===i.Established&&this.handleEstablished())}},{key:"restartNow",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"manual";return D(this,void 0,void 0,c.mark(function t(){return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=1,this.recover(e);case 1:case"end":return t.stop()}},t,this)}))}},{key:"getState",value:function(){return this.state}},{key:"getRetryCount",value:function(){return this.retryCount}},{key:"getIceConnectionState",value:function(){var e;return null===(e=this.getPeerConnection())||void 0===e?void 0:e.iceConnectionState}},{key:"destroy",value:function(){if(!this.destroyed){this.destroyed=!0,this.hardFailed=!0,this.recoveryGeneration++,this.state="terminated",this.clearAllTimers(),this.session.stateChange.removeListener(this.handleSessionStateChange),"undefined"!=typeof window&&(window.removeEventListener("online",this.handleOnline),window.removeEventListener("offline",this.handleOffline));var e=this.getSessionDescriptionHandler();e&&this.bound&&(e.peerConnectionDelegate=void 0),this.bound=!1,this.logInfo("destroy")}}},{key:"handleEstablished",value:function(){this.destroyed||this.hardFailed||(this.bindPeerConnectionDelegate(),this.options.enableRtpWatchdog&&this.startRtpWatchdog())}},{key:"bindPeerConnectionDelegate",value:function(){var e=this,t=this.getSessionDescriptionHandler(),n=null==t?void 0:t.peerConnection;t&&n?this.bound||(this.bound=!0,this.logInfo("bind PeerConnection",{iceConnectionState:n.iceConnectionState,connectionState:n.connectionState,signalingState:n.signalingState}),t.peerConnectionDelegate={oniceconnectionstatechange:function(){e.handleIceConnectionStateChange()},onconnectionstatechange:function(){e.logInfo("connectionState:",n.connectionState),"failed"===n.connectionState&&"stable"!==n.signalingState&&e.logWarn("PeerConnection failed while signaling is busy",{signalingState:n.signalingState,iceConnectionState:n.iceConnectionState})},onicegatheringstatechange:function(){e.logDebug("iceGatheringState:",n.iceGatheringState)},onsignalingstatechange:function(){e.logInfo("signalingState:",n.signalingState),"stable"===n.signalingState&&(e.signalingBusyCount=0,"waiting-signaling"!==e.state||e.signalingBusyTimer||(e.state="idle",e.recover("signaling-became-stable"))),"closed"===n.signalingState&&e.destroy()},onicecandidate:function(t){t.candidate?e.logDebug("ICE candidate:",{type:t.candidate.type,protocol:t.candidate.protocol,address:t.candidate.address,port:t.candidate.port}):e.logDebug("ICE candidate gathering complete")}}):this.logWarn("SessionDescriptionHandler / PeerConnection unavailable")}},{key:"handleIceConnectionStateChange",value:function(){if(!this.destroyed&&!this.hardFailed){var e=this.getPeerConnection();if(e){var t=e.iceConnectionState;switch(this.logInfo("iceConnectionState:",t,"recoveryState:",this.state),t){case"new":break;case"checking":this.clearDisconnectedTimer(),"sending-reinvite"!==this.state&&"waiting-ice"!==this.state||(this.state="waiting-ice");break;case"connected":case"completed":this.handleIceRecovered();break;case"disconnected":this.handleIceDisconnected();break;case"failed":this.clearDisconnectedTimer(),this.recover("ice-failed");break;case"closed":this.destroy()}}}}},{key:"handleIceDisconnected",value:function(){var e=this;this.destroyed||this.hardFailed||"sending-reinvite"!==this.state&&"waiting-ice"!==this.state&&(this.disconnectedTimer||(this.state="waiting-disconnected",this.logInfo("ICE disconnected, wait ".concat(this.options.disconnectedTimeoutMs,"ms")),this.disconnectedTimer=d(function(){if(e.disconnectedTimer=void 0,!e.destroyed&&!e.hardFailed){var t=e.getPeerConnection();if(t){if("disconnected"===t.iceConnectionState)return e.state="idle",void e.recover("ice-disconnected-timeout");e.logInfo("ICE self recovered:",t.iceConnectionState),e.state="idle"}}},this.options.disconnectedTimeoutMs)))}},{key:"handleIceRecovered",value:function(){var e,t;if(!this.destroyed&&!this.hardFailed){var n="idle"!==this.state||this.retryCount>0;this.clearDisconnectedTimer(),this.clearRetryTimer(),this.clearSignalingBusyTimer(),this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.clearTransportRecoveryTimer(),this.transportWaitStartedAt=void 0,this.pendingTransportRecoveryReason=void 0,this.state="idle",this.retryCount=0,this.signalingBusyCount=0,this.lastRtpProgressAt=h(),this.lastRtpSnapshot=void 0,this.logInfo("ICE healthy"),n&&(this.logInfo("ICE recovery succeeded"),null===(t=(e=this.options).onRecovered)||void 0===t||t.call(e))}}},{key:"recover",value:function(e){var t,n,r;return D(this,void 0,void 0,c.mark(function s(){var a,o,l,u,h,f=this;return c.wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!this.destroyed&&!this.hardFailed){s.next=1;break}return s.abrupt("return");case 1:if(this.session.state===i.Established){s.next=2;break}return this.logWarn("skip recovery: session not established",this.session.state),s.abrupt("return");case 2:if("undefined"==typeof navigator||!1!==navigator.onLine){s.next=3;break}return this.logWarn("skip recovery: browser offline"),this.state="idle",s.abrupt("return");case 3:if(this.isTransportAvailable()){s.next=4;break}return this.waitForTransport(e),s.abrupt("return");case 4:if("sending-reinvite"!==this.state&&"waiting-ice"!==this.state){s.next=5;break}return this.logDebug("skip recovery: recovery already running"),s.abrupt("return");case 5:if(a=this.getPeerConnection()){s.next=6;break}return s.abrupt("return");case 6:if("stable"===a.signalingState){s.next=7;break}return this.logWarn("skip recovery: signalingState not stable",a.signalingState),this.state="waiting-signaling",this.scheduleSignalingBusyRetry("signaling-busy:".concat(a.signalingState)),s.abrupt("return");case 7:if(this.signalingBusyCount=0,this.clearSignalingBusyTimer(),!(this.retryCount>=this.options.maxRetries)){s.next=8;break}return this.failRecovery("".concat(e,":max-retries")),s.abrupt("return");case 8:return this.clearDisconnectedTimer(),this.clearRetryTimer(),this.retryCount++,o=++this.recoveryGeneration,this.state="sending-reinvite",l=this.readIceCredentials(null===(t=a.localDescription)||void 0===t?void 0:t.sdp),this.logInfo("ICE recovery #".concat(this.retryCount),e),null===(r=(n=this.options).onRecoveryStart)||void 0===r||r.call(n,e,this.retryCount),this.startNegotiationTimeout(o,e),s.prev=9,s.next=10,this.session.invite({sessionDescriptionHandlerOptions:{offerOptions:{iceRestart:!0},iceGatheringTimeout:this.options.iceGatheringTimeoutMs},requestDelegate:{onTrying:function(){f.isCurrentGeneration(o)&&f.logDebug("ICE re-INVITE trying")},onProgress:function(e){f.isCurrentGeneration(o)&&f.logDebug("ICE re-INVITE progress:",e.message.statusCode)},onAccept:function(){var t;if(f.isCurrentGeneration(o)){f.logInfo("ICE re-INVITE accepted"),f.clearNegotiationTimer();var n=f.getPeerConnection();if(n&&"stable"!==n.signalingState&&f.logWarn("re-INVITE accepted but signalingState is not stable",n.signalingState),f.state="waiting-ice",f.options.debugIceCredentials){var i=f.readIceCredentials(null===(t=null==n?void 0:n.localDescription)||void 0===t?void 0:t.sdp);f.logInfo("ICE credentials:",{old:l,new:i,changed:f.hasIceCredentialsChanged(l,i)})}f.startIceRecoveryTimeout(o,e)}},onReject:function(t){f.handleReinviteRejected(o,e,t.message.statusCode,t.message.reasonPhrase)}}});case 10:s.next=18;break;case 11:if(s.prev=11,h=s.catch(9),this.isCurrentGeneration(o)){s.next=12;break}return s.abrupt("return");case 12:return this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.logWarn("ICE re-INVITE error:",h),s.next=13,this.rollbackLocalOffer("invite-exception");case 13:if(u=s.sent,this.isCurrentGeneration(o)){s.next=14;break}return s.abrupt("return");case 14:if(u){s.next=15;break}return this.failRecovery("".concat(e,":rollback-failed:exception")),s.abrupt("return");case 15:if(this.state="idle",this.signalingBusyCount=0,this.isTransportAvailable()){s.next=16;break}return this.waitForTransport("".concat(e,":invite-exception")),s.abrupt("return");case 16:if(!this.isRequestPendingError(h)){s.next=17;break}return this.scheduleRetry("".concat(e,":request-pending"),1500),s.abrupt("return");case 17:this.scheduleRetry("".concat(e,":exception"));case 18:case"end":return s.stop()}},s,this,[[9,11]])}))}},{key:"rollbackLocalOffer",value:function(e){return D(this,void 0,void 0,c.mark(function t(){var n,i,r,s;return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(n=this.getPeerConnection()){t.next=1;break}return t.abrupt("return",!1);case 1:if("stable"!==n.signalingState){t.next=2;break}return t.abrupt("return",!0);case 2:if("have-local-offer"===n.signalingState){t.next=3;break}return this.logWarn("cannot rollback current signaling state",{reason:e,signalingState:n.signalingState}),t.abrupt("return",!1);case 3:return t.prev=3,this.logWarn("rollback local offer",{reason:e,signalingState:n.signalingState}),t.next=4,n.setLocalDescription({type:"rollback"});case 4:return i=n.signalingState,r="stable"===i,this.logInfo("local offer rollback result",{success:r,signalingState:i}),t.abrupt("return",r);case 5:return t.prev=5,s=t.catch(3),this.logError("local offer rollback failed",{reason:e,error:s,signalingState:n.signalingState}),t.abrupt("return",!1);case 6:case"end":return t.stop()}},t,this,[[3,5]])}))}},{key:"handleReinviteRejected",value:function(e,t,n,i){return D(this,void 0,void 0,c.mark(function r(){var s,a,o,l;return c.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(this.isCurrentGeneration(e)){r.next=1;break}return r.abrupt("return");case 1:return this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.logWarn("ICE re-INVITE rejected:",n,i),r.next=2,this.rollbackLocalOffer("sip-".concat(n));case 2:if(a=r.sent,this.isCurrentGeneration(e)){r.next=3;break}return r.abrupt("return");case 3:if(a){r.next=4;break}return this.failRecovery(m(o="".concat(t,":rollback-failed:sip-")).call(o,n)),r.abrupt("return");case 4:if(this.state="idle",this.signalingBusyCount=0,this.isTransportAvailable()){r.next=5;break}return this.waitForTransport(m(l="".concat(t,":sip-")).call(l,n)),r.abrupt("return");case 5:if(491!==n){r.next=6;break}return this.scheduleRetry("".concat(t,":sip-491"),1500),r.abrupt("return");case 6:if(503!==n){r.next=7;break}return this.scheduleRetry("".concat(t,":sip-503"),3e3),r.abrupt("return");case 7:this.scheduleRetry(m(s="".concat(t,":sip-")).call(s,n));case 8:case"end":return r.stop()}},r,this)}))}},{key:"startNegotiationTimeout",value:function(e,t){var n=this;this.clearNegotiationTimer(),this.negotiationTimer=d(function(){if(n.negotiationTimer=void 0,n.isCurrentGeneration(e)){var i=n.getPeerConnection();n.logError("re-INVITE negotiation timeout",{reason:t,signalingState:null==i?void 0:i.signalingState,iceConnectionState:null==i?void 0:i.iceConnectionState,connectionState:null==i?void 0:i.connectionState}),n.failRecovery("".concat(t,":negotiation-timeout"))}},this.options.negotiationTimeoutMs)}},{key:"startIceRecoveryTimeout",value:function(e,t){var n=this;this.clearIceRecoveryTimer(),this.iceRecoveryTimer=d(function(){if(n.iceRecoveryTimer=void 0,n.isCurrentGeneration(e)){var i=n.getPeerConnection();i&&("connected"!==i.iceConnectionState&&"completed"!==i.iceConnectionState?(n.logWarn("ICE recovery timeout",{reason:t,iceConnectionState:i.iceConnectionState,connectionState:i.connectionState,signalingState:i.signalingState}),n.state="idle","stable"===i.signalingState?n.scheduleRetry("".concat(t,":ice-timeout")):n.scheduleSignalingBusyRetry("ice-timeout:".concat(i.signalingState))):n.handleIceRecovered())}},this.options.iceRecoveryTimeoutMs)}},{key:"scheduleRetry",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!this.destroyed&&!this.hardFailed)if(this.retryCount>=this.options.maxRetries)this.failRecovery("".concat(e,":max-retries"));else if(!this.retryTimer){this.state="waiting-retry";var i=this.options.retryBaseDelayMs*Math.pow(2,Math.max(0,this.retryCount-1)),r=Math.min(i,this.options.retryMaxDelayMs),s=Math.floor(500*Math.random()),a=Math.max(r+s,n);this.logInfo("schedule ICE retry in ".concat(a,"ms"),e),this.retryTimer=d(function(){if(t.retryTimer=void 0,!t.destroyed&&!t.hardFailed)if(t.isTransportAvailable()){var n=t.getPeerConnection();if(n)if("connected"!==n.iceConnectionState&&"completed"!==n.iceConnectionState){if("stable"!==n.signalingState)return t.state="waiting-signaling",void t.scheduleSignalingBusyRetry("retry-signaling-busy:".concat(n.signalingState));t.state="idle",t.recover("retry:".concat(e))}else t.handleIceRecovered()}else t.waitForTransport("retry:".concat(e))},a)}}},{key:"scheduleSignalingBusyRetry",value:function(e){var t,n=this;if(!this.destroyed&&!this.hardFailed)if(this.isTransportAvailable()){if(!this.signalingBusyTimer){this.signalingBusyCount++;var r=this.getPeerConnection();if(this.logWarn("signalingState still busy",{reason:e,signalingState:null==r?void 0:r.signalingState,count:this.signalingBusyCount,max:this.options.maxSignalingBusyRetries}),this.signalingBusyCount>this.options.maxSignalingBusyRetries)this.failRecovery("signaling-stuck:".concat(null!==(t=null==r?void 0:r.signalingState)&&void 0!==t?t:"unknown"));else{this.state="waiting-signaling";var s=Math.floor(500*Math.random()),a=this.options.signalingBusyRetryDelayMs+s;this.logInfo("schedule signaling retry in ".concat(a,"ms")),this.signalingBusyTimer=d(function(){if(n.signalingBusyTimer=void 0,!n.destroyed&&!n.hardFailed&&n.session.state===i.Established)if(n.isTransportAvailable()){var e=n.getPeerConnection();if(e)return"stable"===e.signalingState?(n.signalingBusyCount=0,n.state="idle","connected"===e.iceConnectionState||"completed"===e.iceConnectionState?void n.handleIceRecovered():void n.recover("signaling-recovered")):void n.scheduleSignalingBusyRetry("signaling-busy:".concat(e.signalingState))}else n.waitForTransport("signaling-unavailable")},a)}}}else this.waitForTransport(e)}},{key:"isTransportAvailable",value:function(){var e=this.options.isSignalingAvailable;if(!e)return!0;try{return e()}catch(e){return this.logWarn("isSignalingAvailable() threw",e),!1}}},{key:"waitForTransport",value:function(e){var t=this;if(!this.destroyed&&!this.hardFailed){if(this.isTransportAvailable())return this.transportWaitStartedAt=void 0,this.pendingTransportRecoveryReason=void 0,this.clearTransportRecoveryTimer(),this.state="idle",void this.resumeAfterTransportRecovery(e);if(this.state="waiting-transport",void 0===this.transportWaitStartedAt&&(this.transportWaitStartedAt=h(),this.logWarn("SIP Transport unavailable; pause ICE restart",{reason:e,timeoutMs:this.options.transportRecoveryTimeoutMs})),this.pendingTransportRecoveryReason=e,!this.transportRecoveryTimer)h()-this.transportWaitStartedAt>=this.options.transportRecoveryTimeoutMs?this.failRecovery("transport-recovery-timeout:".concat(e)):this.transportRecoveryTimer=d(function(){var n,r;if(t.transportRecoveryTimer=void 0,!t.destroyed&&!t.hardFailed&&t.session.state===i.Established)if(t.isTransportAvailable()){var s=null!==(r=t.pendingTransportRecoveryReason)&&void 0!==r?r:e,a=void 0===t.transportWaitStartedAt?0:h()-t.transportWaitStartedAt;t.transportWaitStartedAt=void 0,t.pendingTransportRecoveryReason=void 0,t.logInfo("SIP Transport recovered",{waitedMs:a,reason:s}),t.state="idle",t.resumeAfterTransportRecovery(s)}else t.waitForTransport(null!==(n=t.pendingTransportRecoveryReason)&&void 0!==n?n:e)},this.options.transportRecoveryPollMs)}}},{key:"resumeAfterTransportRecovery",value:function(e){return D(this,void 0,void 0,c.mark(function t(){var n;return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.destroyed&&!this.hardFailed&&this.session.state===i.Established){t.next=1;break}return t.abrupt("return");case 1:if(this.isTransportAvailable()){t.next=2;break}return this.waitForTransport(e),t.abrupt("return");case 2:if(n=this.getPeerConnection()){t.next=3;break}return t.abrupt("return");case 3:if("connected"!==n.iceConnectionState&&"completed"!==n.iceConnectionState){t.next=4;break}return this.handleIceRecovered(),t.abrupt("return");case 4:if("stable"===n.signalingState){t.next=5;break}return this.state="waiting-signaling",this.scheduleSignalingBusyRetry("transport-restored:".concat(n.signalingState)),t.abrupt("return");case 5:return this.state="idle",t.next=6,this.recover("transport-restored:".concat(e));case 6:case"end":return t.stop()}},t,this)}))}},{key:"failRecovery",value:function(e){var t,n,i,r,s;this.destroyed||this.hardFailed||(this.hardFailed=!0,this.recoveryGeneration++,this.state="failed",this.clearDisconnectedTimer(),this.clearRetryTimer(),this.clearSignalingBusyTimer(),this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.clearTransportRecoveryTimer(),this.transportWaitStartedAt=void 0,this.pendingTransportRecoveryReason=void 0,this.stopRtpWatchdog(),this.logError("ICE recovery unrecoverable",{reason:e,retryCount:this.retryCount,signalingBusyCount:this.signalingBusyCount,iceConnectionState:null===(t=this.getPeerConnection())||void 0===t?void 0:t.iceConnectionState,connectionState:null===(n=this.getPeerConnection())||void 0===n?void 0:n.connectionState,signalingState:null===(i=this.getPeerConnection())||void 0===i?void 0:i.signalingState}),null===(s=(r=this.options).onRecoveryFailed)||void 0===s||s.call(r,e,this.retryCount))}},{key:"startRtpWatchdog",value:function(){var e=this;this.rtpStatsTimer||this.destroyed||this.hardFailed||(this.lastRtpProgressAt=h(),this.rtpStatsTimer=v(function(){e.checkRtpHealth()},this.options.rtpStatsIntervalMs))}},{key:"stopRtpWatchdog",value:function(){this.rtpStatsTimer&&(clearInterval(this.rtpStatsTimer),this.rtpStatsTimer=void 0)}},{key:"checkRtpHealth",value:function(){return D(this,void 0,void 0,c.mark(function e(){var t,n,r,s,a,o,l,u;return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.destroyed&&!this.hardFailed&&this.session.state===i.Established){e.next=1;break}return e.abrupt("return");case 1:if(t=this.getPeerConnection()){e.next=2;break}return e.abrupt("return");case 2:if("connected"===t.iceConnectionState||"completed"===t.iceConnectionState){e.next=3;break}return e.abrupt("return");case 3:if("sending-reinvite"!==this.state&&"waiting-ice"!==this.state&&"waiting-signaling"!==this.state&&"waiting-transport"!==this.state){e.next=4;break}return e.abrupt("return");case 4:return e.prev=4,e.next=5,this.readRtpSnapshot(t);case 5:n=e.sent,e.next=7;break;case 6:return e.prev=6,u=e.catch(4),this.logDebug("getStats failed:",u),e.abrupt("return");case 7:if(n.hasAudio||n.hasVideo){e.next=8;break}return e.abrupt("return");case 8:if(r=this.lastRtpSnapshot,this.lastRtpSnapshot=n,r){e.next=9;break}return this.lastRtpProgressAt=h(),e.abrupt("return");case 9:if(s=n.audioBytes>r.audioBytes||n.audioPackets>r.audioPackets,a=n.videoBytes>r.videoBytes||n.videoPackets>r.videoPackets||n.videoFramesDecoded>r.videoFramesDecoded,!s&&!a){e.next=10;break}return this.lastRtpProgressAt=h(),e.abrupt("return");case 10:if(!((o=h()-this.lastRtpProgressAt)<this.options.rtpStallTimeoutMs)){e.next=11;break}return e.abrupt("return");case 11:if(!((l=h())-this.lastRtpRecoveryAt<this.options.rtpRecoveryCooldownMs)){e.next=12;break}return e.abrupt("return");case 12:if(this.logWarn("RTP stalled for ".concat(o,"ms"),{ice:t.iceConnectionState,connection:t.connectionState,signaling:t.signalingState,audioBytes:n.audioBytes,audioPackets:n.audioPackets,videoBytes:n.videoBytes,videoPackets:n.videoPackets,videoFramesDecoded:n.videoFramesDecoded}),this.options.recoverOnRtpStallWhenIceConnected){e.next=13;break}return e.abrupt("return");case 13:this.lastRtpRecoveryAt=l,this.recover("rtp-stalled");case 14:case"end":return e.stop()}},e,this,[[4,6]])}))}},{key:"readRtpSnapshot",value:function(e){return D(this,void 0,void 0,c.mark(function t(){var n,i;return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=1,e.getStats();case 1:return n=t.sent,i={timestamp:h(),audioBytes:0,audioPackets:0,videoBytes:0,videoPackets:0,videoFramesDecoded:0,hasAudio:!1,hasVideo:!1},f(n).call(n,function(e){var t;if("inbound-rtp"===e.type&&!0!==e.isRemote){var n=null!==(t=e.kind)&&void 0!==t?t:e.mediaType;"audio"===n&&(i.hasAudio=!0,"number"==typeof e.bytesReceived&&(i.audioBytes+=e.bytesReceived),"number"==typeof e.packetsReceived&&(i.audioPackets+=e.packetsReceived)),"video"===n&&(i.hasVideo=!0,"number"==typeof e.bytesReceived&&(i.videoBytes+=e.bytesReceived),"number"==typeof e.packetsReceived&&(i.videoPackets+=e.packetsReceived),"number"==typeof e.framesDecoded&&(i.videoFramesDecoded+=e.framesDecoded))}}),t.abrupt("return",i);case 2:case"end":return t.stop()}},t)}))}},{key:"getSessionDescriptionHandler",value:function(){return this.session.sessionDescriptionHandler}},{key:"getPeerConnection",value:function(){var e;return null===(e=this.getSessionDescriptionHandler())||void 0===e?void 0:e.peerConnection}},{key:"readIceCredentials",value:function(e){var t,n,i,r;return e?{ufrag:null===(n=null===(t=e.match(/^a=ice-ufrag:(.+)$/m))||void 0===t?void 0:t[1])||void 0===n?void 0:A(n).call(n),pwd:null===(r=null===(i=e.match(/^a=ice-pwd:(.+)$/m))||void 0===i?void 0:i[1])||void 0===r?void 0:A(r).call(r)}:{}}},{key:"hasIceCredentialsChanged",value:function(e,t){return e.ufrag!==t.ufrag||e.pwd!==t.pwd}},{key:"isRequestPendingError",value:function(e){return e instanceof Error&&("RequestPendingError"===e.name||/request.*pending/i.test(e.message))}},{key:"isCurrentGeneration",value:function(e){return!this.destroyed&&!this.hardFailed&&e===this.recoveryGeneration}},{key:"clearDisconnectedTimer",value:function(){this.disconnectedTimer&&(clearTimeout(this.disconnectedTimer),this.disconnectedTimer=void 0)}},{key:"clearRetryTimer",value:function(){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0)}},{key:"clearSignalingBusyTimer",value:function(){this.signalingBusyTimer&&(clearTimeout(this.signalingBusyTimer),this.signalingBusyTimer=void 0)}},{key:"clearNegotiationTimer",value:function(){this.negotiationTimer&&(clearTimeout(this.negotiationTimer),this.negotiationTimer=void 0)}},{key:"clearIceRecoveryTimer",value:function(){this.iceRecoveryTimer&&(clearTimeout(this.iceRecoveryTimer),this.iceRecoveryTimer=void 0)}},{key:"clearTransportRecoveryTimer",value:function(){this.transportRecoveryTimer&&(clearTimeout(this.transportRecoveryTimer),this.transportRecoveryTimer=void 0)}},{key:"clearAllTimers",value:function(){this.clearDisconnectedTimer(),this.clearRetryTimer(),this.clearSignalingBusyTimer(),this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.stopRtpWatchdog(),this.onlineTimer&&(clearTimeout(this.onlineTimer),this.onlineTimer=void 0)}},{key:"logDebug",value:function(){for(var e,t,n,i,r=arguments.length,s=new Array(r),a=0;a<r;a++)s[a]=arguments[a];null===(i=(n=this.options.logger).debug)||void 0===i||(e=i).call.apply(e,m(t=[n,"[SipIceRecovery]"]).call(t,s))}},{key:"logInfo",value:function(){for(var e,t,n,i,r=arguments.length,s=new Array(r),a=0;a<r;a++)s[a]=arguments[a];null===(i=(n=this.options.logger).info)||void 0===i||(e=i).call.apply(e,m(t=[n,"[SipIceRecovery]"]).call(t,s))}},{key:"logWarn",value:function(){for(var e,t,n,i,r=arguments.length,s=new Array(r),a=0;a<r;a++)s[a]=arguments[a];null===(i=(n=this.options.logger).warn)||void 0===i||(e=i).call.apply(e,m(t=[n,"[SipIceRecovery]"]).call(t,s))}},{key:"logError",value:function(){for(var e,t,n,i,r=arguments.length,s=new Array(r),a=0;a<r;a++)s[a]=arguments[a];null===(i=(n=this.options.logger).error)||void 0===i||(e=i).call.apply(e,m(t=[n,"[SipIceRecovery]"]).call(t,s))}}])}(),yn=function(){return t(function t(){var r=this,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e(this,t),ee.add(this),te.set(this,void 0),ne.set(this,void 0),ie.set(this,void 0),re.set(this,void 0),se.set(this,void 0),ae.set(this,void 0),oe.set(this,[]),ce.set(this,[]),le.set(this,{}),ue.set(this,void 0),he.set(this,void 0),fe.set(this,new MediaStream),de.set(this,JSON.parse(l(L))),ve.set(this,0),pe.set(this,void 0),ge.set(this,void 0),me.set(this,void 0),u(this,"token",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),be.set(this,void 0),we.set(this,48e4),ye.set(this,12e6),ke.set(this,{}),xe.set(this,void 0),Se.set(this,void 0),Te.set(this,void 0),Re.set(this,function(e){}),Ce.set(this,function(e){}),Ie.set(this,function(e){}),Ae.set(this,function(e){}),De.set(this,function(e){return D(r,void 0,void 0,c.mark(function t(){var n,i,r,s;return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!E(this,pe,"f")||!E(this,ge,"f")){t.next=3;break}if(!(h()-E(this,ge,"f")>e)){t.next=3;break}return t.next=1,E(this,Me,"f").call(this);case 1:if(s=t.sent){t.next=2;break}s={};case 2:i=(n=s).sign,r=n.timestamp,M(this,pe,null!=i?i:E(this,pe,"f"),"f"),M(this,ge,null!=r?r:E(this,ge,"f"),"f");case 3:case"end":return t.stop()}},t,this)}))}),Ee.set(this,function(e){return D(r,void 0,void 0,c.mark(function t(){var n,i,r,s,a;return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!E(this,be,"f")){t.next=4;break}if(!(h()-E(this,be,"f")>e)){t.next=4;break}if(!E(this,me,"f")){t.next=2;break}return t.next=1,E(this,Pe,"f").call(this);case 1:n=t.sent,i=n.token,r=n.tokenTimestamp,M(this,me,null!=i?i:E(this,me,"f"),"f"),M(this,be,null!=r?r:h(),"f"),t.next=4;break;case 2:if(!this.token){t.next=4;break}return t.next=3,this.getGatewayAccessToken({corpId:E(this,tt,"f"),sid:E(this,rt,"f"),secret:E(this,nt,"f"),seatOnline:!1});case 3:s=t.sent,a=s.token,this.token=a,M(this,be,h(),"f");case 4:case"end":return t.stop()}},t,this)}))}),Me.set(this,function(){}),Pe.set(this,function(){}),Oe.set(this,function(e){}),je.set(this,function(e){}),Ne.set(this,void 0),Be.set(this,void 0),u(this,"networkSpeed",{enumerable:!0,configurable:!0,writable:!0,value:"0.00Mb/s"}),u(this,"networkDelay",{enumerable:!0,configurable:!0,writable:!0,value:"0ms"}),u(this,"onLine",{enumerable:!0,configurable:!0,writable:!0,value:navigator.onLine}),u(this,"testspeeding",{enumerable:!0,configurable:!0,writable:!0,value:!1}),u(this,"goodNetworkSpeed",{enumerable:!0,configurable:!0,writable:!0,value:function(){return 1e3*Number(r.networkSpeed.replace("Mb/s",""))>=30}}),u(this,"goodNetworkDelay",{enumerable:!0,configurable:!0,writable:!0,value:function(){return Number(r.networkDelay.replace("ms",""))<=500&&"0ms"!==r.networkDelay}}),u(this,"authorizedMicrophonePermissions",{enumerable:!0,configurable:!0,writable:!0,value:!1}),u(this,"authorizedNotificationPermissions",{enumerable:!0,configurable:!0,writable:!0,value:!1}),qe.set(this,100),Fe.set(this,3),He.set(this,8),We.set(this,2),Le.set(this,0),Ue.set(this,!1),Ge.set(this,void 0),ze.set(this,3),Xe.set(this,3),Ve.set(this,0),_e.set(this,0),Ye.set(this,0),Je.set(this,!1),Ke.set(this,!1),$e.set(this,!1),Ze.set(this,void 0),Qe.set(this,void 0),et.set(this,void 0),tt.set(this,void 0),nt.set(this,void 0),it.set(this,void 0),rt.set(this,void 0),st.set(this,void 0),at.set(this,void 0),ot.set(this,void 0),ct.set(this,void 0),lt.set(this,function(e){E(r,ee,"m",fn).call(r)}),ut.set(this,function(){}),ht.set(this,void 0),ft.set(this,void 0),dt.set(this,!1),vt.set(this,4e3),pt.set(this,4e3),gt.set(this,{}),mt.set(this,!1),bt.set(this,!0),u(this,"ifAutoAnswer",{enumerable:!0,configurable:!0,writable:!0,value:function(){return String(E(r,gt,"f").autoAnswer)===j.YES}}),u(this,"notNeedSendStarDtmf",{enumerable:!0,configurable:!0,writable:!0,value:function(){return String(E(r,gt,"f").afterTransferLabour)===q.DIRECT_ANSWER}}),wt.set(this,function(){if(E(r,bt,"f")){var e;E(r,yt,"f").call(r);var t=new(window.AudioContext||window.webkitAudioContext);M(r,Se,t.createScriptProcessor(2048,1,1),"f"),E(r,Se,"f").onaudioprocess=function(e){for(var t=e.inputBuffer.getChannelData(0),n=0,i=0;i<t.length;++i)n+=t[i]*t[i];M(r,ve,Number(Math.sqrt(n/t.length).toFixed(2)),"f"),E(r,Re,"f").call(r,E(r,ve,"f"))},M(r,Te,new MediaStream,"f"),f(e=r.getSenders()).call(e,function(e){e.track&&E(r,Te,"f").addTrack(e.track)}),M(r,xe,t.createMediaStreamSource(E(r,Te,"f")),"f"),E(r,xe,"f").connect(E(r,Se,"f")),E(r,Se,"f").connect(t.destination)}}),yt.set(this,function(){if(E(r,bt,"f")){if(E(r,xe,"f"))try{E(r,xe,"f").disconnect()}catch(e){console.log(e)}if(E(r,Se,"f"))try{E(r,Se,"f").disconnect()}catch(e){console.log(e)}if(E(r,Te,"f"))try{var e;f(e=E(r,Te,"f").getTracks()).call(e,function(e){e.stop()})}catch(e){console.log(e)}}M(r,xe,void 0,"f"),M(r,Se,void 0,"f"),M(r,Te,void 0,"f"),M(r,ve,0,"f"),E(r,Re,"f").call(r,E(r,ve,"f"))}),u(this,"disposeSoftphoneEnvRequirementCheck",{enumerable:!0,configurable:!0,writable:!0,value:function(){E(r,kt,"f").call(r),window.removeEventListener("offline",E(r,Tt,"f")),window.removeEventListener("online",E(r,St,"f")),window.removeEventListener("unload",r.disposeSoftphoneEnvRequirementCheck)}}),kt.set(this,function(){clearInterval(E(r,Ne,"f")),M(r,Ne,void 0,"f"),clearTimeout(E(r,Be,"f")),M(r,Be,void 0,"f"),r.testspeeding=!1}),u(this,"softphoneEnvCheck",{enumerable:!0,configurable:!0,writable:!0,value:function(){return D(r,void 0,void 0,c.mark(function e(){return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:this.testspeeding||(E(this,xt,"f").call(this),this.oneRoundOfTesting());case 1:case"end":return e.stop()}},e,this)}))}}),xt.set(this,function(){window.addEventListener("offline",E(r,Tt,"f")),window.addEventListener("online",E(r,St,"f")),window.addEventListener("unload",r.disposeSoftphoneEnvRequirementCheck)}),u(this,"oneRoundOfTesting",{enumerable:!0,configurable:!0,writable:!0,value:function(){return D(r,void 0,void 0,c.mark(function e(){var t=this;return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:this.testspeeding=!0,this.detectNavigatorPermissions(),this.onLine?(E(this,Rt,"f").call(this,this),M(this,Be,d(function(){t.testspeeding=!1,t.disposeSoftphoneEnvRequirementCheck()},4e3),"f")):this.testspeeding=!1;case 1:case"end":return e.stop()}},e,this)}))}}),St.set(this,function(){r.onLine=!0,r.oneRoundOfTesting()}),Tt.set(this,function(){r.onLine=!1,r.networkSpeed="0.00Mb/s",r.networkDelay="0ms",E(r,je,"f").call(r,{networkSpeed:r.networkSpeed,networkDelay:r.networkDelay,authorizedMicrophonePermissions:r.authorizedMicrophonePermissions,authorizedNotificationPermissions:r.authorizedNotificationPermissions}),E(r,kt,"f").call(r)}),Rt.set(this,function(e){return D(r,void 0,void 0,c.mark(function t(){var n,i,r=this;return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=e||this,clearInterval(E(n,Ne,"f")),M(n,Ne,void 0,"f"),i=function(){return D(r,void 0,void 0,c.mark(function e(){var t;return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!n.onLine){e.next=5;break}return e.prev=1,e.next=2,E(n,Ct,"f").call(n,"1"===E(n,ot,"f")?"https://seat.teleai.com/favicon.png":void 0);case 2:t=e.sent,n.networkSpeed=t.networkSpeed,n.networkDelay=t.networkDelay,e.next=4;break;case 3:e.prev=3,e.catch(1),n.networkSpeed="0.00Mb/s",n.networkDelay="0ms";case 4:e.next=6;break;case 5:n.networkSpeed="0.00Mb/s",n.networkDelay="0ms";case 6:E(this,je,"f").call(this,{networkSpeed:this.networkSpeed,networkDelay:this.networkDelay,authorizedMicrophonePermissions:this.authorizedMicrophonePermissions,authorizedNotificationPermissions:this.authorizedNotificationPermissions}),E(this,Be,"f")||(this.testspeeding=!1,this.disposeSoftphoneEnvRequirementCheck());case 7:case"end":return e.stop()}},e,this,[[1,3]])}))},t.next=1,i();case 1:E(this,Be,"f")&&M(n,Ne,v(function(){return D(this,void 0,void 0,c.mark(function e(){return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,i();case 1:case"end":return e.stop()}},e)}))},1e3),"f");case 2:case"end":return t.stop()}},t,this)}))}),Ct.set(this,function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"https://seat.94ai.com/favicon.png",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:63491,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;return D(r,void 0,void 0,c.mark(function i(){var r,s;return c.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:for(r=[],s=0;s<n;s++)r.push(E(this,It,"f").call(this,e+"?d="+h()+s,t));return i.abrupt("return",p.all(r).then(function(e){var t=0,i=0;return f(e).call(e,function(e){t+=Number(e[0]),i+=Number(e[1])}),{networkDelay:(i/n).toFixed(2)+"ms",networkSpeed:(t/n).toFixed(2)+"Mb/s"}}));case 1:case"end":return i.stop()}},i,this)}))}),It.set(this,function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"https://seat.94ai.com/favicon.png?d="+h(),t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:63491;return new p(function(n,i){var r=document.createElement("img");r.start=window.performance.now(),r.onload=function(){var e=window.performance.now()-r.start;n([(1e3*t/(1048576*e)).toFixed(2),e])},r.onerror=function(e){i(e)},r.src=e}).catch(function(e){throw e})}),u(this,"openApiAjax",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return new p(function(t,n){return D(r,void 0,void 0,c.mark(function i(){var r,s,a,o,l,u,f,d,v,p,g,m,b,w,y,k,x;return c.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(i.prev=0,v=E(this,tt,"f")||(null===(r=e.data)||void 0===r?void 0:r.appKey),p=E(this,nt,"f")||(null===(s=e.data)||void 0===s?void 0:s.appSecret),g=E(this,pe,"f")||(null===(a=e.data)||void 0===a?void 0:a.sign),m=E(this,ge,"f")||(null===(o=e.data)||void 0===o?void 0:o.timestamp),null===(l=e.data)||void 0===l||delete l.appKey,null===(u=e.data)||void 0===u||delete u.appSecret,null===(f=e.data)||void 0===f||delete f.sign,null===(d=e.data)||void 0===d||delete d.timestamp,v){i.next=1;break}throw new Error("缺少appKey");case 1:if(!p){i.next=2;break}m=h(),g=C.enc.Base64.stringify(C.HmacSHA1(v+m,p)),i.next=5;break;case 2:if(!g||!m){i.next=4;break}return i.next=3,E(this,De,"f").call(this,E(this,we,"f"));case 3:g=E(this,pe,"f")||g,m=E(this,ge,"f")||m,i.next=5;break;case 4:throw new Error("缺少appSecret或sign+timestamp");case 5:return b=Q(t,n,e),w=b.xhr,y=b.ajaxData,k=b.contentType,w.setRequestHeader("appKey",v),w.setRequestHeader("timestamp",String(m)),w.setRequestHeader("sign",g),w.setRequestHeader("Content-type",k||"application/json"),i.next=6,E(this,Ie,"f").call(this,w);case 6:w.send(y),i.next=8;break;case 7:throw i.prev=7,x=i.catch(0),n(x.message),x;case 8:case"end":return i.stop()}},i,this,[[0,7]])}))})}}),u(this,"requestGateway",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return r.gatewayApiAjax(g(g({},e),{url:r.getGateway()+e.url}),t)}}),u(this,"gatewayApiAjax",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return new p(function(n,i){return D(r,void 0,void 0,c.mark(function r(){var s,a,o,l,u,h;return c.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(r.prev=0,s=Q(n,i,e),a=s.xhr,o=s.ajaxData,l=s.contentType,!t){r.next=2;break}return r.next=1,this.getGatewayToken();case 1:u=r.sent,a.setRequestHeader("x-token",u),a.setRequestHeader("seatsToken",u),a.setRequestHeader("x-authority-token",u);case 2:return a.setRequestHeader("x-app-code",3),a.setRequestHeader("content-type",l||"application/json"),r.next=3,E(this,Ae,"f").call(this,a);case 3:a.send(o),r.next=5;break;case 4:throw r.prev=4,h=r.catch(0),i(h.message),h;case 5:case"end":return r.stop()}},r,this,[[0,4]])}))})}}),u(this,"requestOpenApi",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return r.openApiAjax(g(g({},e),{url:r.getOpenApi()+e.url}))}}),u(this,"getDeviceId",{enumerable:!0,configurable:!0,writable:!0,value:function(){return D(r,void 0,void 0,c.mark(function e(){var t,n;return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!E(this,ct,"f")){e.next=1;break}return e.abrupt("return",E(this,ct,"f"));case 1:return e.next=2,I.load();case 2:return t=e.sent,e.next=3,t.get();case 3:return n=e.sent,M(this,ct,n.visitorId,"f"),e.abrupt("return",E(this,ct,"f"));case 4:case"end":return e.stop()}},e,this)}))}}),Nt.set(this,function(){return D(r,void 0,void 0,c.mark(function e(){var t,i,r,s;return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!E(this,ee,"m",jt).call(this)||E(this,le,"f").authorizationUsername&&E(this,le,"f").uri&&E(this,le,"f").authorizationPassword&&E(this,le,"f").transportOptions.server){e.next=3;break}return e.next=1,this.getAgentInfo();case 1:if(200!=(t=e.sent).code){e.next=2;break}s=t.data,E(this,le,"f").authorizationUsername=s.agentExtension,E(this,le,"f").authorizationPassword=s.extensionPwd,E(this,le,"f").contactName||(E(this,le,"f").contactName=s.agentExtension),E(this,le,"f").uri=n.makeURI(m(i="sip:".concat(s.agentExtension,"@")).call(i,s.wsRegisterAddress)),E(this,le,"f").transportOptions.server=m(r="".concat(s.wsProtocol,"://")).call(r,s.wsRegisterAddress),M(this,rt,s.agentId,"f"),M(this,it,s.agentTag,"f"),e.next=3;break;case 2:throw new Error(l(t));case 3:case"end":return e.stop()}},e,this)}))}),Bt.set(this,function(){return D(r,void 0,void 0,c.mark(function e(){var t;return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(E(this,le,"f").viaHost){e.next=2;break}return t="",e.next=1,this.getDeviceId();case 1:E(this,le,"f").viaHost=m(t).call(t,e.sent,".sip");case 2:case"end":return e.stop()}},e,this)}))}),Ft.set(this,function(e){var t,n,i,s,a,o,c,l,u,h,f,d,v,p,g,m,w,y,k,x,S,T,R;E(r,gt,"f").popWindow=null===(a=e["X-Popwindow"])||void 0===a?void 0:a[0].raw,E(r,gt,"f").afterTransferLabour=null===(o=e["X-Aftertransferlabour"])||void 0===o?void 0:o[0].raw,E(r,gt,"f").callId=null===(c=e["X-94callid"])||void 0===c?void 0:c[0].raw,E(r,gt,"f").cid=null===(l=e["X-Cid"])||void 0===l?void 0:l[0].raw,E(r,gt,"f").numberId=null===(u=e["X-Numberid"])||void 0===u?void 0:u[0].raw,E(r,gt,"f").tag=(null===(h=e["X-Tag"])||void 0===h?void 0:h[0].raw)&&"null"!==(null===(f=e["X-Tag"])||void 0===f?void 0:f[0].raw)?b(t=e["X-Tag"][0].raw.split("-")).call(t,function(e){return String.fromCharCode(e)}).join(""):"",E(r,gt,"f").numberTag=(null===(d=e["X-Numbertag"])||void 0===d?void 0:d[0].raw)&&"null"!==(null===(v=e["X-Numbertag"])||void 0===v?void 0:v[0].raw)?decodeURIComponent(e["X-Numbertag"][0].raw):"",E(r,gt,"f").taskId=null===(p=e["X-Taskid"])||void 0===p?void 0:p[0].raw,E(r,gt,"f").voiceType=null===(g=e["X-Voicetype"])||void 0===g?void 0:g[0].raw,E(r,gt,"f").processTime=null===(m=e["X-Processtime"])||void 0===m?void 0:m[0].raw,E(r,gt,"f").userPhone=null===(w=e["X-Userphone"])||void 0===w?void 0:w[0].raw,E(r,gt,"f").autoAnswer=null===(y=e["X-94autoanswer"])||void 0===y?void 0:y[0].raw,E(r,gt,"f").nodeTitle=null===(k=e["X-Nodetitle"])||void 0===k?void 0:b(n=k[0].raw.split("-")).call(n,function(e){return String.fromCharCode(e)}).join(""),E(r,gt,"f").taskName=null===(x=e["X-Taskname"])||void 0===x?void 0:b(i=x[0].raw.split("-")).call(i,function(e){return String.fromCharCode(e)}).join(""),E(r,gt,"f").templateTitle=null===(S=e["X-Templatetitle"])||void 0===S?void 0:b(s=S[0].raw.split("-")).call(s,function(e){return String.fromCharCode(e)}).join(""),E(r,gt,"f").phoneNumber=(null===(T=e["X-Phonenumber"])||void 0===T?void 0:T[0].raw)||(null===(R=e.From)||void 0===R?void 0:R[0].parsed.uri.normal.user)}),Zt.set(this,function(e){switch(e){case i.Initial:case i.Establishing:break;case i.Established:E(r,ee,"m",$t).call(r);break;case i.Terminating:case i.Terminated:r.clearIceAutoDetection();var t=d(function(){clearTimeout(t),t=void 0,E(r,de,"f").incomingStatus=!1,E(r,de,"f").answerStatus=!1},10);E(r,yt,"f").call(r);break;default:throw new Error("Unknown session state.")}}),en.set(this,function(e,t,n){E(r,He,"f")&&(M(r,Ue,!1,"f"),E(r,de,"f").reconnectStatus=!1,E(r,Ke,"f")&&(M(r,Ke,!1,"f"),E(r,rn,"f").call(r,e,t,n)))}),tn.set(this,function(){return D(r,void 0,void 0,c.mark(function e(){return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(E(this,He,"f")){M(this,Ue,!0,"f"),M(this,Ke,!1,"f");try{this.getUserAgent().transport.disconnect().catch(function(e){return console.error(e)})}catch(e){}console.log("sip transport disconnect");try{E(this,ee,"m",Qt).call(this)}catch(e){}E(this,sn,"f").call(this),E(this,ee,"m",fn).call(this)}case 1:case"end":return e.stop()}},e,this)}))}),nn.set(this,function(){if(E(r,He,"f")){var e=E(r,le,"f").uri.clone(),t=E(r,le,"f").uri.clone(),n=E(r,le,"f").uri.clone();n.user=void 0,E(r,rn,"f").call(r,n,e,t)}}),rn.set(this,function(e,t,n){if(E(r,He,"f")){if(E(r,Ke,"f"))return;M(r,Ke,!0,"f"),M(r,Qe,d(function(){E(r,ee,"m",un).call(r);var i=r.getUserAgent().userAgentCore,s=i.makeOutgoingRequestMessage("OPTIONS",e,t,n,{});M(r,Ge,i.request(s,{onAccept:function(){console.log("sip ping ok"),M(r,Le,0,"f"),M(r,Ge,void 0,"f"),E(r,en,"f").call(r,e,t,n)},onReject:function(i){var s;if(M(r,Ge,void 0,"f"),408===i.message.statusCode||503===i.message.statusCode)if(console.log("sip ping error with code "+i.message.statusCode),E(r,We,"f")>0&&E(r,Le,"f")>=E(r,We,"f"))console.log("sip maximum ping attempts reached"),E(r,tn,"f").call(r);else{var a,o;if(E(r,Le,"f")>0)console.log(m(o="sip ping retry ".concat(E(r,Le,"f")," of ")).call(o,E(r,We,"f")," fail"));M(r,Le,(s=E(r,Le,"f"),++s),"f"),console.log(m(a="sip ping retry ".concat(E(r,Le,"f")," of ")).call(a,E(r,We,"f"))),E(r,en,"f").call(r,e,t,n)}else M(r,Le,0,"f"),E(r,en,"f").call(r,e,t,n)}}),"f")},1e3*E(r,He,"f")),"f")}}),sn.set(this,function(){if(E(r,He,"f")){if(M(r,Ke,!1,"f"),M(r,Ue,!1,"f"),E(r,Ge,"f")){try{E(r,Ge,"f").dispose()}catch(e){}M(r,Ge,void 0,"f")}E(r,Qe,"f")&&E(r,ee,"m",un).call(r)}}),hn.set(this,function(){if(E(r,ze,"f")){if(E(r,$e,"f"))return;M(r,$e,!0,"f"),E(r,de,"f").reconnectStatus=!0,M(r,et,d(function(){return D(r,void 0,void 0,c.mark(function e(){var t,n=this;return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,E(this,ee,"m",cn).call(this),0===E(this,Ve,"f")&&console.log("sip reconnect success then register start"),e.next=1,E(this,re,"f").register({requestDelegate:{onAccept:function(e){console.log("sip reconnect success and register ok"),M(n,Ve,0,"f"),M(n,$e,!1,"f"),E(n,de,"f").registerStatus=!0,E(n,de,"f").reconnectStatus=!1,E(n,nn,"f").call(n)},onReject:function(e){return D(n,void 0,void 0,c.mark(function t(){var n,i;return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(console.log("sip reconnect success but register fail with code "+e.message.statusCode),M(this,$e,!1,"f"),!(E(this,Xe,"f")<=E(this,Ve,"f"))){t.next=2;break}return console.log("sip maximum register attempts reached"),M(this,Ve,0,"f"),t.next=1,this.getUserAgent().transport.disconnect().catch(function(e){return console.error(e)});case 1:E(this,ee,"m",fn).call(this),t.next=3;break;case 2:M(this,Ve,(n=E(this,Ve,"f"),++n),"f"),console.log(m(i="sip reconnect success and register retry ".concat(E(this,Ve,"f")," of ")).call(i,E(this,Xe,"f"))),E(this,hn,"f").call(this);case 3:case"end":return t.stop()}},t,this)}))}},requestOptions:{extraHeaders:E(this,ne,"f")}});case 1:e.next=3;break;case 2:e.prev=2,t=e.catch(0),console.log("sip reconnect then registerer register error",t),M(this,Ve,0,"f"),M(this,$e,!1,"f");case 3:case"end":return e.stop()}},e,this,[[0,2]])}))},1e3*E(r,ze,"f")),"f")}}),"object"!==o(s))throw new Error("userAgentOption must be plain object");E(this,ee,"m",Mt).call(this,s),E(this,ee,"m",Pt).call(this,s),E(this,ee,"m",Et).call(this,s),E(this,ee,"m",Ot).call(this,s),E(this,ee,"m",Wt).call(this,s),E(this,ee,"m",Dt).call(this,s),E(this,ee,"m",At).call(this,s),M(this,le,E(this,ee,"m",Ut).call(this,s),"f")},[{key:"volumeValue",get:function(){return E(this,ve,"f")}},{key:"businessAttribute",get:function(){return E(this,gt,"f")}},{key:"getFastOutboundCall",value:function(){return E(this,gt,"f").voiceType===B.LABOUR}},{key:"getSitOutboundCall",value:function(){return E(this,gt,"f").voiceType===B.AI}},{key:"detectNavigatorPermissions",value:function(){var e,t=this;-1===w(e=navigator.userAgent).call(e,"Firefox")?navigator.permissions.query({name:"microphone"}).then(function(e){"granted"===e.state?t.authorizedMicrophonePermissions=!0:t.authorizedMicrophonePermissions=!1}).catch(function(e){console.log("Got error :",e),t.authorizedMicrophonePermissions=!1}):navigator.mediaDevices.enumerateDevices().then(function(e){""!==y(e).call(e,function(e){return"audioinput"===e.kind})[0].label?t.authorizedMicrophonePermissions=!0:t.authorizedMicrophonePermissions=!1}),navigator.permissions.query({name:"notifications"}).then(function(e){"granted"===e.state?t.authorizedNotificationPermissions=!0:t.authorizedNotificationPermissions=!1}).catch(function(e){console.log("Got error :",e),t.authorizedNotificationPermissions=!1})}},{key:"getGateway",value:function(){return"1"===E(this,ot,"f")?"https://gateway.teleai.com":"https://gateway.94ai.com"}},{key:"getGatewayToken",value:function(){return D(this,void 0,void 0,c.mark(function e(){var t,n;return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,E(this,Ee,"f").call(this,E(this,ye,"f"));case 1:if(!E(this,me,"f")){e.next=2;break}return e.abrupt("return",E(this,me,"f"));case 2:if(this.token){e.next=5;break}return e.next=3,E(this,Nt,"f").call(this);case 3:return e.next=4,this.getGatewayAccessToken({corpId:E(this,tt,"f"),sid:E(this,rt,"f"),secret:E(this,nt,"f"),seatOnline:!1});case 4:t=e.sent,n=t.token,this.token=n,M(this,be,h(),"f");case 5:return e.abrupt("return",this.token);case 6:case"end":return e.stop()}},e,this)}))}},{key:"getGatewayAccessToken",value:function(e){return this.requestGateway({url:"/authority/accessToken/openApi",data:e},!1)}},{key:"getCallNumberDetail",value:function(e){return this.requestGateway({url:"/task-aggre/callCenterNumber/get",data:e})}},{key:"getCallNumberChats",value:function(e){return this.requestGateway({url:"/dialogue-aggre/call-center-number/chat/list",data:e})}},{key:"getCallInfo",value:function(){return D(this,void 0,void 0,c.mark(function e(){var t,n,i,r=this;return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t=g({},E(this,gt,"f")),n=function(){return D(r,void 0,void 0,c.mark(function e(){var n,i,r,s,a,o,l,u,h,f,d,v,p,g,w,y,k,x,S,T;return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.numberId||!t.taskId){e.next=13;break}return n={},e.prev=1,e.next=2,this.getCallNumberDetail({id:t.numberId,taskId:t.taskId});case 2:if(200===(n=e.sent).code){e.next=3;break}return console.error(n.message),t.stop=!0,E(this,Oe,"f").call(this,n.message),e.abrupt("return");case 3:e.next=5;break;case 4:return e.prev=4,e.catch(1),s=m(i=m(r="当前会话callid:".concat(t.callId,",根据numberId:")).call(r,t.numberId,",taskId:")).call(i,t.taskId,":查询坐席接听状态异常"),console.error(s),t.stop=!0,E(this,Oe,"f").call(this,n.message),e.abrupt("return");case 5:if(a=n.data,o=a.callType,l=a.newIntentTag,u=a.intentTag,h=a.number,f=a.numberMd5,d=a.sid,v=a.config,p=a.tag,10!==a.state){e.next=6;break}return console.log("当前会话callid:".concat(t.callId,"已结束")),t.stop=!0,e.abrupt("return");case 6:if(t.callType||(t.callType=o),t.intentTag=l||u,t.number||(t.number=h),t.numberMD5||(t.numberMD5=f),t.agentId||(t.agentId=d),t.tag||(t.tag=p),t.templateId||v&&"string"==typeof v&&(g=JSON.parse(v))&&g.templateId&&(t.templateId=g.templateId),!t.callId){e.next=12;break}return y={},e.prev=7,e.next=8,this.getCallNumberChats({callId:t.callId,taskId:t.taskId});case 8:if(200===(y=e.sent).code){e.next=9;break}return console.error(y.message),t.stop=!0,E(this,Oe,"f").call(this,y.message),e.abrupt("return");case 9:e.next=11;break;case 10:return e.prev=10,e.catch(7),x=m(k="当前会话根据callId:".concat(t.callId,",taskId:")).call(k,t.taskId,":查询会话对话记录异常"),console.error(x),t.stop=!0,E(this,Oe,"f").call(this,x),e.abrupt("return");case 11:t.chats=b(w=y.data).call(w,function(e){return e.matchinfo&&(e.matchinfo=JSON.parse(e.matchinfo)),e}),E(this,ke,"f")[t.callId]=t;case 12:try{E(this,Ce,"f").call(this,E(this,ke,"f")[t.callId])}catch(e){console.log(e)}e.next=14;break;case 13:t.stop=!0,t.taskId||(S="当前会话callid:".concat(t.callId,"的taskId不存在,无法查询通话记录"),console.error(S),E(this,Oe,"f").call(this,S)),t.numberId||(T="当前会话callid:".concat(t.callId,"的numberId不存在,无法查询通话记录"),console.error(T),E(this,Oe,"f").call(this,T));case 14:case"end":return e.stop()}},e,this,[[1,4],[7,10]])}))},e.prev=1;case 2:if(!t.stop){e.next=3;break}return e.abrupt("continue",7);case 3:return e.next=4,n();case 4:if(!t.stop){e.next=5;break}return e.abrupt("continue",7);case 5:return e.next=6,new p(function(e){var t=d(function(){return D(r,void 0,void 0,c.mark(function n(){return c.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:clearTimeout(t),t=void 0,e(!0);case 1:case"end":return n.stop()}},n)}))},3e3)});case 6:e.next=2;break;case 7:e.next=9;break;case 8:e.prev=8,i=e.catch(1),E(this,Oe,"f").call(this,i);case 9:case"end":return e.stop()}},e,this,[[1,8]])}))}},{key:"refreshCallChatInfo",value:function(){return D(this,void 0,void 0,c.mark(function e(){return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!(E(this,gt,"f").numberId&&E(this,gt,"f").callId&&E(this,gt,"f").taskId&&E(this,mt,"f"))){e.next=1;break}return e.next=1,this.getCallInfo();case 1:case"end":return e.stop()}},e,this)}))}},{key:"getOpenApi",value:function(){return function(e){if(!e)return!1;var t=/^[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z]{2,}$/;return!!/^(\d{1,3}\.){3}\d{1,3}$/.test(e)||("//"===R(e).call(e,0,2)?t.test(R(e).call(e,2,e.length)):"http://"===R(e).call(e,0,7)?t.test(R(e).call(e,7,e.length)):"https://"===R(e).call(e,0,8)?t.test(R(e).call(e,8,e.length)):t.test(e))}(E(this,st,"f"))?E(this,st,"f"):"1"===E(this,ot,"f")?"1"===E(this,at,"f")?"https://seat.teleai.com/teleaiopenapi":"https://seat.teleai.com/openapi":"1"===E(this,at,"f")?"https://seat.94ai.com/teleaiopenapi":"https://seat.94ai.com/openapi"}},{key:"getAgentInfo",value:function(){return this.requestOpenApi({url:"/v1/agent/getAgent",data:{agentTag:E(this,it,"f"),agentId:E(this,rt,"f")}})}},{key:"updateOpenApiAgentStatus",value:function(e){return this.requestOpenApi({url:"/v1/agent/updateAgentStatus",data:{agentTag:E(this,it,"f"),agentId:E(this,rt,"f"),agentStatus:e}})}},{key:"importOpenApiAgentCustomer",value:function(e){return this.requestOpenApi({url:"/v1/task/importAgentCustomer",data:{agentTag:E(this,it,"f"),agentId:E(this,rt,"f"),callType:1001,customers:[{number:e}]}})}},{key:"callNumber",value:function(e){return this.importOpenApiAgentCustomer(e)}},{key:"toggleNap",value:function(e){return e?this.updateOpenApiAgentStatus(3):this.updateOpenApiAgentStatus(1)}},{key:"refreshSign",value:function(e){M(this,pe,e,"f")}},{key:"refreshTimestamp",value:function(e){M(this,ge,e,"f")}},{key:"prepareUserAgent",value:function(e,t){var n;return D(this,void 0,void 0,c.mark(function i(){var r,s,a,o,l,u,h,f,d,v,p,m;return c.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return s=(r=e||{}).refresh,a=r.registererOptions,o=r.registererRegisterOptions,l=r.extraHeaders,u=r.authorizationUsername,h=r.authorizationPassword,f=r.uri,d=r.contactName,v=r.transportOptions,i.next=1,this.dispose();case 1:return E(this,le,"f").uri=null!=f?f:E(this,le,"f").uri,E(this,le,"f").authorizationUsername=null!=u?u:E(this,le,"f").authorizationUsername,E(this,le,"f").authorizationPassword=null!=h?h:E(this,le,"f").authorizationPassword,E(this,le,"f").contactName=null!==(n=null!=d?d:u)&&void 0!==n?n:E(this,le,"f").contactName,v&&(E(this,le,"f").transportOptions=g(g({},E(this,le,"f").transportOptions),v)),i.prev=2,E(this,ee,"m",Pt).call(this,e),i.next=3,E(this,Nt,"f").call(this);case 3:return i.next=4,E(this,Bt,"f").call(this);case 4:return E(this,ee,"m",Ht).call(this,{refresh:s}),i.next=5,E(this,ee,"m",pn).call(this);case 5:return t&&E(this,ee,"m",vn).call(this,t),i.next=6,E(this,ee,"m",gn).call(this,{registererOptions:a,registererRegisterOptions:o,extraHeaders:l},E(this,dt,"f"));case 6:return p=i.sent,i.abrupt("return",p);case 7:return i.prev=7,m=i.catch(2),i.next=8,this.dispose();case 8:throw m;case 9:case"end":return i.stop()}},i,this,[[2,7]])}))}},{key:"dispose",value:function(){return D(this,void 0,void 0,c.mark(function e(){var t;return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,E(this,ee,"m",qt).call(this),e.next=1,E(this,ee,"m",zt).call(this);case 1:e.next=3;break;case 2:e.prev=2,t=e.catch(0),E(this,ee,"m",Vt).call(this),console.log("sip dispose with error",t);case 3:case"end":return e.stop()}},e,this,[[0,2]])}))}},{key:"ignoreInvite",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return D(this,void 0,void 0,c.mark(function t(){return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return E(this,de,"f").incomingStatus=!1,t.next=1,this.getCurrentInvitation().reject(e);case 1:case"end":return t.stop()}},t,this)}))}},{key:"acceptInvite",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return D(this,void 0,void 0,c.mark(function t(){var n,i=this;return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=1,new p(function(t,n){D(i,void 0,void 0,c.mark(function i(){var r,s,a;return c.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return i.prev=0,r=null==e?void 0:e.onAck,s=null==e?void 0:e.onAckTimeout,null==e||delete e.onAck,null==e||delete e.onAckTimeout,i.next=1,this.getCurrentInvitation().accept(g({sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}},onAck:function(e){t(e),null==r||r()},onAckTimeout:function(){null==s||s(),n("接听响应超时")}},e||{}));case 1:i.next=3;break;case 2:i.prev=2,a=i.catch(0),n(a);case 3:case"end":return i.stop()}},i,this,[[0,2]])}))});case 1:E(this,de,"f").incomingStatus&&(E(this,de,"f").incomingStatus=!1,E(this,de,"f").answerStatus=!0),t.next=3;break;case 2:throw t.prev=2,n=t.catch(0),E(this,de,"f").incomingStatus=!1,n;case 3:case"end":return t.stop()}},t,this,[[0,2]])}))}},{key:"hangUpInvite",value:function(e){return D(this,void 0,void 0,c.mark(function t(){var n,r,s,a,o,l=this;return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=(n=e||{}).rejectOptions,s=n.byeOptions,a=n.extraHeaders,o=n.scoutResponse,t.abrupt("return",new p(function(e,t){return D(l,void 0,void 0,c.mark(function n(){var l,u,h,f,d,v,p,m,b,w,y;return c.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:n.prev=0,p=null===(l=(v=s||{}).requestDelegate)||void 0===l?void 0:l.onAccept,m=null===(u=v.requestDelegate)||void 0===u?void 0:u.onReject,null===(h=v.requestDelegate)||void 0===h||delete h.onAccept,null===(f=v.requestDelegate)||void 0===f||delete f.onReject,b=E(this,ee,"m",Lt).call(this,{onAccept:function(t){console.log("sip bye success"),e(t),null==p||p(t)},onReject:function(e){null==m||m(e),t("sip bye fail with code "+e.message.statusCode)}},v.requestDelegate),delete v.requestDelegate,w=null===(d=E(this,ue,"f"))||void 0===d?void 0:d.state,n.next=w===i.Initial||w===i.Establishing?1:w===i.Established?3:w===i.Terminating||w===i.Terminated?5:6;break;case 1:return n.next=2,E(this,ue,"f").reject(g({extraHeaders:a},r||{}));case 2:return e(!0),n.abrupt("continue",6);case 3:return n.next=4,E(this,ue,"f").bye(g({requestDelegate:b,requestOptions:{extraHeaders:a}},v));case 4:return o||e(!0),n.abrupt("continue",6);case 5:return e(!0),n.abrupt("continue",6);case 6:n.next=8;break;case 7:n.prev=7,y=n.catch(0),t(y);case 8:return n.prev=8,E(this,de,"f").incomingStatus=!1,E(this,de,"f").answerStatus=!1,n.finish(8);case 9:case"end":return n.stop()}},n,this,[[0,7,8,9]])}))}));case 1:case"end":return t.stop()}},t)}))}},{key:"sendStarDtmf",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return D(this,void 0,void 0,c.mark(function t(){var n=this;return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new p(function(t,i){return D(n,void 0,void 0,c.mark(function n(){var r,s,a,o,l;return c.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,s=(r=e||{}).extraHeaders,a=r.requestDelegate,o=E(this,ee,"m",Lt).call(this,{onAccept:function(e){console.log("sip send dtmf Signal=* success"),t(e)},onReject:function(e){i("sip send dtmf Signal=* fail with code "+e.message.statusCode)}},a),delete r.requestDelegate,n.next=1,this.getCurrentInvitation().info(g({requestOptions:{body:{contentDisposition:"render",contentType:"application/dtmf-relay",content:"Signal=*\r\nDuration=100"},extraHeaders:s},requestDelegate:o},r));case 1:E(this,wt,"f").call(this),n.next=3;break;case 2:n.prev=2,l=n.catch(0),i(l);case 3:case"end":return n.stop()}},n,this,[[0,2]])}))}));case 1:case"end":return t.stop()}},t)}))}},{key:"muteRemoteAudio",value:function(){var e;f(e=E(this,ae,"f").getReceivers()).call(e,function(e){e.track.enabled=!1})}},{key:"unMuteRemoteAudio",value:function(){var e;f(e=E(this,ae,"f").getReceivers()).call(e,function(e){e.track.enabled=!0})}},{key:"muteLocalAudio",value:function(){var e;f(e=E(this,ae,"f").getSenders()).call(e,function(e){e.track.enabled=!1})}},{key:"unMuteLocalAudio",value:function(){var e;f(e=E(this,ae,"f").getSenders()).call(e,function(e){e.track.enabled=!0})}},{key:"getUserAgentStatue",value:function(){return E(this,de,"f")}},{key:"getUserAgent",value:function(){return E(this,ie,"f")||M(this,ie,new n(E(this,le,"f")),"f"),E(this,ie,"f")}},{key:"getSessionDescriptionHandler",value:function(){return E(this,se,"f")}},{key:"getPeerConnection",value:function(){return E(this,ae,"f")}},{key:"getSenders",value:function(){return E(this,ce,"f")}},{key:"getReceivers",value:function(){return E(this,oe,"f")}},{key:"getStream",value:function(){var e,t=this;return E(this,fe,"f")||M(this,fe,new MediaStream,"f"),f(e=E(this,oe,"f")).call(e,function(e){e.track&&E(t,fe,"f").addTrack(e.track)}),E(this,fe,"f")}},{key:"getCurrentInviter",value:function(){if(!E(this,he,"f"))throw new Error("No currentInviter...");return E(this,he,"f")}},{key:"getCurrentInvitation",value:function(){return E(this,ue,"f")}},{key:"clearIceAutoDetection",value:function(){var e;null===(e=E(this,te,"f"))||void 0===e||e.destroy(),M(this,te,void 0,"f")}},{key:"iceAutoDetectRecovery",value:function(e){var t,n=this;null===(t=E(this,te,"f"))||void 0===t||t.destroy(),M(this,te,new wn(e,{maxRetries:3,disconnectedTimeoutMs:8e3,iceRecoveryTimeoutMs:1e4,iceGatheringTimeoutMs:5e3,enableRtpWatchdog:!0,rtpStatsIntervalMs:1e3,rtpStallTimeoutMs:15e3,debugIceCredentials:!0,recoverOnRtpStallWhenIceConnected:!0,onRecoveryStart:function(e,t){console.log("开始 ICE 恢复",e,t)},onRecovered:function(){console.log("媒体连接已恢复")},isSignalingAvailable:function(){return E(n,ie,"f").isConnected()},onRecoveryFailed:function(e,t){console.error("ICE 恢复失败",e,t)}}),"f"),E(this,te,"f").start()}},{key:"invite",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return D(this,void 0,void 0,c.mark(function i(){var s,a,o;return c.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(a=n.makeURI(e.uri?e.uri:m(s="sip:".concat(e.extension,"@")).call(s,E(this,le,"f").transportOptions.server.split("://")[1]))){i.next=1;break}throw new Error("Failed to create target URI.");case 1:return M(this,he,new r(this.getUserAgent(),a,{sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}}}),"f"),o=(t||{}).extraHeaders,i.next=2,this.getCurrentInviter().invite(g({requestOptions:{extraHeaders:o}},t));case 2:return i.abrupt("return",E(this,he,"f"));case 3:case"end":return i.stop()}},i,this)}))}}])}();te=new k,ne=new k,ie=new k,re=new k,se=new k,ae=new k,oe=new k,ce=new k,le=new k,ue=new k,he=new k,fe=new k,de=new k,ve=new k,pe=new k,ge=new k,me=new k,be=new k,we=new k,ye=new k,ke=new k,xe=new k,Se=new k,Te=new k,Re=new k,Ce=new k,Ie=new k,Ae=new k,De=new k,Ee=new k,Me=new k,Pe=new k,Oe=new k,je=new k,Ne=new k,Be=new k,qe=new k,Fe=new k,He=new k,We=new k,Le=new k,Ue=new k,Ge=new k,ze=new k,Xe=new k,Ve=new k,_e=new k,Ye=new k,Je=new k,Ke=new k,$e=new k,Ze=new k,Qe=new k,et=new k,tt=new k,nt=new k,it=new k,rt=new k,st=new k,at=new k,ot=new k,ct=new k,lt=new k,ut=new k,ht=new k,ft=new k,dt=new k,vt=new k,pt=new k,gt=new k,mt=new k,bt=new k,wt=new k,yt=new k,kt=new k,xt=new k,St=new k,Tt=new k,Rt=new k,Ct=new k,It=new k,Nt=new k,Bt=new k,Ft=new k,Zt=new k,en=new k,tn=new k,nn=new k,rn=new k,sn=new k,hn=new k,ee=new x,At=function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};M(this,Ie,null!==(e=n.openXhrIntercept)&&void 0!==e?e:E(this,Ie,"f"),"f"),M(this,Ae,null!==(t=n.gatewayXhrIntercept)&&void 0!==t?t:E(this,Ae,"f"),"f")},Dt=function(){var e,t,n,i,r,s,a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};M(this,mt,null!==(e=a.enableChatInfoPush)&&void 0!==e?e:E(this,mt,"f"),"f"),M(this,bt,null!==(t=a.enableVolumnTrack)&&void 0!==t?t:E(this,bt,"f"),"f"),M(this,Re,null!==(n=a.refreshSpeekVolumn)&&void 0!==n?n:E(this,Re,"f"),"f"),M(this,je,null!==(i=a.refreshRequirementCheck)&&void 0!==i?i:E(this,je,"f"),"f"),M(this,Ce,null!==(r=a.refreshChat)&&void 0!==r?r:E(this,Ce,"f"),"f"),M(this,Oe,null!==(s=a.refreshChatErrorCallback)&&void 0!==s?s:E(this,Oe,"f"),"f")},Et=function(){var e,t,n,i,r,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};M(this,me,null!==(e=s.token)&&void 0!==e?e:E(this,me,"f"),"f"),M(this,be,null!==(t=s.tokenTimestamp)&&void 0!==t?t:E(this,be,"f"),"f"),M(this,ye,null!==(n=s.tokenExpirationTime)&&void 0!==n?n:E(this,ye,"f"),"f"),E(this,me,"f")&&!E(this,be,"f")&&M(this,be,h(),"f"),M(this,Ee,null!==(i=s.tokenCheck)&&void 0!==i?i:E(this,Ee,"f"),"f"),M(this,Pe,null!==(r=s.tokenOverdued)&&void 0!==r?r:E(this,Pe,"f"),"f")},Mt=function(){var e,t,n,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};M(this,dt,null!==(e=i.clusterMode)&&void 0!==e?e:E(this,dt,"f"),"f"),M(this,vt,null!==(t=i.reClusterRegisterTimeout)&&void 0!==t?t:E(this,vt,"f"),"f"),M(this,pt,null!==(n=i.reClusterConnectTimeout)&&void 0!==n?n:E(this,pt,"f"),"f")},Pt=function(){var e,t,n,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=i.agentId,s=i.agentTag,a=i.appKey,o=i.appSecret,c=i.openBaseUrl,l=i.sg,u=i.sgOpen,h=i.sign,f=i.timestamp;M(this,rt,null!=r?r:E(this,rt,"f"),"f"),M(this,it,null!=s?s:E(this,it,"f"),"f"),M(this,tt,null!=a?a:E(this,tt,"f"),"f"),M(this,nt,null!=o?o:E(this,nt,"f"),"f"),M(this,st,null!=c?c:E(this,st,"f"),"f"),M(this,ot,null!=l?l:E(this,ot,"f"),"f"),M(this,at,null!=u?u:E(this,at,"f"),"f"),M(this,pe,null!=h?h:E(this,pe,"f"),"f"),M(this,ge,null!=f?f:E(this,ge,"f"),"f"),M(this,we,null!==(e=i.signExpirationTime)&&void 0!==e?e:E(this,we,"f"),"f"),M(this,De,null!==(t=i.signCheck)&&void 0!==t?t:E(this,De,"f"),"f"),M(this,Me,null!==(n=i.signOverdued)&&void 0!==n?n:E(this,Me,"f"),"f")},Ot=function(e){e.sipHeaders&&(M(this,ne,e.sipHeaders,"f"),delete e.sipHeaders)},jt=function(){return!(!E(this,rt,"f")&&!E(this,it,"f")||!(E(this,tt,"f")&&E(this,nt,"f")||E(this,pe,"f")&&E(this,ge,"f")))},qt=function(){E(this,ee,"m",Xt).call(this),E(this,ee,"m",Jt).call(this),E(this,ee,"m",Kt).call(this),E(this,ee,"m",Yt).call(this),E(this,ee,"m",_t).call(this),E(this,ee,"m",an).call(this),E(this,ee,"m",on).call(this),E(this,ee,"m",Vt).call(this),E(this,yt,"f").call(this),this.clearIceAutoDetection(),M(this,gt,{},"f"),M(this,ke,{},"f")},Ht=function(e){M(this,de,a(JSON.parse(l(L)),"function"==typeof e.refresh?e.refresh:E(this,ut,"f")),"f")},Wt=function(e){var t,n,i,r,s,a,o,c,l,u,h,f,d,v,p;M(this,qe,null!==(i=null!==(t=e.reconnectionAttempts)&&void 0!==t?t:null===(n=null==e?void 0:e.transportOptions)||void 0===n?void 0:n.maxReconnectionAttempts)&&void 0!==i?i:E(this,qe,"f"),"f"),M(this,Fe,null!==(o=null!==(s=null!==(r=e.reconnectionInterval)&&void 0!==r?r:e.reconnectionDelay)&&void 0!==s?s:null===(a=null==e?void 0:e.transportOptions)||void 0===a?void 0:a.reconnectionTimeout)&&void 0!==o?o:E(this,Fe,"f"),"f"),M(this,_e,null!==(l=null===(c=e.transportOptions)||void 0===c?void 0:c.keepAliveInterval)&&void 0!==l?l:E(this,_e,"f"),"f"),M(this,Ye,null!==(h=null===(u=e.transportOptions)||void 0===u?void 0:u.keepAliveDebounce)&&void 0!==h?h:E(this,Ye,"f"),"f"),M(this,ze,null!==(f=e.registerInterval)&&void 0!==f?f:E(this,ze,"f"),"f"),M(this,He,null!==(d=e.optionsPingInterval)&&void 0!==d?d:E(this,He,"f"),"f"),M(this,We,null!==(v=e.optionsPingAttempts)&&void 0!==v?v:E(this,We,"f"),"f"),M(this,Xe,null!==(p=e.registerAttempts)&&void 0!==p?p:E(this,Xe,"f"),"f")},Lt=function(e,t){var n,i=this;return t?(f(n=S(t)).call(n,function(n){if(t[n]&&"function"==typeof t[n])if(e[n]){if("function"==typeof e[n]){var r=e[n];e[n]=function(e){return D(i,void 0,void 0,c.mark(function i(){return c.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return i.next=1,t[n](e);case 1:return i.next=2,r(e);case 2:case"end":return i.stop()}},i)}))}}}else e[n]=t[n]}),e):e},Ut=function(e){var t,n=this,i={delegate:{onConnect:function(){return D(n,void 0,void 0,c.mark(function e(){return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:console.log("sip connected"),E(this,nn,"f").call(this);case 1:case"end":return e.stop()}},e,this)}))},onInvite:function(e){E(n,Ft,"f").call(n,e.incomingInviteRequest.message.headers),n.refreshCallChatInfo(),E(n,ee,"m",Gt).call(n),M(n,ue,e,"f"),E(n,de,"f").incomingStatus=!0,n.iceAutoDetectRecovery(e),e.stateChange.addListener(E(n,Zt,"f"))},onDisconnect:function(e){return D(n,void 0,void 0,c.mark(function t(){var n;return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return console.log("sip disconnected"),n=!1,E(this,He,"f")>0&&(n=E(this,Ue,"f"),E(this,sn,"f").call(this)),t.prev=1,t.next=2,E(this,ee,"m",Qt).call(this);case 2:t.next=4;break;case 3:t.prev=3,t.catch(1);case 4:(e||n)&&E(this,ee,"m",fn).call(this);case 5:case"end":return t.stop()}},t,this,[[1,3]])}))}}};e.delegate?f(t=S(e.delegate)).call(t,function(t){var r=t;if(e.delegate[r]&&"function"==typeof e.delegate[r]){var s=e.delegate[r];e.delegate[r]=function(e){return D(n,void 0,void 0,c.mark(function t(){var n,a;return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return null===(a=(n=i.delegate)[r])||void 0===a||a.call(n,e),t.next=1,s(e);case 1:case"end":return t.stop()}},t)}))}}}):e.delegate=i.delegate;return e.reconnectionAttempts=0,e.transportOptions=g(g({},e.transportOptions||{}),{keepAliveInterval:E(this,_e,"f"),keepAliveDebounce:E(this,Ye,"f")}),void 0===e.sessionDescriptionHandlerFactoryOptions&&(e.sessionDescriptionHandlerFactoryOptions={iceGatheringTimeout:2e3,peerConnectionConfiguration:{iceServers:[]}}),g(g({},W),e)},Gt=function(){E(this,ue,"f")&&(E(this,ue,"f").dispose(),M(this,ue,void 0,"f"))},zt=function(){return D(this,void 0,void 0,c.mark(function e(){return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!E(this,ie,"f")){e.next=2;break}return e.next=1,E(this,ie,"f").stop();case 1:M(this,ie,void 0,"f");case 2:case"end":return e.stop()}},e,this)}))},Xt=function(){var e;E(this,fe,"f")&&(f(e=E(this,fe,"f").getTracks()).call(e,function(e){e.stop()}),M(this,fe,void 0,"f"))},Vt=function(){var e,t=this;f(e=S(L)).call(e,function(e){var n=e;E(t,de,"f")[n]=L[n]})},_t=function(){E(this,se,"f")&&(E(this,se,"f").close(),M(this,se,void 0,"f"))},Yt=function(){E(this,ae,"f")&&(E(this,ae,"f").close(),M(this,ae,void 0,"f"))},Jt=function(){M(this,ce,[],"f")},Kt=function(){M(this,oe,[],"f")},$t=function(){var e=this.getCurrentInvitation().sessionDescriptionHandler;E(this,ee,"m",Yt).call(this),E(this,ee,"m",_t).call(this),E(this,ee,"m",Jt).call(this),E(this,ee,"m",Kt).call(this),M(this,se,e,"f"),M(this,ae,e.peerConnection,"f"),M(this,ce,E(this,ae,"f").getSenders(),"f"),M(this,oe,E(this,ae,"f").getReceivers(),"f"),(this.getFastOutboundCall()||!this.getSitOutboundCall()&&this.notNeedSendStarDtmf())&&E(this,wt,"f").call(this)},Qt=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return D(this,void 0,void 0,c.mark(function t(){var n=this;return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!E(this,re,"f")){t.next=1;break}return console.log("sip due to disconnection, unregistered"),t.abrupt("return",new p(function(t,i){return D(n,void 0,void 0,c.mark(function n(){var r,s,a;return c.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,r=e||{},s=E(this,ee,"m",Lt).call(this,{onAccept:function(e){console.log("sip unregister successed"),t(e)},onReject:function(e){i("sip unregister fail with code "+e.message.statusCode)}},r.requestDelegate),delete e.requestDelegate,n.next=1,E(this,re,"f").unregister(g({requestDelegate:s},e));case 1:n.next=3;break;case 2:n.prev=2,a=n.catch(0),i(a);case 3:case"end":return n.stop()}},n,this,[[0,2]])}))}));case 1:case"end":return t.stop()}},t,this)}))},an=function(){E(this,ee,"m",cn).call(this),E(this,ee,"m",ln).call(this),E(this,ee,"m",un).call(this),M(this,$e,!1,"f"),M(this,Je,!1,"f"),M(this,Ke,!1,"f")},on=function(){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])&&(clearTimeout(E(this,ht,"f")),M(this,ht,void 0,"f")),e&&(clearTimeout(E(this,ft,"f")),M(this,ft,void 0,"f"))},cn=function(){clearTimeout(E(this,et,"f")),M(this,et,void 0,"f")},ln=function(){clearTimeout(E(this,Ze,"f")),M(this,Ze,void 0,"f")},un=function(){clearTimeout(E(this,Qe,"f")),M(this,Qe,void 0,"f")},fn=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return D(this,void 0,void 0,c.mark(function n(){var i=this;return c.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(!E(this,Fe,"f")){n.next=4;break}if(E(this,de,"f").reconnectStatus=!0,!E(this,Je,"f")){n.next=1;break}return n.abrupt("return");case 1:if(!(t>E(this,qe,"f"))){n.next=3;break}return console.log("sip maximum reconnection attempts reached"),n.next=2,this.dispose();case 2:return n.abrupt("return");case 3:console.log("sip reconnection attempt..."),M(this,Je,!0,"f"),M(this,Ze,d(function(){E(i,ee,"m",ln).call(i),i.getUserAgent().reconnect().then(function(){return D(i,void 0,void 0,c.mark(function e(){var n;return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:console.log(m(n="sip reconnection attempt ".concat(t," of ")).call(n,E(this,qe,"f")," - succeeded")),M(this,Je,!1,"f"),E(this,hn,"f").call(this);case 1:case"end":return e.stop()}},e,this)}))}).catch(function(n){var r;console.error(n),console.log(m(r="sip reconnection attempt ".concat(t," of ")).call(r,E(i,qe,"f")," - failed")),M(i,Je,!1,"f"),E(i,ee,"m",e).call(i,++t)})},1===t?0:1e3*E(this,Fe,"f")),"f");case 4:case"end":return n.stop()}},n,this)}))},dn=function(e){var t,n=this;return f(t=S(e)).call(t,function(t){var i=t;if("function"==typeof(null==e?void 0:e[i])){var r=e[i];e[i]=function(e){return D(n,void 0,void 0,c.mark(function t(){var n,s;return c.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return null===(s=(n=E(this,le,"f").delegate)[i])||void 0===s||s.call(n,e),t.next=1,r(e);case 1:case"end":return t.stop()}},t,this)}))}}}),e},vn=function(e){var t=this.getUserAgent();return t.delegate=E(this,ee,"m",dn).call(this,e),t},pn=function(){return D(this,void 0,void 0,c.mark(function e(){var t;return c.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=this.getUserAgent(),e.next=1,t.start();case 1:if(t.isConnected()){e.next=2;break}return e.next=2,t.reconnect();case 2:if(t.isConnected()){e.next=3;break}throw new Error("链接失败,请稍后再试");case 3:return E(this,de,"f").connectStatus=!0,e.abrupt("return",t);case 4:case"end":return e.stop()}},e,this)}))},gn=function e(t){var i=this,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=t||{},o=a.registererOptions,l=a.registererRegisterOptions,u=a.extraHeaders;return new p(function(t,a){return D(i,void 0,void 0,c.mark(function i(){var h,f,v,p,m,b=this;return c.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return h=this.getUserAgent(),M(this,re,new s(h,g({extraHeaders:u||E(this,ne,"f")},o||{})),"f"),v=l||{},p=E(this,ee,"m",Lt).call(this,{onAccept:function(e){f=e,E(b,ee,"m",on).call(b),E(b,de,"f").registerStatus=!0,t(h)},onReject:function(e){E(b,ee,"m",on).call(b),a("sip register fail with code "+e.message.statusCode)}},v.requestDelegate),delete v.requestDelegate,r&&M(this,ht,d(function(){return D(b,void 0,void 0,c.mark(function i(){var r,m=this;return c.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(f){i.next=4;break}M(this,ft,d(function(){return D(m,void 0,void 0,c.mark(function i(){var r,s;return c.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(E(this,ee,"m",on).call(this,!1,!0),f){i.next=6;break}i.prev=1;try{E(this,re,"f").dispose()}catch(e){}return E(this,ee,"m",qt).call(this),E(this,sn,"f").call(this),M(this,Le,0,"f"),M(this,Ve,0,"f"),i.next=2,E(this,ie,"f").transport.dispose();case 2:return M(this,ie,new n(E(this,le,"f")),"f"),i.next=3,E(this,ee,"m",pn).call(this);case 3:return i.next=4,E(this,ee,"m",e).call(this,{registererOptions:o,registererRegisterOptions:l,extraHeaders:u});case 4:r=i.sent,t(r),i.next=6;break;case 5:i.prev=5,s=i.catch(1),a(s);case 6:case"end":return i.stop()}},i,this,[[1,5]])}))},E(this,pt,"f")),"f");try{E(this,re,"f").dispose()}catch(e){}return M(this,re,new s(h,g({extraHeaders:u||E(this,ne,"f")},o||{})),"f"),E(this,ee,"m",on).call(this,!0,!1),i.prev=1,i.next=2,E(this,re,"f").register(g({requestDelegate:p,requestOptions:{extraHeaders:u||E(this,ne,"f")}},v));case 2:i.next=4;break;case 3:i.prev=3,r=i.catch(1),E(this,ee,"m",on).call(this),a(r);case 4:case"end":return i.stop()}},i,this,[[1,3]])}))},E(this,vt,"f")),"f"),i.prev=1,i.next=2,E(this,re,"f").register(g({requestDelegate:p,requestOptions:{extraHeaders:u||E(this,ne,"f")}},v));case 2:i.next=4;break;case 3:i.prev=3,m=i.catch(1),E(this,ee,"m",on).call(this),a(m);case 4:case"end":return i.stop()}},i,this,[[1,3]])}))})};var kn=function(){return t(function t(){e(this,t)},null,[{key:"getUserAgentManager",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return E(this,mn,"f",bn)||M(this,mn,new yn(e),"f",bn),E(this,mn,"f",bn)}},{key:"hasUserAgentManager",value:function(){return!!E(this,mn,"f",bn)}},{key:"newUserAgentManager",value:function(){return new yn(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})}},{key:"dispose",value:function(){if(E(this,mn,"f",bn))try{E(this,mn,"f",bn).dispose()}catch(e){}finally{M(this,mn,void 0,"f",bn)}}}])}();mn=kn,bn={value:void 0};export{kn as UserAgentFactory,yn as UserAgentManager,$ as accumulateSec,Z as accumulationTimer,Y as cleanupMedia,z as getDevicePermission,U as getMedia,J as getTimes,K as getZeorTime,_ as pauseMedia,V as playMedia,X as requestMicroPhonePermission,G as stopStreamTracks,W as userAgentDefault,L as userAgentStatus};
1
+ import e from"@babel/runtime-corejs3/helpers/esm/classCallCheck";import t from"@babel/runtime-corejs3/helpers/esm/createClass";import{UserAgent as i,SessionState as n,RegistererState as r,Inviter as s,Registerer as a}from"sip.js";export{Inviter,Registerer,SessionState,URI,UserAgent}from"sip.js";export{SimpleUser}from"sip.js/lib/platform/web/index.js";import o from"on-change";export{default as onChange}from"on-change";import c from"@babel/runtime-corejs3/helpers/esm/typeof";import l from"@babel/runtime-corejs3/regenerator";import u from"@babel/runtime-corejs3/core-js/json/stringify";import h from"@babel/runtime-corejs3/core-js/object/define-property";import d from"@babel/runtime-corejs3/core-js/date/now";import f from"@babel/runtime-corejs3/core-js/instance/for-each";import v from"@babel/runtime-corejs3/core-js/set-timeout";import p from"@babel/runtime-corejs3/core-js/set-interval";import g from"@babel/runtime-corejs3/core-js/promise";import m from"@babel/runtime-corejs3/core-js/object/assign";import b from"@babel/runtime-corejs3/core-js/instance/concat";import y from"@babel/runtime-corejs3/core-js/instance/map";import w from"@babel/runtime-corejs3/core-js/instance/index-of";import k from"@babel/runtime-corejs3/core-js/instance/filter";import R from"@babel/runtime-corejs3/core-js/weak-map";import S from"@babel/runtime-corejs3/core-js/weak-set";import x from"@babel/runtime-corejs3/core-js/object/keys";import T from"@babel/runtime-corejs3/core-js/instance/pad-start";import C from"@babel/runtime-corejs3/core-js/instance/slice";import I from"crypto-js";import A from"@fingerprintjs/fingerprintjs";import D from"@babel/runtime-corejs3/core-js/instance/includes";import E from"@babel/runtime-corejs3/core-js/instance/starts-with";import M from"@babel/runtime-corejs3/core-js/instance/find-index";import P from"@babel/runtime-corejs3/core-js/instance/splice";import j from"@babel/runtime-corejs3/core-js/instance/trim";function O(e,t,i,n){return new(i||(i=Promise))(function(r,s){function a(e){try{c(n.next(e))}catch(e){s(e)}}function o(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,o)}c((n=n.apply(e,t||[])).next())})}function N(e,t,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(e):n?n.value:t.get(e)}function F(e,t,i,n,r){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?r.call(e,i):r?r.value=i:t.set(e,i),i}var B,q;"function"==typeof SuppressedError&&SuppressedError;var H,W,L,z,G=b(B="sip:".concat("","@")).call(B,""),U=b(q="".concat("","://")).call(q,""),X={authorizationPassword:"",authorizationUsername:"",viaHost:"",uri:i.makeURI(G),logLevel:"error",transportOptions:{server:U},contactName:""},V={connectStatus:!1,registerStatus:!1,invitatingStatus:!1,incomingStatus:!1,answerStatus:!1,reconnectStatus:!1};function _(e){return document.getElementById(e)}function Y(e){if(e&&e.getTracks)try{var t=e.getTracks();f(t).call(t,function(e){try{e.stop()}catch(e){}})}catch(e){}}function J(e){return navigator.mediaDevices.getUserMedia(e).then(function(e){return e?(Y(e),!0):g.reject(new Error("EmptyStreamError"))}).catch(function(e){return(!e||"NotAllowedError"!==e.name)&&g.reject(e)})}function K(){try{var e;if(-1===w(e=navigator.userAgent).call(e,"Firefox"))return J({video:!1,audio:!0}).catch(function(){return!0})}catch(e){console.log(e)}}function Z(e){var t=_(e);t&&(t.currentTime=0,t.play())}function $(e){var t=_(e);t&&(t.currentTime=0,t.pause())}function Q(e){var t=_(e);t&&(t.srcObject=null,t.pause())}!function(e){e.NO="0",e.YES="1"}(H||(H={})),function(e){e.NO="0",e.YES="1"}(W||(W={})),function(e){e.MULTI_AI="1",e.MULTI_VOICE_NOTIFY="2",e.MULTI_PRETEST="3",e.LABOUR="4",e.AI="5",e.NEW_VOICE_NOTIFY="6"}(L||(L={})),function(e){e.DIRECT_ANSWER="1",e.LISTEN_FIRST_AND_THEN_ANSWER_MANUALLY="2"}(z||(z={}));var ee=function(e){var t,i,n;return T(t=e.getHours().toString()).call(t,2,"0")+":"+T(i=e.getMinutes().toString()).call(i,2,"0")+":"+T(n=e.getSeconds().toString()).call(n,2,"0")},te=function(){return new Date(new Date((new Date).toLocaleDateString()).getTime())},ie=function(e){return new Date(e.setSeconds(e.getSeconds()+1))};function ne(e){var t=te();e(ee(t));var i=p(function(){var i=ie(t),n=ee(i);e(n)},1e3);return function(){clearInterval(i),i=null}}function re(e,t,i){var n=window.XMLHttpRequest?new window.XMLHttpRequest:window.ActiveXObject?new window.ActiveXObject("Microsoft.XMLHTTP"):void 0;n||t(new Error("Your Browser does not support ajax")),n.onreadystatechange=function(){if(4==n.readyState){var i=n.response||n.responseText;if(200==n.status){var r=n.getResponseHeader("Content-Type");-1!=w(r).call(r,"json")?e(JSON.parse(n.responseText)):-1!=w(r).call(r,"xml")?e(n.responseXML):e(n.responseText)}else t(i)}};var r=i.url,s=i.data,a=i.type,o=i.contentType,c=a||"POST",l=r,h=null;return s&&("GET"===c?l=l+"?"+function(e){var t=[];for(var i in e)t.push(i+"="+e[i]);return t.join("&")}(s):"POST"===c&&(h=u(s))),n.open(c,l,!0),{xhr:n,ajaxData:h,contentType:o}}var se,ae,oe,ce,le,ue,he,de,fe,ve,pe,ge,me,be,ye,we,ke,Re,Se,xe,Te,Ce,Ie,Ae,De,Ee,Me,Pe,je,Oe,Ne,Fe,Be,qe,He,We,Le,ze,Ge,Ue,Xe,Ve,_e,Ye,Je,Ke,Ze,$e,Qe,et,tt,it,nt,rt,st,at,ot,ct,lt,ut,ht,dt,ft,vt,pt,gt,mt,bt,yt,wt,kt,Rt,St,xt,Tt,Ct,It,At,Dt,Et,Mt,Pt,jt,Ot,Nt,Ft,Bt,qt,Ht,Wt,Lt,zt,Gt,Ut,Xt,Vt,_t,Yt,Jt,Kt,Zt,$t,Qt,ei,ti,ii,ni,ri,si,ai,oi,ci,li,ui,hi,di,fi,vi,pi,gi,mi,bi,yi,wi,ki,Ri,Si=function(){return t(function t(i){var r,s,a,o,c,u,f,p,g,m,b,y,w,k,R,S,x,T,C,I,A,D,E,M,P=this,j=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,t),h(this,"session",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),h(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),h(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:"idle"}),h(this,"destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),h(this,"bound",{enumerable:!0,configurable:!0,writable:!0,value:!1}),h(this,"hardFailed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),h(this,"retryCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),h(this,"signalingBusyCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),h(this,"disconnectedTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),h(this,"retryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),h(this,"signalingBusyTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),h(this,"negotiationTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),h(this,"iceRecoveryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),h(this,"rtpStatsTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),h(this,"onlineTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),h(this,"transportRecoveryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),h(this,"registrationRecoveryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),h(this,"transportWaitStartedAt",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),h(this,"pendingTransportRecoveryReason",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),h(this,"registrationWaitStartedAt",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),h(this,"pendingRegistrationRecoveryReason",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),h(this,"lastRtpSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),h(this,"lastRtpProgressAt",{enumerable:!0,configurable:!0,writable:!0,value:d()}),h(this,"lastRtpRecoveryAt",{enumerable:!0,configurable:!0,writable:!0,value:0}),h(this,"recoveryGeneration",{enumerable:!0,configurable:!0,writable:!0,value:0}),h(this,"acceptedRecoveryGeneration",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),h(this,"recoveryReason",{enumerable:!0,configurable:!0,writable:!0,value:""}),h(this,"reinviteReason",{enumerable:!0,configurable:!0,writable:!0,value:"unknown"}),h(this,"permanentRecoverySdpModifier",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return O(P,void 0,void 0,l.mark(function t(){return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.applyRecoveryReasonToSdp(e));case 1:case"end":return t.stop()}},t,this)}))}}),h(this,"handleSessionStateChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e){switch(P.logInfo("SIP session state:",e),e){case n.Established:P.handleEstablished();break;case n.Terminating:case n.Terminated:P.destroy()}}}),h(this,"handleOffline",{enumerable:!0,configurable:!0,writable:!0,value:function(){P.destroyed||P.hardFailed||(P.logInfo("browser offline"),P.clearDisconnectedTimer(),P.clearRetryTimer(),P.clearSignalingBusyTimer(),P.clearIceRecoveryTimer(),P.clearTransportRecoveryTimer(),"sending-reinvite"!==P.state&&(P.state="idle"))}}),h(this,"handleOnline",{enumerable:!0,configurable:!0,writable:!0,value:function(){P.destroyed||P.hardFailed||(P.logInfo("browser online"),P.onlineTimer&&clearTimeout(P.onlineTimer),P.onlineTimer=v(function(){if(P.onlineTimer=void 0,!P.destroyed&&!P.hardFailed&&P.session.state===n.Established)if(P.isTransportAvailable()){var e=P.getPeerConnection();if(e)if("stable"===e.signalingState)switch(e.iceConnectionState){case"failed":case"disconnected":P.state="idle",P.recover("network-online")}else P.scheduleSignalingBusyRetry("network-online:".concat(e.signalingState))}else P.waitForTransport("network-online")},P.options.onlineRecoveryDelayMs))}}),this.session=i,this.options={disconnectedTimeoutMs:null!==(r=j.disconnectedTimeoutMs)&&void 0!==r?r:3e3,negotiationTimeoutMs:null!==(s=j.negotiationTimeoutMs)&&void 0!==s?s:1e4,iceRecoveryTimeoutMs:null!==(a=j.iceRecoveryTimeoutMs)&&void 0!==a?a:1e4,iceGatheringTimeoutMs:null!==(o=j.iceGatheringTimeoutMs)&&void 0!==o?o:5e3,maxRetries:null!==(c=j.maxRetries)&&void 0!==c?c:3,retryBaseDelayMs:null!==(u=j.retryBaseDelayMs)&&void 0!==u?u:1e3,retryMaxDelayMs:null!==(f=j.retryMaxDelayMs)&&void 0!==f?f:1e4,maxSignalingBusyRetries:null!==(p=j.maxSignalingBusyRetries)&&void 0!==p?p:3,signalingBusyRetryDelayMs:null!==(g=j.signalingBusyRetryDelayMs)&&void 0!==g?g:1e3,enableRtpWatchdog:null===(m=j.enableRtpWatchdog)||void 0===m||m,rtpStatsIntervalMs:null!==(b=j.rtpStatsIntervalMs)&&void 0!==b?b:1e3,rtpStallTimeoutMs:null!==(y=j.rtpStallTimeoutMs)&&void 0!==y?y:5e3,recoverOnRtpStallWhenIceConnected:null===(w=j.recoverOnRtpStallWhenIceConnected)||void 0===w||w,rtpRecoveryCooldownMs:null!==(k=j.rtpRecoveryCooldownMs)&&void 0!==k?k:1e4,onlineRecoveryDelayMs:null!==(R=j.onlineRecoveryDelayMs)&&void 0!==R?R:800,transportRecoveryPollMs:null!==(S=j.transportRecoveryPollMs)&&void 0!==S?S:1e3,transportRecoveryTimeoutMs:null!==(x=j.transportRecoveryTimeoutMs)&&void 0!==x?x:6e4,registrationRecoveryPollMs:null!==(T=j.registrationRecoveryPollMs)&&void 0!==T?T:1e3,registrationRecoveryTimeoutMs:null!==(C=j.registrationRecoveryTimeoutMs)&&void 0!==C?C:6e4,debugIceCredentials:null!==(I=j.debugIceCredentials)&&void 0!==I&&I,includeRecoveryReasonInSdp:null===(A=j.includeRecoveryReasonInSdp)||void 0===A||A,recoveryReasonSdpAttribute:null!==(D=j.recoveryReasonSdpAttribute)&&void 0!==D?D:"x-recovery-reason",reinviteReasonSdpAttribute:null!==(E=j.reinviteReasonSdpAttribute)&&void 0!==E?E:"x-reinvite-reason",isSignalingAvailable:j.isSignalingAvailable,isRegistrationAvailable:j.isRegistrationAvailable,logger:null!==(M=j.logger)&&void 0!==M?M:console,onRecoveryStart:j.onRecoveryStart,onRecovered:j.onRecovered,onRecoveryFailed:j.onRecoveryFailed}},[{key:"start",value:function(){this.destroyed||this.hardFailed||(this.logInfo("start"),this.session.stateChange.addListener(this.handleSessionStateChange),"undefined"!=typeof window&&(window.addEventListener("online",this.handleOnline),window.addEventListener("offline",this.handleOffline)),this.session.state===n.Established&&this.handleEstablished())}},{key:"restartNow",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"manual";return O(this,void 0,void 0,l.mark(function t(){return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=1,this.recover(e);case 1:case"end":return t.stop()}},t,this)}))}},{key:"getState",value:function(){return this.state}},{key:"getRetryCount",value:function(){return this.retryCount}},{key:"getIceConnectionState",value:function(){var e;return null===(e=this.getPeerConnection())||void 0===e?void 0:e.iceConnectionState}},{key:"destroy",value:function(){if(!this.destroyed){this.destroyed=!0,this.hardFailed=!0,this.recoveryGeneration++,this.state="terminated",this.clearAllTimers(),this.session.stateChange.removeListener(this.handleSessionStateChange),"undefined"!=typeof window&&(window.removeEventListener("online",this.handleOnline),window.removeEventListener("offline",this.handleOffline));var e=this.getSessionDescriptionHandler();e&&this.bound&&(e.peerConnectionDelegate=void 0),this.bound=!1,this.logInfo("destroy")}}},{key:"handleEstablished",value:function(){this.destroyed||this.hardFailed||(this.bindPeerConnectionDelegate(),this.options.enableRtpWatchdog&&this.startRtpWatchdog())}},{key:"bindPeerConnectionDelegate",value:function(){var e=this,t=this.getSessionDescriptionHandler(),i=null==t?void 0:t.peerConnection;t&&i?this.bound||(this.bound=!0,this.logInfo("bind PeerConnection",{iceConnectionState:i.iceConnectionState,connectionState:i.connectionState,signalingState:i.signalingState}),t.peerConnectionDelegate={oniceconnectionstatechange:function(){e.handleIceConnectionStateChange()},onconnectionstatechange:function(){e.logInfo("connectionState:",i.connectionState),"failed"===i.connectionState&&"stable"!==i.signalingState&&e.logWarn("PeerConnection failed while signaling is busy",{signalingState:i.signalingState,iceConnectionState:i.iceConnectionState})},onicegatheringstatechange:function(){e.logDebug("iceGatheringState:",i.iceGatheringState)},onsignalingstatechange:function(){e.logInfo("signalingState:",i.signalingState),"stable"===i.signalingState&&(e.signalingBusyCount=0,"waiting-signaling"!==e.state||e.signalingBusyTimer||(e.state="idle",e.recover("signaling-became-stable"))),"closed"===i.signalingState&&e.destroy()},onicecandidate:function(t){t.candidate?e.logDebug("ICE candidate:",{type:t.candidate.type,protocol:t.candidate.protocol,address:t.candidate.address,port:t.candidate.port}):e.logDebug("ICE candidate gathering complete")}}):this.logWarn("SessionDescriptionHandler / PeerConnection unavailable")}},{key:"handleIceConnectionStateChange",value:function(){if(!this.destroyed&&!this.hardFailed){var e=this.getPeerConnection();if(e){var t=e.iceConnectionState;switch(this.logInfo("iceConnectionState:",t,"recoveryState:",this.state),t){case"new":break;case"checking":this.clearDisconnectedTimer(),"sending-reinvite"!==this.state&&"waiting-ice"!==this.state||(this.state="waiting-ice");break;case"connected":case"completed":this.handleIceRecovered();break;case"disconnected":this.handleIceDisconnected();break;case"failed":this.clearDisconnectedTimer(),this.recover("ice-failed");break;case"closed":this.destroy()}}}}},{key:"handleIceDisconnected",value:function(){var e=this;this.destroyed||this.hardFailed||"sending-reinvite"!==this.state&&"waiting-ice"!==this.state&&(this.disconnectedTimer||(this.state="waiting-disconnected",this.logInfo("ICE disconnected, wait ".concat(this.options.disconnectedTimeoutMs,"ms")),this.disconnectedTimer=v(function(){if(e.disconnectedTimer=void 0,!e.destroyed&&!e.hardFailed){var t=e.getPeerConnection();if(t){if("disconnected"===t.iceConnectionState)return e.state="idle",void e.recover("ice-disconnected-timeout");e.logInfo("ICE self recovered:",t.iceConnectionState),e.state="idle"}}},this.options.disconnectedTimeoutMs)))}},{key:"handleIceRecovered",value:function(){var e,t;if(!this.destroyed&&!this.hardFailed){var i="idle"!==this.state||this.retryCount>0;!i||"sending-reinvite"!==this.state&&"waiting-ice"!==this.state||this.acceptedRecoveryGeneration===this.recoveryGeneration?(this.clearDisconnectedTimer(),this.clearRetryTimer(),this.clearSignalingBusyTimer(),this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.clearTransportRecoveryTimer(),this.clearRegistrationRecoveryTimer(),this.transportWaitStartedAt=void 0,this.pendingTransportRecoveryReason=void 0,this.registrationWaitStartedAt=void 0,this.pendingRegistrationRecoveryReason=void 0,this.state="idle",this.retryCount=0,this.signalingBusyCount=0,this.acceptedRecoveryGeneration=void 0,this.recoveryReason="",this.reinviteReason="unknown",this.lastRtpProgressAt=d(),this.lastRtpSnapshot=void 0,this.logInfo("ICE healthy"),i&&(this.logInfo("ICE recovery succeeded"),null===(t=(e=this.options).onRecovered)||void 0===t||t.call(e))):this.logInfo("ICE healthy, waiting for re-INVITE acceptance")}}},{key:"recover",value:function(e){var t,i,r,s,a;return O(this,void 0,void 0,l.mark(function o(){var c,u,h,d,f,v,p=this;return l.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:if(!this.destroyed&&!this.hardFailed){o.next=1;break}return o.abrupt("return");case 1:if(this.session.state===n.Established){o.next=2;break}return this.logWarn("skip recovery: session not established",this.session.state),o.abrupt("return");case 2:if("undefined"==typeof navigator||!1!==navigator.onLine){o.next=3;break}return this.logWarn("skip recovery: browser offline"),this.state="idle",o.abrupt("return");case 3:if(this.isTransportAvailable()){o.next=4;break}return this.waitForTransport(e),o.abrupt("return");case 4:if(this.isRegistrationAvailable()){o.next=5;break}return this.waitForRegistration(e),o.abrupt("return");case 5:if("sending-reinvite"!==this.state&&"waiting-ice"!==this.state){o.next=6;break}return this.logDebug("skip recovery: recovery already running"),o.abrupt("return");case 6:if(c=this.getPeerConnection()){o.next=7;break}return o.abrupt("return");case 7:if("stable"===c.signalingState){o.next=8;break}return this.logWarn("skip recovery: signalingState not stable",c.signalingState),this.state="waiting-signaling",this.scheduleSignalingBusyRetry("signaling-busy:".concat(c.signalingState)),o.abrupt("return");case 8:if(this.signalingBusyCount=0,this.clearSignalingBusyTimer(),!(this.retryCount>=this.options.maxRetries)){o.next=9;break}return this.failRecovery("".concat(e,":max-retries")),o.abrupt("return");case 9:return this.clearDisconnectedTimer(),this.clearRetryTimer(),this.retryCount++,u=++this.recoveryGeneration,this.state="sending-reinvite",h=this.readIceCredentials(null===(t=c.localDescription)||void 0===t?void 0:t.sdp),this.recoveryReason||(this.reinviteReason=this.resolveReinviteReason(e),this.recoveryReason=this.normalizeRecoveryReason(e,this.reinviteReason)),this.acceptedRecoveryGeneration=void 0,this.logInfo("ICE recovery #".concat(this.retryCount),{recoveryReason:this.recoveryReason,reinviteReason:this.reinviteReason}),null===(r=(i=this.options).onRecoveryStart)||void 0===r||r.call(i,this.recoveryReason,this.retryCount),this.startNegotiationTimeout(u,e),o.prev=10,d={offerOptions:{iceRestart:!0},iceGatheringTimeout:this.options.iceGatheringTimeoutMs,finalModifiers:this.options.includeRecoveryReasonInSdp?[this.permanentRecoverySdpModifier]:[]},this.session.sessionDescriptionHandlerOptionsReInvite=d,this.session.sessionDescriptionHandlerModifiersReInvite=[],this.logDebug("re-INVITE Final SDP configured",{recoveryReason:this.recoveryReason,reinviteReason:this.reinviteReason,includeRecoveryReasonInSdp:this.options.includeRecoveryReasonInSdp,finalModifierCount:null!==(a=null===(s=d.finalModifiers)||void 0===s?void 0:s.length)&&void 0!==a?a:0}),o.next=11,this.session.invite({requestDelegate:{onTrying:function(){p.isCurrentGeneration(u)&&p.logDebug("ICE re-INVITE trying")},onProgress:function(e){p.isCurrentGeneration(u)&&p.logDebug("ICE re-INVITE progress:",e.message.statusCode)},onAccept:function(){var t;if(p.isCurrentGeneration(u)){p.logInfo("ICE re-INVITE accepted"),p.clearNegotiationTimer(),p.acceptedRecoveryGeneration=u;var i=p.getPeerConnection();if(i&&"stable"!==i.signalingState&&p.logWarn("re-INVITE accepted but signalingState is not stable",i.signalingState),p.state="waiting-ice",p.options.debugIceCredentials){var n=p.readIceCredentials(null===(t=null==i?void 0:i.localDescription)||void 0===t?void 0:t.sdp);p.logInfo("ICE credentials:",{old:h,new:n,changed:p.hasIceCredentialsChanged(h,n)})}p.startIceRecoveryTimeout(u,e)}},onReject:function(t){p.handleReinviteRejected(u,e,t.message.statusCode,t.message.reasonPhrase)}}});case 11:o.next=19;break;case 12:if(o.prev=12,v=o.catch(10),this.isCurrentGeneration(u)){o.next=13;break}return o.abrupt("return");case 13:return this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.logWarn("ICE re-INVITE error:",v),o.next=14,this.rollbackLocalOffer("invite-exception");case 14:if(f=o.sent,this.isCurrentGeneration(u)){o.next=15;break}return o.abrupt("return");case 15:if(f){o.next=16;break}return this.failRecovery("".concat(e,":rollback-failed:exception")),o.abrupt("return");case 16:if(this.state="idle",this.signalingBusyCount=0,this.isTransportAvailable()){o.next=17;break}return this.waitForTransport("".concat(e,":invite-exception")),o.abrupt("return");case 17:if(!this.isRequestPendingError(v)){o.next=18;break}return this.scheduleRetry("".concat(e,":request-pending"),1500),o.abrupt("return");case 18:this.scheduleRetry("".concat(e,":exception"));case 19:case"end":return o.stop()}},o,this,[[10,12]])}))}},{key:"rollbackLocalOffer",value:function(e){return O(this,void 0,void 0,l.mark(function t(){var i,n,r,s;return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(i=this.getPeerConnection()){t.next=1;break}return t.abrupt("return",!1);case 1:if("stable"!==i.signalingState){t.next=2;break}return t.abrupt("return",!0);case 2:if("have-local-offer"===i.signalingState){t.next=3;break}return this.logWarn("cannot rollback current signaling state",{reason:e,signalingState:i.signalingState}),t.abrupt("return",!1);case 3:return t.prev=3,this.logWarn("rollback local offer",{reason:e,signalingState:i.signalingState}),t.next=4,i.setLocalDescription({type:"rollback"});case 4:return n=i.signalingState,r="stable"===n,this.logInfo("local offer rollback result",{success:r,signalingState:n}),t.abrupt("return",r);case 5:return t.prev=5,s=t.catch(3),this.logError("local offer rollback failed",{reason:e,error:s,signalingState:i.signalingState}),t.abrupt("return",!1);case 6:case"end":return t.stop()}},t,this,[[3,5]])}))}},{key:"normalizeRecoveryReason",value:function(e,t){var i=e.toLowerCase();return D(i).call(i,"transport-restored")?"transport-restored:".concat(t):"unknown"!==t?t:"unknown"}},{key:"resolveReinviteReason",value:function(e){var t=e.toLowerCase();return D(t).call(t,"rtp-stalled")?"rtp-stalled":D(t).call(t,"ice-failed")?"ice-failed":D(t).call(t,"ice-disconnected")||D(t).call(t,"disconnected-timeout")?"ice-disconnected":D(t).call(t,"network-changed")?"network-changed":D(t).call(t,"transport-restored")?"transport-restored":D(t).call(t,"manual")?"manual":"unknown"}},{key:"sanitizeSdpReason",value:function(e){var t,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:256;return C(t=e.replace(/[\r\n]/g,"").replace(/[^a-zA-Z0-9._:-]/g,"_")).call(t,0,i)}},{key:"sanitizeSdpAttributeName",value:function(e){var t;return C(t=e.replace(/[^a-zA-Z0-9_-]/g,"")).call(t,0,64)||"x-reinvite-reason"}},{key:"applyRecoveryReasonToSdp",value:function(e){return O(this,void 0,void 0,l.mark(function t(){var i,n,r,s,a,o,c,u,h,d,f,v,p,g,y,w,R;return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e.sdp&&this.options.includeRecoveryReasonInSdp){t.next=1;break}return t.abrupt("return",e);case 1:for(u=this.sanitizeSdpAttributeName(this.options.recoveryReasonSdpAttribute),h=this.sanitizeSdpAttributeName(this.options.reinviteReasonSdpAttribute),d=this.sanitizeSdpReason(this.recoveryReason||"unknown"),f=this.sanitizeSdpReason(this.reinviteReason||"unknown",64),v=k(i=e.sdp.split(/\r?\n/)).call(i,function(e){return!E(e).call(e,"a=".concat(u,":"))&&!E(e).call(e,"a=".concat(h,":"))});v.length>0&&""===v[v.length-1];)v.pop();return p=M(v).call(v,function(e){return E(e).call(e,"m=")}),g=p>=0?p:v.length,P(v).call(v,g,0,b(n="a=".concat(u,":")).call(n,d),b(r="a=".concat(h,":")).call(r,f)),y="".concat(v.join("\r\n"),"\r\n"),w=D(y).call(y,b(s="a=".concat(u,":")).call(s,d)),R=D(y).call(y,b(a="a=".concat(h,":")).call(a,f)),this.logInfo("SDP modifier RESULT",{recoveryReason:d,reinviteReason:f,containsRecoveryReason:w,containsReinviteReason:R,insertedBeforeFirstMedia:p>=0}),this.logDebug("SDP custom reason lines",{recoveryLine:b(o="a=".concat(u,":")).call(o,d),reinviteLine:b(c="a=".concat(h,":")).call(c,f)}),t.abrupt("return",m(m({},e),{sdp:y}));case 2:case"end":return t.stop()}},t,this)}))}},{key:"createRecoveryReasonSdpModifier",value:function(e,t){var i=this;return function(n){return O(i,void 0,void 0,l.mark(function i(){return l.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return this.recoveryReason=e,this.reinviteReason=t,i.abrupt("return",this.applyRecoveryReasonToSdp(n));case 1:case"end":return i.stop()}},i,this)}))}}},{key:"handleReinviteRejected",value:function(e,t,i,n){return O(this,void 0,void 0,l.mark(function r(){var s,a,o,c;return l.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(this.isCurrentGeneration(e)){r.next=1;break}return r.abrupt("return");case 1:return this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.logWarn("ICE re-INVITE rejected:",i,n),r.next=2,this.rollbackLocalOffer("sip-".concat(i));case 2:if(a=r.sent,this.isCurrentGeneration(e)){r.next=3;break}return r.abrupt("return");case 3:if(a){r.next=4;break}return this.failRecovery(b(o="".concat(t,":rollback-failed:sip-")).call(o,i)),r.abrupt("return");case 4:if(this.state="idle",this.signalingBusyCount=0,481!==i){r.next=5;break}return this.failRecovery("".concat(t,":sip-481")),r.abrupt("return");case 5:if(this.isTransportAvailable()){r.next=6;break}return this.waitForTransport(b(c="".concat(t,":sip-")).call(c,i)),r.abrupt("return");case 6:if(491!==i){r.next=7;break}return this.scheduleRetry("".concat(t,":sip-491"),1500),r.abrupt("return");case 7:if(503!==i){r.next=8;break}return this.scheduleRetry("".concat(t,":sip-503"),3e3),r.abrupt("return");case 8:this.scheduleRetry(b(s="".concat(t,":sip-")).call(s,i));case 9:case"end":return r.stop()}},r,this)}))}},{key:"startNegotiationTimeout",value:function(e,t){var i=this;this.clearNegotiationTimer(),this.negotiationTimer=v(function(){if(i.negotiationTimer=void 0,i.isCurrentGeneration(e)){var n=i.getPeerConnection();i.logError("re-INVITE negotiation timeout",{reason:t,signalingState:null==n?void 0:n.signalingState,iceConnectionState:null==n?void 0:n.iceConnectionState,connectionState:null==n?void 0:n.connectionState}),i.failRecovery("".concat(t,":negotiation-timeout"))}},this.options.negotiationTimeoutMs)}},{key:"startIceRecoveryTimeout",value:function(e,t){var i=this;this.clearIceRecoveryTimer(),this.iceRecoveryTimer=v(function(){if(i.iceRecoveryTimer=void 0,i.isCurrentGeneration(e)){var n=i.getPeerConnection();n&&("connected"!==n.iceConnectionState&&"completed"!==n.iceConnectionState?(i.logWarn("ICE recovery timeout",{reason:t,iceConnectionState:n.iceConnectionState,connectionState:n.connectionState,signalingState:n.signalingState}),i.state="idle","stable"===n.signalingState?i.scheduleRetry("".concat(t,":ice-timeout")):i.scheduleSignalingBusyRetry("ice-timeout:".concat(n.signalingState))):i.handleIceRecovered())}},this.options.iceRecoveryTimeoutMs)}},{key:"scheduleRetry",value:function(e){var t=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!this.destroyed&&!this.hardFailed)if(this.retryCount>=this.options.maxRetries)this.failRecovery("".concat(e,":max-retries"));else if(!this.retryTimer){this.state="waiting-retry";var n=this.options.retryBaseDelayMs*Math.pow(2,Math.max(0,this.retryCount-1)),r=Math.min(n,this.options.retryMaxDelayMs),s=Math.floor(500*Math.random()),a=Math.max(r+s,i);this.logInfo("schedule ICE retry in ".concat(a,"ms"),e),this.retryTimer=v(function(){if(t.retryTimer=void 0,!t.destroyed&&!t.hardFailed)if(t.isTransportAvailable()){var i=t.getPeerConnection();if(i)if("connected"!==i.iceConnectionState&&"completed"!==i.iceConnectionState){if("stable"!==i.signalingState)return t.state="waiting-signaling",void t.scheduleSignalingBusyRetry("retry-signaling-busy:".concat(i.signalingState));t.state="idle",t.recover(t.recoveryReason||e)}else t.handleIceRecovered()}else t.waitForTransport(t.recoveryReason||e)},a)}}},{key:"scheduleSignalingBusyRetry",value:function(e){var t,i=this;if(!this.destroyed&&!this.hardFailed)if(this.isTransportAvailable()){if(!this.signalingBusyTimer){this.signalingBusyCount++;var r=this.getPeerConnection();if(this.logWarn("signalingState still busy",{reason:e,signalingState:null==r?void 0:r.signalingState,count:this.signalingBusyCount,max:this.options.maxSignalingBusyRetries}),this.signalingBusyCount>this.options.maxSignalingBusyRetries)this.failRecovery("signaling-stuck:".concat(null!==(t=null==r?void 0:r.signalingState)&&void 0!==t?t:"unknown"));else{this.state="waiting-signaling";var s=Math.floor(500*Math.random()),a=this.options.signalingBusyRetryDelayMs+s;this.logInfo("schedule signaling retry in ".concat(a,"ms")),this.signalingBusyTimer=v(function(){if(i.signalingBusyTimer=void 0,!i.destroyed&&!i.hardFailed&&i.session.state===n.Established)if(i.isTransportAvailable()){var e=i.getPeerConnection();if(e)return"stable"===e.signalingState?(i.signalingBusyCount=0,i.state="idle","connected"===e.iceConnectionState||"completed"===e.iceConnectionState?void i.handleIceRecovered():void i.recover("signaling-recovered")):void i.scheduleSignalingBusyRetry("signaling-busy:".concat(e.signalingState))}else i.waitForTransport("signaling-unavailable")},a)}}}else this.waitForTransport(e)}},{key:"isTransportAvailable",value:function(){var e=this.options.isSignalingAvailable;if(!e)return!0;try{return e()}catch(e){return this.logWarn("isSignalingAvailable() threw",e),!1}}},{key:"isRegistrationAvailable",value:function(){var e=this.options.isRegistrationAvailable;if(!e)return!0;try{return e()}catch(e){return this.logWarn("isRegistrationAvailable() threw",e),!1}}},{key:"waitForRegistration",value:function(e){var t=this;if(!this.destroyed&&!this.hardFailed){if(!this.isTransportAvailable())return this.clearRegistrationRecoveryTimer(),this.registrationWaitStartedAt=void 0,this.pendingRegistrationRecoveryReason=void 0,void this.waitForTransport(e);if(this.isRegistrationAvailable()){var i=void 0===this.registrationWaitStartedAt?0:d()-this.registrationWaitStartedAt;return this.clearRegistrationRecoveryTimer(),this.registrationWaitStartedAt=void 0,this.pendingRegistrationRecoveryReason=void 0,this.state="idle",this.logInfo("SIP registration recovered",{waitedMs:i,reason:e}),void this.resumeAfterRegistrationRecovery(e)}if(this.state="waiting-registration",this.pendingRegistrationRecoveryReason=e,void 0===this.registrationWaitStartedAt&&(this.registrationWaitStartedAt=d(),this.logWarn("SIP registration unavailable; pause ICE restart",{reason:e,timeoutMs:this.options.registrationRecoveryTimeoutMs})),!this.registrationRecoveryTimer)d()-this.registrationWaitStartedAt>=this.options.registrationRecoveryTimeoutMs?this.failRecovery("registration-recovery-timeout:".concat(e)):this.registrationRecoveryTimer=v(function(){var i;t.registrationRecoveryTimer=void 0,t.destroyed||t.hardFailed||t.session.state===n.Established&&t.waitForRegistration(null!==(i=t.pendingRegistrationRecoveryReason)&&void 0!==i?i:e)},this.options.registrationRecoveryPollMs)}}},{key:"resumeAfterRegistrationRecovery",value:function(e){return O(this,void 0,void 0,l.mark(function t(){var i;return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.destroyed&&!this.hardFailed&&this.session.state===n.Established){t.next=1;break}return t.abrupt("return");case 1:if(this.isTransportAvailable()){t.next=2;break}return this.waitForTransport(e),t.abrupt("return");case 2:if(this.isRegistrationAvailable()){t.next=3;break}return this.waitForRegistration(e),t.abrupt("return");case 3:if(i=this.getPeerConnection()){t.next=4;break}return t.abrupt("return");case 4:if("connected"!==i.iceConnectionState&&"completed"!==i.iceConnectionState){t.next=5;break}return this.handleIceRecovered(),t.abrupt("return");case 5:if("stable"===i.signalingState){t.next=6;break}return this.state="waiting-signaling",this.scheduleSignalingBusyRetry("registration-restored:".concat(i.signalingState)),t.abrupt("return");case 6:return this.state="idle",t.next=7,this.recover("registration-restored:".concat(e));case 7:case"end":return t.stop()}},t,this)}))}},{key:"waitForTransport",value:function(e){var t=this;if(!this.destroyed&&!this.hardFailed){if(this.isTransportAvailable())return this.transportWaitStartedAt=void 0,this.pendingTransportRecoveryReason=void 0,this.clearTransportRecoveryTimer(),this.state="idle",void this.resumeAfterTransportRecovery(e);if(this.state="waiting-transport",void 0===this.transportWaitStartedAt&&(this.transportWaitStartedAt=d(),this.logWarn("SIP Transport unavailable; pause ICE restart",{reason:e,timeoutMs:this.options.transportRecoveryTimeoutMs})),this.pendingTransportRecoveryReason=e,!this.transportRecoveryTimer)d()-this.transportWaitStartedAt>=this.options.transportRecoveryTimeoutMs?this.failRecovery("transport-recovery-timeout:".concat(e)):this.transportRecoveryTimer=v(function(){var i,r;if(t.transportRecoveryTimer=void 0,!t.destroyed&&!t.hardFailed&&t.session.state===n.Established)if(t.isTransportAvailable()){var s=null!==(r=t.pendingTransportRecoveryReason)&&void 0!==r?r:e,a=void 0===t.transportWaitStartedAt?0:d()-t.transportWaitStartedAt;t.transportWaitStartedAt=void 0,t.pendingTransportRecoveryReason=void 0,t.logInfo("SIP Transport recovered",{waitedMs:a,reason:s}),t.state="idle",t.resumeAfterTransportRecovery(s)}else t.waitForTransport(null!==(i=t.pendingTransportRecoveryReason)&&void 0!==i?i:e)},this.options.transportRecoveryPollMs)}}},{key:"resumeAfterTransportRecovery",value:function(e){return O(this,void 0,void 0,l.mark(function t(){var i;return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.destroyed&&!this.hardFailed&&this.session.state===n.Established){t.next=1;break}return t.abrupt("return");case 1:if(this.isTransportAvailable()){t.next=2;break}return this.waitForTransport(e),t.abrupt("return");case 2:if(this.isRegistrationAvailable()){t.next=3;break}return this.waitForRegistration(e),t.abrupt("return");case 3:if(i=this.getPeerConnection()){t.next=4;break}return t.abrupt("return");case 4:if("connected"!==i.iceConnectionState&&"completed"!==i.iceConnectionState){t.next=5;break}return this.handleIceRecovered(),t.abrupt("return");case 5:if("stable"===i.signalingState){t.next=6;break}return this.state="waiting-signaling",this.scheduleSignalingBusyRetry("transport-restored:".concat(i.signalingState)),t.abrupt("return");case 6:return this.state="idle",t.next=7,this.recover("transport-restored:".concat(e));case 7:case"end":return t.stop()}},t,this)}))}},{key:"failRecovery",value:function(e){var t,i,n,r,s;this.destroyed||this.hardFailed||(this.hardFailed=!0,this.recoveryGeneration++,this.state="failed",this.clearDisconnectedTimer(),this.clearRetryTimer(),this.clearSignalingBusyTimer(),this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.clearTransportRecoveryTimer(),this.clearRegistrationRecoveryTimer(),this.transportWaitStartedAt=void 0,this.pendingTransportRecoveryReason=void 0,this.registrationWaitStartedAt=void 0,this.pendingRegistrationRecoveryReason=void 0,this.stopRtpWatchdog(),this.logError("ICE recovery unrecoverable",{reason:e,retryCount:this.retryCount,signalingBusyCount:this.signalingBusyCount,iceConnectionState:null===(t=this.getPeerConnection())||void 0===t?void 0:t.iceConnectionState,connectionState:null===(i=this.getPeerConnection())||void 0===i?void 0:i.connectionState,signalingState:null===(n=this.getPeerConnection())||void 0===n?void 0:n.signalingState}),null===(s=(r=this.options).onRecoveryFailed)||void 0===s||s.call(r,e,this.retryCount))}},{key:"startRtpWatchdog",value:function(){var e=this;this.rtpStatsTimer||this.destroyed||this.hardFailed||(this.lastRtpProgressAt=d(),this.rtpStatsTimer=p(function(){e.checkRtpHealth()},this.options.rtpStatsIntervalMs))}},{key:"stopRtpWatchdog",value:function(){this.rtpStatsTimer&&(clearInterval(this.rtpStatsTimer),this.rtpStatsTimer=void 0)}},{key:"checkRtpHealth",value:function(){return O(this,void 0,void 0,l.mark(function e(){var t,i,r,s,a,o,c,u;return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.destroyed&&!this.hardFailed&&this.session.state===n.Established){e.next=1;break}return e.abrupt("return");case 1:if(t=this.getPeerConnection()){e.next=2;break}return e.abrupt("return");case 2:if("connected"===t.iceConnectionState||"completed"===t.iceConnectionState){e.next=3;break}return e.abrupt("return");case 3:if("sending-reinvite"!==this.state&&"waiting-ice"!==this.state&&"waiting-signaling"!==this.state&&"waiting-transport"!==this.state){e.next=4;break}return e.abrupt("return");case 4:return e.prev=4,e.next=5,this.readRtpSnapshot(t);case 5:i=e.sent,e.next=7;break;case 6:return e.prev=6,u=e.catch(4),this.logDebug("getStats failed:",u),e.abrupt("return");case 7:if(i.hasAudio||i.hasVideo){e.next=8;break}return e.abrupt("return");case 8:if(r=this.lastRtpSnapshot,this.lastRtpSnapshot=i,r){e.next=9;break}return this.lastRtpProgressAt=d(),e.abrupt("return");case 9:if(s=i.audioBytes>r.audioBytes||i.audioPackets>r.audioPackets,a=i.videoBytes>r.videoBytes||i.videoPackets>r.videoPackets||i.videoFramesDecoded>r.videoFramesDecoded,!s&&!a){e.next=10;break}return this.lastRtpProgressAt=d(),e.abrupt("return");case 10:if(!((o=d()-this.lastRtpProgressAt)<this.options.rtpStallTimeoutMs)){e.next=11;break}return e.abrupt("return");case 11:if(!((c=d())-this.lastRtpRecoveryAt<this.options.rtpRecoveryCooldownMs)){e.next=12;break}return e.abrupt("return");case 12:if(this.logWarn("RTP stalled for ".concat(o,"ms"),{ice:t.iceConnectionState,connection:t.connectionState,signaling:t.signalingState,audioBytes:i.audioBytes,audioPackets:i.audioPackets,videoBytes:i.videoBytes,videoPackets:i.videoPackets,videoFramesDecoded:i.videoFramesDecoded}),this.options.recoverOnRtpStallWhenIceConnected){e.next=13;break}return e.abrupt("return");case 13:this.lastRtpRecoveryAt=c,this.recover("rtp-stalled");case 14:case"end":return e.stop()}},e,this,[[4,6]])}))}},{key:"readRtpSnapshot",value:function(e){return O(this,void 0,void 0,l.mark(function t(){var i,n;return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=1,e.getStats();case 1:return i=t.sent,n={timestamp:d(),audioBytes:0,audioPackets:0,videoBytes:0,videoPackets:0,videoFramesDecoded:0,hasAudio:!1,hasVideo:!1},f(i).call(i,function(e){var t;if("inbound-rtp"===e.type&&!0!==e.isRemote){var i=null!==(t=e.kind)&&void 0!==t?t:e.mediaType;"audio"===i&&(n.hasAudio=!0,"number"==typeof e.bytesReceived&&(n.audioBytes+=e.bytesReceived),"number"==typeof e.packetsReceived&&(n.audioPackets+=e.packetsReceived)),"video"===i&&(n.hasVideo=!0,"number"==typeof e.bytesReceived&&(n.videoBytes+=e.bytesReceived),"number"==typeof e.packetsReceived&&(n.videoPackets+=e.packetsReceived),"number"==typeof e.framesDecoded&&(n.videoFramesDecoded+=e.framesDecoded))}}),t.abrupt("return",n);case 2:case"end":return t.stop()}},t)}))}},{key:"getSessionDescriptionHandler",value:function(){return this.session.sessionDescriptionHandler}},{key:"getPeerConnection",value:function(){var e;return null===(e=this.getSessionDescriptionHandler())||void 0===e?void 0:e.peerConnection}},{key:"readIceCredentials",value:function(e){var t,i,n,r;return e?{ufrag:null===(i=null===(t=e.match(/^a=ice-ufrag:(.+)$/m))||void 0===t?void 0:t[1])||void 0===i?void 0:j(i).call(i),pwd:null===(r=null===(n=e.match(/^a=ice-pwd:(.+)$/m))||void 0===n?void 0:n[1])||void 0===r?void 0:j(r).call(r)}:{}}},{key:"hasIceCredentialsChanged",value:function(e,t){return e.ufrag!==t.ufrag||e.pwd!==t.pwd}},{key:"isRequestPendingError",value:function(e){return e instanceof Error&&("RequestPendingError"===e.name||/request.*pending/i.test(e.message))}},{key:"isCurrentGeneration",value:function(e){return!this.destroyed&&!this.hardFailed&&e===this.recoveryGeneration}},{key:"clearDisconnectedTimer",value:function(){this.disconnectedTimer&&(clearTimeout(this.disconnectedTimer),this.disconnectedTimer=void 0)}},{key:"clearRetryTimer",value:function(){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0)}},{key:"clearSignalingBusyTimer",value:function(){this.signalingBusyTimer&&(clearTimeout(this.signalingBusyTimer),this.signalingBusyTimer=void 0)}},{key:"clearNegotiationTimer",value:function(){this.negotiationTimer&&(clearTimeout(this.negotiationTimer),this.negotiationTimer=void 0)}},{key:"clearIceRecoveryTimer",value:function(){this.iceRecoveryTimer&&(clearTimeout(this.iceRecoveryTimer),this.iceRecoveryTimer=void 0)}},{key:"clearTransportRecoveryTimer",value:function(){this.transportRecoveryTimer&&(clearTimeout(this.transportRecoveryTimer),this.transportRecoveryTimer=void 0)}},{key:"clearRegistrationRecoveryTimer",value:function(){this.registrationRecoveryTimer&&(clearTimeout(this.registrationRecoveryTimer),this.registrationRecoveryTimer=void 0)}},{key:"clearAllTimers",value:function(){this.clearDisconnectedTimer(),this.clearRetryTimer(),this.clearSignalingBusyTimer(),this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.stopRtpWatchdog(),this.onlineTimer&&(clearTimeout(this.onlineTimer),this.onlineTimer=void 0)}},{key:"logDebug",value:function(){for(var e,t,i,n,r=arguments.length,s=new Array(r),a=0;a<r;a++)s[a]=arguments[a];null===(n=(i=this.options.logger).debug)||void 0===n||(e=n).call.apply(e,b(t=[i,"[SipIceRecovery]"]).call(t,s))}},{key:"logInfo",value:function(){for(var e,t,i,n,r=arguments.length,s=new Array(r),a=0;a<r;a++)s[a]=arguments[a];null===(n=(i=this.options.logger).info)||void 0===n||(e=n).call.apply(e,b(t=[i,"[SipIceRecovery]"]).call(t,s))}},{key:"logWarn",value:function(){for(var e,t,i,n,r=arguments.length,s=new Array(r),a=0;a<r;a++)s[a]=arguments[a];null===(n=(i=this.options.logger).warn)||void 0===n||(e=n).call.apply(e,b(t=[i,"[SipIceRecovery]"]).call(t,s))}},{key:"logError",value:function(){for(var e,t,i,n,r=arguments.length,s=new Array(r),a=0;a<r;a++)s[a]=arguments[a];null===(n=(i=this.options.logger).error)||void 0===n||(e=n).call.apply(e,b(t=[i,"[SipIceRecovery]"]).call(t,s))}}])}(),xi=function(){return t(function t(){var r=this,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e(this,t),se.add(this),ae.set(this,void 0),oe.set(this,void 0),ce.set(this,void 0),le.set(this,void 0),ue.set(this,void 0),he.set(this,void 0),de.set(this,[]),fe.set(this,[]),ve.set(this,{}),pe.set(this,void 0),ge.set(this,void 0),me.set(this,new MediaStream),be.set(this,JSON.parse(u(V))),ye.set(this,0),we.set(this,void 0),ke.set(this,void 0),Re.set(this,void 0),h(this,"token",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Se.set(this,void 0),xe.set(this,48e4),Te.set(this,12e6),Ce.set(this,{}),Ie.set(this,void 0),Ae.set(this,void 0),De.set(this,void 0),Ee.set(this,function(e){}),Me.set(this,function(e){}),Pe.set(this,function(e){}),je.set(this,function(e){}),Oe.set(this,function(e){return O(r,void 0,void 0,l.mark(function t(){var i,n,r,s;return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!N(this,we,"f")||!N(this,ke,"f")){t.next=3;break}if(!(d()-N(this,ke,"f")>e)){t.next=3;break}return t.next=1,N(this,Fe,"f").call(this);case 1:if(s=t.sent){t.next=2;break}s={};case 2:n=(i=s).sign,r=i.timestamp,F(this,we,null!=n?n:N(this,we,"f"),"f"),F(this,ke,null!=r?r:N(this,ke,"f"),"f");case 3:case"end":return t.stop()}},t,this)}))}),Ne.set(this,function(e){return O(r,void 0,void 0,l.mark(function t(){var i,n,r,s,a;return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!N(this,Se,"f")){t.next=4;break}if(!(d()-N(this,Se,"f")>e)){t.next=4;break}if(!N(this,Re,"f")){t.next=2;break}return t.next=1,N(this,Be,"f").call(this);case 1:i=t.sent,n=i.token,r=i.tokenTimestamp,F(this,Re,null!=n?n:N(this,Re,"f"),"f"),F(this,Se,null!=r?r:d(),"f"),t.next=4;break;case 2:if(!this.token){t.next=4;break}return t.next=3,this.getGatewayAccessToken({corpId:N(this,at,"f"),sid:N(this,lt,"f"),secret:N(this,ot,"f"),seatOnline:!1});case 3:s=t.sent,a=s.token,this.token=a,F(this,Se,d(),"f");case 4:case"end":return t.stop()}},t,this)}))}),Fe.set(this,function(){}),Be.set(this,function(){}),qe.set(this,function(e){}),He.set(this,function(e){}),We.set(this,void 0),Le.set(this,void 0),h(this,"networkSpeed",{enumerable:!0,configurable:!0,writable:!0,value:"0.00Mb/s"}),h(this,"networkDelay",{enumerable:!0,configurable:!0,writable:!0,value:"0ms"}),h(this,"onLine",{enumerable:!0,configurable:!0,writable:!0,value:navigator.onLine}),h(this,"testspeeding",{enumerable:!0,configurable:!0,writable:!0,value:!1}),h(this,"goodNetworkSpeed",{enumerable:!0,configurable:!0,writable:!0,value:function(){return 1e3*Number(r.networkSpeed.replace("Mb/s",""))>=30}}),h(this,"goodNetworkDelay",{enumerable:!0,configurable:!0,writable:!0,value:function(){return Number(r.networkDelay.replace("ms",""))<=500&&"0ms"!==r.networkDelay}}),h(this,"authorizedMicrophonePermissions",{enumerable:!0,configurable:!0,writable:!0,value:!1}),h(this,"authorizedNotificationPermissions",{enumerable:!0,configurable:!0,writable:!0,value:!1}),ze.set(this,100),Ge.set(this,3),Ue.set(this,8),Xe.set(this,2),Ve.set(this,0),_e.set(this,!1),Ye.set(this,void 0),Je.set(this,3),Ke.set(this,3),Ze.set(this,0),$e.set(this,0),Qe.set(this,0),et.set(this,!1),tt.set(this,!1),it.set(this,!1),nt.set(this,void 0),rt.set(this,void 0),st.set(this,void 0),at.set(this,void 0),ot.set(this,void 0),ct.set(this,void 0),lt.set(this,void 0),ut.set(this,void 0),ht.set(this,void 0),dt.set(this,void 0),ft.set(this,void 0),vt.set(this,function(e){N(r,se,"m",gi).call(r)}),pt.set(this,function(){}),gt.set(this,void 0),mt.set(this,void 0),bt.set(this,!1),yt.set(this,4e3),wt.set(this,4e3),kt.set(this,{}),Rt.set(this,!1),St.set(this,!0),h(this,"ifAutoAnswer",{enumerable:!0,configurable:!0,writable:!0,value:function(){return String(N(r,kt,"f").autoAnswer)===H.YES}}),h(this,"notNeedSendStarDtmf",{enumerable:!0,configurable:!0,writable:!0,value:function(){return String(N(r,kt,"f").afterTransferLabour)===z.DIRECT_ANSWER}}),xt.set(this,function(){if(N(r,St,"f")){var e;N(r,Tt,"f").call(r);var t=new(window.AudioContext||window.webkitAudioContext);F(r,Ae,t.createScriptProcessor(2048,1,1),"f"),N(r,Ae,"f").onaudioprocess=function(e){for(var t=e.inputBuffer.getChannelData(0),i=0,n=0;n<t.length;++n)i+=t[n]*t[n];F(r,ye,Number(Math.sqrt(i/t.length).toFixed(2)),"f"),N(r,Ee,"f").call(r,N(r,ye,"f"))},F(r,De,new MediaStream,"f"),f(e=r.getSenders()).call(e,function(e){e.track&&N(r,De,"f").addTrack(e.track)}),F(r,Ie,t.createMediaStreamSource(N(r,De,"f")),"f"),N(r,Ie,"f").connect(N(r,Ae,"f")),N(r,Ae,"f").connect(t.destination)}}),Tt.set(this,function(){if(N(r,St,"f")){if(N(r,Ie,"f"))try{N(r,Ie,"f").disconnect()}catch(e){console.log(e)}if(N(r,Ae,"f"))try{N(r,Ae,"f").disconnect()}catch(e){console.log(e)}if(N(r,De,"f"))try{var e;f(e=N(r,De,"f").getTracks()).call(e,function(e){e.stop()})}catch(e){console.log(e)}}F(r,Ie,void 0,"f"),F(r,Ae,void 0,"f"),F(r,De,void 0,"f"),F(r,ye,0,"f"),N(r,Ee,"f").call(r,N(r,ye,"f"))}),h(this,"disposeSoftphoneEnvRequirementCheck",{enumerable:!0,configurable:!0,writable:!0,value:function(){N(r,Ct,"f").call(r),window.removeEventListener("offline",N(r,Dt,"f")),window.removeEventListener("online",N(r,At,"f")),window.removeEventListener("unload",r.disposeSoftphoneEnvRequirementCheck)}}),Ct.set(this,function(){clearInterval(N(r,We,"f")),F(r,We,void 0,"f"),clearTimeout(N(r,Le,"f")),F(r,Le,void 0,"f"),r.testspeeding=!1}),h(this,"softphoneEnvCheck",{enumerable:!0,configurable:!0,writable:!0,value:function(){return O(r,void 0,void 0,l.mark(function e(){return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:this.testspeeding||(N(this,It,"f").call(this),this.oneRoundOfTesting());case 1:case"end":return e.stop()}},e,this)}))}}),It.set(this,function(){window.addEventListener("offline",N(r,Dt,"f")),window.addEventListener("online",N(r,At,"f")),window.addEventListener("unload",r.disposeSoftphoneEnvRequirementCheck)}),h(this,"oneRoundOfTesting",{enumerable:!0,configurable:!0,writable:!0,value:function(){return O(r,void 0,void 0,l.mark(function e(){var t=this;return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:this.testspeeding=!0,this.detectNavigatorPermissions(),this.onLine?(N(this,Et,"f").call(this,this),F(this,Le,v(function(){t.testspeeding=!1,t.disposeSoftphoneEnvRequirementCheck()},4e3),"f")):this.testspeeding=!1;case 1:case"end":return e.stop()}},e,this)}))}}),At.set(this,function(){r.onLine=!0,r.oneRoundOfTesting()}),Dt.set(this,function(){r.onLine=!1,r.networkSpeed="0.00Mb/s",r.networkDelay="0ms",N(r,He,"f").call(r,{networkSpeed:r.networkSpeed,networkDelay:r.networkDelay,authorizedMicrophonePermissions:r.authorizedMicrophonePermissions,authorizedNotificationPermissions:r.authorizedNotificationPermissions}),N(r,Ct,"f").call(r)}),Et.set(this,function(e){return O(r,void 0,void 0,l.mark(function t(){var i,n,r=this;return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return i=e||this,clearInterval(N(i,We,"f")),F(i,We,void 0,"f"),n=function(){return O(r,void 0,void 0,l.mark(function e(){var t;return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!i.onLine){e.next=5;break}return e.prev=1,e.next=2,N(i,Mt,"f").call(i,"1"===N(i,dt,"f")?"https://seat.teleai.com/favicon.png":void 0);case 2:t=e.sent,i.networkSpeed=t.networkSpeed,i.networkDelay=t.networkDelay,e.next=4;break;case 3:e.prev=3,e.catch(1),i.networkSpeed="0.00Mb/s",i.networkDelay="0ms";case 4:e.next=6;break;case 5:i.networkSpeed="0.00Mb/s",i.networkDelay="0ms";case 6:N(this,He,"f").call(this,{networkSpeed:this.networkSpeed,networkDelay:this.networkDelay,authorizedMicrophonePermissions:this.authorizedMicrophonePermissions,authorizedNotificationPermissions:this.authorizedNotificationPermissions}),N(this,Le,"f")||(this.testspeeding=!1,this.disposeSoftphoneEnvRequirementCheck());case 7:case"end":return e.stop()}},e,this,[[1,3]])}))},t.next=1,n();case 1:N(this,Le,"f")&&F(i,We,p(function(){return O(this,void 0,void 0,l.mark(function e(){return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,n();case 1:case"end":return e.stop()}},e)}))},1e3),"f");case 2:case"end":return t.stop()}},t,this)}))}),Mt.set(this,function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"https://seat.94ai.com/favicon.png",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:63491,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;return O(r,void 0,void 0,l.mark(function n(){var r,s;return l.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:for(r=[],s=0;s<i;s++)r.push(N(this,Pt,"f").call(this,e+"?d="+d()+s,t));return n.abrupt("return",g.all(r).then(function(e){var t=0,n=0;return f(e).call(e,function(e){t+=Number(e[0]),n+=Number(e[1])}),{networkDelay:(n/i).toFixed(2)+"ms",networkSpeed:(t/i).toFixed(2)+"Mb/s"}}));case 1:case"end":return n.stop()}},n,this)}))}),Pt.set(this,function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"https://seat.94ai.com/favicon.png?d="+d(),t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:63491;return new g(function(i,n){var r=document.createElement("img");r.start=window.performance.now(),r.onload=function(){var e=window.performance.now()-r.start;i([(1e3*t/(1048576*e)).toFixed(2),e])},r.onerror=function(e){n(e)},r.src=e}).catch(function(e){throw e})}),h(this,"openApiAjax",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return new g(function(t,i){return O(r,void 0,void 0,l.mark(function n(){var r,s,a,o,c,u,h,f,v,p,g,m,b,y,w,k,R;return l.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(n.prev=0,v=N(this,at,"f")||(null===(r=e.data)||void 0===r?void 0:r.appKey),p=N(this,ot,"f")||(null===(s=e.data)||void 0===s?void 0:s.appSecret),g=N(this,we,"f")||(null===(a=e.data)||void 0===a?void 0:a.sign),m=N(this,ke,"f")||(null===(o=e.data)||void 0===o?void 0:o.timestamp),null===(c=e.data)||void 0===c||delete c.appKey,null===(u=e.data)||void 0===u||delete u.appSecret,null===(h=e.data)||void 0===h||delete h.sign,null===(f=e.data)||void 0===f||delete f.timestamp,v){n.next=1;break}throw new Error("缺少appKey");case 1:if(!p){n.next=2;break}m=d(),g=I.enc.Base64.stringify(I.HmacSHA1(v+m,p)),n.next=5;break;case 2:if(!g||!m){n.next=4;break}return n.next=3,N(this,Oe,"f").call(this,N(this,xe,"f"));case 3:g=N(this,we,"f")||g,m=N(this,ke,"f")||m,n.next=5;break;case 4:throw new Error("缺少appSecret或sign+timestamp");case 5:return b=re(t,i,e),y=b.xhr,w=b.ajaxData,k=b.contentType,y.setRequestHeader("appKey",v),y.setRequestHeader("timestamp",String(m)),y.setRequestHeader("sign",g),y.setRequestHeader("Content-type",k||"application/json"),n.next=6,N(this,Pe,"f").call(this,y);case 6:y.send(w),n.next=8;break;case 7:throw n.prev=7,R=n.catch(0),i(R.message),R;case 8:case"end":return n.stop()}},n,this,[[0,7]])}))})}}),h(this,"requestGateway",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return r.gatewayApiAjax(m(m({},e),{url:r.getGateway()+e.url}),t)}}),h(this,"gatewayApiAjax",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return new g(function(i,n){return O(r,void 0,void 0,l.mark(function r(){var s,a,o,c,u,h;return l.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(r.prev=0,s=re(i,n,e),a=s.xhr,o=s.ajaxData,c=s.contentType,!t){r.next=2;break}return r.next=1,this.getGatewayToken();case 1:u=r.sent,a.setRequestHeader("x-token",u),a.setRequestHeader("seatsToken",u),a.setRequestHeader("x-authority-token",u);case 2:return a.setRequestHeader("x-app-code",3),a.setRequestHeader("content-type",c||"application/json"),r.next=3,N(this,je,"f").call(this,a);case 3:a.send(o),r.next=5;break;case 4:throw r.prev=4,h=r.catch(0),n(h.message),h;case 5:case"end":return r.stop()}},r,this,[[0,4]])}))})}}),h(this,"requestOpenApi",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return r.openApiAjax(m(m({},e),{url:r.getOpenApi()+e.url}))}}),h(this,"getDeviceId",{enumerable:!0,configurable:!0,writable:!0,value:function(){return O(r,void 0,void 0,l.mark(function e(){var t,i;return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!N(this,ft,"f")){e.next=1;break}return e.abrupt("return",N(this,ft,"f"));case 1:return e.next=2,A.load();case 2:return t=e.sent,e.next=3,t.get();case 3:return i=e.sent,F(this,ft,i.visitorId,"f"),e.abrupt("return",N(this,ft,"f"));case 4:case"end":return e.stop()}},e,this)}))}}),Wt.set(this,function(){return O(r,void 0,void 0,l.mark(function e(){var t,n,r,s;return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!N(this,se,"m",Ht).call(this)||N(this,ve,"f").authorizationUsername&&N(this,ve,"f").uri&&N(this,ve,"f").authorizationPassword&&N(this,ve,"f").transportOptions.server){e.next=3;break}return e.next=1,this.getAgentInfo();case 1:if(200!=(t=e.sent).code){e.next=2;break}s=t.data,N(this,ve,"f").authorizationUsername=s.agentExtension,N(this,ve,"f").authorizationPassword=s.extensionPwd,N(this,ve,"f").contactName||(N(this,ve,"f").contactName=s.agentExtension),N(this,ve,"f").uri=i.makeURI(b(n="sip:".concat(s.agentExtension,"@")).call(n,s.wsRegisterAddress)),N(this,ve,"f").transportOptions.server=b(r="".concat(s.wsProtocol,"://")).call(r,s.wsRegisterAddress),F(this,lt,s.agentId,"f"),F(this,ct,s.agentTag,"f"),e.next=3;break;case 2:throw new Error(u(t));case 3:case"end":return e.stop()}},e,this)}))}),Lt.set(this,function(){return O(r,void 0,void 0,l.mark(function e(){var t;return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(N(this,ve,"f").viaHost){e.next=2;break}return t="",e.next=1,this.getDeviceId();case 1:N(this,ve,"f").viaHost=b(t).call(t,e.sent,".sip");case 2:case"end":return e.stop()}},e,this)}))}),Gt.set(this,function(e){var t,i,n,s,a,o,c,l,u,h,d,f,v,p,g,m,b,w,k,R,S,x,T;N(r,kt,"f").popWindow=null===(a=e["X-Popwindow"])||void 0===a?void 0:a[0].raw,N(r,kt,"f").afterTransferLabour=null===(o=e["X-Aftertransferlabour"])||void 0===o?void 0:o[0].raw,N(r,kt,"f").callId=null===(c=e["X-94callid"])||void 0===c?void 0:c[0].raw,N(r,kt,"f").cid=null===(l=e["X-Cid"])||void 0===l?void 0:l[0].raw,N(r,kt,"f").numberId=null===(u=e["X-Numberid"])||void 0===u?void 0:u[0].raw,N(r,kt,"f").tag=(null===(h=e["X-Tag"])||void 0===h?void 0:h[0].raw)&&"null"!==(null===(d=e["X-Tag"])||void 0===d?void 0:d[0].raw)?y(t=e["X-Tag"][0].raw.split("-")).call(t,function(e){return String.fromCharCode(e)}).join(""):"",N(r,kt,"f").numberTag=(null===(f=e["X-Numbertag"])||void 0===f?void 0:f[0].raw)&&"null"!==(null===(v=e["X-Numbertag"])||void 0===v?void 0:v[0].raw)?decodeURIComponent(e["X-Numbertag"][0].raw):"",N(r,kt,"f").taskId=null===(p=e["X-Taskid"])||void 0===p?void 0:p[0].raw,N(r,kt,"f").voiceType=null===(g=e["X-Voicetype"])||void 0===g?void 0:g[0].raw,N(r,kt,"f").processTime=null===(m=e["X-Processtime"])||void 0===m?void 0:m[0].raw,N(r,kt,"f").userPhone=null===(b=e["X-Userphone"])||void 0===b?void 0:b[0].raw,N(r,kt,"f").autoAnswer=null===(w=e["X-94autoanswer"])||void 0===w?void 0:w[0].raw,N(r,kt,"f").nodeTitle=null===(k=e["X-Nodetitle"])||void 0===k?void 0:y(i=k[0].raw.split("-")).call(i,function(e){return String.fromCharCode(e)}).join(""),N(r,kt,"f").taskName=null===(R=e["X-Taskname"])||void 0===R?void 0:y(n=R[0].raw.split("-")).call(n,function(e){return String.fromCharCode(e)}).join(""),N(r,kt,"f").templateTitle=null===(S=e["X-Templatetitle"])||void 0===S?void 0:y(s=S[0].raw.split("-")).call(s,function(e){return String.fromCharCode(e)}).join(""),N(r,kt,"f").phoneNumber=(null===(x=e["X-Phonenumber"])||void 0===x?void 0:x[0].raw)||(null===(T=e.From)||void 0===T?void 0:T[0].parsed.uri.normal.user)}),ni.set(this,function(e){switch(e){case n.Initial:case n.Establishing:break;case n.Established:N(r,se,"m",ii).call(r);break;case n.Terminating:case n.Terminated:r.clearIceAutoDetection();var t=v(function(){clearTimeout(t),t=void 0,N(r,be,"f").incomingStatus=!1,N(r,be,"f").answerStatus=!1},10);N(r,Tt,"f").call(r);break;default:throw new Error("Unknown session state.")}}),si.set(this,function(e,t,i){N(r,Ue,"f")&&(F(r,_e,!1,"f"),N(r,be,"f").reconnectStatus=!1,N(r,tt,"f")&&(F(r,tt,!1,"f"),N(r,ci,"f").call(r,e,t,i)))}),ai.set(this,function(){return O(r,void 0,void 0,l.mark(function e(){return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(N(this,Ue,"f")){F(this,_e,!0,"f"),F(this,tt,!1,"f");try{this.getUserAgent().transport.disconnect().catch(function(e){return console.error(e)})}catch(e){}console.log("sip transport disconnect");try{N(this,se,"m",ri).call(this)}catch(e){}N(this,li,"f").call(this),N(this,se,"m",gi).call(this)}case 1:case"end":return e.stop()}},e,this)}))}),oi.set(this,function(){if(N(r,Ue,"f")){var e=N(r,ve,"f").uri.clone(),t=N(r,ve,"f").uri.clone(),i=N(r,ve,"f").uri.clone();i.user=void 0,N(r,ci,"f").call(r,i,e,t)}}),ci.set(this,function(e,t,i){if(N(r,Ue,"f")){if(N(r,tt,"f"))return;F(r,tt,!0,"f"),F(r,rt,v(function(){N(r,se,"m",vi).call(r);var n=r.getUserAgent().userAgentCore,s=n.makeOutgoingRequestMessage("OPTIONS",e,t,i,{});F(r,Ye,n.request(s,{onAccept:function(){console.log("sip ping ok"),F(r,Ve,0,"f"),F(r,Ye,void 0,"f"),N(r,si,"f").call(r,e,t,i)},onReject:function(n){var s;if(F(r,Ye,void 0,"f"),408===n.message.statusCode||503===n.message.statusCode)if(console.log("sip ping error with code "+n.message.statusCode),N(r,Xe,"f")>0&&N(r,Ve,"f")>=N(r,Xe,"f"))console.log("sip maximum ping attempts reached"),N(r,ai,"f").call(r);else{var a,o;if(N(r,Ve,"f")>0)console.log(b(o="sip ping retry ".concat(N(r,Ve,"f")," of ")).call(o,N(r,Xe,"f")," fail"));F(r,Ve,(s=N(r,Ve,"f"),++s),"f"),console.log(b(a="sip ping retry ".concat(N(r,Ve,"f")," of ")).call(a,N(r,Xe,"f"))),N(r,si,"f").call(r,e,t,i)}else F(r,Ve,0,"f"),N(r,si,"f").call(r,e,t,i)}}),"f")},1e3*N(r,Ue,"f")),"f")}}),li.set(this,function(){if(N(r,Ue,"f")){if(F(r,tt,!1,"f"),F(r,_e,!1,"f"),N(r,Ye,"f")){try{N(r,Ye,"f").dispose()}catch(e){}F(r,Ye,void 0,"f")}N(r,rt,"f")&&N(r,se,"m",vi).call(r)}}),pi.set(this,function(){if(N(r,Je,"f")){if(N(r,it,"f"))return;F(r,it,!0,"f"),N(r,be,"f").reconnectStatus=!0,F(r,st,v(function(){return O(r,void 0,void 0,l.mark(function e(){var t,i=this;return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,N(this,se,"m",di).call(this),0===N(this,Ze,"f")&&console.log("sip reconnect success then register start"),e.next=1,N(this,le,"f").register({requestDelegate:{onAccept:function(e){console.log("sip reconnect success and register ok"),F(i,Ze,0,"f"),F(i,it,!1,"f"),N(i,be,"f").registerStatus=!0,N(i,be,"f").reconnectStatus=!1,N(i,oi,"f").call(i)},onReject:function(e){return O(i,void 0,void 0,l.mark(function t(){var i,n;return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(console.log("sip reconnect success but register fail with code "+e.message.statusCode),F(this,it,!1,"f"),!(N(this,Ke,"f")<=N(this,Ze,"f"))){t.next=2;break}return console.log("sip maximum register attempts reached"),F(this,Ze,0,"f"),t.next=1,this.getUserAgent().transport.disconnect().catch(function(e){return console.error(e)});case 1:N(this,se,"m",gi).call(this),t.next=3;break;case 2:F(this,Ze,(i=N(this,Ze,"f"),++i),"f"),console.log(b(n="sip reconnect success and register retry ".concat(N(this,Ze,"f")," of ")).call(n,N(this,Ke,"f"))),N(this,pi,"f").call(this);case 3:case"end":return t.stop()}},t,this)}))}},requestOptions:{extraHeaders:N(this,oe,"f")}});case 1:e.next=3;break;case 2:e.prev=2,t=e.catch(0),console.log("sip reconnect then registerer register error",t),F(this,Ze,0,"f"),F(this,it,!1,"f");case 3:case"end":return e.stop()}},e,this,[[0,2]])}))},1e3*N(r,Je,"f")),"f")}}),"object"!==c(s))throw new Error("userAgentOption must be plain object");N(this,se,"m",Ft).call(this,s),N(this,se,"m",Bt).call(this,s),N(this,se,"m",Nt).call(this,s),N(this,se,"m",qt).call(this,s),N(this,se,"m",Xt).call(this,s),N(this,se,"m",Ot).call(this,s),N(this,se,"m",jt).call(this,s),F(this,ve,N(this,se,"m",_t).call(this,s),"f")},[{key:"volumeValue",get:function(){return N(this,ye,"f")}},{key:"businessAttribute",get:function(){return N(this,kt,"f")}},{key:"getFastOutboundCall",value:function(){return N(this,kt,"f").voiceType===L.LABOUR}},{key:"getSitOutboundCall",value:function(){return N(this,kt,"f").voiceType===L.AI}},{key:"detectNavigatorPermissions",value:function(){var e,t=this;-1===w(e=navigator.userAgent).call(e,"Firefox")?navigator.permissions.query({name:"microphone"}).then(function(e){"granted"===e.state?t.authorizedMicrophonePermissions=!0:t.authorizedMicrophonePermissions=!1}).catch(function(e){console.log("Got error :",e),t.authorizedMicrophonePermissions=!1}):navigator.mediaDevices.enumerateDevices().then(function(e){""!==k(e).call(e,function(e){return"audioinput"===e.kind})[0].label?t.authorizedMicrophonePermissions=!0:t.authorizedMicrophonePermissions=!1}),navigator.permissions.query({name:"notifications"}).then(function(e){"granted"===e.state?t.authorizedNotificationPermissions=!0:t.authorizedNotificationPermissions=!1}).catch(function(e){console.log("Got error :",e),t.authorizedNotificationPermissions=!1})}},{key:"getGateway",value:function(){return"1"===N(this,dt,"f")?"https://gateway.teleai.com":"https://gateway.94ai.com"}},{key:"getGatewayToken",value:function(){return O(this,void 0,void 0,l.mark(function e(){var t,i;return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,N(this,Ne,"f").call(this,N(this,Te,"f"));case 1:if(!N(this,Re,"f")){e.next=2;break}return e.abrupt("return",N(this,Re,"f"));case 2:if(this.token){e.next=5;break}return e.next=3,N(this,Wt,"f").call(this);case 3:return e.next=4,this.getGatewayAccessToken({corpId:N(this,at,"f"),sid:N(this,lt,"f"),secret:N(this,ot,"f"),seatOnline:!1});case 4:t=e.sent,i=t.token,this.token=i,F(this,Se,d(),"f");case 5:return e.abrupt("return",this.token);case 6:case"end":return e.stop()}},e,this)}))}},{key:"getGatewayAccessToken",value:function(e){return this.requestGateway({url:"/authority/accessToken/openApi",data:e},!1)}},{key:"getCallNumberDetail",value:function(e){return this.requestGateway({url:"/task-aggre/callCenterNumber/get",data:e})}},{key:"getCallNumberChats",value:function(e){return this.requestGateway({url:"/dialogue-aggre/call-center-number/chat/list",data:e})}},{key:"getCallInfo",value:function(){return O(this,void 0,void 0,l.mark(function e(){var t,i,n,r=this;return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t=m({},N(this,kt,"f")),i=function(){return O(r,void 0,void 0,l.mark(function e(){var i,n,r,s,a,o,c,u,h,d,f,v,p,g,m,w,k,R,S,x;return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.numberId||!t.taskId){e.next=13;break}return i={},e.prev=1,e.next=2,this.getCallNumberDetail({id:t.numberId,taskId:t.taskId});case 2:if(200===(i=e.sent).code){e.next=3;break}return console.error(i.message),t.stop=!0,N(this,qe,"f").call(this,i.message),e.abrupt("return");case 3:e.next=5;break;case 4:return e.prev=4,e.catch(1),s=b(n=b(r="当前会话callid:".concat(t.callId,",根据numberId:")).call(r,t.numberId,",taskId:")).call(n,t.taskId,":查询坐席接听状态异常"),console.error(s),t.stop=!0,N(this,qe,"f").call(this,i.message),e.abrupt("return");case 5:if(a=i.data,o=a.callType,c=a.newIntentTag,u=a.intentTag,h=a.number,d=a.numberMd5,f=a.sid,v=a.config,p=a.tag,10!==a.state){e.next=6;break}return console.log("当前会话callid:".concat(t.callId,"已结束")),t.stop=!0,e.abrupt("return");case 6:if(t.callType||(t.callType=o),t.intentTag=c||u,t.number||(t.number=h),t.numberMD5||(t.numberMD5=d),t.agentId||(t.agentId=f),t.tag||(t.tag=p),t.templateId||v&&"string"==typeof v&&(g=JSON.parse(v))&&g.templateId&&(t.templateId=g.templateId),!t.callId){e.next=12;break}return w={},e.prev=7,e.next=8,this.getCallNumberChats({callId:t.callId,taskId:t.taskId});case 8:if(200===(w=e.sent).code){e.next=9;break}return console.error(w.message),t.stop=!0,N(this,qe,"f").call(this,w.message),e.abrupt("return");case 9:e.next=11;break;case 10:return e.prev=10,e.catch(7),R=b(k="当前会话根据callId:".concat(t.callId,",taskId:")).call(k,t.taskId,":查询会话对话记录异常"),console.error(R),t.stop=!0,N(this,qe,"f").call(this,R),e.abrupt("return");case 11:t.chats=y(m=w.data).call(m,function(e){return e.matchinfo&&(e.matchinfo=JSON.parse(e.matchinfo)),e}),N(this,Ce,"f")[t.callId]=t;case 12:try{N(this,Me,"f").call(this,N(this,Ce,"f")[t.callId])}catch(e){console.log(e)}e.next=14;break;case 13:t.stop=!0,t.taskId||(S="当前会话callid:".concat(t.callId,"的taskId不存在,无法查询通话记录"),console.error(S),N(this,qe,"f").call(this,S)),t.numberId||(x="当前会话callid:".concat(t.callId,"的numberId不存在,无法查询通话记录"),console.error(x),N(this,qe,"f").call(this,x));case 14:case"end":return e.stop()}},e,this,[[1,4],[7,10]])}))},e.prev=1;case 2:if(!t.stop){e.next=3;break}return e.abrupt("continue",7);case 3:return e.next=4,i();case 4:if(!t.stop){e.next=5;break}return e.abrupt("continue",7);case 5:return e.next=6,new g(function(e){var t=v(function(){return O(r,void 0,void 0,l.mark(function i(){return l.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:clearTimeout(t),t=void 0,e(!0);case 1:case"end":return i.stop()}},i)}))},3e3)});case 6:e.next=2;break;case 7:e.next=9;break;case 8:e.prev=8,n=e.catch(1),N(this,qe,"f").call(this,n);case 9:case"end":return e.stop()}},e,this,[[1,8]])}))}},{key:"refreshCallChatInfo",value:function(){return O(this,void 0,void 0,l.mark(function e(){return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!(N(this,kt,"f").numberId&&N(this,kt,"f").callId&&N(this,kt,"f").taskId&&N(this,Rt,"f"))){e.next=1;break}return e.next=1,this.getCallInfo();case 1:case"end":return e.stop()}},e,this)}))}},{key:"getOpenApi",value:function(){return function(e){if(!e)return!1;var t=/^[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z]{2,}$/;return!!/^(\d{1,3}\.){3}\d{1,3}$/.test(e)||("//"===C(e).call(e,0,2)?t.test(C(e).call(e,2,e.length)):"http://"===C(e).call(e,0,7)?t.test(C(e).call(e,7,e.length)):"https://"===C(e).call(e,0,8)?t.test(C(e).call(e,8,e.length)):t.test(e))}(N(this,ut,"f"))?N(this,ut,"f"):"1"===N(this,dt,"f")?"1"===N(this,ht,"f")?"https://seat.teleai.com/teleaiopenapi":"https://seat.teleai.com/openapi":"1"===N(this,ht,"f")?"https://seat.94ai.com/teleaiopenapi":"https://seat.94ai.com/openapi"}},{key:"getAgentInfo",value:function(){return this.requestOpenApi({url:"/v1/agent/getAgent",data:{agentTag:N(this,ct,"f"),agentId:N(this,lt,"f")}})}},{key:"updateOpenApiAgentStatus",value:function(e){return this.requestOpenApi({url:"/v1/agent/updateAgentStatus",data:{agentTag:N(this,ct,"f"),agentId:N(this,lt,"f"),agentStatus:e}})}},{key:"importOpenApiAgentCustomer",value:function(e){return this.requestOpenApi({url:"/v1/task/importAgentCustomer",data:{agentTag:N(this,ct,"f"),agentId:N(this,lt,"f"),callType:1001,customers:[{number:e}]}})}},{key:"callNumber",value:function(e){return this.importOpenApiAgentCustomer(e)}},{key:"toggleNap",value:function(e){return e?this.updateOpenApiAgentStatus(3):this.updateOpenApiAgentStatus(1)}},{key:"refreshSign",value:function(e){F(this,we,e,"f")}},{key:"refreshTimestamp",value:function(e){F(this,ke,e,"f")}},{key:"prepareUserAgent",value:function(e,t){var i;return O(this,void 0,void 0,l.mark(function n(){var r,s,a,o,c,u,h,d,f,v,p,g;return l.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return s=(r=e||{}).refresh,a=r.registererOptions,o=r.registererRegisterOptions,c=r.extraHeaders,u=r.authorizationUsername,h=r.authorizationPassword,d=r.uri,f=r.contactName,v=r.transportOptions,n.next=1,this.dispose();case 1:return N(this,ve,"f").uri=null!=d?d:N(this,ve,"f").uri,N(this,ve,"f").authorizationUsername=null!=u?u:N(this,ve,"f").authorizationUsername,N(this,ve,"f").authorizationPassword=null!=h?h:N(this,ve,"f").authorizationPassword,N(this,ve,"f").contactName=null!==(i=null!=f?f:u)&&void 0!==i?i:N(this,ve,"f").contactName,v&&(N(this,ve,"f").transportOptions=m(m({},N(this,ve,"f").transportOptions),v)),n.prev=2,N(this,se,"m",Bt).call(this,e),n.next=3,N(this,Wt,"f").call(this);case 3:return n.next=4,N(this,Lt,"f").call(this);case 4:return N(this,se,"m",Ut).call(this,{refresh:s}),n.next=5,N(this,se,"m",yi).call(this);case 5:return t&&N(this,se,"m",bi).call(this,t),n.next=6,N(this,se,"m",wi).call(this,{registererOptions:a,registererRegisterOptions:o,extraHeaders:c},N(this,bt,"f"));case 6:return p=n.sent,n.abrupt("return",p);case 7:return n.prev=7,g=n.catch(2),n.next=8,this.dispose();case 8:throw g;case 9:case"end":return n.stop()}},n,this,[[2,7]])}))}},{key:"dispose",value:function(){return O(this,void 0,void 0,l.mark(function e(){var t;return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,N(this,se,"m",zt).call(this),e.next=1,N(this,se,"m",Jt).call(this);case 1:e.next=3;break;case 2:e.prev=2,t=e.catch(0),N(this,se,"m",Zt).call(this),console.log("sip dispose with error",t);case 3:case"end":return e.stop()}},e,this,[[0,2]])}))}},{key:"ignoreInvite",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return O(this,void 0,void 0,l.mark(function t(){return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return N(this,be,"f").incomingStatus=!1,t.next=1,this.getCurrentInvitation().reject(e);case 1:case"end":return t.stop()}},t,this)}))}},{key:"acceptInvite",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return O(this,void 0,void 0,l.mark(function t(){var i,n=this;return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=1,new g(function(t,i){O(n,void 0,void 0,l.mark(function n(){var r,s,a;return l.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,r=null==e?void 0:e.onAck,s=null==e?void 0:e.onAckTimeout,null==e||delete e.onAck,null==e||delete e.onAckTimeout,n.next=1,this.getCurrentInvitation().accept(m({sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}},onAck:function(e){t(e),null==r||r()},onAckTimeout:function(){null==s||s(),i("接听响应超时")}},e||{}));case 1:n.next=3;break;case 2:n.prev=2,a=n.catch(0),i(a);case 3:case"end":return n.stop()}},n,this,[[0,2]])}))});case 1:N(this,be,"f").incomingStatus&&(N(this,be,"f").incomingStatus=!1,N(this,be,"f").answerStatus=!0),t.next=3;break;case 2:throw t.prev=2,i=t.catch(0),N(this,be,"f").incomingStatus=!1,i;case 3:case"end":return t.stop()}},t,this,[[0,2]])}))}},{key:"hangUpInvite",value:function(e){return O(this,void 0,void 0,l.mark(function t(){var i,r,s,a,o,c=this;return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=(i=e||{}).rejectOptions,s=i.byeOptions,a=i.extraHeaders,o=i.scoutResponse,t.abrupt("return",new g(function(e,t){return O(c,void 0,void 0,l.mark(function i(){var c,u,h,d,f,v,p,g,b,y,w;return l.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:i.prev=0,p=null===(c=(v=s||{}).requestDelegate)||void 0===c?void 0:c.onAccept,g=null===(u=v.requestDelegate)||void 0===u?void 0:u.onReject,null===(h=v.requestDelegate)||void 0===h||delete h.onAccept,null===(d=v.requestDelegate)||void 0===d||delete d.onReject,b=N(this,se,"m",Vt).call(this,{onAccept:function(t){console.log("sip bye success"),e(t),null==p||p(t)},onReject:function(e){null==g||g(e),t("sip bye fail with code "+e.message.statusCode)}},v.requestDelegate),delete v.requestDelegate,y=null===(f=N(this,pe,"f"))||void 0===f?void 0:f.state,i.next=y===n.Initial||y===n.Establishing?1:y===n.Established?3:y===n.Terminating||y===n.Terminated?5:6;break;case 1:return i.next=2,N(this,pe,"f").reject(m({extraHeaders:a},r||{}));case 2:return e(!0),i.abrupt("continue",6);case 3:return i.next=4,N(this,pe,"f").bye(m({requestDelegate:b,requestOptions:{extraHeaders:a}},v));case 4:return o||e(!0),i.abrupt("continue",6);case 5:return e(!0),i.abrupt("continue",6);case 6:i.next=8;break;case 7:i.prev=7,w=i.catch(0),t(w);case 8:return i.prev=8,N(this,be,"f").incomingStatus=!1,N(this,be,"f").answerStatus=!1,i.finish(8);case 9:case"end":return i.stop()}},i,this,[[0,7,8,9]])}))}));case 1:case"end":return t.stop()}},t)}))}},{key:"sendStarDtmf",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return O(this,void 0,void 0,l.mark(function t(){var i=this;return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new g(function(t,n){return O(i,void 0,void 0,l.mark(function i(){var r,s,a,o,c;return l.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return i.prev=0,s=(r=e||{}).extraHeaders,a=r.requestDelegate,o=N(this,se,"m",Vt).call(this,{onAccept:function(e){console.log("sip send dtmf Signal=* success"),t(e)},onReject:function(e){n("sip send dtmf Signal=* fail with code "+e.message.statusCode)}},a),delete r.requestDelegate,i.next=1,this.getCurrentInvitation().info(m({requestOptions:{body:{contentDisposition:"render",contentType:"application/dtmf-relay",content:"Signal=*\r\nDuration=100"},extraHeaders:s},requestDelegate:o},r));case 1:N(this,xt,"f").call(this),i.next=3;break;case 2:i.prev=2,c=i.catch(0),n(c);case 3:case"end":return i.stop()}},i,this,[[0,2]])}))}));case 1:case"end":return t.stop()}},t)}))}},{key:"muteRemoteAudio",value:function(){var e;f(e=N(this,he,"f").getReceivers()).call(e,function(e){e.track.enabled=!1})}},{key:"unMuteRemoteAudio",value:function(){var e;f(e=N(this,he,"f").getReceivers()).call(e,function(e){e.track.enabled=!0})}},{key:"muteLocalAudio",value:function(){var e;f(e=N(this,he,"f").getSenders()).call(e,function(e){e.track.enabled=!1})}},{key:"unMuteLocalAudio",value:function(){var e;f(e=N(this,he,"f").getSenders()).call(e,function(e){e.track.enabled=!0})}},{key:"getUserAgentStatue",value:function(){return N(this,be,"f")}},{key:"getUserAgent",value:function(){return N(this,ce,"f")||F(this,ce,new i(N(this,ve,"f")),"f"),N(this,ce,"f")}},{key:"getSessionDescriptionHandler",value:function(){return N(this,ue,"f")}},{key:"getPeerConnection",value:function(){return N(this,he,"f")}},{key:"getSenders",value:function(){return N(this,fe,"f")}},{key:"getReceivers",value:function(){return N(this,de,"f")}},{key:"getStream",value:function(){var e,t=this;return N(this,me,"f")||F(this,me,new MediaStream,"f"),f(e=N(this,de,"f")).call(e,function(e){e.track&&N(t,me,"f").addTrack(e.track)}),N(this,me,"f")}},{key:"getCurrentInviter",value:function(){if(!N(this,ge,"f"))throw new Error("No currentInviter...");return N(this,ge,"f")}},{key:"getCurrentInvitation",value:function(){return N(this,pe,"f")}},{key:"clearIceAutoDetection",value:function(){var e;null===(e=N(this,ae,"f"))||void 0===e||e.destroy(),F(this,ae,void 0,"f")}},{key:"iceAutoDetectRecovery",value:function(e){var t,i=this;null===(t=N(this,ae,"f"))||void 0===t||t.destroy(),F(this,ae,new Si(e,{debugIceCredentials:!0,onRecoveryStart:function(e,t){console.log("开始 ICE 恢复",e,t)},onRecovered:function(){console.log("媒体连接已恢复")},isSignalingAvailable:function(){return N(i,ce,"f").isConnected()},isRegistrationAvailable:function(){return N(i,le,"f").state===r.Registered},onRecoveryFailed:function(e,t){console.error("ICE 恢复失败",e,t)}}),"f"),N(this,ae,"f").start()}},{key:"invite",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return O(this,void 0,void 0,l.mark(function n(){var r,a,o;return l.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(a=i.makeURI(e.uri?e.uri:b(r="sip:".concat(e.extension,"@")).call(r,N(this,ve,"f").transportOptions.server.split("://")[1]))){n.next=1;break}throw new Error("Failed to create target URI.");case 1:return F(this,ge,new s(this.getUserAgent(),a,{sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}}}),"f"),o=(t||{}).extraHeaders,n.next=2,this.getCurrentInviter().invite(m({requestOptions:{extraHeaders:o}},t));case 2:return n.abrupt("return",N(this,ge,"f"));case 3:case"end":return n.stop()}},n,this)}))}}])}();ae=new R,oe=new R,ce=new R,le=new R,ue=new R,he=new R,de=new R,fe=new R,ve=new R,pe=new R,ge=new R,me=new R,be=new R,ye=new R,we=new R,ke=new R,Re=new R,Se=new R,xe=new R,Te=new R,Ce=new R,Ie=new R,Ae=new R,De=new R,Ee=new R,Me=new R,Pe=new R,je=new R,Oe=new R,Ne=new R,Fe=new R,Be=new R,qe=new R,He=new R,We=new R,Le=new R,ze=new R,Ge=new R,Ue=new R,Xe=new R,Ve=new R,_e=new R,Ye=new R,Je=new R,Ke=new R,Ze=new R,$e=new R,Qe=new R,et=new R,tt=new R,it=new R,nt=new R,rt=new R,st=new R,at=new R,ot=new R,ct=new R,lt=new R,ut=new R,ht=new R,dt=new R,ft=new R,vt=new R,pt=new R,gt=new R,mt=new R,bt=new R,yt=new R,wt=new R,kt=new R,Rt=new R,St=new R,xt=new R,Tt=new R,Ct=new R,It=new R,At=new R,Dt=new R,Et=new R,Mt=new R,Pt=new R,Wt=new R,Lt=new R,Gt=new R,ni=new R,si=new R,ai=new R,oi=new R,ci=new R,li=new R,pi=new R,se=new S,jt=function(){var e,t,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};F(this,Pe,null!==(e=i.openXhrIntercept)&&void 0!==e?e:N(this,Pe,"f"),"f"),F(this,je,null!==(t=i.gatewayXhrIntercept)&&void 0!==t?t:N(this,je,"f"),"f")},Ot=function(){var e,t,i,n,r,s,a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};F(this,Rt,null!==(e=a.enableChatInfoPush)&&void 0!==e?e:N(this,Rt,"f"),"f"),F(this,St,null!==(t=a.enableVolumnTrack)&&void 0!==t?t:N(this,St,"f"),"f"),F(this,Ee,null!==(i=a.refreshSpeekVolumn)&&void 0!==i?i:N(this,Ee,"f"),"f"),F(this,He,null!==(n=a.refreshRequirementCheck)&&void 0!==n?n:N(this,He,"f"),"f"),F(this,Me,null!==(r=a.refreshChat)&&void 0!==r?r:N(this,Me,"f"),"f"),F(this,qe,null!==(s=a.refreshChatErrorCallback)&&void 0!==s?s:N(this,qe,"f"),"f")},Nt=function(){var e,t,i,n,r,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};F(this,Re,null!==(e=s.token)&&void 0!==e?e:N(this,Re,"f"),"f"),F(this,Se,null!==(t=s.tokenTimestamp)&&void 0!==t?t:N(this,Se,"f"),"f"),F(this,Te,null!==(i=s.tokenExpirationTime)&&void 0!==i?i:N(this,Te,"f"),"f"),N(this,Re,"f")&&!N(this,Se,"f")&&F(this,Se,d(),"f"),F(this,Ne,null!==(n=s.tokenCheck)&&void 0!==n?n:N(this,Ne,"f"),"f"),F(this,Be,null!==(r=s.tokenOverdued)&&void 0!==r?r:N(this,Be,"f"),"f")},Ft=function(){var e,t,i,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};F(this,bt,null!==(e=n.clusterMode)&&void 0!==e?e:N(this,bt,"f"),"f"),F(this,yt,null!==(t=n.reClusterRegisterTimeout)&&void 0!==t?t:N(this,yt,"f"),"f"),F(this,wt,null!==(i=n.reClusterConnectTimeout)&&void 0!==i?i:N(this,wt,"f"),"f")},Bt=function(){var e,t,i,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=n.agentId,s=n.agentTag,a=n.appKey,o=n.appSecret,c=n.openBaseUrl,l=n.sg,u=n.sgOpen,h=n.sign,d=n.timestamp;F(this,lt,null!=r?r:N(this,lt,"f"),"f"),F(this,ct,null!=s?s:N(this,ct,"f"),"f"),F(this,at,null!=a?a:N(this,at,"f"),"f"),F(this,ot,null!=o?o:N(this,ot,"f"),"f"),F(this,ut,null!=c?c:N(this,ut,"f"),"f"),F(this,dt,null!=l?l:N(this,dt,"f"),"f"),F(this,ht,null!=u?u:N(this,ht,"f"),"f"),F(this,we,null!=h?h:N(this,we,"f"),"f"),F(this,ke,null!=d?d:N(this,ke,"f"),"f"),F(this,xe,null!==(e=n.signExpirationTime)&&void 0!==e?e:N(this,xe,"f"),"f"),F(this,Oe,null!==(t=n.signCheck)&&void 0!==t?t:N(this,Oe,"f"),"f"),F(this,Fe,null!==(i=n.signOverdued)&&void 0!==i?i:N(this,Fe,"f"),"f")},qt=function(e){e.sipHeaders&&(F(this,oe,e.sipHeaders,"f"),delete e.sipHeaders)},Ht=function(){return!(!N(this,lt,"f")&&!N(this,ct,"f")||!(N(this,at,"f")&&N(this,ot,"f")||N(this,we,"f")&&N(this,ke,"f")))},zt=function(){N(this,se,"m",Kt).call(this),N(this,se,"m",ei).call(this),N(this,se,"m",ti).call(this),N(this,se,"m",Qt).call(this),N(this,se,"m",$t).call(this),N(this,se,"m",ui).call(this),N(this,se,"m",hi).call(this),N(this,se,"m",Zt).call(this),N(this,Tt,"f").call(this),this.clearIceAutoDetection(),F(this,kt,{},"f"),F(this,Ce,{},"f")},Ut=function(e){F(this,be,o(JSON.parse(u(V)),"function"==typeof e.refresh?e.refresh:N(this,pt,"f")),"f")},Xt=function(e){var t,i,n,r,s,a,o,c,l,u,h,d,f,v,p;F(this,ze,null!==(n=null!==(t=e.reconnectionAttempts)&&void 0!==t?t:null===(i=null==e?void 0:e.transportOptions)||void 0===i?void 0:i.maxReconnectionAttempts)&&void 0!==n?n:N(this,ze,"f"),"f"),F(this,Ge,null!==(o=null!==(s=null!==(r=e.reconnectionInterval)&&void 0!==r?r:e.reconnectionDelay)&&void 0!==s?s:null===(a=null==e?void 0:e.transportOptions)||void 0===a?void 0:a.reconnectionTimeout)&&void 0!==o?o:N(this,Ge,"f"),"f"),F(this,$e,null!==(l=null===(c=e.transportOptions)||void 0===c?void 0:c.keepAliveInterval)&&void 0!==l?l:N(this,$e,"f"),"f"),F(this,Qe,null!==(h=null===(u=e.transportOptions)||void 0===u?void 0:u.keepAliveDebounce)&&void 0!==h?h:N(this,Qe,"f"),"f"),F(this,Je,null!==(d=e.registerInterval)&&void 0!==d?d:N(this,Je,"f"),"f"),F(this,Ue,null!==(f=e.optionsPingInterval)&&void 0!==f?f:N(this,Ue,"f"),"f"),F(this,Xe,null!==(v=e.optionsPingAttempts)&&void 0!==v?v:N(this,Xe,"f"),"f"),F(this,Ke,null!==(p=e.registerAttempts)&&void 0!==p?p:N(this,Ke,"f"),"f")},Vt=function(e,t){var i,n=this;return t?(f(i=x(t)).call(i,function(i){if(t[i]&&"function"==typeof t[i])if(e[i]){if("function"==typeof e[i]){var r=e[i];e[i]=function(e){return O(n,void 0,void 0,l.mark(function n(){return l.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=1,t[i](e);case 1:return n.next=2,r(e);case 2:case"end":return n.stop()}},n)}))}}}else e[i]=t[i]}),e):e},_t=function(e){var t,i=this,n={delegate:{onConnect:function(){return O(i,void 0,void 0,l.mark(function e(){return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:console.log("sip connected"),N(this,oi,"f").call(this);case 1:case"end":return e.stop()}},e,this)}))},onInvite:function(e){N(i,Gt,"f").call(i,e.incomingInviteRequest.message.headers),i.refreshCallChatInfo(),N(i,se,"m",Yt).call(i),F(i,pe,e,"f"),N(i,be,"f").incomingStatus=!0,i.iceAutoDetectRecovery(e),e.stateChange.addListener(N(i,ni,"f"))},onDisconnect:function(e){return O(i,void 0,void 0,l.mark(function t(){var i;return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return console.log("sip disconnected"),i=!1,N(this,Ue,"f")>0&&(i=N(this,_e,"f"),N(this,li,"f").call(this)),t.prev=1,t.next=2,N(this,se,"m",ri).call(this);case 2:t.next=4;break;case 3:t.prev=3,t.catch(1);case 4:(e||i)&&N(this,se,"m",gi).call(this);case 5:case"end":return t.stop()}},t,this,[[1,3]])}))}}};e.delegate?f(t=x(e.delegate)).call(t,function(t){var r=t;if(e.delegate[r]&&"function"==typeof e.delegate[r]){var s=e.delegate[r];e.delegate[r]=function(e){return O(i,void 0,void 0,l.mark(function t(){var i,a;return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return null===(a=(i=n.delegate)[r])||void 0===a||a.call(i,e),t.next=1,s(e);case 1:case"end":return t.stop()}},t)}))}}}):e.delegate=n.delegate;return e.reconnectionAttempts=0,e.transportOptions=m(m({},e.transportOptions||{}),{keepAliveInterval:N(this,$e,"f"),keepAliveDebounce:N(this,Qe,"f")}),void 0===e.sessionDescriptionHandlerFactoryOptions&&(e.sessionDescriptionHandlerFactoryOptions={iceGatheringTimeout:2e3,peerConnectionConfiguration:{iceServers:[]}}),m(m({},X),e)},Yt=function(){N(this,pe,"f")&&(N(this,pe,"f").dispose(),F(this,pe,void 0,"f"))},Jt=function(){return O(this,void 0,void 0,l.mark(function e(){return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!N(this,ce,"f")){e.next=2;break}return e.next=1,N(this,ce,"f").stop();case 1:F(this,ce,void 0,"f");case 2:case"end":return e.stop()}},e,this)}))},Kt=function(){var e;N(this,me,"f")&&(f(e=N(this,me,"f").getTracks()).call(e,function(e){e.stop()}),F(this,me,void 0,"f"))},Zt=function(){var e,t=this;f(e=x(V)).call(e,function(e){var i=e;N(t,be,"f")[i]=V[i]})},$t=function(){N(this,ue,"f")&&(N(this,ue,"f").close(),F(this,ue,void 0,"f"))},Qt=function(){N(this,he,"f")&&(N(this,he,"f").close(),F(this,he,void 0,"f"))},ei=function(){F(this,fe,[],"f")},ti=function(){F(this,de,[],"f")},ii=function(){var e=this.getCurrentInvitation().sessionDescriptionHandler;N(this,se,"m",Qt).call(this),N(this,se,"m",$t).call(this),N(this,se,"m",ei).call(this),N(this,se,"m",ti).call(this),F(this,ue,e,"f"),F(this,he,e.peerConnection,"f"),F(this,fe,N(this,he,"f").getSenders(),"f"),F(this,de,N(this,he,"f").getReceivers(),"f"),(this.getFastOutboundCall()||!this.getSitOutboundCall()&&this.notNeedSendStarDtmf())&&N(this,xt,"f").call(this)},ri=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return O(this,void 0,void 0,l.mark(function t(){var i=this;return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!N(this,le,"f")){t.next=1;break}return console.log("sip due to disconnection, unregistered"),t.abrupt("return",new g(function(t,n){return O(i,void 0,void 0,l.mark(function i(){var r,s,a;return l.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return i.prev=0,r=e||{},s=N(this,se,"m",Vt).call(this,{onAccept:function(e){console.log("sip unregister successed"),t(e)},onReject:function(e){n("sip unregister fail with code "+e.message.statusCode)}},r.requestDelegate),delete e.requestDelegate,i.next=1,N(this,le,"f").unregister(m({requestDelegate:s},e));case 1:i.next=3;break;case 2:i.prev=2,a=i.catch(0),n(a);case 3:case"end":return i.stop()}},i,this,[[0,2]])}))}));case 1:case"end":return t.stop()}},t,this)}))},ui=function(){N(this,se,"m",di).call(this),N(this,se,"m",fi).call(this),N(this,se,"m",vi).call(this),F(this,it,!1,"f"),F(this,et,!1,"f"),F(this,tt,!1,"f")},hi=function(){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])&&(clearTimeout(N(this,gt,"f")),F(this,gt,void 0,"f")),e&&(clearTimeout(N(this,mt,"f")),F(this,mt,void 0,"f"))},di=function(){clearTimeout(N(this,st,"f")),F(this,st,void 0,"f")},fi=function(){clearTimeout(N(this,nt,"f")),F(this,nt,void 0,"f")},vi=function(){clearTimeout(N(this,rt,"f")),F(this,rt,void 0,"f")},gi=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return O(this,void 0,void 0,l.mark(function i(){var n=this;return l.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(!N(this,Ge,"f")){i.next=4;break}if(N(this,be,"f").reconnectStatus=!0,!N(this,et,"f")){i.next=1;break}return i.abrupt("return");case 1:if(!(t>N(this,ze,"f"))){i.next=3;break}return console.log("sip maximum reconnection attempts reached"),i.next=2,this.dispose();case 2:return i.abrupt("return");case 3:console.log("sip reconnection attempt..."),F(this,et,!0,"f"),F(this,nt,v(function(){N(n,se,"m",fi).call(n),n.getUserAgent().reconnect().then(function(){return O(n,void 0,void 0,l.mark(function e(){var i;return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:console.log(b(i="sip reconnection attempt ".concat(t," of ")).call(i,N(this,ze,"f")," - succeeded")),F(this,et,!1,"f"),N(this,pi,"f").call(this);case 1:case"end":return e.stop()}},e,this)}))}).catch(function(i){var r;console.error(i),console.log(b(r="sip reconnection attempt ".concat(t," of ")).call(r,N(n,ze,"f")," - failed")),F(n,et,!1,"f"),N(n,se,"m",e).call(n,++t)})},1===t?0:1e3*N(this,Ge,"f")),"f");case 4:case"end":return i.stop()}},i,this)}))},mi=function(e){var t,i=this;return f(t=x(e)).call(t,function(t){var n=t;if("function"==typeof(null==e?void 0:e[n])){var r=e[n];e[n]=function(e){return O(i,void 0,void 0,l.mark(function t(){var i,s;return l.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return null===(s=(i=N(this,ve,"f").delegate)[n])||void 0===s||s.call(i,e),t.next=1,r(e);case 1:case"end":return t.stop()}},t,this)}))}}}),e},bi=function(e){var t=this.getUserAgent();return t.delegate=N(this,se,"m",mi).call(this,e),t},yi=function(){return O(this,void 0,void 0,l.mark(function e(){var t;return l.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=this.getUserAgent(),e.next=1,t.start();case 1:if(t.isConnected()){e.next=2;break}return e.next=2,t.reconnect();case 2:if(t.isConnected()){e.next=3;break}throw new Error("链接失败,请稍后再试");case 3:return N(this,be,"f").connectStatus=!0,e.abrupt("return",t);case 4:case"end":return e.stop()}},e,this)}))},wi=function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=t||{},o=s.registererOptions,c=s.registererRegisterOptions,u=s.extraHeaders;return new g(function(t,s){return O(n,void 0,void 0,l.mark(function n(){var h,d,f,p,g,b=this;return l.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return h=this.getUserAgent(),F(this,le,new a(h,m({extraHeaders:u||N(this,oe,"f")},o||{})),"f"),f=c||{},p=N(this,se,"m",Vt).call(this,{onAccept:function(e){d=e,N(b,se,"m",hi).call(b),N(b,be,"f").registerStatus=!0,t(h)},onReject:function(e){N(b,se,"m",hi).call(b),s("sip register fail with code "+e.message.statusCode)}},f.requestDelegate),delete f.requestDelegate,r&&F(this,gt,v(function(){return O(b,void 0,void 0,l.mark(function n(){var r,g=this;return l.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(d){n.next=4;break}F(this,mt,v(function(){return O(g,void 0,void 0,l.mark(function n(){var r,a;return l.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(N(this,se,"m",hi).call(this,!1,!0),d){n.next=6;break}n.prev=1;try{N(this,le,"f").dispose()}catch(e){}return N(this,se,"m",zt).call(this),N(this,li,"f").call(this),F(this,Ve,0,"f"),F(this,Ze,0,"f"),n.next=2,N(this,ce,"f").transport.dispose();case 2:return F(this,ce,new i(N(this,ve,"f")),"f"),n.next=3,N(this,se,"m",yi).call(this);case 3:return n.next=4,N(this,se,"m",e).call(this,{registererOptions:o,registererRegisterOptions:c,extraHeaders:u});case 4:r=n.sent,t(r),n.next=6;break;case 5:n.prev=5,a=n.catch(1),s(a);case 6:case"end":return n.stop()}},n,this,[[1,5]])}))},N(this,wt,"f")),"f");try{N(this,le,"f").dispose()}catch(e){}return F(this,le,new a(h,m({extraHeaders:u||N(this,oe,"f")},o||{})),"f"),N(this,se,"m",hi).call(this,!0,!1),n.prev=1,n.next=2,N(this,le,"f").register(m({requestDelegate:p,requestOptions:{extraHeaders:u||N(this,oe,"f")}},f));case 2:n.next=4;break;case 3:n.prev=3,r=n.catch(1),N(this,se,"m",hi).call(this),s(r);case 4:case"end":return n.stop()}},n,this,[[1,3]])}))},N(this,yt,"f")),"f"),n.prev=1,n.next=2,N(this,le,"f").register(m({requestDelegate:p,requestOptions:{extraHeaders:u||N(this,oe,"f")}},f));case 2:n.next=4;break;case 3:n.prev=3,g=n.catch(1),N(this,se,"m",hi).call(this),s(g);case 4:case"end":return n.stop()}},n,this,[[1,3]])}))})};var Ti=function(){return t(function t(){e(this,t)},null,[{key:"getUserAgentManager",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return N(this,ki,"f",Ri)||F(this,ki,new xi(e),"f",Ri),N(this,ki,"f",Ri)}},{key:"hasUserAgentManager",value:function(){return!!N(this,ki,"f",Ri)}},{key:"newUserAgentManager",value:function(){return new xi(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})}},{key:"dispose",value:function(){if(N(this,ki,"f",Ri))try{N(this,ki,"f",Ri).dispose()}catch(e){}finally{F(this,ki,void 0,"f",Ri)}}}])}();ki=Ti,Ri={value:void 0};export{Ti as UserAgentFactory,xi as UserAgentManager,ie as accumulateSec,ne as accumulationTimer,Q as cleanupMedia,J as getDevicePermission,_ as getMedia,ee as getTimes,te as getZeorTime,$ as pauseMedia,Z as playMedia,K as requestMicroPhonePermission,Y as stopStreamTracks,X as userAgentDefault,V as userAgentStatus};