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