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