@94ai/softphone 6.0.1 → 6.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.yarnrc.yml +19 -19
- package/README.md +941 -941
- package/html-softphone-demo/CryptoJS.js +2 -2
- package/html-softphone-demo/cert.pem +20 -20
- package/html-softphone-demo/gg.xccjh.top.key +27 -27
- package/html-softphone-demo/gg.xccjh.top.pem +61 -61
- package/html-softphone-demo/private.key +27 -27
- package/html-softphone-demo/softphone.umd.min.js +2 -2
- package/lib/softphone.cjs.min.cjs +1 -1
- package/lib/softphone.esm-bundler.min.mjs +1 -1
- package/lib/softphone.umd.min.js +1 -1
- package/package.json +1 -1
|
@@ -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:8e3,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:15e3,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,3),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 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};
|