@94ai/softphone 6.0.4 → 6.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +5098 -27
- package/lib/softphone.cjs.min.cjs +1 -1
- package/lib/softphone.esm-bundler.min.mjs +1 -1
- package/lib/softphone.umd.min.js +2 -1
- package/package.json +5 -5
- package/.yarnrc.yml +0 -19
- package/README.md +0 -941
- package/html-softphone-demo/CryptoJS.js +0 -3
- package/html-softphone-demo/README.md +0 -10
- package/html-softphone-demo/RootCA.pem +0 -20
- package/html-softphone-demo/WebrtcDiver.js +0 -320
- package/html-softphone-demo/antique_phone.mp3 +0 -0
- package/html-softphone-demo/cert.pem +0 -21
- package/html-softphone-demo/embed-ui/index.html +0 -123
- package/html-softphone-demo/embed-ui/softphone.js +0 -533
- package/html-softphone-demo/embed-ui/util.js +0 -123
- package/html-softphone-demo/fp.umd.min.js +0 -9
- package/html-softphone-demo/gg.xccjh.top.key +0 -27
- package/html-softphone-demo/gg.xccjh.top.pem +0 -61
- package/html-softphone-demo/index-channel.html +0 -904
- package/html-softphone-demo/index-local.html +0 -586
- package/html-softphone-demo/index-open.html +0 -617
- package/html-softphone-demo/index-switch-pcm.html +0 -613
- package/html-softphone-demo/index-test.html +0 -593
- package/html-softphone-demo/index-voice.html +0 -720
- package/html-softphone-demo/index.html +0 -1090
- package/html-softphone-demo/localhost.crt +0 -21
- package/html-softphone-demo/localhost.key +0 -28
- package/html-softphone-demo/micro-call-ui/CryptoJS.js +0 -3
- package/html-softphone-demo/micro-call-ui/draggable.html +0 -168
- package/html-softphone-demo/micro-call-ui/draggable.js +0 -1
- package/html-softphone-demo/micro-call-ui/index.html +0 -153
- package/html-softphone-demo/micro-call-ui/microphone.js +0 -824
- package/html-softphone-demo/micro-call-ui/qiankun.js +0 -2
- package/html-softphone-demo/micro-call-ui/util.js +0 -33
- package/html-softphone-demo/micro-call-ui/wujie.js +0 -3
- package/html-softphone-demo/pcm-player.js +0 -131
- package/html-softphone-demo/pcm-server/16bit-44100.pcm +0 -0
- package/html-softphone-demo/pcm-server/index.html +0 -110
- package/html-softphone-demo/pcm-server/server.js +0 -54
- package/html-softphone-demo/private.key +0 -28
- package/html-softphone-demo/softphone.umd.min.js +0 -2
- package/html-softphone-demo/tapd_35238004_base64_1695010473_859.gif +0 -0
- package/html-softphone-demo/test.html +0 -190
- package/html-softphone-demo/vue-esm-ui/common-ui.es.browser.js +0 -56545
- package/html-softphone-demo/vue-esm-ui/vue-esm.html +0 -2043
- package/html-softphone-demo/vue-sfc-ui/CryptoJS.js +0 -3
- package/html-softphone-demo/vue-sfc-ui/vue-sfc.html +0 -1858
- package/html-softphone-demo/vue-umd-ui/common-ui.umd.browser.js +0 -338
- package/html-softphone-demo/vue-umd-ui/vue-umd.html +0 -1978
|
@@ -1 +1 @@
|
|
|
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;
|
|
1
|
+
"use strict";var e=require("@babel/runtime-corejs3/helpers/esm/classCallCheck"),t=require("@babel/runtime-corejs3/helpers/esm/createClass"),n=require("@babel/runtime-corejs3/core-js/reflect/construct"),r=require("@babel/runtime-corejs3/helpers/esm/possibleConstructorReturn"),i=require("@babel/runtime-corejs3/helpers/esm/getPrototypeOf"),s=require("@babel/runtime-corejs3/helpers/esm/inherits"),o=require("@babel/runtime-corejs3/helpers/esm/wrapNativeSuper"),a=require("@babel/runtime-corejs3/core-js/object/set-prototype-of"),c=require("@babel/runtime-corejs3/core-js/object/define-property"),l=require("@babel/runtime-corejs3/core-js/promise"),u=require("@babel/runtime-corejs3/core-js/instance/for-each"),d=require("@babel/runtime-corejs3/core-js/instance/slice"),h=require("@babel/runtime-corejs3/core-js/instance/filter"),g=require("@babel/runtime-corejs3/helpers/esm/get"),f=require("@babel/runtime-corejs3/core-js/instance/includes"),v=require("@babel/runtime-corejs3/core-js/set-timeout"),p=require("@babel/runtime-corejs3/core-js/instance/repeat"),m=require("@babel/runtime-corejs3/core-js/instance/map"),b=require("@babel/runtime-corejs3/core-js/array/is-array"),w=require("@babel/runtime-corejs3/core-js/instance/sort"),y=require("@babel/runtime-corejs3/core-js/parse-int"),S=require("@babel/runtime-corejs3/core-js/instance/trim"),k=require("@babel/runtime-corejs3/core-js/parse-float"),R=require("@babel/runtime-corejs3/core-js/instance/splice"),T=require("@babel/runtime-corejs3/core-js/instance/concat"),I=require("@babel/runtime-corejs3/core-js/json/stringify"),E=require("@babel/runtime-corejs3/core-js/object/keys"),C=require("@babel/runtime-corejs3/core-js/instance/every"),x=require("@babel/runtime-corejs3/core-js/array/from"),A=require("@babel/runtime-corejs3/core-js/symbol"),D=require("@babel/runtime-corejs3/core-js/get-iterator-method"),H=require("@babel/runtime-corejs3/core-js/object/assign"),q=require("@babel/runtime-corejs3/core-js/instance/index-of"),_=require("@babel/runtime-corejs3/core-js/map"),$=require("@babel/runtime-corejs3/core-js/number/parse-int"),M=require("@babel/runtime-corejs3/core-js/instance/reduce"),P=require("@babel/runtime-corejs3/helpers/esm/toConsumableArray"),O=require("@babel/runtime-corejs3/regenerator"),N=require("@babel/runtime-corejs3/core-js/instance/keys"),j=require("@babel/runtime-corejs3/core-js/set"),F=require("@babel/runtime-corejs3/core-js/instance/some"),B=require("@babel/runtime-corejs3/core-js/instance/values"),U=require("@babel/runtime-corejs3/core-js/set-interval"),L=require("@babel/runtime-corejs3/core-js/instance/reverse");require("@babel/runtime-corejs3/helpers/esm/readOnlyError");var G=require("@babel/runtime-corejs3/core-js/date/now"),V=require("@babel/runtime-corejs3/core-js/instance/find");require("@babel/runtime-corejs3/helpers/esm/slicedToArray");var W=require("on-change"),Y=require("@babel/runtime-corejs3/helpers/esm/typeof"),K=require("@babel/runtime-corejs3/core-js/weak-map"),z=require("@babel/runtime-corejs3/core-js/weak-set"),Z=require("@babel/runtime-corejs3/core-js/instance/pad-start"),J=require("crypto-js"),X=require("@fingerprintjs/fingerprintjs"),Q=require("@babel/runtime-corejs3/core-js/instance/starts-with"),ee=require("@babel/runtime-corejs3/core-js/instance/find-index");function te(e,t,n,r){return new(n||(n=Promise))(function(i,s){function o(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,a)}c((r=r.apply(e,t||[])).next())})}function ne(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function re(e,t,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?i.call(e,n):i?i.value=n:t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;function ie(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(ie=function(){return!!e})()}var se=function(o){function c(t){var s,o,l,u;return e(this,c),o=this,u=[t],l=i(l=c),s=r(o,ie()?n(l,u||[],i(o).constructor):l.apply(o,u)),a(s,(this instanceof c?this.constructor:void 0).prototype),s}return s(c,o),t(c)}(o(Error));function oe(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(oe=function(){return!!e})()}var ae=function(){function o(t){return e(this,o),s=this,c=[t||"Unsupported content type."],a=i(a=o),r(s,oe()?n(a,c||[],i(s).constructor):a.apply(s,c));var s,a,c}return s(o,se),t(o)}();function ce(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(ce=function(){return!!e})()}var le=function(){function o(t){return e(this,o),s=this,c=[t||"Request pending."],a=i(a=o),r(s,ce()?n(a,c||[],i(s).constructor):a.apply(s,c));var s,a,c}return s(o,se),t(o)}();function ue(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(ue=function(){return!!e})()}var de=function(){function o(t){return e(this,o),s=this,c=[t||"Unspecified session description handler error."],a=i(a=o),r(s,ue()?n(a,c||[],i(s).constructor):a.apply(s,c));var s,a,c}return s(o,se),t(o)}();function he(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(he=function(){return!!e})()}var ge=function(){function o(){return e(this,o),t=this,a=["The session has terminated."],s=i(s=o),r(t,he()?n(s,a||[],i(t).constructor):s.apply(t,a));var t,s,a}return s(o,se),t(o)}();function fe(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(fe=function(){return!!e})()}var ve=function(){function o(t){return e(this,o),s=this,c=[t||"An error occurred during state transition."],a=i(a=o),r(s,fe()?n(a,c||[],i(s).constructor):a.apply(s,c));var s,a,c}return s(o,se),t(o)}(),pe=function(){return t(function t(n){e(this,t),c(this,"incomingAckRequest",{enumerable:!0,configurable:!0,writable:!0,value:n})},[{key:"request",get:function(){return this.incomingAckRequest.message}}])}(),me=function(){return t(function t(n){e(this,t),c(this,"incomingByeRequest",{enumerable:!0,configurable:!0,writable:!0,value:n})},[{key:"request",get:function(){return this.incomingByeRequest.message}},{key:"accept",value:function(e){return this.incomingByeRequest.accept(e),l.resolve()}},{key:"reject",value:function(e){return this.incomingByeRequest.reject(e),l.resolve()}}])}(),be=function(){return t(function t(n){e(this,t),c(this,"incomingCancelRequest",{enumerable:!0,configurable:!0,writable:!0,value:n})},[{key:"request",get:function(){return this.incomingCancelRequest}}])}(),we=function(){return t(function t(){e(this,t),c(this,"listeners",{enumerable:!0,configurable:!0,writable:!0,value:new Array})},[{key:"addListener",value:function(e,t){var n=this,r=function(t){n.removeListener(r),e(t)};!0===(null==t?void 0:t.once)?this.listeners.push(r):this.listeners.push(e)}},{key:"emit",value:function(e){var t,n;u(t=d(n=this.listeners).call(n)).call(t,function(t){return t(e)})}},{key:"removeAllListeners",value:function(){this.listeners=[]}},{key:"removeListener",value:function(e){var t;this.listeners=h(t=this.listeners).call(t,function(t){return t!==e})}},{key:"on",value:function(e){return this.addListener(e)}},{key:"off",value:function(e){return this.removeListener(e)}},{key:"once",value:function(e){return this.addListener(e,{once:!0})}}])}(),ye=function(){return t(function t(n){e(this,t),c(this,"incomingInfoRequest",{enumerable:!0,configurable:!0,writable:!0,value:n})},[{key:"request",get:function(){return this.incomingInfoRequest.message}},{key:"accept",value:function(e){return this.incomingInfoRequest.accept(e),l.resolve()}},{key:"reject",value:function(e){return this.incomingInfoRequest.reject(e),l.resolve()}}])}(),Se=function(){return t(function t(n){for(var r in e(this,t),c(this,"parameters",{enumerable:!0,configurable:!0,writable:!0,value:{}}),n)n.hasOwnProperty(r)&&this.setParam(r,n[r])},[{key:"setParam",value:function(e,t){e&&(this.parameters[e.toLowerCase()]=null==t?null:t.toString())}},{key:"getParam",value:function(e){if(e)return this.parameters[e.toLowerCase()]}},{key:"hasParam",value:function(e){return!(!e||void 0===this.parameters[e.toLowerCase()])}},{key:"deleteParam",value:function(e){if(e=e.toLowerCase(),this.hasParam(e)){var t=this.parameters[e];return delete this.parameters[e],t}}},{key:"clearParams",value:function(){this.parameters={}}}])}();function ke(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(ke=function(){return!!e})()}var Re=function(){function o(t,s,a){var l,u,d,h;return e(this,o),u=this,h=[a],d=i(d=o),l=r(u,ke()?n(d,h||[],i(u).constructor):d.apply(u,h)),c(l,"uri",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"_displayName",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),l.uri=t,l._displayName=s,l}return s(o,Se),t(o,[{key:"friendlyName",get:function(){return this.displayName||this.uri.aor}},{key:"displayName",get:function(){return this._displayName},set:function(e){this._displayName=e}},{key:"clone",value:function(){return new o(this.uri.clone(),this._displayName,JSON.parse(I(this.parameters)))}},{key:"toString",value:function(){var e=this.displayName||"0"===this.displayName?'"'+this.displayName+'" ':"";for(var t in e+="<"+this.uri.toString()+">",this.parameters)this.parameters.hasOwnProperty(t)&&(e+=";"+t,null!==this.parameters[t]&&(e+="="+this.parameters[t]));return e}}])}();function Te(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Te=function(){return!!e})()}var Ie=function(){function o(){var t,s,a,l,u=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"sip",d=arguments.length>1?arguments[1]:void 0,h=arguments.length>2?arguments[2]:void 0,g=arguments.length>3?arguments[3]:void 0,f=arguments.length>4?arguments[4]:void 0,v=arguments.length>5?arguments[5]:void 0;if(e(this,o),s=this,l=[f||{}],a=i(a=o),t=r(s,Te()?n(a,l||[],i(s).constructor):a.apply(s,l)),c(t,"headers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),c(t,"normal",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(t,"raw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),!h)throw new TypeError('missing or invalid "host" parameter');for(var p in v)v.hasOwnProperty(p)&&t.setHeader(p,v[p]);return t.raw={scheme:u,user:d,host:h,port:g},t.normal={scheme:u.toLowerCase(),user:d,host:h.toLowerCase(),port:g},t}return s(o,Se),t(o,[{key:"scheme",get:function(){return this.normal.scheme},set:function(e){this.raw.scheme=e,this.normal.scheme=e.toLowerCase()}},{key:"user",get:function(){return this.normal.user},set:function(e){this.normal.user=this.raw.user=e}},{key:"host",get:function(){return this.normal.host},set:function(e){this.raw.host=e,this.normal.host=e.toLowerCase()}},{key:"aor",get:function(){return this.normal.user+"@"+this.normal.host}},{key:"port",get:function(){return this.normal.port},set:function(e){this.normal.port=this.raw.port=e}},{key:"setHeader",value:function(e,t){this.headers[this.headerize(e)]=t instanceof Array?t:[t]}},{key:"getHeader",value:function(e){if(e)return this.headers[this.headerize(e)]}},{key:"hasHeader",value:function(e){return!!e&&!!this.headers.hasOwnProperty(this.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=this.headerize(e),this.headers.hasOwnProperty(e)){var t=this.headers[e];return delete this.headers[e],t}}},{key:"clearHeaders",value:function(){this.headers={}}},{key:"clone",value:function(){return new o(this._raw.scheme,this._raw.user||"",this._raw.host,this._raw.port,JSON.parse(I(this.parameters)),JSON.parse(I(this.headers)))}},{key:"toRaw",value:function(){return this._toString(this._raw)}},{key:"toString",value:function(){return this._toString(this._normal)}},{key:"_normal",get:function(){return this.normal}},{key:"_raw",get:function(){return this.raw}},{key:"_toString",value:function(e){var t=e.scheme+":";for(var n in e.scheme.toLowerCase().match("^sips?$")||(t+="//"),e.user&&(t+=this.escapeUser(e.user)+"@"),t+=e.host,(e.port||0===e.port)&&(t+=":"+e.port),this.parameters)this.parameters.hasOwnProperty(n)&&(t+=";"+n,null!==this.parameters[n]&&(t+="="+this.parameters[n]));var r=[];for(var i in this.headers)if(this.headers.hasOwnProperty(i))for(var s in this.headers[i])this.headers[i].hasOwnProperty(s)&&r.push(i+"="+this.headers[i][s]);return r.length>0&&(t+="?"+r.join("&")),t}},{key:"escapeUser",value:function(e){var t;try{t=decodeURIComponent(e)}catch(e){throw e}return encodeURIComponent(t).replace(/%3A/gi,":").replace(/%2B/gi,"+").replace(/%3F/gi,"?").replace(/%2F/gi,"/")}},{key:"headerize",value:function(e){for(var t={"Call-Id":"Call-ID",Cseq:"CSeq","Min-Se":"Min-SE",Rack:"RAck",Rseq:"RSeq","Www-Authenticate":"WWW-Authenticate"},n=e.toLowerCase().replace(/_/g,"-").split("-"),r=n.length,i="",s=0;s<r;s++)0!==s&&(i+="-"),i+=n[s].charAt(0).toUpperCase()+n[s].substring(1);return t[i]&&(i=t[i]),i}}])}();function Ee(e,t){if(e.scheme!==t.scheme)return!1;if(e.user!==t.user||e.host!==t.host||e.port!==t.port)return!1;if(!function(e,t){var n,r,i=E(e.parameters),s=E(t.parameters),o=h(i).call(i,function(e){return f(s).call(s,e)});return!!C(o).call(o,function(n){return e.parameters[n]===t.parameters[n]})&&(!!C(n=["user","ttl","method","transport"]).call(n,function(n){return e.hasParam(n)&&t.hasParam(n)||!e.hasParam(n)&&!t.hasParam(n)})&&!!C(r=["maddr"]).call(r,function(n){return e.hasParam(n)&&t.hasParam(n)||!e.hasParam(n)&&!t.hasParam(n)}))}(e,t))return!1;var n=E(e.headers),r=E(t.headers);if(0!==n.length||0!==r.length){if(n.length!==r.length)return!1;var i=h(n).call(n,function(e){return f(r).call(r,e)});if(i.length!==r.length)return!1;if(!C(i).call(i,function(n){return e.headers[n].length&&t.headers[n].length&&e.headers[n][0]===t.headers[n][0]}))return!1}return!0}function Ce(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Ce=function(){return!!e})()}function xe(e,t,n){return n=n||" ",e.length>t?e:(t-=e.length,n+=p(n).call(n,t),e+d(n).call(n,0,t))}var Ae=function(o){function l(t,s,o,u){var d,h,g,f;return e(this,l),h=this,g=i(g=l),d=r(h,Ce()?n(g,f||[],i(h).constructor):g.apply(h,f)),c(d,"message",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(d,"expected",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(d,"found",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(d,"location",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(d,"name",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d.message=t,d.expected=s,d.found=o,d.location=u,d.name="SyntaxError","function"==typeof a?a(d,l.prototype):d.__proto__=l.prototype,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(d,l),d}return s(l,o),t(l,[{key:"format",value:function(e){var t="Error: "+this.message;if(this.location){var n,r=null;for(n=0;n<e.length;n++)if(e[n].source===this.location.source){r=e[n].text.split(/\r\n|\n|\r/g);break}var i=this.location.start,s=this.location.source+":"+i.line+":"+i.column;if(r){var o=this.location.end,a=xe("",i.line.toString().length," "),c=r[i.line-1],l=i.line===o.line?o.column:c.length+1;t+="\n --\x3e "+s+"\n"+a+" |\n"+i.line+" | "+c+"\n"+a+" | "+xe("",i.column-1," ")+xe("",l-i.column,"^")}else t+="\n at "+s}return t}}],[{key:"buildMessage",value:function(e,t){function n(e){return e.charCodeAt(0).toString(16).toUpperCase()}function r(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+n(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+n(e)})}function i(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+n(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+n(e)})}function s(e){var t;switch(e.type){case"literal":return'"'+r(e.text)+'"';case"class":var n=m(t=e.parts).call(t,function(e){return b(e)?i(e[0])+"-"+i(e[1]):i(e)});return"["+(e.inverted?"^":"")+n+"]";case"any":return"any character";case"end":return"end of input";case"other":return e.description}}return"Expected "+function(e){var t,n,r=m(e).call(e,s);if(w(r).call(r),r.length>0){for(t=1,n=1;t<r.length;t++)r[t-1]!==r[t]&&(r[n]=r[t],n++);r.length=n}switch(r.length){case 1:return r[0];case 2:return r[0]+" or "+r[1];default:return d(r).call(r,0,-1).join(", ")+", or "+r[r.length-1]}}(e)+" but "+(((o=t)?'"'+r(o)+'"':"end of input")+" found.");var o}}])}(o(Error));var De,He=function(e,t){var n,r,i,s,o={},a=(t=void 0!==t?t:{}).grammarSource,c={Contact:119,Name_Addr_Header:156,Record_Route:176,Request_Response:81,SIP_URI:45,Subscription_State:186,Supported:191,Require:182,Via:194,absoluteURI:84,Call_ID:118,Content_Disposition:130,Content_Length:135,Content_Type:136,CSeq:146,displayName:122,Event:149,From:151,host:52,Max_Forwards:154,Min_SE:213,Proxy_Authenticate:157,quoted_string:40,Refer_To:178,Replaces:179,Session_Expires:210,stun_URI:217,To:192,turn_URI:223,uuid:226,WWW_Authenticate:209,challenge:158,sipfrag:230,Referred_By:231},l=119,u=["\r\n",C("\r\n",!1),/^[0-9]/,x([["0","9"]],!1,!1),/^[a-zA-Z]/,x([["a","z"],["A","Z"]],!1,!1),/^[0-9a-fA-F]/,x([["0","9"],["a","f"],["A","F"]],!1,!1),/^[\0-\xFF]/,x([["\0","ÿ"]],!1,!1),/^["]/,x(['"'],!1,!1)," ",C(" ",!1),"\t",C("\t",!1),/^[a-zA-Z0-9]/,x([["a","z"],["A","Z"],["0","9"]],!1,!1),";",C(";",!1),"/",C("/",!1),"?",C("?",!1),":",C(":",!1),"@",C("@",!1),"&",C("&",!1),"=",C("=",!1),"+",C("+",!1),"$",C("$",!1),",",C(",",!1),"-",C("-",!1),"_",C("_",!1),".",C(".",!1),"!",C("!",!1),"~",C("~",!1),"*",C("*",!1),"'",C("'",!1),"(",C("(",!1),")",C(")",!1),"%",C("%",!1),function(){return" "},function(){return":"},/^[!-~]/,x([["!","~"]],!1,!1),/^[\x80-\uFFFF]/,x([["",""]],!1,!1),/^[\x80-\xBF]/,x([["","¿"]],!1,!1),/^[a-f]/,x([["a","f"]],!1,!1),"`",C("`",!1),"<",C("<",!1),">",C(">",!1),"\\",C("\\",!1),"[",C("[",!1),"]",C("]",!1),"{",C("{",!1),"}",C("}",!1),function(){return"*"},function(){return"/"},function(){return"="},function(){return"("},function(){return")"},function(){return">"},function(){return"<"},function(){return","},function(){return";"},function(){return":"},function(){return'"'},/^[!-']/,x([["!","'"]],!1,!1),/^[*-[]/,x([["*","["]],!1,!1),/^[\]-~]/,x([["]","~"]],!1,!1),function(e){return e},/^[#-[]/,x([["#","["]],!1,!1),/^[\0-\t]/,x([["\0","\t"]],!1,!1),/^[\v-\f]/,x([["\v","\f"]],!1,!1),/^[\x0E-\x7F]/,x([["",""]],!1,!1),function(){(t=t||{data:{}}).data.uri=new Ie(t.data.scheme,t.data.user,t.data.host,t.data.port),delete t.data.scheme,delete t.data.user,delete t.data.host,delete t.data.host_type,delete t.data.port},function(){(t=t||{data:{}}).data.uri=new Ie(t.data.scheme,t.data.user,t.data.host,t.data.port,t.data.uri_params,t.data.uri_headers),delete t.data.scheme,delete t.data.user,delete t.data.host,delete t.data.host_type,delete t.data.port,delete t.data.uri_params,"SIP_URI"===t.startRule&&(t.data=t.data.uri)},"sips",C("sips",!0),"sip",C("sip",!0),function(e){(t=t||{data:{}}).data.scheme=e},function(){var e;(t=t||{data:{}}).data.user=decodeURIComponent(d(e=I()).call(e,0,-1))},function(){(t=t||{data:{}}).data.password=I()},function(){return(t=t||{data:{}}).data.host=I(),t.data.host},function(){return(t=t||{data:{}}).data.host_type="domain",I()},/^[a-zA-Z0-9_\-]/,x([["a","z"],["A","Z"],["0","9"],"_","-"],!1,!1),/^[a-zA-Z0-9\-]/,x([["a","z"],["A","Z"],["0","9"],"-"],!1,!1),function(){return(t=t||{data:{}}).data.host_type="IPv6",I()},"::",C("::",!1),function(){return(t=t||{data:{}}).data.host_type="IPv6",I()},function(){return(t=t||{data:{}}).data.host_type="IPv4",I()},"25",C("25",!1),/^[0-5]/,x([["0","5"]],!1,!1),"2",C("2",!1),/^[0-4]/,x([["0","4"]],!1,!1),"1",C("1",!1),/^[1-9]/,x([["1","9"]],!1,!1),function(e){return t=t||{data:{}},e=y(e.join("")),t.data.port=e,e},"transport=",C("transport=",!0),"udp",C("udp",!0),"tcp",C("tcp",!0),"sctp",C("sctp",!0),"tls",C("tls",!0),function(e){(t=t||{data:{}}).data.uri_params||(t.data.uri_params={}),t.data.uri_params.transport=e.toLowerCase()},"user=",C("user=",!0),"phone",C("phone",!0),"ip",C("ip",!0),function(e){(t=t||{data:{}}).data.uri_params||(t.data.uri_params={}),t.data.uri_params.user=e.toLowerCase()},"method=",C("method=",!0),function(e){(t=t||{data:{}}).data.uri_params||(t.data.uri_params={}),t.data.uri_params.method=e},"ttl=",C("ttl=",!0),function(e){(t=t||{data:{}}).data.params||(t.data.params={}),t.data.params.ttl=e},"maddr=",C("maddr=",!0),function(e){(t=t||{data:{}}).data.uri_params||(t.data.uri_params={}),t.data.uri_params.maddr=e},"lr",C("lr",!0),function(){(t=t||{data:{}}).data.uri_params||(t.data.uri_params={}),t.data.uri_params.lr=void 0},function(e,n){(t=t||{data:{}}).data.uri_params||(t.data.uri_params={}),n=null===n?void 0:n[1],t.data.uri_params[e.toLowerCase()]=n},function(e,n){e=e.join("").toLowerCase(),n=n.join(""),(t=t||{data:{}}).data.uri_headers||(t.data.uri_headers={}),t.data.uri_headers[e]?t.data.uri_headers[e].push(n):t.data.uri_headers[e]=[n]},function(){"Refer_To"===(t=t||{data:{}}).startRule&&(t.data.uri=new Ie(t.data.scheme,t.data.user,t.data.host,t.data.port,t.data.uri_params,t.data.uri_headers),delete t.data.scheme,delete t.data.user,delete t.data.host,delete t.data.host_type,delete t.data.port,delete t.data.uri_params)},"//",C("//",!1),function(){(t=t||{data:{}}).data.scheme=I()},C("SIP",!0),function(){(t=t||{data:{}}).data.sip_version=I()},"INVITE",C("INVITE",!1),"ACK",C("ACK",!1),"VXACH",C("VXACH",!1),"OPTIONS",C("OPTIONS",!1),"BYE",C("BYE",!1),"CANCEL",C("CANCEL",!1),"REGISTER",C("REGISTER",!1),"SUBSCRIBE",C("SUBSCRIBE",!1),"NOTIFY",C("NOTIFY",!1),"REFER",C("REFER",!1),"PUBLISH",C("PUBLISH",!1),function(){return(t=t||{data:{}}).data.method=I(),t.data.method},function(e){(t=t||{data:{}}).data.status_code=y(e.join(""))},function(){(t=t||{data:{}}).data.reason_phrase=I()},function(){(t=t||{data:{}}).data=I()},function(){var e,n;for(n=(t=t||{data:{}}).data.multi_header.length,e=0;e<n;e++)if(null===t.data.multi_header[e].parsed){t.data=null;break}null!==t.data?t.data=t.data.multi_header:t.data=-1},function(){var e;(t=t||{data:{}}).data.multi_header||(t.data.multi_header=[]);try{e=new Re(t.data.uri,t.data.displayName,t.data.params),delete t.data.uri,delete t.data.displayName,delete t.data.params}catch(t){e=null}t.data.multi_header.push({position:g,offset:E().start.offset,parsed:e})},function(e){var n;'"'===(e=S(n=I()).call(n))[0]&&(e=e.substring(1,e.length-1)),(t=t||{data:{}}).data.displayName=e},"q",C("q",!0),function(e){(t=t||{data:{}}).data.params||(t.data.params={}),t.data.params.q=e},"expires",C("expires",!0),function(e){(t=t||{data:{}}).data.params||(t.data.params={}),t.data.params.expires=e},function(e){return y(e.join(""))},"0",C("0",!1),function(){return k(I())},function(e,n){(t=t||{data:{}}).data.params||(t.data.params={}),n=null===n?void 0:n[1],t.data.params[e.toLowerCase()]=n},"render",C("render",!0),"session",C("session",!0),"icon",C("icon",!0),"alert",C("alert",!0),function(){"Content_Disposition"===(t=t||{data:{}}).startRule&&(t.data.type=I().toLowerCase())},"handling",C("handling",!0),"optional",C("optional",!0),"required",C("required",!0),function(e){(t=t||{data:{}}).data=y(e.join(""))},function(){(t=t||{data:{}}).data=I()},"text",C("text",!0),"image",C("image",!0),"audio",C("audio",!0),"video",C("video",!0),"application",C("application",!0),"message",C("message",!0),"multipart",C("multipart",!0),"x-",C("x-",!0),function(e){(t=t||{data:{}}).data.value=y(e.join(""))},function(e){(t=t||{data:{}}).data=e},function(e){(t=t||{data:{}}).data.event=e.toLowerCase()},function(){var e=(t=t||{data:{}}).data.tag;t.data=new Re(t.data.uri,t.data.displayName,t.data.params),e&&t.data.setParam("tag",e)},"tag",C("tag",!0),function(e){(t=t||{data:{}}).data.tag=e},function(e){(t=t||{data:{}}).data=y(e.join(""))},function(e){(t=t||{data:{}}).data=e},function(){(t=t||{data:{}}).data=new Re(t.data.uri,t.data.displayName,t.data.params)},"digest",C("Digest",!0),"realm",C("realm",!0),function(e){(t=t||{data:{}}).data.realm=e},"domain",C("domain",!0),"nonce",C("nonce",!0),function(e){(t=t||{data:{}}).data.nonce=e},"opaque",C("opaque",!0),function(e){(t=t||{data:{}}).data.opaque=e},"stale",C("stale",!0),"true",C("true",!0),function(){(t=t||{data:{}}).data.stale=!0},"false",C("false",!0),function(){(t=t||{data:{}}).data.stale=!1},"algorithm",C("algorithm",!0),"md5",C("MD5",!0),"md5-sess",C("MD5-sess",!0),function(e){(t=t||{data:{}}).data.algorithm=e.toUpperCase()},"qop",C("qop",!0),"auth-int",C("auth-int",!0),"auth",C("auth",!0),function(e){(t=t||{data:{}}).data.qop||(t.data.qop=[]),t.data.qop.push(e.toLowerCase())},function(e){(t=t||{data:{}}).data.value=y(e.join(""))},function(){var e,n;for(n=(t=t||{data:{}}).data.multi_header.length,e=0;e<n;e++)if(null===t.data.multi_header[e].parsed){t.data=null;break}null!==t.data?t.data=t.data.multi_header:t.data=-1},function(){var e;(t=t||{data:{}}).data.multi_header||(t.data.multi_header=[]);try{e=new Re(t.data.uri,t.data.displayName,t.data.params),delete t.data.uri,delete t.data.displayName,delete t.data.params}catch(t){e=null}t.data.multi_header.push({position:g,offset:E().start.offset,parsed:e})},function(){(t=t||{data:{}}).data=new Re(t.data.uri,t.data.displayName,t.data.params)},function(){(t=t||{data:{}}).data.replaces_from_tag&&t.data.replaces_to_tag||(t.data=-1)},function(){(t=t||{data:{}}).data={call_id:t.data}},"from-tag",C("from-tag",!0),function(e){(t=t||{data:{}}).data.replaces_from_tag=e},"to-tag",C("to-tag",!0),function(e){(t=t||{data:{}}).data.replaces_to_tag=e},"early-only",C("early-only",!0),function(){(t=t||{data:{}}).data.early_only=!0},function(e,t){return t},function(e,t){return function(e,t){var n;return T(n=[e]).call(n,t)}(e,t)},function(e){"Require"===(t=t||{data:{}}).startRule&&(t.data=e||[])},function(e){(t=t||{data:{}}).data.value=y(e.join(""))},"active",C("active",!0),"pending",C("pending",!0),"terminated",C("terminated",!0),function(){(t=t||{data:{}}).data.state=I()},"reason",C("reason",!0),function(e){t=t||{data:{}},void 0!==e&&(t.data.reason=e)},function(e){t=t||{data:{}},void 0!==e&&(t.data.expires=e)},"retry_after",C("retry_after",!0),function(e){t=t||{data:{}},void 0!==e&&(t.data.retry_after=e)},"deactivated",C("deactivated",!0),"probation",C("probation",!0),"rejected",C("rejected",!0),"timeout",C("timeout",!0),"giveup",C("giveup",!0),"noresource",C("noresource",!0),"invariant",C("invariant",!0),function(e){"Supported"===(t=t||{data:{}}).startRule&&(t.data=e||[])},function(){var e=(t=t||{data:{}}).data.tag;t.data=new Re(t.data.uri,t.data.displayName,t.data.params),e&&t.data.setParam("tag",e)},"ttl",C("ttl",!0),function(e){(t=t||{data:{}}).data.ttl=e},"maddr",C("maddr",!0),function(e){(t=t||{data:{}}).data.maddr=e},"received",C("received",!0),function(e){(t=t||{data:{}}).data.received=e},"branch",C("branch",!0),function(e){(t=t||{data:{}}).data.branch=e},"rport",C("rport",!0),function(e){t=t||{data:{}},void 0!==e&&(t.data.rport=e.join(""))},function(e){(t=t||{data:{}}).data.protocol=e},C("UDP",!0),C("TCP",!0),C("TLS",!0),C("SCTP",!0),function(e){(t=t||{data:{}}).data.transport=e},function(){(t=t||{data:{}}).data.host=I()},function(e){(t=t||{data:{}}).data.port=y(e.join(""))},function(e){return y(e.join(""))},function(e){"Session_Expires"===(t=t||{data:{}}).startRule&&(t.data.deltaSeconds=e)},"refresher",C("refresher",!1),"uas",C("uas",!1),"uac",C("uac",!1),function(e){"Session_Expires"===(t=t||{data:{}}).startRule&&(t.data.refresher=e)},function(e){"Min_SE"===(t=t||{data:{}}).startRule&&(t.data=e)},"stuns",C("stuns",!0),"stun",C("stun",!0),function(e){(t=t||{data:{}}).data.scheme=e},function(e){(t=t||{data:{}}).data.host=e},"?transport=",C("?transport=",!1),"turns",C("turns",!0),"turn",C("turn",!0),function(e){(t=t||{data:{}}).data.transport=e},function(){(t=t||{data:{}}).data=I()},"Referred-By",C("Referred-By",!1),"b",C("b",!1),"cid",C("cid",!1)],h=[q('2 ""6 7!'),q('4"""5!7#'),q('4$""5!7%'),q('4&""5!7\''),q(";'.# &;("),q('4(""5!7)'),q('4*""5!7+'),q('2,""6,7-'),q('2.""6.7/'),q('40""5!71'),q('22""6273. &24""6475.} &26""6677.q &28""6879.e &2:""6:7;.Y &2<""6<7=.M &2>""6>7?.A &2@""6@7A.5 &2B""6B7C.) &2D""6D7E'),q(";).# &;,"),q('2F""6F7G.} &2H""6H7I.q &2J""6J7K.e &2L""6L7M.Y &2N""6N7O.M &2P""6P7Q.A &2R""6R7S.5 &2T""6T7U.) &2V""6V7W'),q('%%2X""6X7Y/5#;#/,$;#/#$+#)(#\'#("\'#&\'#/"!&,)'),q('%%$;$0#*;$&/,#; /#$+")("\'#&\'#." &"/=#$;$/�#*;$&&&#/\'$8":Z" )("\'#&\'#'),q(';.." &"'),q("%$;'.# &;(0)*;'.# &;(&/?#28\"\"6879/0$;//'$8#:[# )(#'#(\"'#&'#"),q('%%$;2/�#*;2&&&#/g#$%$;.0#*;.&/,#;2/#$+")("\'#&\'#0=*%$;.0#*;.&/,#;2/#$+")("\'#&\'#&/#$+")("\'#&\'#/"!&,)'),q('4\\""5!7].# &;3'),q('4^""5!7_'),q('4`""5!7a'),q(';!.) &4b""5!7c'),q('%$;). &2F""6F7G. &2J""6J7K.} &2L""6L7M.q &2X""6X7Y.e &2P""6P7Q.Y &2H""6H7I.M &2@""6@7A.A &2d""6d7e.5 &2R""6R7S.) &2N""6N7O/#0*;). &2F""6F7G. &2J""6J7K.} &2L""6L7M.q &2X""6X7Y.e &2P""6P7Q.Y &2H""6H7I.M &2@""6@7A.A &2d""6d7e.5 &2R""6R7S.) &2N""6N7O&&&#/"!&,)'),q('%$;). &2F""6F7G.} &2L""6L7M.q &2X""6X7Y.e &2P""6P7Q.Y &2H""6H7I.M &2@""6@7A.A &2d""6d7e.5 &2R""6R7S.) &2N""6N7O/#0*;). &2F""6F7G.} &2L""6L7M.q &2X""6X7Y.e &2P""6P7Q.Y &2H""6H7I.M &2@""6@7A.A &2d""6d7e.5 &2R""6R7S.) &2N""6N7O&&&#/"!&,)'),q('2T""6T7U.ã &2V""6V7W.× &2f""6f7g.Ë &2h""6h7i.¿ &2:""6:7;.³ &2D""6D7E.§ &22""6273. &28""6879. &2j""6j7k. &;&.} &24""6475.q &2l""6l7m.e &2n""6n7o.Y &26""6677.M &2>""6>7?.A &2p""6p7q.5 &2r""6r7s.) &;\'.# &;('),q('%$;).ī &2F""6F7G.ğ &2J""6J7K.ē &2L""6L7M.ć &2X""6X7Y.û &2P""6P7Q.ï &2H""6H7I.ã &2@""6@7A.× &2d""6d7e.Ë &2R""6R7S.¿ &2N""6N7O.³ &2T""6T7U.§ &2V""6V7W. &2f""6f7g. &2h""6h7i. &28""6879.w &2j""6j7k.k &;&.e &24""6475.Y &2l""6l7m.M &2n""6n7o.A &26""6677.5 &2p""6p7q.) &2r""6r7s/Ĵ#0ı*;).ī &2F""6F7G.ğ &2J""6J7K.ē &2L""6L7M.ć &2X""6X7Y.û &2P""6P7Q.ï &2H""6H7I.ã &2@""6@7A.× &2d""6d7e.Ë &2R""6R7S.¿ &2N""6N7O.³ &2T""6T7U.§ &2V""6V7W. &2f""6f7g. &2h""6h7i. &28""6879.w &2j""6j7k.k &;&.e &24""6475.Y &2l""6l7m.M &2n""6n7o.A &26""6677.5 &2p""6p7q.) &2r""6r7s&&&#/"!&,)'),q("%;//?#2P\"\"6P7Q/0$;//'$8#:t# )(#'#(\"'#&'#"),q("%;//?#24\"\"6475/0$;//'$8#:u# )(#'#(\"'#&'#"),q("%;//?#2>\"\"6>7?/0$;//'$8#:v# )(#'#(\"'#&'#"),q("%;//?#2T\"\"6T7U/0$;//'$8#:w# )(#'#(\"'#&'#"),q("%;//?#2V\"\"6V7W/0$;//'$8#:x# )(#'#(\"'#&'#"),q('%2h""6h7i/0#;//\'$8":y" )("\'#&\'#'),q('%;//6#2f""6f7g/\'$8":z" )("\'#&\'#'),q("%;//?#2D\"\"6D7E/0$;//'$8#:{# )(#'#(\"'#&'#"),q("%;//?#22\"\"6273/0$;//'$8#:|# )(#'#(\"'#&'#"),q("%;//?#28\"\"6879/0$;//'$8#:}# )(#'#(\"'#&'#"),q("%;//0#;&/'$8\":~\" )(\"'#&'#"),q("%;&/0#;//'$8\":~\" )(\"'#&'#"),q("%;=/T#$;G.) &;K.# &;F0/*;G.) &;K.# &;F&/,$;>/#$+#)(#'#(\"'#&'#"),q('4""5!7.A &4""5!7.5 &4""5!7.) &;3.# &;.'),q("%%;//Q#;&/H$$;J.# &;K0)*;J.# &;K&/,$;&/#$+$)($'#(#'#(\"'#&'#/\"!&,)"),q("%;//]#;&/T$%$;J.# &;K0)*;J.# &;K&/\"!&,)/1$;&/($8$:
$!!)($'#(#'#(\"'#&'#"),q(';..G &2L""6L7M.; &4""5!7./ &4""5!7.# &;3'),q('%2j""6j7k/J#4""5!7.5 &4""5!7.) &4""5!7/#$+")("\'#&\'#'),q("%;N/M#28\"\"6879/>$;O.\" &\"/0$;S/'$8$:$ )($'#(#'#(\"'#&'#"),q("%;N/d#28\"\"6879/U$;O.\" &\"/G$;S/>$;_/5$;l.\" &\"/'$8&:& )(&'#(%'#($'#(#'#(\"'#&'#"),q('%3""5$7.) &3""5#7/\' 8!:!! )'),q('%;P/]#%28""6879/,#;R/#$+")("\'#&\'#." &"/6$2:""6:7;/\'$8#:# )(#\'#("\'#&\'#'),q("$;+.) &;-.# &;Q/2#0/*;+.) &;-.# &;Q&&&#"),q('2<""6<7=.q &2>""6>7?.e &2@""6@7A.Y &2B""6B7C.M &2D""6D7E.A &22""6273.5 &26""6677.) &24""6475'),q('%$;+._ &;-.Y &2<""6<7=.M &2>""6>7?.A &2@""6@7A.5 &2B""6B7C.) &2D""6D7E0e*;+._ &;-.Y &2<""6<7=.M &2>""6>7?.A &2@""6@7A.5 &2B""6B7C.) &2D""6D7E&/& 8!:! )'),q('%;T/J#%28""6879/,#;^/#$+")("\'#&\'#." &"/#$+")("\'#&\'#'),q("%;U.) &;\\.# &;X/& 8!:! )"),q('%$%;V/2#2J""6J7K/#$+")("\'#&\'#0<*%;V/2#2J""6J7K/#$+")("\'#&\'#&/D#;W/;$2J""6J7K." &"/\'$8#:# )(#\'#("\'#&\'#'),q('$4""5!7/,#0)*4""5!7&&&#'),q('%4$""5!7%/?#$4""5!70)*4""5!7&/#$+")("\'#&\'#'),q('%2l""6l7m/?#;Y/6$2n""6n7o/\'$8#:# )(#\'#("\'#&\'#'),q('%%;Z/³#28""6879/¤$;Z/$28""6879/$;Z/$28""6879/t$;Z/k$28""6879/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+-)(-\'#(,\'#(+\'#(*\'#()\'#((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.ސ &%2""67/¤#;Z/$28""6879/$;Z/$28""6879/t$;Z/k$28""6879/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+,)(,\'#(+\'#(*\'#()\'#((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.۹ &%2""67/#;Z/$28""6879/t$;Z/k$28""6879/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+*)(*\'#()\'#((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.ٺ &%2""67/t#;Z/k$28""6879/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+()((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.ؓ &%2""67/\\#;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+&)(&\'#(%\'#($\'#(#\'#("\'#&\'#.ׄ &%2""67/D#;Z/;$28""6879/,$;[/#$+$)($\'#(#\'#("\'#&\'#.֍ &%2""67/,#;[/#$+")("\'#&\'#.ծ &%2""67/,#;Z/#$+")("\'#&\'#.Տ &%;Z/#2""67/$;Z/$28""6879/t$;Z/k$28""6879/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$++)(+\'#(*\'#()\'#((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.Ӈ &%;Z/ª#%28""6879/,#;Z/#$+")("\'#&\'#." &"/$2""67/t$;Z/k$28""6879/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+*)(*\'#()\'#((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.а &%;Z/¹#%28""6879/,#;Z/#$+")("\'#&\'#." &"/$%28""6879/,#;Z/#$+")("\'#&\'#." &"/k$2""67/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+))()\'#((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.Ί &%;Z/È#%28""6879/,#;Z/#$+")("\'#&\'#." &"/¡$%28""6879/,#;Z/#$+")("\'#&\'#." &"/z$%28""6879/,#;Z/#$+")("\'#&\'#." &"/S$2""67/D$;Z/;$28""6879/,$;[/#$+()((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.˕ &%;Z/×#%28""6879/,#;Z/#$+")("\'#&\'#." &"/°$%28""6879/,#;Z/#$+")("\'#&\'#." &"/$%28""6879/,#;Z/#$+")("\'#&\'#." &"/b$%28""6879/,#;Z/#$+")("\'#&\'#." &"/;$2""67/,$;[/#$+\')(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.ȑ &%;Z/þ#%28""6879/,#;Z/#$+")("\'#&\'#." &"/×$%28""6879/,#;Z/#$+")("\'#&\'#." &"/°$%28""6879/,#;Z/#$+")("\'#&\'#." &"/$%28""6879/,#;Z/#$+")("\'#&\'#." &"/b$%28""6879/,#;Z/#$+")("\'#&\'#." &"/;$2""67/,$;Z/#$+()((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.Ħ &%;Z/Ĝ#%28""6879/,#;Z/#$+")("\'#&\'#." &"/õ$%28""6879/,#;Z/#$+")("\'#&\'#." &"/Î$%28""6879/,#;Z/#$+")("\'#&\'#." &"/§$%28""6879/,#;Z/#$+")("\'#&\'#." &"/$%28""6879/,#;Z/#$+")("\'#&\'#." &"/Y$%28""6879/,#;Z/#$+")("\'#&\'#." &"/2$2""67/#$+()((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#/& 8!: ! )'),q('%;#/M#;#." &"/?$;#." &"/1$;#." &"/#$+$)($\'#(#\'#("\'#&\'#'),q("%;Z/;#28\"\"6879/,$;Z/#$+#)(#'#(\"'#&'#.# &;\\"),q("%;]/o#2J\"\"6J7K/`$;]/W$2J\"\"6J7K/H$;]/?$2J\"\"6J7K/0$;]/'$8':¡' )(''#(&'#(%'#($'#(#'#(\"'#&'#"),q('%2¢""6¢7£/2#4¤""5!7¥/#$+")("\'#&\'#. &%2¦""6¦7§/;#4¨""5!7©/,$;!/#$+#)(#\'#("\'#&\'#.j &%2ª""6ª7«/5#;!/,$;!/#$+#)(#\'#("\'#&\'#.B &%4¬""5!7/,#;!/#$+")("\'#&\'#.# &;!'),q('%%;!." &"/[#;!." &"/M$;!." &"/?$;!." &"/1$;!." &"/#$+%)(%\'#($\'#(#\'#("\'#&\'#/\' 8!:®!! )'),q('$%22""6273/,#;`/#$+")("\'#&\'#0<*%22""6273/,#;`/#$+")("\'#&\'#&'),q(";a.A &;b.; &;c.5 &;d./ &;e.) &;f.# &;g"),q('%3¯""5*7°/a#3±""5#7².G &3³""5#7´.; &3µ""5$7¶./ &3·""5#7¸.# &;6/($8":¹"! )("\'#&\'#'),q('%3º""5%7»/I#3¼""5%7½./ &3¾""5"7¿.# &;6/($8":À"! )("\'#&\'#'),q('%3Á""5\'7Â/1#;/($8":Ã"! )("\'#&\'#'),q('%3Ä""5$7Å/1#;ð/($8":Æ"! )("\'#&\'#'),q('%3Ç""5&7È/1#;T/($8":É"! )("\'#&\'#'),q('%3Ê""5"7Ë/N#%2>""6>7?/,#;6/#$+")("\'#&\'#." &"/\'$8":Ì" )("\'#&\'#'),q('%;h/P#%2>""6>7?/,#;i/#$+")("\'#&\'#." &"/)$8":Í""! )("\'#&\'#'),q('%$;j/�#*;j&&&#/"!&,)'),q('%$;j/�#*;j&&&#/"!&,)'),q(";k.) &;+.# &;-"),q('2l""6l7m.e &2n""6n7o.Y &24""6475.M &28""6879.A &2<""6<7=.5 &2@""6@7A.) &2B""6B7C'),q('%26""6677/n#;m/e$$%2<""6<7=/,#;m/#$+")("\'#&\'#0<*%2<""6<7=/,#;m/#$+")("\'#&\'#&/#$+#)(#\'#("\'#&\'#'),q('%;n/A#2>""6>7?/2$;o/)$8#:Î#"" )(#\'#("\'#&\'#'),q("$;p.) &;+.# &;-/2#0/*;p.) &;+.# &;-&&&#"),q("$;p.) &;+.# &;-0/*;p.) &;+.# &;-&"),q('2l""6l7m.e &2n""6n7o.Y &24""6475.M &26""6677.A &28""6879.5 &2@""6@7A.) &2B""6B7C'),q(";.# &;r"),q("%;/G#;'/>$;s/5$;'/,$;/#$+%)(%'#($'#(#'#(\"'#&'#"),q(";M.# &;t"),q("%;/E#28\"\"6879/6$;u.# &;x/'$8#:Ï# )(#'#(\"'#&'#"),q('%;v.# &;w/J#%26""6677/,#;/#$+")("\'#&\'#." &"/#$+")("\'#&\'#'),q('%2Ð""6Ð7Ñ/:#;/1$;w." &"/#$+#)(#\'#("\'#&\'#'),q('%24""6475/,#;{/#$+")("\'#&\'#'),q("%;z/3#$;y0#*;y&/#$+\")(\"'#&'#"),q(";*.) &;+.# &;-"),q(';+. &;-. &22""6273.} &26""6677.q &28""6879.e &2:""6:7;.Y &2<""6<7=.M &2>""6>7?.A &2@""6@7A.5 &2B""6B7C.) &2D""6D7E'),q('%;|/e#$%24""6475/,#;|/#$+")("\'#&\'#0<*%24""6475/,#;|/#$+")("\'#&\'#&/#$+")("\'#&\'#'),q('%$;~0#*;~&/e#$%22""6273/,#;}/#$+")("\'#&\'#0<*%22""6273/,#;}/#$+")("\'#&\'#&/#$+")("\'#&\'#'),q("$;~0#*;~&"),q(';+.w &;-.q &28""6879.e &2:""6:7;.Y &2<""6<7=.M &2>""6>7?.A &2@""6@7A.5 &2B""6B7C.) &2D""6D7E'),q('%%;"/#$;".G &;!.A &2@""6@7A.5 &2F""6F7G.) &2J""6J7K0M*;".G &;!.A &2@""6@7A.5 &2F""6F7G.) &2J""6J7K&/#$+")("\'#&\'#/& 8!:Ò! )'),q(";.# &;"),q('%%;O/2#2:""6:7;/#$+")("\'#&\'#." &"/,#;S/#$+")("\'#&\'#." &"'),q('$;+. &;-.} &2B""6B7C.q &2D""6D7E.e &22""6273.Y &28""6879.M &2:""6:7;.A &2<""6<7=.5 &2>""6>7?.) &2@""6@7A/#0*;+. &;-.} &2B""6B7C.q &2D""6D7E.e &22""6273.Y &28""6879.M &2:""6:7;.A &2<""6<7=.5 &2>""6>7?.) &2@""6@7A&&&#'),q("$;y0#*;y&"),q('%3""5#7Ó/q#24""6475/b$$;!/�#*;!&&&#/L$2J""6J7K/=$$;!/�#*;!&&&#/\'$8%:Ô% )(%\'#($\'#(#\'#("\'#&\'#'),q('2Õ""6Õ7Ö'),q('2×""6×7Ø'),q('2Ù""6Ù7Ú'),q('2Û""6Û7Ü'),q('2Ý""6Ý7Þ'),q('2ß""6ß7à'),q('2á""6á7â'),q('2ã""6ã7ä'),q('2å""6å7æ'),q('2ç""6ç7è'),q('2é""6é7ê'),q("%;
.Y &;.S &;.M &;.G &;.A &;.; &;.5 &;./ &;.) &;.# &;6/& 8!:ë! )"),q("%;/G#;'/>$;/5$;'/,$;/#$+%)(%'#($'#(#'#(\"'#&'#"),q("%;/' 8!:ì!! )"),q("%;!/5#;!/,$;!/#$+#)(#'#(\"'#&'#"),q("%$;*.A &;+.; &;-.5 &;3./ &;4.) &;'.# &;(0G*;*.A &;+.; &;-.5 &;3./ &;4.) &;'.# &;(&/& 8!:í! )"),q("%;¶/Y#$%;A/,#;¶/#$+\")(\"'#&'#06*%;A/,#;¶/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),q('%;9/N#%2:""6:7;/,#;9/#$+")("\'#&\'#." &"/\'$8":î" )("\'#&\'#'),q("%;:.c &%;/Y#$%;A/,#;/#$+\")(\"'#&'#06*%;A/,#;/#$+\")(\"'#&'#&/#$+\")(\"'#&'#/& 8!:ï! )"),q("%;L.# &;/]#$%;B/,#;/#$+\")(\"'#&'#06*%;B/,#;/#$+\")(\"'#&'#&/'$8\":ð\" )(\"'#&'#"),q("%;.\" &\"/>#;@/5$;M/,$;?/#$+$)($'#(#'#(\"'#&'#"),q("%%;6/Y#$%;./,#;6/#$+\")(\"'#&'#06*%;./,#;6/#$+\")(\"'#&'#&/#$+\")(\"'#&'#.# &;H/' 8!:ñ!! )"),q(";.) &;.# &; "),q("%3ò\"\"5!7ó/:#;</1$;/($8#:ô#! )(#'#(\"'#&'#"),q("%3õ\"\"5'7ö/:#;</1$;/($8#:÷#! )(#'#(\"'#&'#"),q("%$;!/�#*;!&&&#/' 8!:ø!! )"),q('%2ù""6ù7ú/o#%2J""6J7K/M#;!." &"/?$;!." &"/1$;!." &"/#$+$)($\'#(#\'#("\'#&\'#." &"/\'$8":û" )("\'#&\'#'),q('%;6/J#%;</,#;¡/#$+")("\'#&\'#." &"/)$8":ü""! )("\'#&\'#'),q(";6.) &;T.# &;H"),q("%;£/Y#$%;B/,#;¤/#$+\")(\"'#&'#06*%;B/,#;¤/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),q('%3ý""5&7þ.G &3ÿ""5\'7Ā.; &3ā""5$7Ă./ &3ă""5%7Ą.# &;6/& 8!:ą! )'),q(";¥.# &; "),q('%3Ć""5(7ć/M#;</D$3Ĉ""5(7ĉ./ &3Ċ""5(7ċ.# &;6/#$+#)(#\'#("\'#&\'#'),q("%;6/Y#$%;A/,#;6/#$+\")(\"'#&'#06*%;A/,#;6/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),q("%$;!/�#*;!&&&#/' 8!:Č!! )"),q("%;©/& 8!:č! )"),q("%;ª/k#;;/b$;¯/Y$$%;B/,#;°/#$+\")(\"'#&'#06*%;B/,#;°/#$+\")(\"'#&'#&/#$+$)($'#(#'#(\"'#&'#"),q(";«.# &;¬"),q('3Ď""5$7ď.S &3Đ""5%7đ.G &3Ē""5%7ē.; &3Ĕ""5%7ĕ./ &3Ė""5+7ė.# &;'),q('3Ę""5\'7ę./ &3Ě""5)7ě.# &;'),q(";6.# &;®"),q('%3Ĝ""5"7ĝ/,#;6/#$+")("\'#&\'#'),q(";.# &;6"),q("%;6/5#;</,$;±/#$+#)(#'#(\"'#&'#"),q(";6.# &;H"),q("%;³/5#;./,$;/#$+#)(#'#(\"'#&'#"),q("%$;!/�#*;!&&&#/' 8!:Ğ!! )"),q("%;/' 8!:ğ!! )"),q('%;¶/^#$%;B/,#; /#$+")("\'#&\'#06*%;B/,#; /#$+")("\'#&\'#&/($8":Ġ"!!)("\'#&\'#'),q('%%;7/e#$%2J""6J7K/,#;7/#$+")("\'#&\'#0<*%2J""6J7K/,#;7/#$+")("\'#&\'#&/#$+")("\'#&\'#/"!&,)'),q("%;L.# &;/]#$%;B/,#;¸/#$+\")(\"'#&'#06*%;B/,#;¸/#$+\")(\"'#&'#&/'$8\":ġ\" )(\"'#&'#"),q(";¹.# &; "),q("%3Ģ\"\"5#7ģ/:#;</1$;6/($8#:Ĥ#! )(#'#(\"'#&'#"),q("%$;!/�#*;!&&&#/' 8!:ĥ!! )"),q("%;/' 8!:Ħ!! )"),q("%$;0#*;&/x#;@/o$;M/f$;?/]$$%;B/,#; /#$+\")(\"'#&'#06*%;B/,#; /#$+\")(\"'#&'#&/'$8%:ħ% )(%'#($'#(#'#(\"'#&'#"),q(";¾"),q("%3Ĩ\"\"5&7ĩ/k#;./b$;Á/Y$$%;A/,#;Á/#$+\")(\"'#&'#06*%;A/,#;Á/#$+\")(\"'#&'#&/#$+$)($'#(#'#(\"'#&'#.# &;¿"),q("%;6/k#;./b$;À/Y$$%;A/,#;À/#$+\")(\"'#&'#06*%;A/,#;À/#$+\")(\"'#&'#&/#$+$)($'#(#'#(\"'#&'#"),q("%;6/;#;</2$;6.# &;H/#$+#)(#'#(\"'#&'#"),q(";Â.G &;Ä.A &;Æ.; &;È.5 &;É./ &;Ê.) &;Ë.# &;À"),q("%3Ī\"\"5%7ī/5#;</,$;Ã/#$+#)(#'#(\"'#&'#"),q("%;I/' 8!:Ĭ!! )"),q("%3ĭ\"\"5&7Į/#;</$;D/
$;Å/|$$%$;'/�#*;'&&&#/,#;Å/#$+\")(\"'#&'#0C*%$;'/�#*;'&&&#/,#;Å/#$+\")(\"'#&'#&/,$;E/#$+&)(&'#(%'#($'#(#'#(\"'#&'#"),q(";t.# &;w"),q("%3į\"\"5%7İ/5#;</,$;Ç/#$+#)(#'#(\"'#&'#"),q("%;I/' 8!:ı!! )"),q("%3IJ\"\"5&7ij/:#;</1$;I/($8#:Ĵ#! )(#'#(\"'#&'#"),q('%3ĵ""5%7Ķ/]#;</T$%3ķ""5$7ĸ/& 8!:Ĺ! ).4 &%3ĺ""5%7Ļ/& 8!:ļ! )/#$+#)(#\'#("\'#&\'#'),q('%3Ľ""5)7ľ/R#;</I$3Ŀ""5#7ŀ./ &3Ł""5(7ł.# &;6/($8#:Ń#! )(#\'#("\'#&\'#'),q('%3ń""5#7Ņ/#;</$;D/$%;Ì/e#$%2D""6D7E/,#;Ì/#$+")("\'#&\'#0<*%2D""6D7E/,#;Ì/#$+")("\'#&\'#&/#$+")("\'#&\'#/,$;E/#$+%)(%\'#($\'#(#\'#("\'#&\'#'),q('%3ņ""5(7Ň./ &3ň""5$7ʼn.# &;6/\' 8!:Ŋ!! )'),q("%;6/Y#$%;A/,#;6/#$+\")(\"'#&'#06*%;A/,#;6/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),q("%;Ï/G#;./>$;Ï/5$;./,$;/#$+%)(%'#($'#(#'#(\"'#&'#"),q("%$;!/�#*;!&&&#/' 8!:ŋ!! )"),q("%;Ñ/]#$%;A/,#;Ñ/#$+\")(\"'#&'#06*%;A/,#;Ñ/#$+\")(\"'#&'#&/'$8\":Ō\" )(\"'#&'#"),q("%;/]#$%;B/,#; /#$+\")(\"'#&'#06*%;B/,#; /#$+\")(\"'#&'#&/'$8\":ō\" )(\"'#&'#"),q('%;L.O &;.I &%;@." &"/:#;t/1$;?." &"/#$+#)(#\'#("\'#&\'#/]#$%;B/,#; /#$+")("\'#&\'#06*%;B/,#; /#$+")("\'#&\'#&/\'$8":Ŏ" )("\'#&\'#'),q("%;Ô/]#$%;B/,#;Õ/#$+\")(\"'#&'#06*%;B/,#;Õ/#$+\")(\"'#&'#&/'$8\":ŏ\" )(\"'#&'#"),q("%;/& 8!:Ő! )"),q('%3ő""5(7Œ/:#;</1$;6/($8#:œ#! )(#\'#("\'#&\'#.g &%3Ŕ""5&7ŕ/:#;</1$;6/($8#:Ŗ#! )(#\'#("\'#&\'#.: &%3ŗ""5*7Ř/& 8!:ř! ).# &; '),q('%%;6/k#$%;A/2#;6/)$8":Ś""$ )("\'#&\'#0<*%;A/2#;6/)$8":Ś""$ )("\'#&\'#&/)$8":ś""! )("\'#&\'#." &"/\' 8!:Ŝ!! )'),q("%;Ø/Y#$%;A/,#;Ø/#$+\")(\"'#&'#06*%;A/,#;Ø/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),q("%;/Y#$%;B/,#; /#$+\")(\"'#&'#06*%;B/,#; /#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),q("%$;!/�#*;!&&&#/' 8!:ŝ!! )"),q("%;Û/Y#$%;B/,#;Ü/#$+\")(\"'#&'#06*%;B/,#;Ü/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),q('%3Ş""5&7ş.; &3Š""5\'7š./ &3Ţ""5*7ţ.# &;6/& 8!:Ť! )'),q("%3ť\"\"5&7Ŧ/:#;</1$;Ý/($8#:ŧ#! )(#'#(\"'#&'#.} &%3õ\"\"5'7ö/:#;</1$;/($8#:Ũ#! )(#'#(\"'#&'#.P &%3ũ\"\"5+7Ū/:#;</1$;/($8#:ū#! )(#'#(\"'#&'#.# &; "),q('3Ŭ""5+7ŭ.k &3Ů""5)7ů._ &3Ű""5(7ű.S &3Ų""5\'7ų.G &3Ŵ""5&7ŵ.; &3Ŷ""5*7ŷ./ &3Ÿ""5)7Ź.# &;6'),q(';1." &"'),q('%%;6/k#$%;A/2#;6/)$8":Ś""$ )("\'#&\'#0<*%;A/2#;6/)$8":Ś""$ )("\'#&\'#&/)$8":ś""! )("\'#&\'#." &"/\' 8!:ź!! )'),q("%;L.# &;/]#$%;B/,#;á/#$+\")(\"'#&'#06*%;B/,#;á/#$+\")(\"'#&'#&/'$8\":Ż\" )(\"'#&'#"),q(";¹.# &; "),q("%;ã/Y#$%;A/,#;ã/#$+\")(\"'#&'#06*%;A/,#;ã/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),q("%;ê/k#;./b$;í/Y$$%;B/,#;ä/#$+\")(\"'#&'#06*%;B/,#;ä/#$+\")(\"'#&'#&/#$+$)($'#(#'#(\"'#&'#"),q(";å.; &;æ.5 &;ç./ &;è.) &;é.# &; "),q("%3ż\"\"5#7Ž/:#;</1$;ð/($8#:ž#! )(#'#(\"'#&'#"),q("%3ſ\"\"5%7ƀ/:#;</1$;T/($8#:Ɓ#! )(#'#(\"'#&'#"),q("%3Ƃ\"\"5(7ƃ/F#;</=$;\\.) &;Y.# &;X/($8#:Ƅ#! )(#'#(\"'#&'#"),q("%3ƅ\"\"5&7Ɔ/:#;</1$;6/($8#:Ƈ#! )(#'#(\"'#&'#"),q("%3ƈ\"\"5%7Ɖ/A#;</8$$;!0#*;!&/($8#:Ɗ#! )(#'#(\"'#&'#"),q("%;ë/G#;;/>$;6/5$;;/,$;ì/#$+%)(%'#($'#(#'#(\"'#&'#"),q('%3""5#7Ó.# &;6/\' 8!:Ƌ!! )'),q('%3±""5#7ƌ.G &3³""5#7ƍ.; &3·""5#7Ǝ./ &3µ""5$7Ə.# &;6/\' 8!:Ɛ!! )'),q('%;î/D#%;C/,#;ï/#$+")("\'#&\'#." &"/#$+")("\'#&\'#'),q("%;U.) &;\\.# &;X/& 8!:Ƒ! )"),q('%%;!." &"/[#;!." &"/M$;!." &"/?$;!." &"/1$;!." &"/#$+%)(%\'#($\'#(#\'#("\'#&\'#/\' 8!:ƒ!! )'),q('%%;!/?#;!." &"/1$;!." &"/#$+#)(#\'#("\'#&\'#/\' 8!:Ɠ!! )'),q(";¾"),q('%;/^#$%;B/,#;ó/#$+")("\'#&\'#06*%;B/,#;ó/#$+")("\'#&\'#&/($8":Ɣ"!!)("\'#&\'#'),q(";ô.# &; "),q('%2ƕ""6ƕ7Ɩ/L#;</C$2Ɨ""6Ɨ7Ƙ.) &2ƙ""6ƙ7ƚ/($8#:ƛ#! )(#\'#("\'#&\'#'),q('%;/^#$%;B/,#; /#$+")("\'#&\'#06*%;B/,#; /#$+")("\'#&\'#&/($8":Ɯ"!!)("\'#&\'#'),q("%;6/5#;0/,$;÷/#$+#)(#'#(\"'#&'#"),q("$;2.) &;4.# &;.0/*;2.) &;4.# &;.&"),q("$;%0#*;%&"),q("%;ú/;#28\"\"6879/,$;û/#$+#)(#'#(\"'#&'#"),q('%3Ɲ""5%7ƞ.) &3Ɵ""5$7Ơ/\' 8!:ơ!! )'),q('%;ü/J#%28""6879/,#;^/#$+")("\'#&\'#." &"/#$+")("\'#&\'#'),q("%;\\.) &;X.# &;/' 8!:Ƣ!! )"),q(';".S &;!.M &2F""6F7G.A &2J""6J7K.5 &2H""6H7I.) &2N""6N7O'),q('2L""6L7M. &2B""6B7C. &2<""6<7=.} &2R""6R7S.q &2T""6T7U.e &2V""6V7W.Y &2P""6P7Q.M &2@""6@7A.A &2D""6D7E.5 &22""6273.) &2>""6>7?'),q('%;Ā/b#28""6879/S$;û/J$%2ƣ""6ƣ7Ƥ/,#;ì/#$+")("\'#&\'#." &"/#$+$)($\'#(#\'#("\'#&\'#'),q('%3ƥ""5%7Ʀ.) &3Ƨ""5$7ƨ/\' 8!:ơ!! )'),q('%3±""5#7².6 &3³""5#7´.* &$;+0#*;+&/\' 8!:Ʃ!! )'),q("%;Ą/#2F\"\"6F7G/x$;ă/o$2F\"\"6F7G/`$;ă/W$2F\"\"6F7G/H$;ă/?$2F\"\"6F7G/0$;ą/'$8):ƪ) )()'#(('#(''#(&'#(%'#($'#(#'#(\"'#&'#"),q("%;#/>#;#/5$;#/,$;#/#$+$)($'#(#'#(\"'#&'#"),q("%;ă/,#;ă/#$+\")(\"'#&'#"),q("%;ă/5#;ă/,$;ă/#$+#)(#'#(\"'#&'#"),q("%;q/T#$;m0#*;m&/D$%; /,#;ø/#$+\")(\"'#&'#.\" &\"/#$+#)(#'#(\"'#&'#"),q('%2ƫ""6ƫ7Ƭ.) &2ƭ""6ƭ7Ʈ/w#;0/n$;Ĉ/e$$%;B/2#;ĉ.# &; /#$+")("\'#&\'#0<*%;B/2#;ĉ.# &; /#$+")("\'#&\'#&/#$+$)($\'#(#\'#("\'#&\'#'),q(";.# &;L"),q("%2Ư\"\"6Ư7ư/5#;</,$;Ċ/#$+#)(#'#(\"'#&'#"),q("%;D/S#;,/J$2:\"\"6:7;/;$;,.# &;T/,$;E/#$+%)(%'#($'#(#'#(\"'#&'#")],g=0,f=0,v=[{line:1,column:1}],p=0,b=[],w=0;if(void 0!==t.startRule){if(!(t.startRule in c))throw new Error("Can't start parsing from rule \""+t.startRule+'".');l=c[t.startRule]}function I(){return e.substring(f,g)}function E(){return D(f,g)}function C(e,t){return{type:"literal",text:e,ignoreCase:t}}function x(e,t,n){return{type:"class",parts:e,inverted:t,ignoreCase:n}}function A(t){var n,r=v[t];if(r)return r;for(n=t-1;!v[n];)n--;for(r={line:(r=v[n]).line,column:r.column};n<t;)10===e.charCodeAt(n)?(r.line++,r.column=1):r.column++,n++;return v[t]=r,r}function D(e,t){var n=A(e),r=A(t);return{source:a,start:{offset:e,line:n.line,column:n.column},end:{offset:t,line:r.line,column:r.column}}}function H(e){g<p||(g>p&&(p=g,b=[]),b.push(e))}function q(e){var t;return m(t=e.split("")).call(t,function(e){return e.charCodeAt(0)-32})}if(t.data={},n=function t(n){for(var r,i,s=h[n],a=0,c=[],l=s.length,v=[],p=[];;){for(;a<l;)switch(s[a]){case 0:p.push(u[s[a+1]]),a+=2;break;case 1:p.push(void 0),a++;break;case 2:p.push(null),a++;break;case 3:p.push(o),a++;break;case 4:p.push([]),a++;break;case 5:p.push(g),a++;break;case 6:p.pop(),a++;break;case 7:g=p.pop(),a++;break;case 8:p.length-=s[a+1],a+=2;break;case 9:R(p).call(p,-2,1),a++;break;case 10:p[p.length-2].push(p.pop()),a++;break;case 11:p.push(R(p).call(p,p.length-s[a+1],s[a+1])),a+=2;break;case 12:p.push(e.substring(p.pop(),g)),a++;break;case 13:v.push(l),c.push(a+3+s[a+1]+s[a+2]),p[p.length-1]?(l=a+3+s[a+1],a+=3):(l=a+3+s[a+1]+s[a+2],a+=3+s[a+1]);break;case 14:v.push(l),c.push(a+3+s[a+1]+s[a+2]),p[p.length-1]===o?(l=a+3+s[a+1],a+=3):(l=a+3+s[a+1]+s[a+2],a+=3+s[a+1]);break;case 15:v.push(l),c.push(a+3+s[a+1]+s[a+2]),p[p.length-1]!==o?(l=a+3+s[a+1],a+=3):(l=a+3+s[a+1]+s[a+2],a+=3+s[a+1]);break;case 16:p[p.length-1]!==o?(v.push(l),c.push(a),l=a+2+s[a+1],a+=2):a+=2+s[a+1];break;case 17:v.push(l),c.push(a+3+s[a+1]+s[a+2]),e.length>g?(l=a+3+s[a+1],a+=3):(l=a+3+s[a+1]+s[a+2],a+=3+s[a+1]);break;case 18:v.push(l),c.push(a+4+s[a+2]+s[a+3]),e.substr(g,u[s[a+1]].length)===u[s[a+1]]?(l=a+4+s[a+2],a+=4):(l=a+4+s[a+2]+s[a+3],a+=4+s[a+2]);break;case 19:v.push(l),c.push(a+4+s[a+2]+s[a+3]),e.substr(g,u[s[a+1]].length).toLowerCase()===u[s[a+1]]?(l=a+4+s[a+2],a+=4):(l=a+4+s[a+2]+s[a+3],a+=4+s[a+2]);break;case 20:v.push(l),c.push(a+4+s[a+2]+s[a+3]),u[s[a+1]].test(e.charAt(g))?(l=a+4+s[a+2],a+=4):(l=a+4+s[a+2]+s[a+3],a+=4+s[a+2]);break;case 21:p.push(e.substr(g,s[a+1])),g+=s[a+1],a+=2;break;case 22:p.push(u[s[a+1]]),g+=u[s[a+1]].length,a+=2;break;case 23:p.push(o),0===w&&H(u[s[a+1]]),a+=2;break;case 24:f=p[p.length-1-s[a+1]],a+=2;break;case 25:f=g,a++;break;case 26:i=m(r=d(s).call(s,a+4,a+4+s[a+3])).call(r,function(e){return p[p.length-1-e]}),R(p).call(p,p.length-s[a+2],s[a+2],u[s[a+1]].apply(null,i)),a+=4+s[a+3];break;case 27:p.push(t(s[a+1])),a+=2;break;case 28:w++,a++;break;case 29:w--,a++;break;default:throw new Error("Invalid opcode: "+s[a]+".")}if(!(v.length>0))break;l=v.pop(),a=c.pop()}return p[0]}(l),n!==o&&g===e.length)return n;throw n!==o&&g<e.length&&H({type:"end"}),r=b,i=p<e.length?e.charAt(p):null,s=p<e.length?D(p,p+1):D(p,p),new Ae(Ae.buildMessage(r,i),r,i,s)};!function(e){e.parse=function(e,t){var n={startRule:t};try{He(e,n)}catch(e){n.data=-1}return n.data},e.nameAddrHeaderParse=function(t){var n=e.parse(t,"Name_Addr_Header");return-1!==n?n:void 0},e.URIParse=function(t){var n=e.parse(t,"SIP_URI");return-1!==n?n:void 0}}(De||(De={}));var qe={100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"};function _e(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:32,n="",r=0;r<e;r++){n+=Math.floor(Math.random()*t).toString(t)}return n}function $e(e){return qe[e]||""}function Me(){return _e(10)}function Pe(e){for(var t={"Call-Id":"Call-ID",Cseq:"CSeq","Min-Se":"Min-SE",Rack:"RAck",Rseq:"RSeq","Www-Authenticate":"WWW-Authenticate"},n=e.toLowerCase().replace(/_/g,"-").split("-"),r=n.length,i="",s=0;s<r;s++)0!==s&&(i+="-"),i+=n[s].charAt(0).toUpperCase()+n[s].substring(1);return t[i]&&(i=t[i]),i}function Oe(e){return encodeURIComponent(e).replace(/%[A-F\d]{2}/g,"U").length}function Ne(e,t){var n=void 0!==A&&D(e)||e["@@iterator"];if(!n){if(b(e)||(n=function(e,t){if(e){var n;if("string"==typeof e)return je(e,t);var r=d(n={}.toString.call(e)).call(n,8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?x(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?je(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,o=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){a=!0,s=e},f:function(){try{o||null==n.return||n.return()}finally{if(a)throw s}}}}function je(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var Fe=function(){return t(function t(){e(this,t),c(this,"viaBranch",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"method",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"toTag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"to",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"fromTag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"from",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"callId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"cseq",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"via",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"headers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),c(this,"referTo",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0})},[{key:"addHeader",value:function(e,t){var n={raw:t};e=Pe(e),this.headers[e]?this.headers[e].push(n):this.headers[e]=[n]}},{key:"getHeader",value:function(e){var t=this.headers[Pe(e)];if(t)return t[0]?t[0].raw:void 0}},{key:"getHeaders",value:function(e){var t=this.headers[Pe(e)],n=[];if(!t)return[];var r,i=Ne(t);try{for(i.s();!(r=i.n()).done;){var s=r.value;n.push(s.raw)}}catch(e){i.e(e)}finally{i.f()}return n}},{key:"hasHeader",value:function(e){return!!this.headers[Pe(e)]}},{key:"parseHeader",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(e=Pe(e),this.headers[e]&&!(t>=this.headers[e].length)){var n=this.headers[e][t],r=n.raw;if(n.parsed)return n.parsed;var i,s=De.parse(r,e.replace(/-/g,"_"));return-1===s?void R(i=this.headers[e]).call(i,t,1):(n.parsed=s,s)}}},{key:"s",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return this.parseHeader(e,t)}},{key:"setHeader",value:function(e,t){this.headers[Pe(e)]=[{raw:t}]}},{key:"toString",value:function(){return this.data}}])}();function Be(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Be=function(){return!!e})()}var Ue=function(){function o(){var t,s,a,l;return e(this,o),s=this,a=i(a=o),t=r(s,Be()?n(a,l||[],i(s).constructor):a.apply(s,l)),c(t,"ruri",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),t}return s(o,Fe),t(o)}();function Le(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Le=function(){return!!e})()}var Ge=function(){function o(){var t,s,a,l;return e(this,o),s=this,a=i(a=o),t=r(s,Le()?n(a,l||[],i(s).constructor):a.apply(s,l)),c(t,"statusCode",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(t,"reasonPhrase",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),t}return s(o,Fe),t(o)}();function Ve(e,t){var n=void 0!==A&&D(e)||e["@@iterator"];if(!n){if(b(e)||(n=function(e,t){if(e){var n;if("string"==typeof e)return We(e,t);var r=d(n={}.toString.call(e)).call(n,8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?x(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?We(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,o=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){a=!0,s=e},f:function(){try{o||null==n.return||n.return()}finally{if(a)throw s}}}}function We(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var Ye,Ke,ze=function(){return t(function t(n,r,i,s,o,a,l){if(e(this,t),c(this,"headers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),c(this,"method",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"ruri",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"from",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"fromTag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"fromURI",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"to",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"toTag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"toURI",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"branch",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"callId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"cseq",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"extraHeaders",{enumerable:!0,configurable:!0,writable:!0,value:[]}),c(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.options=t.getDefaultOptions(),o){var u,h;if(this.options=H(H({},this.options),o),this.options.optionTags&&this.options.optionTags.length)this.options.optionTags=d(u=this.options.optionTags).call(u);if(this.options.routeSet&&this.options.routeSet.length)this.options.routeSet=d(h=this.options.routeSet).call(h)}a&&a.length&&(this.extraHeaders=d(a).call(a)),l&&(this.body={body:l.content,contentType:l.contentType}),this.method=n,this.ruri=r.clone(),this.fromURI=i.clone(),this.fromTag=this.options.fromTag?this.options.fromTag:Me(),this.from=t.makeNameAddrHeader(this.fromURI,this.options.fromDisplayName,this.fromTag),this.toURI=s.clone(),this.toTag=this.options.toTag,this.to=t.makeNameAddrHeader(this.toURI,this.options.toDisplayName,this.toTag),this.callId=this.options.callId?this.options.callId:this.options.callIdPrefix+_e(15),this.cseq=this.options.cseq,this.setHeader("route",this.options.routeSet),this.setHeader("via",""),this.setHeader("to",this.to.toString()),this.setHeader("from",this.from.toString()),this.setHeader("cseq",this.cseq+" "+this.method),this.setHeader("call-id",this.callId),this.setHeader("max-forwards","70")},[{key:"getHeader",value:function(e){var t=this.headers[Pe(e)];if(t){if(t[0])return t[0]}else{var n,r=new RegExp("^\\s*"+e+"\\s*:","i"),i=Ve(this.extraHeaders);try{for(i.s();!(n=i.n()).done;){var s,o=n.value;if(r.test(o))return S(s=o.substring(q(o).call(o,":")+1)).call(s)}}catch(e){i.e(e)}finally{i.f()}}}},{key:"getHeaders",value:function(e){var t=[],n=this.headers[Pe(e)];if(n){var r,i=Ve(n);try{for(i.s();!(r=i.n()).done;){var s=r.value;t.push(s)}}catch(e){i.e(e)}finally{i.f()}}else{var o,a=new RegExp("^\\s*"+e+"\\s*:","i"),c=Ve(this.extraHeaders);try{for(c.s();!(o=c.n()).done;){var l,u=o.value;if(a.test(u))t.push(S(l=u.substring(q(u).call(u,":")+1)).call(l))}}catch(e){c.e(e)}finally{c.f()}}return t}},{key:"hasHeader",value:function(e){if(this.headers[Pe(e)])return!0;var t,n=new RegExp("^\\s*"+e+"\\s*:","i"),r=Ve(this.extraHeaders);try{for(r.s();!(t=r.n()).done;){var i=t.value;if(n.test(i))return!0}}catch(e){r.e(e)}finally{r.f()}return!1}},{key:"setHeader",value:function(e,t){this.headers[Pe(e)]=t instanceof Array?t:[t]}},{key:"setViaHeader",value:function(e,t){this.options.hackViaTcp&&(t="TCP");var n="SIP/2.0/"+t;n+=" "+this.options.viaHost+";branch="+e,this.options.forceRport&&(n+=";rport"),this.setHeader("via",n),this.branch=e}},{key:"toString",value:function(){var e="";for(var t in e+=this.method+" "+this.ruri.toRaw()+" SIP/2.0\r\n",this.headers)if(this.headers[t]){var n,r=Ve(this.headers[t]);try{for(r.s();!(n=r.n()).done;){e+=t+": "+n.value+"\r\n"}}catch(e){r.e(e)}finally{r.f()}}var i,s=Ve(this.extraHeaders);try{for(s.s();!(i=s.n()).done;){var o=i.value;e+=S(o).call(o)+"\r\n"}}catch(e){s.e(e)}finally{s.f()}return e+="Supported: "+this.options.optionTags.join(", ")+"\r\n",e+="User-Agent: "+this.options.userAgentString+"\r\n",this.body?"string"==typeof this.body?(e+="Content-Length: "+Oe(this.body)+"\r\n\r\n",e+=this.body):this.body.body&&this.body.contentType?(e+="Content-Type: "+this.body.contentType+"\r\n",e+="Content-Length: "+Oe(this.body.body)+"\r\n\r\n",e+=this.body.body):e+="Content-Length: 0\r\n\r\n":e+="Content-Length: 0\r\n\r\n",e}}],[{key:"getDefaultOptions",value:function(){return{callId:"",callIdPrefix:"",cseq:1,toDisplayName:"",toTag:"",fromDisplayName:"",fromTag:"",forceRport:!1,hackViaTcp:!1,optionTags:["outbound"],routeSet:[],userAgentString:"sip.js",viaHost:""}}},{key:"makeNameAddrHeader",value:function(e,t,n){var r={};return n&&(r.tag=n),new Re(e,t,r)}}])}();function Ze(e){return"application/sdp"===e?"session":"render"}function Je(e){var t="string"==typeof e?e:e.body,n="string"==typeof e?"application/sdp":e.contentType;return{contentDisposition:Ze(n),contentType:n,content:t}}function Xe(e){return!(!e||"string"!=typeof e.content||"string"!=typeof e.contentType||void 0!==e.contentDisposition)||"string"==typeof e.contentDisposition}function Qe(e){var t,n,r;if(e instanceof Ue&&e.body){var i=e.parseHeader("Content-Disposition");t=i?i.type:void 0,n=e.parseHeader("Content-Type"),r=e.body}if(e instanceof Ge&&e.body){var s=e.parseHeader("Content-Disposition");t=s?s.type:void 0,n=e.parseHeader("Content-Type"),r=e.body}if(e instanceof ze&&e.body)if(t=e.getHeader("Content-Disposition"),n=e.getHeader("Content-Type"),"string"==typeof e.body){if(!n)throw new Error("Header content type header does not equal body content type.");r=e.body}else{if(n&&n!==e.body.contentType)throw new Error("Header content type header does not equal body content type.");n=e.body.contentType,r=e.body.body}if(Xe(e)&&(t=e.contentDisposition,n=e.contentType,r=e.content),r){if(n&&!t&&(t=Ze(n)),!t)throw new Error("Content disposition undefined.");if(!n)throw new Error("Content type undefined.");return{contentDisposition:t,contentType:n,content:r}}}!function(e){e.Initial="Initial",e.Early="Early",e.AckWait="AckWait",e.Confirmed="Confirmed",e.Terminated="Terminated"}(Ye||(Ye={})),function(e){e.Initial="Initial",e.HaveLocalOffer="HaveLocalOffer",e.HaveRemoteOffer="HaveRemoteOffer",e.Stable="Stable",e.Closed="Closed"}(Ke||(Ke={}));var et=500,tt=5e3,nt={T1:et,T2:4e3,T4:tt,TIMER_B:32e3,TIMER_D:0,TIMER_F:32e3,TIMER_H:32e3,TIMER_I:0,TIMER_J:0,TIMER_K:0,TIMER_L:32e3,TIMER_M:32e3,TIMER_N:32e3,PROVISIONAL_RESPONSE_INTERVAL:6e4};function rt(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(rt=function(){return!!e})()}var it,st=function(){function o(t){return e(this,o),s=this,c=[t||"Transaction state error."],a=i(a=o),r(s,rt()?n(a,c||[],i(s).constructor):a.apply(s,c));var s,a,c}return s(o,se),t(o)}();!function(e){e.ACK="ACK",e.BYE="BYE",e.CANCEL="CANCEL",e.INFO="INFO",e.INVITE="INVITE",e.MESSAGE="MESSAGE",e.NOTIFY="NOTIFY",e.OPTIONS="OPTIONS",e.REGISTER="REGISTER",e.UPDATE="UPDATE",e.SUBSCRIBE="SUBSCRIBE",e.PUBLISH="PUBLISH",e.REFER="REFER",e.PRACK="PRACK"}(it||(it={}));var ot=[it.ACK,it.BYE,it.CANCEL,it.INFO,it.INVITE,it.MESSAGE,it.NOTIFY,it.OPTIONS,it.PRACK,it.REFER,it.REGISTER,it.SUBSCRIBE],at=function(){return t(function t(n){e(this,t),c(this,"incomingMessageRequest",{enumerable:!0,configurable:!0,writable:!0,value:n})},[{key:"request",get:function(){return this.incomingMessageRequest.message}},{key:"accept",value:function(e){return this.incomingMessageRequest.accept(e),l.resolve()}},{key:"reject",value:function(e){return this.incomingMessageRequest.reject(e),l.resolve()}}])}(),ct=function(){return t(function t(n){e(this,t),c(this,"incomingNotifyRequest",{enumerable:!0,configurable:!0,writable:!0,value:n})},[{key:"request",get:function(){return this.incomingNotifyRequest.message}},{key:"accept",value:function(e){return this.incomingNotifyRequest.accept(e),l.resolve()}},{key:"reject",value:function(e){return this.incomingNotifyRequest.reject(e),l.resolve()}}])}(),lt=function(){return t(function t(n,r){e(this,t),c(this,"incomingReferRequest",{enumerable:!0,configurable:!0,writable:!0,value:n}),c(this,"session",{enumerable:!0,configurable:!0,writable:!0,value:r}),c(this,"inviter",{enumerable:!0,configurable:!0,writable:!0,value:void 0})},[{key:"referTo",get:function(){var e=this.incomingReferRequest.message.parseHeader("refer-to");if(!(e instanceof Re))throw new Error("Failed to parse Refer-To header.");return e}},{key:"referredBy",get:function(){return this.incomingReferRequest.message.getHeader("referred-by")}},{key:"replaces",get:function(){var e=this.referTo.uri.getHeader("replaces");return e instanceof Array?e[0]:e}},{key:"request",get:function(){return this.incomingReferRequest.message}},{key:"accept",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:202};return this.incomingReferRequest.accept(e),l.resolve()}},{key:"reject",value:function(e){return this.incomingReferRequest.reject(e),l.resolve()}},{key:"makeInviter",value:function(e){var t;if(this.inviter)return this.inviter;var n=this.referTo.uri.clone();n.clearHeaders();var r=d(t=(e=e||{}).extraHeaders||[]).call(t),i=this.replaces;i&&r.push("Replaces: "+decodeURIComponent(i));var s=this.referredBy;return s&&r.push("Referred-By: "+s),e.extraHeaders=r,this.inviter=this.session.userAgent._makeInviter(n,e),this.inviter._referred=this.session,this.session._referral=this.inviter,this.inviter}}])}();function ut(){var e=new Date,t=e.getFullYear(),n=e.getMonth()+1,r=e.getDate(),i=e.getHours(),s=e.getMinutes(),o=e.getSeconds();return t+"-"+dt(n)+"-"+dt(r)+" "+dt(i)+":"+dt(s)+":"+dt(o)}function dt(e){return e<10?"0"+e:e}exports.SessionState=void 0,function(e){e.Initial="Initial",e.Establishing="Establishing",e.Established="Established",e.Terminating="Terminating",e.Terminated="Terminated"}(exports.SessionState||(exports.SessionState={}));var ht,gt=function(){function n(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,n),c(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_contact",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_referral",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_replacee",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_assertedIdentity",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_dialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_referralInviterOptions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_renderbody",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_rendertype",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"onNotify",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"pendingReinvite",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(this,"pendingReinviteAck",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(this,"_sessionDescriptionHandler",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_sessionDescriptionHandlerModifiers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_sessionDescriptionHandlerOptions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_sessionDescriptionHandlerModifiersReInvite",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_sessionDescriptionHandlerOptionsReInvite",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:exports.SessionState.Initial}),c(this,"_stateEventEmitter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_userAgent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.delegate=r.delegate,this._stateEventEmitter=new we,this._userAgent=t}return t(n,[{key:"dispose",value:function(){var e,t=this;switch(this.logger.log(T(e="Session ".concat(this.id," in state ")).call(e,this._state," is being disposed")),delete this.userAgent._sessions[this.id],this._sessionDescriptionHandler&&this._sessionDescriptionHandler.close(),this.state){case exports.SessionState.Initial:case exports.SessionState.Establishing:break;case exports.SessionState.Established:return new l(function(e){t._bye({onAccept:function(){return e()},onRedirect:function(){return e()},onReject:function(){return e()}})});case exports.SessionState.Terminating:case exports.SessionState.Terminated:break;default:throw new Error("Unknown state.")}return l.resolve()}},{key:"assertedIdentity",get:function(){return this._assertedIdentity}},{key:"dialog",get:function(){return this._dialog}},{key:"id",get:function(){return this._id}},{key:"replacee",get:function(){return this._replacee}},{key:"sessionDescriptionHandler",get:function(){return this._sessionDescriptionHandler}},{key:"sessionDescriptionHandlerFactory",get:function(){return this.userAgent.configuration.sessionDescriptionHandlerFactory}},{key:"sessionDescriptionHandlerModifiers",get:function(){return this._sessionDescriptionHandlerModifiers||[]},set:function(e){this._sessionDescriptionHandlerModifiers=d(e).call(e)}},{key:"sessionDescriptionHandlerOptions",get:function(){return this._sessionDescriptionHandlerOptions||{}},set:function(e){this._sessionDescriptionHandlerOptions=H({},e)}},{key:"sessionDescriptionHandlerModifiersReInvite",get:function(){return this._sessionDescriptionHandlerModifiersReInvite||[]},set:function(e){this._sessionDescriptionHandlerModifiersReInvite=d(e).call(e)}},{key:"sessionDescriptionHandlerOptionsReInvite",get:function(){return this._sessionDescriptionHandlerOptionsReInvite||{}},set:function(e){this._sessionDescriptionHandlerOptionsReInvite=H({},e)}},{key:"state",get:function(){return this._state}},{key:"stateChange",get:function(){return this._stateEventEmitter}},{key:"userAgent",get:function(){return this._userAgent}},{key:"bye",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t="Session.bye() may only be called if established session.";switch(this.state){case exports.SessionState.Initial:"function"==typeof this.cancel?(t+=" However Inviter.invite() has not yet been called.",t+=" Perhaps you should have called Inviter.cancel()?"):"function"==typeof this.reject&&(t+=" However Invitation.accept() has not yet been called.",t+=" Perhaps you should have called Invitation.reject()?");break;case exports.SessionState.Establishing:"function"==typeof this.cancel?(t+=" However a dialog does not yet exist.",t+=" Perhaps you should have called Inviter.cancel()?"):"function"==typeof this.reject&&(t+=" However Invitation.accept() has not yet been called (or not yet resolved).",t+=" Perhaps you should have called Invitation.reject()?");break;case exports.SessionState.Established:var n=e.requestDelegate,r=this.copyRequestOptions(e.requestOptions);return this._bye(n,r);case exports.SessionState.Terminating:t+=" However this session is already terminating.","function"==typeof this.cancel?t+=" Perhaps you have already called Inviter.cancel()?":"function"==typeof this.reject&&(t+=" Perhaps you have already called Session.bye()?");break;case exports.SessionState.Terminated:t+=" However this session is already terminated.";break;default:throw new Error("Unknown state")}return this.logger.error(t),l.reject(new Error("Invalid session state ".concat(this.state)))}},{key:"info",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.state!==exports.SessionState.Established){return this.logger.error("Session.info() may only be called if established session."),l.reject(new Error("Invalid session state ".concat(this.state)))}var t=e.requestDelegate,n=this.copyRequestOptions(e.requestOptions);return this._info(t,n)}},{key:"invite",value:function(){var e,t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("Session.invite"),this.state!==exports.SessionState.Established)return l.reject(new Error("Invalid session state ".concat(this.state)));if(this.pendingReinvite)return l.reject(new le("Reinvite in progress. Please wait until complete, then try again."));this.pendingReinvite=!0,n.sessionDescriptionHandlerModifiers&&(this.sessionDescriptionHandlerModifiersReInvite=n.sessionDescriptionHandlerModifiers),n.sessionDescriptionHandlerOptions&&(this.sessionDescriptionHandlerOptionsReInvite=n.sessionDescriptionHandlerOptions);var r={onAccept:function(e){var r=Qe(e.message);if(!r)return t.logger.error("Received 2xx response to re-INVITE without a session description"),t.ackAndBye(e,400,"Missing session description"),t.stateTransition(exports.SessionState.Terminated),void(t.pendingReinvite=!1);if(n.withoutSdp){var i={sessionDescriptionHandlerOptions:t.sessionDescriptionHandlerOptionsReInvite,sessionDescriptionHandlerModifiers:t.sessionDescriptionHandlerModifiersReInvite};t.setOfferAndGetAnswer(r,i).then(function(t){e.ack({body:t})}).catch(function(n){t.logger.error("Failed to handle offer in 2xx response to re-INVITE"),t.logger.error(n.message),t.state===exports.SessionState.Terminated?e.ack():(t.ackAndBye(e,488,"Bad Media Description"),t.stateTransition(exports.SessionState.Terminated))}).then(function(){t.pendingReinvite=!1,n.requestDelegate&&n.requestDelegate.onAccept&&n.requestDelegate.onAccept(e)})}else{var s={sessionDescriptionHandlerOptions:t.sessionDescriptionHandlerOptionsReInvite,sessionDescriptionHandlerModifiers:t.sessionDescriptionHandlerModifiersReInvite};t.setAnswer(r,s).then(function(){e.ack()}).catch(function(n){t.logger.error("Failed to handle answer in 2xx response to re-INVITE"),t.logger.error(n.message),t.state!==exports.SessionState.Terminated?(t.ackAndBye(e,488,"Bad Media Description"),t.stateTransition(exports.SessionState.Terminated)):e.ack()}).then(function(){t.pendingReinvite=!1,n.requestDelegate&&n.requestDelegate.onAccept&&n.requestDelegate.onAccept(e)})}},onProgress:function(e){},onRedirect:function(e){},onReject:function(e){t.logger.warn("Received a non-2xx response to re-INVITE"),t.pendingReinvite=!1,n.withoutSdp?n.requestDelegate&&n.requestDelegate.onReject&&n.requestDelegate.onReject(e):t.rollbackOffer().catch(function(e){if(t.logger.error("Failed to rollback offer on non-2xx response to re-INVITE"),t.logger.error(e.message),t.state!==exports.SessionState.Terminated){if(!t.dialog)throw new Error("Dialog undefined.");var n=[];n.push("Reason: "+t.getReasonHeaderValue(500,"Internal Server Error")),t.dialog.bye(void 0,{extraHeaders:n}),t.stateTransition(exports.SessionState.Terminated)}}).then(function(){n.requestDelegate&&n.requestDelegate.onReject&&n.requestDelegate.onReject(e)})},onTrying:function(e){}},i=n.requestOptions||{};if(i.extraHeaders=d(e=i.extraHeaders||[]).call(e),i.extraHeaders.push("Allow: "+ot.toString()),i.extraHeaders.push("Contact: "+this._contact),n.withoutSdp){if(!this.dialog)throw this.pendingReinvite=!1,new Error("Dialog undefined.");return l.resolve(this.dialog.invite(r,i))}var s={sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptionsReInvite,sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiersReInvite};return this.getOffer(s).then(function(e){if(!t.dialog)throw t.pendingReinvite=!1,new Error("Dialog undefined.");return i.body=e,t.dialog.invite(r,i)}).catch(function(e){throw t.logger.error(e.message),t.logger.error("Failed to send re-INVITE"),t.pendingReinvite=!1,e})}},{key:"message",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.state!==exports.SessionState.Established){return this.logger.error("Session.message() may only be called if established session."),l.reject(new Error("Invalid session state ".concat(this.state)))}var t=e.requestDelegate,n=this.copyRequestOptions(e.requestOptions);return this._message(t,n)}},{key:"refer",value:function(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.state!==exports.SessionState.Established){return this.logger.error("Session.refer() may only be called if established session."),l.reject(new Error("Invalid session state ".concat(this.state)))}if(e instanceof n&&!e.dialog){return this.logger.error("Session.refer() may only be called with session which is established. You are perhaps attempting to attended transfer to a target for which there is not dialog yet established. Perhaps you are attempting a 'semi-attended' tansfer? Regardless, this is not supported. The recommended approached is to check to see if the target Session is in the Established state before calling refer(); if the state is not Established you may proceed by falling back using a URI as the target (blind transfer)."),l.reject(new Error("Invalid session state ".concat(this.state)))}var i=r.requestDelegate,s=this.copyRequestOptions(r.requestOptions);return s.extraHeaders=s.extraHeaders?T(t=s.extraHeaders).call(t,this.referExtraHeaders(this.referToString(e))):this.referExtraHeaders(this.referToString(e)),this._refer(r.onNotify,i,s)}},{key:"_bye",value:function(e,t){var n=this;if(!this.dialog)return l.reject(new Error("Session dialog undefined."));var r=this.dialog;switch(r.sessionState){case Ye.Initial:case Ye.Early:throw new Error("Invalid dialog state ".concat(r.sessionState));case Ye.AckWait:return this.stateTransition(exports.SessionState.Terminating),new l(function(i){r.delegate={onAck:function(){var s=r.bye(e,t);return n.stateTransition(exports.SessionState.Terminated),i(s),l.resolve()},onAckTimeout:function(){var s=r.bye(e,t);n.stateTransition(exports.SessionState.Terminated),i(s)}}});case Ye.Confirmed:var i=r.bye(e,t);return this.stateTransition(exports.SessionState.Terminated),l.resolve(i);case Ye.Terminated:throw new Error("Invalid dialog state ".concat(r.sessionState));default:throw new Error("Unrecognized state.")}}},{key:"_info",value:function(e,t){return this.dialog?l.resolve(this.dialog.info(e,t)):l.reject(new Error("Session dialog undefined."))}},{key:"_message",value:function(e,t){return this.dialog?l.resolve(this.dialog.message(e,t)):l.reject(new Error("Session dialog undefined."))}},{key:"_refer",value:function(e,t,n){return this.dialog?(this.onNotify=e,l.resolve(this.dialog.refer(t,n))):l.reject(new Error("Session dialog undefined."))}},{key:"ackAndBye",value:function(e,t,n){e.ack();var r=[];t&&r.push("Reason: "+this.getReasonHeaderValue(t,n)),e.session.bye(void 0,{extraHeaders:r})}},{key:"onAckRequest",value:function(e){var t=this;if(this.logger.log("Session.onAckRequest"),this.state!==exports.SessionState.Established&&this.state!==exports.SessionState.Terminating)return this.logger.error("ACK received while in state ".concat(this.state,", dropping request")),l.resolve();var n=this.dialog;if(!n)throw new Error("Dialog undefined.");var r={sessionDescriptionHandlerOptions:this.pendingReinviteAck?this.sessionDescriptionHandlerOptionsReInvite:this.sessionDescriptionHandlerOptions,sessionDescriptionHandlerModifiers:this.pendingReinviteAck?this._sessionDescriptionHandlerModifiersReInvite:this._sessionDescriptionHandlerModifiers};if(this.delegate&&this.delegate.onAck){var i=new pe(e);this.delegate.onAck(i)}switch(this.pendingReinviteAck=!1,n.signalingState){case Ke.Initial:this.logger.error("Invalid signaling state ".concat(n.signalingState,"."));var s=["Reason: "+this.getReasonHeaderValue(488,"Bad Media Description")];return n.bye(void 0,{extraHeaders:s}),this.stateTransition(exports.SessionState.Terminated),l.resolve();case Ke.Stable:var o=Qe(e.message);return o?"render"===o.contentDisposition?(this._renderbody=o.content,this._rendertype=o.contentType,l.resolve()):"session"!==o.contentDisposition?l.resolve():this.setAnswer(o,r).catch(function(e){t.logger.error(e.message);var r=["Reason: "+t.getReasonHeaderValue(488,"Bad Media Description")];n.bye(void 0,{extraHeaders:r}),t.stateTransition(exports.SessionState.Terminated)}):l.resolve();case Ke.HaveLocalOffer:this.logger.error("Invalid signaling state ".concat(n.signalingState,"."));var a=["Reason: "+this.getReasonHeaderValue(488,"Bad Media Description")];return n.bye(void 0,{extraHeaders:a}),this.stateTransition(exports.SessionState.Terminated),l.resolve();case Ke.HaveRemoteOffer:this.logger.error("Invalid signaling state ".concat(n.signalingState,"."));var c=["Reason: "+this.getReasonHeaderValue(488,"Bad Media Description")];return n.bye(void 0,{extraHeaders:c}),this.stateTransition(exports.SessionState.Terminated),l.resolve();case Ke.Closed:default:throw new Error("Invalid signaling state ".concat(n.signalingState,"."))}}},{key:"onByeRequest",value:function(e){if(this.logger.log("Session.onByeRequest"),this.state===exports.SessionState.Established){if(this.delegate&&this.delegate.onBye){var t=new me(e);this.delegate.onBye(t)}else e.accept();this.stateTransition(exports.SessionState.Terminated)}else this.logger.error("BYE received while in state ".concat(this.state,", dropping request"))}},{key:"onInfoRequest",value:function(e){if(this.logger.log("Session.onInfoRequest"),this.state===exports.SessionState.Established)if(this.delegate&&this.delegate.onInfo){var t=new ye(e);this.delegate.onInfo(t)}else e.accept();else this.logger.error("INFO received while in state ".concat(this.state,", dropping request"))}},{key:"onInviteRequest",value:function(e){var t=this;if(this.logger.log("Session.onInviteRequest"),this.state===exports.SessionState.Established){this.pendingReinviteAck=!0;var n=["Contact: "+this._contact];if(e.message.hasHeader("P-Asserted-Identity")){var r=e.message.getHeader("P-Asserted-Identity");if(!r)throw new Error("Header undefined.");this._assertedIdentity=De.nameAddrHeaderParse(r)}var i={sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptionsReInvite,sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiersReInvite};this.generateResponseOfferAnswerInDialog(i,e).then(function(r){var i=e.accept({statusCode:200,extraHeaders:n,body:r});t.delegate&&t.delegate.onInvite&&t.delegate.onInvite(e.message,i.message,200)}).catch(function(n){if(t.logger.error(n.message),t.logger.error("Failed to handle to re-INVITE request"),!t.dialog)throw new Error("Dialog undefined.");if(t.logger.error(t.dialog.signalingState),t.dialog.signalingState!==Ke.Stable)t.rollbackOffer().then(function(){var n=e.reject({statusCode:488});t.delegate&&t.delegate.onInvite&&t.delegate.onInvite(e.message,n.message,488)}).catch(function(n){t.logger.error(n.message),t.logger.error("Failed to rollback offer on re-INVITE request");var r=e.reject({statusCode:488});if(t.state!==exports.SessionState.Terminated){if(!t.dialog)throw new Error("Dialog undefined.");var i=[];i.push("Reason: "+t.getReasonHeaderValue(500,"Internal Server Error")),t.dialog.bye(void 0,{extraHeaders:i}),t.stateTransition(exports.SessionState.Terminated)}t.delegate&&t.delegate.onInvite&&t.delegate.onInvite(e.message,r.message,488)});else{var r=e.reject({statusCode:488});t.delegate&&t.delegate.onInvite&&t.delegate.onInvite(e.message,r.message,488)}})}else this.logger.error("INVITE received while in state ".concat(this.state,", dropping request"))}},{key:"onMessageRequest",value:function(e){if(this.logger.log("Session.onMessageRequest"),this.state===exports.SessionState.Established)if(this.delegate&&this.delegate.onMessage){var t=new at(e);this.delegate.onMessage(t)}else e.accept();else this.logger.error("MESSAGE received while in state ".concat(this.state,", dropping request"))}},{key:"onNotifyRequest",value:function(e){if(this.logger.log("Session.onNotifyRequest"),this.state===exports.SessionState.Established)if(this.onNotify){var t=new ct(e);this.onNotify(t)}else if(this.delegate&&this.delegate.onNotify){var n=new ct(e);this.delegate.onNotify(n)}else e.accept();else this.logger.error("NOTIFY received while in state ".concat(this.state,", dropping request"))}},{key:"onPrackRequest",value:function(e){if(this.logger.log("Session.onPrackRequest"),this.state===exports.SessionState.Established)throw new Error("Unimplemented.");this.logger.error("PRACK received while in state ".concat(this.state,", dropping request"))}},{key:"onReferRequest",value:function(e){var t=this;if(this.logger.log("Session.onReferRequest"),this.state===exports.SessionState.Established){if(!e.message.hasHeader("refer-to"))return this.logger.warn("Invalid REFER packet. A refer-to header is required. Rejecting."),void e.reject();var n=new lt(e,this);this.delegate&&this.delegate.onRefer?this.delegate.onRefer(n):(this.logger.log("No delegate available to handle REFER, automatically accepting and following."),n.accept().then(function(){return n.makeInviter(t._referralInviterOptions).invite()}).catch(function(e){t.logger.error(e.message)}))}else this.logger.error("REFER received while in state ".concat(this.state,", dropping request"))}},{key:"generateResponseOfferAnswer",value:function(e,t){var n=this;if(this.dialog)return this.generateResponseOfferAnswerInDialog(t,e).catch(function(t){var r;throw null===(r=n.userAgent.configuration)||void 0===r||r.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ut(),CALLID:e.message.callId,INVITE:e.message.toString(),ENTRY:"session: generateResponseOfferAnswer generateResponseOfferAnswerInDialog catch"}),t});var r=Qe(e.message);return r&&"session"===r.contentDisposition?this.setOfferAndGetAnswer(r,t,e).catch(function(t){var r;throw null===(r=n.userAgent.configuration)||void 0===r||r.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ut(),CALLID:e.message.callId,INVITE:e.message.toString(),ENTRY:"session: generateResponseOfferAnswer setOfferAndGetAnswer catch"}),t}):this.getOffer(t,e).catch(function(t){var r;throw null===(r=n.userAgent.configuration)||void 0===r||r.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ut(),CALLID:e.message.callId,INVITE:e.message.toString(),ENTRY:"session: generateResponseOfferAnswer getOffer catch"}),t})}},{key:"generateResponseOfferAnswerInDialog",value:function(e,t){var n=this;if(!this.dialog)throw new Error("Dialog undefined.");switch(this.dialog.signalingState){case Ke.Initial:return this.getOffer(e,t).catch(function(e){var r;throw null===(r=n.userAgent.configuration)||void 0===r||r.errorCallback({ERR_MESSAGE:e.message,CODE:"480",TIMESTAMP:ut(),CALLID:(null==t?void 0:t.message.callId)||"",INVITE:(null==t?void 0:t.message.toString())||"",ENTRY:"session: generateResponseOfferAnswerInDialog SignalingState.Initial getOffer catch"}),e});case Ke.HaveLocalOffer:return l.resolve(void 0);case Ke.HaveRemoteOffer:if(!this.dialog.offer)throw new Error("Session offer undefined in signaling state ".concat(this.dialog.signalingState,"."));return this.setOfferAndGetAnswer(this.dialog.offer,e,t).catch(function(e){var r;throw null===(r=n.userAgent.configuration)||void 0===r||r.errorCallback({ERR_MESSAGE:e.message,CODE:"480",TIMESTAMP:ut(),CALLID:(null==t?void 0:t.message.callId)||"",INVITE:(null==t?void 0:t.message.toString())||"",ENTRY:"session: generateResponseOfferAnswerInDialog setOfferAndGetAnswer catch"}),e});case Ke.Stable:return this.state!==exports.SessionState.Established?l.resolve(void 0):this.getOffer(e,t).catch(function(e){var r;throw null===(r=n.userAgent.configuration)||void 0===r||r.errorCallback({ERR_MESSAGE:e.message,CODE:"480",TIMESTAMP:ut(),CALLID:(null==t?void 0:t.message.callId)||"",INVITE:(null==t?void 0:t.message.toString())||"",ENTRY:"session: generateResponseOfferAnswerInDialog SignalingState.Stable getOffer catch"}),e});case Ke.Closed:default:throw new Error("Invalid signaling state ".concat(this.dialog.signalingState,"."))}}},{key:"getOffer",value:function(e,t){var n,r=this;try{var i=this.setupSessionDescriptionHandler(),s=e.sessionDescriptionHandlerOptions,o=e.sessionDescriptionHandlerModifiers;return i.getDescription(s,o).catch(function(e){var n;throw null===(n=r.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:e.message,CODE:"480",TIMESTAMP:ut(),CALLID:(null==t?void 0:t.message.callId)||"",INVITE:(null==t?void 0:t.message.toString())||"",ENTRY:"session: getOffer sdh.getDescription catch"}),e}).then(function(e){return Je(e)}).catch(function(e){r.logger.error("Session.getOffer: SDH getDescription rejected...");var t=e instanceof Error?e:new Error("Session.getOffer unknown error.");throw r.logger.error(t.message),t})}catch(e){this.logger.error("Session.getOffer: SDH getDescription threw...");var a=e instanceof Error?e:new Error(e);return this.logger.error(a.message),null===(n=this.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:a.message,CODE:"480",TIMESTAMP:ut(),CALLID:(null==t?void 0:t.message.callId)||"",INVITE:(null==t?void 0:t.message.toString())||"",ENTRY:"session: getOffer setupSessionDescriptionHandler catch"}),l.reject(a)}}},{key:"rollbackOffer",value:function(){var e=this;try{var t=this.setupSessionDescriptionHandler();return void 0===t.rollbackDescription?l.resolve():t.rollbackDescription().catch(function(t){e.logger.error("Session.rollbackOffer: SDH rollbackDescription rejected...");var n=t instanceof Error?t:new Error("Session.rollbackOffer unknown error.");throw e.logger.error(n.message),n})}catch(e){this.logger.error("Session.rollbackOffer: SDH rollbackDescription threw...");var n=e instanceof Error?e:new Error(e);return this.logger.error(n.message),l.reject(n)}}},{key:"setAnswer",value:function(e,t){var n,r,i,s=this;try{if(n=this.setupSessionDescriptionHandler(),r=t.sessionDescriptionHandlerOptions,i=t.sessionDescriptionHandlerModifiers,!n.hasDescription(e.contentType))return l.reject(new ae)}catch(e){this.logger.error("Session.setAnswer: SDH hasDescription threw...");var o=e instanceof Error?e:new Error(e);return this.logger.error(o.message),l.reject(o)}try{return n.setDescription(e.content,r,i).catch(function(e){s.logger.error("Session.setAnswer: SDH setDescription rejected...");var t=e instanceof Error?e:new Error("Session.setAnswer unknown error.");throw s.logger.error(t.message),t})}catch(e){this.logger.error("Session.setAnswer: SDH setDescription threw...");var a=e instanceof Error?e:new Error(e);return this.logger.error(a.message),l.reject(a)}}},{key:"setOfferAndGetAnswer",value:function(e,t,n){var r,i,s,o,a=this;try{if(i=this.setupSessionDescriptionHandler(),s=t.sessionDescriptionHandlerOptions,o=t.sessionDescriptionHandlerModifiers,!i.hasDescription(e.contentType))return l.reject(new ae)}catch(e){this.logger.error("Session.setOfferAndGetAnswer: SDH hasDescription threw...");var c=e instanceof Error?e:new Error(e);return this.logger.error(c.message),null===(r=this.userAgent.configuration)||void 0===r||r.errorCallback({ERR_MESSAGE:c.message,CODE:"480",TIMESTAMP:ut(),CALLID:(null==n?void 0:n.message.callId)||"",INVITE:(null==n?void 0:n.message.toString())||"",ENTRY:"session: setOfferAndGetAnswer setupSessionDescriptionHandler catch"}),l.reject(c)}try{return i.setDescription(e.content,s,o).catch(function(e){var t;throw null===(t=a.userAgent.configuration)||void 0===t||t.errorCallback({ERR_MESSAGE:e.message,CODE:"480",TIMESTAMP:ut(),CALLID:(null==n?void 0:n.message.callId)||"",INVITE:(null==n?void 0:n.message.toString())||"",ENTRY:"session: setOfferAndGetAnswer sdh.setDescription catch"}),e}).then(function(){return i.getDescription(s,o)}).catch(function(e){var t;throw null===(t=a.userAgent.configuration)||void 0===t||t.errorCallback({ERR_MESSAGE:e.message,CODE:"480",TIMESTAMP:ut(),CALLID:(null==n?void 0:n.message.callId)||"",INVITE:(null==n?void 0:n.message.toString())||"",ENTRY:"session: setOfferAndGetAnswer sdh.getDescription catch"}),e}).then(function(e){return Je(e)}).catch(function(e){a.logger.error("Session.setOfferAndGetAnswer: SDH setDescription or getDescription rejected...");var t=e instanceof Error?e:new Error("Session.setOfferAndGetAnswer unknown error.");throw a.logger.error(t.message),t})}catch(e){this.logger.error("Session.setOfferAndGetAnswer: SDH setDescription or getDescription threw...");var u=e instanceof Error?e:new Error(e);return this.logger.error(u.message),l.reject(u)}}},{key:"setSessionDescriptionHandler",value:function(e){if(this._sessionDescriptionHandler)throw new Error("Session description handler defined.");this._sessionDescriptionHandler=e}},{key:"setupSessionDescriptionHandler",value:function(){var e;return this._sessionDescriptionHandler||(this._sessionDescriptionHandler=this.sessionDescriptionHandlerFactory(this,this.userAgent.configuration.sessionDescriptionHandlerFactoryOptions),(null===(e=this.delegate)||void 0===e?void 0:e.onSessionDescriptionHandler)&&this.delegate.onSessionDescriptionHandler(this._sessionDescriptionHandler,!1)),this._sessionDescriptionHandler}},{key:"stateTransition",value:function(e){var t,n=this,r=function(){var t;throw new Error(T(t="Invalid state transition from ".concat(n._state," to ")).call(t,e))};switch(this._state){case exports.SessionState.Initial:e!==exports.SessionState.Establishing&&e!==exports.SessionState.Established&&e!==exports.SessionState.Terminating&&e!==exports.SessionState.Terminated&&r();break;case exports.SessionState.Establishing:e!==exports.SessionState.Established&&e!==exports.SessionState.Terminating&&e!==exports.SessionState.Terminated&&r();break;case exports.SessionState.Established:e!==exports.SessionState.Terminating&&e!==exports.SessionState.Terminated&&r();break;case exports.SessionState.Terminating:e!==exports.SessionState.Terminated&&r();break;case exports.SessionState.Terminated:r();break;default:throw new Error("Unrecognized state.")}this._state=e,this.logger.log(T(t="Session ".concat(this.id," transitioned to state ")).call(t,this._state)),this._stateEventEmitter.emit(this._state),e===exports.SessionState.Terminated&&this.dispose()}},{key:"copyRequestOptions",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{extraHeaders:t.extraHeaders?d(e=t.extraHeaders).call(e):void 0,body:t.body?{contentDisposition:t.body.contentDisposition||"render",contentType:t.body.contentType||"text/plain",content:t.body.content||""}:void 0}}},{key:"getReasonHeaderValue",value:function(e,t){var n=e,r=$e(e);return!r&&t&&(r=t),"SIP;cause="+n+';text="'+r+'"'}},{key:"referExtraHeaders",value:function(e){var t=[];return t.push("Referred-By: <"+this.userAgent.configuration.uri+">"),t.push("Contact: "+this._contact),t.push("Allow: "+["ACK","CANCEL","INVITE","MESSAGE","BYE","OPTIONS","INFO","NOTIFY","REFER"].toString()),t.push("Refer-To: "+e),t}},{key:"referToString",value:function(e){var t;if(e instanceof Ie)t=e.toString();else{var n,r,i,s;if(!e.dialog)throw new Error("Dialog undefined.");var o=e.remoteIdentity.friendlyName,a=e.dialog.remoteTarget.toString(),c=e.dialog.callId,l=e.dialog.remoteTag,u=e.dialog.localTag,d=encodeURIComponent(T(n=T(r="".concat(c,";to-tag=")).call(r,l,";from-tag=")).call(n,u));t=T(i=T(s='"'.concat(o,'" <')).call(s,a,"?Replaces=")).call(i,d,">")}return t}}])}();!function(e){e.Required="Required",e.Supported="Supported",e.Unsupported="Unsupported"}(ht||(ht={}));var ft={"100rel":!0,199:!0,answermode:!0,"early-session":!0,eventlist:!0,explicitsub:!0,"from-change":!0,"geolocation-http":!0,"geolocation-sip":!0,gin:!0,gruu:!0,histinfo:!0,ice:!0,join:!0,"multiple-refer":!0,norefersub:!0,nosub:!0,outbound:!0,path:!0,policy:!0,precondition:!0,pref:!0,privacy:!0,"recipient-list-invite":!0,"recipient-list-message":!0,"recipient-list-subscribe":!0,replaces:!0,"resource-priority":!0,"sdp-anat":!0,"sec-agree":!0,tdialog:!0,timer:!0,uui:!0};function vt(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(vt=function(){return!!e})()}function pt(e,t,n,r){var s=g(i(1&r?e.prototype:e),t,n);return 2&r&&"function"==typeof s?function(e){return s.apply(n,e)}:s}var mt=function(){function o(t,s){var a,l,u,d,h,g;e(this,o),d=this,g=[t],h=i(h=o),u=r(d,vt()?n(h,g||[],i(d).constructor):h.apply(d,g)),c(u,"incomingInviteRequest",{enumerable:!0,configurable:!0,writable:!0,value:s}),c(u,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(u,"_id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(u,"disposed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(u,"expiresTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(u,"isCanceled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(u,"rel100",{enumerable:!0,configurable:!0,writable:!0,value:"none"}),c(u,"rseq",{enumerable:!0,configurable:!0,writable:!0,value:Math.floor(1e4*Math.random())}),c(u,"userNoAnswerTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(u,"waitingForPrack",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(u,"waitingForPrackPromise",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(u,"waitingForPrackResolve",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(u,"waitingForPrackReject",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),u.logger=t.getLogger("sip.Invitation");var p=u.incomingInviteRequest.message,m=p.getHeader("require");m&&f(a=m.toLowerCase()).call(a,"100rel")&&(u.rel100="required");var b=p.getHeader("supported");if(b&&f(l=b.toLowerCase()).call(l,"100rel")&&(u.rel100="supported"),p.toTag=s.toTag,"string"!=typeof p.toTag)throw new TypeError("toTag should have been a string.");if(u.userNoAnswerTimer=v(function(){var e;null===(e=u.userAgent.configuration)||void 0===e||e.errorCallback({ERR_MESSAGE:"NOT ERROR",CODE:"480",TIMESTAMP:ut(),CALLID:u.incomingInviteRequest.message.callId,INVITE:u.incomingInviteRequest.message.toString(),ENTRY:"invitation: constructor userNoAnswerTimer ".concat(u.userAgent.configuration.noAnswerTimeout?1e3*u.userAgent.configuration.noAnswerTimeout:6e4)}),s.reject({statusCode:480}),u.stateTransition(exports.SessionState.Terminated)},u.userAgent.configuration.noAnswerTimeout?1e3*u.userAgent.configuration.noAnswerTimeout:6e4),p.hasHeader("expires")){var w=1e3*Number(p.getHeader("expires")||0);u.expiresTimer=v(function(){u.state===exports.SessionState.Initial&&(s.reject({statusCode:487}),u.stateTransition(exports.SessionState.Terminated))},w)}var y=u.request.getHeader("P-Asserted-Identity");y&&(u._assertedIdentity=De.nameAddrHeaderParse(y)),u._contact=u.userAgent.contact.toString();var S=p.parseHeader("Content-Disposition");return S&&"render"===S.type&&(u._renderbody=p.body,u._rendertype=p.getHeader("Content-Type")),u._id=p.callId+p.fromTag,u.userAgent._sessions[u._id]=u,u}return s(o,gt),t(o,[{key:"dispose",value:function(){var e=this;if(this.disposed)return l.resolve();switch(this.disposed=!0,this.expiresTimer&&(clearTimeout(this.expiresTimer),this.expiresTimer=void 0),this.userNoAnswerTimer&&(clearTimeout(this.userNoAnswerTimer),this.userNoAnswerTimer=void 0),this.prackNeverArrived(),this.state){case exports.SessionState.Initial:case exports.SessionState.Establishing:return this.reject().then(function(){return pt(o,"dispose",e,3)([])});case exports.SessionState.Established:case exports.SessionState.Terminating:case exports.SessionState.Terminated:return pt(o,"dispose",this,3)([]);default:throw new Error("Unknown state.")}}},{key:"autoSendAnInitialProvisionalResponse",get:function(){return"required"!==this.rel100&&this.userAgent.configuration.sendInitialProvisionalResponse}},{key:"body",get:function(){return this.incomingInviteRequest.message.body}},{key:"localIdentity",get:function(){return this.request.to}},{key:"remoteIdentity",get:function(){return this.request.from}},{key:"request",get:function(){return this.incomingInviteRequest.message}},{key:"accept",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("Invitation.accept"),this.state!==exports.SessionState.Initial){var n=new Error("Invalid session state ".concat(this.state));return this.logger.error(n.message),l.reject(n)}return t.sessionDescriptionHandlerModifiers&&(this.sessionDescriptionHandlerModifiers=t.sessionDescriptionHandlerModifiers),t.sessionDescriptionHandlerOptions&&(this.sessionDescriptionHandlerOptions=t.sessionDescriptionHandlerOptions),this.stateTransition(exports.SessionState.Establishing),this.sendAccept(t).then(function(n){n.message;var r=n.session;r.delegate={onAck:function(n){var r=e.onAckRequest(n);return t.onAck&&t.onAck(n),r},onAckTimeout:function(){e.onAckTimeout(),t.onAckTimeout&&t.onAckTimeout()},onBye:function(t){return e.onByeRequest(t)},onInfo:function(t){return e.onInfoRequest(t)},onInvite:function(t){return e.onInviteRequest(t)},onMessage:function(t){return e.onMessageRequest(t)},onNotify:function(t){return e.onNotifyRequest(t)},onPrack:function(t){return e.onPrackRequest(t)},onRefer:function(t){return e.onReferRequest(t)}},e._dialog=r,e.stateTransition(exports.SessionState.Established),e._replacee&&e._replacee._bye()}).catch(function(t){var n;return null===(n=e.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ut(),CALLID:e.incomingInviteRequest.message.callId,INVITE:e.incomingInviteRequest.message.toString(),ENTRY:"invitation: accept sendAccept catch"}),e.handleResponseError(t)})}},{key:"progress",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("Invitation.progress"),this.state!==exports.SessionState.Initial){var n=new Error("Invalid session state ".concat(this.state));return this.logger.error(n.message),l.reject(n)}var r=t.statusCode||180;if(r<100||r>199)throw new TypeError("Invalid statusCode: "+r);return t.sessionDescriptionHandlerModifiers&&(this.sessionDescriptionHandlerModifiers=t.sessionDescriptionHandlerModifiers),t.sessionDescriptionHandlerOptions&&(this.sessionDescriptionHandlerOptions=t.sessionDescriptionHandlerOptions),this.waitingForPrack?(this.logger.warn("Unexpected call for progress while waiting for prack, ignoring"),l.resolve()):100===t.statusCode?this.sendProgressTrying().then(function(){}).catch(function(t){var n;return null===(n=e.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ut(),CALLID:e.incomingInviteRequest.message.callId,INVITE:e.incomingInviteRequest.message.toString(),ENTRY:"invitation: progress sendProgressTrying catch"}),e.handleResponseError(t)}):"required"===this.rel100||"supported"===this.rel100&&t.rel100||"supported"===this.rel100&&this.userAgent.configuration.sipExtension100rel===ht.Required?this.sendProgressReliableWaitForPrack(t).then(function(){}).catch(function(t){var n;return null===(n=e.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ut(),CALLID:e.incomingInviteRequest.message.callId,INVITE:e.incomingInviteRequest.message.toString(),ENTRY:"invitation: progress sendProgressReliableWaitForPrack catch"}),e.handleResponseError(t)}):this.sendProgress(t).then(function(){}).catch(function(t){var n;return null===(n=e.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ut(),CALLID:e.incomingInviteRequest.message.callId,INVITE:e.incomingInviteRequest.message.toString(),ENTRY:"invitation: progress rel100 sendProgress catch"}),e.handleResponseError(t)})}},{key:"reject",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("Invitation.reject"),this.state!==exports.SessionState.Initial&&this.state!==exports.SessionState.Establishing){var t=new Error("Invalid session state ".concat(this.state));return this.logger.error(t.message),l.reject(t)}var n=e.statusCode||480,r=e.reasonPhrase?e.reasonPhrase:$e(n),i=e.extraHeaders||[];if(n<300||n>699)throw new TypeError("Invalid statusCode: "+n);var s=e.body?Je(e.body):void 0;return n<400?this.incomingInviteRequest.redirect([],{statusCode:n,reasonPhrase:r,extraHeaders:i,body:s}):this.incomingInviteRequest.reject({statusCode:n,reasonPhrase:r,extraHeaders:i,body:s}),this.stateTransition(exports.SessionState.Terminated),l.resolve()}},{key:"_onCancel",value:function(e){if(this.logger.log("Invitation._onCancel"),this.state===exports.SessionState.Initial||this.state===exports.SessionState.Establishing){if(this.delegate&&this.delegate.onCancel){var t=new be(e);this.delegate.onCancel(t)}this.isCanceled=!0,this.incomingInviteRequest.reject({statusCode:487}),this.stateTransition(exports.SessionState.Terminated)}else this.logger.error("CANCEL received while in state ".concat(this.state,", dropping request"))}},{key:"handlePrackOfferAnswer",value:function(e){if(!this.dialog)throw new Error("Dialog undefined.");var t=Qe(e.message);if(!t||"session"!==t.contentDisposition)return l.resolve(void 0);var n={sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions,sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers};switch(this.dialog.signalingState){case Ke.Initial:throw new Error("Invalid signaling state ".concat(this.dialog.signalingState,"."));case Ke.Stable:return this.setAnswer(t,n).then(function(){});case Ke.HaveLocalOffer:throw new Error("Invalid signaling state ".concat(this.dialog.signalingState,"."));case Ke.HaveRemoteOffer:return this.setOfferAndGetAnswer(t,n);case Ke.Closed:default:throw new Error("Invalid signaling state ".concat(this.dialog.signalingState,"."))}}},{key:"handleResponseError",value:function(e){var t=480;if(e instanceof Error?this.logger.error(e.message):this.logger.error(e),e instanceof ae?(this.logger.error("A session description handler occurred while sending response (content type unsupported"),t=415):e instanceof de?this.logger.error("A session description handler occurred while sending response"):e instanceof ge?this.logger.error("Session ended before response could be formulated and sent (while waiting for PRACK)"):e instanceof st&&this.logger.error("Session changed state before response could be formulated and sent"),this.state===exports.SessionState.Initial||this.state===exports.SessionState.Establishing)try{this.incomingInviteRequest.reject({statusCode:t}),this.stateTransition(exports.SessionState.Terminated)}catch(e){throw this.logger.error("An error occurred attempting to reject the request while handling another error"),e}if(!this.isCanceled)throw e;this.logger.warn("An error occurred while attempting to formulate and send a response to an incoming INVITE. However a CANCEL was received and processed while doing so which can (and often does) result in errors occurring as the session terminates in the meantime. Said error is being ignored.")}},{key:"onAckTimeout",value:function(){if(this.logger.log("Invitation.onAckTimeout"),!this.dialog)throw new Error("Dialog undefined.");this.logger.log("No ACK received for an extended period of time, terminating session"),this.dialog.bye(),this.stateTransition(exports.SessionState.Terminated)}},{key:"sendAccept",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n={sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions,sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers},r=t.extraHeaders||[];return this.waitingForPrack?this.waitForArrivalOfPrack().then(function(){return clearTimeout(e.userNoAnswerTimer)}).then(function(){return e.generateResponseOfferAnswer(e.incomingInviteRequest,n)}).catch(function(t){var n;throw null===(n=e.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ut(),CALLID:e.incomingInviteRequest.message.callId,INVITE:e.incomingInviteRequest.message.toString(),ENTRY:"invitation: sendAccept waitForArrivalOfPrack generateResponseOfferAnswer catch"}),t}).then(function(t){return e.incomingInviteRequest.accept({statusCode:200,body:t,extraHeaders:r})}):(clearTimeout(this.userNoAnswerTimer),this.generateResponseOfferAnswer(this.incomingInviteRequest,n).catch(function(t){var n;throw null===(n=e.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ut(),CALLID:e.incomingInviteRequest.message.callId,INVITE:e.incomingInviteRequest.message.toString(),ENTRY:"invitation: sendAccept generateResponseOfferAnswer catch"}),t}).then(function(t){return e.incomingInviteRequest.accept({statusCode:200,body:t,extraHeaders:r})}))}},{key:"sendProgress",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.statusCode||180,r=t.reasonPhrase,i=d(e=t.extraHeaders||[]).call(e),s=t.body?Je(t.body):void 0;if(183===n&&!s)return this.sendProgressWithSDP(t);try{var o=this.incomingInviteRequest.progress({statusCode:n,reasonPhrase:r,extraHeaders:i,body:s});return this._dialog=o.session,l.resolve(o)}catch(e){return l.reject(e)}}},{key:"sendProgressWithSDP",value:function(){var e,t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r={sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions,sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers},i=n.statusCode||183,s=n.reasonPhrase,o=d(e=n.extraHeaders||[]).call(e);return this.generateResponseOfferAnswer(this.incomingInviteRequest,r).then(function(e){return t.incomingInviteRequest.progress({statusCode:i,reasonPhrase:s,extraHeaders:o,body:e})}).then(function(e){return t._dialog=e.session,e})}},{key:"sendProgressReliable",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return t.extraHeaders=d(e=t.extraHeaders||[]).call(e),t.extraHeaders.push("Require: 100rel"),t.extraHeaders.push("RSeq: "+Math.floor(1e4*Math.random())),this.sendProgressWithSDP(t)}},{key:"sendProgressReliableWaitForPrack",value:function(){var e,t,n=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i={sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions,sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers},s=r.statusCode||183,o=r.reasonPhrase,a=d(e=r.extraHeaders||[]).call(e);return a.push("Require: 100rel"),a.push("RSeq: "+this.rseq++),new l(function(e,r){n.waitingForPrack=!0,n.generateResponseOfferAnswer(n.incomingInviteRequest,i).then(function(e){return t=e,n.incomingInviteRequest.progress({statusCode:s,reasonPhrase:o,extraHeaders:a,body:t})}).then(function(i){var c,l;n._dialog=i.session,i.session.delegate={onPrack:function(t){c=t,clearTimeout(u),clearTimeout(g),n.waitingForPrack&&(n.waitingForPrack=!1,n.handlePrackOfferAnswer(c).then(function(t){try{l=c.accept({statusCode:200,body:t}),n.prackArrived(),e({prackRequest:c,prackResponse:l,progressResponse:i})}catch(e){r(e)}}).catch(function(e){return r(e)}))}};var u=v(function(){n.waitingForPrack&&(n.waitingForPrack=!1,n.logger.warn("No PRACK received, rejecting INVITE."),clearTimeout(g),n.reject({statusCode:504}).then(function(){return r(new ge)}).catch(function(e){return r(e)}))},64*nt.T1),d=function(){try{n.incomingInviteRequest.progress({statusCode:s,reasonPhrase:o,extraHeaders:a,body:t})}catch(e){return n.waitingForPrack=!1,void r(e)}g=v(d,h*=2)},h=nt.T1,g=v(d,h)}).catch(function(e){n.waitingForPrack=!1,r(e)})})}},{key:"sendProgressTrying",value:function(){try{var e=this.incomingInviteRequest.trying();return l.resolve(e)}catch(e){return l.reject(e)}}},{key:"waitForArrivalOfPrack",value:function(){var e=this;if(this.waitingForPrackPromise)throw new Error("Already waiting for PRACK");return this.waitingForPrackPromise=new l(function(t,n){e.waitingForPrackResolve=t,e.waitingForPrackReject=n}),this.waitingForPrackPromise}},{key:"prackArrived",value:function(){this.waitingForPrackResolve&&this.waitingForPrackResolve(),this.waitingForPrackPromise=void 0,this.waitingForPrackResolve=void 0,this.waitingForPrackReject=void 0}},{key:"prackNeverArrived",value:function(){this.waitingForPrackReject&&this.waitingForPrackReject(new ge),this.waitingForPrackPromise=void 0,this.waitingForPrackResolve=void 0,this.waitingForPrackReject=void 0}}])}();function bt(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(bt=function(){return!!e})()}function wt(e,t,n,r){var s=g(i(1&r?e.prototype:e),t,n);return 2&r&&"function"==typeof s?function(e){return s.apply(n,e)}:s}var yt,St,kt=function(){function o(t,s){var a,l,u,h,g,f=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};e(this,o),u=this,g=[t,f],h=i(h=o),l=r(u,bt()?n(h,g||[],i(u).constructor):h.apply(u,g)),c(l,"_referred",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"_id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"disposed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(l,"earlyMedia",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(l,"earlyMediaDialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"earlyMediaSessionDescriptionHandlers",{enumerable:!0,configurable:!0,writable:!0,value:new _}),c(l,"fromTag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"isCanceled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(l,"inviteWithoutSdp",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(l,"outgoingInviteRequest",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"outgoingRequestMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),l.logger=t.getLogger("sip.Inviter"),l.earlyMedia=void 0!==f.earlyMedia?f.earlyMedia:l.earlyMedia,l.fromTag=Me(),l.inviteWithoutSdp=void 0!==f.inviteWithoutSdp?f.inviteWithoutSdp:l.inviteWithoutSdp;var v=H({},f);v.params=H({},f.params);var p=f.anonymous||!1,m=t.contact.toString({anonymous:p,outbound:p?!t.contact.tempGruu:!t.contact.pubGruu});p&&t.configuration.uri&&(v.params.fromDisplayName="Anonymous",v.params.fromUri="sip:anonymous@anonymous.invalid");var b=t.userAgentCore.configuration.aor;if(v.params.fromUri&&(b="string"==typeof v.params.fromUri?De.URIParse(v.params.fromUri):v.params.fromUri),!b)throw new TypeError("Invalid from URI: "+v.params.fromUri);var w=s;if(v.params.toUri&&(w="string"==typeof v.params.toUri?De.URIParse(v.params.toUri):v.params.toUri),!w)throw new TypeError("Invalid to URI: "+v.params.toUri);var y=H({},v.params);y.fromTag=l.fromTag;var S=d(a=v.extraHeaders||[]).call(a);p&&t.configuration.uri&&(S.push("P-Preferred-Identity: "+t.configuration.uri.toString()),S.push("Privacy: id")),S.push("Contact: "+m),S.push("Allow: "+["ACK","CANCEL","INVITE","MESSAGE","BYE","OPTIONS","INFO","NOTIFY","REFER"].toString()),t.configuration.sipExtension100rel===ht.Required&&S.push("Require: 100rel"),t.configuration.sipExtensionReplaces===ht.Required&&S.push("Require: replaces"),v.extraHeaders=S;return l.outgoingRequestMessage=t.userAgentCore.makeOutgoingRequestMessage(it.INVITE,s,b,w,y,S,undefined),l._contact=m,l._referralInviterOptions=v,l._renderbody=f.renderbody,l._rendertype=f.rendertype,f.sessionDescriptionHandlerModifiers&&(l.sessionDescriptionHandlerModifiers=f.sessionDescriptionHandlerModifiers),f.sessionDescriptionHandlerOptions&&(l.sessionDescriptionHandlerOptions=f.sessionDescriptionHandlerOptions),f.sessionDescriptionHandlerModifiersReInvite&&(l.sessionDescriptionHandlerModifiersReInvite=f.sessionDescriptionHandlerModifiersReInvite),f.sessionDescriptionHandlerOptionsReInvite&&(l.sessionDescriptionHandlerOptionsReInvite=f.sessionDescriptionHandlerOptionsReInvite),l._id=l.outgoingRequestMessage.callId+l.fromTag,l.userAgent._sessions[l._id]=l,l}return s(o,gt),t(o,[{key:"dispose",value:function(){var e=this;if(this.disposed)return l.resolve();switch(this.disposed=!0,this.disposeEarlyMedia(),this.state){case exports.SessionState.Initial:case exports.SessionState.Establishing:return this.cancel().then(function(){return wt(o,"dispose",e,3)([])});case exports.SessionState.Established:case exports.SessionState.Terminating:case exports.SessionState.Terminated:return wt(o,"dispose",this,3)([]);default:throw new Error("Unknown state.")}}},{key:"body",get:function(){return this.outgoingRequestMessage.body}},{key:"localIdentity",get:function(){return this.outgoingRequestMessage.from}},{key:"remoteIdentity",get:function(){return this.outgoingRequestMessage.to}},{key:"request",get:function(){return this.outgoingRequestMessage}},{key:"cancel",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("Inviter.cancel"),this.state!==exports.SessionState.Initial&&this.state!==exports.SessionState.Establishing){var n=new Error("Invalid session state ".concat(this.state));return this.logger.error(n.message),l.reject(n)}(this.isCanceled=!0,this.stateTransition(exports.SessionState.Terminating),this.outgoingInviteRequest)?(t.statusCode&&t.reasonPhrase&&(e=function(e,t){if(e&&e<200||e>699)throw new TypeError("Invalid statusCode: "+e);if(e)return"SIP;cause="+e+';text="'+($e(e)||t)+'"'}(t.statusCode,t.reasonPhrase)),this.outgoingInviteRequest.cancel(e,t)):(this.logger.warn("Canceled session before INVITE was sent"),this.stateTransition(exports.SessionState.Terminated));return l.resolve()}},{key:"invite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("Inviter.invite"),this.state!==exports.SessionState.Initial)return wt(o,"invite",this,3)([t]);if(t.sessionDescriptionHandlerModifiers&&(this.sessionDescriptionHandlerModifiers=t.sessionDescriptionHandlerModifiers),t.sessionDescriptionHandlerOptions&&(this.sessionDescriptionHandlerOptions=t.sessionDescriptionHandlerOptions),t.withoutSdp||this.inviteWithoutSdp)return this._renderbody&&this._rendertype&&(this.outgoingRequestMessage.body={contentType:this._rendertype,body:this._renderbody}),this.stateTransition(exports.SessionState.Establishing),l.resolve(this.sendInvite(t));var n={sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers,sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions};return this.getOffer(n).then(function(n){return e.outgoingRequestMessage.body={body:n.content,contentType:n.contentType},e.stateTransition(exports.SessionState.Establishing),e.sendInvite(t)}).catch(function(t){throw e.logger.log(t.message),e.state!==exports.SessionState.Terminated&&e.stateTransition(exports.SessionState.Terminated),t})}},{key:"sendInvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.outgoingInviteRequest=this.userAgent.userAgentCore.invite(this.outgoingRequestMessage,{onAccept:function(n){return e.dialog?(e.logger.log("Additional confirmed dialog, sending ACK and BYE"),void e.ackAndBye(n)):e.isCanceled?(e.logger.log("Canceled session accepted, sending ACK and BYE"),e.ackAndBye(n),void e.stateTransition(exports.SessionState.Terminated)):(e.notifyReferer(n),void e.onAccept(n).then(function(){e.disposeEarlyMedia()}).catch(function(){e.disposeEarlyMedia()}).then(function(){t.requestDelegate&&t.requestDelegate.onAccept&&t.requestDelegate.onAccept(n)}))},onProgress:function(n){e.isCanceled||(e.notifyReferer(n),e.onProgress(n).catch(function(){e.disposeEarlyMedia()}).then(function(){t.requestDelegate&&t.requestDelegate.onProgress&&t.requestDelegate.onProgress(n)}))},onRedirect:function(n){e.notifyReferer(n),e.onRedirect(n),t.requestDelegate&&t.requestDelegate.onRedirect&&t.requestDelegate.onRedirect(n)},onReject:function(n){e.notifyReferer(n),e.onReject(n),t.requestDelegate&&t.requestDelegate.onReject&&t.requestDelegate.onReject(n)},onTrying:function(n){e.notifyReferer(n),e.onTrying(n),t.requestDelegate&&t.requestDelegate.onTrying&&t.requestDelegate.onTrying(n)}}),this.outgoingInviteRequest}},{key:"disposeEarlyMedia",value:function(){var e;u(e=this.earlyMediaSessionDescriptionHandlers).call(e,function(e){e.close()}),this.earlyMediaSessionDescriptionHandlers.clear()}},{key:"notifyReferer",value:function(e){var t,n,r=this;if(this._referred){if(!(this._referred instanceof gt))throw new Error("Referred session not instance of session");if(this._referred.dialog){if(!e.message.statusCode)throw new Error("Status code undefined.");if(!e.message.reasonPhrase)throw new Error("Reason phrase undefined.");var i=e.message.statusCode,s=e.message.reasonPhrase,o=S(t=T(n="SIP/2.0 ".concat(i," ")).call(n,s)).call(t);this._referred.dialog.notify(void 0,{extraHeaders:["Event: refer","Subscription-State: terminated"],body:{contentDisposition:"render",contentType:"message/sipfrag",content:o}}).delegate={onReject:function(){r._referred=void 0}}}}}},{key:"onAccept",value:function(e){var t=this;if(this.logger.log("Inviter.onAccept"),this.state!==exports.SessionState.Establishing)return this.logger.error("Accept received while in state ".concat(this.state,", dropping response")),l.reject(new Error("Invalid session state ".concat(this.state)));var n=e.message,r=e.session;switch(n.hasHeader("P-Asserted-Identity")&&(this._assertedIdentity=De.nameAddrHeaderParse(n.getHeader("P-Asserted-Identity"))),r.delegate={onAck:function(e){return t.onAckRequest(e)},onBye:function(e){return t.onByeRequest(e)},onInfo:function(e){return t.onInfoRequest(e)},onInvite:function(e){return t.onInviteRequest(e)},onMessage:function(e){return t.onMessageRequest(e)},onNotify:function(e){return t.onNotifyRequest(e)},onPrack:function(e){return t.onPrackRequest(e)},onRefer:function(e){return t.onReferRequest(e)}},this._dialog=r,r.signalingState){case Ke.Initial:case Ke.HaveLocalOffer:return this.logger.error("Received 2xx response to INVITE without a session description"),this.ackAndBye(e,400,"Missing session description"),this.stateTransition(exports.SessionState.Terminated),l.reject(new Error("Bad Media Description"));case Ke.HaveRemoteOffer:if(!this._dialog.offer)throw new Error("Session offer undefined in signaling state ".concat(this._dialog.signalingState,"."));var i={sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers,sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions};return this.setOfferAndGetAnswer(this._dialog.offer,i).then(function(n){e.ack({body:n}),t.stateTransition(exports.SessionState.Established)}).catch(function(n){throw t.ackAndBye(e,488,"Invalid session description"),t.stateTransition(exports.SessionState.Terminated),n});case Ke.Stable:if(this.earlyMediaSessionDescriptionHandlers.size>0){var s=this.earlyMediaSessionDescriptionHandlers.get(r.id);if(!s)throw new Error("Session description handler undefined.");return this.setSessionDescriptionHandler(s),this.earlyMediaSessionDescriptionHandlers.delete(r.id),e.ack(),this.stateTransition(exports.SessionState.Established),l.resolve()}if(this.earlyMediaDialog){if(this.earlyMediaDialog!==r){if(this.earlyMedia){this.logger.error("You have set the 'earlyMedia' option to 'true' which requires that your INVITE requests do not fork and yet this INVITE request did in fact fork. Consequentially and not surprisingly the end point which accepted the INVITE (confirmed dialog) does not match the end point with which early media has been setup (early dialog) and thus this session is unable to proceed. In accordance with the SIP specifications, the SIP servers your end point is connected to determine if an INVITE forks and the forking behavior of those servers cannot be controlled by this library. If you wish to use early media with this library you must configure those servers accordingly. Alternatively you may set the 'earlyMedia' to 'false' which will allow this library to function with any INVITE requests which do fork.")}var o=new Error("Early media dialog does not equal confirmed dialog, terminating session");return this.logger.error(o.message),this.ackAndBye(e,488,"Not Acceptable Here"),this.stateTransition(exports.SessionState.Terminated),l.reject(o)}return e.ack(),this.stateTransition(exports.SessionState.Established),l.resolve()}var a=r.answer;if(!a)throw new Error("Answer is undefined.");var c={sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers,sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions};return this.setAnswer(a,c).then(function(){var n;t._renderbody&&t._rendertype&&(n={body:{contentDisposition:"render",contentType:t._rendertype,content:t._renderbody}}),e.ack(n),t.stateTransition(exports.SessionState.Established)}).catch(function(n){throw t.logger.error(n.message),t.ackAndBye(e,488,"Not Acceptable Here"),t.stateTransition(exports.SessionState.Terminated),n});case Ke.Closed:return l.reject(new Error("Terminated."));default:throw new Error("Unknown session signaling state.")}}},{key:"onProgress",value:function(e){var t,n=this;if(this.logger.log("Inviter.onProgress"),this.state!==exports.SessionState.Establishing)return this.logger.error("Progress received while in state ".concat(this.state,", dropping response")),l.reject(new Error("Invalid session state ".concat(this.state)));if(!this.outgoingInviteRequest)throw new Error("Outgoing INVITE request undefined.");var r=e.message,i=e.session;r.hasHeader("P-Asserted-Identity")&&(this._assertedIdentity=De.nameAddrHeaderParse(r.getHeader("P-Asserted-Identity")));var s=r.getHeader("require"),o=r.getHeader("rseq"),a=!!(s&&f(s).call(s,"100rel")&&o?Number(o):void 0),c=[];switch(a&&c.push("RAck: "+r.getHeader("rseq")+" "+r.getHeader("cseq")),i.signalingState){case Ke.Initial:return a&&(this.logger.warn("First reliable provisional response received MUST contain an offer when INVITE does not contain an offer."),e.prack({extraHeaders:c})),l.resolve();case Ke.HaveLocalOffer:return a&&e.prack({extraHeaders:c}),l.resolve();case Ke.HaveRemoteOffer:if(!a)return this.logger.warn("Non-reliable provisional response MUST NOT contain an initial offer, discarding response."),l.resolve();var u=this.sessionDescriptionHandlerFactory(this,this.userAgent.configuration.sessionDescriptionHandlerFactoryOptions||{});return(null===(t=this.delegate)||void 0===t?void 0:t.onSessionDescriptionHandler)&&this.delegate.onSessionDescriptionHandler(u,!0),this.earlyMediaSessionDescriptionHandlers.set(i.id,u),u.setDescription(r.body,this.sessionDescriptionHandlerOptions,this.sessionDescriptionHandlerModifiers).then(function(){return u.getDescription(n.sessionDescriptionHandlerOptions,n.sessionDescriptionHandlerModifiers)}).then(function(t){var n={contentDisposition:"session",contentType:t.contentType,content:t.body};e.prack({extraHeaders:c,body:n})}).catch(function(e){throw n.stateTransition(exports.SessionState.Terminated),e});case Ke.Stable:if(a&&e.prack({extraHeaders:c}),this.earlyMedia&&!this.earlyMediaDialog){this.earlyMediaDialog=i;var d=i.answer;if(!d)throw new Error("Answer is undefined.");var h={sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers,sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions};return this.setAnswer(d,h).catch(function(e){throw n.stateTransition(exports.SessionState.Terminated),e})}return l.resolve();case Ke.Closed:return l.reject(new Error("Terminated."));default:throw new Error("Unknown session signaling state.")}}},{key:"onRedirect",value:function(e){this.logger.log("Inviter.onRedirect"),this.state===exports.SessionState.Establishing||this.state===exports.SessionState.Terminating?this.stateTransition(exports.SessionState.Terminated):this.logger.error("Redirect received while in state ".concat(this.state,", dropping response"))}},{key:"onReject",value:function(e){this.logger.log("Inviter.onReject"),this.state===exports.SessionState.Establishing||this.state===exports.SessionState.Terminating?this.stateTransition(exports.SessionState.Terminated):this.logger.error("Reject received while in state ".concat(this.state,", dropping response"))}},{key:"onTrying",value:function(e){this.logger.log("Inviter.onTrying"),this.state===exports.SessionState.Establishing||this.logger.error("Trying received while in state ".concat(this.state,", dropping response"))}}])}(),Rt=function(){return t(function t(n,r,i){var s,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"text/plain",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};e(this,t),c(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"userAgent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.logger=n.getLogger("sip.Messager"),a.params=a.params||{};var l=n.userAgentCore.configuration.aor;if(a.params.fromUri&&(l="string"==typeof a.params.fromUri?De.URIParse(a.params.fromUri):a.params.fromUri),!l)throw new TypeError("Invalid from URI: "+a.params.fromUri);var u=r;if(a.params.toUri&&(u="string"==typeof a.params.toUri?De.URIParse(a.params.toUri):a.params.toUri),!u)throw new TypeError("Invalid to URI: "+a.params.toUri);var h=a.params?H({},a.params):{},g=d(s=a.extraHeaders||[]).call(s),f={contentDisposition:"render",contentType:o,content:i};this.request=n.userAgentCore.makeOutgoingRequestMessage(it.MESSAGE,r,l,u,h,g,f),this.userAgent=n},[{key:"message",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.userAgent.userAgentCore.request(this.request,e.requestDelegate),l.resolve()}}])}();!function(e){e.Initial="Initial",e.Published="Published",e.Unpublished="Unpublished",e.Terminated="Terminated"}(yt||(yt={})),function(e){e.Initial="Initial",e.Registered="Registered",e.Unregistered="Unregistered",e.Terminated="Terminated"}(St||(St={}));var Tt,It,Et,Ct,xt=function(){function n(t){var r,i,s,o=this,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,n),c(this,"disposed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"expires",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"refreshFrequency",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"userAgent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"registrationExpiredTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"registrationTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_contacts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),c(this,"_retryAfter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:St.Initial}),c(this,"_stateEventEmitter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_waiting",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(this,"_waitingEventEmitter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._stateEventEmitter=new we,this._waitingEventEmitter=new we,this.userAgent=t;var l=t.configuration.uri.clone();if(l.user=void 0,this.options=H(H(H({},n.defaultOptions()),{registrar:l}),n.stripUndefinedProperties(a)),this.options.extraContactHeaderParams=d(r=this.options.extraContactHeaderParams||[]).call(r),this.options.extraHeaders=d(i=this.options.extraHeaders||[]).call(i),!this.options.registrar)throw new Error("Registrar undefined.");if(this.options.registrar=this.options.registrar.clone(),this.options.regId&&!this.options.instanceId?this.options.instanceId=this.userAgent.instanceId:!this.options.regId&&this.options.instanceId&&(this.options.regId=1),this.options.instanceId&&-1===De.parse(this.options.instanceId,"uuid"))throw new Error("Invalid instanceId.");if(this.options.regId&&this.options.regId<0)throw new Error("Invalid regId.");var h,g=this.options.registrar,f=this.options.params&&this.options.params.fromUri||t.userAgentCore.configuration.aor,v=this.options.params&&this.options.params.toUri||t.configuration.uri,p=this.options.params||{},m=d(s=a.extraHeaders||[]).call(s);if(this.request=t.userAgentCore.makeOutgoingRequestMessage(it.REGISTER,g,f,v,p,m,void 0),this.expires=this.options.expires||n.defaultExpires,this.expires<0)throw new Error("Invalid expires.");if(this.refreshFrequency=this.options.refreshFrequency||n.defaultRefreshFrequency,this.refreshFrequency<50||this.refreshFrequency>99)throw new Error("Invalid refresh frequency. The value represents a percentage of the expiration time and should be between 50 and 99.");(this.logger=t.getLogger("sip.Registerer"),this.options.logConfiguration)&&(this.logger.log("Configuration:"),u(h=E(this.options)).call(h,function(e){var t=o.options[e];if("registrar"===e)o.logger.log("· "+e+": "+t);else o.logger.log("· "+e+": "+I(t))}));this.id=this.request.callId+this.request.from.parameters.tag,this.userAgent._registerers[this.id]=this}return t(n,[{key:"contacts",get:function(){var e;return d(e=this._contacts).call(e)}},{key:"retryAfter",get:function(){return this._retryAfter}},{key:"state",get:function(){return this._state}},{key:"stateChange",get:function(){return this._stateEventEmitter}},{key:"dispose",value:function(){var e,t=this;return this.disposed?l.resolve():(this.disposed=!0,this.logger.log(T(e="Registerer ".concat(this.id," in state ")).call(e,this.state," is being disposed")),delete this.userAgent._registerers[this.id],new l(function(e){var n=function(){if(!t.waiting&&t._state===St.Registered)return t.stateChange.addListener(function(){t.terminated(),e()},{once:!0}),void t.unregister();t.terminated(),e()};t.waiting?t.waitingChange.addListener(function(){n()},{once:!0}):n()}))}},{key:"register",value:function(){var e,t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.state===St.Terminated)throw this.stateError(),new Error("Registerer terminated. Unable to register.");if(this.disposed)throw this.stateError(),new Error("Registerer disposed. Unable to register.");if(this.waiting){this.waitingWarning();var r=new le("REGISTER request already in progress, waiting for final response");return l.reject(r)}n.requestOptions&&(this.options=H(H({},this.options),n.requestOptions));var i=d(e=this.options.extraHeaders||[]).call(e);i.push("Contact: "+this.generateContactHeader(this.expires)),i.push("Allow: "+["ACK","CANCEL","INVITE","MESSAGE","BYE","OPTIONS","INFO","NOTIFY","REFER"].toString()),this.request.cseq++,this.request.setHeader("cseq",this.request.cseq+" REGISTER"),this.request.extraHeaders=i,this.waitingToggle(!0);var s=this.userAgent.userAgentCore.register(this.request,{onAccept:function(e){var r;e.message.hasHeader("expires")&&(r=Number(e.message.getHeader("expires"))),t._contacts=e.message.getHeaders("contact");var i,s=t._contacts.length;if(!s)return t.logger.error("No Contact header in response to REGISTER, dropping response."),void t.unregistered();for(;s--;){if(!(i=e.message.parseHeader("contact",s)))throw new Error("Contact undefined");if(t.userAgent.contact.pubGruu&&Ee(i.uri,t.userAgent.contact.pubGruu)){r=Number(i.getParam("expires"));break}if(""===t.userAgent.configuration.contactName){if(i.uri.user===t.userAgent.contact.uri.user){r=Number(i.getParam("expires"));break}}else if(Ee(i.uri,t.userAgent.contact.uri)){r=Number(i.getParam("expires"));break}i=void 0}if(void 0===i)return t.logger.error("No Contact header pointing to us, dropping response"),t.unregistered(),void t.waitingToggle(!1);if(void 0===r)return t.logger.error("Contact pointing to us is missing expires parameter, dropping response"),t.unregistered(),void t.waitingToggle(!1);if(i.hasParam("temp-gruu")){var o=i.getParam("temp-gruu");o&&(t.userAgent.contact.tempGruu=De.URIParse(o.replace(/"/g,"")))}if(i.hasParam("pub-gruu")){var a=i.getParam("pub-gruu");a&&(t.userAgent.contact.pubGruu=De.URIParse(a.replace(/"/g,"")))}t.registered(r),n.requestDelegate&&n.requestDelegate.onAccept&&n.requestDelegate.onAccept(e),t.waitingToggle(!1)},onProgress:function(e){n.requestDelegate&&n.requestDelegate.onProgress&&n.requestDelegate.onProgress(e)},onRedirect:function(e){t.logger.error("Redirect received. Not supported."),t.unregistered(),n.requestDelegate&&n.requestDelegate.onRedirect&&n.requestDelegate.onRedirect(e),t.waitingToggle(!1)},onReject:function(e){if(423===e.message.statusCode)return e.message.hasHeader("min-expires")?(t.expires=Number(e.message.getHeader("min-expires")),t.waitingToggle(!1),void t.register()):(t.logger.error("423 response received for REGISTER without Min-Expires, dropping response"),t.unregistered(),void t.waitingToggle(!1));t.logger.warn("Failed to register, status code ".concat(e.message.statusCode));var r=NaN;if(500===e.message.statusCode||503===e.message.statusCode){var i=e.message.getHeader("retry-after");i&&(r=$(i,void 0))}t._retryAfter=isNaN(r)?void 0:r,t.unregistered(),n.requestDelegate&&n.requestDelegate.onReject&&n.requestDelegate.onReject(e),t._retryAfter=void 0,t.waitingToggle(!1)},onTrying:function(e){n.requestDelegate&&n.requestDelegate.onTrying&&n.requestDelegate.onTrying(e)}});return l.resolve(s)}},{key:"unregister",value:function(){var e,t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.state===St.Terminated)throw this.stateError(),new Error("Registerer terminated. Unable to register.");if(this.disposed&&this.state!==St.Registered)throw this.stateError(),new Error("Registerer disposed. Unable to register.");if(this.waiting){this.waitingWarning();var r=new le("REGISTER request already in progress, waiting for final response");return l.reject(r)}this._state===St.Registered||n.all||this.logger.warn("Not currently registered, but sending an unregister anyway.");var i=d(e=n.requestOptions&&n.requestOptions.extraHeaders||[]).call(e);this.request.extraHeaders=i,n.all?(i.push("Contact: *"),i.push("Expires: 0")):i.push("Contact: "+this.generateContactHeader(0)),this.request.cseq++,this.request.setHeader("cseq",this.request.cseq+" REGISTER"),void 0!==this.registrationTimer&&(clearTimeout(this.registrationTimer),this.registrationTimer=void 0),this.waitingToggle(!0);var s=this.userAgent.userAgentCore.register(this.request,{onAccept:function(e){t._contacts=e.message.getHeaders("contact"),t.unregistered(),n.requestDelegate&&n.requestDelegate.onAccept&&n.requestDelegate.onAccept(e),t.waitingToggle(!1)},onProgress:function(e){n.requestDelegate&&n.requestDelegate.onProgress&&n.requestDelegate.onProgress(e)},onRedirect:function(e){t.logger.error("Unregister redirected. Not currently supported."),t.unregistered(),n.requestDelegate&&n.requestDelegate.onRedirect&&n.requestDelegate.onRedirect(e),t.waitingToggle(!1)},onReject:function(e){t.logger.error("Unregister rejected with status code ".concat(e.message.statusCode)),t.unregistered(),n.requestDelegate&&n.requestDelegate.onReject&&n.requestDelegate.onReject(e),t.waitingToggle(!1)},onTrying:function(e){n.requestDelegate&&n.requestDelegate.onTrying&&n.requestDelegate.onTrying(e)}});return l.resolve(s)}},{key:"clearTimers",value:function(){void 0!==this.registrationTimer&&(clearTimeout(this.registrationTimer),this.registrationTimer=void 0),void 0!==this.registrationExpiredTimer&&(clearTimeout(this.registrationExpiredTimer),this.registrationExpiredTimer=void 0)}},{key:"generateContactHeader",value:function(e){var t,n=this.userAgent.contact.toString({register:!0});(this.options.regId&&this.options.instanceId&&(n+=";reg-id="+this.options.regId,n+=';+sip.instance="<urn:uuid:'+this.options.instanceId+'>"'),this.options.extraContactHeaderParams)&&u(t=this.options.extraContactHeaderParams).call(t,function(e){n+=";"+e});return n+=";expires="+e}},{key:"registered",value:function(e){var t=this;this.clearTimers(),this.registrationTimer=v(function(){t.registrationTimer=void 0,t.register()},this.refreshFrequency/100*e*1e3),this.registrationExpiredTimer=v(function(){t.logger.warn("Registration expired"),t.unregistered()},1e3*e),this._state!==St.Registered&&this.stateTransition(St.Registered)}},{key:"unregistered",value:function(){this.clearTimers(),this._state!==St.Unregistered&&this.stateTransition(St.Unregistered)}},{key:"terminated",value:function(){this.clearTimers(),this._state!==St.Terminated&&this.stateTransition(St.Terminated)}},{key:"stateTransition",value:function(e){var t=this,n=function(){var n;throw new Error(T(n="Invalid state transition from ".concat(t._state," to ")).call(n,e))};switch(this._state){case St.Initial:e!==St.Registered&&e!==St.Unregistered&&e!==St.Terminated&&n();break;case St.Registered:e!==St.Unregistered&&e!==St.Terminated&&n();break;case St.Unregistered:e!==St.Registered&&e!==St.Terminated&&n();break;case St.Terminated:n();break;default:throw new Error("Unrecognized state.")}this._state=e,this.logger.log("Registration transitioned to state ".concat(this._state)),this._stateEventEmitter.emit(this._state),e===St.Terminated&&this.dispose()}},{key:"waiting",get:function(){return this._waiting}},{key:"waitingChange",get:function(){return this._waitingEventEmitter}},{key:"waitingToggle",value:function(e){var t;if(this._waiting===e)throw new Error(T(t="Invalid waiting transition from ".concat(this._waiting," to ")).call(t,e));this._waiting=e,this.logger.log("Waiting toggled to ".concat(this._waiting)),this._waitingEventEmitter.emit(this._waiting)}},{key:"waitingWarning",value:function(){this.logger.warn("An attempt was made to send a REGISTER request while a prior one was still in progress. RFC 3261 requires UAs MUST NOT send a new registration until they have received a final response from the registrar for the previous one or the previous REGISTER request has timed out. Note that if the transport disconnects, you still must wait for the prior request to time out before sending a new REGISTER request or alternatively dispose of the current Registerer and create a new Registerer.")}},{key:"stateError",value:function(){var e=this.state===St.Terminated?"is in 'Terminated' state":"has been disposed",t="An attempt was made to send a REGISTER request when the Registerer ".concat(e,".");t+=" The Registerer transitions to 'Terminated' when Registerer.dispose() is called.",t+=" Perhaps you called UserAgent.stop() which dipsoses of all Registerers?",this.logger.error(t)}}],[{key:"defaultOptions",value:function(){return{expires:n.defaultExpires,extraContactHeaderParams:[],extraHeaders:[],logConfiguration:!0,instanceId:"",params:{},regId:0,registrar:new Ie("sip","anonymous","anonymous.invalid"),refreshFrequency:n.defaultRefreshFrequency}}},{key:"stripUndefinedProperties",value:function(e){var t;return M(t=E(e)).call(t,function(t,n){return void 0!==e[n]&&(t[n]=e[n]),t},{})}}])}();c(xt,"defaultExpires",{enumerable:!0,configurable:!0,writable:!0,value:600}),c(xt,"defaultRefreshFrequency",{enumerable:!0,configurable:!0,writable:!0,value:99}),function(e){e.Initial="Initial",e.NotifyWait="NotifyWait",e.Pending="Pending",e.Active="Active",e.Terminated="Terminated"}(Tt||(Tt={})),function(e){e.Initial="Initial",e.NotifyWait="NotifyWait",e.Subscribed="Subscribed",e.Terminated="Terminated"}(It||(It={})),function(e){e.Connecting="Connecting",e.Connected="Connected",e.Disconnecting="Disconnecting",e.Disconnected="Disconnected"}(Et||(Et={})),function(e){e.Started="Started",e.Stopped="Stopped"}(Ct||(Ct={}));var At=function(){function n(){e(this,n),c(this,"_dataLength",{enumerable:!0,configurable:!0,writable:!0,value:0}),c(this,"_bufferLength",{enumerable:!0,configurable:!0,writable:!0,value:0}),c(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:new Int32Array(4)}),c(this,"_buffer",{enumerable:!0,configurable:!0,writable:!0,value:new ArrayBuffer(68)}),c(this,"_buffer8",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_buffer32",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._buffer8=new Uint8Array(this._buffer,0,68),this._buffer32=new Uint32Array(this._buffer,0,17),this.start()}return t(n,[{key:"start",value:function(){return this._dataLength=0,this._bufferLength=0,this._state.set(n.stateIdentity),this}},{key:"appendStr",value:function(e){var t,r,i=this._buffer8,s=this._buffer32,o=this._bufferLength;for(r=0;r<e.length;r+=1){if((t=e.charCodeAt(r))<128)i[o++]=t;else if(t<2048)i[o++]=(t>>>6)+192,i[o++]=63&t|128;else if(t<55296||t>56319)i[o++]=(t>>>12)+224,i[o++]=t>>>6&63|128,i[o++]=63&t|128;else{if((t=1024*(t-55296)+(e.charCodeAt(++r)-56320)+65536)>1114111)throw new Error("Unicode standard supports code points up to U+10FFFF");i[o++]=(t>>>18)+240,i[o++]=t>>>12&63|128,i[o++]=t>>>6&63|128,i[o++]=63&t|128}o>=64&&(this._dataLength+=64,n._md5cycle(this._state,s),o-=64,s[0]=s[16])}return this._bufferLength=o,this}},{key:"appendAsciiStr",value:function(e){for(var t,r=this._buffer8,i=this._buffer32,s=this._bufferLength,o=0;;){for(t=Math.min(e.length-o,64-s);t--;)r[s++]=e.charCodeAt(o++);if(s<64)break;this._dataLength+=64,n._md5cycle(this._state,i),s=0}return this._bufferLength=s,this}},{key:"appendByteArray",value:function(e){for(var t,r=this._buffer8,i=this._buffer32,s=this._bufferLength,o=0;;){for(t=Math.min(e.length-o,64-s);t--;)r[s++]=e[o++];if(s<64)break;this._dataLength+=64,n._md5cycle(this._state,i),s=0}return this._bufferLength=s,this}},{key:"getState",value:function(){var e=this,t=e._state;return{buffer:String.fromCharCode.apply(null,e._buffer8),buflen:e._bufferLength,length:e._dataLength,state:[t[0],t[1],t[2],t[3]]}}},{key:"setState",value:function(e){var t,n=e.buffer,r=e.state,i=this._state;for(this._dataLength=e.length,this._bufferLength=e.buflen,i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],t=0;t<n.length;t+=1)this._buffer8[t]=n.charCodeAt(t)}},{key:"end",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],r=this._bufferLength,i=this._buffer8,s=this._buffer32,o=1+(r>>2);if(this._dataLength+=r,i[r]=128,i[r+1]=i[r+2]=i[r+3]=0,s.set(n.buffer32Identity.subarray(o),o),r>55&&(n._md5cycle(this._state,s),s.set(n.buffer32Identity)),(e=8*this._dataLength)<=4294967295)s[14]=e;else{var a=e.toString(16).match(/(.*?)(.{0,8})$/);if(null===a)return;var c=y(a[2],16),l=y(a[1],16)||0;s[14]=c,s[15]=l}return n._md5cycle(this._state,s),t?this._state:n._hex(this._state)}}],[{key:"hashStr",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.onePassHasher.start().appendStr(e).end(t)}},{key:"hashAsciiStr",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.onePassHasher.start().appendAsciiStr(e).end(t)}},{key:"_hex",value:function(e){var t,r,i,s,o=n.hexChars,a=n.hexOut;for(s=0;s<4;s+=1)for(r=8*s,t=e[s],i=0;i<8;i+=2)a[r+1+i]=o.charAt(15&t),t>>>=4,a[r+0+i]=o.charAt(15&t),t>>>=4;return a.join("")}},{key:"_md5cycle",value:function(e,t){var n=e[0],r=e[1],i=e[2],s=e[3];r=((r+=((i=((i+=((s=((s+=((n=((n+=(r&i|~r&s)+t[0]-680876936|0)<<7|n>>>25)+r|0)&r|~n&i)+t[1]-389564586|0)<<12|s>>>20)+n|0)&n|~s&r)+t[2]+606105819|0)<<17|i>>>15)+s|0)&s|~i&n)+t[3]-1044525330|0)<<22|r>>>10)+i|0,r=((r+=((i=((i+=((s=((s+=((n=((n+=(r&i|~r&s)+t[4]-176418897|0)<<7|n>>>25)+r|0)&r|~n&i)+t[5]+1200080426|0)<<12|s>>>20)+n|0)&n|~s&r)+t[6]-1473231341|0)<<17|i>>>15)+s|0)&s|~i&n)+t[7]-45705983|0)<<22|r>>>10)+i|0,r=((r+=((i=((i+=((s=((s+=((n=((n+=(r&i|~r&s)+t[8]+1770035416|0)<<7|n>>>25)+r|0)&r|~n&i)+t[9]-1958414417|0)<<12|s>>>20)+n|0)&n|~s&r)+t[10]-42063|0)<<17|i>>>15)+s|0)&s|~i&n)+t[11]-1990404162|0)<<22|r>>>10)+i|0,r=((r+=((i=((i+=((s=((s+=((n=((n+=(r&i|~r&s)+t[12]+1804603682|0)<<7|n>>>25)+r|0)&r|~n&i)+t[13]-40341101|0)<<12|s>>>20)+n|0)&n|~s&r)+t[14]-1502002290|0)<<17|i>>>15)+s|0)&s|~i&n)+t[15]+1236535329|0)<<22|r>>>10)+i|0,r=((r+=((i=((i+=((s=((s+=((n=((n+=(r&s|i&~s)+t[1]-165796510|0)<<5|n>>>27)+r|0)&i|r&~i)+t[6]-1069501632|0)<<9|s>>>23)+n|0)&r|n&~r)+t[11]+643717713|0)<<14|i>>>18)+s|0)&n|s&~n)+t[0]-373897302|0)<<20|r>>>12)+i|0,r=((r+=((i=((i+=((s=((s+=((n=((n+=(r&s|i&~s)+t[5]-701558691|0)<<5|n>>>27)+r|0)&i|r&~i)+t[10]+38016083|0)<<9|s>>>23)+n|0)&r|n&~r)+t[15]-660478335|0)<<14|i>>>18)+s|0)&n|s&~n)+t[4]-405537848|0)<<20|r>>>12)+i|0,r=((r+=((i=((i+=((s=((s+=((n=((n+=(r&s|i&~s)+t[9]+568446438|0)<<5|n>>>27)+r|0)&i|r&~i)+t[14]-1019803690|0)<<9|s>>>23)+n|0)&r|n&~r)+t[3]-187363961|0)<<14|i>>>18)+s|0)&n|s&~n)+t[8]+1163531501|0)<<20|r>>>12)+i|0,r=((r+=((i=((i+=((s=((s+=((n=((n+=(r&s|i&~s)+t[13]-1444681467|0)<<5|n>>>27)+r|0)&i|r&~i)+t[2]-51403784|0)<<9|s>>>23)+n|0)&r|n&~r)+t[7]+1735328473|0)<<14|i>>>18)+s|0)&n|s&~n)+t[12]-1926607734|0)<<20|r>>>12)+i|0,r=((r+=((i=((i+=((s=((s+=((n=((n+=(r^i^s)+t[5]-378558|0)<<4|n>>>28)+r|0)^r^i)+t[8]-2022574463|0)<<11|s>>>21)+n|0)^n^r)+t[11]+1839030562|0)<<16|i>>>16)+s|0)^s^n)+t[14]-35309556|0)<<23|r>>>9)+i|0,r=((r+=((i=((i+=((s=((s+=((n=((n+=(r^i^s)+t[1]-1530992060|0)<<4|n>>>28)+r|0)^r^i)+t[4]+1272893353|0)<<11|s>>>21)+n|0)^n^r)+t[7]-155497632|0)<<16|i>>>16)+s|0)^s^n)+t[10]-1094730640|0)<<23|r>>>9)+i|0,r=((r+=((i=((i+=((s=((s+=((n=((n+=(r^i^s)+t[13]+681279174|0)<<4|n>>>28)+r|0)^r^i)+t[0]-358537222|0)<<11|s>>>21)+n|0)^n^r)+t[3]-722521979|0)<<16|i>>>16)+s|0)^s^n)+t[6]+76029189|0)<<23|r>>>9)+i|0,r=((r+=((i=((i+=((s=((s+=((n=((n+=(r^i^s)+t[9]-640364487|0)<<4|n>>>28)+r|0)^r^i)+t[12]-421815835|0)<<11|s>>>21)+n|0)^n^r)+t[15]+530742520|0)<<16|i>>>16)+s|0)^s^n)+t[2]-995338651|0)<<23|r>>>9)+i|0,r=((r+=((s=((s+=(r^((n=((n+=(i^(r|~s))+t[0]-198630844|0)<<6|n>>>26)+r|0)|~i))+t[7]+1126891415|0)<<10|s>>>22)+n|0)^((i=((i+=(n^(s|~r))+t[14]-1416354905|0)<<15|i>>>17)+s|0)|~n))+t[5]-57434055|0)<<21|r>>>11)+i|0,r=((r+=((s=((s+=(r^((n=((n+=(i^(r|~s))+t[12]+1700485571|0)<<6|n>>>26)+r|0)|~i))+t[3]-1894986606|0)<<10|s>>>22)+n|0)^((i=((i+=(n^(s|~r))+t[10]-1051523|0)<<15|i>>>17)+s|0)|~n))+t[1]-2054922799|0)<<21|r>>>11)+i|0,r=((r+=((s=((s+=(r^((n=((n+=(i^(r|~s))+t[8]+1873313359|0)<<6|n>>>26)+r|0)|~i))+t[15]-30611744|0)<<10|s>>>22)+n|0)^((i=((i+=(n^(s|~r))+t[6]-1560198380|0)<<15|i>>>17)+s|0)|~n))+t[13]+1309151649|0)<<21|r>>>11)+i|0,r=((r+=((s=((s+=(r^((n=((n+=(i^(r|~s))+t[4]-145523070|0)<<6|n>>>26)+r|0)|~i))+t[11]-1120210379|0)<<10|s>>>22)+n|0)^((i=((i+=(n^(s|~r))+t[2]+718787259|0)<<15|i>>>17)+s|0)|~n))+t[9]-343485551|0)<<21|r>>>11)+i|0,e[0]=n+e[0]|0,e[1]=r+e[1]|0,e[2]=i+e[2]|0,e[3]=s+e[3]|0}}])}();function Dt(e){return At.hashStr(e)}c(At,"stateIdentity",{enumerable:!0,configurable:!0,writable:!0,value:new Int32Array([1732584193,-271733879,-1732584194,271733878])}),c(At,"buffer32Identity",{enumerable:!0,configurable:!0,writable:!0,value:new Int32Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])}),c(At,"hexChars",{enumerable:!0,configurable:!0,writable:!0,value:"0123456789abcdef"}),c(At,"hexOut",{enumerable:!0,configurable:!0,writable:!0,value:[]}),c(At,"onePassHasher",{enumerable:!0,configurable:!0,writable:!0,value:new At}),"5d41402abc4b2a76b9719d911017c592"!==At.hashStr("hello")&&console.error("Md5 self test failed.");var Ht,qt=function(){return t(function t(n,r,i,s){e(this,t),c(this,"stale",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"ha1",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"username",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"password",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"cnonce",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"nc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"ncHex",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"response",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"algorithm",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"realm",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"nonce",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"opaque",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"qop",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"method",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"uri",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.logger=n.getLogger("sipjs.digestauthentication"),this.username=i,this.password=s,this.ha1=r,this.nc=0,this.ncHex="00000000"},[{key:"authenticate",value:function(e,t,n){if(this.algorithm=t.algorithm,this.realm=t.realm,this.nonce=t.nonce,this.opaque=t.opaque,this.stale=t.stale,this.algorithm){if("MD5"!==this.algorithm)return this.logger.warn("challenge with Digest algorithm different than 'MD5', authentication aborted"),!1}else this.algorithm="MD5";if(!this.realm)return this.logger.warn("challenge without Digest realm, authentication aborted"),!1;if(!this.nonce)return this.logger.warn("challenge without Digest nonce, authentication aborted"),!1;var r,i;if(t.qop)if(q(r=t.qop).call(r,"auth")>-1)this.qop="auth";else{if(!(q(i=t.qop).call(i,"auth-int")>-1))return this.logger.warn("challenge without Digest qop different than 'auth' or 'auth-int', authentication aborted"),!1;this.qop="auth-int"}else this.qop=void 0;return this.method=e.method,this.uri=e.ruri,this.cnonce=_e(12),this.nc+=1,this.updateNcHex(),4294967296===this.nc&&(this.nc=1,this.ncHex="00000001"),this.calculateResponse(n),!0}},{key:"toString",value:function(){var e=[];if(!this.response)throw new Error("response field does not exist, cannot generate Authorization header");return e.push("algorithm="+this.algorithm),e.push('username="'+this.username+'"'),e.push('realm="'+this.realm+'"'),e.push('nonce="'+this.nonce+'"'),e.push('uri="'+this.uri+'"'),e.push('response="'+this.response+'"'),this.opaque&&e.push('opaque="'+this.opaque+'"'),this.qop&&(e.push("qop="+this.qop),e.push('cnonce="'+this.cnonce+'"'),e.push("nc="+this.ncHex)),"Digest "+e.join(", ")}},{key:"updateNcHex",value:function(){var e=Number(this.nc).toString(16);this.ncHex="00000000".substr(0,8-e.length)+e}},{key:"calculateResponse",value:function(e){var t,n;""!==(t=this.ha1)&&void 0!==t||(t=Dt(this.username+":"+this.realm+":"+this.password)),"auth"===this.qop?(n=Dt(this.method+":"+this.uri),this.response=Dt(t+":"+this.nonce+":"+this.ncHex+":"+this.cnonce+":auth:"+n)):"auth-int"===this.qop?(n=Dt(this.method+":"+this.uri+":"+Dt(e||"")),this.response=Dt(t+":"+this.nonce+":"+this.ncHex+":"+this.cnonce+":auth-int:"+n)):void 0===this.qop&&(n=Dt(this.method+":"+this.uri),this.response=Dt(t+":"+this.nonce+":"+n))}}])}();!function(e){e[e.error=0]="error",e[e.warn=1]="warn",e[e.log=2]="log",e[e.debug=3]="debug"}(Ht||(Ht={}));var _t,$t=function(){return t(function t(n,r,i){e(this,t),c(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"category",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"label",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.logger=n,this.category=r,this.label=i},[{key:"error",value:function(e){this.genericLog(Ht.error,e)}},{key:"warn",value:function(e){this.genericLog(Ht.warn,e)}},{key:"log",value:function(e){this.genericLog(Ht.log,e)}},{key:"debug",value:function(e){this.genericLog(Ht.debug,e)}},{key:"genericLog",value:function(e,t){this.logger.genericLog(e,this.category,this.label,t)}},{key:"level",get:function(){return this.logger.level},set:function(e){this.logger.level=e}}])}(),Mt=function(){return t(function t(){e(this,t),c(this,"builtinEnabled",{enumerable:!0,configurable:!0,writable:!0,value:!0}),c(this,"_level",{enumerable:!0,configurable:!0,writable:!0,value:Ht.log}),c(this,"_connector",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"loggers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),c(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.logger=this.getLogger("sip:loggerfactory")},[{key:"level",get:function(){return this._level},set:function(e){e>=0&&e<=3?this._level=e:e>3?this._level=3:Ht.hasOwnProperty(e)?this._level=e:this.logger.error("invalid 'level' parameter value: "+I(e))}},{key:"connector",get:function(){return this._connector},set:function(e){e?"function"==typeof e?this._connector=e:this.logger.error("invalid 'connector' parameter value: "+I(e)):this._connector=void 0}},{key:"getLogger",value:function(e,t){if(t&&3===this.level)return new $t(this,e,t);if(this.loggers[e])return this.loggers[e];var n=new $t(this,e);return this.loggers[e]=n,n}},{key:"genericLog",value:function(e,t,n,r){this.level>=e&&this.builtinEnabled&&this.print(e,t,n,r),this.connector&&this.connector(Ht[e],t,n,r)}},{key:"print",value:function(e,t,n,r){if("string"==typeof r){var i=[new Date,t];n&&i.push(n),r=T(i).call(i,r).join(" | ")}switch(e){case Ht.error:console.error(r);break;case Ht.warn:console.warn(r);break;case Ht.log:console.log(r);break;case Ht.debug:console.debug(r)}}}])}();function Pt(e,t){var n,r="\r\n";if(t.statusCode<100||t.statusCode>699)throw new TypeError("Invalid statusCode: "+t.statusCode);var i=t.reasonPhrase?t.reasonPhrase:$e(t.statusCode),s="SIP/2.0 "+t.statusCode+" "+i+r;t.statusCode>=100&&t.statusCode,t.statusCode;var o="From: "+e.getHeader("From")+r,a="Call-ID: "+e.callId+r,c="CSeq: "+e.cseq+" "+e.method+r,l=M(n=e.getHeaders("via")).call(n,function(e,t){return e+"Via: "+t+r},""),u="To: "+e.getHeader("to");if(t.statusCode>100&&!e.parseHeader("to").hasParam("tag")){var d=t.toTag;d||(d=Me()),u+=";tag="+d}u+=r;var h="";t.supported&&(h="Supported: "+t.supported.join(", ")+r);var g="";t.userAgent&&(g="User-Agent: "+t.userAgent+r);var f,v="";t.extraHeaders&&(v=M(f=t.extraHeaders).call(f,function(e,t){return e+S(t).call(t)+r},""));return s+=l,s+=o,s+=u,s+=c,s+=a,s+=h,s+=g,s+=v,t.body?(s+="Content-Type: "+t.body.contentType+r,s+="Content-Length: "+Oe(t.body.content)+r+r,s+=t.body.content):s+="Content-Length: 0\r\n\r\n",{message:s}}function Ot(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Ot=function(){return!!e})()}!function(e){function t(e,t){var n=t,r=0,i=0;if(e.substring(n,n+2).match(/(^\r\n)/))return-2;for(;0===r;){if(-1===(i=q(e).call(e,"\r\n",n)))return i;!e.substring(i+2,i+4).match(/(^\r\n)/)&&e.charAt(i+2).match(/(^\s+)/)?n=i+2:r=i}return r}function n(e,t,n,r){var i,s,o,a=q(t).call(t,":",n),c=S(i=t.substring(n,a)).call(i),l=S(s=t.substring(a+1,r)).call(s);switch(c.toLowerCase()){case"via":case"v":e.addHeader("via",l),1===e.getHeaders("via").length?(o=e.parseHeader("Via"))&&(e.via=o,e.viaBranch=o.branch):o=0;break;case"from":case"f":e.setHeader("from",l),(o=e.parseHeader("from"))&&(e.from=o,e.fromTag=o.getParam("tag"));break;case"to":case"t":e.setHeader("to",l),(o=e.parseHeader("to"))&&(e.to=o,e.toTag=o.getParam("tag"));break;case"record-route":if(-1===(o=De.parse(l,"Record_Route"))){o=void 0;break}if(!(o instanceof Array)){o=void 0;break}u(o).call(o,function(t){e.addHeader("record-route",l.substring(t.position,t.offset)),e.headers["Record-Route"][e.getHeaders("record-route").length-1].parsed=t.parsed});break;case"call-id":case"i":e.setHeader("call-id",l),(o=e.parseHeader("call-id"))&&(e.callId=l);break;case"contact":case"m":if(-1===(o=De.parse(l,"Contact"))){o=void 0;break}if(!(o instanceof Array)){o=void 0;break}u(o).call(o,function(t){e.addHeader("contact",l.substring(t.position,t.offset)),e.headers.Contact[e.getHeaders("contact").length-1].parsed=t.parsed});break;case"content-length":case"l":e.setHeader("content-length",l),o=e.parseHeader("content-length");break;case"content-type":case"c":e.setHeader("content-type",l),o=e.parseHeader("content-type");break;case"cseq":e.setHeader("cseq",l),(o=e.parseHeader("cseq"))&&(e.cseq=o.value),e instanceof Ge&&(e.method=o.method);break;case"max-forwards":e.setHeader("max-forwards",l),o=e.parseHeader("max-forwards");break;case"www-authenticate":e.setHeader("www-authenticate",l),o=e.parseHeader("www-authenticate");break;case"proxy-authenticate":e.setHeader("proxy-authenticate",l),o=e.parseHeader("proxy-authenticate");break;case"refer-to":case"r":e.setHeader("refer-to",l),(o=e.parseHeader("refer-to"))&&(e.referTo=o);break;default:e.addHeader(c.toLowerCase(),l),o=0}return void 0!==o||{error:"error parsing header '"+c+"'"}}e.getHeader=t,e.parseHeader=n,e.parseMessage=function(e,r){var i=0,s=q(e).call(e,"\r\n");if(-1!==s){var o,a=e.substring(0,s),c=De.parse(a,"Request_Response");if(-1!==c){var l;for(c.status_code?((o=new Ge).statusCode=c.status_code,o.reasonPhrase=c.reason_phrase):((o=new Ue).method=c.method,o.ruri=c.uri),o.data=e,i=s+2;;){if(-2===(s=t(e,i))){l=i+2;break}if(-1===s)return void r.error("malformed message");var u=n(o,e,i,s);if(u&&!0!==u)return void r.error(u.error);i=s+2}return o.hasHeader("content-length")?o.body=e.substr(l,Number(o.getHeader("content-length"))):o.body=e.substring(l),o}r.warn('error parsing first line of SIP message: "'+a+'"')}else r.warn("no CRLF found, not a SIP message, discarded")}}(_t||(_t={}));var Nt=function(){function o(t){return e(this,o),s=this,c=[t||"Unspecified transport error."],a=i(a=o),r(s,Ot()?n(a,c||[],i(s).constructor):a.apply(s,c));var s,a,c}return s(o,se),t(o)}(),jt=function(){return t(function t(n,r,i,s,o){var a;e(this,t),c(this,"_transport",{enumerable:!0,configurable:!0,writable:!0,value:n}),c(this,"_user",{enumerable:!0,configurable:!0,writable:!0,value:r}),c(this,"_id",{enumerable:!0,configurable:!0,writable:!0,value:i}),c(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:s}),c(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"listeners",{enumerable:!0,configurable:!0,writable:!0,value:new Array}),this.logger=r.loggerFactory.getLogger(o,i),this.logger.debug(T(a="Constructing ".concat(this.typeToString()," with id ")).call(a,this.id,"."))},[{key:"dispose",value:function(){var e;this.logger.debug(T(e="Destroyed ".concat(this.typeToString()," with id ")).call(e,this.id,"."))}},{key:"id",get:function(){return this._id}},{key:"kind",get:function(){throw new Error("Invalid kind.")}},{key:"state",get:function(){return this._state}},{key:"transport",get:function(){return this._transport}},{key:"addStateChangeListener",value:function(e,t){var n=this,r=function(){n.removeStateChangeListener(r),e()};!0===(null==t?void 0:t.once)?this.listeners.push(r):this.listeners.push(e)}},{key:"notifyStateChangeListeners",value:function(){var e,t;u(e=d(t=this.listeners).call(t)).call(e,function(e){return e()})}},{key:"removeStateChangeListener",value:function(e){var t;this.listeners=h(t=this.listeners).call(t,function(t){return t!==e})}},{key:"logTransportError",value:function(e,t){var n;this.logger.error(e.message),this.logger.error(T(n="Transport error occurred in ".concat(this.typeToString()," with id ")).call(n,this.id,".")),this.logger.error(t)}},{key:"send",value:function(e){var t=this;return this.transport.send(e).catch(function(e){if(e instanceof Nt)throw t.onTransportError(e),e;var n;throw n=e&&"string"==typeof e.message?new Nt(e.message):new Nt,t.onTransportError(n),n})}},{key:"setState",value:function(e){var t,n;this.logger.debug(T(t=T(n='State change to "'.concat(e,'" on ')).call(n,this.typeToString()," with id ")).call(t,this.id,".")),this._state=e,this._user.onStateChange&&this._user.onStateChange(e),this.notifyStateChangeListeners()}},{key:"typeToString",value:function(){return"UnknownType"}}])}();function Ft(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Ft=function(){return!!e})()}var Bt,Ut=function(){function o(t,s,a,l,u){var d,h,g,f;return e(this,o),h=this,g=o,f=[s,a,t.viaBranch,l,u],g=i(g),d=r(h,Ft()?n(g,f||[],i(h).constructor):g.apply(h,f)),c(d,"_request",{enumerable:!0,configurable:!0,writable:!0,value:t}),c(d,"user",{enumerable:!0,configurable:!0,writable:!0,value:a}),d}return s(o,jt),t(o,[{key:"request",get:function(){return this._request}}])}();function Lt(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Lt=function(){return!!e})()}!function(e){e.Accepted="Accepted",e.Calling="Calling",e.Completed="Completed",e.Confirmed="Confirmed",e.Proceeding="Proceeding",e.Terminated="Terminated",e.Trying="Trying"}(Bt||(Bt={}));var Gt=function(){function o(t,s,a){var l,u,d,h;return e(this,o),u=this,d=o,h=[t,s,a,Bt.Proceeding,"sip.transaction.ist"],d=i(d),l=r(u,Lt()?n(d,h||[],i(u).constructor):d.apply(u,h)),c(l,"lastFinalResponse",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"lastProvisionalResponse",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"H",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"I",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"L",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"progressExtensionTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),l}return s(o,Ut),t(o,[{key:"dispose",value:function(){var e,t,n,r,s;this.stopProgressExtensionTimer(),this.H&&(clearTimeout(this.H),this.H=void 0),this.I&&(clearTimeout(this.I),this.I=void 0),this.L&&(clearTimeout(this.L),this.L=void 0),(e=o,t="dispose",n=this,s=g(i(1&(r=3)?e.prototype:e),t,n),2&r&&"function"==typeof s?function(e){return s.apply(n,e)}:s)([])}},{key:"kind",get:function(){return"ist"}},{key:"receiveRequest",value:function(e){var t,n=this;switch(this.state){case Bt.Proceeding:if(e.method===it.INVITE)return void(this.lastProvisionalResponse&&this.send(this.lastProvisionalResponse).catch(function(e){n.logTransportError(e,"Failed to send retransmission of provisional response.")}));break;case Bt.Accepted:if(e.method===it.INVITE)return;break;case Bt.Completed:if(e.method===it.INVITE){if(!this.lastFinalResponse)throw new Error("Last final response undefined.");return void this.send(this.lastFinalResponse).catch(function(e){n.logTransportError(e,"Failed to send retransmission of final response.")})}if(e.method===it.ACK)return void this.stateTransition(Bt.Confirmed);break;case Bt.Confirmed:case Bt.Terminated:if(e.method===it.INVITE||e.method===it.ACK)return;break;default:throw new Error("Invalid state ".concat(this.state))}var r=T(t="INVITE server transaction received unexpected ".concat(e.method," request while in state ")).call(t,this.state,".");this.logger.warn(r)}},{key:"receiveResponse",value:function(e,t){var n,r=this;if(e<100||e>699)throw new Error("Invalid status code ".concat(e));switch(this.state){case Bt.Proceeding:if(e>=100&&e<=199)return this.lastProvisionalResponse=t,e>100&&this.startProgressExtensionTimer(),void this.send(t).catch(function(e){r.logTransportError(e,"Failed to send 1xx response.")});if(e>=200&&e<=299)return this.lastFinalResponse=t,this.stateTransition(Bt.Accepted),void this.send(t).catch(function(e){r.logTransportError(e,"Failed to send 2xx response.")});if(e>=300&&e<=699)return this.lastFinalResponse=t,this.stateTransition(Bt.Completed),void this.send(t).catch(function(e){r.logTransportError(e,"Failed to send non-2xx final response.")});break;case Bt.Accepted:if(e>=200&&e<=299)return void this.send(t).catch(function(e){r.logTransportError(e,"Failed to send 2xx response.")});break;case Bt.Completed:case Bt.Confirmed:case Bt.Terminated:break;default:throw new Error("Invalid state ".concat(this.state))}var i=T(n="INVITE server transaction received unexpected ".concat(e," response from TU while in state ")).call(n,this.state,".");throw this.logger.error(i),new Error(i)}},{key:"retransmitAcceptedResponse",value:function(){var e=this;this.state===Bt.Accepted&&this.lastFinalResponse&&this.send(this.lastFinalResponse).catch(function(t){e.logTransportError(t,"Failed to send 2xx response.")})}},{key:"onTransportError",value:function(e){this.user.onTransportError&&this.user.onTransportError(e)}},{key:"typeToString",value:function(){return"INVITE server transaction"}},{key:"stateTransition",value:function(e){var t=this,n=function(){var n;throw new Error(T(n="Invalid state transition from ".concat(t.state," to ")).call(n,e))};switch(e){case Bt.Proceeding:n();break;case Bt.Accepted:case Bt.Completed:this.state!==Bt.Proceeding&&n();break;case Bt.Confirmed:this.state!==Bt.Completed&&n();break;case Bt.Terminated:this.state!==Bt.Accepted&&this.state!==Bt.Completed&&this.state!==Bt.Confirmed&&n();break;default:n()}this.stopProgressExtensionTimer(),e===Bt.Accepted&&(this.L=v(function(){return t.timerL()},nt.TIMER_L)),e===Bt.Completed&&(this.H=v(function(){return t.timerH()},nt.TIMER_H)),e===Bt.Confirmed&&(this.I=v(function(){return t.timerI()},nt.TIMER_I)),e===Bt.Terminated&&this.dispose(),this.setState(e)}},{key:"startProgressExtensionTimer",value:function(){var e=this;void 0===this.progressExtensionTimer&&(this.progressExtensionTimer=U(function(){if(e.logger.debug("Progress extension timer expired for INVITE server transaction ".concat(e.id,".")),!e.lastProvisionalResponse)throw new Error("Last provisional response undefined.");e.send(e.lastProvisionalResponse).catch(function(t){e.logTransportError(t,"Failed to send retransmission of provisional response.")})},nt.PROVISIONAL_RESPONSE_INTERVAL))}},{key:"stopProgressExtensionTimer",value:function(){void 0!==this.progressExtensionTimer&&(clearInterval(this.progressExtensionTimer),this.progressExtensionTimer=void 0)}},{key:"timerG",value:function(){}},{key:"timerH",value:function(){this.logger.debug("Timer H expired for INVITE server transaction ".concat(this.id,".")),this.state===Bt.Completed&&(this.logger.warn("ACK to negative final response was never received, terminating transaction."),this.stateTransition(Bt.Terminated))}},{key:"timerI",value:function(){this.logger.debug("Timer I expired for INVITE server transaction ".concat(this.id,".")),this.stateTransition(Bt.Terminated)}},{key:"timerL",value:function(){this.logger.debug("Timer L expired for INVITE server transaction ".concat(this.id,".")),this.state===Bt.Accepted&&this.stateTransition(Bt.Terminated)}}])}();function Vt(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Vt=function(){return!!e})()}var Wt=function(){function o(t,s,a,l,u){var d,h,g,f;return e(this,o),h=this,g=o,f=[s,a,o.makeId(t),l,u],g=i(g),d=r(h,Vt()?n(g,f||[],i(h).constructor):g.apply(h,f)),c(d,"_request",{enumerable:!0,configurable:!0,writable:!0,value:t}),c(d,"user",{enumerable:!0,configurable:!0,writable:!0,value:a}),t.setViaHeader(d.id,s.protocol),d}return s(o,jt),t(o,[{key:"request",get:function(){return this._request}},{key:"onRequestTimeout",value:function(){this.user.onRequestTimeout&&this.user.onRequestTimeout()}}],[{key:"makeId",value:function(e){if("CANCEL"===e.method){if(!e.branch)throw new Error("Outgoing CANCEL request without a branch.");return e.branch}return"z9hG4bK"+Math.floor(1e7*Math.random())}}])}();function Yt(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Yt=function(){return!!e})()}var Kt=function(){function o(t,s,a){var l,u,d,h;return e(this,o),u=this,d=o,h=[t,s,a,Bt.Trying,"sip.transaction.nict"],d=i(d),l=r(u,Yt()?n(d,h||[],i(u).constructor):d.apply(u,h)),c(l,"F",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"K",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),l.F=v(function(){return l.timerF()},nt.TIMER_F),l.send(t.toString()).catch(function(e){l.logTransportError(e,"Failed to send initial outgoing request.")}),l}return s(o,Wt),t(o,[{key:"dispose",value:function(){var e,t,n,r,s;this.F&&(clearTimeout(this.F),this.F=void 0),this.K&&(clearTimeout(this.K),this.K=void 0),(e=o,t="dispose",n=this,s=g(i(1&(r=3)?e.prototype:e),t,n),2&r&&"function"==typeof s?function(e){return s.apply(n,e)}:s)([])}},{key:"kind",get:function(){return"nict"}},{key:"receiveResponse",value:function(e){var t,n=e.statusCode;if(!n||n<100||n>699)throw new Error("Invalid status code ".concat(n));switch(this.state){case Bt.Trying:if(n>=100&&n<=199)return this.stateTransition(Bt.Proceeding),void(this.user.receiveResponse&&this.user.receiveResponse(e));if(n>=200&&n<=699)return this.stateTransition(Bt.Completed),408===n?void this.onRequestTimeout():void(this.user.receiveResponse&&this.user.receiveResponse(e));break;case Bt.Proceeding:if(n>=100&&n<=199&&this.user.receiveResponse)return this.user.receiveResponse(e);if(n>=200&&n<=699)return this.stateTransition(Bt.Completed),408===n?void this.onRequestTimeout():void(this.user.receiveResponse&&this.user.receiveResponse(e));break;case Bt.Completed:case Bt.Terminated:return;default:throw new Error("Invalid state ".concat(this.state))}var r=T(t="Non-INVITE client transaction received unexpected ".concat(n," response while in state ")).call(t,this.state,".");this.logger.warn(r)}},{key:"onTransportError",value:function(e){this.user.onTransportError&&this.user.onTransportError(e),this.stateTransition(Bt.Terminated,!0)}},{key:"typeToString",value:function(){return"non-INVITE client transaction"}},{key:"stateTransition",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=function(){var n;throw new Error(T(n="Invalid state transition from ".concat(t.state," to ")).call(n,e))};switch(e){case Bt.Trying:r();break;case Bt.Proceeding:this.state!==Bt.Trying&&r();break;case Bt.Completed:this.state!==Bt.Trying&&this.state!==Bt.Proceeding&&r();break;case Bt.Terminated:this.state!==Bt.Trying&&this.state!==Bt.Proceeding&&this.state!==Bt.Completed&&(n||r());break;default:r()}e===Bt.Completed&&(this.F&&(clearTimeout(this.F),this.F=void 0),this.K=v(function(){return t.timerK()},nt.TIMER_K)),e===Bt.Terminated&&this.dispose(),this.setState(e)}},{key:"timerF",value:function(){this.logger.debug("Timer F expired for non-INVITE client transaction ".concat(this.id,".")),this.state!==Bt.Trying&&this.state!==Bt.Proceeding||(this.onRequestTimeout(),this.stateTransition(Bt.Terminated))}},{key:"timerK",value:function(){this.state===Bt.Completed&&this.stateTransition(Bt.Terminated)}}])}(),zt=function(){return t(function t(n,r){e(this,t),c(this,"core",{enumerable:!0,configurable:!0,writable:!0,value:n}),c(this,"dialogState",{enumerable:!0,configurable:!0,writable:!0,value:r}),this.core.dialogs.set(this.id,this)},[{key:"dispose",value:function(){this.core.dialogs.delete(this.id)}},{key:"id",get:function(){return this.dialogState.id}},{key:"early",get:function(){return this.dialogState.early}},{key:"callId",get:function(){return this.dialogState.callId}},{key:"localTag",get:function(){return this.dialogState.localTag}},{key:"remoteTag",get:function(){return this.dialogState.remoteTag}},{key:"localSequenceNumber",get:function(){return this.dialogState.localSequenceNumber}},{key:"remoteSequenceNumber",get:function(){return this.dialogState.remoteSequenceNumber}},{key:"localURI",get:function(){return this.dialogState.localURI}},{key:"remoteURI",get:function(){return this.dialogState.remoteURI}},{key:"remoteTarget",get:function(){return this.dialogState.remoteTarget}},{key:"routeSet",get:function(){return this.dialogState.routeSet}},{key:"secure",get:function(){return this.dialogState.secure}},{key:"userAgentCore",get:function(){return this.core}},{key:"confirm",value:function(){this.dialogState.early=!1}},{key:"receiveRequest",value:function(e){if(e.method!==it.ACK){if(this.remoteSequenceNumber){if(e.cseq<=this.remoteSequenceNumber)throw new Error("Out of sequence in dialog request. Did you forget to call sequenceGuard()?");this.dialogState.remoteSequenceNumber=e.cseq}this.remoteSequenceNumber||(this.dialogState.remoteSequenceNumber=e.cseq)}}},{key:"recomputeRouteSet",value:function(e){var t;this.dialogState.routeSet=L(t=e.getHeaders("record-route")).call(t)}},{key:"createOutgoingRequestMessage",value:function(e,t){var n,r=this.remoteURI,i=this.remoteTag,s=this.localURI,o=this.localTag,a=this.callId;n=t&&t.cseq?t.cseq:this.dialogState.localSequenceNumber?this.dialogState.localSequenceNumber+=1:this.dialogState.localSequenceNumber=1;var c=this.remoteTarget,l=this.routeSet,u=t&&t.extraHeaders,d=t&&t.body;return this.userAgentCore.makeOutgoingRequestMessage(e,c,s,r,{callId:a,cseq:n,fromTag:o,toTag:i,routeSet:l},u,d)}},{key:"incrementLocalSequenceNumber",value:function(){if(!this.dialogState.localSequenceNumber)throw new Error("Local sequence number undefined.");this.dialogState.localSequenceNumber+=1}},{key:"sequenceGuard",value:function(e){return e.method===it.ACK||(!(this.remoteSequenceNumber&&e.cseq<=this.remoteSequenceNumber)||(this.core.replyStateless(e,{statusCode:500}),!1))}}],[{key:"initialDialogStateForUserAgentClient",value:function(e,t){var n,r=L(n=t.getHeaders("record-route")).call(n),i=t.parseHeader("contact");if(!i)throw new Error("Contact undefined.");if(!(i instanceof Re))throw new Error("Contact not instance of NameAddrHeader.");var s=i.uri,o=e.cseq,a=e.callId,c=e.fromTag,l=t.toTag;if(!a)throw new Error("Call id undefined.");if(!c)throw new Error("From tag undefined.");if(!l)throw new Error("To tag undefined.");if(!e.from)throw new Error("From undefined.");if(!e.to)throw new Error("To undefined.");var u=e.from.uri,d=e.to.uri;if(!t.statusCode)throw new Error("Incoming response status code undefined.");return{id:a+c+l,early:t.statusCode<200,callId:a,localTag:c,remoteTag:l,localSequenceNumber:o,remoteSequenceNumber:undefined,localURI:u,remoteURI:d,remoteTarget:s,routeSet:r,secure:!1}}},{key:"initialDialogStateForUserAgentServer",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=e.getHeaders("record-route"),i=e.parseHeader("contact");if(!i)throw new Error("Contact undefined.");if(!(i instanceof Re))throw new Error("Contact not instance of NameAddrHeader.");var s=i.uri,o=e.cseq,a=e.callId,c=t,l=e.fromTag,u=e.from.uri;return{id:a+c+l,early:n,callId:a,localTag:c,remoteTag:l,localSequenceNumber:undefined,remoteSequenceNumber:o,localURI:e.to.uri,remoteURI:u,remoteTarget:s,routeSet:r,secure:!1}}}])}();function Zt(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Zt=function(){return!!e})()}var Jt=function(){function o(t,s,a){var l,u,d,h;return e(this,o),u=this,d=o,h=[t,s,a,Bt.Calling,"sip.transaction.ict"],d=i(d),l=r(u,Zt()?n(d,h||[],i(u).constructor):d.apply(u,h)),c(l,"B",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"D",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"M",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"ackRetransmissionCache",{enumerable:!0,configurable:!0,writable:!0,value:new _}),l.B=v(function(){return l.timerB()},nt.TIMER_B),l.send(t.toString()).catch(function(e){l.logTransportError(e,"Failed to send initial outgoing request.")}),l}return s(o,Wt),t(o,[{key:"dispose",value:function(){var e,t,n,r,s;this.B&&(clearTimeout(this.B),this.B=void 0),this.D&&(clearTimeout(this.D),this.D=void 0),this.M&&(clearTimeout(this.M),this.M=void 0),(e=o,t="dispose",n=this,s=g(i(1&(r=3)?e.prototype:e),t,n),2&r&&"function"==typeof s?function(e){return s.apply(n,e)}:s)([])}},{key:"kind",get:function(){return"ict"}},{key:"ackResponse",value:function(e){var t=this,n=e.toTag;if(!n)throw new Error("To tag undefined.");var r="z9hG4bK"+Math.floor(1e7*Math.random());e.setViaHeader(r,this.transport.protocol),this.ackRetransmissionCache.set(n,e),this.send(e.toString()).catch(function(e){t.logTransportError(e,"Failed to send ACK to 2xx response.")})}},{key:"receiveResponse",value:function(e){var t,n=this,r=e.statusCode;if(!r||r<100||r>699)throw new Error("Invalid status code ".concat(r));switch(this.state){case Bt.Calling:if(r>=100&&r<=199)return this.stateTransition(Bt.Proceeding),void(this.user.receiveResponse&&this.user.receiveResponse(e));if(r>=200&&r<=299)return this.ackRetransmissionCache.set(e.toTag,void 0),this.stateTransition(Bt.Accepted),void(this.user.receiveResponse&&this.user.receiveResponse(e));if(r>=300&&r<=699)return this.stateTransition(Bt.Completed),this.ack(e),void(this.user.receiveResponse&&this.user.receiveResponse(e));break;case Bt.Proceeding:if(r>=100&&r<=199)return void(this.user.receiveResponse&&this.user.receiveResponse(e));if(r>=200&&r<=299)return this.ackRetransmissionCache.set(e.toTag,void 0),this.stateTransition(Bt.Accepted),void(this.user.receiveResponse&&this.user.receiveResponse(e));if(r>=300&&r<=699)return this.stateTransition(Bt.Completed),this.ack(e),void(this.user.receiveResponse&&this.user.receiveResponse(e));break;case Bt.Accepted:if(r>=200&&r<=299){if(!this.ackRetransmissionCache.has(e.toTag))return this.ackRetransmissionCache.set(e.toTag,void 0),void(this.user.receiveResponse&&this.user.receiveResponse(e));var i=this.ackRetransmissionCache.get(e.toTag);return i?void this.send(i.toString()).catch(function(e){n.logTransportError(e,"Failed to send retransmission of ACK to 2xx response.")}):void 0}break;case Bt.Completed:if(r>=300&&r<=699)return void this.ack(e);break;case Bt.Terminated:break;default:throw new Error("Invalid state ".concat(this.state))}var s=T(t="Received unexpected ".concat(r," response while in state ")).call(t,this.state,".");this.logger.warn(s)}},{key:"onTransportError",value:function(e){this.user.onTransportError&&this.user.onTransportError(e),this.stateTransition(Bt.Terminated,!0)}},{key:"typeToString",value:function(){return"INVITE client transaction"}},{key:"ack",value:function(e){var t=this,n=this.request.ruri,r=this.request.callId,i=this.request.cseq,s=this.request.getHeader("from"),o=e.getHeader("to"),a=this.request.getHeader("via"),c=this.request.getHeader("route");if(!s)throw new Error("From undefined.");if(!o)throw new Error("To undefined.");if(!a)throw new Error("Via undefined.");var l="ACK ".concat(n," SIP/2.0\r\n");c&&(l+="Route: ".concat(c,"\r\n")),l+="Via: ".concat(a,"\r\n"),l+="To: ".concat(o,"\r\n"),l+="From: ".concat(s,"\r\n"),l+="Call-ID: ".concat(r,"\r\n"),l+="CSeq: ".concat(i," ACK\r\n"),l+="Max-Forwards: 70\r\n",l+="Content-Length: 0\r\n\r\n",this.send(l).catch(function(e){t.logTransportError(e,"Failed to send ACK to non-2xx response.")})}},{key:"stateTransition",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=function(){var n;throw new Error(T(n="Invalid state transition from ".concat(t.state," to ")).call(n,e))};switch(e){case Bt.Calling:r();break;case Bt.Proceeding:this.state!==Bt.Calling&&r();break;case Bt.Accepted:case Bt.Completed:this.state!==Bt.Calling&&this.state!==Bt.Proceeding&&r();break;case Bt.Terminated:this.state!==Bt.Calling&&this.state!==Bt.Accepted&&this.state!==Bt.Completed&&(n||r());break;default:r()}this.B&&(clearTimeout(this.B),this.B=void 0),Bt.Proceeding,e===Bt.Completed&&(this.D=v(function(){return t.timerD()},nt.TIMER_D)),e===Bt.Accepted&&(this.M=v(function(){return t.timerM()},nt.TIMER_M)),e===Bt.Terminated&&this.dispose(),this.setState(e)}},{key:"timerA",value:function(){}},{key:"timerB",value:function(){this.logger.debug("Timer B expired for INVITE client transaction ".concat(this.id,".")),this.state===Bt.Calling&&(this.onRequestTimeout(),this.stateTransition(Bt.Terminated))}},{key:"timerD",value:function(){this.logger.debug("Timer D expired for INVITE client transaction ".concat(this.id,".")),this.state===Bt.Completed&&this.stateTransition(Bt.Terminated)}},{key:"timerM",value:function(){this.logger.debug("Timer M expired for INVITE client transaction ".concat(this.id,".")),this.state===Bt.Accepted&&this.stateTransition(Bt.Terminated)}}])}(),Xt=function(){function n(t,r,i,s){e(this,n),c(this,"transactionConstructor",{enumerable:!0,configurable:!0,writable:!0,value:t}),c(this,"core",{enumerable:!0,configurable:!0,writable:!0,value:r}),c(this,"message",{enumerable:!0,configurable:!0,writable:!0,value:i}),c(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:s}),c(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_transaction",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"credentials",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"challenged",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(this,"stale",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this.logger=this.loggerFactory.getLogger("sip.user-agent-client"),this.init()}return t(n,[{key:"dispose",value:function(){this.transaction.dispose()}},{key:"loggerFactory",get:function(){return this.core.loggerFactory}},{key:"transaction",get:function(){if(!this._transaction)throw new Error("Transaction undefined.");return this._transaction}},{key:"cancel",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!this.transaction)throw new Error("Transaction undefined.");if(!this.message.to)throw new Error("To undefined.");if(!this.message.from)throw new Error("From undefined.");var i=this.core.makeOutgoingRequestMessage(it.CANCEL,this.message.ruri,this.message.from.uri,this.message.to.uri,{toTag:this.message.toTag,fromTag:this.message.fromTag,callId:this.message.callId,cseq:this.message.cseq},r.extraHeaders);return i.branch=this.message.branch,this.message.headers.Route&&(i.headers.Route=this.message.headers.Route),e&&i.setHeader("Reason",e),this.transaction.state===Bt.Proceeding?new n(Kt,this.core,i):this.transaction.addStateChangeListener(function(){t.transaction&&t.transaction.state===Bt.Proceeding&&new n(Kt,t.core,i)},{once:!0}),i}},{key:"authenticationGuard",value:function(e,t){var n,r,i=e.statusCode;if(!i)throw new Error("Response status code undefined.");if(401!==i&&407!==i)return!0;if(401===i?(n=e.parseHeader("www-authenticate"),r="authorization"):(n=e.parseHeader("proxy-authenticate"),r="proxy-authorization"),!n)return this.logger.warn(i+" with wrong or missing challenge, cannot authenticate"),!0;if(this.challenged&&(this.stale||!0!==n.stale))return this.logger.warn(i+" apparently in authentication loop, cannot authenticate"),!0;if(!this.credentials&&(this.credentials=this.core.configuration.authenticationFactory(),!this.credentials))return this.logger.warn("Unable to obtain credentials, cannot authenticate"),!0;if(!this.credentials.authenticate(this.message,n))return!0;this.challenged=!0,n.stale&&(this.stale=!0);var s=this.message.cseq+=1;return t&&t.localSequenceNumber&&(t.incrementLocalSequenceNumber(),s=this.message.cseq=t.localSequenceNumber),this.message.setHeader("cseq",s+" "+this.message.method),this.message.setHeader(r,this.credentials.toString()),this.init(),!1}},{key:"onRequestTimeout",value:function(){this.logger.warn("User agent client request timed out. Generating internal 408 Request Timeout.");var e=new Ge;e.statusCode=408,e.reasonPhrase="Request Timeout",this.receiveResponse(e)}},{key:"onTransportError",value:function(e){this.logger.error(e.message),this.logger.error("User agent client request transport error. Generating internal 503 Service Unavailable.");var t=new Ge;t.statusCode=503,t.reasonPhrase="Service Unavailable",this.receiveResponse(t)}},{key:"receiveResponse",value:function(e){if(this.authenticationGuard(e)){var t=e.statusCode?e.statusCode.toString():"";if(!t)throw new Error("Response status code undefined.");switch(!0){case/^100$/.test(t):this.delegate&&this.delegate.onTrying&&this.delegate.onTrying({message:e});break;case/^1[0-9]{2}$/.test(t):this.delegate&&this.delegate.onProgress&&this.delegate.onProgress({message:e});break;case/^2[0-9]{2}$/.test(t):this.delegate&&this.delegate.onAccept&&this.delegate.onAccept({message:e});break;case/^3[0-9]{2}$/.test(t):this.delegate&&this.delegate.onRedirect&&this.delegate.onRedirect({message:e});break;case/^[4-6][0-9]{2}$/.test(t):this.delegate&&this.delegate.onReject&&this.delegate.onReject({message:e});break;default:throw new Error("Invalid status code ".concat(t))}}}},{key:"init",value:function(){var e=this,t={loggerFactory:this.loggerFactory,onRequestTimeout:function(){return e.onRequestTimeout()},onStateChange:function(t){t===Bt.Terminated&&(e.core.userAgentClients.delete(r),n===e._transaction&&e.dispose())},onTransportError:function(t){return e.onTransportError(t)},receiveResponse:function(t){return e.receiveResponse(t)}},n=new this.transactionConstructor(this.message,this.core.transport,t);this._transaction=n;var r=n.id+n.request.method;this.core.userAgentClients.set(r,this)}}])}();function Qt(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Qt=function(){return!!e})()}var en=function(){function o(t,s,a){var c;e(this,o);var l,u,d,h=t.createOutgoingRequestMessage(it.BYE,a);return l=this,u=o,d=[Kt,t.userAgentCore,h,s],u=i(u),c=r(l,Qt()?n(u,d||[],i(l).constructor):u.apply(l,d)),t.dispose(),c}return s(o,Xt),t(o)}();function tn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(tn=function(){return!!e})()}var nn=function(){function o(t,s,a){var l,u,d,h;return e(this,o),u=this,d=o,h=[t,s,a,Bt.Trying,"sip.transaction.nist"],d=i(d),l=r(u,tn()?n(d,h||[],i(u).constructor):d.apply(u,h)),c(l,"lastResponse",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"J",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),l}return s(o,Ut),t(o,[{key:"dispose",value:function(){var e,t,n,r,s;this.J&&(clearTimeout(this.J),this.J=void 0),(e=o,t="dispose",n=this,s=g(i(1&(r=3)?e.prototype:e),t,n),2&r&&"function"==typeof s?function(e){return s.apply(n,e)}:s)([])}},{key:"kind",get:function(){return"nist"}},{key:"receiveRequest",value:function(e){var t=this;switch(this.state){case Bt.Trying:break;case Bt.Proceeding:if(!this.lastResponse)throw new Error("Last response undefined.");this.send(this.lastResponse).catch(function(e){t.logTransportError(e,"Failed to send retransmission of provisional response.")});break;case Bt.Completed:if(!this.lastResponse)throw new Error("Last response undefined.");this.send(this.lastResponse).catch(function(e){t.logTransportError(e,"Failed to send retransmission of final response.")});break;case Bt.Terminated:break;default:throw new Error("Invalid state ".concat(this.state))}}},{key:"receiveResponse",value:function(e,t){var n,r=this;if(e<100||e>699)throw new Error("Invalid status code ".concat(e));if(e>100&&e<=199)throw new Error("Provisional response other than 100 not allowed.");switch(this.state){case Bt.Trying:if(this.lastResponse=t,e>=100&&e<200)return this.stateTransition(Bt.Proceeding),void this.send(t).catch(function(e){r.logTransportError(e,"Failed to send provisional response.")});if(e>=200&&e<=699)return this.stateTransition(Bt.Completed),void this.send(t).catch(function(e){r.logTransportError(e,"Failed to send final response.")});break;case Bt.Proceeding:if(this.lastResponse=t,e>=200&&e<=699)return this.stateTransition(Bt.Completed),void this.send(t).catch(function(e){r.logTransportError(e,"Failed to send final response.")});break;case Bt.Completed:return;case Bt.Terminated:break;default:throw new Error("Invalid state ".concat(this.state))}var i=T(n="Non-INVITE server transaction received unexpected ".concat(e," response from TU while in state ")).call(n,this.state,".");throw this.logger.error(i),new Error(i)}},{key:"onTransportError",value:function(e){this.user.onTransportError&&this.user.onTransportError(e),this.stateTransition(Bt.Terminated,!0)}},{key:"typeToString",value:function(){return"non-INVITE server transaction"}},{key:"stateTransition",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=function(){var n;throw new Error(T(n="Invalid state transition from ".concat(t.state," to ")).call(n,e))};switch(e){case Bt.Trying:r();break;case Bt.Proceeding:this.state!==Bt.Trying&&r();break;case Bt.Completed:this.state!==Bt.Trying&&this.state!==Bt.Proceeding&&r();break;case Bt.Terminated:this.state!==Bt.Proceeding&&this.state!==Bt.Completed&&(n||r());break;default:r()}e===Bt.Completed&&(this.J=v(function(){return t.timerJ()},nt.TIMER_J)),e===Bt.Terminated&&this.dispose(),this.setState(e)}},{key:"timerJ",value:function(){this.logger.debug("Timer J expired for NON-INVITE server transaction ".concat(this.id,".")),this.state===Bt.Completed&&this.stateTransition(Bt.Terminated)}}])}(),rn=function(){return t(function t(n,r,i,s){e(this,t),c(this,"transactionConstructor",{enumerable:!0,configurable:!0,writable:!0,value:n}),c(this,"core",{enumerable:!0,configurable:!0,writable:!0,value:r}),c(this,"message",{enumerable:!0,configurable:!0,writable:!0,value:i}),c(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:s}),c(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"toTag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_transaction",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.logger=this.loggerFactory.getLogger("sip.user-agent-server"),this.toTag=i.toTag?i.toTag:Me(),this.init()},[{key:"dispose",value:function(){this.transaction.dispose()}},{key:"loggerFactory",get:function(){return this.core.loggerFactory}},{key:"transaction",get:function(){if(!this._transaction)throw new Error("Transaction undefined.");return this._transaction}},{key:"accept",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:200};if(!this.acceptable)throw new st(T(e="".concat(this.message.method," not acceptable in state ")).call(e,this.transaction.state,"."));var n=t.statusCode;if(n<200||n>299)throw new TypeError("Invalid statusCode: ".concat(n));return this.reply(t)}},{key:"progress",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:180};if(!this.progressable)throw new st(T(e="".concat(this.message.method," not progressable in state ")).call(e,this.transaction.state,"."));var n=t.statusCode;if(n<101||n>199)throw new TypeError("Invalid statusCode: ".concat(n));return this.reply(t)}},{key:"redirect",value:function(e){var t,n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{statusCode:302};if(!this.redirectable)throw new st(T(n="".concat(this.message.method," not redirectable in state ")).call(n,this.transaction.state,"."));var i=r.statusCode;if(i<300||i>399)throw new TypeError("Invalid statusCode: ".concat(i));var s=new Array;return u(e).call(e,function(e){return s.push("Contact: ".concat(e.toString()))}),r.extraHeaders=T(t=r.extraHeaders||[]).call(t,s),this.reply(r)}},{key:"reject",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:480};if(!this.rejectable)throw new st(T(e="".concat(this.message.method," not rejectable in state ")).call(e,this.transaction.state,"."));var n=t.statusCode;if(n<400||n>699)throw new TypeError("Invalid statusCode: ".concat(n));return this.reply(t)}},{key:"trying",value:function(e){var t;if(!this.tryingable)throw new st(T(t="".concat(this.message.method," not tryingable in state ")).call(t,this.transaction.state,"."));return this.reply({statusCode:100})}},{key:"receiveCancel",value:function(e){this.delegate&&this.delegate.onCancel&&this.delegate.onCancel(e)}},{key:"acceptable",get:function(){if(this.transaction instanceof Gt)return this.transaction.state===Bt.Proceeding||this.transaction.state===Bt.Accepted;if(this.transaction instanceof nn)return this.transaction.state===Bt.Trying||this.transaction.state===Bt.Proceeding;throw new Error("Unknown transaction type.")}},{key:"progressable",get:function(){if(this.transaction instanceof Gt)return this.transaction.state===Bt.Proceeding;if(this.transaction instanceof nn)return!1;throw new Error("Unknown transaction type.")}},{key:"redirectable",get:function(){if(this.transaction instanceof Gt)return this.transaction.state===Bt.Proceeding;if(this.transaction instanceof nn)return this.transaction.state===Bt.Trying||this.transaction.state===Bt.Proceeding;throw new Error("Unknown transaction type.")}},{key:"rejectable",get:function(){if(this.transaction instanceof Gt)return this.transaction.state===Bt.Proceeding;if(this.transaction instanceof nn)return this.transaction.state===Bt.Trying||this.transaction.state===Bt.Proceeding;throw new Error("Unknown transaction type.")}},{key:"tryingable",get:function(){if(this.transaction instanceof Gt)return this.transaction.state===Bt.Proceeding;if(this.transaction instanceof nn)return this.transaction.state===Bt.Trying;throw new Error("Unknown transaction type.")}},{key:"reply",value:function(e){e.toTag||100===e.statusCode||(e.toTag=this.toTag),e.userAgent=e.userAgent||this.core.configuration.userAgentHeaderFieldValue,e.supported=e.supported||this.core.configuration.supportedOptionTagsResponse;var t=Pt(this.message,e);return this.transaction.receiveResponse(e.statusCode,t.message),t}},{key:"init",value:function(){var e=this,t={loggerFactory:this.loggerFactory,onStateChange:function(t){t===Bt.Terminated&&(e.core.userAgentServers.delete(r),e.dispose())},onTransportError:function(t){e.logger.error(t.message),e.delegate&&e.delegate.onTransportError?e.delegate.onTransportError(t):e.logger.error("User agent server response transport error.")}},n=new this.transactionConstructor(this.message,this.core.transport,t);this._transaction=n;var r=n.id;this.core.userAgentServers.set(n.id,this)}}])}();function sn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(sn=function(){return!!e})()}var on=function(){function o(t,s,a){return e(this,o),c=this,l=o,u=[nn,t.userAgentCore,s,a],l=i(l),r(c,sn()?n(l,u||[],i(c).constructor):l.apply(c,u));var c,l,u}return s(o,rn),t(o)}();function an(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(an=function(){return!!e})()}var cn=function(){function o(t,s,a){e(this,o);var c,l,u,d=t.createOutgoingRequestMessage(it.INFO,a);return c=this,l=o,u=[Kt,t.userAgentCore,d,s],l=i(l),r(c,an()?n(l,u||[],i(c).constructor):l.apply(c,u))}return s(o,Xt),t(o)}();function ln(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(ln=function(){return!!e})()}var un=function(){function o(t,s,a){return e(this,o),c=this,l=o,u=[nn,t.userAgentCore,s,a],l=i(l),r(c,ln()?n(l,u||[],i(c).constructor):l.apply(c,u));var c,l,u}return s(o,rn),t(o)}();function dn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(dn=function(){return!!e})()}var hn=function(){function o(t,s,a){return e(this,o),c=this,u=[Kt,t,s,a],l=i(l=o),r(c,dn()?n(l,u||[],i(c).constructor):l.apply(c,u));var c,l,u}return s(o,Xt),t(o)}();function gn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(gn=function(){return!!e})()}var fn=function(){function o(t,s,a){return e(this,o),c=this,u=[nn,t,s,a],l=i(l=o),r(c,gn()?n(l,u||[],i(c).constructor):l.apply(c,u));var c,l,u}return s(o,rn),t(o)}();function vn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(vn=function(){return!!e})()}var pn=function(){function o(t,s,a){e(this,o);var c,l,u,d=t.createOutgoingRequestMessage(it.NOTIFY,a);return c=this,l=o,u=[Kt,t.userAgentCore,d,s],l=i(l),r(c,vn()?n(l,u||[],i(c).constructor):l.apply(c,u))}return s(o,Xt),t(o)}();function mn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(mn=function(){return!!e})()}var bn=function(){function o(t,s,a){e(this,o);var c,l,u,d=void 0!==t.userAgentCore?t.userAgentCore:t;return c=this,u=[nn,d,s,a],l=i(l=o),r(c,mn()?n(l,u||[],i(c).constructor):l.apply(c,u))}return s(o,rn),t(o)}();function wn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(wn=function(){return!!e})()}var yn=function(){function o(t,s,a){var c;e(this,o);var l,u,d,h=t.createOutgoingRequestMessage(it.PRACK,a);return l=this,u=o,d=[Kt,t.userAgentCore,h,s],u=i(u),c=r(l,wn()?n(u,d||[],i(l).constructor):u.apply(l,d)),t.signalingStateTransition(h),c}return s(o,Xt),t(o)}();function Sn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Sn=function(){return!!e})()}var kn=function(){function o(t,s,a){var l,u,d,h;return e(this,o),u=this,d=o,h=[nn,t.userAgentCore,s,a],d=i(d),l=r(u,Sn()?n(d,h||[],i(u).constructor):d.apply(u,h)),c(l,"dialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),t.signalingStateTransition(s),l.dialog=t,l}return s(o,rn),t(o,[{key:"accept",value:function(){var e,t,n,r,s,a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:200};return a.body&&this.dialog.signalingStateTransition(a.body),(e=o,t="accept",n=this,s=g(i(1&(r=3)?e.prototype:e),t,n),2&r&&"function"==typeof s?function(e){return s.apply(n,e)}:s)([a])}}])}();function Rn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Rn=function(){return!!e})()}var Tn=function(){function o(t,s,a){var l;e(this,o);var u,d,h,g=t.createOutgoingRequestMessage(it.INVITE,a);return u=this,d=o,h=[Jt,t.userAgentCore,g,s],d=i(d),l=r(u,Rn()?n(d,h||[],i(u).constructor):d.apply(u,h)),c(l,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"dialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),l.delegate=s,t.signalingStateTransition(g),t.reinviteUserAgentClient=l,l.dialog=t,l}return s(o,Xt),t(o,[{key:"receiveResponse",value:function(e){var t=this;if(this.authenticationGuard(e,this.dialog)){var n=e.statusCode?e.statusCode.toString():"";if(!n)throw new Error("Response status code undefined.");switch(!0){case/^100$/.test(n):this.delegate&&this.delegate.onTrying&&this.delegate.onTrying({message:e});break;case/^1[0-9]{2}$/.test(n):this.delegate&&this.delegate.onProgress&&this.delegate.onProgress({message:e,session:this.dialog,prack:function(e){throw new Error("Unimplemented.")}});break;case/^2[0-9]{2}$/.test(n):this.dialog.signalingStateTransition(e),this.delegate&&this.delegate.onAccept&&this.delegate.onAccept({message:e,session:this.dialog,ack:function(e){return t.dialog.ack(e)}});break;case/^3[0-9]{2}$/.test(n):this.dialog.signalingStateRollback(),this.dialog.reinviteUserAgentClient=void 0,this.delegate&&this.delegate.onRedirect&&this.delegate.onRedirect({message:e});break;case/^[4-6][0-9]{2}$/.test(n):this.dialog.signalingStateRollback(),this.dialog.reinviteUserAgentClient=void 0,this.delegate&&this.delegate.onReject&&this.delegate.onReject({message:e});break;default:throw new Error("Invalid status code ".concat(n))}}}}])}();function In(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(In=function(){return!!e})()}function En(e,t,n,r){var s=g(i(1&r?e.prototype:e),t,n);return 2&r&&"function"==typeof s?function(e){return s.apply(n,e)}:s}var Cn=function(){function o(t,s,a){var l,u,d,h;return e(this,o),u=this,d=o,h=[Gt,t.userAgentCore,s,a],d=i(d),l=r(u,In()?n(d,h||[],i(u).constructor):d.apply(u,h)),c(l,"dialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),t.reinviteUserAgentServer=l,l.dialog=t,l}return s(o,rn),t(o,[{key:"accept",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:200};n.extraHeaders=n.extraHeaders||[],n.extraHeaders=T(e=n.extraHeaders).call(e,m(t=this.dialog.routeSet).call(t,function(e){return"Record-Route: ".concat(e)}));var r=En(o,"accept",this,3)([n]),i=this.dialog,s=H(H({},r),{session:i});return n.body&&this.dialog.signalingStateTransition(n.body),this.dialog.reConfirm(),s}},{key:"progress",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:180},t=En(o,"progress",this,3)([e]),n=this.dialog,r=H(H({},t),{session:n});return e.body&&this.dialog.signalingStateTransition(e.body),r}},{key:"redirect",value:function(e){throw this.dialog.signalingStateRollback(),this.dialog.reinviteUserAgentServer=void 0,new Error("Unimplemented.")}},{key:"reject",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:488};return this.dialog.signalingStateRollback(),this.dialog.reinviteUserAgentServer=void 0,En(o,"reject",this,3)([e])}}])}();function xn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(xn=function(){return!!e})()}var An=function(){function o(t,s,a){e(this,o);var c,l,u,d=t.createOutgoingRequestMessage(it.REFER,a);return c=this,l=o,u=[Kt,t.userAgentCore,d,s],l=i(l),r(c,xn()?n(l,u||[],i(c).constructor):l.apply(c,u))}return s(o,Xt),t(o)}();function Dn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Dn=function(){return!!e})()}var Hn=function(){function o(t,s,a){e(this,o);var c,l,u,d=void 0!==t.userAgentCore?t.userAgentCore:t;return c=this,u=[nn,d,s,a],l=i(l=o),r(c,Dn()?n(l,u||[],i(c).constructor):l.apply(c,u))}return s(o,rn),t(o)}();function qn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(qn=function(){return!!e})()}function _n(e,t,n,r){var s=g(i(1&r?e.prototype:e),t,n);return 2&r&&"function"==typeof s?function(e){return s.apply(n,e)}:s}var $n=function(){function o(t,s,a,l){var u,d,h,g;return e(this,o),d=this,g=[s,a],h=i(h=o),u=r(d,qn()?n(h,g||[],i(d).constructor):h.apply(d,g)),c(u,"initialTransaction",{enumerable:!0,configurable:!0,writable:!0,value:t}),c(u,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(u,"reinviteUserAgentClient",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(u,"reinviteUserAgentServer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(u,"_signalingState",{enumerable:!0,configurable:!0,writable:!0,value:Ke.Initial}),c(u,"_offer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(u,"_answer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(u,"_rollbackOffer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(u,"_rollbackAnswer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(u,"ackWait",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(u,"ackProcessing",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(u,"invite2xxTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(u,"rseq",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(u,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),u.delegate=l,t instanceof Gt&&(u.ackWait=!0),u.early||u.start2xxRetransmissionTimer(),u.signalingStateTransition(t.request),u.logger=s.loggerFactory.getLogger("sip.invite-dialog"),u.logger.log("INVITE dialog ".concat(u.id," constructed")),u}return s(o,zt),t(o,[{key:"dispose",value:function(){_n(o,"dispose",this,3)([]),this._signalingState=Ke.Closed,this._offer=void 0,this._answer=void 0,this.invite2xxTimer&&(clearTimeout(this.invite2xxTimer),this.invite2xxTimer=void 0),this.logger.log("INVITE dialog ".concat(this.id," destroyed"))}},{key:"sessionState",get:function(){return this.early?Ye.Early:this.ackWait?Ye.AckWait:this._signalingState===Ke.Closed?Ye.Terminated:Ye.Confirmed}},{key:"signalingState",get:function(){return this._signalingState}},{key:"offer",get:function(){return this._offer}},{key:"answer",get:function(){return this._answer}},{key:"confirm",value:function(){this.early&&this.start2xxRetransmissionTimer(),_n(o,"confirm",this,3)([])}},{key:"reConfirm",value:function(){this.reinviteUserAgentServer&&this.startReInvite2xxRetransmissionTimer()}},{key:"ack",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("INVITE dialog ".concat(this.id," sending ACK request")),this.reinviteUserAgentClient){if(!(this.reinviteUserAgentClient.transaction instanceof Jt))throw new Error("Transaction not instance of InviteClientTransaction.");e=this.reinviteUserAgentClient.transaction,this.reinviteUserAgentClient=void 0}else{if(!(this.initialTransaction instanceof Jt))throw new Error("Initial transaction not instance of InviteClientTransaction.");e=this.initialTransaction}var n=this.createOutgoingRequestMessage(it.ACK,{cseq:e.request.cseq,extraHeaders:t.extraHeaders,body:t.body});return e.ackResponse(n),this.signalingStateTransition(n),{message:n}}},{key:"bye",value:function(e,t){if(this.logger.log("INVITE dialog ".concat(this.id," sending BYE request")),this.initialTransaction instanceof Gt){if(this.early)throw new Error("UAS MUST NOT send a BYE on early dialogs.");if(this.ackWait&&this.initialTransaction.state!==Bt.Terminated)throw new Error("UAS MUST NOT send a BYE on a confirmed dialog until it has received an ACK for its 2xx response or until the server transaction times out.")}return new en(this,e,t)}},{key:"info",value:function(e,t){if(this.logger.log("INVITE dialog ".concat(this.id," sending INFO request")),this.early)throw new Error("Dialog not confirmed.");return new cn(this,e,t)}},{key:"invite",value:function(e,t){if(this.logger.log("INVITE dialog ".concat(this.id," sending INVITE request")),this.early)throw new Error("Dialog not confirmed.");if(this.reinviteUserAgentClient)throw new Error("There is an ongoing re-INVITE client transaction.");if(this.reinviteUserAgentServer)throw new Error("There is an ongoing re-INVITE server transaction.");return new Tn(this,e,t)}},{key:"message",value:function(e,t){if(this.logger.log("INVITE dialog ".concat(this.id," sending MESSAGE request")),this.early)throw new Error("Dialog not confirmed.");var n=this.createOutgoingRequestMessage(it.MESSAGE,t);return new hn(this.core,n,e)}},{key:"notify",value:function(e,t){if(this.logger.log("INVITE dialog ".concat(this.id," sending NOTIFY request")),this.early)throw new Error("Dialog not confirmed.");return new pn(this,e,t)}},{key:"prack",value:function(e,t){return this.logger.log("INVITE dialog ".concat(this.id," sending PRACK request")),new yn(this,e,t)}},{key:"refer",value:function(e,t){if(this.logger.log("INVITE dialog ".concat(this.id," sending REFER request")),this.early)throw new Error("Dialog not confirmed.");return new An(this,e,t)}},{key:"receiveRequest",value:function(e){var t,n=this;if(this.logger.log(T(t="INVITE dialog ".concat(this.id," received ")).call(t,e.method," request")),e.method!==it.ACK)if(this.sequenceGuard(e)){if(_n(o,"receiveRequest",this,3)([e]),e.method===it.INVITE){var r=function(){var e,t=n.ackWait?"waiting for initial ACK":"processing initial ACK";n.logger.warn(T(e="INVITE dialog ".concat(n.id," received re-INVITE while ")).call(e,t));n.logger.warn("RFC 5407 suggests the following to avoid this race condition... Note: Implementation issues are outside the scope of this document, but the following tip is provided for avoiding race conditions of this type. The caller can delay sending re-INVITE F6 for some period of time (2 seconds, perhaps), after which the caller can reasonably assume that its ACK has been received. Implementors can decouple the actions of the user (e.g., pressing the hold button) from the actions of the protocol (the sending of re-INVITE F6), so that the UA can behave like this. In this case, it is the implementor's choice as to how long to wait. In most cases, such an implementation may be useful to prevent the type of race condition shown in this section. This document expresses no preference about whether or not they should wait for an ACK to be delivered. After considering the impact on user experience, implementors should decide whether or not to wait for a while, because the user experience depends on the implementation and has no direct bearing on protocol behavior.")},i=Math.floor(10*Math.random())+1,s=["Retry-After: ".concat(i)];if(this.ackProcessing)return this.core.replyStateless(e,{statusCode:500,extraHeaders:s}),void r();if(this.ackWait&&this.signalingState!==Ke.Stable)return this.core.replyStateless(e,{statusCode:500,extraHeaders:s}),void r();if(this.reinviteUserAgentServer)return void this.core.replyStateless(e,{statusCode:500,extraHeaders:s});if(this.reinviteUserAgentClient)return void this.core.replyStateless(e,{statusCode:491})}if(e.method===it.INVITE){var a=e.parseHeader("contact");if(!a)throw new Error("Contact undefined.");if(!(a instanceof Re))throw new Error("Contact not instance of NameAddrHeader.");this.dialogState.remoteTarget=a.uri}switch(e.method){case it.BYE:var c=new on(this,e);this.delegate&&this.delegate.onBye?this.delegate.onBye(c):c.accept(),this.dispose();break;case it.INFO:var u=new un(this,e);this.delegate&&this.delegate.onInfo?this.delegate.onInfo(u):u.reject({statusCode:469,extraHeaders:["Recv-Info:"]});break;case it.INVITE:var d=new Cn(this,e);this.signalingStateTransition(e),this.delegate&&this.delegate.onInvite?this.delegate.onInvite(d):d.reject({statusCode:488});break;case it.MESSAGE:var h=new fn(this.core,e);this.delegate&&this.delegate.onMessage?this.delegate.onMessage(h):h.accept();break;case it.NOTIFY:var g=new bn(this,e);this.delegate&&this.delegate.onNotify?this.delegate.onNotify(g):g.accept();break;case it.PRACK:var f=new kn(this,e);this.delegate&&this.delegate.onPrack?this.delegate.onPrack(f):f.accept();break;case it.REFER:var v=new Hn(this,e);this.delegate&&this.delegate.onRefer?this.delegate.onRefer(v):v.reject();break;default:var p;this.logger.log(T(p="INVITE dialog ".concat(this.id," received unimplemented ")).call(p,e.method," request")),this.core.replyStateless(e,{statusCode:501})}}else{var m;this.logger.log(T(m="INVITE dialog ".concat(this.id," rejected out of order ")).call(m,e.method," request."))}else{if(this.ackWait){var b,w;if(this.initialTransaction instanceof Jt)return void this.logger.warn(T(b="INVITE dialog ".concat(this.id," received unexpected ")).call(b,e.method," request, dropping."));if(this.initialTransaction.request.cseq!==e.cseq)return void this.logger.warn(T(w="INVITE dialog ".concat(this.id," received unexpected ")).call(w,e.method," request, dropping."));this.ackWait=!1}else{var y,S;if(!this.reinviteUserAgentServer)return void this.logger.warn(T(y="INVITE dialog ".concat(this.id," received unexpected ")).call(y,e.method," request, dropping."));if(this.reinviteUserAgentServer.transaction.request.cseq!==e.cseq)return void this.logger.warn(T(S="INVITE dialog ".concat(this.id," received unexpected ")).call(S,e.method," request, dropping."));this.reinviteUserAgentServer=void 0}if(this.signalingStateTransition(e),this.delegate&&this.delegate.onAck){var k=this.delegate.onAck({message:e});k instanceof l&&(this.ackProcessing=!0,k.then(function(){return n.ackProcessing=!1}).catch(function(){return n.ackProcessing=!1}))}}}},{key:"reliableSequenceGuard",value:function(e){var t=e.statusCode;if(!t)throw new Error("Status code undefined");if(t>100&&t<200){var n=e.getHeader("require"),r=e.getHeader("rseq"),i=n&&f(n).call(n,"100rel")&&r?Number(r):void 0;if(i){if(this.rseq&&this.rseq+1!==i)return!1;this.rseq=this.rseq?this.rseq+1:i}}return!0}},{key:"signalingStateRollback",value:function(){this._signalingState!==Ke.HaveLocalOffer&&this.signalingState!==Ke.HaveRemoteOffer||this._rollbackOffer&&this._rollbackAnswer&&(this._signalingState=Ke.Stable,this._offer=this._rollbackOffer,this._answer=this._rollbackAnswer)}},{key:"signalingStateTransition",value:function(e){var t=Qe(e);if(t&&"session"===t.contentDisposition){if(this._signalingState===Ke.Stable&&(this._rollbackOffer=this._offer,this._rollbackAnswer=this._answer),e instanceof Ue)switch(this._signalingState){case Ke.Initial:case Ke.Stable:this._signalingState=Ke.HaveRemoteOffer,this._offer=t,this._answer=void 0;break;case Ke.HaveLocalOffer:this._signalingState=Ke.Stable,this._answer=t;break;case Ke.HaveRemoteOffer:case Ke.Closed:break;default:throw new Error("Unexpected signaling state.")}if(e instanceof Ge)switch(this._signalingState){case Ke.Initial:case Ke.Stable:this._signalingState=Ke.HaveRemoteOffer,this._offer=t,this._answer=void 0;break;case Ke.HaveLocalOffer:this._signalingState=Ke.Stable,this._answer=t;break;case Ke.HaveRemoteOffer:case Ke.Closed:break;default:throw new Error("Unexpected signaling state.")}if(e instanceof ze)switch(this._signalingState){case Ke.Initial:case Ke.Stable:this._signalingState=Ke.HaveLocalOffer,this._offer=t,this._answer=void 0;break;case Ke.HaveLocalOffer:break;case Ke.HaveRemoteOffer:this._signalingState=Ke.Stable,this._answer=t;break;case Ke.Closed:break;default:throw new Error("Unexpected signaling state.")}if(Xe(e))switch(this._signalingState){case Ke.Initial:case Ke.Stable:this._signalingState=Ke.HaveLocalOffer,this._offer=t,this._answer=void 0;break;case Ke.HaveLocalOffer:break;case Ke.HaveRemoteOffer:this._signalingState=Ke.Stable,this._answer=t;break;case Ke.Closed:break;default:throw new Error("Unexpected signaling state.")}}}},{key:"start2xxRetransmissionTimer",value:function(){var e=this;if(this.initialTransaction instanceof Gt){var t=this.initialTransaction,n=nt.T1,r=function(){e.ackWait?(e.logger.log("No ACK for 2xx response received, attempting retransmission"),t.retransmitAcceptedResponse(),n=Math.min(2*n,nt.T2),e.invite2xxTimer=v(r,n)):e.invite2xxTimer=void 0};this.invite2xxTimer=v(r,n);var i=function(){t.state===Bt.Terminated&&(t.removeStateChangeListener(i),e.invite2xxTimer&&(clearTimeout(e.invite2xxTimer),e.invite2xxTimer=void 0),e.ackWait&&(e.delegate&&e.delegate.onAckTimeout?e.delegate.onAckTimeout():e.bye()))};t.addStateChangeListener(i)}}},{key:"startReInvite2xxRetransmissionTimer",value:function(){var e=this;if(this.reinviteUserAgentServer&&this.reinviteUserAgentServer.transaction instanceof Gt){var t=this.reinviteUserAgentServer.transaction,n=nt.T1,r=function(){e.reinviteUserAgentServer?(e.logger.log("No ACK for 2xx response received, attempting retransmission"),t.retransmitAcceptedResponse(),n=Math.min(2*n,nt.T2),e.invite2xxTimer=v(r,n)):e.invite2xxTimer=void 0};this.invite2xxTimer=v(r,n);var i=function(){t.state===Bt.Terminated&&(t.removeStateChangeListener(i),e.invite2xxTimer&&(clearTimeout(e.invite2xxTimer),e.invite2xxTimer=void 0),e.reinviteUserAgentServer)};t.addStateChangeListener(i)}}}])}();function Mn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Mn=function(){return!!e})()}function Pn(e,t,n,r){var s=g(i(1&r?e.prototype:e),t,n);return 2&r&&"function"==typeof s?function(e){return s.apply(n,e)}:s}var On=function(){function o(t,s,a){var l,u,d,h;return e(this,o),u=this,h=[Jt,t,s,a],d=i(d=o),l=r(u,Mn()?n(d,h||[],i(u).constructor):d.apply(u,h)),c(l,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"confirmedDialogAcks",{enumerable:!0,configurable:!0,writable:!0,value:new _}),c(l,"confirmedDialogs",{enumerable:!0,configurable:!0,writable:!0,value:new _}),c(l,"earlyDialogs",{enumerable:!0,configurable:!0,writable:!0,value:new _}),l.delegate=a,l}return s(o,Xt),t(o,[{key:"dispose",value:function(){var e;u(e=this.earlyDialogs).call(e,function(e){return e.dispose()}),this.earlyDialogs.clear(),Pn(o,"dispose",this,3)([])}},{key:"onTransportError",value:function(e){if(this.transaction.state===Bt.Calling)return Pn(o,"onTransportError",this,3)([e]);this.logger.error(e.message),this.logger.error("User agent client request transport error while sending ACK.")}},{key:"receiveResponse",value:function(e){var t,n,r=this;if(this.authenticationGuard(e)){var i=e.statusCode?e.statusCode.toString():"";if(!i)throw new Error("Response status code undefined.");switch(!0){case/^100$/.test(i):return void(this.delegate&&this.delegate.onTrying&&this.delegate.onTrying({message:e}));case/^1[0-9]{2}$/.test(i):if(!e.toTag)return void this.logger.warn("Non-100 1xx INVITE response received without a to tag, dropping.");if(!e.parseHeader("contact"))return void this.logger.error("Non-100 1xx INVITE response received without a Contact header field, dropping.");var s=zt.initialDialogStateForUserAgentClient(this.message,e),o=this.earlyDialogs.get(s.id);if(!o){var a=this.transaction;if(!(a instanceof Jt))throw new Error("Transaction not instance of InviteClientTransaction.");o=new $n(a,this.core,s),this.earlyDialogs.set(o.id,o)}if(!o.reliableSequenceGuard(e))return void this.logger.warn("1xx INVITE reliable response received out of order or is a retransmission, dropping.");o.signalingState!==Ke.Initial&&o.signalingState!==Ke.HaveLocalOffer||o.signalingStateTransition(e);var c=o;return void(this.delegate&&this.delegate.onProgress&&this.delegate.onProgress({message:e,session:c,prack:function(e){return c.prack(void 0,e)}}));case/^2[0-9]{2}$/.test(i):if(!e.toTag)return void this.logger.error("2xx INVITE response received without a to tag, dropping.");if(!e.parseHeader("contact"))return void this.logger.error("2xx INVITE response received without a Contact header field, dropping.");var l=zt.initialDialogStateForUserAgentClient(this.message,e),d=this.confirmedDialogs.get(l.id);if(d){var h=this.confirmedDialogAcks.get(l.id);if(h){var g=this.transaction;if(!(g instanceof Jt))throw new Error("Client transaction not instance of InviteClientTransaction.");g.ackResponse(h.message)}return}if(d=this.earlyDialogs.get(l.id))d.confirm(),d.recomputeRouteSet(e),this.earlyDialogs.delete(d.id),this.confirmedDialogs.set(d.id,d);else{var f=this.transaction;if(!(f instanceof Jt))throw new Error("Transaction not instance of InviteClientTransaction.");d=new $n(f,this.core,l),this.confirmedDialogs.set(d.id,d)}d.signalingState!==Ke.Initial&&d.signalingState!==Ke.HaveLocalOffer||d.signalingStateTransition(e);var v=d;if(this.delegate&&this.delegate.onAccept)this.delegate.onAccept({message:e,session:v,ack:function(e){var t=v.ack(e);return r.confirmedDialogAcks.set(v.id,t),t}});else{var p=v.ack();this.confirmedDialogAcks.set(v.id,p)}return;case/^3[0-9]{2}$/.test(i):return u(t=this.earlyDialogs).call(t,function(e){return e.dispose()}),this.earlyDialogs.clear(),void(this.delegate&&this.delegate.onRedirect&&this.delegate.onRedirect({message:e}));case/^[4-6][0-9]{2}$/.test(i):return u(n=this.earlyDialogs).call(n,function(e){return e.dispose()}),this.earlyDialogs.clear(),void(this.delegate&&this.delegate.onReject&&this.delegate.onReject({message:e}));default:throw new Error("Invalid status code ".concat(i))}}}}])}();function Nn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Nn=function(){return!!e})()}function jn(e,t,n,r){var s=g(i(1&r?e.prototype:e),t,n);return 2&r&&"function"==typeof s?function(e){return s.apply(n,e)}:s}var Fn=function(){function o(t,s,a){var l,u,d,h;return e(this,o),u=this,h=[Gt,t,s,a],d=i(d=o),l=r(u,Nn()?n(d,h||[],i(u).constructor):d.apply(u,h)),c(l,"core",{enumerable:!0,configurable:!0,writable:!0,value:t}),c(l,"confirmedDialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"earlyDialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),l}return s(o,rn),t(o,[{key:"dispose",value:function(){this.earlyDialog&&this.earlyDialog.dispose(),jn(o,"dispose",this,3)([])}},{key:"accept",value:function(){var e,t,n,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:200};if(!this.acceptable)throw new st(T(n="".concat(this.message.method," not acceptable in state ")).call(n,this.transaction.state,"."));if(!this.confirmedDialog)if(this.earlyDialog)this.earlyDialog.confirm(),this.confirmedDialog=this.earlyDialog,this.earlyDialog=void 0;else{var i=this.transaction;if(!(i instanceof Gt))throw new Error("Transaction not instance of InviteClientTransaction.");var s=zt.initialDialogStateForUserAgentServer(this.message,this.toTag);this.confirmedDialog=new $n(i,this.core,s)}var a=m(e=this.message.getHeaders("record-route")).call(e,function(e){return"Record-Route: ".concat(e)}),c="Contact: ".concat(this.core.configuration.contact.toString()),l="Allow: "+ot.toString();if(!r.body)if(this.confirmedDialog.signalingState===Ke.Stable)r.body=this.confirmedDialog.answer;else if(this.confirmedDialog.signalingState===Ke.Initial||this.confirmedDialog.signalingState===Ke.HaveRemoteOffer)throw new Error("Response must have a body.");r.statusCode=r.statusCode||200,r.extraHeaders=r.extraHeaders||[],r.extraHeaders=T(t=r.extraHeaders).call(t,a),r.extraHeaders.push(l),r.extraHeaders.push(c);var u=jn(o,"accept",this,3)([r]),d=this.confirmedDialog,h=H(H({},u),{session:d});return r.body&&this.confirmedDialog.signalingState!==Ke.Stable&&this.confirmedDialog.signalingStateTransition(r.body),h}},{key:"progress",value:function(){var e,t,n,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:180};if(!this.progressable)throw new st(T(n="".concat(this.message.method," not progressable in state ")).call(n,this.transaction.state,"."));if(!this.earlyDialog){var i=this.transaction;if(!(i instanceof Gt))throw new Error("Transaction not instance of InviteClientTransaction.");var s=zt.initialDialogStateForUserAgentServer(this.message,this.toTag,!0);this.earlyDialog=new $n(i,this.core,s)}var a=m(e=this.message.getHeaders("record-route")).call(e,function(e){return"Record-Route: ".concat(e)}),c="Contact: ".concat(this.core.configuration.contact);r.extraHeaders=r.extraHeaders||[],r.extraHeaders=T(t=r.extraHeaders).call(t,a),r.extraHeaders.push(c);var l=jn(o,"progress",this,3)([r]),u=this.earlyDialog,d=H(H({},l),{session:u});return r.body&&this.earlyDialog.signalingState!==Ke.Stable&&this.earlyDialog.signalingStateTransition(r.body),d}},{key:"redirect",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{statusCode:302};return jn(o,"redirect",this,3)([e,t])}},{key:"reject",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:486};return jn(o,"reject",this,3)([e])}}])}();function Bn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Bn=function(){return!!e})()}var Un=function(){function o(t,s,a){return e(this,o),c=this,u=[Kt,t,s,a],l=i(l=o),r(c,Bn()?n(l,u||[],i(c).constructor):l.apply(c,u));var c,l,u}return s(o,Xt),t(o)}();function Ln(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Ln=function(){return!!e})()}var Gn=function(){function o(t,s,a){return e(this,o),c=this,u=[Kt,t,s,a],l=i(l=o),r(c,Ln()?n(l,u||[],i(c).constructor):l.apply(c,u));var c,l,u}return s(o,Xt),t(o)}();function Vn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Vn=function(){return!!e})()}var Wn=function(){function o(t,s,a){var l,u,d,h;return e(this,o),u=this,h=[nn,t,s,a],d=i(d=o),l=r(u,Vn()?n(d,h||[],i(u).constructor):d.apply(u,h)),c(l,"core",{enumerable:!0,configurable:!0,writable:!0,value:t}),l}return s(o,rn),t(o)}();function Yn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Yn=function(){return!!e})()}var Kn=function(){function o(t,s,a){var l;e(this,o);var u,d,h,g=t.createOutgoingRequestMessage(it.SUBSCRIBE,a);return u=this,d=o,h=[Kt,t.userAgentCore,g,s],d=i(d),l=r(u,Yn()?n(d,h||[],i(u).constructor):d.apply(u,h)),c(l,"dialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),l.dialog=t,l}return s(o,Xt),t(o,[{key:"waitNotifyStop",value:function(){}},{key:"receiveResponse",value:function(e){if(e.statusCode&&e.statusCode>=200&&e.statusCode<300){var t=e.getHeader("Expires");if(t){var n=Number(t);this.dialog.subscriptionExpires>n&&(this.dialog.subscriptionExpires=n)}else this.logger.warn("Expires header missing in a 200-class response to SUBSCRIBE")}if(e.statusCode&&e.statusCode>=400&&e.statusCode<700){var r=[404,405,410,416,480,481,482,483,484,485,489,501,604];f(r).call(r,e.statusCode)&&this.dialog.terminate()}var s,a,c,l,u;(s=o,a="receiveResponse",c=this,u=g(i(1&(l=3)?s.prototype:s),a,c),2&l&&"function"==typeof u?function(e){return u.apply(c,e)}:u)([e])}}])}();function zn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(zn=function(){return!!e})()}function Zn(e,t,n,r){var s=g(i(1&r?e.prototype:e),t,n);return 2&r&&"function"==typeof s?function(e){return s.apply(n,e)}:s}var Jn=function(){function o(t,s,a,l,u,d){var h,g,f,v;return e(this,o),g=this,v=[l,u],f=i(f=o),h=r(g,zn()?n(f,v||[],i(g).constructor):f.apply(g,v)),c(h,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(h,"_autoRefresh",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(h,"_subscriptionEvent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(h,"_subscriptionExpires",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(h,"_subscriptionExpiresInitial",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(h,"_subscriptionExpiresLastSet",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(h,"_subscriptionRefresh",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(h,"_subscriptionRefreshLastSet",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(h,"_subscriptionState",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(h,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(h,"N",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(h,"refreshTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),h.delegate=d,h._autoRefresh=!1,h._subscriptionEvent=t,h._subscriptionExpires=s,h._subscriptionExpiresInitial=s,h._subscriptionExpiresLastSet=Math.floor(G()/1e3),h._subscriptionRefresh=void 0,h._subscriptionRefreshLastSet=void 0,h._subscriptionState=a,h.logger=l.loggerFactory.getLogger("sip.subscribe-dialog"),h.logger.log("SUBSCRIBE dialog ".concat(h.id," constructed")),h}return s(o,zt),t(o,[{key:"dispose",value:function(){Zn(o,"dispose",this,3)([]),this.N&&(clearTimeout(this.N),this.N=void 0),this.refreshTimerClear(),this.logger.log("SUBSCRIBE dialog ".concat(this.id," destroyed"))}},{key:"autoRefresh",get:function(){return this._autoRefresh},set:function(e){this._autoRefresh=!0,this.refreshTimerSet()}},{key:"subscriptionEvent",get:function(){return this._subscriptionEvent}},{key:"subscriptionExpires",get:function(){var e=Math.floor(G()/1e3)-this._subscriptionExpiresLastSet,t=this._subscriptionExpires-e;return Math.max(t,0)},set:function(e){if(e<0)throw new Error("Expires must be greater than or equal to zero.");if(this._subscriptionExpires=e,this._subscriptionExpiresLastSet=Math.floor(G()/1e3),this.autoRefresh){var t=this.subscriptionRefresh;(void 0===t||t>=e)&&this.refreshTimerSet()}}},{key:"subscriptionExpiresInitial",get:function(){return this._subscriptionExpiresInitial}},{key:"subscriptionRefresh",get:function(){if(void 0!==this._subscriptionRefresh&&void 0!==this._subscriptionRefreshLastSet){var e=Math.floor(G()/1e3)-this._subscriptionRefreshLastSet,t=this._subscriptionRefresh-e;return Math.max(t,0)}}},{key:"subscriptionState",get:function(){return this._subscriptionState}},{key:"receiveRequest",value:function(e){var t,n,r;if(this.logger.log(T(t="SUBSCRIBE dialog ".concat(this.id," received ")).call(t,e.method," request")),this.sequenceGuard(e))if(Zn(o,"receiveRequest",this,3)([e]),e.method===it.NOTIFY)this.onNotify(e);else this.logger.log(T(n="SUBSCRIBE dialog ".concat(this.id," received unimplemented ")).call(n,e.method," request")),this.core.replyStateless(e,{statusCode:501});else this.logger.log(T(r="SUBSCRIBE dialog ".concat(this.id," rejected out of order ")).call(r,e.method," request."))}},{key:"refresh",value:function(){var e,t="Allow: "+ot.toString(),n={};return n.extraHeaders=d(e=n.extraHeaders||[]).call(e),n.extraHeaders.push(t),n.extraHeaders.push("Event: "+this.subscriptionEvent),n.extraHeaders.push("Expires: "+this.subscriptionExpiresInitial),n.extraHeaders.push("Contact: "+this.core.configuration.contact.toString()),this.subscribe(void 0,n)}},{key:"subscribe",value:function(e){var t,n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.subscriptionState!==Tt.Pending&&this.subscriptionState!==Tt.Active)throw new Error("Invalid state ".concat(this.subscriptionState,'. May only re-subscribe while in state "pending" or "active".'));this.logger.log("SUBSCRIBE dialog ".concat(this.id," sending SUBSCRIBE request"));var i=new Kn(this,e,r);return this.N&&(clearTimeout(this.N),this.N=void 0),(null===(t=r.extraHeaders)||void 0===t?void 0:f(t).call(t,"Expires: 0"))||(this.N=v(function(){return n.timerN()},nt.TIMER_N)),i}},{key:"terminate",value:function(){this.stateTransition(Tt.Terminated),this.onTerminated()}},{key:"unsubscribe",value:function(){var e,t="Allow: "+ot.toString(),n={};return n.extraHeaders=d(e=n.extraHeaders||[]).call(e),n.extraHeaders.push(t),n.extraHeaders.push("Event: "+this.subscriptionEvent),n.extraHeaders.push("Expires: 0"),n.extraHeaders.push("Contact: "+this.core.configuration.contact.toString()),this.subscribe(void 0,n)}},{key:"onNotify",value:function(e){var t=e.parseHeader("Event").event;if(t&&t===this.subscriptionEvent){this.N&&(clearTimeout(this.N),this.N=void 0);var n=e.parseHeader("Subscription-State");if(n&&n.state){var r=n.state,i=n.expires?Math.max(n.expires,0):void 0;switch(r){case"pending":this.stateTransition(Tt.Pending,i);break;case"active":this.stateTransition(Tt.Active,i);break;case"terminated":this.stateTransition(Tt.Terminated,i);break;default:this.logger.warn("Unrecognized subscription state.")}var s=new bn(this,e);this.delegate&&this.delegate.onNotify?this.delegate.onNotify(s):s.accept()}else this.core.replyStateless(e,{statusCode:489})}else this.core.replyStateless(e,{statusCode:489})}},{key:"onRefresh",value:function(e){this.delegate&&this.delegate.onRefresh&&this.delegate.onRefresh(e)}},{key:"onTerminated",value:function(){this.delegate&&this.delegate.onTerminated&&this.delegate.onTerminated()}},{key:"refreshTimerClear",value:function(){this.refreshTimer&&(clearTimeout(this.refreshTimer),this.refreshTimer=void 0)}},{key:"refreshTimerSet",value:function(){var e=this;if(this.refreshTimerClear(),this.autoRefresh&&this.subscriptionExpires>0){var t=900*this.subscriptionExpires;this._subscriptionRefresh=Math.floor(t/1e3),this._subscriptionRefreshLastSet=Math.floor(G()/1e3),this.refreshTimer=v(function(){e.refreshTimer=void 0,e._subscriptionRefresh=void 0,e._subscriptionRefreshLastSet=void 0,e.onRefresh(e.refresh())},t)}}},{key:"stateTransition",value:function(e,t){var n=this,r=function(){var t;n.logger.warn(T(t="Invalid subscription state transition from ".concat(n.subscriptionState," to ")).call(t,e))};switch(e){case Tt.Initial:case Tt.NotifyWait:return void r();case Tt.Pending:if(this.subscriptionState!==Tt.NotifyWait&&this.subscriptionState!==Tt.Pending)return void r();break;case Tt.Active:case Tt.Terminated:if(this.subscriptionState!==Tt.NotifyWait&&this.subscriptionState!==Tt.Pending&&this.subscriptionState!==Tt.Active)return void r();break;default:return void r()}e===Tt.Pending&&t&&(this.subscriptionExpires=t),e===Tt.Active&&t&&(this.subscriptionExpires=t),e===Tt.Terminated&&this.dispose(),this._subscriptionState=e}},{key:"timerN",value:function(){this.logger.warn("Timer N expired for SUBSCRIBE dialog. Timed out waiting for NOTIFY."),this.subscriptionState!==Tt.Terminated&&(this.stateTransition(Tt.Terminated),this.onTerminated())}}],[{key:"initialDialogStateForSubscription",value:function(e,t){var n=t.getHeaders("record-route"),r=t.parseHeader("contact");if(!r)throw new Error("Contact undefined.");if(!(r instanceof Re))throw new Error("Contact not instance of NameAddrHeader.");var i=r.uri,s=e.cseq,o=e.callId,a=e.fromTag,c=t.fromTag;if(!o)throw new Error("Call id undefined.");if(!a)throw new Error("From tag undefined.");if(!c)throw new Error("To tag undefined.");if(!e.from)throw new Error("From undefined.");if(!e.to)throw new Error("To undefined.");return{id:o+a+c,early:!1,callId:o,localTag:a,remoteTag:c,localSequenceNumber:s,remoteSequenceNumber:undefined,localURI:e.from.uri,remoteURI:e.to.uri,remoteTarget:i,routeSet:n,secure:!1}}}])}();function Xn(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(Xn=function(){return!!e})()}function Qn(e,t,n,r){var s=g(i(1&r?e.prototype:e),t,n);return 2&r&&"function"==typeof s?function(e){return s.apply(n,e)}:s}var er=function(){function o(t,s,a){var l;e(this,o);var u=s.getHeader("Event");if(!u)throw new Error("Event undefined");var d,h,g,f=s.getHeader("Expires");if(!f)throw new Error("Expires undefined");return d=this,g=[Kt,t,s,a],h=i(h=o),l=r(d,Xn()?n(h,g||[],i(d).constructor):h.apply(d,g)),c(l,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"dialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"subscriberId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"subscriptionExpires",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"subscriptionExpiresRequested",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"subscriptionEvent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"subscriptionState",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(l,"N",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),l.delegate=a,l.subscriberId=s.callId+s.fromTag+u,l.subscriptionExpiresRequested=l.subscriptionExpires=Number(f),l.subscriptionEvent=u,l.subscriptionState=Tt.NotifyWait,l.waitNotifyStart(),l}return s(o,Xt),t(o,[{key:"dispose",value:function(){Qn(o,"dispose",this,3)([])}},{key:"onNotify",value:function(e){var t=e.message.parseHeader("Event").event;if(!t||t!==this.subscriptionEvent)return this.logger.warn("Failed to parse event."),void e.reject({statusCode:489});var n=e.message.parseHeader("Subscription-State");if(!n||!n.state)return this.logger.warn("Failed to parse subscription state."),void e.reject({statusCode:489});var r=n.state;switch(r){case"pending":case"active":case"terminated":break;default:return this.logger.warn("Invalid subscription state ".concat(r)),void e.reject({statusCode:489})}if("terminated"!==r&&!e.message.parseHeader("contact"))return this.logger.warn("Failed to parse contact."),void e.reject({statusCode:489});if(this.dialog)throw new Error("Dialog already created. This implementation only supports install of single subscriptions.");switch(this.waitNotifyStop(),this.subscriptionExpires=n.expires?Math.min(this.subscriptionExpires,Math.max(n.expires,0)):this.subscriptionExpires,r){case"pending":this.subscriptionState=Tt.Pending;break;case"active":this.subscriptionState=Tt.Active;break;case"terminated":this.subscriptionState=Tt.Terminated;break;default:throw new Error("Unrecognized state ".concat(r,"."))}if(this.subscriptionState!==Tt.Terminated){var i=Jn.initialDialogStateForSubscription(this.message,e.message);this.dialog=new Jn(this.subscriptionEvent,this.subscriptionExpires,this.subscriptionState,this.core,i)}if(this.delegate&&this.delegate.onNotify){var s=e,o=this.dialog;this.delegate.onNotify({request:s,subscription:o})}else e.accept()}},{key:"waitNotifyStart",value:function(){var e=this;this.N||(this.core.subscribers.set(this.subscriberId,this),this.N=v(function(){return e.timerN()},nt.TIMER_N))}},{key:"waitNotifyStop",value:function(){this.N&&(this.core.subscribers.delete(this.subscriberId),clearTimeout(this.N),this.N=void 0)}},{key:"receiveResponse",value:function(e){if(this.authenticationGuard(e)){if(e.statusCode&&e.statusCode>=200&&e.statusCode<300){var t=e.getHeader("Expires");if(t){var n=Number(t);n>this.subscriptionExpiresRequested&&this.logger.warn("Expires header in a 200-class response to SUBSCRIBE with a higher value than the one in the request"),n<this.subscriptionExpires&&(this.subscriptionExpires=n)}else this.logger.warn("Expires header missing in a 200-class response to SUBSCRIBE");this.dialog&&this.dialog.subscriptionExpires>this.subscriptionExpires&&(this.dialog.subscriptionExpires=this.subscriptionExpires)}e.statusCode&&e.statusCode>=300&&e.statusCode<700&&this.waitNotifyStop(),Qn(o,"receiveResponse",this,3)([e])}}},{key:"timerN",value:function(){this.logger.warn("Timer N expired for SUBSCRIBE user agent client. Timed out waiting for NOTIFY."),this.waitNotifyStop(),this.delegate&&this.delegate.onNotifyTimeout&&this.delegate.onNotifyTimeout()}}])}();function tr(){try{var e=!Boolean.prototype.valueOf.call(n(Boolean,[],function(){}))}catch(e){}return(tr=function(){return!!e})()}var nr=function(){function o(t,s,a){var l,u,d,h;return e(this,o),u=this,h=[nn,t,s,a],d=i(d=o),l=r(u,tr()?n(d,h||[],i(u).constructor):d.apply(u,h)),c(l,"core",{enumerable:!0,configurable:!0,writable:!0,value:t}),l}return s(o,rn),t(o)}(),rr=["application/sdp","application/dtmf-relay"],ir=function(){return t(function t(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,t),c(this,"configuration",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"dialogs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"subscribers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"userAgentClients",{enumerable:!0,configurable:!0,writable:!0,value:new _}),c(this,"userAgentServers",{enumerable:!0,configurable:!0,writable:!0,value:new _}),c(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.configuration=n,this.delegate=r,this.dialogs=new _,this.subscribers=new _,this.logger=n.loggerFactory.getLogger("sip.user-agent-core")},[{key:"dispose",value:function(){this.reset()}},{key:"reset",value:function(){var e,t,n,r;u(e=this.dialogs).call(e,function(e){return e.dispose()}),this.dialogs.clear(),u(t=this.subscribers).call(t,function(e){return e.dispose()}),this.subscribers.clear(),u(n=this.userAgentClients).call(n,function(e){return e.dispose()}),this.userAgentClients.clear(),u(r=this.userAgentServers).call(r,function(e){return e.dispose()}),this.userAgentServers.clear()}},{key:"loggerFactory",get:function(){return this.configuration.loggerFactory}},{key:"transport",get:function(){var e=this.configuration.transportAccessor();if(!e)throw new Error("Transport undefined.");return e}},{key:"invite",value:function(e,t){return new On(this,e,t)}},{key:"message",value:function(e,t){return new hn(this,e,t)}},{key:"publish",value:function(e,t){return new Un(this,e,t)}},{key:"register",value:function(e,t){return new Gn(this,e,t)}},{key:"subscribe",value:function(e,t){return new er(this,e,t)}},{key:"request",value:function(e,t){return new Xt(Kt,this,e,t)}},{key:"makeOutgoingRequestMessage",value:function(e,t,n,r,i,s,o){var a,c=this.configuration.sipjsId,l=this.configuration.displayName,u=this.configuration.viaForceRport,h=this.configuration.hackViaTcp,g=d(a=this.configuration.supportedOptionTags).call(a);e===it.REGISTER&&g.push("path","gruu"),e===it.INVITE&&(this.configuration.contact.pubGruu||this.configuration.contact.tempGruu)&&g.push("gruu");var f=this.configuration.routeSet,v=this.configuration.userAgentHeaderFieldValue,p=this.configuration.viaHost,m=H(H({},{callIdPrefix:c,forceRport:u,fromDisplayName:l,hackViaTcp:h,optionTags:g,routeSet:f,userAgentString:v,viaHost:p}),i);return new ze(e,t,n,r,m,s,o)}},{key:"receiveIncomingRequestFromTransport",value:function(e){this.receiveRequestFromTransport(e)}},{key:"receiveIncomingResponseFromTransport",value:function(e){this.receiveResponseFromTransport(e)}},{key:"replyStateless",value:function(e,t){var n=this,r=this.configuration.userAgentHeaderFieldValue,i=this.configuration.supportedOptionTagsResponse;t=H(H({},t),{userAgent:r,supported:i});var s=Pt(e,t);return this.transport.send(s.message).catch(function(t){t instanceof Error&&n.logger.error(t.message),n.logger.error("Transport error occurred sending stateless reply to ".concat(e.method," request."))}),s}},{key:"receiveRequestFromTransport",value:function(e){var t=e.viaBranch,n=this.userAgentServers.get(t);e.method===it.ACK&&n&&n.transaction.state===Bt.Accepted&&n instanceof Fn?this.logger.warn("Discarding out of dialog ACK after 2xx response sent on transaction ".concat(t,".")):e.method!==it.CANCEL?n?n.transaction.receiveRequest(e):this.receiveRequest(e):n?(this.replyStateless(e,{statusCode:200}),n.transaction instanceof Gt&&n.transaction.state===Bt.Proceeding&&n instanceof Fn&&n.receiveCancel(e)):this.replyStateless(e,{statusCode:481})}},{key:"receiveRequest",value:function(e){if(f(ot).call(ot,e.method)){if(!e.ruri)throw new Error("Request-URI undefined.");if("sip"===e.ruri.scheme){var t=e.ruri,n=function(e){return!!e&&e.user===t.user};if(!n(this.configuration.aor)&&!(n(this.configuration.contact.uri)||n(this.configuration.contact.pubGruu)||n(this.configuration.contact.tempGruu)))return this.logger.warn("Request-URI does not point to us."),void(e.method!==it.ACK&&this.replyStateless(e,{statusCode:404}));if(e.method!==it.INVITE||e.hasHeader("Contact")){if(!e.toTag){var r,i,s=e.viaBranch;if(!this.userAgentServers.has(s))if(F(r=x(B(i=this.userAgentServers).call(i))).call(r,function(t){return t.transaction.request.fromTag===e.fromTag&&t.transaction.request.callId===e.callId&&t.transaction.request.cseq===e.cseq}))return void this.replyStateless(e,{statusCode:482})}e.toTag?this.receiveInsideDialogRequest(e):this.receiveOutsideDialogRequest(e)}else this.replyStateless(e,{statusCode:400,reasonPhrase:"Missing Contact Header"})}else this.replyStateless(e,{statusCode:416})}else{var o="Allow: "+ot.toString();this.replyStateless(e,{statusCode:405,extraHeaders:[o]})}}},{key:"receiveInsideDialogRequest",value:function(e){if(e.method===it.NOTIFY){var t=e.parseHeader("Event");if(!t||!t.event)return void this.replyStateless(e,{statusCode:489});var n=e.callId+e.toTag+t.event,r=this.subscribers.get(n);if(r){var i=new bn(this,e);return void r.onNotify(i)}}var s=e.callId+e.toTag+e.fromTag,o=this.dialogs.get(s);if(o){if(e.method===it.OPTIONS){var a="Allow: "+ot.toString(),c="Accept: "+rr.toString();return void this.replyStateless(e,{statusCode:200,extraHeaders:[a,c]})}o.receiveRequest(e)}else e.method!==it.ACK&&this.replyStateless(e,{statusCode:481})}},{key:"receiveOutsideDialogRequest",value:function(e){switch(e.method){case it.ACK:break;case it.BYE:this.replyStateless(e,{statusCode:481});break;case it.CANCEL:throw new Error("Unexpected out of dialog request method ".concat(e.method,"."));case it.INFO:this.replyStateless(e,{statusCode:405});break;case it.INVITE:var t=new Fn(this,e);this.delegate.onInvite?this.delegate.onInvite(t):t.reject();break;case it.MESSAGE:var n=new fn(this,e);this.delegate.onMessage?this.delegate.onMessage(n):n.accept();break;case it.NOTIFY:var r=new bn(this,e);this.delegate.onNotify?this.delegate.onNotify(r):r.reject({statusCode:405});break;case it.OPTIONS:var i="Allow: "+ot.toString(),s="Accept: "+rr.toString();this.replyStateless(e,{statusCode:200,extraHeaders:[i,s]});break;case it.REFER:var o=new Hn(this,e);this.delegate.onRefer?this.delegate.onRefer(o):o.reject({statusCode:405});break;case it.REGISTER:var a=new Wn(this,e);this.delegate.onRegister?this.delegate.onRegister(a):a.reject({statusCode:405});break;case it.SUBSCRIBE:var c=new nr(this,e);this.delegate.onSubscribe?this.delegate.onSubscribe(c):c.reject({statusCode:480});break;default:throw new Error("Unexpected out of dialog request method ".concat(e.method,"."))}}},{key:"receiveResponseFromTransport",value:function(e){if(e.getHeaders("via").length>1)this.logger.warn("More than one Via header field present in the response, dropping");else{var t,n,r=e.viaBranch+e.method,i=this.userAgentClients.get(r);if(i)i.transaction.receiveResponse(e);else this.logger.warn(T(t=T(n="Discarding unmatched ".concat(e.statusCode," response to ")).call(n,e.method," ")).call(t,r,"."))}}}])}();var sr=function(){function n(t,r,i){e(this,n),c(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"mediaStreamFactory",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"sessionDescriptionHandlerConfiguration",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_localMediaStream",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_remoteMediaStream",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_dataChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_peerConnection",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_peerConnectionDelegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"iceGatheringCompletePromise",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"iceGatheringCompleteTimeoutId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"iceGatheringCompleteResolve",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"iceGatheringCompleteReject",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"localMediaStreamConstraints",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"onDataChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),t.debug("SessionDescriptionHandler.constructor"),this.logger=t,this.mediaStreamFactory=r,this.sessionDescriptionHandlerConfiguration=i,this._localMediaStream=new MediaStream,this._remoteMediaStream=new MediaStream,this._peerConnection=new RTCPeerConnection(null==i?void 0:i.peerConnectionConfiguration),this.initPeerConnectionEventHandlers()}return t(n,[{key:"localMediaStream",get:function(){return this._localMediaStream}},{key:"remoteMediaStream",get:function(){return this._remoteMediaStream}},{key:"dataChannel",get:function(){return this._dataChannel}},{key:"peerConnection",get:function(){return this._peerConnection}},{key:"peerConnectionDelegate",get:function(){return this._peerConnectionDelegate},set:function(e){this._peerConnectionDelegate=e}},{key:"close",value:function(){var e,t;this.logger.debug("SessionDescriptionHandler.close"),void 0!==this._peerConnection&&(u(e=this._peerConnection.getReceivers()).call(e,function(e){e.track&&e.track.stop()}),u(t=this._peerConnection.getSenders()).call(t,function(e){e.track&&e.track.stop()}),this._dataChannel&&this._dataChannel.close(),this._peerConnection.close(),this._peerConnection=void 0)}},{key:"enableReceiverTracks",value:function(e){var t,n=this.peerConnection;if(!n)throw new Error("Peer connection closed.");u(t=n.getReceivers()).call(t,function(t){t.track&&(t.track.enabled=e)})}},{key:"enableSenderTracks",value:function(e){var t,n=this.peerConnection;if(!n)throw new Error("Peer connection closed.");u(t=n.getSenders()).call(t,function(t){t.track&&(t.track.enabled=e)})}},{key:"getDescription",value:function(e,t){var n,r,i=this;if(this.logger.debug("SessionDescriptionHandler.getDescription"),void 0===this._peerConnection)return l.reject(new Error("Peer connection closed."));this.onDataChannel=null==e?void 0:e.onDataChannel;var s=null===(n=null==e?void 0:e.offerOptions)||void 0===n?void 0:n.iceRestart,o=void 0===(null==e?void 0:e.iceGatheringTimeout)?null===(r=this.sessionDescriptionHandlerConfiguration)||void 0===r?void 0:r.iceGatheringTimeout:null==e?void 0:e.iceGatheringTimeout;return this.getLocalMediaStream(e).then(function(){return i.updateDirection(e)}).then(function(){return i.createDataChannel(e)}).then(function(){return i.createLocalOfferOrAnswer(e)}).then(function(e){return i.applyModifiers(e,t)}).then(function(e){return i.setLocalSessionDescription(e)}).then(function(){return i.waitForIceGatheringComplete(s,o)}).then(function(){return i.getLocalSessionDescription()}).then(function(t){var n=null==e?void 0:e.finalModifiers;return n&&0!==n.length?(i.logger.debug("SessionDescriptionHandler.getDescription - applying final SDP modifiers"),i.applyFinalModifiers(t,n)):t}).then(function(e){var t=e.sdp||"";return i.logger.log("SessionDescriptionHandler.getDescription - final SDP "+I({hasRecoveryReason:f(t).call(t,"a=x-recovery-reason:"),hasReinviteReason:f(t).call(t,"a=x-reinvite-reason:")})),{body:t,contentType:"application/sdp"}}).catch(function(e){throw i.logger.error("SessionDescriptionHandler.getDescription failed - "+e),e})}},{key:"hasDescription",value:function(e){return this.logger.debug("SessionDescriptionHandler.hasDescription"),"application/sdp"===e}},{key:"iceGatheringComplete",value:function(){this.logger.debug("SessionDescriptionHandler.iceGatheringComplete"),void 0!==this.iceGatheringCompleteTimeoutId&&(this.logger.debug("SessionDescriptionHandler.iceGatheringComplete - clearing timeout"),clearTimeout(this.iceGatheringCompleteTimeoutId),this.iceGatheringCompleteTimeoutId=void 0),void 0!==this.iceGatheringCompletePromise&&(this.logger.debug("SessionDescriptionHandler.iceGatheringComplete - resolving promise"),this.iceGatheringCompleteResolve&&this.iceGatheringCompleteResolve(),this.iceGatheringCompletePromise=void 0,this.iceGatheringCompleteResolve=void 0,this.iceGatheringCompleteReject=void 0)}},{key:"sendDtmf",value:function(e,t){if(this.logger.debug("SessionDescriptionHandler.sendDtmf"),void 0===this._peerConnection)return this.logger.error("SessionDescriptionHandler.sendDtmf failed - peer connection closed"),!1;var n=this._peerConnection.getSenders();if(0===n.length)return this.logger.error("SessionDescriptionHandler.sendDtmf failed - no senders"),!1;var r=n[0].dtmf;if(!r)return this.logger.error("SessionDescriptionHandler.sendDtmf failed - no DTMF sender"),!1;var i=null==t?void 0:t.duration,s=null==t?void 0:t.interToneGap;try{r.insertDTMF(e,i,s)}catch(e){return this.logger.error(e.toString()),!1}return this.logger.log("SessionDescriptionHandler.sendDtmf sent via RTP: "+e.toString()),!0}},{key:"setDescription",value:function(e,t,n){var r=this;if(this.logger.debug("SessionDescriptionHandler.setDescription"),void 0===this._peerConnection)return l.reject(new Error("Peer connection closed."));this.onDataChannel=null==t?void 0:t.onDataChannel;var i="have-local-offer"===this._peerConnection.signalingState?"answer":"offer";return this.getLocalMediaStream(t).then(function(){return r.applyModifiers({sdp:e,type:i},n)}).then(function(e){return r.setRemoteSessionDescription(e)}).catch(function(e){throw r.logger.error("SessionDescriptionHandler.setDescription failed - "+e),e})}},{key:"applyFinalModifiers",value:function(e,t){var n=this;return this.logger.debug("SessionDescriptionHandler.applyFinalModifiers"),t&&0!==t.length?M(t).call(t,function(e,t){return e.then(function(e){return te(n,void 0,void 0,O.mark(function n(){var r,i;return O.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=1,t(e);case 1:if((i=n.sent)&&i.sdp){n.next=2;break}throw new Error("Invalid final SDP.");case 2:return n.abrupt("return",{sdp:i.sdp,type:null!==(r=i.type)&&void 0!==r?r:e.type});case 3:case"end":return n.stop()}},n)}))})},l.resolve({sdp:e.sdp,type:e.type})):l.resolve(e)}},{key:"applyModifiers",value:function(e,t){var n=this;return this.logger.debug("SessionDescriptionHandler.applyModifiers"),t&&0!==t.length?M(t).call(t,function(e,t){return e.then(t)},l.resolve(e)).then(function(e){if(n.logger.debug("SessionDescriptionHandler.applyModifiers - modified sdp"),!e.sdp||!e.type)throw new Error("Invalid SDP.");return{sdp:e.sdp,type:e.type}}):l.resolve(e)}},{key:"createDataChannel",value:function(e){if(void 0===this._peerConnection)return l.reject(new Error("Peer connection closed."));if(!0!==(null==e?void 0:e.dataChannel))return l.resolve();if(this._dataChannel)return l.resolve();switch(this._peerConnection.signalingState){case"stable":this.logger.debug("SessionDescriptionHandler.createDataChannel - creating data channel");try{return this._dataChannel=this._peerConnection.createDataChannel((null==e?void 0:e.dataChannelLabel)||"",null==e?void 0:e.dataChannelOptions),this.onDataChannel&&this.onDataChannel(this._dataChannel),l.resolve()}catch(e){return l.reject(e)}case"have-remote-offer":return l.resolve();default:return l.reject(new Error("Invalid signaling state "+this._peerConnection.signalingState))}}},{key:"createLocalOfferOrAnswer",value:function(e){if(void 0===this._peerConnection)return l.reject(new Error("Peer connection closed."));switch(this._peerConnection.signalingState){case"stable":return this.logger.debug("SessionDescriptionHandler.createLocalOfferOrAnswer - creating SDP offer"),this._peerConnection.createOffer(null==e?void 0:e.offerOptions);case"have-remote-offer":return this.logger.debug("SessionDescriptionHandler.createLocalOfferOrAnswer - creating SDP answer"),this._peerConnection.createAnswer(null==e?void 0:e.answerOptions);default:return l.reject(new Error("Invalid signaling state "+this._peerConnection.signalingState))}}},{key:"getLocalMediaStream",value:function(e){var t=this;if(this.logger.debug("SessionDescriptionHandler.getLocalMediaStream"),void 0===this._peerConnection)return l.reject(new Error("Peer connection closed."));var n=H({},null==e?void 0:e.constraints);if(this.localMediaStreamConstraints){if(n.audio=n.audio||this.localMediaStreamConstraints.audio,n.video=n.video||this.localMediaStreamConstraints.video,I(this.localMediaStreamConstraints.audio)===I(n.audio)&&I(this.localMediaStreamConstraints.video)===I(n.video))return l.resolve()}else void 0===n.audio&&void 0===n.video&&(n={audio:!0});return this.localMediaStreamConstraints=n,this.mediaStreamFactory(n,this,e).then(function(e){return t.setLocalMediaStream(e)})}},{key:"setLocalMediaStream",value:function(e){var t=this;if(this.logger.debug("SessionDescriptionHandler.setLocalMediaStream"),!this._peerConnection)throw new Error("Peer connection undefined.");var r=this._peerConnection,i=this._localMediaStream,s=[],o=function(e){var o,a=e.kind;if("audio"!==a&&"video"!==a)throw new Error("Unknown new track kind ".concat(a,"."));var c=V(o=r.getSenders()).call(o,function(e){return e.track&&e.track.kind===a});c?s.push(new l(function(e){t.logger.debug("SessionDescriptionHandler.setLocalMediaStream - replacing sender ".concat(a," track")),e()}).then(function(){return c.replaceTrack(e).then(function(){var t,r=V(t=i.getTracks()).call(t,function(e){return e.kind===a});r&&(r.stop(),i.removeTrack(r),n.dispatchRemoveTrackEvent(i,r)),i.addTrack(e),n.dispatchAddTrackEvent(i,e)}).catch(function(e){throw t.logger.error("SessionDescriptionHandler.setLocalMediaStream - failed to replace sender ".concat(a," track")),e})})):s.push(new l(function(e){t.logger.debug("SessionDescriptionHandler.setLocalMediaStream - adding sender ".concat(a," track")),e()}).then(function(){try{r.addTrack(e,i)}catch(e){throw t.logger.error("SessionDescriptionHandler.setLocalMediaStream - failed to add sender ".concat(a," track")),e}i.addTrack(e),n.dispatchAddTrackEvent(i,e)}))},a=e.getAudioTracks();a.length&&o(a[0]);var c=e.getVideoTracks();return c.length&&o(c[0]),M(s).call(s,function(e,t){return e.then(function(){return t})},l.resolve())}},{key:"getLocalSessionDescription",value:function(){if(this.logger.debug("SessionDescriptionHandler.getLocalSessionDescription"),void 0===this._peerConnection)return l.reject(new Error("Peer connection closed."));var e=this._peerConnection.localDescription;return e?l.resolve(e):l.reject(new Error("Failed to get local session description"))}},{key:"setLocalSessionDescription",value:function(e){return this.logger.debug("SessionDescriptionHandler.setLocalSessionDescription"),void 0===this._peerConnection?l.reject(new Error("Peer connection closed.")):this._peerConnection.setLocalDescription(e)}},{key:"setRemoteSessionDescription",value:function(e){if(this.logger.debug("SessionDescriptionHandler.setRemoteSessionDescription"),void 0===this._peerConnection)return l.reject(new Error("Peer connection closed."));var t,n=e.sdp;switch(this._peerConnection.signalingState){case"stable":t="offer";break;case"have-local-offer":t="answer";break;default:return l.reject(new Error("Invalid signaling state "+this._peerConnection.signalingState))}return n?this._peerConnection.setRemoteDescription({sdp:n,type:t}):(this.logger.error("SessionDescriptionHandler.setRemoteSessionDescription failed - cannot set null sdp"),l.reject(new Error("SDP is undefined")))}},{key:"setRemoteTrack",value:function(e){this.logger.debug("SessionDescriptionHandler.setRemoteTrack");var t=this._remoteMediaStream;if(t.getTrackById(e.id))this.logger.debug("SessionDescriptionHandler.setRemoteTrack - have remote ".concat(e.kind," track"));else if("audio"===e.kind){var r;this.logger.debug("SessionDescriptionHandler.setRemoteTrack - adding remote ".concat(e.kind," track")),u(r=t.getAudioTracks()).call(r,function(e){e.stop(),t.removeTrack(e),n.dispatchRemoveTrackEvent(t,e)}),t.addTrack(e),n.dispatchAddTrackEvent(t,e)}else if("video"===e.kind){var i;this.logger.debug("SessionDescriptionHandler.setRemoteTrack - adding remote ".concat(e.kind," track")),u(i=t.getVideoTracks()).call(i,function(e){e.stop(),t.removeTrack(e),n.dispatchRemoveTrackEvent(t,e)}),t.addTrack(e),n.dispatchAddTrackEvent(t,e)}}},{key:"updateDirection",value:function(e){var t=this;if(void 0===this._peerConnection)return l.reject(new Error("Peer connection closed."));switch(this._peerConnection.signalingState){case"stable":this.logger.debug("SessionDescriptionHandler.updateDirection - setting offer direction");var n;u(n=this._peerConnection.getTransceivers()).call(n,function(t){if(t.direction){var n=function(t){switch(t){case"inactive":case"recvonly":return(null==e?void 0:e.hold)?"inactive":"recvonly";case"sendonly":case"sendrecv":return(null==e?void 0:e.hold)?"sendonly":"sendrecv";case"stopped":return"stopped";default:throw new Error("Should never happen")}}(t.direction);t.direction!==n&&(t.direction=n)}});break;case"have-remote-offer":this.logger.debug("SessionDescriptionHandler.updateDirection - setting answer direction");var r,i=function(){var e=t._peerConnection.remoteDescription;if(!e)throw new Error("Failed to read remote offer");var n=/a=sendrecv\r\n|a=sendonly\r\n|a=recvonly\r\n|a=inactive\r\n/.exec(e.sdp);if(n)switch(n[0]){case"a=inactive\r\n":return"inactive";case"a=recvonly\r\n":return"recvonly";case"a=sendonly\r\n":return"sendonly";case"a=sendrecv\r\n":return"sendrecv";default:throw new Error("Should never happen")}return"sendrecv"}(),s=function(){switch(i){case"inactive":return"inactive";case"recvonly":return"sendonly";case"sendonly":return(null==e?void 0:e.hold)?"inactive":"recvonly";case"sendrecv":return(null==e?void 0:e.hold)?"sendonly":"sendrecv";default:throw new Error("Should never happen")}}();u(r=this._peerConnection.getTransceivers()).call(r,function(e){e.direction&&"stopped"!==e.direction&&e.direction!==s&&(e.direction=s)});break;default:return l.reject(new Error("Invalid signaling state "+this._peerConnection.signalingState))}return l.resolve()}},{key:"waitForIceGatheringComplete",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return this.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete"),void 0===this._peerConnection?l.reject("Peer connection closed."):t||"complete"!==this._peerConnection.iceGatheringState?(void 0!==this.iceGatheringCompletePromise&&(this.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete - rejecting prior waiting promise"),this.iceGatheringCompleteReject&&this.iceGatheringCompleteReject(new Error("Promise superseded.")),this.iceGatheringCompletePromise=void 0,this.iceGatheringCompleteResolve=void 0,this.iceGatheringCompleteReject=void 0),this.iceGatheringCompletePromise=new l(function(t,r){e.iceGatheringCompleteResolve=t,e.iceGatheringCompleteReject=r,n>0&&(e.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete - timeout in "+n),e.iceGatheringCompleteTimeoutId=v(function(){e.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete - timeout"),e.iceGatheringComplete()},n))}),this.iceGatheringCompletePromise):(this.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete - already complete"),l.resolve())}},{key:"initPeerConnectionEventHandlers",value:function(){var e=this;if(this.logger.debug("SessionDescriptionHandler.initPeerConnectionEventHandlers"),!this._peerConnection)throw new Error("Peer connection undefined.");var t=this._peerConnection;t.onconnectionstatechange=function(n){var r,i=t.connectionState;e.logger.debug("SessionDescriptionHandler.onconnectionstatechange ".concat(i)),(null===(r=e._peerConnectionDelegate)||void 0===r?void 0:r.onconnectionstatechange)&&e._peerConnectionDelegate.onconnectionstatechange(n)},t.ondatachannel=function(t){var n;e.logger.debug("SessionDescriptionHandler.ondatachannel"),e._dataChannel=t.channel,e.onDataChannel&&e.onDataChannel(e._dataChannel),(null===(n=e._peerConnectionDelegate)||void 0===n?void 0:n.ondatachannel)&&e._peerConnectionDelegate.ondatachannel(t)},t.onicecandidate=function(t){var n;e.logger.debug("SessionDescriptionHandler.onicecandidate"),(null===(n=e._peerConnectionDelegate)||void 0===n?void 0:n.onicecandidate)&&e._peerConnectionDelegate.onicecandidate(t)},t.onicecandidateerror=function(t){var n;e.logger.debug("SessionDescriptionHandler.onicecandidateerror"),(null===(n=e._peerConnectionDelegate)||void 0===n?void 0:n.onicecandidateerror)&&e._peerConnectionDelegate.onicecandidateerror(t)},t.oniceconnectionstatechange=function(n){var r,i=t.iceConnectionState;e.logger.debug("SessionDescriptionHandler.oniceconnectionstatechange ".concat(i)),(null===(r=e._peerConnectionDelegate)||void 0===r?void 0:r.oniceconnectionstatechange)&&e._peerConnectionDelegate.oniceconnectionstatechange(n)},t.onicegatheringstatechange=function(n){var r,i=t.iceGatheringState;e.logger.debug("SessionDescriptionHandler.onicegatheringstatechange ".concat(i)),"complete"===i&&e.iceGatheringComplete(),(null===(r=e._peerConnectionDelegate)||void 0===r?void 0:r.onicegatheringstatechange)&&e._peerConnectionDelegate.onicegatheringstatechange(n)},t.onnegotiationneeded=function(t){var n;e.logger.debug("SessionDescriptionHandler.onnegotiationneeded"),(null===(n=e._peerConnectionDelegate)||void 0===n?void 0:n.onnegotiationneeded)&&e._peerConnectionDelegate.onnegotiationneeded(t)},t.onsignalingstatechange=function(n){var r,i=t.signalingState;e.logger.debug("SessionDescriptionHandler.onsignalingstatechange ".concat(i)),(null===(r=e._peerConnectionDelegate)||void 0===r?void 0:r.onsignalingstatechange)&&e._peerConnectionDelegate.onsignalingstatechange(n)},t.ontrack=function(t){var n,r,i=t.track.kind,s=t.track.enabled?"enabled":"disabled";e.logger.debug(T(n="SessionDescriptionHandler.ontrack ".concat(i," ")).call(n,s)),e.setRemoteTrack(t.track),(null===(r=e._peerConnectionDelegate)||void 0===r?void 0:r.ontrack)&&e._peerConnectionDelegate.ontrack(t)}}}],[{key:"dispatchAddTrackEvent",value:function(e,t){e.dispatchEvent(new MediaStreamTrackEvent("addtrack",{track:t}))}},{key:"dispatchRemoveTrackEvent",value:function(e,t){e.dispatchEvent(new MediaStreamTrackEvent("removetrack",{track:t}))}}])}();function or(e){return function(t,n){void 0===e&&(e=function(e){return e.audio||e.video?void 0===navigator.mediaDevices?l.reject(new Error("Media devices not available in insecure contexts.")):navigator.mediaDevices.getUserMedia.call(navigator.mediaDevices,e):l.resolve(new MediaStream)});var r={iceGatheringTimeout:void 0!==(null==n?void 0:n.iceGatheringTimeout)?null==n?void 0:n.iceGatheringTimeout:5e3,peerConnectionConfiguration:H(H({},{bundlePolicy:"balanced",certificates:void 0,iceCandidatePoolSize:0,iceServers:[{urls:"stun:stun.l.google.com:19302"}],iceTransportPolicy:"all",rtcpMuxPolicy:"require"}),null==n?void 0:n.peerConnectionConfiguration)},i=t.userAgent.getLogger("sip.SessionDescriptionHandler");return new sr(i,e,r)}}var ar=function(){return t(function t(n,r){var i;if(e(this,t),c(this,"onConnect",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"onDisconnect",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"onMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_protocol",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:Et.Disconnected}),c(this,"_stateEventEmitter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_ws",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"configuration",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"connectPromise",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"connectResolve",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"connectReject",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"connectTimeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"disconnectPromise",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"disconnectResolve",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"disconnectReject",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"keepAliveInterval",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"keepAliveDebounceTimeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"transitioningState",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this._stateEventEmitter=new we,this.logger=n,r){var s=r,o=null==s?void 0:s.wsServers,a=null==s?void 0:s.maxReconnectionAttempts;if(void 0!==o){this.logger.warn('The transport option "wsServers" as has apparently been specified and has been deprecated. It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.')}if(void 0!==a){this.logger.warn('The transport option "maxReconnectionAttempts" as has apparently been specified and has been deprecated. It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.')}o&&!r.server&&("string"==typeof o&&(r.server=o),o instanceof Array&&(r.server=o[0]))}this.configuration=H(H({},t.defaultOptions),r);var l=this.configuration.server,u=De.parse(l,"absoluteURI");if(-1===u)throw this.logger.error('Invalid WebSocket Server URL "'.concat(l,'"')),new Error("Invalid WebSocket Server URL");if(!f(i=["wss","ws","udp"]).call(i,u.scheme))throw this.logger.error('Invalid scheme in WebSocket Server URL "'.concat(l,'"')),new Error("Invalid scheme in WebSocket Server URL");this._protocol=u.scheme.toUpperCase()},[{key:"dispose",value:function(){return this.disconnect()}},{key:"protocol",get:function(){return this._protocol}},{key:"server",get:function(){return this.configuration.server}},{key:"state",get:function(){return this._state}},{key:"stateChange",get:function(){return this._stateEventEmitter}},{key:"ws",get:function(){return this._ws}},{key:"connect",value:function(){return this._connect()}},{key:"disconnect",value:function(){return this._disconnect()}},{key:"isConnected",value:function(){return this.state===Et.Connected}},{key:"send",value:function(e){return this._send(e)}},{key:"_connect",value:function(){var e,t=this;switch(this.logger.log("Connecting ".concat(this.server)),this.state){case Et.Connecting:if(this.transitioningState)return l.reject(this.transitionLoopDetectedError(Et.Connecting));if(!this.connectPromise)throw new Error("Connect promise must be defined.");return this.connectPromise;case Et.Connected:if(this.transitioningState)return l.reject(this.transitionLoopDetectedError(Et.Connecting));if(this.connectPromise)throw new Error("Connect promise must not be defined.");return l.resolve();case Et.Disconnecting:if(this.connectPromise)throw new Error("Connect promise must not be defined.");try{this.transitionState(Et.Connecting)}catch(e){if(e instanceof ve)return l.reject(e);throw e}break;case Et.Disconnected:if(this.connectPromise)throw new Error("Connect promise must not be defined.");try{this.transitionState(Et.Connecting)}catch(e){if(e instanceof ve)return l.reject(e);throw e}break;default:throw new Error("Unknown state")}try{(e=new WebSocket(this.server,"sip")).binaryType="arraybuffer",e.addEventListener("close",function(n){return t.onWebSocketClose(n,e)}),e.addEventListener("error",function(n){return t.onWebSocketError(n,e)}),e.addEventListener("open",function(n){return t.onWebSocketOpen(n,e)}),e.addEventListener("message",function(n){return t.onWebSocketMessage(n,e)}),this._ws=e}catch(e){return this._ws=void 0,this.logger.error("WebSocket construction failed."),this.logger.error(e.toString()),new l(function(n,r){t.connectResolve=n,t.connectReject=r,t.transitionState(Et.Disconnected,e)})}return this.connectPromise=new l(function(n,r){t.connectResolve=n,t.connectReject=r,t.connectTimeout=v(function(){t.logger.warn("Connect timed out. Exceeded time set in configuration.connectionTimeout: "+t.configuration.connectionTimeout+"s."),e.close(1e3)},1e3*t.configuration.connectionTimeout)}),this.connectPromise}},{key:"_disconnect",value:function(){var e=this;switch(this.logger.log("Disconnecting ".concat(this.server)),this.state){case Et.Connecting:if(this.disconnectPromise)throw new Error("Disconnect promise must not be defined.");try{this.transitionState(Et.Disconnecting)}catch(e){if(e instanceof ve)return l.reject(e);throw e}break;case Et.Connected:if(this.disconnectPromise)throw new Error("Disconnect promise must not be defined.");try{this.transitionState(Et.Disconnecting)}catch(e){if(e instanceof ve)return l.reject(e);throw e}break;case Et.Disconnecting:if(this.transitioningState)return l.reject(this.transitionLoopDetectedError(Et.Disconnecting));if(!this.disconnectPromise)throw new Error("Disconnect promise must be defined.");return this.disconnectPromise;case Et.Disconnected:if(this.transitioningState)return l.reject(this.transitionLoopDetectedError(Et.Disconnecting));if(this.disconnectPromise)throw new Error("Disconnect promise must not be defined.");return l.resolve();default:throw new Error("Unknown state")}if(!this._ws)throw new Error("WebSocket must be defined.");var t=this._ws;return this.disconnectPromise=new l(function(n,r){e.disconnectResolve=n,e.disconnectReject=r;try{t.close(1e3)}catch(t){throw e.logger.error("WebSocket close failed."),e.logger.error(t.toString()),t}}),this.disconnectPromise}},{key:"_send",value:function(e){if(!0===this.configuration.traceSip&&this.logger.log("Sending WebSocket message:\n\n"+e+"\n"),this._state!==Et.Connected)return l.reject(new Error("Not connected."));if(!this._ws)throw new Error("WebSocket undefined.");try{this._ws.send(e)}catch(e){return e instanceof Error?l.reject(e):l.reject(new Error("WebSocket send failed."))}return l.resolve()}},{key:"onWebSocketClose",value:function(e,t){var n;if(t===this._ws){var r=T(n="WebSocket closed ".concat(this.server," (code: ")).call(n,e.code,")"),i=this.disconnectPromise?void 0:new Error(r);i&&this.logger.warn("WebSocket closed unexpectedly"),this.logger.log(r),this._ws=void 0,this.transitionState(Et.Disconnected,i)}}},{key:"onWebSocketError",value:function(e,t){t===this._ws&&this.logger.error("WebSocket error occurred.")}},{key:"onWebSocketMessage",value:function(e,t){if(t===this._ws){var n,r=e.data;if(/^(\r\n)+$/.test(r))return this.clearKeepAliveTimeout(),void(!0===this.configuration.traceSip&&this.logger.log("Received WebSocket message with CRLF Keep Alive response"));if(r){if("string"!=typeof r){try{n=(new TextDecoder).decode(new Uint8Array(r))}catch(e){return this.logger.error(e.toString()),void this.logger.error("Received WebSocket binary message failed to be converted into string, message discarded")}!0===this.configuration.traceSip&&this.logger.log("Received WebSocket binary message:\n\n"+n+"\n")}else n=r,!0===this.configuration.traceSip&&this.logger.log("Received WebSocket text message:\n\n"+n+"\n");if(this.state===Et.Connected){if(this.onMessage)try{this.onMessage(n)}catch(e){throw this.logger.error(e.toString()),this.logger.error("Exception thrown by onMessage callback"),e}}else this.logger.warn("Received message while not connected, discarding...")}else this.logger.warn("Received empty message, discarding...")}}},{key:"onWebSocketOpen",value:function(e,t){t===this._ws&&this._state===Et.Connecting&&(this.logger.log("WebSocket opened ".concat(this.server)),this.transitionState(Et.Connected))}},{key:"transitionLoopDetectedError",value:function(e){var t,n="A state transition loop has been detected.";return n+=T(t=" An attempt to transition from ".concat(this._state," to ")).call(t,e," before the prior transition completed."),n+=" Perhaps you are synchronously calling connect() or disconnect() from a callback or state change handler?",this.logger.error(n),new ve("Loop detected.")}},{key:"transitionState",value:function(e,t){var n,r=this,i=function(){var t;throw new Error(T(t="Invalid state transition from ".concat(r._state," to ")).call(t,e))};if(this.transitioningState)throw this.transitionLoopDetectedError(e);switch(this.transitioningState=!0,this._state){case Et.Connecting:e!==Et.Connected&&e!==Et.Disconnecting&&e!==Et.Disconnected&&i();break;case Et.Connected:e!==Et.Disconnecting&&e!==Et.Disconnected&&i();break;case Et.Disconnecting:e!==Et.Connecting&&e!==Et.Disconnected&&i();break;case Et.Disconnected:e!==Et.Connecting&&i();break;default:throw new Error("Unknown state.")}var s=this._state;this._state=e;var o=this.connectResolve,a=this.connectReject;s===Et.Connecting&&(this.connectPromise=void 0,this.connectResolve=void 0,this.connectReject=void 0);var c=this.disconnectResolve,l=this.disconnectReject;if(s===Et.Disconnecting&&(this.disconnectPromise=void 0,this.disconnectResolve=void 0,this.disconnectReject=void 0),this.connectTimeout&&(clearTimeout(this.connectTimeout),this.connectTimeout=void 0),this.logger.log(T(n="Transitioned from ".concat(s," to ")).call(n,this._state)),this._stateEventEmitter.emit(this._state),e===Et.Connected&&(this.startSendingKeepAlives(),this.onConnect))try{this.onConnect()}catch(e){throw this.logger.error(e.toString()),this.logger.error("Exception thrown by onConnect callback"),e}if(s===Et.Connected&&(this.stopSendingKeepAlives(),this.onDisconnect))try{t?this.onDisconnect(t):this.onDisconnect()}catch(e){throw this.logger.error(e.toString()),this.logger.error("Exception thrown by onDisconnect callback"),e}if(s===Et.Connecting){if(!o)throw new Error("Connect resolve undefined.");if(!a)throw new Error("Connect reject undefined.");e===Et.Connected?o():a(t||new Error("Connect aborted."))}if(s===Et.Disconnecting){if(!c)throw new Error("Disconnect resolve undefined.");if(!l)throw new Error("Disconnect reject undefined.");e===Et.Disconnected?c():l(t||new Error("Disconnect aborted."))}this.transitioningState=!1}},{key:"clearKeepAliveTimeout",value:function(){this.keepAliveDebounceTimeout&&clearTimeout(this.keepAliveDebounceTimeout),this.keepAliveDebounceTimeout=void 0}},{key:"sendKeepAlive",value:function(){var e=this;return this.keepAliveDebounceTimeout?l.resolve():(this.keepAliveDebounceTimeout=v(function(){e.clearKeepAliveTimeout()},1e3*this.configuration.keepAliveDebounce),this.send("\r\n\r\n"))}},{key:"startSendingKeepAlives",value:function(){var e,t,n=this;this.configuration.keepAliveInterval&&!this.keepAliveInterval&&(this.keepAliveInterval=U(function(){n.sendKeepAlive(),n.startSendingKeepAlives()},(e=this.configuration.keepAliveInterval,t=.8*e,1e3*(Math.random()*(e-t)+t))))}},{key:"stopSendingKeepAlives",value:function(){this.keepAliveInterval&&clearInterval(this.keepAliveInterval),this.keepAliveDebounceTimeout&&clearTimeout(this.keepAliveDebounceTimeout),this.keepAliveInterval=void 0,this.keepAliveDebounceTimeout=void 0}}])}();c(ar,"defaultOptions",{enumerable:!0,configurable:!0,writable:!0,value:{server:"",connectionTimeout:5,keepAliveInterval:0,keepAliveDebounce:10,traceSip:!0}});var cr=function(){return t(function t(){var n,r=this,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e(this,t),c(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_publishers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),c(this,"_registerers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),c(this,"_sessions",{enumerable:!0,configurable:!0,writable:!0,value:{}}),c(this,"_subscriptions",{enumerable:!0,configurable:!0,writable:!0,value:{}}),c(this,"_contact",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_instanceId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:Ct.Stopped}),c(this,"_stateEventEmitter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_transport",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"_userAgentCore",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"loggerFactory",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._stateEventEmitter=new we,this.delegate=i.delegate,this.options=H(H(H(H(H({},t.defaultOptions()),{sipjsId:_e(5)}),{uri:new Ie("sip","anonymous."+_e(6),"anonymous.invalid")}),{viaHost:_e(12)+".invalid"}),t.stripUndefinedProperties(i)),this.options.hackIpInContact)if("boolean"==typeof this.options.hackIpInContact&&this.options.hackIpInContact){var s=Math.floor(254*Math.random()+1);this.options.viaHost="192.0.2."+s}else this.options.hackIpInContact&&(this.options.viaHost=this.options.hackIpInContact);switch(this.loggerFactory=new Mt,this.logger=this.loggerFactory.getLogger("sip.UserAgent"),this.loggerFactory.builtinEnabled=this.options.logBuiltinEnabled,this.loggerFactory.connector=this.options.logConnector,this.options.logLevel){case"error":this.loggerFactory.level=Ht.error;break;case"warn":this.loggerFactory.level=Ht.warn;break;case"log":this.loggerFactory.level=Ht.log;break;case"debug":this.loggerFactory.level=Ht.debug}if(this.options.logConfiguration&&(this.logger.log("Configuration:"),u(n=E(this.options)).call(n,function(e){var t=r.options[e];switch(e){case"uri":case"sessionDescriptionHandlerFactory":r.logger.log("· "+e+": "+t);break;case"authorizationPassword":r.logger.log("· "+e+": NOT SHOWN");break;case"transportConstructor":r.logger.log("· "+e+": "+t.name);break;default:r.logger.log("· "+e+": "+I(t))}})),this.options.transportOptions){var o=this.options.transportOptions,a=o.maxReconnectionAttempts,l=o.reconnectionTimeout;if(void 0!==a){this.logger.warn('The transport option "maxReconnectionAttempts" as has apparently been specified and has been deprecated. It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.')}if(void 0!==l){this.logger.warn('The transport option "reconnectionTimeout" as has apparently been specified and has been deprecated. It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.')}void 0===i.reconnectionDelay&&void 0!==l&&(this.options.reconnectionDelay=l),void 0===i.reconnectionAttempts&&void 0!==a&&(this.options.reconnectionAttempts=a)}if(void 0!==i.reconnectionDelay){this.logger.warn('The user agent option "reconnectionDelay" as has apparently been specified and has been deprecated. It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.')}if(void 0!==i.reconnectionAttempts){this.logger.warn('The user agent option "reconnectionAttempts" as has apparently been specified and has been deprecated. It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.')}if(this._transport=new this.options.transportConstructor(this.getLogger("sip.Transport"),this.options.transportOptions),this.initTransportCallbacks(),this._contact=this.initContact(),this._instanceId=this.options.instanceId?this.options.instanceId:t.newUUID(),-1===De.parse(this._instanceId,"uuid"))throw new Error("Invalid instanceId.");this._userAgentCore=this.initCore()},[{key:"configuration",get:function(){return this.options}},{key:"contact",get:function(){return this._contact}},{key:"instanceId",get:function(){return this._instanceId}},{key:"state",get:function(){return this._state}},{key:"stateChange",get:function(){return this._stateEventEmitter}},{key:"transport",get:function(){return this._transport}},{key:"userAgentCore",get:function(){return this._userAgentCore}},{key:"getLogger",value:function(e,t){return this.loggerFactory.getLogger(e,t)}},{key:"getLoggerFactory",value:function(){return this.loggerFactory}},{key:"isConnected",value:function(){return this.transport.isConnected()}},{key:"reconnect",value:function(){var e=this;return this.state===Ct.Stopped?l.reject(new Error("User agent stopped.")):l.resolve().then(function(){return e.transport.connect()})}},{key:"start",value:function(){return this.state===Ct.Started?(this.logger.warn("User agent already started"),l.resolve()):(this.logger.log("Starting ".concat(this.configuration.uri)),this.transitionState(Ct.Started),this.transport.connect())}},{key:"stop",value:function(){return te(this,void 0,void 0,O.mark(function e(){var t,n,r,i,s,o,a,c,u,d,h,g,f,v,p,m,b,w,y,S,k,R,T=this;return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.state!==Ct.Stopped){e.next=1;break}return this.logger.warn("User agent already stopped"),e.abrupt("return",l.resolve());case 1:if(this.logger.log("Stopping ".concat(this.configuration.uri)),this.options.gracefulShutdown){e.next=2;break}return this.logger.log("Dispose of transport"),this.transport.dispose().catch(function(e){throw T.logger.error(e.message),e}),this.logger.log("Dispose of core"),this.userAgentCore.dispose(),this._publishers={},this._registerers={},this._sessions={},this._subscriptions={},this.transitionState(Ct.Stopped),e.abrupt("return",l.resolve());case 2:t=H({},this._publishers),n=H({},this._registerers),r=H({},this._sessions),i=H({},this._subscriptions),s=this.transport,o=this.userAgentCore,this.logger.log("Dispose of registerers"),a=O.mark(function e(t){return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!n[t]){e.next=1;break}return e.next=1,n[t].dispose().catch(function(e){throw T.logger.error(e.message),delete T._registerers[t],e});case 1:case"end":return e.stop()}},e)}),p=N(O).call(O,n);case 3:if((m=p()).done){e.next=5;break}return c=m.value,e.delegateYield(a(c),"t0",4);case 4:e.next=3;break;case 5:this.logger.log("Dispose of sessions"),u=O.mark(function e(t){return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!r[t]){e.next=1;break}return e.next=1,r[t].dispose().catch(function(e){throw T.logger.error(e.message),delete T._sessions[t],e});case 1:case"end":return e.stop()}},e)}),b=N(O).call(O,r);case 6:if((w=b()).done){e.next=8;break}return d=w.value,e.delegateYield(u(d),"t1",7);case 7:e.next=6;break;case 8:this.logger.log("Dispose of subscriptions"),h=O.mark(function e(t){return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!i[t]){e.next=1;break}return e.next=1,i[t].dispose().catch(function(e){throw T.logger.error(e.message),delete T._subscriptions[t],e});case 1:case"end":return e.stop()}},e)}),y=N(O).call(O,i);case 9:if((S=y()).done){e.next=11;break}return g=S.value,e.delegateYield(h(g),"t2",10);case 10:e.next=9;break;case 11:this.logger.log("Dispose of publishers"),f=O.mark(function e(n){return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!t[n]){e.next=1;break}return e.next=1,t[n].dispose().catch(function(e){throw T.logger.error(e.message),delete T._publishers[n],e});case 1:case"end":return e.stop()}},e)}),k=N(O).call(O,t);case 12:if((R=k()).done){e.next=14;break}return v=R.value,e.delegateYield(f(v),"t3",13);case 13:e.next=12;break;case 14:return this.logger.log("Dispose of transport"),e.next=15,s.dispose().catch(function(e){throw T.logger.error(e.message),e});case 15:this.logger.log("Dispose of core"),o.dispose(),this.transitionState(Ct.Stopped);case 16:case"end":return e.stop()}},e,this)}))}},{key:"_makeInviter",value:function(e,t){return new kt(this,e,t)}},{key:"attemptReconnection",value:function(){var e,t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,r=this.options.reconnectionAttempts,i=this.options.reconnectionDelay;n>r?this.logger.log("Maximum reconnection attempts reached"):(this.logger.log(T(e="Reconnection attempt ".concat(n," of ")).call(e,r," - trying")),v(function(){t.reconnect().then(function(){var e;t.logger.log(T(e="Reconnection attempt ".concat(n," of ")).call(e,r," - succeeded"))}).catch(function(e){var i;t.logger.error(e.message),t.logger.log(T(i="Reconnection attempt ".concat(n," of ")).call(i,r," - failed")),t.attemptReconnection(++n)})},1===n?0:1e3*i))}},{key:"initContact",value:function(){var e=this,t=""!==this.options.contactName?this.options.contactName:_e(8),n=this.options.contactParams,r={pubGruu:void 0,tempGruu:void 0,uri:new Ie("sip",t,this.options.viaHost,void 0,n),toString:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.anonymous||!1,i=t.outbound||!1,s=t.register||!1,o="<";return o+=r?e.contact.tempGruu||"sip:anonymous@anonymous.invalid;transport=".concat(n.transport?n.transport:"ws"):s?e.contact.uri:e.contact.pubGruu||e.contact.uri,i&&(o+=";ob"),o+=">",e.options.instanceIdAlwaysAdded&&(o+=';+sip.instance="<urn:uuid:'+e._instanceId+'>"'),o}};return r}},{key:"initCore",value:function(){var e,t=this,n=[];(n.push("outbound"),this.options.sipExtension100rel===ht.Supported&&n.push("100rel"),this.options.sipExtensionReplaces===ht.Supported&&n.push("replaces"),this.options.sipExtensionExtraSupported)&&(e=n).push.apply(e,P(this.options.sipExtensionExtraSupported));this.options.hackAllowUnregisteredOptionTags||(n=h(n).call(n,function(e){return ft[e]})),n=x(new j(n));var r=d(n).call(n);(this.contact.pubGruu||this.contact.tempGruu)&&r.push("gruu");var i={aor:this.options.uri,contact:this.contact,displayName:this.options.displayName,loggerFactory:this.loggerFactory,hackViaTcp:this.options.hackViaTcp,routeSet:this.options.preloadedRouteSet,supportedOptionTags:n,supportedOptionTagsResponse:r,sipjsId:this.options.sipjsId,userAgentHeaderFieldValue:this.options.userAgentString,viaForceRport:this.options.forceRport,viaHost:this.options.viaHost,authenticationFactory:function(){var e=t.options.authorizationUsername?t.options.authorizationUsername:t.options.uri.user,n=t.options.authorizationPassword?t.options.authorizationPassword:void 0,r=t.options.authorizationHa1?t.options.authorizationHa1:void 0;return new qt(t.getLoggerFactory(),r,e,n)},transportAccessor:function(){return t.transport}},s={onInvite:function(e){var n,r=new mt(t,e);if(e.delegate={onCancel:function(e){r._onCancel(e)},onTransportError:function(e){t.logger.error("A transport error has occurred while handling an incoming INVITE request.")}},e.trying(),t.options.sipExtensionReplaces!==ht.Unsupported){var i=e.message.parseHeader("replaces");if(i){var s=i.call_id;if("string"!=typeof s)throw new Error("Type of call id is not string");var o=i.replaces_to_tag;if("string"!=typeof o)throw new Error("Type of to tag is not string");var a=i.replaces_from_tag;if("string"!=typeof a)throw new Error("type of from tag is not string");var c=s+o+a,l=t.userAgentCore.dialogs.get(c);if(!l)return void r.reject({statusCode:481});if(!l.early&&!0===i.early_only)return void r.reject({statusCode:486});var u=t._sessions[s+a]||t._sessions[s+o]||void 0;if(!u)throw new Error("Session does not exist.");r._replacee=u}}if(null===(n=t.delegate)||void 0===n?void 0:n.onInvite)return r.autoSendAnInitialProvisionalResponse?void r.progress().then(function(){var e;if(void 0===(null===(e=t.delegate)||void 0===e?void 0:e.onInvite))throw new Error("onInvite undefined.");t.delegate.onInvite(r)}):void t.delegate.onInvite(r);r.reject({statusCode:486})},onMessage:function(e){if(t.delegate&&t.delegate.onMessage){var n=new at(e);t.delegate.onMessage(n)}else e.accept()},onNotify:function(e){if(t.delegate&&t.delegate.onNotify){var n=new ct(e);t.delegate.onNotify(n)}else t.options.allowLegacyNotifications?e.accept():e.reject({statusCode:481})},onRefer:function(e){t.logger.warn("Received an out of dialog REFER request"),t.delegate&&t.delegate.onReferRequest?t.delegate.onReferRequest(e):e.reject({statusCode:405})},onRegister:function(e){t.logger.warn("Received an out of dialog REGISTER request"),t.delegate&&t.delegate.onRegisterRequest?t.delegate.onRegisterRequest(e):e.reject({statusCode:405})},onSubscribe:function(e){t.logger.warn("Received an out of dialog SUBSCRIBE request"),t.delegate&&t.delegate.onSubscribeRequest?t.delegate.onSubscribeRequest(e):e.reject({statusCode:405})}};return new ir(i,s)}},{key:"initTransportCallbacks",value:function(){var e=this;this.transport.onConnect=function(){return e.onTransportConnect()},this.transport.onDisconnect=function(t){return e.onTransportDisconnect(t)},this.transport.onMessage=function(t){return e.onTransportMessage(t)}}},{key:"onTransportConnect",value:function(){this.state!==Ct.Stopped&&this.delegate&&this.delegate.onConnect&&this.delegate.onConnect()}},{key:"onTransportDisconnect",value:function(e){this.state!==Ct.Stopped&&(this.delegate&&this.delegate.onDisconnect&&this.delegate.onDisconnect(e),e&&this.options.reconnectionAttempts>0&&this.attemptReconnection())}},{key:"onTransportMessage",value:function(e){var t=this,n=_t.parseMessage(e,this.getLogger("sip.Parser"));if(n)if(this.state===Ct.Stopped&&n instanceof Ue)this.logger.warn("Received ".concat(n.method," request while stopped. Dropping."));else{var r=function(){for(var e=0,r=["from","to","call_id","cseq","via"];e<r.length;e++){var i=r[e];if(!n.hasHeader(i))return t.logger.warn("Missing mandatory header field : ".concat(i,".")),!1}return!0};if(n instanceof Ue){if(!r())return void this.logger.warn("Request missing mandatory header field. Dropping.");if(!n.toTag&&n.callId.substr(0,5)===this.options.sipjsId)return void this.userAgentCore.replyStateless(n,{statusCode:482});var i=Oe(n.body),s=n.getHeader("content-length");if(s&&i<Number(s))return void this.userAgentCore.replyStateless(n,{statusCode:400})}if(n instanceof Ge){if(!r())return void this.logger.warn("Response missing mandatory header field. Dropping.");if(n.getHeaders("via").length>1)return void this.logger.warn("More than one Via header field present in the response. Dropping.");if(n.via.host!==this.options.viaHost||void 0!==n.via.port)return void this.logger.warn("Via sent-by in the response does not match UA Via host value. Dropping.");var o=Oe(n.body),a=n.getHeader("content-length");if(a&&o<Number(a))return void this.logger.warn("Message body length is lower than the value in Content-Length header field. Dropping.")}if(n instanceof Ue)this.userAgentCore.receiveIncomingRequestFromTransport(n);else{if(!(n instanceof Ge))throw new Error("Invalid message type.");this.userAgentCore.receiveIncomingResponseFromTransport(n)}}else this.logger.warn("Failed to parse incoming message. Dropping.")}},{key:"transitionState",value:function(e,t){var n,r=this,i=function(){var t;throw new Error(T(t="Invalid state transition from ".concat(r._state," to ")).call(t,e))};switch(this._state){case Ct.Started:e!==Ct.Stopped&&i();break;case Ct.Stopped:e!==Ct.Started&&i();break;default:throw new Error("Unknown state.")}this.logger.log(T(n="Transitioned from ".concat(this._state," to ")).call(n,e)),this._state=e,this._stateEventEmitter.emit(this._state)}}],[{key:"makeURI",value:function(e){return De.URIParse(e)}},{key:"defaultOptions",value:function(){return{errorCallback:function(){},allowLegacyNotifications:!1,authorizationHa1:"",authorizationPassword:"",authorizationUsername:"",delegate:{},contactName:"",contactParams:{transport:"ws"},displayName:"",forceRport:!1,gracefulShutdown:!0,hackAllowUnregisteredOptionTags:!1,hackIpInContact:!1,hackViaTcp:!1,instanceId:"",instanceIdAlwaysAdded:!1,logBuiltinEnabled:!0,logConfiguration:!0,logConnector:function(){},logLevel:"log",noAnswerTimeout:60,preloadedRouteSet:[],reconnectionAttempts:0,reconnectionDelay:4,sendInitialProvisionalResponse:!0,sessionDescriptionHandlerFactory:or(),sessionDescriptionHandlerFactoryOptions:{},sipExtension100rel:ht.Unsupported,sipExtensionReplaces:ht.Unsupported,sipExtensionExtraSupported:[],sipjsId:"",transportConstructor:ar,transportOptions:{},uri:new Ie("sip","anonymous","anonymous.invalid"),userAgentString:"SIP.js/0.21.17",viaHost:""}}},{key:"newUUID",value:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=Math.floor(16*Math.random());return("x"===e?t:t%4+8).toString(16)})}},{key:"stripUndefinedProperties",value:function(e){var t;return M(t=E(e)).call(t,function(t,n){return void 0!==e[n]&&(t[n]=e[n]),t},{})}}])}();var lr,ur,dr,hr,gr,fr,vr=function(){return t(function t(n){var r=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,t),c(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"managedSessions",{enumerable:!0,configurable:!0,writable:!0,value:[]}),c(this,"userAgent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"attemptingReconnection",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"optionsPingFailure",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(this,"optionsPingRequest",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"optionsPingRunning",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(this,"optionsPingTimeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"registrationAttemptTimeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"registerer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"registererOptions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"registererRegisterOptions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"shouldBeConnected",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(this,"shouldBeRegistered",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this.delegate=i.delegate,this.options=H({aor:"",autoStop:!0,delegate:{},iceStopWaitingOnServerReflexive:!1,managedSessionFactory:function(e,t){return{session:t,held:!1,muted:!1}},maxSimultaneousSessions:2,media:{},optionsPingInterval:-1,optionsPingRequestURI:"",reconnectionAttempts:3,reconnectionDelay:4,registrationRetry:!1,registrationRetryInterval:3,registerGuard:null,registererOptions:{},registererRegisterOptions:{},sendDTMFUsingSessionDescriptionHandler:!1,userAgentOptions:{}},t.stripUndefinedProperties(i));var s=H({},i.userAgentOptions);if(s.transportConstructor||(s.transportConstructor=ar),s.transportOptions||(s.transportOptions={server:n}),!s.uri&&i.aor){var o=cr.makeURI(i.aor);if(!o)throw new Error("Failed to create valid URI from ".concat(i.aor));s.uri=o}if(this.userAgent=new cr(s),this.userAgent.delegate={onConnect:function(){r.logger.log("Connected"),r.delegate&&r.delegate.onServerConnect&&r.delegate.onServerConnect(),r.shouldBeRegistered&&r.register(),r.options.optionsPingInterval>0&&r.optionsPingStart()},onDisconnect:function(e){return te(r,void 0,void 0,O.mark(function t(){var n,r,i,s,o=this;return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:this.logger.log("Disconnected"),n=!1,this.options.optionsPingInterval>0&&(n=this.optionsPingFailure,this.optionsPingFailure=!1,this.optionsPingStop()),this.delegate&&this.delegate.onServerDisconnect&&this.delegate.onServerDisconnect(e),(e||n)&&(this.registerer&&(this.logger.log("Disposing of registerer..."),this.registerer.dispose().catch(function(e){o.logger.debug("Error occurred disposing of registerer after connection with server was lost."),o.logger.debug(e.toString())}),this.registerer=void 0),u(r=m(i=d(s=this.managedSessions).call(s)).call(i,function(e){return e.session})).call(r,function(e){return te(o,void 0,void 0,O.mark(function t(){var n=this;return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:this.logger.log("Disposing of session..."),e.dispose().catch(function(e){n.logger.debug("Error occurred disposing of a session after connection with server was lost."),n.logger.debug(e.toString())});case 1:case"end":return t.stop()}},t,this)}))}),this.shouldBeConnected&&this.attemptReconnection());case 1:case"end":return t.stop()}},t,this)}))},onInvite:function(e){r.logger.log("[".concat(e.id,"] Received INVITE"));var t=r.options.maxSimultaneousSessions;if(0!==t&&r.managedSessions.length>t)return r.logger.warn("[".concat(e.id,"] Session already in progress, rejecting INVITE...")),void e.reject().then(function(){r.logger.log("[".concat(e.id,"] Rejected INVITE"))}).catch(function(t){r.logger.error("[".concat(e.id,"] Failed to reject INVITE")),r.logger.error(t.toString())});var n={sessionDescriptionHandlerOptions:{constraints:r.constraints}};r.initSession(e,n),r.delegate&&r.delegate.onCallReceived?r.delegate.onCallReceived(e):(r.logger.warn("[".concat(e.id,"] No handler available, rejecting INVITE...")),e.reject().then(function(){r.logger.log("[".concat(e.id,"] Rejected INVITE"))}).catch(function(t){r.logger.error("[".concat(e.id,"] Failed to reject INVITE")),r.logger.error(t.toString())}))},onMessage:function(e){e.accept().then(function(){r.delegate&&r.delegate.onMessageReceived&&r.delegate.onMessageReceived(e)})},onNotify:function(e){e.accept().then(function(){r.delegate&&r.delegate.onNotificationReceived&&r.delegate.onNotificationReceived(e)})}},this.registererOptions=H({},i.registererOptions),this.registererRegisterOptions=H({},i.registererRegisterOptions),this.options.registrationRetry){this.registererRegisterOptions.requestDelegate=this.registererRegisterOptions.requestDelegate||{};var a=this.registererRegisterOptions.requestDelegate.onReject;this.registererRegisterOptions.requestDelegate.onReject=function(e){a&&a(e),r.attemptRegistration()}}this.logger=this.userAgent.getLogger("sip.SessionManager"),window.addEventListener("online",function(){r.logger.log("Online"),r.shouldBeConnected&&r.connect()}),this.options.autoStop&&window.addEventListener("beforeunload",function(){return te(r,void 0,void 0,O.mark(function e(){return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.shouldBeConnected=!1,this.shouldBeRegistered=!1,this.userAgent.state===Ct.Stopped){e.next=1;break}return e.next=1,this.userAgent.stop();case 1:case"end":return e.stop()}},e,this)}))})},[{key:"getLocalMediaStream",value:function(e){var t=e.sessionDescriptionHandler;if(t){if(!(t instanceof sr))throw new Error("Session description handler not instance of web SessionDescriptionHandler");return t.localMediaStream}}},{key:"getRemoteMediaStream",value:function(e){var t=e.sessionDescriptionHandler;if(t){if(!(t instanceof sr))throw new Error("Session description handler not instance of web SessionDescriptionHandler");return t.remoteMediaStream}}},{key:"getLocalAudioTrack",value:function(e){var t,n;return null===(n=this.getLocalMediaStream(e))||void 0===n?void 0:V(t=n.getTracks()).call(t,function(e){return"audio"===e.kind})}},{key:"getLocalVideoTrack",value:function(e){var t,n;return null===(n=this.getLocalMediaStream(e))||void 0===n?void 0:V(t=n.getTracks()).call(t,function(e){return"video"===e.kind})}},{key:"getRemoteAudioTrack",value:function(e){var t,n;return null===(n=this.getRemoteMediaStream(e))||void 0===n?void 0:V(t=n.getTracks()).call(t,function(e){return"audio"===e.kind})}},{key:"getRemoteVideoTrack",value:function(e){var t,n;return null===(n=this.getRemoteMediaStream(e))||void 0===n?void 0:V(t=n.getTracks()).call(t,function(e){return"video"===e.kind})}},{key:"connect",value:function(){return te(this,void 0,void 0,O.mark(function e(){return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.logger.log("Connecting UserAgent..."),this.shouldBeConnected=!0,this.userAgent.state===Ct.Started){e.next=1;break}return e.abrupt("return",this.userAgent.start());case 1:return e.abrupt("return",this.userAgent.reconnect());case 2:case"end":return e.stop()}},e,this)}))}},{key:"disconnect",value:function(){return te(this,void 0,void 0,O.mark(function e(){return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.logger.log("Disconnecting UserAgent..."),this.userAgent.state!==Ct.Stopped){e.next=1;break}return e.abrupt("return",l.resolve());case 1:return this.shouldBeConnected=!1,this.shouldBeRegistered=!1,this.registerer=void 0,e.abrupt("return",this.userAgent.stop());case 2:case"end":return e.stop()}},e,this)}))}},{key:"isConnected",value:function(){return this.userAgent.isConnected()}},{key:"register",value:function(e){return te(this,void 0,void 0,O.mark(function t(){var n=this;return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.logger.log("Registering UserAgent..."),this.shouldBeRegistered=!0,void 0!==e&&(this.registererRegisterOptions=H({},e)),this.registerer||(this.registerer=new xt(this.userAgent,this.registererOptions),this.registerer.stateChange.addListener(function(e){switch(e){case St.Initial:break;case St.Registered:n.delegate&&n.delegate.onRegistered&&n.delegate.onRegistered();break;case St.Unregistered:n.delegate&&n.delegate.onUnregistered&&n.delegate.onUnregistered(),n.shouldBeRegistered&&n.attemptRegistration();break;case St.Terminated:break;default:throw new Error("Unknown registerer state.")}})),t.abrupt("return",this.attemptRegistration(!0));case 1:case"end":return t.stop()}},t,this)}))}},{key:"unregister",value:function(e){return te(this,void 0,void 0,O.mark(function t(){return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.logger.log("Unregistering UserAgent..."),this.shouldBeRegistered=!1,this.registerer){t.next=1;break}return this.logger.warn("No registerer to unregister."),t.abrupt("return",l.resolve());case 1:return t.abrupt("return",this.registerer.unregister(e).then(function(){}));case 2:case"end":return t.stop()}},t,this)}))}},{key:"call",value:function(e,t,n){return te(this,void 0,void 0,O.mark(function r(){var i,s,o,a,c=this;return O.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(this.logger.log("Beginning Session..."),!(0!==(i=this.options.maxSimultaneousSessions)&&this.managedSessions.length>i)){r.next=1;break}return r.abrupt("return",l.reject(new Error("Maximum number of sessions already exists.")));case 1:if(s=cr.makeURI(e)){r.next=2;break}return r.abrupt("return",l.reject(new Error('Failed to create a valid URI from "'.concat(e,'"'))));case 2:return t||(t={}),t.sessionDescriptionHandlerOptions||(t.sessionDescriptionHandlerOptions={}),t.sessionDescriptionHandlerOptions.constraints||(t.sessionDescriptionHandlerOptions.constraints=this.constraints),t.earlyMedia&&((n=n||{}).requestDelegate=n.requestDelegate||{},o=n.requestDelegate.onProgress,n.requestDelegate.onProgress=function(e){183===e.message.statusCode&&c.setupRemoteMedia(a),o&&o(e)}),this.options.iceStopWaitingOnServerReflexive&&(t.delegate=t.delegate||{},t.delegate.onSessionDescriptionHandler=function(e){if(!(e instanceof sr))throw new Error("Session description handler not instance of SessionDescriptionHandler");e.peerConnectionDelegate={onicecandidate:function(t){var n;"srflx"===(null===(n=t.candidate)||void 0===n?void 0:n.type)&&(c.logger.log("[".concat(a.id,"] Found srflx ICE candidate, stop waiting...")),e.iceGatheringComplete())}}}),a=new kt(this.userAgent,s,t),r.abrupt("return",this.sendInvite(a,t,n).then(function(){return a}));case 3:case"end":return r.stop()}},r,this)}))}},{key:"hangup",value:function(e){return te(this,void 0,void 0,O.mark(function t(){return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.logger.log("[".concat(e.id,"] Hangup...")),this.sessionExists(e)){t.next=1;break}return t.abrupt("return",l.reject(new Error("Session does not exist.")));case 1:return t.abrupt("return",this.terminate(e));case 2:case"end":return t.stop()}},t,this)}))}},{key:"answer",value:function(e,t){return te(this,void 0,void 0,O.mark(function n(){return O.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.logger.log("[".concat(e.id,"] Accepting Invitation...")),this.sessionExists(e)){n.next=1;break}return n.abrupt("return",l.reject(new Error("Session does not exist.")));case 1:if(e instanceof mt){n.next=2;break}return n.abrupt("return",l.reject(new Error("Session not instance of Invitation.")));case 2:return t||(t={}),t.sessionDescriptionHandlerOptions||(t.sessionDescriptionHandlerOptions={}),t.sessionDescriptionHandlerOptions.constraints||(t.sessionDescriptionHandlerOptions.constraints=this.constraints),n.abrupt("return",e.accept(t));case 3:case"end":return n.stop()}},n,this)}))}},{key:"decline",value:function(e){return te(this,void 0,void 0,O.mark(function t(){return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.logger.log("[".concat(e.id,"] Rejecting Invitation...")),this.sessionExists(e)){t.next=1;break}return t.abrupt("return",l.reject(new Error("Session does not exist.")));case 1:if(e instanceof mt){t.next=2;break}return t.abrupt("return",l.reject(new Error("Session not instance of Invitation.")));case 2:return t.abrupt("return",e.reject());case 3:case"end":return t.stop()}},t,this)}))}},{key:"hold",value:function(e){return te(this,void 0,void 0,O.mark(function t(){return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.logger.log("[".concat(e.id,"] Holding session...")),t.abrupt("return",this.setHold(e,!0));case 1:case"end":return t.stop()}},t,this)}))}},{key:"unhold",value:function(e){return te(this,void 0,void 0,O.mark(function t(){return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.logger.log("[".concat(e.id,"] Unholding session...")),t.abrupt("return",this.setHold(e,!1));case 1:case"end":return t.stop()}},t,this)}))}},{key:"isHeld",value:function(e){var t=this.sessionManaged(e);return!!t&&t.held}},{key:"mute",value:function(e){this.logger.log("[".concat(e.id,"] Disabling media tracks...")),this.setMute(e,!0)}},{key:"unmute",value:function(e){this.logger.log("[".concat(e.id,"] Enabling media tracks...")),this.setMute(e,!1)}},{key:"isMuted",value:function(e){var t=this.sessionManaged(e);return!!t&&t.muted}},{key:"sendDTMF",value:function(e,t){return te(this,void 0,void 0,O.mark(function n(){var r,i;return O.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.logger.log("[".concat(e.id,"] Sending DTMF...")),/^[0-9A-D#*,]$/.exec(t)){n.next=1;break}return n.abrupt("return",l.reject(new Error("Invalid DTMF tone.")));case 1:if(this.sessionExists(e)){n.next=2;break}return n.abrupt("return",l.reject(new Error("Session does not exist.")));case 2:if(this.logger.log(T(r="[".concat(e.id,"] Sending DTMF tone: ")).call(r,t)),!this.options.sendDTMFUsingSessionDescriptionHandler){n.next=5;break}if(e.sessionDescriptionHandler){n.next=3;break}return n.abrupt("return",l.reject(new Error("Session desciption handler undefined.")));case 3:if(e.sessionDescriptionHandler.sendDtmf(t)){n.next=4;break}return n.abrupt("return",l.reject(new Error("Failed to send DTMF")));case 4:return n.abrupt("return",l.resolve());case 5:return i={body:{contentDisposition:"render",contentType:"application/dtmf-relay",content:"Signal="+t+"\r\nDuration=2000"}},n.abrupt("return",e.info({requestOptions:i}).then(function(){}));case 6:case"end":return n.stop()}},n,this)}))}},{key:"transfer",value:function(e,t,n){return te(this,void 0,void 0,O.mark(function r(){var i;return O.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(this.logger.log("[".concat(e.id,"] Referring session...")),!(t instanceof gt)){r.next=1;break}return r.abrupt("return",e.refer(t,n).then(function(){}));case 1:if(i=cr.makeURI(t)){r.next=2;break}return r.abrupt("return",l.reject(new Error('Failed to create a valid URI from "'.concat(t,'"'))));case 2:return r.abrupt("return",e.refer(i,n).then(function(){}));case 3:case"end":return r.stop()}},r,this)}))}},{key:"message",value:function(e,t){return te(this,void 0,void 0,O.mark(function n(){var r;return O.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.logger.log("Sending message..."),r=cr.makeURI(e)){n.next=1;break}return n.abrupt("return",l.reject(new Error('Failed to create a valid URI from "'.concat(e,'"'))));case 1:return n.abrupt("return",new Rt(this.userAgent,r,t).message());case 2:case"end":return n.stop()}},n,this)}))}},{key:"constraints",get:function(){var e={audio:!0,video:!1};return this.options.media.constraints&&(e=H({},this.options.media.constraints)),e}},{key:"attemptReconnection",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,n=this.options.reconnectionAttempts,r=this.options.reconnectionDelay;if(this.shouldBeConnected)if(this.attemptingReconnection&&this.logger.log("Reconnection attempt already in progress"),t>n)this.logger.log("Reconnection maximum attempts reached");else{var i,s,o;if(1===t)this.logger.log(T(i="Reconnection attempt ".concat(t," of ")).call(i,n," - trying"));else this.logger.log(T(s=T(o="Reconnection attempt ".concat(t," of ")).call(o,n," - trying in ")).call(s,r," seconds"));this.attemptingReconnection=!0,v(function(){var r;if(!e.shouldBeConnected)return e.logger.log(T(r="Reconnection attempt ".concat(t," of ")).call(r,n," - aborted")),void(e.attemptingReconnection=!1);e.userAgent.reconnect().then(function(){var r;e.logger.log(T(r="Reconnection attempt ".concat(t," of ")).call(r,n," - succeeded")),e.attemptingReconnection=!1}).catch(function(r){var i;e.logger.log(T(i="Reconnection attempt ".concat(t," of ")).call(i,n," - failed")),e.logger.error(r.message),e.attemptingReconnection=!1,e.attemptReconnection(++t)})},1===t?0:1e3*r)}else this.logger.log("Should not be connected currently")}},{key:"attemptRegistration",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(this.logger.log("Registration attempt ".concat(t?"without delay":"")),!this.shouldBeRegistered)return this.logger.log("Should not be registered currently"),l.resolve();if(void 0!==this.registrationAttemptTimeout)return this.logger.log("Registration attempt already in progress"),l.resolve();return new l(function(n,r){var i,s;e.registrationAttemptTimeout=v(function(){(e.registerer?e.isConnected()?e.userAgent.state===Ct.Stopped?(e.logger.log("User agent stopped"),l.resolve()):e.options.registerGuard?e.options.registerGuard().catch(function(t){throw e.logger.log("Register guard rejected will making registration attempt"),t}).then(function(t){return t||!e.registerer?l.resolve():e.registerer.register(e.registererRegisterOptions).then(function(){})}):e.registerer.register(e.registererRegisterOptions).then(function(){}):(e.logger.log("User agent not connected"),l.resolve()):(e.logger.log("Registerer undefined"),l.resolve())).then(function(){e.registrationAttemptTimeout=void 0,n()}).catch(function(t){e.registrationAttemptTimeout=void 0,t instanceof le?n():r(t)})},t?0:(i=e.options.registrationRetryInterval,s=2*i,1e3*(Math.random()*(s-i)+i)))})}},{key:"cleanupMedia",value:function(e){var t=this.sessionManaged(e);if(!t)throw new Error("Managed session does not exist.");t.mediaLocal&&t.mediaLocal.video&&(t.mediaLocal.video.srcObject=null,t.mediaLocal.video.pause()),t.mediaRemote&&(t.mediaRemote.audio&&(t.mediaRemote.audio.srcObject=null,t.mediaRemote.audio.pause()),t.mediaRemote.video&&(t.mediaRemote.video.srcObject=null,t.mediaRemote.video.pause()))}},{key:"enableReceiverTracks",value:function(e,t){if(!this.sessionExists(e))throw new Error("Session does not exist.");var n=e.sessionDescriptionHandler;if(!(n instanceof sr))throw new Error("Session's session description handler not instance of SessionDescriptionHandler.");n.enableReceiverTracks(t)}},{key:"enableSenderTracks",value:function(e,t){if(!this.sessionExists(e))throw new Error("Session does not exist.");var n=e.sessionDescriptionHandler;if(!(n instanceof sr))throw new Error("Session's session description handler not instance of SessionDescriptionHandler.");n.enableSenderTracks(t)}},{key:"initSession",value:function(e,t){var n=this;this.sessionAdd(e),this.delegate&&this.delegate.onCallCreated&&this.delegate.onCallCreated(e),e.stateChange.addListener(function(t){var r;switch(n.logger.log(T(r="[".concat(e.id,"] Session state changed to ")).call(r,t)),t){case exports.SessionState.Initial:case exports.SessionState.Establishing:break;case exports.SessionState.Established:n.setupLocalMedia(e),n.setupRemoteMedia(e),n.delegate&&n.delegate.onCallAnswered&&n.delegate.onCallAnswered(e);break;case exports.SessionState.Terminating:case exports.SessionState.Terminated:n.sessionExists(e)&&(n.cleanupMedia(e),n.sessionRemove(e),n.delegate&&n.delegate.onCallHangup&&n.delegate.onCallHangup(e));break;default:throw new Error("Unknown session state.")}}),e.delegate=e.delegate||{},e.delegate.onInfo=function(t){var r;if(void 0!==(null===(r=n.delegate)||void 0===r?void 0:r.onCallDTMFReceived)){var i=t.request.getHeader("content-type");if(i&&/^application\/dtmf-relay/i.exec(i)){var s=t.request.body.split("\r\n",2);if(2===s.length){var o,a=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/;if(void 0!==s[0]&&a.test(s[0])&&(o=s[0].replace(a,"$2")),o){var c,l=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;void 0!==s[1]&&l.test(s[1])&&(c=y(s[1].replace(l,"$2"),10)),c?t.accept().then(function(){if(n.delegate&&n.delegate.onCallDTMFReceived){if(!o||!c)throw new Error("Tone or duration undefined.");n.delegate.onCallDTMFReceived(e,o,c)}}).catch(function(e){n.logger.error(e.message)}):t.reject()}else t.reject()}else t.reject()}else t.reject()}else t.reject()},e.delegate.onRefer=function(e){e.accept().then(function(){return n.sendInvite(e.makeInviter(t),t)}).catch(function(e){n.logger.error(e.message)})}}},{key:"optionsPingRun",value:function(e,t,n){var r=this;if(this.options.optionsPingInterval<1)throw new Error("Invalid options ping interval.");this.optionsPingRunning||(this.optionsPingRunning=!0,this.optionsPingTimeout=v(function(){r.optionsPingTimeout=void 0;var i=function(){r.optionsPingFailure=!1,r.optionsPingRunning&&(r.optionsPingRunning=!1,r.optionsPingRun(e,t,n))},s=r.userAgent.userAgentCore,o=s.makeOutgoingRequestMessage("OPTIONS",e,t,n,{});r.optionsPingRequest=s.request(o,{onAccept:function(){r.optionsPingRequest=void 0,i()},onReject:function(e){r.optionsPingRequest=void 0,408===e.message.statusCode||503===e.message.statusCode?(r.logger.error("OPTIONS ping failed"),r.optionsPingFailure=!0,r.optionsPingRunning=!1,r.userAgent.transport.disconnect().catch(function(e){return r.logger.error(e)})):i()}})},1e3*this.options.optionsPingInterval))}},{key:"optionsPingStart",value:function(){var e,t,n;if(this.logger.log("OPTIONS pings started"),this.options.optionsPingRequestURI){if(!(e=cr.makeURI(this.options.optionsPingRequestURI)))throw new Error("Failed to create Request URI.");t=this.userAgent.contact.uri.clone(),n=this.userAgent.contact.uri.clone()}else{if(!this.options.aor)return void this.logger.error("You have enabled sending OPTIONS pings and as such you must provide either a) an AOR to register, or b) an RURI to use for the target of the OPTIONS ping requests. ");var r=cr.makeURI(this.options.aor);if(!r)throw new Error("Failed to create URI.");(e=r.clone()).user=void 0,t=r.clone(),n=r.clone()}this.optionsPingRun(e,t,n)}},{key:"optionsPingStop",value:function(){this.logger.log("OPTIONS pings stopped"),this.optionsPingRunning=!1,this.optionsPingFailure=!1,this.optionsPingRequest&&(this.optionsPingRequest.dispose(),this.optionsPingRequest=void 0),this.optionsPingTimeout&&(clearTimeout(this.optionsPingTimeout),this.optionsPingTimeout=void 0)}},{key:"sendInvite",value:function(e,t,n){return te(this,void 0,void 0,O.mark(function r(){var i=this;return O.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return this.initSession(e,t),r.abrupt("return",e.invite(n).then(function(){i.logger.log("[".concat(e.id,"] Sent INVITE"))}));case 1:case"end":return r.stop()}},r,this)}))}},{key:"sessionAdd",value:function(e){var t=this.options.managedSessionFactory(this,e);this.managedSessions.push(t)}},{key:"sessionExists",value:function(e){return void 0!==this.sessionManaged(e)}},{key:"sessionManaged",value:function(e){var t;return V(t=this.managedSessions).call(t,function(t){return t.session.id===e.id})}},{key:"sessionRemove",value:function(e){var t;this.managedSessions=h(t=this.managedSessions).call(t,function(t){return t.session.id!==e.id})}},{key:"setHold",value:function(e,t){return te(this,void 0,void 0,O.mark(function n(){var r,i,s,o=this;return O.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.sessionExists(e)){n.next=1;break}return n.abrupt("return",l.reject(new Error("Session does not exist.")));case 1:if(this.isHeld(e)!==t){n.next=2;break}return n.abrupt("return",l.resolve());case 2:if(e.sessionDescriptionHandler instanceof sr){n.next=3;break}throw new Error("Session's session description handler not instance of SessionDescriptionHandler.");case 3:if(r={requestDelegate:{onAccept:function(){var n=o.sessionManaged(e);void 0!==n&&(n.held=t,o.enableReceiverTracks(e,!n.held),o.enableSenderTracks(e,!n.held&&!n.muted),o.delegate&&o.delegate.onCallHold&&o.delegate.onCallHold(e,n.held))},onReject:function(){o.logger.warn("[".concat(e.id,"] Re-invite request was rejected"));var n=o.sessionManaged(e);void 0!==n&&(n.held=!t,o.enableReceiverTracks(e,!n.held),o.enableSenderTracks(e,!n.held&&!n.muted),o.delegate&&o.delegate.onCallHold&&o.delegate.onCallHold(e,n.held))}}},(i=e.sessionDescriptionHandlerOptionsReInvite).hold=t,e.sessionDescriptionHandlerOptionsReInvite=i,s=this.sessionManaged(e)){n.next=4;break}throw new Error("Managed session is undefiend.");case 4:return s.held=t,n.abrupt("return",e.invite(r).then(function(){var t=o.sessionManaged(e);void 0!==t&&(o.enableReceiverTracks(e,!t.held),o.enableSenderTracks(e,!t.held&&!t.muted))}).catch(function(n){throw s.held=!t,n instanceof le&&o.logger.error("[".concat(e.id,"] A hold request is already in progress.")),n}));case 5:case"end":return n.stop()}},n,this)}))}},{key:"setMute",value:function(e,t){if(this.sessionExists(e))if(e.state===exports.SessionState.Established){var n=this.sessionManaged(e);void 0!==n&&(n.muted=t,this.enableSenderTracks(e,!n.held&&!n.muted))}else this.logger.warn("[".concat(e.id,"] An established session is required to enable/disable media tracks"));else this.logger.warn("[".concat(e.id,"] A session is required to enabled/disable media tracks"))}},{key:"setupLocalMedia",value:function(e){var t=this,n=this.sessionManaged(e);if(!n)throw new Error("Managed session does not exist.");var r="function"==typeof this.options.media.local?this.options.media.local(e):this.options.media.local;n.mediaLocal=r;var i=null==r?void 0:r.video;if(i){var s=this.getLocalMediaStream(e);if(!s)throw new Error("Local media stream undefiend.");i.srcObject=s,i.volume=0,i.play().catch(function(n){t.logger.error("[".concat(e.id,"] Failed to play local media")),t.logger.error(n.message)})}}},{key:"setupRemoteMedia",value:function(e){var t=this,n=this.sessionManaged(e);if(!n)throw new Error("Managed session does not exist.");var r="function"==typeof this.options.media.remote?this.options.media.remote(e):this.options.media.remote;n.mediaRemote=r;var i=(null==r?void 0:r.video)||(null==r?void 0:r.audio);if(i){var s=this.getRemoteMediaStream(e);if(!s)throw new Error("Remote media stream undefiend.");i.autoplay=!0,i.srcObject=s,i.play().catch(function(n){t.logger.error("[".concat(e.id,"] Failed to play remote media")),t.logger.error(n.message)}),s.onaddtrack=function(){t.logger.log("Remote media onaddtrack"),i.load(),i.play().catch(function(n){t.logger.error("[".concat(e.id,"] Failed to play remote media")),t.logger.error(n.message)})}}}},{key:"terminate",value:function(e){return te(this,void 0,void 0,O.mark(function t(){var n,r,i=this;return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:this.logger.log("[".concat(e.id,"] Terminating...")),r=e.state,t.next=r===exports.SessionState.Initial?1:r===exports.SessionState.Establishing?4:r===exports.SessionState.Established?7:r===exports.SessionState.Terminating?8:r===exports.SessionState.Terminated?9:10;break;case 1:if(!(e instanceof kt)){t.next=2;break}return t.abrupt("return",e.cancel().then(function(){i.logger.log("[".concat(e.id,"] Inviter never sent INVITE (canceled)"))}));case 2:if(!(e instanceof mt)){t.next=3;break}return t.abrupt("return",e.reject().then(function(){i.logger.log("[".concat(e.id,"] Invitation rejected (sent 480)"))}));case 3:case 6:throw new Error("Unknown session type.");case 4:if(!(e instanceof kt)){t.next=5;break}return t.abrupt("return",e.cancel().then(function(){i.logger.log("[".concat(e.id,"] Inviter canceled (sent CANCEL)"))}));case 5:if(!(e instanceof mt)){t.next=6;break}return t.abrupt("return",e.reject().then(function(){i.logger.log("[".concat(e.id,"] Invitation rejected (sent 480)"))}));case 7:return t.abrupt("return",e.bye().then(function(){i.logger.log("[".concat(e.id,"] Session ended (sent BYE)"))}));case 8:case 9:return t.abrupt("continue",11);case 10:throw new Error("Unknown state");case 11:return this.logger.log(T(n="[".concat(e.id,"] Terminating in state ")).call(n,e.state,", no action taken")),t.abrupt("return",l.resolve());case 12:case"end":return t.stop()}},t,this)}))}}],[{key:"stripUndefinedProperties",value:function(e){var t;return M(t=E(e)).call(t,function(t,n){return void 0!==e[n]&&(t[n]=e[n]),t},{})}}])}(),pr=function(){return t(function t(n){var r=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,t),c(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"session",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"sessionManager",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.delegate=i.delegate,this.options=H({},i);var s={aor:this.options.aor,delegate:{onCallAnswered:function(){var e,t;return null===(t=null===(e=r.delegate)||void 0===e?void 0:e.onCallAnswered)||void 0===t?void 0:t.call(e)},onCallCreated:function(e){var t,n;r.session=e,null===(n=null===(t=r.delegate)||void 0===t?void 0:t.onCallCreated)||void 0===n||n.call(t)},onCallReceived:function(){var e,t;return null===(t=null===(e=r.delegate)||void 0===e?void 0:e.onCallReceived)||void 0===t?void 0:t.call(e)},onCallHangup:function(){var e,t;r.session=void 0,(null===(e=r.delegate)||void 0===e?void 0:e.onCallHangup)&&(null===(t=r.delegate)||void 0===t||t.onCallHangup())},onCallHold:function(e,t){var n,i;return null===(i=null===(n=r.delegate)||void 0===n?void 0:n.onCallHold)||void 0===i?void 0:i.call(n,t)},onCallDTMFReceived:function(e,t,n){var i,s;return null===(s=null===(i=r.delegate)||void 0===i?void 0:i.onCallDTMFReceived)||void 0===s?void 0:s.call(i,t,n)},onMessageReceived:function(e){var t,n;return null===(n=null===(t=r.delegate)||void 0===t?void 0:t.onMessageReceived)||void 0===n?void 0:n.call(t,e.request.body)},onRegistered:function(){var e,t;return null===(t=null===(e=r.delegate)||void 0===e?void 0:e.onRegistered)||void 0===t?void 0:t.call(e)},onUnregistered:function(){var e,t;return null===(t=null===(e=r.delegate)||void 0===e?void 0:e.onUnregistered)||void 0===t?void 0:t.call(e)},onServerConnect:function(){var e,t;return null===(t=null===(e=r.delegate)||void 0===e?void 0:e.onServerConnect)||void 0===t?void 0:t.call(e)},onServerDisconnect:function(){var e,t;return null===(t=null===(e=r.delegate)||void 0===e?void 0:e.onServerDisconnect)||void 0===t?void 0:t.call(e)}},maxSimultaneousSessions:1,media:this.options.media,reconnectionAttempts:this.options.reconnectionAttempts,reconnectionDelay:this.options.reconnectionDelay,registererOptions:this.options.registererOptions,sendDTMFUsingSessionDescriptionHandler:this.options.sendDTMFUsingSessionDescriptionHandler,userAgentOptions:this.options.userAgentOptions};this.sessionManager=new vr(n,s),this.logger=this.sessionManager.userAgent.getLogger("sip.SimpleUser")},[{key:"id",get:function(){return this.options.userAgentOptions&&this.options.userAgentOptions.displayName||"Anonymous"}},{key:"localMediaStream",get:function(){return this.session&&this.sessionManager.getLocalMediaStream(this.session)}},{key:"remoteMediaStream",get:function(){return this.session&&this.sessionManager.getRemoteMediaStream(this.session)}},{key:"localAudioTrack",get:function(){return this.session&&this.sessionManager.getLocalAudioTrack(this.session)}},{key:"localVideoTrack",get:function(){return this.session&&this.sessionManager.getLocalVideoTrack(this.session)}},{key:"remoteAudioTrack",get:function(){return this.session&&this.sessionManager.getRemoteAudioTrack(this.session)}},{key:"remoteVideoTrack",get:function(){return this.session&&this.sessionManager.getRemoteVideoTrack(this.session)}},{key:"connect",value:function(){return this.logger.log("[".concat(this.id,"] Connecting UserAgent...")),this.sessionManager.connect()}},{key:"disconnect",value:function(){return this.logger.log("[".concat(this.id,"] Disconnecting UserAgent...")),this.sessionManager.disconnect()}},{key:"isConnected",value:function(){return this.sessionManager.isConnected()}},{key:"register",value:function(e){return this.logger.log("[".concat(this.id,"] Registering UserAgent...")),this.sessionManager.register(e)}},{key:"unregister",value:function(e){return this.logger.log("[".concat(this.id,"] Unregistering UserAgent...")),this.sessionManager.unregister(e)}},{key:"call",value:function(e,t,n){return this.logger.log("[".concat(this.id,"] Beginning Session...")),this.session?l.reject(new Error("Session already exists.")):this.sessionManager.call(e,t,n).then(function(){})}},{key:"hangup",value:function(){var e=this;return this.logger.log("[".concat(this.id,"] Hangup...")),this.session?this.sessionManager.hangup(this.session).then(function(){e.session=void 0}):l.reject(new Error("Session does not exist."))}},{key:"answer",value:function(e){return this.logger.log("[".concat(this.id,"] Accepting Invitation...")),this.session?this.sessionManager.answer(this.session,e):l.reject(new Error("Session does not exist."))}},{key:"decline",value:function(){return this.logger.log("[".concat(this.id,"] rejecting Invitation...")),this.session?this.sessionManager.decline(this.session):l.reject(new Error("Session does not exist."))}},{key:"hold",value:function(){return this.logger.log("[".concat(this.id,"] holding session...")),this.session?this.sessionManager.hold(this.session):l.reject(new Error("Session does not exist."))}},{key:"unhold",value:function(){return this.logger.log("[".concat(this.id,"] unholding session...")),this.session?this.sessionManager.unhold(this.session):l.reject(new Error("Session does not exist."))}},{key:"isHeld",value:function(){return!!this.session&&this.sessionManager.isHeld(this.session)}},{key:"mute",value:function(){return this.logger.log("[".concat(this.id,"] disabling media tracks...")),this.session&&this.sessionManager.mute(this.session)}},{key:"unmute",value:function(){return this.logger.log("[".concat(this.id,"] enabling media tracks...")),this.session&&this.sessionManager.unmute(this.session)}},{key:"isMuted",value:function(){return!!this.session&&this.sessionManager.isMuted(this.session)}},{key:"sendDTMF",value:function(e){return this.logger.log("[".concat(this.id,"] sending DTMF...")),this.session?this.sessionManager.sendDTMF(this.session,e):l.reject(new Error("Session does not exist."))}},{key:"message",value:function(e,t){return this.logger.log("[".concat(this.id,"] sending message...")),this.sessionManager.message(e,t)}}])}(),mr=T(lr="sip:".concat("","@")).call(lr,""),br=T(ur="".concat("","://")).call(ur,""),wr={authorizationPassword:"",authorizationUsername:"",viaHost:"",uri:cr.makeURI(mr),logLevel:"error",transportOptions:{server:br},contactName:""},yr={connectStatus:!1,registerStatus:!1,invitatingStatus:!1,incomingStatus:!1,answerStatus:!1,reconnectStatus:!1};function Sr(e){return document.getElementById(e)}function kr(e){if(e&&e.getTracks)try{var t=e.getTracks();u(t).call(t,function(e){try{e.stop()}catch(e){}})}catch(e){}}function Rr(e){return navigator.mediaDevices.getUserMedia(e).then(function(e){return e?(kr(e),!0):l.reject(new Error("EmptyStreamError"))}).catch(function(e){return(!e||"NotAllowedError"!==e.name)&&l.reject(e)})}!function(e){e.NO="0",e.YES="1"}(dr||(dr={})),function(e){e.NO="0",e.YES="1"}(hr||(hr={})),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"}(gr||(gr={})),function(e){e.DIRECT_ANSWER="1",e.LISTEN_FIRST_AND_THEN_ANSWER_MANUALLY="2"}(fr||(fr={}));var Tr=function(e){var t,n,r;return Z(t=e.getHours().toString()).call(t,2,"0")+":"+Z(n=e.getMinutes().toString()).call(n,2,"0")+":"+Z(r=e.getSeconds().toString()).call(r,2,"0")},Ir=function(){return new Date(new Date((new Date).toLocaleDateString()).getTime())},Er=function(e){return new Date(e.setSeconds(e.getSeconds()+1))};function Cr(e,t,n){var r=window.XMLHttpRequest?new window.XMLHttpRequest:window.ActiveXObject?new window.ActiveXObject("Microsoft.XMLHTTP"):void 0;r||t(new Error("Your Browser does not support ajax")),r.onreadystatechange=function(){if(4==r.readyState){var n=r.response||r.responseText;if(200==r.status){var i=r.getResponseHeader("Content-Type");-1!=q(i).call(i,"json")?e(JSON.parse(r.responseText)):-1!=q(i).call(i,"xml")?e(r.responseXML):e(r.responseText)}else t(n)}};var i=n.url,s=n.data,o=n.type,a=n.contentType,c=o||"POST",l=i,u=null;return s&&("GET"===c?l=l+"?"+function(e){var t=[];for(var n in e)t.push(n+"="+e[n]);return t.join("&")}(s):"POST"===c&&(u=I(s))),r.open(c,l,!0),{xhr:r,ajaxData:u,contentType:a}}var xr,Ar,Dr,Hr,qr,_r,$r,Mr,Pr,Or,Nr,jr,Fr,Br,Ur,Lr,Gr,Vr,Wr,Yr,Kr,zr,Zr,Jr,Xr,Qr,ei,ti,ni,ri,ii,si,oi,ai,ci,li,ui,di,hi,gi,fi,vi,pi,mi,bi,wi,yi,Si,ki,Ri,Ti,Ii,Ei,Ci,xi,Ai,Di,Hi,qi,_i,$i,Mi,Pi,Oi,Ni,ji,Fi,Bi,Ui,Li,Gi,Vi,Wi,Yi,Ki,zi,Zi,Ji,Xi,Qi,es,ts,ns,rs,is,ss,os,as,cs,ls,us,ds,hs,gs,fs,vs,ps,ms,bs,ws,ys,Ss,ks,Rs,Ts,Is,Es,Cs,xs,As,Ds,Hs,qs,_s,$s,Ms,Ps,Os,Ns,js,Fs,Bs,Us,Ls,Gs,Vs,Ws=function(){return t(function t(n){var r,i,s,o,a,l,u,d,h,g,f,p,m,b,w,y,S,k,R,T,I,E,C,x,A=this,D=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,t),c(this,"session",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:"idle"}),c(this,"destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(this,"bound",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(this,"hardFailed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(this,"retryCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),c(this,"signalingBusyCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),c(this,"disconnectedTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"retryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"signalingBusyTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"negotiationTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"iceRecoveryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"rtpStatsTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"onlineTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"transportRecoveryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"registrationRecoveryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"transportWaitStartedAt",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"pendingTransportRecoveryReason",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"registrationWaitStartedAt",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"pendingRegistrationRecoveryReason",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"lastRtpSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"lastRtpProgressAt",{enumerable:!0,configurable:!0,writable:!0,value:G()}),c(this,"lastRtpRecoveryAt",{enumerable:!0,configurable:!0,writable:!0,value:0}),c(this,"recoveryGeneration",{enumerable:!0,configurable:!0,writable:!0,value:0}),c(this,"acceptedRecoveryGeneration",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c(this,"recoveryReason",{enumerable:!0,configurable:!0,writable:!0,value:""}),c(this,"reinviteReason",{enumerable:!0,configurable:!0,writable:!0,value:"unknown"}),c(this,"permanentRecoverySdpModifier",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return te(A,void 0,void 0,O.mark(function t(){return O.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)}))}}),c(this,"handleSessionStateChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e){switch(A.logInfo("SIP session state:",e),e){case exports.SessionState.Established:A.handleEstablished();break;case exports.SessionState.Terminating:case exports.SessionState.Terminated:A.destroy()}}}),c(this,"handleOffline",{enumerable:!0,configurable:!0,writable:!0,value:function(){A.destroyed||A.hardFailed||(A.logInfo("browser offline"),A.clearDisconnectedTimer(),A.clearRetryTimer(),A.clearSignalingBusyTimer(),A.clearIceRecoveryTimer(),A.clearTransportRecoveryTimer(),"sending-reinvite"!==A.state&&(A.state="idle"))}}),c(this,"handleOnline",{enumerable:!0,configurable:!0,writable:!0,value:function(){A.destroyed||A.hardFailed||(A.logInfo("browser online"),A.onlineTimer&&clearTimeout(A.onlineTimer),A.onlineTimer=v(function(){if(A.onlineTimer=void 0,!A.destroyed&&!A.hardFailed&&A.session.state===exports.SessionState.Established)if(A.isTransportAvailable()){var e=A.getPeerConnection();if(e)if("stable"===e.signalingState)switch(e.iceConnectionState){case"failed":case"disconnected":A.state="idle",A.recover("network-online")}else A.scheduleSignalingBusyRetry("network-online:".concat(e.signalingState))}else A.waitForTransport("network-online")},A.options.onlineRecoveryDelayMs))}}),this.session=n,this.options={disconnectedTimeoutMs:null!==(r=D.disconnectedTimeoutMs)&&void 0!==r?r:3e3,negotiationTimeoutMs:null!==(i=D.negotiationTimeoutMs)&&void 0!==i?i:1e4,iceRecoveryTimeoutMs:null!==(s=D.iceRecoveryTimeoutMs)&&void 0!==s?s:1e4,iceGatheringTimeoutMs:null!==(o=D.iceGatheringTimeoutMs)&&void 0!==o?o:5e3,maxRetries:null!==(a=D.maxRetries)&&void 0!==a?a:3,retryBaseDelayMs:null!==(l=D.retryBaseDelayMs)&&void 0!==l?l:1e3,retryMaxDelayMs:null!==(u=D.retryMaxDelayMs)&&void 0!==u?u:1e4,maxSignalingBusyRetries:null!==(d=D.maxSignalingBusyRetries)&&void 0!==d?d:3,signalingBusyRetryDelayMs:null!==(h=D.signalingBusyRetryDelayMs)&&void 0!==h?h:1e3,enableRtpWatchdog:null===(g=D.enableRtpWatchdog)||void 0===g||g,rtpStatsIntervalMs:null!==(f=D.rtpStatsIntervalMs)&&void 0!==f?f:1e3,rtpStallTimeoutMs:null!==(p=D.rtpStallTimeoutMs)&&void 0!==p?p:5e3,recoverOnRtpStallWhenIceConnected:null===(m=D.recoverOnRtpStallWhenIceConnected)||void 0===m||m,rtpRecoveryCooldownMs:null!==(b=D.rtpRecoveryCooldownMs)&&void 0!==b?b:1e4,onlineRecoveryDelayMs:null!==(w=D.onlineRecoveryDelayMs)&&void 0!==w?w:800,transportRecoveryPollMs:null!==(y=D.transportRecoveryPollMs)&&void 0!==y?y:1e3,transportRecoveryTimeoutMs:null!==(S=D.transportRecoveryTimeoutMs)&&void 0!==S?S:6e4,registrationRecoveryPollMs:null!==(k=D.registrationRecoveryPollMs)&&void 0!==k?k:1e3,registrationRecoveryTimeoutMs:null!==(R=D.registrationRecoveryTimeoutMs)&&void 0!==R?R:6e4,debugIceCredentials:null!==(T=D.debugIceCredentials)&&void 0!==T&&T,includeRecoveryReasonInSdp:null===(I=D.includeRecoveryReasonInSdp)||void 0===I||I,recoveryReasonSdpAttribute:null!==(E=D.recoveryReasonSdpAttribute)&&void 0!==E?E:"x-recovery-reason",reinviteReasonSdpAttribute:null!==(C=D.reinviteReasonSdpAttribute)&&void 0!==C?C:"x-reinvite-reason",isSignalingAvailable:D.isSignalingAvailable,isRegistrationAvailable:D.isRegistrationAvailable,logger:null!==(x=D.logger)&&void 0!==x?x:console,onRecoveryStart:D.onRecoveryStart,onRecovered:D.onRecovered,onRecoveryFailed:D.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===exports.SessionState.Established&&this.handleEstablished())}},{key:"restartNow",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"manual";return te(this,void 0,void 0,O.mark(function t(){return O.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=v(function(){if(e.disconnectedTimer=void 0,!e.destroyed&&!e.hardFailed){var t=e.getPeerConnection();if(t){if("disconnected"===t.iceConnectionState)return e.state="idle",void e.recover("ice-disconnected-timeout");e.logInfo("ICE self recovered:",t.iceConnectionState),e.state="idle"}}},this.options.disconnectedTimeoutMs)))}},{key:"handleIceRecovered",value:function(){var e,t;if(!this.destroyed&&!this.hardFailed){var n="idle"!==this.state||this.retryCount>0;!n||"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=G(),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))):this.logInfo("ICE healthy, waiting for re-INVITE acceptance")}}},{key:"recover",value:function(e){var t,n,r,i,s;return te(this,void 0,void 0,O.mark(function o(){var a,c,l,u,d,h,g=this;return O.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===exports.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(a=this.getPeerConnection()){o.next=7;break}return o.abrupt("return");case 7:if("stable"===a.signalingState){o.next=8;break}return this.logWarn("skip recovery: signalingState not stable",a.signalingState),this.state="waiting-signaling",this.scheduleSignalingBusyRetry("signaling-busy:".concat(a.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++,c=++this.recoveryGeneration,this.state="sending-reinvite",l=this.readIceCredentials(null===(t=a.localDescription)||void 0===t?void 0:t.sdp),this.recoveryReason||(this.reinviteReason=this.resolveReinviteReason(e),this.recoveryReason=this.normalizeRecoveryReason(e,this.reinviteReason)),this.acceptedRecoveryGeneration=void 0,this.logInfo("ICE recovery #".concat(this.retryCount),{recoveryReason:this.recoveryReason,reinviteReason:this.reinviteReason}),null===(r=(n=this.options).onRecoveryStart)||void 0===r||r.call(n,this.recoveryReason,this.retryCount),this.startNegotiationTimeout(c,e),o.prev=10,u={offerOptions:{iceRestart:!0},iceGatheringTimeout:this.options.iceGatheringTimeoutMs,finalModifiers:this.options.includeRecoveryReasonInSdp?[this.permanentRecoverySdpModifier]:[]},this.session.sessionDescriptionHandlerOptionsReInvite=u,this.session.sessionDescriptionHandlerModifiersReInvite=[],this.logDebug("re-INVITE Final SDP configured",{recoveryReason:this.recoveryReason,reinviteReason:this.reinviteReason,includeRecoveryReasonInSdp:this.options.includeRecoveryReasonInSdp,finalModifierCount:null!==(s=null===(i=u.finalModifiers)||void 0===i?void 0:i.length)&&void 0!==s?s:0}),o.next=11,this.session.invite({requestDelegate:{onTrying:function(){g.isCurrentGeneration(c)&&g.logDebug("ICE re-INVITE trying")},onProgress:function(e){g.isCurrentGeneration(c)&&g.logDebug("ICE re-INVITE progress:",e.message.statusCode)},onAccept:function(){var t;if(g.isCurrentGeneration(c)){g.logInfo("ICE re-INVITE accepted"),g.clearNegotiationTimer(),g.acceptedRecoveryGeneration=c;var n=g.getPeerConnection();if(n&&"stable"!==n.signalingState&&g.logWarn("re-INVITE accepted but signalingState is not stable",n.signalingState),g.state="waiting-ice",g.options.debugIceCredentials){var r=g.readIceCredentials(null===(t=null==n?void 0:n.localDescription)||void 0===t?void 0:t.sdp);g.logInfo("ICE credentials:",{old:l,new:r,changed:g.hasIceCredentialsChanged(l,r)})}g.startIceRecoveryTimeout(c,e)}},onReject:function(t){g.handleReinviteRejected(c,e,t.message.statusCode,t.message.reasonPhrase)}}});case 11:o.next=19;break;case 12:if(o.prev=12,h=o.catch(10),this.isCurrentGeneration(c)){o.next=13;break}return o.abrupt("return");case 13:return this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.logWarn("ICE re-INVITE error:",h),o.next=14,this.rollbackLocalOffer("invite-exception");case 14:if(d=o.sent,this.isCurrentGeneration(c)){o.next=15;break}return o.abrupt("return");case 15:if(d){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(h)){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 te(this,void 0,void 0,O.mark(function t(){var n,r,i,s;return O.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 r=n.signalingState,i="stable"===r,this.logInfo("local offer rollback result",{success:i,signalingState:r}),t.abrupt("return",i);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:"normalizeRecoveryReason",value:function(e,t){var n=e.toLowerCase();return f(n).call(n,"transport-restored")?"transport-restored:".concat(t):"unknown"!==t?t:"unknown"}},{key:"resolveReinviteReason",value:function(e){var t=e.toLowerCase();return f(t).call(t,"rtp-stalled")?"rtp-stalled":f(t).call(t,"ice-failed")?"ice-failed":f(t).call(t,"ice-disconnected")||f(t).call(t,"disconnected-timeout")?"ice-disconnected":f(t).call(t,"network-changed")?"network-changed":f(t).call(t,"transport-restored")?"transport-restored":f(t).call(t,"manual")?"manual":"unknown"}},{key:"sanitizeSdpReason",value:function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:256;return d(t=e.replace(/[\r\n]/g,"").replace(/[^a-zA-Z0-9._:-]/g,"_")).call(t,0,n)}},{key:"sanitizeSdpAttributeName",value:function(e){var t;return d(t=e.replace(/[^a-zA-Z0-9_-]/g,"")).call(t,0,64)||"x-reinvite-reason"}},{key:"applyRecoveryReasonToSdp",value:function(e){return te(this,void 0,void 0,O.mark(function t(){var n,r,i,s,o,a,c,l,u,d,g,v,p,m,b,w,y;return O.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(l=this.sanitizeSdpAttributeName(this.options.recoveryReasonSdpAttribute),u=this.sanitizeSdpAttributeName(this.options.reinviteReasonSdpAttribute),d=this.sanitizeSdpReason(this.recoveryReason||"unknown"),g=this.sanitizeSdpReason(this.reinviteReason||"unknown",64),v=h(n=e.sdp.split(/\r?\n/)).call(n,function(e){return!Q(e).call(e,"a=".concat(l,":"))&&!Q(e).call(e,"a=".concat(u,":"))});v.length>0&&""===v[v.length-1];)v.pop();return p=ee(v).call(v,function(e){return Q(e).call(e,"m=")}),m=p>=0?p:v.length,R(v).call(v,m,0,T(r="a=".concat(l,":")).call(r,d),T(i="a=".concat(u,":")).call(i,g)),b="".concat(v.join("\r\n"),"\r\n"),w=f(b).call(b,T(s="a=".concat(l,":")).call(s,d)),y=f(b).call(b,T(o="a=".concat(u,":")).call(o,g)),this.logInfo("SDP modifier RESULT",{recoveryReason:d,reinviteReason:g,containsRecoveryReason:w,containsReinviteReason:y,insertedBeforeFirstMedia:p>=0}),this.logDebug("SDP custom reason lines",{recoveryLine:T(a="a=".concat(l,":")).call(a,d),reinviteLine:T(c="a=".concat(u,":")).call(c,g)}),t.abrupt("return",H(H({},e),{sdp:b}));case 2:case"end":return t.stop()}},t,this)}))}},{key:"createRecoveryReasonSdpModifier",value:function(e,t){var n=this;return function(r){return te(n,void 0,void 0,O.mark(function n(){return O.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return this.recoveryReason=e,this.reinviteReason=t,n.abrupt("return",this.applyRecoveryReasonToSdp(r));case 1:case"end":return n.stop()}},n,this)}))}}},{key:"handleReinviteRejected",value:function(e,t,n,r){return te(this,void 0,void 0,O.mark(function i(){var s,o,a,c;return O.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(this.isCurrentGeneration(e)){i.next=1;break}return i.abrupt("return");case 1:return this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.logWarn("ICE re-INVITE rejected:",n,r),i.next=2,this.rollbackLocalOffer("sip-".concat(n));case 2:if(o=i.sent,this.isCurrentGeneration(e)){i.next=3;break}return i.abrupt("return");case 3:if(o){i.next=4;break}return this.failRecovery(T(a="".concat(t,":rollback-failed:sip-")).call(a,n)),i.abrupt("return");case 4:if(this.state="idle",this.signalingBusyCount=0,481!==n){i.next=5;break}return this.failRecovery("".concat(t,":sip-481")),i.abrupt("return");case 5:if(this.isTransportAvailable()){i.next=6;break}return this.waitForTransport(T(c="".concat(t,":sip-")).call(c,n)),i.abrupt("return");case 6:if(491!==n){i.next=7;break}return this.scheduleRetry("".concat(t,":sip-491"),1500),i.abrupt("return");case 7:if(503!==n){i.next=8;break}return this.scheduleRetry("".concat(t,":sip-503"),3e3),i.abrupt("return");case 8:this.scheduleRetry(T(s="".concat(t,":sip-")).call(s,n));case 9:case"end":return i.stop()}},i,this)}))}},{key:"startNegotiationTimeout",value:function(e,t){var n=this;this.clearNegotiationTimer(),this.negotiationTimer=v(function(){if(n.negotiationTimer=void 0,n.isCurrentGeneration(e)){var r=n.getPeerConnection();n.logError("re-INVITE negotiation timeout",{reason:t,signalingState:null==r?void 0:r.signalingState,iceConnectionState:null==r?void 0:r.iceConnectionState,connectionState:null==r?void 0:r.connectionState}),n.failRecovery("".concat(t,":negotiation-timeout"))}},this.options.negotiationTimeoutMs)}},{key:"startIceRecoveryTimeout",value:function(e,t){var n=this;this.clearIceRecoveryTimer(),this.iceRecoveryTimer=v(function(){if(n.iceRecoveryTimer=void 0,n.isCurrentGeneration(e)){var r=n.getPeerConnection();r&&("connected"!==r.iceConnectionState&&"completed"!==r.iceConnectionState?(n.logWarn("ICE recovery timeout",{reason:t,iceConnectionState:r.iceConnectionState,connectionState:r.connectionState,signalingState:r.signalingState}),n.state="idle","stable"===r.signalingState?n.scheduleRetry("".concat(t,":ice-timeout")):n.scheduleSignalingBusyRetry("ice-timeout:".concat(r.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 r=this.options.retryBaseDelayMs*Math.pow(2,Math.max(0,this.retryCount-1)),i=Math.min(r,this.options.retryMaxDelayMs),s=Math.floor(500*Math.random()),o=Math.max(i+s,n);this.logInfo("schedule ICE retry in ".concat(o,"ms"),e),this.retryTimer=v(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(t.recoveryReason||e)}else t.handleIceRecovered()}else t.waitForTransport(t.recoveryReason||e)},o)}}},{key:"scheduleSignalingBusyRetry",value:function(e){var t,n=this;if(!this.destroyed&&!this.hardFailed)if(this.isTransportAvailable()){if(!this.signalingBusyTimer){this.signalingBusyCount++;var r=this.getPeerConnection();if(this.logWarn("signalingState still busy",{reason:e,signalingState:null==r?void 0:r.signalingState,count:this.signalingBusyCount,max:this.options.maxSignalingBusyRetries}),this.signalingBusyCount>this.options.maxSignalingBusyRetries)this.failRecovery("signaling-stuck:".concat(null!==(t=null==r?void 0:r.signalingState)&&void 0!==t?t:"unknown"));else{this.state="waiting-signaling";var i=Math.floor(500*Math.random()),s=this.options.signalingBusyRetryDelayMs+i;this.logInfo("schedule signaling retry in ".concat(s,"ms")),this.signalingBusyTimer=v(function(){if(n.signalingBusyTimer=void 0,!n.destroyed&&!n.hardFailed&&n.session.state===exports.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")},s)}}}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 n=void 0===this.registrationWaitStartedAt?0:G()-this.registrationWaitStartedAt;return this.clearRegistrationRecoveryTimer(),this.registrationWaitStartedAt=void 0,this.pendingRegistrationRecoveryReason=void 0,this.state="idle",this.logInfo("SIP registration recovered",{waitedMs:n,reason:e}),void this.resumeAfterRegistrationRecovery(e)}if(this.state="waiting-registration",this.pendingRegistrationRecoveryReason=e,void 0===this.registrationWaitStartedAt&&(this.registrationWaitStartedAt=G(),this.logWarn("SIP registration unavailable; pause ICE restart",{reason:e,timeoutMs:this.options.registrationRecoveryTimeoutMs})),!this.registrationRecoveryTimer)G()-this.registrationWaitStartedAt>=this.options.registrationRecoveryTimeoutMs?this.failRecovery("registration-recovery-timeout:".concat(e)):this.registrationRecoveryTimer=v(function(){var n;t.registrationRecoveryTimer=void 0,t.destroyed||t.hardFailed||t.session.state===exports.SessionState.Established&&t.waitForRegistration(null!==(n=t.pendingRegistrationRecoveryReason)&&void 0!==n?n:e)},this.options.registrationRecoveryPollMs)}}},{key:"resumeAfterRegistrationRecovery",value:function(e){return te(this,void 0,void 0,O.mark(function t(){var n;return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.destroyed&&!this.hardFailed&&this.session.state===exports.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(n=this.getPeerConnection()){t.next=4;break}return t.abrupt("return");case 4:if("connected"!==n.iceConnectionState&&"completed"!==n.iceConnectionState){t.next=5;break}return this.handleIceRecovered(),t.abrupt("return");case 5:if("stable"===n.signalingState){t.next=6;break}return this.state="waiting-signaling",this.scheduleSignalingBusyRetry("registration-restored:".concat(n.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=G(),this.logWarn("SIP Transport unavailable; pause ICE restart",{reason:e,timeoutMs:this.options.transportRecoveryTimeoutMs})),this.pendingTransportRecoveryReason=e,!this.transportRecoveryTimer)G()-this.transportWaitStartedAt>=this.options.transportRecoveryTimeoutMs?this.failRecovery("transport-recovery-timeout:".concat(e)):this.transportRecoveryTimer=v(function(){var n,r;if(t.transportRecoveryTimer=void 0,!t.destroyed&&!t.hardFailed&&t.session.state===exports.SessionState.Established)if(t.isTransportAvailable()){var i=null!==(r=t.pendingTransportRecoveryReason)&&void 0!==r?r:e,s=void 0===t.transportWaitStartedAt?0:G()-t.transportWaitStartedAt;t.transportWaitStartedAt=void 0,t.pendingTransportRecoveryReason=void 0,t.logInfo("SIP Transport recovered",{waitedMs:s,reason:i}),t.state="idle",t.resumeAfterTransportRecovery(i)}else t.waitForTransport(null!==(n=t.pendingTransportRecoveryReason)&&void 0!==n?n:e)},this.options.transportRecoveryPollMs)}}},{key:"resumeAfterTransportRecovery",value:function(e){return te(this,void 0,void 0,O.mark(function t(){var n;return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.destroyed&&!this.hardFailed&&this.session.state===exports.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(n=this.getPeerConnection()){t.next=4;break}return t.abrupt("return");case 4:if("connected"!==n.iceConnectionState&&"completed"!==n.iceConnectionState){t.next=5;break}return this.handleIceRecovered(),t.abrupt("return");case 5:if("stable"===n.signalingState){t.next=6;break}return this.state="waiting-signaling",this.scheduleSignalingBusyRetry("transport-restored:".concat(n.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,n,r,i,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===(n=this.getPeerConnection())||void 0===n?void 0:n.connectionState,signalingState:null===(r=this.getPeerConnection())||void 0===r?void 0:r.signalingState}),null===(s=(i=this.options).onRecoveryFailed)||void 0===s||s.call(i,e,this.retryCount))}},{key:"startRtpWatchdog",value:function(){var e=this;this.rtpStatsTimer||this.destroyed||this.hardFailed||(this.lastRtpProgressAt=G(),this.rtpStatsTimer=U(function(){e.checkRtpHealth()},this.options.rtpStatsIntervalMs))}},{key:"stopRtpWatchdog",value:function(){this.rtpStatsTimer&&(clearInterval(this.rtpStatsTimer),this.rtpStatsTimer=void 0)}},{key:"checkRtpHealth",value:function(){return te(this,void 0,void 0,O.mark(function e(){var t,n,r,i,s,o,a,c;return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.destroyed&&!this.hardFailed&&this.session.state===exports.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,c=e.catch(4),this.logDebug("getStats failed:",c),e.abrupt("return");case 7:if(n.hasAudio||n.hasVideo){e.next=8;break}return e.abrupt("return");case 8:if(r=this.lastRtpSnapshot,this.lastRtpSnapshot=n,r){e.next=9;break}return this.lastRtpProgressAt=G(),e.abrupt("return");case 9:if(i=n.audioBytes>r.audioBytes||n.audioPackets>r.audioPackets,s=n.videoBytes>r.videoBytes||n.videoPackets>r.videoPackets||n.videoFramesDecoded>r.videoFramesDecoded,!i&&!s){e.next=10;break}return this.lastRtpProgressAt=G(),e.abrupt("return");case 10:if(!((o=G()-this.lastRtpProgressAt)<this.options.rtpStallTimeoutMs)){e.next=11;break}return e.abrupt("return");case 11:if(!((a=G())-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=a,this.recover("rtp-stalled");case 14:case"end":return e.stop()}},e,this,[[4,6]])}))}},{key:"readRtpSnapshot",value:function(e){return te(this,void 0,void 0,O.mark(function t(){var n,r;return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=1,e.getStats();case 1:return n=t.sent,r={timestamp:G(),audioBytes:0,audioPackets:0,videoBytes:0,videoPackets:0,videoFramesDecoded:0,hasAudio:!1,hasVideo:!1},u(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&&(r.hasAudio=!0,"number"==typeof e.bytesReceived&&(r.audioBytes+=e.bytesReceived),"number"==typeof e.packetsReceived&&(r.audioPackets+=e.packetsReceived)),"video"===n&&(r.hasVideo=!0,"number"==typeof e.bytesReceived&&(r.videoBytes+=e.bytesReceived),"number"==typeof e.packetsReceived&&(r.videoPackets+=e.packetsReceived),"number"==typeof e.framesDecoded&&(r.videoFramesDecoded+=e.framesDecoded))}}),t.abrupt("return",r);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,r,i;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:S(n).call(n),pwd:null===(i=null===(r=e.match(/^a=ice-pwd:(.+)$/m))||void 0===r?void 0:r[1])||void 0===i?void 0:S(i).call(i)}:{}}},{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,n,r,i=arguments.length,s=new Array(i),o=0;o<i;o++)s[o]=arguments[o];null===(r=(n=this.options.logger).debug)||void 0===r||(e=r).call.apply(e,T(t=[n,"[SipIceRecovery]"]).call(t,s))}},{key:"logInfo",value:function(){for(var e,t,n,r,i=arguments.length,s=new Array(i),o=0;o<i;o++)s[o]=arguments[o];null===(r=(n=this.options.logger).info)||void 0===r||(e=r).call.apply(e,T(t=[n,"[SipIceRecovery]"]).call(t,s))}},{key:"logWarn",value:function(){for(var e,t,n,r,i=arguments.length,s=new Array(i),o=0;o<i;o++)s[o]=arguments[o];null===(r=(n=this.options.logger).warn)||void 0===r||(e=r).call.apply(e,T(t=[n,"[SipIceRecovery]"]).call(t,s))}},{key:"logError",value:function(){for(var e,t,n,r,i=arguments.length,s=new Array(i),o=0;o<i;o++)s[o]=arguments[o];null===(r=(n=this.options.logger).error)||void 0===r||(e=r).call.apply(e,T(t=[n,"[SipIceRecovery]"]).call(t,s))}}])}(),Ys=function(){return t(function t(){var n=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e(this,t),xr.add(this),Ar.set(this,void 0),Dr.set(this,void 0),Hr.set(this,void 0),qr.set(this,void 0),_r.set(this,void 0),$r.set(this,void 0),Mr.set(this,[]),Pr.set(this,[]),Or.set(this,{}),Nr.set(this,void 0),jr.set(this,void 0),Fr.set(this,new MediaStream),Br.set(this,JSON.parse(I(yr))),Ur.set(this,0),Lr.set(this,void 0),Gr.set(this,void 0),Vr.set(this,void 0),c(this,"token",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Wr.set(this,void 0),Yr.set(this,48e4),Kr.set(this,12e6),zr.set(this,{}),Zr.set(this,void 0),Jr.set(this,void 0),Xr.set(this,void 0),Qr.set(this,function(e){}),ei.set(this,function(e){}),ti.set(this,function(e){}),ni.set(this,function(e){}),ri.set(this,function(e){return te(n,void 0,void 0,O.mark(function t(){var n,r,i,s;return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!ne(this,Lr,"f")||!ne(this,Gr,"f")){t.next=3;break}if(!(G()-ne(this,Gr,"f")>e)){t.next=3;break}return t.next=1,ne(this,si,"f").call(this);case 1:if(s=t.sent){t.next=2;break}s={};case 2:r=(n=s).sign,i=n.timestamp,re(this,Lr,null!=r?r:ne(this,Lr,"f"),"f"),re(this,Gr,null!=i?i:ne(this,Gr,"f"),"f");case 3:case"end":return t.stop()}},t,this)}))}),ii.set(this,function(e){return te(n,void 0,void 0,O.mark(function t(){var n,r,i,s,o;return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!ne(this,Wr,"f")){t.next=4;break}if(!(G()-ne(this,Wr,"f")>e)){t.next=4;break}if(!ne(this,Vr,"f")){t.next=2;break}return t.next=1,ne(this,oi,"f").call(this);case 1:n=t.sent,r=n.token,i=n.tokenTimestamp,re(this,Vr,null!=r?r:ne(this,Vr,"f"),"f"),re(this,Wr,null!=i?i:G(),"f"),t.next=4;break;case 2:if(!this.token){t.next=4;break}return t.next=3,this.getGatewayAccessToken({corpId:ne(this,Ai,"f"),sid:ne(this,qi,"f"),secret:ne(this,Di,"f"),seatOnline:!1});case 3:s=t.sent,o=s.token,this.token=o,re(this,Wr,G(),"f");case 4:case"end":return t.stop()}},t,this)}))}),si.set(this,function(){}),oi.set(this,function(){}),ai.set(this,function(e){}),ci.set(this,function(e){}),li.set(this,void 0),ui.set(this,void 0),c(this,"networkSpeed",{enumerable:!0,configurable:!0,writable:!0,value:"0.00Mb/s"}),c(this,"networkDelay",{enumerable:!0,configurable:!0,writable:!0,value:"0ms"}),c(this,"onLine",{enumerable:!0,configurable:!0,writable:!0,value:navigator.onLine}),c(this,"testspeeding",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(this,"goodNetworkSpeed",{enumerable:!0,configurable:!0,writable:!0,value:function(){return 1e3*Number(n.networkSpeed.replace("Mb/s",""))>=30}}),c(this,"goodNetworkDelay",{enumerable:!0,configurable:!0,writable:!0,value:function(){return Number(n.networkDelay.replace("ms",""))<=500&&"0ms"!==n.networkDelay}}),c(this,"authorizedMicrophonePermissions",{enumerable:!0,configurable:!0,writable:!0,value:!1}),c(this,"authorizedNotificationPermissions",{enumerable:!0,configurable:!0,writable:!0,value:!1}),di.set(this,100),hi.set(this,3),gi.set(this,8),fi.set(this,2),vi.set(this,0),pi.set(this,!1),mi.set(this,void 0),bi.set(this,3),wi.set(this,3),yi.set(this,0),Si.set(this,0),ki.set(this,0),Ri.set(this,!1),Ti.set(this,!1),Ii.set(this,!1),Ei.set(this,void 0),Ci.set(this,void 0),xi.set(this,void 0),Ai.set(this,void 0),Di.set(this,void 0),Hi.set(this,void 0),qi.set(this,void 0),_i.set(this,void 0),$i.set(this,void 0),Mi.set(this,void 0),Pi.set(this,void 0),Oi.set(this,function(e){ne(n,xr,"m",js).call(n)}),Ni.set(this,function(){}),ji.set(this,void 0),Fi.set(this,void 0),Bi.set(this,!1),Ui.set(this,4e3),Li.set(this,4e3),Gi.set(this,{}),Vi.set(this,!1),Wi.set(this,!0),c(this,"ifAutoAnswer",{enumerable:!0,configurable:!0,writable:!0,value:function(){return String(ne(n,Gi,"f").autoAnswer)===dr.YES}}),c(this,"notNeedSendStarDtmf",{enumerable:!0,configurable:!0,writable:!0,value:function(){return String(ne(n,Gi,"f").afterTransferLabour)===fr.DIRECT_ANSWER}}),Yi.set(this,function(){if(ne(n,Wi,"f")){var e;ne(n,Ki,"f").call(n);var t=new(window.AudioContext||window.webkitAudioContext);re(n,Jr,t.createScriptProcessor(2048,1,1),"f"),ne(n,Jr,"f").onaudioprocess=function(e){for(var t=e.inputBuffer.getChannelData(0),r=0,i=0;i<t.length;++i)r+=t[i]*t[i];re(n,Ur,Number(Math.sqrt(r/t.length).toFixed(2)),"f"),ne(n,Qr,"f").call(n,ne(n,Ur,"f"))},re(n,Xr,new MediaStream,"f"),u(e=n.getSenders()).call(e,function(e){e.track&&ne(n,Xr,"f").addTrack(e.track)}),re(n,Zr,t.createMediaStreamSource(ne(n,Xr,"f")),"f"),ne(n,Zr,"f").connect(ne(n,Jr,"f")),ne(n,Jr,"f").connect(t.destination)}}),Ki.set(this,function(){if(ne(n,Wi,"f")){if(ne(n,Zr,"f"))try{ne(n,Zr,"f").disconnect()}catch(e){console.log(e)}if(ne(n,Jr,"f"))try{ne(n,Jr,"f").disconnect()}catch(e){console.log(e)}if(ne(n,Xr,"f"))try{var e;u(e=ne(n,Xr,"f").getTracks()).call(e,function(e){e.stop()})}catch(e){console.log(e)}}re(n,Zr,void 0,"f"),re(n,Jr,void 0,"f"),re(n,Xr,void 0,"f"),re(n,Ur,0,"f"),ne(n,Qr,"f").call(n,ne(n,Ur,"f"))}),c(this,"disposeSoftphoneEnvRequirementCheck",{enumerable:!0,configurable:!0,writable:!0,value:function(){ne(n,zi,"f").call(n),window.removeEventListener("offline",ne(n,Xi,"f")),window.removeEventListener("online",ne(n,Ji,"f")),window.removeEventListener("unload",n.disposeSoftphoneEnvRequirementCheck)}}),zi.set(this,function(){clearInterval(ne(n,li,"f")),re(n,li,void 0,"f"),clearTimeout(ne(n,ui,"f")),re(n,ui,void 0,"f"),n.testspeeding=!1}),c(this,"softphoneEnvCheck",{enumerable:!0,configurable:!0,writable:!0,value:function(){return te(n,void 0,void 0,O.mark(function e(){return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:this.testspeeding||(ne(this,Zi,"f").call(this),this.oneRoundOfTesting());case 1:case"end":return e.stop()}},e,this)}))}}),Zi.set(this,function(){window.addEventListener("offline",ne(n,Xi,"f")),window.addEventListener("online",ne(n,Ji,"f")),window.addEventListener("unload",n.disposeSoftphoneEnvRequirementCheck)}),c(this,"oneRoundOfTesting",{enumerable:!0,configurable:!0,writable:!0,value:function(){return te(n,void 0,void 0,O.mark(function e(){var t=this;return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:this.testspeeding=!0,this.detectNavigatorPermissions(),this.onLine?(ne(this,Qi,"f").call(this,this),re(this,ui,v(function(){t.testspeeding=!1,t.disposeSoftphoneEnvRequirementCheck()},4e3),"f")):this.testspeeding=!1;case 1:case"end":return e.stop()}},e,this)}))}}),Ji.set(this,function(){n.onLine=!0,n.oneRoundOfTesting()}),Xi.set(this,function(){n.onLine=!1,n.networkSpeed="0.00Mb/s",n.networkDelay="0ms",ne(n,ci,"f").call(n,{networkSpeed:n.networkSpeed,networkDelay:n.networkDelay,authorizedMicrophonePermissions:n.authorizedMicrophonePermissions,authorizedNotificationPermissions:n.authorizedNotificationPermissions}),ne(n,zi,"f").call(n)}),Qi.set(this,function(e){return te(n,void 0,void 0,O.mark(function t(){var n,r,i=this;return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=e||this,clearInterval(ne(n,li,"f")),re(n,li,void 0,"f"),r=function(){return te(i,void 0,void 0,O.mark(function e(){var t;return O.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,ne(n,es,"f").call(n,"1"===ne(n,Mi,"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:ne(this,ci,"f").call(this,{networkSpeed:this.networkSpeed,networkDelay:this.networkDelay,authorizedMicrophonePermissions:this.authorizedMicrophonePermissions,authorizedNotificationPermissions:this.authorizedNotificationPermissions}),ne(this,ui,"f")||(this.testspeeding=!1,this.disposeSoftphoneEnvRequirementCheck());case 7:case"end":return e.stop()}},e,this,[[1,3]])}))},t.next=1,r();case 1:ne(this,ui,"f")&&re(n,li,U(function(){return te(this,void 0,void 0,O.mark(function e(){return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,r();case 1:case"end":return e.stop()}},e)}))},1e3),"f");case 2:case"end":return t.stop()}},t,this)}))}),es.set(this,function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"https://seat.94ai.com/favicon.png",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:63491,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;return te(n,void 0,void 0,O.mark(function n(){var i,s;return O.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:for(i=[],s=0;s<r;s++)i.push(ne(this,ts,"f").call(this,e+"?d="+G()+s,t));return n.abrupt("return",l.all(i).then(function(e){var t=0,n=0;return u(e).call(e,function(e){t+=Number(e[0]),n+=Number(e[1])}),{networkDelay:(n/r).toFixed(2)+"ms",networkSpeed:(t/r).toFixed(2)+"Mb/s"}}));case 1:case"end":return n.stop()}},n,this)}))}),ts.set(this,function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"https://seat.94ai.com/favicon.png?d="+G(),t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:63491;return new l(function(n,r){var i=document.createElement("img");i.start=window.performance.now(),i.onload=function(){var e=window.performance.now()-i.start;n([(1e3*t/(1048576*e)).toFixed(2),e])},i.onerror=function(e){r(e)},i.src=e}).catch(function(e){throw e})}),c(this,"openApiAjax",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return new l(function(t,r){return te(n,void 0,void 0,O.mark(function n(){var i,s,o,a,c,l,u,d,h,g,f,v,p,m,b,w,y;return O.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(n.prev=0,h=ne(this,Ai,"f")||(null===(i=e.data)||void 0===i?void 0:i.appKey),g=ne(this,Di,"f")||(null===(s=e.data)||void 0===s?void 0:s.appSecret),f=ne(this,Lr,"f")||(null===(o=e.data)||void 0===o?void 0:o.sign),v=ne(this,Gr,"f")||(null===(a=e.data)||void 0===a?void 0:a.timestamp),null===(c=e.data)||void 0===c||delete c.appKey,null===(l=e.data)||void 0===l||delete l.appSecret,null===(u=e.data)||void 0===u||delete u.sign,null===(d=e.data)||void 0===d||delete d.timestamp,h){n.next=1;break}throw new Error("缺少appKey");case 1:if(!g){n.next=2;break}v=G(),f=J.enc.Base64.stringify(J.HmacSHA1(h+v,g)),n.next=5;break;case 2:if(!f||!v){n.next=4;break}return n.next=3,ne(this,ri,"f").call(this,ne(this,Yr,"f"));case 3:f=ne(this,Lr,"f")||f,v=ne(this,Gr,"f")||v,n.next=5;break;case 4:throw new Error("缺少appSecret或sign+timestamp");case 5:return p=Cr(t,r,e),m=p.xhr,b=p.ajaxData,w=p.contentType,m.setRequestHeader("appKey",h),m.setRequestHeader("timestamp",String(v)),m.setRequestHeader("sign",f),m.setRequestHeader("Content-type",w||"application/json"),n.next=6,ne(this,ti,"f").call(this,m);case 6:m.send(b),n.next=8;break;case 7:throw n.prev=7,y=n.catch(0),r(y.message),y;case 8:case"end":return n.stop()}},n,this,[[0,7]])}))})}}),c(this,"requestGateway",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return n.gatewayApiAjax(H(H({},e),{url:n.getGateway()+e.url}),t)}}),c(this,"gatewayApiAjax",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return new l(function(r,i){return te(n,void 0,void 0,O.mark(function n(){var s,o,a,c,l,u;return O.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(n.prev=0,s=Cr(r,i,e),o=s.xhr,a=s.ajaxData,c=s.contentType,!t){n.next=2;break}return n.next=1,this.getGatewayToken();case 1:l=n.sent,o.setRequestHeader("x-token",l),o.setRequestHeader("seatsToken",l),o.setRequestHeader("x-authority-token",l);case 2:return o.setRequestHeader("x-app-code",3),o.setRequestHeader("content-type",c||"application/json"),n.next=3,ne(this,ni,"f").call(this,o);case 3:o.send(a),n.next=5;break;case 4:throw n.prev=4,u=n.catch(0),i(u.message),u;case 5:case"end":return n.stop()}},n,this,[[0,4]])}))})}}),c(this,"requestOpenApi",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return n.openApiAjax(H(H({},e),{url:n.getOpenApi()+e.url}))}}),c(this,"getDeviceId",{enumerable:!0,configurable:!0,writable:!0,value:function(){return te(n,void 0,void 0,O.mark(function e(){var t,n;return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!ne(this,Pi,"f")){e.next=1;break}return e.abrupt("return",ne(this,Pi,"f"));case 1:return e.next=2,X.load();case 2:return t=e.sent,e.next=3,t.get();case 3:return n=e.sent,re(this,Pi,n.visitorId,"f"),e.abrupt("return",ne(this,Pi,"f"));case 4:case"end":return e.stop()}},e,this)}))}}),ls.set(this,function(){return te(n,void 0,void 0,O.mark(function e(){var t,n,r,i;return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!ne(this,xr,"m",cs).call(this)||ne(this,Or,"f").authorizationUsername&&ne(this,Or,"f").uri&&ne(this,Or,"f").authorizationPassword&&ne(this,Or,"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}i=t.data,ne(this,Or,"f").authorizationUsername=i.agentExtension,ne(this,Or,"f").authorizationPassword=i.extensionPwd,ne(this,Or,"f").contactName||(ne(this,Or,"f").contactName=i.agentExtension),ne(this,Or,"f").uri=cr.makeURI(T(n="sip:".concat(i.agentExtension,"@")).call(n,i.wsRegisterAddress)),ne(this,Or,"f").transportOptions.server=T(r="".concat(i.wsProtocol,"://")).call(r,i.wsRegisterAddress),re(this,qi,i.agentId,"f"),re(this,Hi,i.agentTag,"f"),e.next=3;break;case 2:throw new Error(I(t));case 3:case"end":return e.stop()}},e,this)}))}),us.set(this,function(){return te(n,void 0,void 0,O.mark(function e(){var t;return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(ne(this,Or,"f").viaHost){e.next=2;break}return t="",e.next=1,this.getDeviceId();case 1:ne(this,Or,"f").viaHost=T(t).call(t,e.sent,".sip");case 2:case"end":return e.stop()}},e,this)}))}),hs.set(this,function(e){var t,r,i,s,o,a,c,l,u,d,h,g,f,v,p,b,w,y,S,k,R,T,I;ne(n,Gi,"f").popWindow=null===(o=e["X-Popwindow"])||void 0===o?void 0:o[0].raw,ne(n,Gi,"f").afterTransferLabour=null===(a=e["X-Aftertransferlabour"])||void 0===a?void 0:a[0].raw,ne(n,Gi,"f").callId=null===(c=e["X-94callid"])||void 0===c?void 0:c[0].raw,ne(n,Gi,"f").cid=null===(l=e["X-Cid"])||void 0===l?void 0:l[0].raw,ne(n,Gi,"f").numberId=null===(u=e["X-Numberid"])||void 0===u?void 0:u[0].raw,ne(n,Gi,"f").tag=(null===(d=e["X-Tag"])||void 0===d?void 0:d[0].raw)&&"null"!==(null===(h=e["X-Tag"])||void 0===h?void 0:h[0].raw)?m(t=e["X-Tag"][0].raw.split("-")).call(t,function(e){return String.fromCharCode(e)}).join(""):"",ne(n,Gi,"f").numberTag=(null===(g=e["X-Numbertag"])||void 0===g?void 0:g[0].raw)&&"null"!==(null===(f=e["X-Numbertag"])||void 0===f?void 0:f[0].raw)?decodeURIComponent(e["X-Numbertag"][0].raw):"",ne(n,Gi,"f").taskId=null===(v=e["X-Taskid"])||void 0===v?void 0:v[0].raw,ne(n,Gi,"f").voiceType=null===(p=e["X-Voicetype"])||void 0===p?void 0:p[0].raw,ne(n,Gi,"f").processTime=null===(b=e["X-Processtime"])||void 0===b?void 0:b[0].raw,ne(n,Gi,"f").userPhone=null===(w=e["X-Userphone"])||void 0===w?void 0:w[0].raw,ne(n,Gi,"f").autoAnswer=null===(y=e["X-94autoanswer"])||void 0===y?void 0:y[0].raw,ne(n,Gi,"f").nodeTitle=null===(S=e["X-Nodetitle"])||void 0===S?void 0:m(r=S[0].raw.split("-")).call(r,function(e){return String.fromCharCode(e)}).join(""),ne(n,Gi,"f").taskName=null===(k=e["X-Taskname"])||void 0===k?void 0:m(i=k[0].raw.split("-")).call(i,function(e){return String.fromCharCode(e)}).join(""),ne(n,Gi,"f").templateTitle=null===(R=e["X-Templatetitle"])||void 0===R?void 0:m(s=R[0].raw.split("-")).call(s,function(e){return String.fromCharCode(e)}).join(""),ne(n,Gi,"f").phoneNumber=(null===(T=e["X-Phonenumber"])||void 0===T?void 0:T[0].raw)||(null===(I=e.From)||void 0===I?void 0:I[0].parsed.uri.normal.user)}),Es.set(this,function(e){switch(e){case exports.SessionState.Initial:case exports.SessionState.Establishing:break;case exports.SessionState.Established:ne(n,xr,"m",Is).call(n);break;case exports.SessionState.Terminating:case exports.SessionState.Terminated:n.clearIceAutoDetection();var t=v(function(){clearTimeout(t),t=void 0,ne(n,Br,"f").incomingStatus=!1,ne(n,Br,"f").answerStatus=!1},10);ne(n,Ki,"f").call(n);break;default:throw new Error("Unknown session state.")}}),xs.set(this,function(e,t,r){ne(n,gi,"f")&&(re(n,pi,!1,"f"),ne(n,Br,"f").reconnectStatus=!1,ne(n,Ti,"f")&&(re(n,Ti,!1,"f"),ne(n,Hs,"f").call(n,e,t,r)))}),As.set(this,function(){return te(n,void 0,void 0,O.mark(function e(){return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(ne(this,gi,"f")){re(this,pi,!0,"f"),re(this,Ti,!1,"f");try{this.getUserAgent().transport.disconnect().catch(function(e){return console.error(e)})}catch(e){}console.log("sip transport disconnect");try{ne(this,xr,"m",Cs).call(this)}catch(e){}ne(this,qs,"f").call(this),ne(this,xr,"m",js).call(this)}case 1:case"end":return e.stop()}},e,this)}))}),Ds.set(this,function(){if(ne(n,gi,"f")){var e=ne(n,Or,"f").uri.clone(),t=ne(n,Or,"f").uri.clone(),r=ne(n,Or,"f").uri.clone();r.user=void 0,ne(n,Hs,"f").call(n,r,e,t)}}),Hs.set(this,function(e,t,r){if(ne(n,gi,"f")){if(ne(n,Ti,"f"))return;re(n,Ti,!0,"f"),re(n,Ci,v(function(){ne(n,xr,"m",Os).call(n);var i=n.getUserAgent().userAgentCore,s=i.makeOutgoingRequestMessage("OPTIONS",e,t,r,{});re(n,mi,i.request(s,{onAccept:function(){console.log("sip ping ok"),re(n,vi,0,"f"),re(n,mi,void 0,"f"),ne(n,xs,"f").call(n,e,t,r)},onReject:function(i){var s;if(re(n,mi,void 0,"f"),408===i.message.statusCode||503===i.message.statusCode)if(console.log("sip ping error with code "+i.message.statusCode),ne(n,fi,"f")>0&&ne(n,vi,"f")>=ne(n,fi,"f"))console.log("sip maximum ping attempts reached"),ne(n,As,"f").call(n);else{var o,a;if(ne(n,vi,"f")>0)console.log(T(a="sip ping retry ".concat(ne(n,vi,"f")," of ")).call(a,ne(n,fi,"f")," fail"));re(n,vi,(s=ne(n,vi,"f"),++s),"f"),console.log(T(o="sip ping retry ".concat(ne(n,vi,"f")," of ")).call(o,ne(n,fi,"f"))),ne(n,xs,"f").call(n,e,t,r)}else re(n,vi,0,"f"),ne(n,xs,"f").call(n,e,t,r)}}),"f")},1e3*ne(n,gi,"f")),"f")}}),qs.set(this,function(){if(ne(n,gi,"f")){if(re(n,Ti,!1,"f"),re(n,pi,!1,"f"),ne(n,mi,"f")){try{ne(n,mi,"f").dispose()}catch(e){}re(n,mi,void 0,"f")}ne(n,Ci,"f")&&ne(n,xr,"m",Os).call(n)}}),Ns.set(this,function(){if(ne(n,bi,"f")){if(ne(n,Ii,"f"))return;re(n,Ii,!0,"f"),ne(n,Br,"f").reconnectStatus=!0,re(n,xi,v(function(){return te(n,void 0,void 0,O.mark(function e(){var t,n=this;return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,ne(this,xr,"m",Ms).call(this),0===ne(this,yi,"f")&&console.log("sip reconnect success then register start"),e.next=1,ne(this,qr,"f").register({requestDelegate:{onAccept:function(e){console.log("sip reconnect success and register ok"),re(n,yi,0,"f"),re(n,Ii,!1,"f"),ne(n,Br,"f").registerStatus=!0,ne(n,Br,"f").reconnectStatus=!1,ne(n,Ds,"f").call(n)},onReject:function(e){return te(n,void 0,void 0,O.mark(function t(){var n,r;return O.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),re(this,Ii,!1,"f"),!(ne(this,wi,"f")<=ne(this,yi,"f"))){t.next=2;break}return console.log("sip maximum register attempts reached"),re(this,yi,0,"f"),t.next=1,this.getUserAgent().transport.disconnect().catch(function(e){return console.error(e)});case 1:ne(this,xr,"m",js).call(this),t.next=3;break;case 2:re(this,yi,(n=ne(this,yi,"f"),++n),"f"),console.log(T(r="sip reconnect success and register retry ".concat(ne(this,yi,"f")," of ")).call(r,ne(this,wi,"f"))),ne(this,Ns,"f").call(this);case 3:case"end":return t.stop()}},t,this)}))}},requestOptions:{extraHeaders:ne(this,Dr,"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),re(this,yi,0,"f"),re(this,Ii,!1,"f");case 3:case"end":return e.stop()}},e,this,[[0,2]])}))},1e3*ne(n,bi,"f")),"f")}}),"object"!==Y(r))throw new Error("userAgentOption must be plain object");ne(this,xr,"m",ss).call(this,r),ne(this,xr,"m",os).call(this,r),ne(this,xr,"m",is).call(this,r),ne(this,xr,"m",as).call(this,r),ne(this,xr,"m",fs).call(this,r),ne(this,xr,"m",rs).call(this,r),ne(this,xr,"m",ns).call(this,r),re(this,Or,ne(this,xr,"m",ps).call(this,r),"f")},[{key:"volumeValue",get:function(){return ne(this,Ur,"f")}},{key:"businessAttribute",get:function(){return ne(this,Gi,"f")}},{key:"getFastOutboundCall",value:function(){return ne(this,Gi,"f").voiceType===gr.LABOUR}},{key:"getSitOutboundCall",value:function(){return ne(this,Gi,"f").voiceType===gr.AI}},{key:"detectNavigatorPermissions",value:function(){var e,t=this;-1===q(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){""!==h(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"===ne(this,Mi,"f")?"https://gateway.teleai.com":"https://gateway.94ai.com"}},{key:"getGatewayToken",value:function(){return te(this,void 0,void 0,O.mark(function e(){var t,n;return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,ne(this,ii,"f").call(this,ne(this,Kr,"f"));case 1:if(!ne(this,Vr,"f")){e.next=2;break}return e.abrupt("return",ne(this,Vr,"f"));case 2:if(this.token){e.next=5;break}return e.next=3,ne(this,ls,"f").call(this);case 3:return e.next=4,this.getGatewayAccessToken({corpId:ne(this,Ai,"f"),sid:ne(this,qi,"f"),secret:ne(this,Di,"f"),seatOnline:!1});case 4:t=e.sent,n=t.token,this.token=n,re(this,Wr,G(),"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 te(this,void 0,void 0,O.mark(function e(){var t,n,r,i=this;return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t=H({},ne(this,Gi,"f")),n=function(){return te(i,void 0,void 0,O.mark(function e(){var n,r,i,s,o,a,c,l,u,d,h,g,f,v,p,b,w,y,S,k;return O.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,ne(this,ai,"f").call(this,n.message),e.abrupt("return");case 3:e.next=5;break;case 4:return e.prev=4,e.catch(1),s=T(r=T(i="当前会话callid:".concat(t.callId,",根据numberId:")).call(i,t.numberId,",taskId:")).call(r,t.taskId,":查询坐席接听状态异常"),console.error(s),t.stop=!0,ne(this,ai,"f").call(this,n.message),e.abrupt("return");case 5:if(o=n.data,a=o.callType,c=o.newIntentTag,l=o.intentTag,u=o.number,d=o.numberMd5,h=o.sid,g=o.config,f=o.tag,10!==o.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=a),t.intentTag=c||l,t.number||(t.number=u),t.numberMD5||(t.numberMD5=d),t.agentId||(t.agentId=h),t.tag||(t.tag=f),t.templateId||g&&"string"==typeof g&&(v=JSON.parse(g))&&v.templateId&&(t.templateId=v.templateId),!t.callId){e.next=12;break}return b={},e.prev=7,e.next=8,this.getCallNumberChats({callId:t.callId,taskId:t.taskId});case 8:if(200===(b=e.sent).code){e.next=9;break}return console.error(b.message),t.stop=!0,ne(this,ai,"f").call(this,b.message),e.abrupt("return");case 9:e.next=11;break;case 10:return e.prev=10,e.catch(7),y=T(w="当前会话根据callId:".concat(t.callId,",taskId:")).call(w,t.taskId,":查询会话对话记录异常"),console.error(y),t.stop=!0,ne(this,ai,"f").call(this,y),e.abrupt("return");case 11:t.chats=m(p=b.data).call(p,function(e){return e.matchinfo&&(e.matchinfo=JSON.parse(e.matchinfo)),e}),ne(this,zr,"f")[t.callId]=t;case 12:try{ne(this,ei,"f").call(this,ne(this,zr,"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),ne(this,ai,"f").call(this,S)),t.numberId||(k="当前会话callid:".concat(t.callId,"的numberId不存在,无法查询通话记录"),console.error(k),ne(this,ai,"f").call(this,k));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 l(function(e){var t=v(function(){return te(i,void 0,void 0,O.mark(function n(){return O.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,r=e.catch(1),ne(this,ai,"f").call(this,r);case 9:case"end":return e.stop()}},e,this,[[1,8]])}))}},{key:"refreshCallChatInfo",value:function(){return te(this,void 0,void 0,O.mark(function e(){return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!(ne(this,Gi,"f").numberId&&ne(this,Gi,"f").callId&&ne(this,Gi,"f").taskId&&ne(this,Vi,"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)||("//"===d(e).call(e,0,2)?t.test(d(e).call(e,2,e.length)):"http://"===d(e).call(e,0,7)?t.test(d(e).call(e,7,e.length)):"https://"===d(e).call(e,0,8)?t.test(d(e).call(e,8,e.length)):t.test(e))}(ne(this,_i,"f"))?ne(this,_i,"f"):"1"===ne(this,Mi,"f")?"1"===ne(this,$i,"f")?"https://seat.teleai.com/teleaiopenapi":"https://seat.teleai.com/openapi":"1"===ne(this,$i,"f")?"https://seat.94ai.com/teleaiopenapi":"https://seat.94ai.com/openapi"}},{key:"getAgentInfo",value:function(){return this.requestOpenApi({url:"/v1/agent/getAgent",data:{agentTag:ne(this,Hi,"f"),agentId:ne(this,qi,"f")}})}},{key:"updateOpenApiAgentStatus",value:function(e){return this.requestOpenApi({url:"/v1/agent/updateAgentStatus",data:{agentTag:ne(this,Hi,"f"),agentId:ne(this,qi,"f"),agentStatus:e}})}},{key:"importOpenApiAgentCustomer",value:function(e){return this.requestOpenApi({url:"/v1/task/importAgentCustomer",data:{agentTag:ne(this,Hi,"f"),agentId:ne(this,qi,"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){re(this,Lr,e,"f")}},{key:"refreshTimestamp",value:function(e){re(this,Gr,e,"f")}},{key:"prepareUserAgent",value:function(e,t){var n;return te(this,void 0,void 0,O.mark(function r(){var i,s,o,a,c,l,u,d,h,g,f,v;return O.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return s=(i=e||{}).refresh,o=i.registererOptions,a=i.registererRegisterOptions,c=i.extraHeaders,l=i.authorizationUsername,u=i.authorizationPassword,d=i.uri,h=i.contactName,g=i.transportOptions,r.next=1,this.dispose();case 1:return ne(this,Or,"f").uri=null!=d?d:ne(this,Or,"f").uri,ne(this,Or,"f").authorizationUsername=null!=l?l:ne(this,Or,"f").authorizationUsername,ne(this,Or,"f").authorizationPassword=null!=u?u:ne(this,Or,"f").authorizationPassword,ne(this,Or,"f").contactName=null!==(n=null!=h?h:l)&&void 0!==n?n:ne(this,Or,"f").contactName,g&&(ne(this,Or,"f").transportOptions=H(H({},ne(this,Or,"f").transportOptions),g)),r.prev=2,ne(this,xr,"m",os).call(this,e),r.next=3,ne(this,ls,"f").call(this);case 3:return r.next=4,ne(this,us,"f").call(this);case 4:return ne(this,xr,"m",gs).call(this,{refresh:s}),r.next=5,ne(this,xr,"m",Us).call(this);case 5:return t&&ne(this,xr,"m",Bs).call(this,t),r.next=6,ne(this,xr,"m",Ls).call(this,{registererOptions:o,registererRegisterOptions:a,extraHeaders:c},ne(this,Bi,"f"));case 6:return f=r.sent,r.abrupt("return",f);case 7:return r.prev=7,v=r.catch(2),r.next=8,this.dispose();case 8:throw v;case 9:case"end":return r.stop()}},r,this,[[2,7]])}))}},{key:"dispose",value:function(){return te(this,void 0,void 0,O.mark(function e(){var t;return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,ne(this,xr,"m",ds).call(this),e.next=1,ne(this,xr,"m",bs).call(this);case 1:e.next=3;break;case 2:e.prev=2,t=e.catch(0),ne(this,xr,"m",ys).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 te(this,void 0,void 0,O.mark(function t(){return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return ne(this,Br,"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 te(this,void 0,void 0,O.mark(function t(){var n,r=this;return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=1,new l(function(t,n){te(r,void 0,void 0,O.mark(function r(){var i,s,o;return O.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.prev=0,i=null==e?void 0:e.onAck,s=null==e?void 0:e.onAckTimeout,null==e||delete e.onAck,null==e||delete e.onAckTimeout,r.next=1,this.getCurrentInvitation().accept(H({sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}},onAck:function(e){t(e),null==i||i()},onAckTimeout:function(){null==s||s(),n("接听响应超时")}},e||{}));case 1:r.next=3;break;case 2:r.prev=2,o=r.catch(0),n(o);case 3:case"end":return r.stop()}},r,this,[[0,2]])}))});case 1:ne(this,Br,"f").incomingStatus&&(ne(this,Br,"f").incomingStatus=!1,ne(this,Br,"f").answerStatus=!0),t.next=3;break;case 2:throw t.prev=2,n=t.catch(0),ne(this,Br,"f").incomingStatus=!1,n;case 3:case"end":return t.stop()}},t,this,[[0,2]])}))}},{key:"hangUpInvite",value:function(e){return te(this,void 0,void 0,O.mark(function t(){var n,r,i,s,o,a=this;return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=(n=e||{}).rejectOptions,i=n.byeOptions,s=n.extraHeaders,o=n.scoutResponse,t.abrupt("return",new l(function(e,t){return te(a,void 0,void 0,O.mark(function n(){var a,c,l,u,d,h,g,f,v,p,m;return O.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:n.prev=0,g=null===(a=(h=i||{}).requestDelegate)||void 0===a?void 0:a.onAccept,f=null===(c=h.requestDelegate)||void 0===c?void 0:c.onReject,null===(l=h.requestDelegate)||void 0===l||delete l.onAccept,null===(u=h.requestDelegate)||void 0===u||delete u.onReject,v=ne(this,xr,"m",vs).call(this,{onAccept:function(t){console.log("sip bye success"),e(t),null==g||g(t)},onReject:function(e){null==f||f(e),t("sip bye fail with code "+e.message.statusCode)}},h.requestDelegate),delete h.requestDelegate,p=null===(d=ne(this,Nr,"f"))||void 0===d?void 0:d.state,n.next=p===exports.SessionState.Initial||p===exports.SessionState.Establishing?1:p===exports.SessionState.Established?3:p===exports.SessionState.Terminating||p===exports.SessionState.Terminated?5:6;break;case 1:return n.next=2,ne(this,Nr,"f").reject(H({extraHeaders:s},r||{}));case 2:return e(!0),n.abrupt("continue",6);case 3:return n.next=4,ne(this,Nr,"f").bye(H({requestDelegate:v,requestOptions:{extraHeaders:s}},h));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,m=n.catch(0),t(m);case 8:return n.prev=8,ne(this,Br,"f").incomingStatus=!1,ne(this,Br,"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 te(this,void 0,void 0,O.mark(function t(){var n=this;return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new l(function(t,r){return te(n,void 0,void 0,O.mark(function n(){var i,s,o,a,c;return O.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,s=(i=e||{}).extraHeaders,o=i.requestDelegate,a=ne(this,xr,"m",vs).call(this,{onAccept:function(e){console.log("sip send dtmf Signal=* success"),t(e)},onReject:function(e){r("sip send dtmf Signal=* fail with code "+e.message.statusCode)}},o),delete i.requestDelegate,n.next=1,this.getCurrentInvitation().info(H({requestOptions:{body:{contentDisposition:"render",contentType:"application/dtmf-relay",content:"Signal=*\r\nDuration=100"},extraHeaders:s},requestDelegate:a},i));case 1:ne(this,Yi,"f").call(this),n.next=3;break;case 2:n.prev=2,c=n.catch(0),r(c);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;u(e=ne(this,$r,"f").getReceivers()).call(e,function(e){e.track.enabled=!1})}},{key:"unMuteRemoteAudio",value:function(){var e;u(e=ne(this,$r,"f").getReceivers()).call(e,function(e){e.track.enabled=!0})}},{key:"muteLocalAudio",value:function(){var e;u(e=ne(this,$r,"f").getSenders()).call(e,function(e){e.track.enabled=!1})}},{key:"unMuteLocalAudio",value:function(){var e;u(e=ne(this,$r,"f").getSenders()).call(e,function(e){e.track.enabled=!0})}},{key:"getUserAgentStatue",value:function(){return ne(this,Br,"f")}},{key:"getUserAgent",value:function(){return ne(this,Hr,"f")||re(this,Hr,new cr(ne(this,Or,"f")),"f"),ne(this,Hr,"f")}},{key:"getSessionDescriptionHandler",value:function(){return ne(this,_r,"f")}},{key:"getPeerConnection",value:function(){return ne(this,$r,"f")}},{key:"getSenders",value:function(){return ne(this,Pr,"f")}},{key:"getReceivers",value:function(){return ne(this,Mr,"f")}},{key:"getStream",value:function(){var e,t=this;return ne(this,Fr,"f")||re(this,Fr,new MediaStream,"f"),u(e=ne(this,Mr,"f")).call(e,function(e){e.track&&ne(t,Fr,"f").addTrack(e.track)}),ne(this,Fr,"f")}},{key:"getCurrentInviter",value:function(){if(!ne(this,jr,"f"))throw new Error("No currentInviter...");return ne(this,jr,"f")}},{key:"getCurrentInvitation",value:function(){return ne(this,Nr,"f")}},{key:"clearIceAutoDetection",value:function(){var e;null===(e=ne(this,Ar,"f"))||void 0===e||e.destroy(),re(this,Ar,void 0,"f")}},{key:"iceAutoDetectRecovery",value:function(e){var t,n=this;null===(t=ne(this,Ar,"f"))||void 0===t||t.destroy(),re(this,Ar,new Ws(e,{debugIceCredentials:!0,onRecoveryStart:function(e,t){console.log("开始 ICE 恢复",e,t)},onRecovered:function(){console.log("媒体连接已恢复")},isSignalingAvailable:function(){return ne(n,Hr,"f").isConnected()},isRegistrationAvailable:function(){return ne(n,qr,"f").state===St.Registered},onRecoveryFailed:function(e,t){console.error("ICE 恢复失败",e,t)}}),"f"),ne(this,Ar,"f").start()}},{key:"invite",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return te(this,void 0,void 0,O.mark(function n(){var r,i,s;return O.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(i=cr.makeURI(e.uri?e.uri:T(r="sip:".concat(e.extension,"@")).call(r,ne(this,Or,"f").transportOptions.server.split("://")[1]))){n.next=1;break}throw new Error("Failed to create target URI.");case 1:return re(this,jr,new kt(this.getUserAgent(),i,{sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}}}),"f"),s=(t||{}).extraHeaders,n.next=2,this.getCurrentInviter().invite(H({requestOptions:{extraHeaders:s}},t));case 2:return n.abrupt("return",ne(this,jr,"f"));case 3:case"end":return n.stop()}},n,this)}))}}])}();Ar=new K,Dr=new K,Hr=new K,qr=new K,_r=new K,$r=new K,Mr=new K,Pr=new K,Or=new K,Nr=new K,jr=new K,Fr=new K,Br=new K,Ur=new K,Lr=new K,Gr=new K,Vr=new K,Wr=new K,Yr=new K,Kr=new K,zr=new K,Zr=new K,Jr=new K,Xr=new K,Qr=new K,ei=new K,ti=new K,ni=new K,ri=new K,ii=new K,si=new K,oi=new K,ai=new K,ci=new K,li=new K,ui=new K,di=new K,hi=new K,gi=new K,fi=new K,vi=new K,pi=new K,mi=new K,bi=new K,wi=new K,yi=new K,Si=new K,ki=new K,Ri=new K,Ti=new K,Ii=new K,Ei=new K,Ci=new K,xi=new K,Ai=new K,Di=new K,Hi=new K,qi=new K,_i=new K,$i=new K,Mi=new K,Pi=new K,Oi=new K,Ni=new K,ji=new K,Fi=new K,Bi=new K,Ui=new K,Li=new K,Gi=new K,Vi=new K,Wi=new K,Yi=new K,Ki=new K,zi=new K,Zi=new K,Ji=new K,Xi=new K,Qi=new K,es=new K,ts=new K,ls=new K,us=new K,hs=new K,Es=new K,xs=new K,As=new K,Ds=new K,Hs=new K,qs=new K,Ns=new K,xr=new z,ns=function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};re(this,ti,null!==(e=n.openXhrIntercept)&&void 0!==e?e:ne(this,ti,"f"),"f"),re(this,ni,null!==(t=n.gatewayXhrIntercept)&&void 0!==t?t:ne(this,ni,"f"),"f")},rs=function(){var e,t,n,r,i,s,o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};re(this,Vi,null!==(e=o.enableChatInfoPush)&&void 0!==e?e:ne(this,Vi,"f"),"f"),re(this,Wi,null!==(t=o.enableVolumnTrack)&&void 0!==t?t:ne(this,Wi,"f"),"f"),re(this,Qr,null!==(n=o.refreshSpeekVolumn)&&void 0!==n?n:ne(this,Qr,"f"),"f"),re(this,ci,null!==(r=o.refreshRequirementCheck)&&void 0!==r?r:ne(this,ci,"f"),"f"),re(this,ei,null!==(i=o.refreshChat)&&void 0!==i?i:ne(this,ei,"f"),"f"),re(this,ai,null!==(s=o.refreshChatErrorCallback)&&void 0!==s?s:ne(this,ai,"f"),"f")},is=function(){var e,t,n,r,i,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};re(this,Vr,null!==(e=s.token)&&void 0!==e?e:ne(this,Vr,"f"),"f"),re(this,Wr,null!==(t=s.tokenTimestamp)&&void 0!==t?t:ne(this,Wr,"f"),"f"),re(this,Kr,null!==(n=s.tokenExpirationTime)&&void 0!==n?n:ne(this,Kr,"f"),"f"),ne(this,Vr,"f")&&!ne(this,Wr,"f")&&re(this,Wr,G(),"f"),re(this,ii,null!==(r=s.tokenCheck)&&void 0!==r?r:ne(this,ii,"f"),"f"),re(this,oi,null!==(i=s.tokenOverdued)&&void 0!==i?i:ne(this,oi,"f"),"f")},ss=function(){var e,t,n,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};re(this,Bi,null!==(e=r.clusterMode)&&void 0!==e?e:ne(this,Bi,"f"),"f"),re(this,Ui,null!==(t=r.reClusterRegisterTimeout)&&void 0!==t?t:ne(this,Ui,"f"),"f"),re(this,Li,null!==(n=r.reClusterConnectTimeout)&&void 0!==n?n:ne(this,Li,"f"),"f")},os=function(){var e,t,n,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=r.agentId,s=r.agentTag,o=r.appKey,a=r.appSecret,c=r.openBaseUrl,l=r.sg,u=r.sgOpen,d=r.sign,h=r.timestamp;re(this,qi,null!=i?i:ne(this,qi,"f"),"f"),re(this,Hi,null!=s?s:ne(this,Hi,"f"),"f"),re(this,Ai,null!=o?o:ne(this,Ai,"f"),"f"),re(this,Di,null!=a?a:ne(this,Di,"f"),"f"),re(this,_i,null!=c?c:ne(this,_i,"f"),"f"),re(this,Mi,null!=l?l:ne(this,Mi,"f"),"f"),re(this,$i,null!=u?u:ne(this,$i,"f"),"f"),re(this,Lr,null!=d?d:ne(this,Lr,"f"),"f"),re(this,Gr,null!=h?h:ne(this,Gr,"f"),"f"),re(this,Yr,null!==(e=r.signExpirationTime)&&void 0!==e?e:ne(this,Yr,"f"),"f"),re(this,ri,null!==(t=r.signCheck)&&void 0!==t?t:ne(this,ri,"f"),"f"),re(this,si,null!==(n=r.signOverdued)&&void 0!==n?n:ne(this,si,"f"),"f")},as=function(e){e.sipHeaders&&(re(this,Dr,e.sipHeaders,"f"),delete e.sipHeaders)},cs=function(){return!(!ne(this,qi,"f")&&!ne(this,Hi,"f")||!(ne(this,Ai,"f")&&ne(this,Di,"f")||ne(this,Lr,"f")&&ne(this,Gr,"f")))},ds=function(){ne(this,xr,"m",ws).call(this),ne(this,xr,"m",Rs).call(this),ne(this,xr,"m",Ts).call(this),ne(this,xr,"m",ks).call(this),ne(this,xr,"m",Ss).call(this),ne(this,xr,"m",_s).call(this),ne(this,xr,"m",$s).call(this),ne(this,xr,"m",ys).call(this),ne(this,Ki,"f").call(this),this.clearIceAutoDetection(),re(this,Gi,{},"f"),re(this,zr,{},"f")},gs=function(e){re(this,Br,W(JSON.parse(I(yr)),"function"==typeof e.refresh?e.refresh:ne(this,Ni,"f")),"f")},fs=function(e){var t,n,r,i,s,o,a,c,l,u,d,h,g,f,v;re(this,di,null!==(r=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!==r?r:ne(this,di,"f"),"f"),re(this,hi,null!==(a=null!==(s=null!==(i=e.reconnectionInterval)&&void 0!==i?i:e.reconnectionDelay)&&void 0!==s?s:null===(o=null==e?void 0:e.transportOptions)||void 0===o?void 0:o.reconnectionTimeout)&&void 0!==a?a:ne(this,hi,"f"),"f"),re(this,Si,null!==(l=null===(c=e.transportOptions)||void 0===c?void 0:c.keepAliveInterval)&&void 0!==l?l:ne(this,Si,"f"),"f"),re(this,ki,null!==(d=null===(u=e.transportOptions)||void 0===u?void 0:u.keepAliveDebounce)&&void 0!==d?d:ne(this,ki,"f"),"f"),re(this,bi,null!==(h=e.registerInterval)&&void 0!==h?h:ne(this,bi,"f"),"f"),re(this,gi,null!==(g=e.optionsPingInterval)&&void 0!==g?g:ne(this,gi,"f"),"f"),re(this,fi,null!==(f=e.optionsPingAttempts)&&void 0!==f?f:ne(this,fi,"f"),"f"),re(this,wi,null!==(v=e.registerAttempts)&&void 0!==v?v:ne(this,wi,"f"),"f")},vs=function(e,t){var n,r=this;return t?(u(n=E(t)).call(n,function(n){if(t[n]&&"function"==typeof t[n])if(e[n]){if("function"==typeof e[n]){var i=e[n];e[n]=function(e){return te(r,void 0,void 0,O.mark(function r(){return O.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=1,t[n](e);case 1:return r.next=2,i(e);case 2:case"end":return r.stop()}},r)}))}}}else e[n]=t[n]}),e):e},ps=function(e){var t,n=this,r={delegate:{onConnect:function(){return te(n,void 0,void 0,O.mark(function e(){return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:console.log("sip connected"),ne(this,Ds,"f").call(this);case 1:case"end":return e.stop()}},e,this)}))},onInvite:function(e){ne(n,hs,"f").call(n,e.incomingInviteRequest.message.headers),n.refreshCallChatInfo(),ne(n,xr,"m",ms).call(n),re(n,Nr,e,"f"),ne(n,Br,"f").incomingStatus=!0,n.iceAutoDetectRecovery(e),e.stateChange.addListener(ne(n,Es,"f"))},onDisconnect:function(e){return te(n,void 0,void 0,O.mark(function t(){var n;return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return console.log("sip disconnected"),n=!1,ne(this,gi,"f")>0&&(n=ne(this,pi,"f"),ne(this,qs,"f").call(this)),t.prev=1,t.next=2,ne(this,xr,"m",Cs).call(this);case 2:t.next=4;break;case 3:t.prev=3,t.catch(1);case 4:(e||n)&&ne(this,xr,"m",js).call(this);case 5:case"end":return t.stop()}},t,this,[[1,3]])}))}}};e.delegate?u(t=E(e.delegate)).call(t,function(t){var i=t;if(e.delegate[i]&&"function"==typeof e.delegate[i]){var s=e.delegate[i];e.delegate[i]=function(e){return te(n,void 0,void 0,O.mark(function t(){var n,o;return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return null===(o=(n=r.delegate)[i])||void 0===o||o.call(n,e),t.next=1,s(e);case 1:case"end":return t.stop()}},t)}))}}}):e.delegate=r.delegate;return e.reconnectionAttempts=0,e.transportOptions=H(H({},e.transportOptions||{}),{keepAliveInterval:ne(this,Si,"f"),keepAliveDebounce:ne(this,ki,"f")}),void 0===e.sessionDescriptionHandlerFactoryOptions&&(e.sessionDescriptionHandlerFactoryOptions={iceGatheringTimeout:2e3,peerConnectionConfiguration:{iceServers:[]}}),H(H({},wr),e)},ms=function(){ne(this,Nr,"f")&&(ne(this,Nr,"f").dispose(),re(this,Nr,void 0,"f"))},bs=function(){return te(this,void 0,void 0,O.mark(function e(){return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!ne(this,Hr,"f")){e.next=2;break}return e.next=1,ne(this,Hr,"f").stop();case 1:re(this,Hr,void 0,"f");case 2:case"end":return e.stop()}},e,this)}))},ws=function(){var e;ne(this,Fr,"f")&&(u(e=ne(this,Fr,"f").getTracks()).call(e,function(e){e.stop()}),re(this,Fr,void 0,"f"))},ys=function(){var e,t=this;u(e=E(yr)).call(e,function(e){var n=e;ne(t,Br,"f")[n]=yr[n]})},Ss=function(){ne(this,_r,"f")&&(ne(this,_r,"f").close(),re(this,_r,void 0,"f"))},ks=function(){ne(this,$r,"f")&&(ne(this,$r,"f").close(),re(this,$r,void 0,"f"))},Rs=function(){re(this,Pr,[],"f")},Ts=function(){re(this,Mr,[],"f")},Is=function(){var e=this.getCurrentInvitation().sessionDescriptionHandler;ne(this,xr,"m",ks).call(this),ne(this,xr,"m",Ss).call(this),ne(this,xr,"m",Rs).call(this),ne(this,xr,"m",Ts).call(this),re(this,_r,e,"f"),re(this,$r,e.peerConnection,"f"),re(this,Pr,ne(this,$r,"f").getSenders(),"f"),re(this,Mr,ne(this,$r,"f").getReceivers(),"f"),(this.getFastOutboundCall()||!this.getSitOutboundCall()&&this.notNeedSendStarDtmf())&&ne(this,Yi,"f").call(this)},Cs=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return te(this,void 0,void 0,O.mark(function t(){var n=this;return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!ne(this,qr,"f")){t.next=1;break}return console.log("sip due to disconnection, unregistered"),t.abrupt("return",new l(function(t,r){return te(n,void 0,void 0,O.mark(function n(){var i,s,o;return O.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,i=e||{},s=ne(this,xr,"m",vs).call(this,{onAccept:function(e){console.log("sip unregister successed"),t(e)},onReject:function(e){r("sip unregister fail with code "+e.message.statusCode)}},i.requestDelegate),delete e.requestDelegate,n.next=1,ne(this,qr,"f").unregister(H({requestDelegate:s},e));case 1:n.next=3;break;case 2:n.prev=2,o=n.catch(0),r(o);case 3:case"end":return n.stop()}},n,this,[[0,2]])}))}));case 1:case"end":return t.stop()}},t,this)}))},_s=function(){ne(this,xr,"m",Ms).call(this),ne(this,xr,"m",Ps).call(this),ne(this,xr,"m",Os).call(this),re(this,Ii,!1,"f"),re(this,Ri,!1,"f"),re(this,Ti,!1,"f")},$s=function(){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])&&(clearTimeout(ne(this,ji,"f")),re(this,ji,void 0,"f")),e&&(clearTimeout(ne(this,Fi,"f")),re(this,Fi,void 0,"f"))},Ms=function(){clearTimeout(ne(this,xi,"f")),re(this,xi,void 0,"f")},Ps=function(){clearTimeout(ne(this,Ei,"f")),re(this,Ei,void 0,"f")},Os=function(){clearTimeout(ne(this,Ci,"f")),re(this,Ci,void 0,"f")},js=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return te(this,void 0,void 0,O.mark(function n(){var r=this;return O.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(!ne(this,hi,"f")){n.next=4;break}if(ne(this,Br,"f").reconnectStatus=!0,!ne(this,Ri,"f")){n.next=1;break}return n.abrupt("return");case 1:if(!(t>ne(this,di,"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..."),re(this,Ri,!0,"f"),re(this,Ei,v(function(){ne(r,xr,"m",Ps).call(r),r.getUserAgent().reconnect().then(function(){return te(r,void 0,void 0,O.mark(function e(){var n;return O.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:console.log(T(n="sip reconnection attempt ".concat(t," of ")).call(n,ne(this,di,"f")," - succeeded")),re(this,Ri,!1,"f"),ne(this,Ns,"f").call(this);case 1:case"end":return e.stop()}},e,this)}))}).catch(function(n){var i;console.error(n),console.log(T(i="sip reconnection attempt ".concat(t," of ")).call(i,ne(r,di,"f")," - failed")),re(r,Ri,!1,"f"),ne(r,xr,"m",e).call(r,++t)})},1===t?0:1e3*ne(this,hi,"f")),"f");case 4:case"end":return n.stop()}},n,this)}))},Fs=function(e){var t,n=this;return u(t=E(e)).call(t,function(t){var r=t;if("function"==typeof(null==e?void 0:e[r])){var i=e[r];e[r]=function(e){return te(n,void 0,void 0,O.mark(function t(){var n,s;return O.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return null===(s=(n=ne(this,Or,"f").delegate)[r])||void 0===s||s.call(n,e),t.next=1,i(e);case 1:case"end":return t.stop()}},t,this)}))}}}),e},Bs=function(e){var t=this.getUserAgent();return t.delegate=ne(this,xr,"m",Fs).call(this,e),t},Us=function(){return te(this,void 0,void 0,O.mark(function e(){var t;return O.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 ne(this,Br,"f").connectStatus=!0,e.abrupt("return",t);case 4:case"end":return e.stop()}},e,this)}))},Ls=function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=t||{},s=i.registererOptions,o=i.registererRegisterOptions,a=i.extraHeaders;return new l(function(t,i){return te(n,void 0,void 0,O.mark(function n(){var c,l,u,d,h,g=this;return O.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return c=this.getUserAgent(),re(this,qr,new xt(c,H({extraHeaders:a||ne(this,Dr,"f")},s||{})),"f"),u=o||{},d=ne(this,xr,"m",vs).call(this,{onAccept:function(e){l=e,ne(g,xr,"m",$s).call(g),ne(g,Br,"f").registerStatus=!0,t(c)},onReject:function(e){ne(g,xr,"m",$s).call(g),i("sip register fail with code "+e.message.statusCode)}},u.requestDelegate),delete u.requestDelegate,r&&re(this,ji,v(function(){return te(g,void 0,void 0,O.mark(function n(){var r,h=this;return O.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(l){n.next=4;break}re(this,Fi,v(function(){return te(h,void 0,void 0,O.mark(function n(){var r,c;return O.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(ne(this,xr,"m",$s).call(this,!1,!0),l){n.next=6;break}n.prev=1;try{ne(this,qr,"f").dispose()}catch(e){}return ne(this,xr,"m",ds).call(this),ne(this,qs,"f").call(this),re(this,vi,0,"f"),re(this,yi,0,"f"),n.next=2,ne(this,Hr,"f").transport.dispose();case 2:return re(this,Hr,new cr(ne(this,Or,"f")),"f"),n.next=3,ne(this,xr,"m",Us).call(this);case 3:return n.next=4,ne(this,xr,"m",e).call(this,{registererOptions:s,registererRegisterOptions:o,extraHeaders:a});case 4:r=n.sent,t(r),n.next=6;break;case 5:n.prev=5,c=n.catch(1),i(c);case 6:case"end":return n.stop()}},n,this,[[1,5]])}))},ne(this,Li,"f")),"f");try{ne(this,qr,"f").dispose()}catch(e){}return re(this,qr,new xt(c,H({extraHeaders:a||ne(this,Dr,"f")},s||{})),"f"),ne(this,xr,"m",$s).call(this,!0,!1),n.prev=1,n.next=2,ne(this,qr,"f").register(H({requestDelegate:d,requestOptions:{extraHeaders:a||ne(this,Dr,"f")}},u));case 2:n.next=4;break;case 3:n.prev=3,r=n.catch(1),ne(this,xr,"m",$s).call(this),i(r);case 4:case"end":return n.stop()}},n,this,[[1,3]])}))},ne(this,Ui,"f")),"f"),n.prev=1,n.next=2,ne(this,qr,"f").register(H({requestDelegate:d,requestOptions:{extraHeaders:a||ne(this,Dr,"f")}},u));case 2:n.next=4;break;case 3:n.prev=3,h=n.catch(1),ne(this,xr,"m",$s).call(this),i(h);case 4:case"end":return n.stop()}},n,this,[[1,3]])}))})};var Ks=function(){return t(function t(){e(this,t)},null,[{key:"getUserAgentManager",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return ne(this,Gs,"f",Vs)||re(this,Gs,new Ys(e),"f",Vs),ne(this,Gs,"f",Vs)}},{key:"hasUserAgentManager",value:function(){return!!ne(this,Gs,"f",Vs)}},{key:"newUserAgentManager",value:function(){return new Ys(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})}},{key:"dispose",value:function(){if(ne(this,Gs,"f",Vs))try{ne(this,Gs,"f",Vs).dispose()}catch(e){}finally{re(this,Gs,void 0,"f",Vs)}}}])}();Gs=Ks,Vs={value:void 0},exports.onChange=W,exports.Inviter=kt,exports.Registerer=xt,exports.SimpleUser=pr,exports.URI=Ie,exports.UserAgent=cr,exports.UserAgentFactory=Ks,exports.UserAgentManager=Ys,exports.accumulateSec=Er,exports.accumulationTimer=function(e){var t=Ir();e(Tr(t));var n=U(function(){var n=Er(t),r=Tr(n);e(r)},1e3);return function(){clearInterval(n),n=null}},exports.cleanupMedia=function(e){var t=Sr(e);t&&(t.srcObject=null,t.pause())},exports.getDevicePermission=Rr,exports.getMedia=Sr,exports.getTimes=Tr,exports.getZeorTime=Ir,exports.pauseMedia=function(e){var t=Sr(e);t&&(t.currentTime=0,t.pause())},exports.playMedia=function(e){var t=Sr(e);t&&(t.currentTime=0,t.play())},exports.requestMicroPhonePermission=function(){try{var e;if(-1===q(e=navigator.userAgent).call(e,"Firefox"))return Rr({video:!1,audio:!0}).catch(function(){return!0})}catch(e){console.log(e)}},exports.stopStreamTracks=kr,exports.userAgentDefault=wr,exports.userAgentStatus=yr;
|