@94ai/softphone 6.0.11 → 6.0.12
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/README.md +943 -0
- 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 +2 -2
- 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 n from"@babel/runtime-corejs3/regenerator";import i from"@babel/runtime-corejs3/core-js/promise";import r from"@babel/runtime-corejs3/core-js/date/now";import s from"@babel/runtime-corejs3/core-js/reflect/construct";import a from"@babel/runtime-corejs3/helpers/esm/possibleConstructorReturn";import o from"@babel/runtime-corejs3/helpers/esm/getPrototypeOf";import c from"@babel/runtime-corejs3/helpers/esm/inherits";import l from"@babel/runtime-corejs3/helpers/esm/wrapNativeSuper";import u from"@babel/runtime-corejs3/core-js/object/set-prototype-of";import d from"@babel/runtime-corejs3/core-js/object/define-property";import h from"@babel/runtime-corejs3/core-js/instance/for-each";import g from"@babel/runtime-corejs3/core-js/instance/slice";import f from"@babel/runtime-corejs3/core-js/instance/filter";import v from"@babel/runtime-corejs3/helpers/esm/get";import p from"@babel/runtime-corejs3/core-js/instance/includes";import m from"@babel/runtime-corejs3/core-js/set-timeout";import b from"@babel/runtime-corejs3/core-js/instance/repeat";import w from"@babel/runtime-corejs3/core-js/instance/map";import y from"@babel/runtime-corejs3/core-js/array/is-array";import k from"@babel/runtime-corejs3/core-js/instance/sort";import T from"@babel/runtime-corejs3/core-js/parse-int";import R from"@babel/runtime-corejs3/core-js/instance/trim";import S from"@babel/runtime-corejs3/core-js/parse-float";import I from"@babel/runtime-corejs3/core-js/instance/splice";import E from"@babel/runtime-corejs3/core-js/instance/concat";import C from"@babel/runtime-corejs3/core-js/json/stringify";import A from"@babel/runtime-corejs3/core-js/object/keys";import x from"@babel/runtime-corejs3/core-js/instance/every";import D from"@babel/runtime-corejs3/core-js/array/from";import H from"@babel/runtime-corejs3/core-js/symbol";import _ from"@babel/runtime-corejs3/core-js/get-iterator-method";import $ from"@babel/runtime-corejs3/core-js/object/assign";import q from"@babel/runtime-corejs3/core-js/instance/index-of";import M from"@babel/runtime-corejs3/core-js/map";import P from"@babel/runtime-corejs3/core-js/number/parse-int";import O from"@babel/runtime-corejs3/core-js/instance/reduce";import N from"@babel/runtime-corejs3/helpers/esm/toConsumableArray";import j from"@babel/runtime-corejs3/core-js/instance/keys";import F from"@babel/runtime-corejs3/core-js/set";import U from"@babel/runtime-corejs3/core-js/instance/some";import B from"@babel/runtime-corejs3/core-js/instance/values";import L from"@babel/runtime-corejs3/core-js/set-interval";import G from"@babel/runtime-corejs3/core-js/instance/reverse";import"@babel/runtime-corejs3/helpers/esm/readOnlyError";import V from"@babel/runtime-corejs3/core-js/instance/find";import"@babel/runtime-corejs3/helpers/esm/slicedToArray";import W from"on-change";export{default as onChange}from"on-change";import Y from"@babel/runtime-corejs3/core-js/instance/pad-start";import K from"@babel/runtime-corejs3/helpers/esm/typeof";import z from"@babel/runtime-corejs3/core-js/weak-map";import Z from"@babel/runtime-corejs3/core-js/weak-set";import J from"crypto-js";import X from"@fingerprintjs/fingerprintjs";import Q from"@babel/runtime-corejs3/core-js/instance/starts-with";import ee from"@babel/runtime-corejs3/core-js/instance/find-index";import{AliArmsManager as te}from"@94ai/arms";function ne(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 ie(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 re(e,t,n,i,r){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?r.call(e,n):r?r.value=n:t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;function se(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(se=function(){return!!e})()}var ae=function(n){function i(t){var n,r,c,l;return e(this,i),r=this,l=[t],c=o(c=i),n=a(r,se()?s(c,l||[],o(r).constructor):c.apply(r,l)),u(n,(this instanceof i?this.constructor:void 0).prototype),n}return c(i,n),t(i)}(l(Error));function oe(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(oe=function(){return!!e})()}var ce=function(){function n(t){return e(this,n),i=this,c=[t||"Unsupported content type."],r=o(r=n),a(i,oe()?s(r,c||[],o(i).constructor):r.apply(i,c));var i,r,c}return c(n,ae),t(n)}();function le(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(le=function(){return!!e})()}var ue=function(){function n(t){return e(this,n),i=this,c=[t||"Request pending."],r=o(r=n),a(i,le()?s(r,c||[],o(i).constructor):r.apply(i,c));var i,r,c}return c(n,ae),t(n)}();function de(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(de=function(){return!!e})()}var he=function(){function n(t){return e(this,n),i=this,c=[t||"Unspecified session description handler error."],r=o(r=n),a(i,de()?s(r,c||[],o(i).constructor):r.apply(i,c));var i,r,c}return c(n,ae),t(n)}();function ge(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(ge=function(){return!!e})()}var fe=function(){function n(){return e(this,n),t=this,r=["The session has terminated."],i=o(i=n),a(t,ge()?s(i,r||[],o(t).constructor):i.apply(t,r));var t,i,r}return c(n,ae),t(n)}();function ve(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(ve=function(){return!!e})()}var pe=function(){function n(t){return e(this,n),i=this,c=[t||"An error occurred during state transition."],r=o(r=n),a(i,ve()?s(r,c||[],o(i).constructor):r.apply(i,c));var i,r,c}return c(n,ae),t(n)}(),me=function(){return t(function t(n){e(this,t),d(this,"incomingAckRequest",{enumerable:!0,configurable:!0,writable:!0,value:n})},[{key:"request",get:function(){return this.incomingAckRequest.message}}])}(),be=function(){return t(function t(n){e(this,t),d(this,"incomingByeRequest",{enumerable:!0,configurable:!0,writable:!0,value:n})},[{key:"request",get:function(){return this.incomingByeRequest.message}},{key:"accept",value:function(e){return this.incomingByeRequest.accept(e),i.resolve()}},{key:"reject",value:function(e){return this.incomingByeRequest.reject(e),i.resolve()}}])}(),we=function(){return t(function t(n){e(this,t),d(this,"incomingCancelRequest",{enumerable:!0,configurable:!0,writable:!0,value:n})},[{key:"request",get:function(){return this.incomingCancelRequest}}])}(),ye=function(){return t(function t(){e(this,t),d(this,"listeners",{enumerable:!0,configurable:!0,writable:!0,value:new Array})},[{key:"addListener",value:function(e,t){var n=this,i=function(t){n.removeListener(i),e(t)};!0===(null==t?void 0:t.once)?this.listeners.push(i):this.listeners.push(e)}},{key:"emit",value:function(e){var t,n;h(t=g(n=this.listeners).call(n)).call(t,function(t){return t(e)})}},{key:"removeAllListeners",value:function(){this.listeners=[]}},{key:"removeListener",value:function(e){var t;this.listeners=f(t=this.listeners).call(t,function(t){return t!==e})}},{key:"on",value:function(e){return this.addListener(e)}},{key:"off",value:function(e){return this.removeListener(e)}},{key:"once",value:function(e){return this.addListener(e,{once:!0})}}])}(),ke=function(){return t(function t(n){e(this,t),d(this,"incomingInfoRequest",{enumerable:!0,configurable:!0,writable:!0,value:n})},[{key:"request",get:function(){return this.incomingInfoRequest.message}},{key:"accept",value:function(e){return this.incomingInfoRequest.accept(e),i.resolve()}},{key:"reject",value:function(e){return this.incomingInfoRequest.reject(e),i.resolve()}}])}(),Te=function(){return t(function t(n){for(var i in e(this,t),d(this,"parameters",{enumerable:!0,configurable:!0,writable:!0,value:{}}),n)n.hasOwnProperty(i)&&this.setParam(i,n[i])},[{key:"setParam",value:function(e,t){e&&(this.parameters[e.toLowerCase()]=null==t?null:t.toString())}},{key:"getParam",value:function(e){if(e)return this.parameters[e.toLowerCase()]}},{key:"hasParam",value:function(e){return!(!e||void 0===this.parameters[e.toLowerCase()])}},{key:"deleteParam",value:function(e){if(e=e.toLowerCase(),this.hasParam(e)){var t=this.parameters[e];return delete this.parameters[e],t}}},{key:"clearParams",value:function(){this.parameters={}}}])}();function Re(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Re=function(){return!!e})()}var Se=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,h=[r],u=o(u=n),c=a(l,Re()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"uri",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"_displayName",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c.uri=t,c._displayName=i,c}return c(n,Te),t(n,[{key:"friendlyName",get:function(){return this.displayName||this.uri.aor}},{key:"displayName",get:function(){return this._displayName},set:function(e){this._displayName=e}},{key:"clone",value:function(){return new n(this.uri.clone(),this._displayName,JSON.parse(C(this.parameters)))}},{key:"toString",value:function(){var e=this.displayName||"0"===this.displayName?'"'+this.displayName+'" ':"";for(var t in e+="<"+this.uri.toString()+">",this.parameters)this.parameters.hasOwnProperty(t)&&(e+=";"+t,null!==this.parameters[t]&&(e+="="+this.parameters[t]));return e}}])}();function Ie(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Ie=function(){return!!e})()}var Ee=function(){function n(){var t,i,r,c,l=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"sip",u=arguments.length>1?arguments[1]:void 0,h=arguments.length>2?arguments[2]:void 0,g=arguments.length>3?arguments[3]:void 0,f=arguments.length>4?arguments[4]:void 0,v=arguments.length>5?arguments[5]:void 0;if(e(this,n),i=this,c=[f||{}],r=o(r=n),t=a(i,Ie()?s(r,c||[],o(i).constructor):r.apply(i,c)),d(t,"headers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),d(t,"normal",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(t,"raw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),!h)throw new TypeError('missing or invalid "host" parameter');for(var p in v)v.hasOwnProperty(p)&&t.setHeader(p,v[p]);return t.raw={scheme:l,user:u,host:h,port:g},t.normal={scheme:l.toLowerCase(),user:u,host:h.toLowerCase(),port:g},t}return c(n,Te),t(n,[{key:"scheme",get:function(){return this.normal.scheme},set:function(e){this.raw.scheme=e,this.normal.scheme=e.toLowerCase()}},{key:"user",get:function(){return this.normal.user},set:function(e){this.normal.user=this.raw.user=e}},{key:"host",get:function(){return this.normal.host},set:function(e){this.raw.host=e,this.normal.host=e.toLowerCase()}},{key:"aor",get:function(){return this.normal.user+"@"+this.normal.host}},{key:"port",get:function(){return this.normal.port},set:function(e){this.normal.port=this.raw.port=e}},{key:"setHeader",value:function(e,t){this.headers[this.headerize(e)]=t instanceof Array?t:[t]}},{key:"getHeader",value:function(e){if(e)return this.headers[this.headerize(e)]}},{key:"hasHeader",value:function(e){return!!e&&!!this.headers.hasOwnProperty(this.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=this.headerize(e),this.headers.hasOwnProperty(e)){var t=this.headers[e];return delete this.headers[e],t}}},{key:"clearHeaders",value:function(){this.headers={}}},{key:"clone",value:function(){return new n(this._raw.scheme,this._raw.user||"",this._raw.host,this._raw.port,JSON.parse(C(this.parameters)),JSON.parse(C(this.headers)))}},{key:"toRaw",value:function(){return this._toString(this._raw)}},{key:"toString",value:function(){return this._toString(this._normal)}},{key:"_normal",get:function(){return this.normal}},{key:"_raw",get:function(){return this.raw}},{key:"_toString",value:function(e){var t=e.scheme+":";for(var n in e.scheme.toLowerCase().match("^sips?$")||(t+="//"),e.user&&(t+=this.escapeUser(e.user)+"@"),t+=e.host,(e.port||0===e.port)&&(t+=":"+e.port),this.parameters)this.parameters.hasOwnProperty(n)&&(t+=";"+n,null!==this.parameters[n]&&(t+="="+this.parameters[n]));var i=[];for(var r in this.headers)if(this.headers.hasOwnProperty(r))for(var s in this.headers[r])this.headers[r].hasOwnProperty(s)&&i.push(r+"="+this.headers[r][s]);return i.length>0&&(t+="?"+i.join("&")),t}},{key:"escapeUser",value:function(e){var t;try{t=decodeURIComponent(e)}catch(e){throw e}return encodeURIComponent(t).replace(/%3A/gi,":").replace(/%2B/gi,"+").replace(/%3F/gi,"?").replace(/%2F/gi,"/")}},{key:"headerize",value:function(e){for(var t={"Call-Id":"Call-ID",Cseq:"CSeq","Min-Se":"Min-SE",Rack:"RAck",Rseq:"RSeq","Www-Authenticate":"WWW-Authenticate"},n=e.toLowerCase().replace(/_/g,"-").split("-"),i=n.length,r="",s=0;s<i;s++)0!==s&&(r+="-"),r+=n[s].charAt(0).toUpperCase()+n[s].substring(1);return t[r]&&(r=t[r]),r}}])}();function Ce(e,t){if(e.scheme!==t.scheme)return!1;if(e.user!==t.user||e.host!==t.host||e.port!==t.port)return!1;if(!function(e,t){var n,i,r=A(e.parameters),s=A(t.parameters),a=f(r).call(r,function(e){return p(s).call(s,e)});return!!x(a).call(a,function(n){return e.parameters[n]===t.parameters[n]})&&(!!x(n=["user","ttl","method","transport"]).call(n,function(n){return e.hasParam(n)&&t.hasParam(n)||!e.hasParam(n)&&!t.hasParam(n)})&&!!x(i=["maddr"]).call(i,function(n){return e.hasParam(n)&&t.hasParam(n)||!e.hasParam(n)&&!t.hasParam(n)}))}(e,t))return!1;var n=A(e.headers),i=A(t.headers);if(0!==n.length||0!==i.length){if(n.length!==i.length)return!1;var r=f(n).call(n,function(e){return p(i).call(i,e)});if(r.length!==i.length)return!1;if(!x(r).call(r,function(n){return e.headers[n].length&&t.headers[n].length&&e.headers[n][0]===t.headers[n][0]}))return!1}return!0}function Ae(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Ae=function(){return!!e})()}function xe(e,t,n){return n=n||" ",e.length>t?e:(t-=e.length,n+=b(n).call(n,t),e+g(n).call(n,0,t))}var De=function(n){function i(t,n,r,c){var l,h,g,f;return e(this,i),h=this,g=o(g=i),l=a(h,Ae()?s(g,f||[],o(h).constructor):g.apply(h,f)),d(l,"message",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"expected",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"found",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"location",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"name",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),l.message=t,l.expected=n,l.found=r,l.location=c,l.name="SyntaxError","function"==typeof u?u(l,i.prototype):l.__proto__=i.prototype,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(l,i),l}return c(i,n),t(i,[{key:"format",value:function(e){var t="Error: "+this.message;if(this.location){var n,i=null;for(n=0;n<e.length;n++)if(e[n].source===this.location.source){i=e[n].text.split(/\r\n|\n|\r/g);break}var r=this.location.start,s=this.location.source+":"+r.line+":"+r.column;if(i){var a=this.location.end,o=xe("",r.line.toString().length," "),c=i[r.line-1],l=r.line===a.line?a.column:c.length+1;t+="\n --\x3e "+s+"\n"+o+" |\n"+r.line+" | "+c+"\n"+o+" | "+xe("",r.column-1," ")+xe("",l-r.column,"^")}else t+="\n at "+s}return t}}],[{key:"buildMessage",value:function(e,t){function n(e){return e.charCodeAt(0).toString(16).toUpperCase()}function i(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+n(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+n(e)})}function r(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+n(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+n(e)})}function s(e){var t;switch(e.type){case"literal":return'"'+i(e.text)+'"';case"class":var n=w(t=e.parts).call(t,function(e){return y(e)?r(e[0])+"-"+r(e[1]):r(e)});return"["+(e.inverted?"^":"")+n+"]";case"any":return"any character";case"end":return"end of input";case"other":return e.description}}return"Expected "+function(e){var t,n,i=w(e).call(e,s);if(k(i).call(i),i.length>0){for(t=1,n=1;t<i.length;t++)i[t-1]!==i[t]&&(i[n]=i[t],n++);i.length=n}switch(i.length){case 1:return i[0];case 2:return i[0]+" or "+i[1];default:return g(i).call(i,0,-1).join(", ")+", or "+i[i.length-1]}}(e)+" but "+(((a=t)?'"'+i(a)+'"':"end of input")+" found.");var a}}])}(l(Error));var He,_e=function(e,t){var n,i,r,s,a={},o=(t=void 0!==t?t:{}).grammarSource,c={Contact:119,Name_Addr_Header:156,Record_Route:176,Request_Response:81,SIP_URI:45,Subscription_State:186,Supported:191,Require:182,Via:194,absoluteURI:84,Call_ID:118,Content_Disposition:130,Content_Length:135,Content_Type:136,CSeq:146,displayName:122,Event:149,From:151,host:52,Max_Forwards:154,Min_SE:213,Proxy_Authenticate:157,quoted_string:40,Refer_To:178,Replaces:179,Session_Expires:210,stun_URI:217,To:192,turn_URI:223,uuid:226,WWW_Authenticate:209,challenge:158,sipfrag:230,Referred_By:231},l=119,u=["\r\n",C("\r\n",!1),/^[0-9]/,A([["0","9"]],!1,!1),/^[a-zA-Z]/,A([["a","z"],["A","Z"]],!1,!1),/^[0-9a-fA-F]/,A([["0","9"],["a","f"],["A","F"]],!1,!1),/^[\0-\xFF]/,A([["\0","ÿ"]],!1,!1),/^["]/,A(['"'],!1,!1)," ",C(" ",!1),"\t",C("\t",!1),/^[a-zA-Z0-9]/,A([["a","z"],["A","Z"],["0","9"]],!1,!1),";",C(";",!1),"/",C("/",!1),"?",C("?",!1),":",C(":",!1),"@",C("@",!1),"&",C("&",!1),"=",C("=",!1),"+",C("+",!1),"$",C("$",!1),",",C(",",!1),"-",C("-",!1),"_",C("_",!1),".",C(".",!1),"!",C("!",!1),"~",C("~",!1),"*",C("*",!1),"'",C("'",!1),"(",C("(",!1),")",C(")",!1),"%",C("%",!1),function(){return" "},function(){return":"},/^[!-~]/,A([["!","~"]],!1,!1),/^[\x80-\uFFFF]/,A([["",""]],!1,!1),/^[\x80-\xBF]/,A([["","¿"]],!1,!1),/^[a-f]/,A([["a","f"]],!1,!1),"`",C("`",!1),"<",C("<",!1),">",C(">",!1),"\\",C("\\",!1),"[",C("[",!1),"]",C("]",!1),"{",C("{",!1),"}",C("}",!1),function(){return"*"},function(){return"/"},function(){return"="},function(){return"("},function(){return")"},function(){return">"},function(){return"<"},function(){return","},function(){return";"},function(){return":"},function(){return'"'},/^[!-']/,A([["!","'"]],!1,!1),/^[*-[]/,A([["*","["]],!1,!1),/^[\]-~]/,A([["]","~"]],!1,!1),function(e){return e},/^[#-[]/,A([["#","["]],!1,!1),/^[\0-\t]/,A([["\0","\t"]],!1,!1),/^[\v-\f]/,A([["\v","\f"]],!1,!1),/^[\x0E-\x7F]/,A([["",""]],!1,!1),function(){(t=t||{data:{}}).data.uri=new Ee(t.data.scheme,t.data.user,t.data.host,t.data.port),delete t.data.scheme,delete t.data.user,delete t.data.host,delete t.data.host_type,delete t.data.port},function(){(t=t||{data:{}}).data.uri=new Ee(t.data.scheme,t.data.user,t.data.host,t.data.port,t.data.uri_params,t.data.uri_headers),delete t.data.scheme,delete t.data.user,delete t.data.host,delete t.data.host_type,delete t.data.port,delete t.data.uri_params,"SIP_URI"===t.startRule&&(t.data=t.data.uri)},"sips",C("sips",!0),"sip",C("sip",!0),function(e){(t=t||{data:{}}).data.scheme=e},function(){var e;(t=t||{data:{}}).data.user=decodeURIComponent(g(e=y()).call(e,0,-1))},function(){(t=t||{data:{}}).data.password=y()},function(){return(t=t||{data:{}}).data.host=y(),t.data.host},function(){return(t=t||{data:{}}).data.host_type="domain",y()},/^[a-zA-Z0-9_\-]/,A([["a","z"],["A","Z"],["0","9"],"_","-"],!1,!1),/^[a-zA-Z0-9\-]/,A([["a","z"],["A","Z"],["0","9"],"-"],!1,!1),function(){return(t=t||{data:{}}).data.host_type="IPv6",y()},"::",C("::",!1),function(){return(t=t||{data:{}}).data.host_type="IPv6",y()},function(){return(t=t||{data:{}}).data.host_type="IPv4",y()},"25",C("25",!1),/^[0-5]/,A([["0","5"]],!1,!1),"2",C("2",!1),/^[0-4]/,A([["0","4"]],!1,!1),"1",C("1",!1),/^[1-9]/,A([["1","9"]],!1,!1),function(e){return t=t||{data:{}},e=T(e.join("")),t.data.port=e,e},"transport=",C("transport=",!0),"udp",C("udp",!0),"tcp",C("tcp",!0),"sctp",C("sctp",!0),"tls",C("tls",!0),function(e){(t=t||{data:{}}).data.uri_params||(t.data.uri_params={}),t.data.uri_params.transport=e.toLowerCase()},"user=",C("user=",!0),"phone",C("phone",!0),"ip",C("ip",!0),function(e){(t=t||{data:{}}).data.uri_params||(t.data.uri_params={}),t.data.uri_params.user=e.toLowerCase()},"method=",C("method=",!0),function(e){(t=t||{data:{}}).data.uri_params||(t.data.uri_params={}),t.data.uri_params.method=e},"ttl=",C("ttl=",!0),function(e){(t=t||{data:{}}).data.params||(t.data.params={}),t.data.params.ttl=e},"maddr=",C("maddr=",!0),function(e){(t=t||{data:{}}).data.uri_params||(t.data.uri_params={}),t.data.uri_params.maddr=e},"lr",C("lr",!0),function(){(t=t||{data:{}}).data.uri_params||(t.data.uri_params={}),t.data.uri_params.lr=void 0},function(e,n){(t=t||{data:{}}).data.uri_params||(t.data.uri_params={}),n=null===n?void 0:n[1],t.data.uri_params[e.toLowerCase()]=n},function(e,n){e=e.join("").toLowerCase(),n=n.join(""),(t=t||{data:{}}).data.uri_headers||(t.data.uri_headers={}),t.data.uri_headers[e]?t.data.uri_headers[e].push(n):t.data.uri_headers[e]=[n]},function(){"Refer_To"===(t=t||{data:{}}).startRule&&(t.data.uri=new Ee(t.data.scheme,t.data.user,t.data.host,t.data.port,t.data.uri_params,t.data.uri_headers),delete t.data.scheme,delete t.data.user,delete t.data.host,delete t.data.host_type,delete t.data.port,delete t.data.uri_params)},"//",C("//",!1),function(){(t=t||{data:{}}).data.scheme=y()},C("SIP",!0),function(){(t=t||{data:{}}).data.sip_version=y()},"INVITE",C("INVITE",!1),"ACK",C("ACK",!1),"VXACH",C("VXACH",!1),"OPTIONS",C("OPTIONS",!1),"BYE",C("BYE",!1),"CANCEL",C("CANCEL",!1),"REGISTER",C("REGISTER",!1),"SUBSCRIBE",C("SUBSCRIBE",!1),"NOTIFY",C("NOTIFY",!1),"REFER",C("REFER",!1),"PUBLISH",C("PUBLISH",!1),function(){return(t=t||{data:{}}).data.method=y(),t.data.method},function(e){(t=t||{data:{}}).data.status_code=T(e.join(""))},function(){(t=t||{data:{}}).data.reason_phrase=y()},function(){(t=t||{data:{}}).data=y()},function(){var e,n;for(n=(t=t||{data:{}}).data.multi_header.length,e=0;e<n;e++)if(null===t.data.multi_header[e].parsed){t.data=null;break}null!==t.data?t.data=t.data.multi_header:t.data=-1},function(){var e;(t=t||{data:{}}).data.multi_header||(t.data.multi_header=[]);try{e=new Se(t.data.uri,t.data.displayName,t.data.params),delete t.data.uri,delete t.data.displayName,delete t.data.params}catch(t){e=null}t.data.multi_header.push({position:h,offset:k().start.offset,parsed:e})},function(e){var n;'"'===(e=R(n=y()).call(n))[0]&&(e=e.substring(1,e.length-1)),(t=t||{data:{}}).data.displayName=e},"q",C("q",!0),function(e){(t=t||{data:{}}).data.params||(t.data.params={}),t.data.params.q=e},"expires",C("expires",!0),function(e){(t=t||{data:{}}).data.params||(t.data.params={}),t.data.params.expires=e},function(e){return T(e.join(""))},"0",C("0",!1),function(){return S(y())},function(e,n){(t=t||{data:{}}).data.params||(t.data.params={}),n=null===n?void 0:n[1],t.data.params[e.toLowerCase()]=n},"render",C("render",!0),"session",C("session",!0),"icon",C("icon",!0),"alert",C("alert",!0),function(){"Content_Disposition"===(t=t||{data:{}}).startRule&&(t.data.type=y().toLowerCase())},"handling",C("handling",!0),"optional",C("optional",!0),"required",C("required",!0),function(e){(t=t||{data:{}}).data=T(e.join(""))},function(){(t=t||{data:{}}).data=y()},"text",C("text",!0),"image",C("image",!0),"audio",C("audio",!0),"video",C("video",!0),"application",C("application",!0),"message",C("message",!0),"multipart",C("multipart",!0),"x-",C("x-",!0),function(e){(t=t||{data:{}}).data.value=T(e.join(""))},function(e){(t=t||{data:{}}).data=e},function(e){(t=t||{data:{}}).data.event=e.toLowerCase()},function(){var e=(t=t||{data:{}}).data.tag;t.data=new Se(t.data.uri,t.data.displayName,t.data.params),e&&t.data.setParam("tag",e)},"tag",C("tag",!0),function(e){(t=t||{data:{}}).data.tag=e},function(e){(t=t||{data:{}}).data=T(e.join(""))},function(e){(t=t||{data:{}}).data=e},function(){(t=t||{data:{}}).data=new Se(t.data.uri,t.data.displayName,t.data.params)},"digest",C("Digest",!0),"realm",C("realm",!0),function(e){(t=t||{data:{}}).data.realm=e},"domain",C("domain",!0),"nonce",C("nonce",!0),function(e){(t=t||{data:{}}).data.nonce=e},"opaque",C("opaque",!0),function(e){(t=t||{data:{}}).data.opaque=e},"stale",C("stale",!0),"true",C("true",!0),function(){(t=t||{data:{}}).data.stale=!0},"false",C("false",!0),function(){(t=t||{data:{}}).data.stale=!1},"algorithm",C("algorithm",!0),"md5",C("MD5",!0),"md5-sess",C("MD5-sess",!0),function(e){(t=t||{data:{}}).data.algorithm=e.toUpperCase()},"qop",C("qop",!0),"auth-int",C("auth-int",!0),"auth",C("auth",!0),function(e){(t=t||{data:{}}).data.qop||(t.data.qop=[]),t.data.qop.push(e.toLowerCase())},function(e){(t=t||{data:{}}).data.value=T(e.join(""))},function(){var e,n;for(n=(t=t||{data:{}}).data.multi_header.length,e=0;e<n;e++)if(null===t.data.multi_header[e].parsed){t.data=null;break}null!==t.data?t.data=t.data.multi_header:t.data=-1},function(){var e;(t=t||{data:{}}).data.multi_header||(t.data.multi_header=[]);try{e=new Se(t.data.uri,t.data.displayName,t.data.params),delete t.data.uri,delete t.data.displayName,delete t.data.params}catch(t){e=null}t.data.multi_header.push({position:h,offset:k().start.offset,parsed:e})},function(){(t=t||{data:{}}).data=new Se(t.data.uri,t.data.displayName,t.data.params)},function(){(t=t||{data:{}}).data.replaces_from_tag&&t.data.replaces_to_tag||(t.data=-1)},function(){(t=t||{data:{}}).data={call_id:t.data}},"from-tag",C("from-tag",!0),function(e){(t=t||{data:{}}).data.replaces_from_tag=e},"to-tag",C("to-tag",!0),function(e){(t=t||{data:{}}).data.replaces_to_tag=e},"early-only",C("early-only",!0),function(){(t=t||{data:{}}).data.early_only=!0},function(e,t){return t},function(e,t){return function(e,t){var n;return E(n=[e]).call(n,t)}(e,t)},function(e){"Require"===(t=t||{data:{}}).startRule&&(t.data=e||[])},function(e){(t=t||{data:{}}).data.value=T(e.join(""))},"active",C("active",!0),"pending",C("pending",!0),"terminated",C("terminated",!0),function(){(t=t||{data:{}}).data.state=y()},"reason",C("reason",!0),function(e){t=t||{data:{}},void 0!==e&&(t.data.reason=e)},function(e){t=t||{data:{}},void 0!==e&&(t.data.expires=e)},"retry_after",C("retry_after",!0),function(e){t=t||{data:{}},void 0!==e&&(t.data.retry_after=e)},"deactivated",C("deactivated",!0),"probation",C("probation",!0),"rejected",C("rejected",!0),"timeout",C("timeout",!0),"giveup",C("giveup",!0),"noresource",C("noresource",!0),"invariant",C("invariant",!0),function(e){"Supported"===(t=t||{data:{}}).startRule&&(t.data=e||[])},function(){var e=(t=t||{data:{}}).data.tag;t.data=new Se(t.data.uri,t.data.displayName,t.data.params),e&&t.data.setParam("tag",e)},"ttl",C("ttl",!0),function(e){(t=t||{data:{}}).data.ttl=e},"maddr",C("maddr",!0),function(e){(t=t||{data:{}}).data.maddr=e},"received",C("received",!0),function(e){(t=t||{data:{}}).data.received=e},"branch",C("branch",!0),function(e){(t=t||{data:{}}).data.branch=e},"rport",C("rport",!0),function(e){t=t||{data:{}},void 0!==e&&(t.data.rport=e.join(""))},function(e){(t=t||{data:{}}).data.protocol=e},C("UDP",!0),C("TCP",!0),C("TLS",!0),C("SCTP",!0),function(e){(t=t||{data:{}}).data.transport=e},function(){(t=t||{data:{}}).data.host=y()},function(e){(t=t||{data:{}}).data.port=T(e.join(""))},function(e){return T(e.join(""))},function(e){"Session_Expires"===(t=t||{data:{}}).startRule&&(t.data.deltaSeconds=e)},"refresher",C("refresher",!1),"uas",C("uas",!1),"uac",C("uac",!1),function(e){"Session_Expires"===(t=t||{data:{}}).startRule&&(t.data.refresher=e)},function(e){"Min_SE"===(t=t||{data:{}}).startRule&&(t.data=e)},"stuns",C("stuns",!0),"stun",C("stun",!0),function(e){(t=t||{data:{}}).data.scheme=e},function(e){(t=t||{data:{}}).data.host=e},"?transport=",C("?transport=",!1),"turns",C("turns",!0),"turn",C("turn",!0),function(e){(t=t||{data:{}}).data.transport=e},function(){(t=t||{data:{}}).data=y()},"Referred-By",C("Referred-By",!1),"b",C("b",!1),"cid",C("cid",!1)],d=[_('2 ""6 7!'),_('4"""5!7#'),_('4$""5!7%'),_('4&""5!7\''),_(";'.# &;("),_('4(""5!7)'),_('4*""5!7+'),_('2,""6,7-'),_('2.""6.7/'),_('40""5!71'),_('22""6273. &24""6475.} &26""6677.q &28""6879.e &2:""6:7;.Y &2<""6<7=.M &2>""6>7?.A &2@""6@7A.5 &2B""6B7C.) &2D""6D7E'),_(";).# &;,"),_('2F""6F7G.} &2H""6H7I.q &2J""6J7K.e &2L""6L7M.Y &2N""6N7O.M &2P""6P7Q.A &2R""6R7S.5 &2T""6T7U.) &2V""6V7W'),_('%%2X""6X7Y/5#;#/,$;#/#$+#)(#\'#("\'#&\'#/"!&,)'),_('%%$;$0#*;$&/,#; /#$+")("\'#&\'#." &"/=#$;$/�#*;$&&&#/\'$8":Z" )("\'#&\'#'),_(';.." &"'),_("%$;'.# &;(0)*;'.# &;(&/?#28\"\"6879/0$;//'$8#:[# )(#'#(\"'#&'#"),_('%%$;2/�#*;2&&&#/g#$%$;.0#*;.&/,#;2/#$+")("\'#&\'#0=*%$;.0#*;.&/,#;2/#$+")("\'#&\'#&/#$+")("\'#&\'#/"!&,)'),_('4\\""5!7].# &;3'),_('4^""5!7_'),_('4`""5!7a'),_(';!.) &4b""5!7c'),_('%$;). &2F""6F7G. &2J""6J7K.} &2L""6L7M.q &2X""6X7Y.e &2P""6P7Q.Y &2H""6H7I.M &2@""6@7A.A &2d""6d7e.5 &2R""6R7S.) &2N""6N7O/#0*;). &2F""6F7G. &2J""6J7K.} &2L""6L7M.q &2X""6X7Y.e &2P""6P7Q.Y &2H""6H7I.M &2@""6@7A.A &2d""6d7e.5 &2R""6R7S.) &2N""6N7O&&&#/"!&,)'),_('%$;). &2F""6F7G.} &2L""6L7M.q &2X""6X7Y.e &2P""6P7Q.Y &2H""6H7I.M &2@""6@7A.A &2d""6d7e.5 &2R""6R7S.) &2N""6N7O/#0*;). &2F""6F7G.} &2L""6L7M.q &2X""6X7Y.e &2P""6P7Q.Y &2H""6H7I.M &2@""6@7A.A &2d""6d7e.5 &2R""6R7S.) &2N""6N7O&&&#/"!&,)'),_('2T""6T7U.ã &2V""6V7W.× &2f""6f7g.Ë &2h""6h7i.¿ &2:""6:7;.³ &2D""6D7E.§ &22""6273. &28""6879. &2j""6j7k. &;&.} &24""6475.q &2l""6l7m.e &2n""6n7o.Y &26""6677.M &2>""6>7?.A &2p""6p7q.5 &2r""6r7s.) &;\'.# &;('),_('%$;).ī &2F""6F7G.ğ &2J""6J7K.ē &2L""6L7M.ć &2X""6X7Y.û &2P""6P7Q.ï &2H""6H7I.ã &2@""6@7A.× &2d""6d7e.Ë &2R""6R7S.¿ &2N""6N7O.³ &2T""6T7U.§ &2V""6V7W. &2f""6f7g. &2h""6h7i. &28""6879.w &2j""6j7k.k &;&.e &24""6475.Y &2l""6l7m.M &2n""6n7o.A &26""6677.5 &2p""6p7q.) &2r""6r7s/Ĵ#0ı*;).ī &2F""6F7G.ğ &2J""6J7K.ē &2L""6L7M.ć &2X""6X7Y.û &2P""6P7Q.ï &2H""6H7I.ã &2@""6@7A.× &2d""6d7e.Ë &2R""6R7S.¿ &2N""6N7O.³ &2T""6T7U.§ &2V""6V7W. &2f""6f7g. &2h""6h7i. &28""6879.w &2j""6j7k.k &;&.e &24""6475.Y &2l""6l7m.M &2n""6n7o.A &26""6677.5 &2p""6p7q.) &2r""6r7s&&&#/"!&,)'),_("%;//?#2P\"\"6P7Q/0$;//'$8#:t# )(#'#(\"'#&'#"),_("%;//?#24\"\"6475/0$;//'$8#:u# )(#'#(\"'#&'#"),_("%;//?#2>\"\"6>7?/0$;//'$8#:v# )(#'#(\"'#&'#"),_("%;//?#2T\"\"6T7U/0$;//'$8#:w# )(#'#(\"'#&'#"),_("%;//?#2V\"\"6V7W/0$;//'$8#:x# )(#'#(\"'#&'#"),_('%2h""6h7i/0#;//\'$8":y" )("\'#&\'#'),_('%;//6#2f""6f7g/\'$8":z" )("\'#&\'#'),_("%;//?#2D\"\"6D7E/0$;//'$8#:{# )(#'#(\"'#&'#"),_("%;//?#22\"\"6273/0$;//'$8#:|# )(#'#(\"'#&'#"),_("%;//?#28\"\"6879/0$;//'$8#:}# )(#'#(\"'#&'#"),_("%;//0#;&/'$8\":~\" )(\"'#&'#"),_("%;&/0#;//'$8\":~\" )(\"'#&'#"),_("%;=/T#$;G.) &;K.# &;F0/*;G.) &;K.# &;F&/,$;>/#$+#)(#'#(\"'#&'#"),_('4""5!7.A &4""5!7.5 &4""5!7.) &;3.# &;.'),_("%%;//Q#;&/H$$;J.# &;K0)*;J.# &;K&/,$;&/#$+$)($'#(#'#(\"'#&'#/\"!&,)"),_("%;//]#;&/T$%$;J.# &;K0)*;J.# &;K&/\"!&,)/1$;&/($8$:
$!!)($'#(#'#(\"'#&'#"),_(';..G &2L""6L7M.; &4""5!7./ &4""5!7.# &;3'),_('%2j""6j7k/J#4""5!7.5 &4""5!7.) &4""5!7/#$+")("\'#&\'#'),_("%;N/M#28\"\"6879/>$;O.\" &\"/0$;S/'$8$:$ )($'#(#'#(\"'#&'#"),_("%;N/d#28\"\"6879/U$;O.\" &\"/G$;S/>$;_/5$;l.\" &\"/'$8&:& )(&'#(%'#($'#(#'#(\"'#&'#"),_('%3""5$7.) &3""5#7/\' 8!:!! )'),_('%;P/]#%28""6879/,#;R/#$+")("\'#&\'#." &"/6$2:""6:7;/\'$8#:# )(#\'#("\'#&\'#'),_("$;+.) &;-.# &;Q/2#0/*;+.) &;-.# &;Q&&&#"),_('2<""6<7=.q &2>""6>7?.e &2@""6@7A.Y &2B""6B7C.M &2D""6D7E.A &22""6273.5 &26""6677.) &24""6475'),_('%$;+._ &;-.Y &2<""6<7=.M &2>""6>7?.A &2@""6@7A.5 &2B""6B7C.) &2D""6D7E0e*;+._ &;-.Y &2<""6<7=.M &2>""6>7?.A &2@""6@7A.5 &2B""6B7C.) &2D""6D7E&/& 8!:! )'),_('%;T/J#%28""6879/,#;^/#$+")("\'#&\'#." &"/#$+")("\'#&\'#'),_("%;U.) &;\\.# &;X/& 8!:! )"),_('%$%;V/2#2J""6J7K/#$+")("\'#&\'#0<*%;V/2#2J""6J7K/#$+")("\'#&\'#&/D#;W/;$2J""6J7K." &"/\'$8#:# )(#\'#("\'#&\'#'),_('$4""5!7/,#0)*4""5!7&&&#'),_('%4$""5!7%/?#$4""5!70)*4""5!7&/#$+")("\'#&\'#'),_('%2l""6l7m/?#;Y/6$2n""6n7o/\'$8#:# )(#\'#("\'#&\'#'),_('%%;Z/³#28""6879/¤$;Z/$28""6879/$;Z/$28""6879/t$;Z/k$28""6879/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+-)(-\'#(,\'#(+\'#(*\'#()\'#((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.ސ &%2""67/¤#;Z/$28""6879/$;Z/$28""6879/t$;Z/k$28""6879/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+,)(,\'#(+\'#(*\'#()\'#((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.۹ &%2""67/#;Z/$28""6879/t$;Z/k$28""6879/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+*)(*\'#()\'#((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.ٺ &%2""67/t#;Z/k$28""6879/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+()((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.ؓ &%2""67/\\#;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+&)(&\'#(%\'#($\'#(#\'#("\'#&\'#.ׄ &%2""67/D#;Z/;$28""6879/,$;[/#$+$)($\'#(#\'#("\'#&\'#.֍ &%2""67/,#;[/#$+")("\'#&\'#.ծ &%2""67/,#;Z/#$+")("\'#&\'#.Տ &%;Z/#2""67/$;Z/$28""6879/t$;Z/k$28""6879/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$++)(+\'#(*\'#()\'#((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.Ӈ &%;Z/ª#%28""6879/,#;Z/#$+")("\'#&\'#." &"/$2""67/t$;Z/k$28""6879/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+*)(*\'#()\'#((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.а &%;Z/¹#%28""6879/,#;Z/#$+")("\'#&\'#." &"/$%28""6879/,#;Z/#$+")("\'#&\'#." &"/k$2""67/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+))()\'#((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.Ί &%;Z/È#%28""6879/,#;Z/#$+")("\'#&\'#." &"/¡$%28""6879/,#;Z/#$+")("\'#&\'#." &"/z$%28""6879/,#;Z/#$+")("\'#&\'#." &"/S$2""67/D$;Z/;$28""6879/,$;[/#$+()((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.˕ &%;Z/×#%28""6879/,#;Z/#$+")("\'#&\'#." &"/°$%28""6879/,#;Z/#$+")("\'#&\'#." &"/$%28""6879/,#;Z/#$+")("\'#&\'#." &"/b$%28""6879/,#;Z/#$+")("\'#&\'#." &"/;$2""67/,$;[/#$+\')(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.ȑ &%;Z/þ#%28""6879/,#;Z/#$+")("\'#&\'#." &"/×$%28""6879/,#;Z/#$+")("\'#&\'#." &"/°$%28""6879/,#;Z/#$+")("\'#&\'#." &"/$%28""6879/,#;Z/#$+")("\'#&\'#." &"/b$%28""6879/,#;Z/#$+")("\'#&\'#." &"/;$2""67/,$;Z/#$+()((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.Ħ &%;Z/Ĝ#%28""6879/,#;Z/#$+")("\'#&\'#." &"/õ$%28""6879/,#;Z/#$+")("\'#&\'#." &"/Î$%28""6879/,#;Z/#$+")("\'#&\'#." &"/§$%28""6879/,#;Z/#$+")("\'#&\'#." &"/$%28""6879/,#;Z/#$+")("\'#&\'#." &"/Y$%28""6879/,#;Z/#$+")("\'#&\'#." &"/2$2""67/#$+()((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#/& 8!: ! )'),_('%;#/M#;#." &"/?$;#." &"/1$;#." &"/#$+$)($\'#(#\'#("\'#&\'#'),_("%;Z/;#28\"\"6879/,$;Z/#$+#)(#'#(\"'#&'#.# &;\\"),_("%;]/o#2J\"\"6J7K/`$;]/W$2J\"\"6J7K/H$;]/?$2J\"\"6J7K/0$;]/'$8':¡' )(''#(&'#(%'#($'#(#'#(\"'#&'#"),_('%2¢""6¢7£/2#4¤""5!7¥/#$+")("\'#&\'#. &%2¦""6¦7§/;#4¨""5!7©/,$;!/#$+#)(#\'#("\'#&\'#.j &%2ª""6ª7«/5#;!/,$;!/#$+#)(#\'#("\'#&\'#.B &%4¬""5!7/,#;!/#$+")("\'#&\'#.# &;!'),_('%%;!." &"/[#;!." &"/M$;!." &"/?$;!." &"/1$;!." &"/#$+%)(%\'#($\'#(#\'#("\'#&\'#/\' 8!:®!! )'),_('$%22""6273/,#;`/#$+")("\'#&\'#0<*%22""6273/,#;`/#$+")("\'#&\'#&'),_(";a.A &;b.; &;c.5 &;d./ &;e.) &;f.# &;g"),_('%3¯""5*7°/a#3±""5#7².G &3³""5#7´.; &3µ""5$7¶./ &3·""5#7¸.# &;6/($8":¹"! )("\'#&\'#'),_('%3º""5%7»/I#3¼""5%7½./ &3¾""5"7¿.# &;6/($8":À"! )("\'#&\'#'),_('%3Á""5\'7Â/1#;/($8":Ã"! )("\'#&\'#'),_('%3Ä""5$7Å/1#;ð/($8":Æ"! )("\'#&\'#'),_('%3Ç""5&7È/1#;T/($8":É"! )("\'#&\'#'),_('%3Ê""5"7Ë/N#%2>""6>7?/,#;6/#$+")("\'#&\'#." &"/\'$8":Ì" )("\'#&\'#'),_('%;h/P#%2>""6>7?/,#;i/#$+")("\'#&\'#." &"/)$8":Í""! )("\'#&\'#'),_('%$;j/�#*;j&&&#/"!&,)'),_('%$;j/�#*;j&&&#/"!&,)'),_(";k.) &;+.# &;-"),_('2l""6l7m.e &2n""6n7o.Y &24""6475.M &28""6879.A &2<""6<7=.5 &2@""6@7A.) &2B""6B7C'),_('%26""6677/n#;m/e$$%2<""6<7=/,#;m/#$+")("\'#&\'#0<*%2<""6<7=/,#;m/#$+")("\'#&\'#&/#$+#)(#\'#("\'#&\'#'),_('%;n/A#2>""6>7?/2$;o/)$8#:Î#"" )(#\'#("\'#&\'#'),_("$;p.) &;+.# &;-/2#0/*;p.) &;+.# &;-&&&#"),_("$;p.) &;+.# &;-0/*;p.) &;+.# &;-&"),_('2l""6l7m.e &2n""6n7o.Y &24""6475.M &26""6677.A &28""6879.5 &2@""6@7A.) &2B""6B7C'),_(";.# &;r"),_("%;/G#;'/>$;s/5$;'/,$;/#$+%)(%'#($'#(#'#(\"'#&'#"),_(";M.# &;t"),_("%;/E#28\"\"6879/6$;u.# &;x/'$8#:Ï# )(#'#(\"'#&'#"),_('%;v.# &;w/J#%26""6677/,#;/#$+")("\'#&\'#." &"/#$+")("\'#&\'#'),_('%2Ð""6Ð7Ñ/:#;/1$;w." &"/#$+#)(#\'#("\'#&\'#'),_('%24""6475/,#;{/#$+")("\'#&\'#'),_("%;z/3#$;y0#*;y&/#$+\")(\"'#&'#"),_(";*.) &;+.# &;-"),_(';+. &;-. &22""6273.} &26""6677.q &28""6879.e &2:""6:7;.Y &2<""6<7=.M &2>""6>7?.A &2@""6@7A.5 &2B""6B7C.) &2D""6D7E'),_('%;|/e#$%24""6475/,#;|/#$+")("\'#&\'#0<*%24""6475/,#;|/#$+")("\'#&\'#&/#$+")("\'#&\'#'),_('%$;~0#*;~&/e#$%22""6273/,#;}/#$+")("\'#&\'#0<*%22""6273/,#;}/#$+")("\'#&\'#&/#$+")("\'#&\'#'),_("$;~0#*;~&"),_(';+.w &;-.q &28""6879.e &2:""6:7;.Y &2<""6<7=.M &2>""6>7?.A &2@""6@7A.5 &2B""6B7C.) &2D""6D7E'),_('%%;"/#$;".G &;!.A &2@""6@7A.5 &2F""6F7G.) &2J""6J7K0M*;".G &;!.A &2@""6@7A.5 &2F""6F7G.) &2J""6J7K&/#$+")("\'#&\'#/& 8!:Ò! )'),_(";.# &;"),_('%%;O/2#2:""6:7;/#$+")("\'#&\'#." &"/,#;S/#$+")("\'#&\'#." &"'),_('$;+. &;-.} &2B""6B7C.q &2D""6D7E.e &22""6273.Y &28""6879.M &2:""6:7;.A &2<""6<7=.5 &2>""6>7?.) &2@""6@7A/#0*;+. &;-.} &2B""6B7C.q &2D""6D7E.e &22""6273.Y &28""6879.M &2:""6:7;.A &2<""6<7=.5 &2>""6>7?.) &2@""6@7A&&&#'),_("$;y0#*;y&"),_('%3""5#7Ó/q#24""6475/b$$;!/�#*;!&&&#/L$2J""6J7K/=$$;!/�#*;!&&&#/\'$8%:Ô% )(%\'#($\'#(#\'#("\'#&\'#'),_('2Õ""6Õ7Ö'),_('2×""6×7Ø'),_('2Ù""6Ù7Ú'),_('2Û""6Û7Ü'),_('2Ý""6Ý7Þ'),_('2ß""6ß7à'),_('2á""6á7â'),_('2ã""6ã7ä'),_('2å""6å7æ'),_('2ç""6ç7è'),_('2é""6é7ê'),_("%;
.Y &;.S &;.M &;.G &;.A &;.; &;.5 &;./ &;.) &;.# &;6/& 8!:ë! )"),_("%;/G#;'/>$;/5$;'/,$;/#$+%)(%'#($'#(#'#(\"'#&'#"),_("%;/' 8!:ì!! )"),_("%;!/5#;!/,$;!/#$+#)(#'#(\"'#&'#"),_("%$;*.A &;+.; &;-.5 &;3./ &;4.) &;'.# &;(0G*;*.A &;+.; &;-.5 &;3./ &;4.) &;'.# &;(&/& 8!:í! )"),_("%;¶/Y#$%;A/,#;¶/#$+\")(\"'#&'#06*%;A/,#;¶/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),_('%;9/N#%2:""6:7;/,#;9/#$+")("\'#&\'#." &"/\'$8":î" )("\'#&\'#'),_("%;:.c &%;/Y#$%;A/,#;/#$+\")(\"'#&'#06*%;A/,#;/#$+\")(\"'#&'#&/#$+\")(\"'#&'#/& 8!:ï! )"),_("%;L.# &;/]#$%;B/,#;/#$+\")(\"'#&'#06*%;B/,#;/#$+\")(\"'#&'#&/'$8\":ð\" )(\"'#&'#"),_("%;.\" &\"/>#;@/5$;M/,$;?/#$+$)($'#(#'#(\"'#&'#"),_("%%;6/Y#$%;./,#;6/#$+\")(\"'#&'#06*%;./,#;6/#$+\")(\"'#&'#&/#$+\")(\"'#&'#.# &;H/' 8!:ñ!! )"),_(";.) &;.# &; "),_("%3ò\"\"5!7ó/:#;</1$;/($8#:ô#! )(#'#(\"'#&'#"),_("%3õ\"\"5'7ö/:#;</1$;/($8#:÷#! )(#'#(\"'#&'#"),_("%$;!/�#*;!&&&#/' 8!:ø!! )"),_('%2ù""6ù7ú/o#%2J""6J7K/M#;!." &"/?$;!." &"/1$;!." &"/#$+$)($\'#(#\'#("\'#&\'#." &"/\'$8":û" )("\'#&\'#'),_('%;6/J#%;</,#;¡/#$+")("\'#&\'#." &"/)$8":ü""! )("\'#&\'#'),_(";6.) &;T.# &;H"),_("%;£/Y#$%;B/,#;¤/#$+\")(\"'#&'#06*%;B/,#;¤/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),_('%3ý""5&7þ.G &3ÿ""5\'7Ā.; &3ā""5$7Ă./ &3ă""5%7Ą.# &;6/& 8!:ą! )'),_(";¥.# &; "),_('%3Ć""5(7ć/M#;</D$3Ĉ""5(7ĉ./ &3Ċ""5(7ċ.# &;6/#$+#)(#\'#("\'#&\'#'),_("%;6/Y#$%;A/,#;6/#$+\")(\"'#&'#06*%;A/,#;6/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),_("%$;!/�#*;!&&&#/' 8!:Č!! )"),_("%;©/& 8!:č! )"),_("%;ª/k#;;/b$;¯/Y$$%;B/,#;°/#$+\")(\"'#&'#06*%;B/,#;°/#$+\")(\"'#&'#&/#$+$)($'#(#'#(\"'#&'#"),_(";«.# &;¬"),_('3Ď""5$7ď.S &3Đ""5%7đ.G &3Ē""5%7ē.; &3Ĕ""5%7ĕ./ &3Ė""5+7ė.# &;'),_('3Ę""5\'7ę./ &3Ě""5)7ě.# &;'),_(";6.# &;®"),_('%3Ĝ""5"7ĝ/,#;6/#$+")("\'#&\'#'),_(";.# &;6"),_("%;6/5#;</,$;±/#$+#)(#'#(\"'#&'#"),_(";6.# &;H"),_("%;³/5#;./,$;/#$+#)(#'#(\"'#&'#"),_("%$;!/�#*;!&&&#/' 8!:Ğ!! )"),_("%;/' 8!:ğ!! )"),_('%;¶/^#$%;B/,#; /#$+")("\'#&\'#06*%;B/,#; /#$+")("\'#&\'#&/($8":Ġ"!!)("\'#&\'#'),_('%%;7/e#$%2J""6J7K/,#;7/#$+")("\'#&\'#0<*%2J""6J7K/,#;7/#$+")("\'#&\'#&/#$+")("\'#&\'#/"!&,)'),_("%;L.# &;/]#$%;B/,#;¸/#$+\")(\"'#&'#06*%;B/,#;¸/#$+\")(\"'#&'#&/'$8\":ġ\" )(\"'#&'#"),_(";¹.# &; "),_("%3Ģ\"\"5#7ģ/:#;</1$;6/($8#:Ĥ#! )(#'#(\"'#&'#"),_("%$;!/�#*;!&&&#/' 8!:ĥ!! )"),_("%;/' 8!:Ħ!! )"),_("%$;0#*;&/x#;@/o$;M/f$;?/]$$%;B/,#; /#$+\")(\"'#&'#06*%;B/,#; /#$+\")(\"'#&'#&/'$8%:ħ% )(%'#($'#(#'#(\"'#&'#"),_(";¾"),_("%3Ĩ\"\"5&7ĩ/k#;./b$;Á/Y$$%;A/,#;Á/#$+\")(\"'#&'#06*%;A/,#;Á/#$+\")(\"'#&'#&/#$+$)($'#(#'#(\"'#&'#.# &;¿"),_("%;6/k#;./b$;À/Y$$%;A/,#;À/#$+\")(\"'#&'#06*%;A/,#;À/#$+\")(\"'#&'#&/#$+$)($'#(#'#(\"'#&'#"),_("%;6/;#;</2$;6.# &;H/#$+#)(#'#(\"'#&'#"),_(";Â.G &;Ä.A &;Æ.; &;È.5 &;É./ &;Ê.) &;Ë.# &;À"),_("%3Ī\"\"5%7ī/5#;</,$;Ã/#$+#)(#'#(\"'#&'#"),_("%;I/' 8!:Ĭ!! )"),_("%3ĭ\"\"5&7Į/#;</$;D/
$;Å/|$$%$;'/�#*;'&&&#/,#;Å/#$+\")(\"'#&'#0C*%$;'/�#*;'&&&#/,#;Å/#$+\")(\"'#&'#&/,$;E/#$+&)(&'#(%'#($'#(#'#(\"'#&'#"),_(";t.# &;w"),_("%3į\"\"5%7İ/5#;</,$;Ç/#$+#)(#'#(\"'#&'#"),_("%;I/' 8!:ı!! )"),_("%3IJ\"\"5&7ij/:#;</1$;I/($8#:Ĵ#! )(#'#(\"'#&'#"),_('%3ĵ""5%7Ķ/]#;</T$%3ķ""5$7ĸ/& 8!:Ĺ! ).4 &%3ĺ""5%7Ļ/& 8!:ļ! )/#$+#)(#\'#("\'#&\'#'),_('%3Ľ""5)7ľ/R#;</I$3Ŀ""5#7ŀ./ &3Ł""5(7ł.# &;6/($8#:Ń#! )(#\'#("\'#&\'#'),_('%3ń""5#7Ņ/#;</$;D/$%;Ì/e#$%2D""6D7E/,#;Ì/#$+")("\'#&\'#0<*%2D""6D7E/,#;Ì/#$+")("\'#&\'#&/#$+")("\'#&\'#/,$;E/#$+%)(%\'#($\'#(#\'#("\'#&\'#'),_('%3ņ""5(7Ň./ &3ň""5$7ʼn.# &;6/\' 8!:Ŋ!! )'),_("%;6/Y#$%;A/,#;6/#$+\")(\"'#&'#06*%;A/,#;6/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),_("%;Ï/G#;./>$;Ï/5$;./,$;/#$+%)(%'#($'#(#'#(\"'#&'#"),_("%$;!/�#*;!&&&#/' 8!:ŋ!! )"),_("%;Ñ/]#$%;A/,#;Ñ/#$+\")(\"'#&'#06*%;A/,#;Ñ/#$+\")(\"'#&'#&/'$8\":Ō\" )(\"'#&'#"),_("%;/]#$%;B/,#; /#$+\")(\"'#&'#06*%;B/,#; /#$+\")(\"'#&'#&/'$8\":ō\" )(\"'#&'#"),_('%;L.O &;.I &%;@." &"/:#;t/1$;?." &"/#$+#)(#\'#("\'#&\'#/]#$%;B/,#; /#$+")("\'#&\'#06*%;B/,#; /#$+")("\'#&\'#&/\'$8":Ŏ" )("\'#&\'#'),_("%;Ô/]#$%;B/,#;Õ/#$+\")(\"'#&'#06*%;B/,#;Õ/#$+\")(\"'#&'#&/'$8\":ŏ\" )(\"'#&'#"),_("%;/& 8!:Ő! )"),_('%3ő""5(7Œ/:#;</1$;6/($8#:œ#! )(#\'#("\'#&\'#.g &%3Ŕ""5&7ŕ/:#;</1$;6/($8#:Ŗ#! )(#\'#("\'#&\'#.: &%3ŗ""5*7Ř/& 8!:ř! ).# &; '),_('%%;6/k#$%;A/2#;6/)$8":Ś""$ )("\'#&\'#0<*%;A/2#;6/)$8":Ś""$ )("\'#&\'#&/)$8":ś""! )("\'#&\'#." &"/\' 8!:Ŝ!! )'),_("%;Ø/Y#$%;A/,#;Ø/#$+\")(\"'#&'#06*%;A/,#;Ø/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),_("%;/Y#$%;B/,#; /#$+\")(\"'#&'#06*%;B/,#; /#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),_("%$;!/�#*;!&&&#/' 8!:ŝ!! )"),_("%;Û/Y#$%;B/,#;Ü/#$+\")(\"'#&'#06*%;B/,#;Ü/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),_('%3Ş""5&7ş.; &3Š""5\'7š./ &3Ţ""5*7ţ.# &;6/& 8!:Ť! )'),_("%3ť\"\"5&7Ŧ/:#;</1$;Ý/($8#:ŧ#! )(#'#(\"'#&'#.} &%3õ\"\"5'7ö/:#;</1$;/($8#:Ũ#! )(#'#(\"'#&'#.P &%3ũ\"\"5+7Ū/:#;</1$;/($8#:ū#! )(#'#(\"'#&'#.# &; "),_('3Ŭ""5+7ŭ.k &3Ů""5)7ů._ &3Ű""5(7ű.S &3Ų""5\'7ų.G &3Ŵ""5&7ŵ.; &3Ŷ""5*7ŷ./ &3Ÿ""5)7Ź.# &;6'),_(';1." &"'),_('%%;6/k#$%;A/2#;6/)$8":Ś""$ )("\'#&\'#0<*%;A/2#;6/)$8":Ś""$ )("\'#&\'#&/)$8":ś""! )("\'#&\'#." &"/\' 8!:ź!! )'),_("%;L.# &;/]#$%;B/,#;á/#$+\")(\"'#&'#06*%;B/,#;á/#$+\")(\"'#&'#&/'$8\":Ż\" )(\"'#&'#"),_(";¹.# &; "),_("%;ã/Y#$%;A/,#;ã/#$+\")(\"'#&'#06*%;A/,#;ã/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),_("%;ê/k#;./b$;í/Y$$%;B/,#;ä/#$+\")(\"'#&'#06*%;B/,#;ä/#$+\")(\"'#&'#&/#$+$)($'#(#'#(\"'#&'#"),_(";å.; &;æ.5 &;ç./ &;è.) &;é.# &; "),_("%3ż\"\"5#7Ž/:#;</1$;ð/($8#:ž#! )(#'#(\"'#&'#"),_("%3ſ\"\"5%7ƀ/:#;</1$;T/($8#:Ɓ#! )(#'#(\"'#&'#"),_("%3Ƃ\"\"5(7ƃ/F#;</=$;\\.) &;Y.# &;X/($8#:Ƅ#! )(#'#(\"'#&'#"),_("%3ƅ\"\"5&7Ɔ/:#;</1$;6/($8#:Ƈ#! )(#'#(\"'#&'#"),_("%3ƈ\"\"5%7Ɖ/A#;</8$$;!0#*;!&/($8#:Ɗ#! )(#'#(\"'#&'#"),_("%;ë/G#;;/>$;6/5$;;/,$;ì/#$+%)(%'#($'#(#'#(\"'#&'#"),_('%3""5#7Ó.# &;6/\' 8!:Ƌ!! )'),_('%3±""5#7ƌ.G &3³""5#7ƍ.; &3·""5#7Ǝ./ &3µ""5$7Ə.# &;6/\' 8!:Ɛ!! )'),_('%;î/D#%;C/,#;ï/#$+")("\'#&\'#." &"/#$+")("\'#&\'#'),_("%;U.) &;\\.# &;X/& 8!:Ƒ! )"),_('%%;!." &"/[#;!." &"/M$;!." &"/?$;!." &"/1$;!." &"/#$+%)(%\'#($\'#(#\'#("\'#&\'#/\' 8!:ƒ!! )'),_('%%;!/?#;!." &"/1$;!." &"/#$+#)(#\'#("\'#&\'#/\' 8!:Ɠ!! )'),_(";¾"),_('%;/^#$%;B/,#;ó/#$+")("\'#&\'#06*%;B/,#;ó/#$+")("\'#&\'#&/($8":Ɣ"!!)("\'#&\'#'),_(";ô.# &; "),_('%2ƕ""6ƕ7Ɩ/L#;</C$2Ɨ""6Ɨ7Ƙ.) &2ƙ""6ƙ7ƚ/($8#:ƛ#! )(#\'#("\'#&\'#'),_('%;/^#$%;B/,#; /#$+")("\'#&\'#06*%;B/,#; /#$+")("\'#&\'#&/($8":Ɯ"!!)("\'#&\'#'),_("%;6/5#;0/,$;÷/#$+#)(#'#(\"'#&'#"),_("$;2.) &;4.# &;.0/*;2.) &;4.# &;.&"),_("$;%0#*;%&"),_("%;ú/;#28\"\"6879/,$;û/#$+#)(#'#(\"'#&'#"),_('%3Ɲ""5%7ƞ.) &3Ɵ""5$7Ơ/\' 8!:ơ!! )'),_('%;ü/J#%28""6879/,#;^/#$+")("\'#&\'#." &"/#$+")("\'#&\'#'),_("%;\\.) &;X.# &;/' 8!:Ƣ!! )"),_(';".S &;!.M &2F""6F7G.A &2J""6J7K.5 &2H""6H7I.) &2N""6N7O'),_('2L""6L7M. &2B""6B7C. &2<""6<7=.} &2R""6R7S.q &2T""6T7U.e &2V""6V7W.Y &2P""6P7Q.M &2@""6@7A.A &2D""6D7E.5 &22""6273.) &2>""6>7?'),_('%;Ā/b#28""6879/S$;û/J$%2ƣ""6ƣ7Ƥ/,#;ì/#$+")("\'#&\'#." &"/#$+$)($\'#(#\'#("\'#&\'#'),_('%3ƥ""5%7Ʀ.) &3Ƨ""5$7ƨ/\' 8!:ơ!! )'),_('%3±""5#7².6 &3³""5#7´.* &$;+0#*;+&/\' 8!:Ʃ!! )'),_("%;Ą/#2F\"\"6F7G/x$;ă/o$2F\"\"6F7G/`$;ă/W$2F\"\"6F7G/H$;ă/?$2F\"\"6F7G/0$;ą/'$8):ƪ) )()'#(('#(''#(&'#(%'#($'#(#'#(\"'#&'#"),_("%;#/>#;#/5$;#/,$;#/#$+$)($'#(#'#(\"'#&'#"),_("%;ă/,#;ă/#$+\")(\"'#&'#"),_("%;ă/5#;ă/,$;ă/#$+#)(#'#(\"'#&'#"),_("%;q/T#$;m0#*;m&/D$%; /,#;ø/#$+\")(\"'#&'#.\" &\"/#$+#)(#'#(\"'#&'#"),_('%2ƫ""6ƫ7Ƭ.) &2ƭ""6ƭ7Ʈ/w#;0/n$;Ĉ/e$$%;B/2#;ĉ.# &; /#$+")("\'#&\'#0<*%;B/2#;ĉ.# &; /#$+")("\'#&\'#&/#$+$)($\'#(#\'#("\'#&\'#'),_(";.# &;L"),_("%2Ư\"\"6Ư7ư/5#;</,$;Ċ/#$+#)(#'#(\"'#&'#"),_("%;D/S#;,/J$2:\"\"6:7;/;$;,.# &;T/,$;E/#$+%)(%'#($'#(#'#(\"'#&'#")],h=0,f=0,v=[{line:1,column:1}],p=0,m=[],b=0;if(void 0!==t.startRule){if(!(t.startRule in c))throw new Error("Can't start parsing from rule \""+t.startRule+'".');l=c[t.startRule]}function y(){return e.substring(f,h)}function k(){return D(f,h)}function C(e,t){return{type:"literal",text:e,ignoreCase:t}}function A(e,t,n){return{type:"class",parts:e,inverted:t,ignoreCase:n}}function x(t){var n,i=v[t];if(i)return i;for(n=t-1;!v[n];)n--;for(i={line:(i=v[n]).line,column:i.column};n<t;)10===e.charCodeAt(n)?(i.line++,i.column=1):i.column++,n++;return v[t]=i,i}function D(e,t){var n=x(e),i=x(t);return{source:o,start:{offset:e,line:n.line,column:n.column},end:{offset:t,line:i.line,column:i.column}}}function H(e){h<p||(h>p&&(p=h,m=[]),m.push(e))}function _(e){var t;return w(t=e.split("")).call(t,function(e){return e.charCodeAt(0)-32})}if(t.data={},n=function t(n){for(var i,r,s=d[n],o=0,c=[],l=s.length,v=[],p=[];;){for(;o<l;)switch(s[o]){case 0:p.push(u[s[o+1]]),o+=2;break;case 1:p.push(void 0),o++;break;case 2:p.push(null),o++;break;case 3:p.push(a),o++;break;case 4:p.push([]),o++;break;case 5:p.push(h),o++;break;case 6:p.pop(),o++;break;case 7:h=p.pop(),o++;break;case 8:p.length-=s[o+1],o+=2;break;case 9:I(p).call(p,-2,1),o++;break;case 10:p[p.length-2].push(p.pop()),o++;break;case 11:p.push(I(p).call(p,p.length-s[o+1],s[o+1])),o+=2;break;case 12:p.push(e.substring(p.pop(),h)),o++;break;case 13:v.push(l),c.push(o+3+s[o+1]+s[o+2]),p[p.length-1]?(l=o+3+s[o+1],o+=3):(l=o+3+s[o+1]+s[o+2],o+=3+s[o+1]);break;case 14:v.push(l),c.push(o+3+s[o+1]+s[o+2]),p[p.length-1]===a?(l=o+3+s[o+1],o+=3):(l=o+3+s[o+1]+s[o+2],o+=3+s[o+1]);break;case 15:v.push(l),c.push(o+3+s[o+1]+s[o+2]),p[p.length-1]!==a?(l=o+3+s[o+1],o+=3):(l=o+3+s[o+1]+s[o+2],o+=3+s[o+1]);break;case 16:p[p.length-1]!==a?(v.push(l),c.push(o),l=o+2+s[o+1],o+=2):o+=2+s[o+1];break;case 17:v.push(l),c.push(o+3+s[o+1]+s[o+2]),e.length>h?(l=o+3+s[o+1],o+=3):(l=o+3+s[o+1]+s[o+2],o+=3+s[o+1]);break;case 18:v.push(l),c.push(o+4+s[o+2]+s[o+3]),e.substr(h,u[s[o+1]].length)===u[s[o+1]]?(l=o+4+s[o+2],o+=4):(l=o+4+s[o+2]+s[o+3],o+=4+s[o+2]);break;case 19:v.push(l),c.push(o+4+s[o+2]+s[o+3]),e.substr(h,u[s[o+1]].length).toLowerCase()===u[s[o+1]]?(l=o+4+s[o+2],o+=4):(l=o+4+s[o+2]+s[o+3],o+=4+s[o+2]);break;case 20:v.push(l),c.push(o+4+s[o+2]+s[o+3]),u[s[o+1]].test(e.charAt(h))?(l=o+4+s[o+2],o+=4):(l=o+4+s[o+2]+s[o+3],o+=4+s[o+2]);break;case 21:p.push(e.substr(h,s[o+1])),h+=s[o+1],o+=2;break;case 22:p.push(u[s[o+1]]),h+=u[s[o+1]].length,o+=2;break;case 23:p.push(a),0===b&&H(u[s[o+1]]),o+=2;break;case 24:f=p[p.length-1-s[o+1]],o+=2;break;case 25:f=h,o++;break;case 26:r=w(i=g(s).call(s,o+4,o+4+s[o+3])).call(i,function(e){return p[p.length-1-e]}),I(p).call(p,p.length-s[o+2],s[o+2],u[s[o+1]].apply(null,r)),o+=4+s[o+3];break;case 27:p.push(t(s[o+1])),o+=2;break;case 28:b++,o++;break;case 29:b--,o++;break;default:throw new Error("Invalid opcode: "+s[o]+".")}if(!(v.length>0))break;l=v.pop(),o=c.pop()}return p[0]}(l),n!==a&&h===e.length)return n;throw n!==a&&h<e.length&&H({type:"end"}),i=m,r=p<e.length?e.charAt(p):null,s=p<e.length?D(p,p+1):D(p,p),new De(De.buildMessage(i,r),i,r,s)};!function(e){e.parse=function(e,t){var n={startRule:t};try{_e(e,n)}catch(e){n.data=-1}return n.data},e.nameAddrHeaderParse=function(t){var n=e.parse(t,"Name_Addr_Header");return-1!==n?n:void 0},e.URIParse=function(t){var n=e.parse(t,"SIP_URI");return-1!==n?n:void 0}}(He||(He={}));var $e={100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"};function qe(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:32,n="",i=0;i<e;i++){n+=Math.floor(Math.random()*t).toString(t)}return n}function Me(e){return $e[e]||""}function Pe(){return qe(10)}function Oe(e){for(var t={"Call-Id":"Call-ID",Cseq:"CSeq","Min-Se":"Min-SE",Rack:"RAck",Rseq:"RSeq","Www-Authenticate":"WWW-Authenticate"},n=e.toLowerCase().replace(/_/g,"-").split("-"),i=n.length,r="",s=0;s<i;s++)0!==s&&(r+="-"),r+=n[s].charAt(0).toUpperCase()+n[s].substring(1);return t[r]&&(r=t[r]),r}function Ne(e){return encodeURIComponent(e).replace(/%[A-F\d]{2}/g,"U").length}function je(e,t){var n=void 0!==H&&_(e)||e["@@iterator"];if(!n){if(y(e)||(n=function(e,t){if(e){var n;if("string"==typeof e)return Fe(e,t);var i=g(n={}.toString.call(e)).call(n,8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?D(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?Fe(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var i=0,r=function(){};return{s:r,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){o=!0,s=e},f:function(){try{a||null==n.return||n.return()}finally{if(o)throw s}}}}function Fe(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=Array(t);n<t;n++)i[n]=e[n];return i}var Ue=function(){return t(function t(){e(this,t),d(this,"viaBranch",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"method",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"toTag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"to",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"fromTag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"from",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"callId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"cseq",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"via",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"headers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),d(this,"referTo",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0})},[{key:"addHeader",value:function(e,t){var n={raw:t};e=Oe(e),this.headers[e]?this.headers[e].push(n):this.headers[e]=[n]}},{key:"getHeader",value:function(e){var t=this.headers[Oe(e)];if(t)return t[0]?t[0].raw:void 0}},{key:"getHeaders",value:function(e){var t=this.headers[Oe(e)],n=[];if(!t)return[];var i,r=je(t);try{for(r.s();!(i=r.n()).done;){var s=i.value;n.push(s.raw)}}catch(e){r.e(e)}finally{r.f()}return n}},{key:"hasHeader",value:function(e){return!!this.headers[Oe(e)]}},{key:"parseHeader",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(e=Oe(e),this.headers[e]&&!(t>=this.headers[e].length)){var n=this.headers[e][t],i=n.raw;if(n.parsed)return n.parsed;var r,s=He.parse(i,e.replace(/-/g,"_"));return-1===s?void I(r=this.headers[e]).call(r,t,1):(n.parsed=s,s)}}},{key:"s",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return this.parseHeader(e,t)}},{key:"setHeader",value:function(e,t){this.headers[Oe(e)]=[{raw:t}]}},{key:"toString",value:function(){return this.data}}])}();function Be(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Be=function(){return!!e})()}var Le=function(){function n(){var t,i,r,c;return e(this,n),i=this,r=o(r=n),t=a(i,Be()?s(r,c||[],o(i).constructor):r.apply(i,c)),d(t,"ruri",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),t}return c(n,Ue),t(n)}();function Ge(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Ge=function(){return!!e})()}var Ve=function(){function n(){var t,i,r,c;return e(this,n),i=this,r=o(r=n),t=a(i,Ge()?s(r,c||[],o(i).constructor):r.apply(i,c)),d(t,"statusCode",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(t,"reasonPhrase",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),t}return c(n,Ue),t(n)}();function We(e,t){var n=void 0!==H&&_(e)||e["@@iterator"];if(!n){if(y(e)||(n=function(e,t){if(e){var n;if("string"==typeof e)return Ye(e,t);var i=g(n={}.toString.call(e)).call(n,8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?D(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?Ye(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var i=0,r=function(){};return{s:r,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){o=!0,s=e},f:function(){try{a||null==n.return||n.return()}finally{if(o)throw s}}}}function Ye(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=Array(t);n<t;n++)i[n]=e[n];return i}var Ke,ze,Ze=function(){return t(function t(n,i,r,s,a,o,c){if(e(this,t),d(this,"headers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),d(this,"method",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"ruri",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"from",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"fromTag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"fromURI",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"to",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"toTag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"toURI",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"branch",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"callId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"cseq",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"extraHeaders",{enumerable:!0,configurable:!0,writable:!0,value:[]}),d(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.options=t.getDefaultOptions(),a){var l,u;if(this.options=$($({},this.options),a),this.options.optionTags&&this.options.optionTags.length)this.options.optionTags=g(l=this.options.optionTags).call(l);if(this.options.routeSet&&this.options.routeSet.length)this.options.routeSet=g(u=this.options.routeSet).call(u)}o&&o.length&&(this.extraHeaders=g(o).call(o)),c&&(this.body={body:c.content,contentType:c.contentType}),this.method=n,this.ruri=i.clone(),this.fromURI=r.clone(),this.fromTag=this.options.fromTag?this.options.fromTag:Pe(),this.from=t.makeNameAddrHeader(this.fromURI,this.options.fromDisplayName,this.fromTag),this.toURI=s.clone(),this.toTag=this.options.toTag,this.to=t.makeNameAddrHeader(this.toURI,this.options.toDisplayName,this.toTag),this.callId=this.options.callId?this.options.callId:this.options.callIdPrefix+qe(15),this.cseq=this.options.cseq,this.setHeader("route",this.options.routeSet),this.setHeader("via",""),this.setHeader("to",this.to.toString()),this.setHeader("from",this.from.toString()),this.setHeader("cseq",this.cseq+" "+this.method),this.setHeader("call-id",this.callId),this.setHeader("max-forwards","70")},[{key:"getHeader",value:function(e){var t=this.headers[Oe(e)];if(t){if(t[0])return t[0]}else{var n,i=new RegExp("^\\s*"+e+"\\s*:","i"),r=We(this.extraHeaders);try{for(r.s();!(n=r.n()).done;){var s,a=n.value;if(i.test(a))return R(s=a.substring(q(a).call(a,":")+1)).call(s)}}catch(e){r.e(e)}finally{r.f()}}}},{key:"getHeaders",value:function(e){var t=[],n=this.headers[Oe(e)];if(n){var i,r=We(n);try{for(r.s();!(i=r.n()).done;){var s=i.value;t.push(s)}}catch(e){r.e(e)}finally{r.f()}}else{var a,o=new RegExp("^\\s*"+e+"\\s*:","i"),c=We(this.extraHeaders);try{for(c.s();!(a=c.n()).done;){var l,u=a.value;if(o.test(u))t.push(R(l=u.substring(q(u).call(u,":")+1)).call(l))}}catch(e){c.e(e)}finally{c.f()}}return t}},{key:"hasHeader",value:function(e){if(this.headers[Oe(e)])return!0;var t,n=new RegExp("^\\s*"+e+"\\s*:","i"),i=We(this.extraHeaders);try{for(i.s();!(t=i.n()).done;){var r=t.value;if(n.test(r))return!0}}catch(e){i.e(e)}finally{i.f()}return!1}},{key:"setHeader",value:function(e,t){this.headers[Oe(e)]=t instanceof Array?t:[t]}},{key:"setViaHeader",value:function(e,t){this.options.hackViaTcp&&(t="TCP");var n="SIP/2.0/"+t;n+=" "+this.options.viaHost+";branch="+e,this.options.forceRport&&(n+=";rport"),this.setHeader("via",n),this.branch=e}},{key:"toString",value:function(){var e="";for(var t in e+=this.method+" "+this.ruri.toRaw()+" SIP/2.0\r\n",this.headers)if(this.headers[t]){var n,i=We(this.headers[t]);try{for(i.s();!(n=i.n()).done;){e+=t+": "+n.value+"\r\n"}}catch(e){i.e(e)}finally{i.f()}}var r,s=We(this.extraHeaders);try{for(s.s();!(r=s.n()).done;){var a=r.value;e+=R(a).call(a)+"\r\n"}}catch(e){s.e(e)}finally{s.f()}return e+="Supported: "+this.options.optionTags.join(", ")+"\r\n",e+="User-Agent: "+this.options.userAgentString+"\r\n",this.body?"string"==typeof this.body?(e+="Content-Length: "+Ne(this.body)+"\r\n\r\n",e+=this.body):this.body.body&&this.body.contentType?(e+="Content-Type: "+this.body.contentType+"\r\n",e+="Content-Length: "+Ne(this.body.body)+"\r\n\r\n",e+=this.body.body):e+="Content-Length: 0\r\n\r\n":e+="Content-Length: 0\r\n\r\n",e}}],[{key:"getDefaultOptions",value:function(){return{callId:"",callIdPrefix:"",cseq:1,toDisplayName:"",toTag:"",fromDisplayName:"",fromTag:"",forceRport:!1,hackViaTcp:!1,optionTags:["outbound"],routeSet:[],userAgentString:"sip.js",viaHost:""}}},{key:"makeNameAddrHeader",value:function(e,t,n){var i={};return n&&(i.tag=n),new Se(e,t,i)}}])}();function Je(e){return"application/sdp"===e?"session":"render"}function Xe(e){var t="string"==typeof e?e:e.body,n="string"==typeof e?"application/sdp":e.contentType;return{contentDisposition:Je(n),contentType:n,content:t}}function Qe(e){return!(!e||"string"!=typeof e.content||"string"!=typeof e.contentType||void 0!==e.contentDisposition)||"string"==typeof e.contentDisposition}function et(e){var t,n,i;if(e instanceof Le&&e.body){var r=e.parseHeader("Content-Disposition");t=r?r.type:void 0,n=e.parseHeader("Content-Type"),i=e.body}if(e instanceof Ve&&e.body){var s=e.parseHeader("Content-Disposition");t=s?s.type:void 0,n=e.parseHeader("Content-Type"),i=e.body}if(e instanceof Ze&&e.body)if(t=e.getHeader("Content-Disposition"),n=e.getHeader("Content-Type"),"string"==typeof e.body){if(!n)throw new Error("Header content type header does not equal body content type.");i=e.body}else{if(n&&n!==e.body.contentType)throw new Error("Header content type header does not equal body content type.");n=e.body.contentType,i=e.body.body}if(Qe(e)&&(t=e.contentDisposition,n=e.contentType,i=e.content),i){if(n&&!t&&(t=Je(n)),!t)throw new Error("Content disposition undefined.");if(!n)throw new Error("Content type undefined.");return{contentDisposition:t,contentType:n,content:i}}}!function(e){e.Initial="Initial",e.Early="Early",e.AckWait="AckWait",e.Confirmed="Confirmed",e.Terminated="Terminated"}(Ke||(Ke={})),function(e){e.Initial="Initial",e.HaveLocalOffer="HaveLocalOffer",e.HaveRemoteOffer="HaveRemoteOffer",e.Stable="Stable",e.Closed="Closed"}(ze||(ze={}));var tt=500,nt=5e3,it={T1:tt,T2:4e3,T4:nt,TIMER_B:32e3,TIMER_D:0,TIMER_F:32e3,TIMER_H:32e3,TIMER_I:0,TIMER_J:0,TIMER_K:0,TIMER_L:32e3,TIMER_M:32e3,TIMER_N:32e3,PROVISIONAL_RESPONSE_INTERVAL:6e4};function rt(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(rt=function(){return!!e})()}var st,at=function(){function n(t){return e(this,n),i=this,c=[t||"Transaction state error."],r=o(r=n),a(i,rt()?s(r,c||[],o(i).constructor):r.apply(i,c));var i,r,c}return c(n,ae),t(n)}();!function(e){e.ACK="ACK",e.BYE="BYE",e.CANCEL="CANCEL",e.INFO="INFO",e.INVITE="INVITE",e.MESSAGE="MESSAGE",e.NOTIFY="NOTIFY",e.OPTIONS="OPTIONS",e.REGISTER="REGISTER",e.UPDATE="UPDATE",e.SUBSCRIBE="SUBSCRIBE",e.PUBLISH="PUBLISH",e.REFER="REFER",e.PRACK="PRACK"}(st||(st={}));var ot,ct=[st.ACK,st.BYE,st.CANCEL,st.INFO,st.INVITE,st.MESSAGE,st.NOTIFY,st.OPTIONS,st.PRACK,st.REFER,st.REGISTER,st.SUBSCRIBE],lt=function(){return t(function t(n){e(this,t),d(this,"incomingMessageRequest",{enumerable:!0,configurable:!0,writable:!0,value:n})},[{key:"request",get:function(){return this.incomingMessageRequest.message}},{key:"accept",value:function(e){return this.incomingMessageRequest.accept(e),i.resolve()}},{key:"reject",value:function(e){return this.incomingMessageRequest.reject(e),i.resolve()}}])}(),ut=function(){return t(function t(n){e(this,t),d(this,"incomingNotifyRequest",{enumerable:!0,configurable:!0,writable:!0,value:n})},[{key:"request",get:function(){return this.incomingNotifyRequest.message}},{key:"accept",value:function(e){return this.incomingNotifyRequest.accept(e),i.resolve()}},{key:"reject",value:function(e){return this.incomingNotifyRequest.reject(e),i.resolve()}}])}(),dt=function(){return t(function t(n,i){e(this,t),d(this,"incomingReferRequest",{enumerable:!0,configurable:!0,writable:!0,value:n}),d(this,"session",{enumerable:!0,configurable:!0,writable:!0,value:i}),d(this,"inviter",{enumerable:!0,configurable:!0,writable:!0,value:void 0})},[{key:"referTo",get:function(){var e=this.incomingReferRequest.message.parseHeader("refer-to");if(!(e instanceof Se))throw new Error("Failed to parse Refer-To header.");return e}},{key:"referredBy",get:function(){return this.incomingReferRequest.message.getHeader("referred-by")}},{key:"replaces",get:function(){var e=this.referTo.uri.getHeader("replaces");return e instanceof Array?e[0]:e}},{key:"request",get:function(){return this.incomingReferRequest.message}},{key:"accept",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:202};return this.incomingReferRequest.accept(e),i.resolve()}},{key:"reject",value:function(e){return this.incomingReferRequest.reject(e),i.resolve()}},{key:"makeInviter",value:function(e){var t;if(this.inviter)return this.inviter;var n=this.referTo.uri.clone();n.clearHeaders();var i=g(t=(e=e||{}).extraHeaders||[]).call(t),r=this.replaces;r&&i.push("Replaces: "+decodeURIComponent(r));var s=this.referredBy;return s&&i.push("Referred-By: "+s),e.extraHeaders=i,this.inviter=this.session.userAgent._makeInviter(n,e),this.inviter._referred=this.session,this.session._referral=this.inviter,this.inviter}}])}();function ht(){var e=new Date,t=e.getFullYear(),n=e.getMonth()+1,i=e.getDate(),r=e.getHours(),s=e.getMinutes(),a=e.getSeconds();return t+"-"+gt(n)+"-"+gt(i)+" "+gt(r)+":"+gt(s)+":"+gt(a)}function gt(e){return e<10?"0"+e:e}!function(e){e.Initial="Initial",e.Establishing="Establishing",e.Established="Established",e.Terminating="Terminating",e.Terminated="Terminated"}(ot||(ot={}));var ft,vt=function(){function n(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,n),d(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_contact",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_referral",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_replacee",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_assertedIdentity",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_dialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_referralInviterOptions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_renderbody",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_rendertype",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"onNotify",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"pendingReinvite",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"pendingReinviteAck",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"_sessionDescriptionHandler",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_sessionDescriptionHandlerModifiers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_sessionDescriptionHandlerOptions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_sessionDescriptionHandlerModifiersReInvite",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_sessionDescriptionHandlerOptionsReInvite",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:ot.Initial}),d(this,"_stateEventEmitter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_userAgent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.delegate=i.delegate,this._stateEventEmitter=new ye,this._userAgent=t}return t(n,[{key:"dispose",value:function(){var e,t=this;switch(this.logger.log(E(e="Session ".concat(this.id," in state ")).call(e,this._state," is being disposed")),delete this.userAgent._sessions[this.id],this._sessionDescriptionHandler&&this._sessionDescriptionHandler.close(),this.state){case ot.Initial:case ot.Establishing:break;case ot.Established:return new i(function(e){t._bye({onAccept:function(){return e()},onRedirect:function(){return e()},onReject:function(){return e()}})});case ot.Terminating:case ot.Terminated:break;default:throw new Error("Unknown state.")}return i.resolve()}},{key:"assertedIdentity",get:function(){return this._assertedIdentity}},{key:"dialog",get:function(){return this._dialog}},{key:"id",get:function(){return this._id}},{key:"replacee",get:function(){return this._replacee}},{key:"sessionDescriptionHandler",get:function(){return this._sessionDescriptionHandler}},{key:"sessionDescriptionHandlerFactory",get:function(){return this.userAgent.configuration.sessionDescriptionHandlerFactory}},{key:"sessionDescriptionHandlerModifiers",get:function(){return this._sessionDescriptionHandlerModifiers||[]},set:function(e){this._sessionDescriptionHandlerModifiers=g(e).call(e)}},{key:"sessionDescriptionHandlerOptions",get:function(){return this._sessionDescriptionHandlerOptions||{}},set:function(e){this._sessionDescriptionHandlerOptions=$({},e)}},{key:"sessionDescriptionHandlerModifiersReInvite",get:function(){return this._sessionDescriptionHandlerModifiersReInvite||[]},set:function(e){this._sessionDescriptionHandlerModifiersReInvite=g(e).call(e)}},{key:"sessionDescriptionHandlerOptionsReInvite",get:function(){return this._sessionDescriptionHandlerOptionsReInvite||{}},set:function(e){this._sessionDescriptionHandlerOptionsReInvite=$({},e)}},{key:"state",get:function(){return this._state}},{key:"stateChange",get:function(){return this._stateEventEmitter}},{key:"userAgent",get:function(){return this._userAgent}},{key:"bye",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t="Session.bye() may only be called if established session.";switch(this.state){case ot.Initial:"function"==typeof this.cancel?(t+=" However Inviter.invite() has not yet been called.",t+=" Perhaps you should have called Inviter.cancel()?"):"function"==typeof this.reject&&(t+=" However Invitation.accept() has not yet been called.",t+=" Perhaps you should have called Invitation.reject()?");break;case ot.Establishing:"function"==typeof this.cancel?(t+=" However a dialog does not yet exist.",t+=" Perhaps you should have called Inviter.cancel()?"):"function"==typeof this.reject&&(t+=" However Invitation.accept() has not yet been called (or not yet resolved).",t+=" Perhaps you should have called Invitation.reject()?");break;case ot.Established:var n=e.requestDelegate,r=this.copyRequestOptions(e.requestOptions);return this._bye(n,r);case ot.Terminating:t+=" However this session is already terminating.","function"==typeof this.cancel?t+=" Perhaps you have already called Inviter.cancel()?":"function"==typeof this.reject&&(t+=" Perhaps you have already called Session.bye()?");break;case ot.Terminated:t+=" However this session is already terminated.";break;default:throw new Error("Unknown state")}return this.logger.error(t),i.reject(new Error("Invalid session state ".concat(this.state)))}},{key:"info",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.state!==ot.Established){return this.logger.error("Session.info() may only be called if established session."),i.reject(new Error("Invalid session state ".concat(this.state)))}var t=e.requestDelegate,n=this.copyRequestOptions(e.requestOptions);return this._info(t,n)}},{key:"invite",value:function(){var e,t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("Session.invite"),this.state!==ot.Established)return i.reject(new Error("Invalid session state ".concat(this.state)));if(this.pendingReinvite)return i.reject(new ue("Reinvite in progress. Please wait until complete, then try again."));this.pendingReinvite=!0,n.sessionDescriptionHandlerModifiers&&(this.sessionDescriptionHandlerModifiersReInvite=n.sessionDescriptionHandlerModifiers),n.sessionDescriptionHandlerOptions&&(this.sessionDescriptionHandlerOptionsReInvite=n.sessionDescriptionHandlerOptions);var r={onAccept:function(e){var i=et(e.message);if(!i)return t.logger.error("Received 2xx response to re-INVITE without a session description"),t.ackAndBye(e,400,"Missing session description"),t.stateTransition(ot.Terminated),void(t.pendingReinvite=!1);if(n.withoutSdp){var r={sessionDescriptionHandlerOptions:t.sessionDescriptionHandlerOptionsReInvite,sessionDescriptionHandlerModifiers:t.sessionDescriptionHandlerModifiersReInvite};t.setOfferAndGetAnswer(i,r).then(function(t){e.ack({body:t})}).catch(function(n){t.logger.error("Failed to handle offer in 2xx response to re-INVITE"),t.logger.error(n.message),t.state===ot.Terminated?e.ack():(t.ackAndBye(e,488,"Bad Media Description"),t.stateTransition(ot.Terminated))}).then(function(){t.pendingReinvite=!1,n.requestDelegate&&n.requestDelegate.onAccept&&n.requestDelegate.onAccept(e)})}else{var s={sessionDescriptionHandlerOptions:t.sessionDescriptionHandlerOptionsReInvite,sessionDescriptionHandlerModifiers:t.sessionDescriptionHandlerModifiersReInvite};t.setAnswer(i,s).then(function(){e.ack()}).catch(function(n){t.logger.error("Failed to handle answer in 2xx response to re-INVITE"),t.logger.error(n.message),t.state!==ot.Terminated?(t.ackAndBye(e,488,"Bad Media Description"),t.stateTransition(ot.Terminated)):e.ack()}).then(function(){t.pendingReinvite=!1,n.requestDelegate&&n.requestDelegate.onAccept&&n.requestDelegate.onAccept(e)})}},onProgress:function(e){},onRedirect:function(e){},onReject:function(e){t.logger.warn("Received a non-2xx response to re-INVITE"),t.pendingReinvite=!1,n.withoutSdp?n.requestDelegate&&n.requestDelegate.onReject&&n.requestDelegate.onReject(e):t.rollbackOffer().catch(function(e){if(t.logger.error("Failed to rollback offer on non-2xx response to re-INVITE"),t.logger.error(e.message),t.state!==ot.Terminated){if(!t.dialog)throw new Error("Dialog undefined.");var n=[];n.push("Reason: "+t.getReasonHeaderValue(500,"Internal Server Error")),t.dialog.bye(void 0,{extraHeaders:n}),t.stateTransition(ot.Terminated)}}).then(function(){n.requestDelegate&&n.requestDelegate.onReject&&n.requestDelegate.onReject(e)})},onTrying:function(e){}},s=n.requestOptions||{};if(s.extraHeaders=g(e=s.extraHeaders||[]).call(e),s.extraHeaders.push("Allow: "+ct.toString()),s.extraHeaders.push("Contact: "+this._contact),n.withoutSdp){if(!this.dialog)throw this.pendingReinvite=!1,new Error("Dialog undefined.");return i.resolve(this.dialog.invite(r,s))}var a={sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptionsReInvite,sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiersReInvite};return this.getOffer(a).then(function(e){if(!t.dialog)throw t.pendingReinvite=!1,new Error("Dialog undefined.");return s.body=e,t.dialog.invite(r,s)}).catch(function(e){throw t.logger.error(e.message),t.logger.error("Failed to send re-INVITE"),t.pendingReinvite=!1,e})}},{key:"message",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.state!==ot.Established){return this.logger.error("Session.message() may only be called if established session."),i.reject(new Error("Invalid session state ".concat(this.state)))}var t=e.requestDelegate,n=this.copyRequestOptions(e.requestOptions);return this._message(t,n)}},{key:"refer",value:function(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.state!==ot.Established){return this.logger.error("Session.refer() may only be called if established session."),i.reject(new Error("Invalid session state ".concat(this.state)))}if(e instanceof n&&!e.dialog){return this.logger.error("Session.refer() may only be called with session which is established. You are perhaps attempting to attended transfer to a target for which there is not dialog yet established. Perhaps you are attempting a 'semi-attended' tansfer? Regardless, this is not supported. The recommended approached is to check to see if the target Session is in the Established state before calling refer(); if the state is not Established you may proceed by falling back using a URI as the target (blind transfer)."),i.reject(new Error("Invalid session state ".concat(this.state)))}var s=r.requestDelegate,a=this.copyRequestOptions(r.requestOptions);return a.extraHeaders=a.extraHeaders?E(t=a.extraHeaders).call(t,this.referExtraHeaders(this.referToString(e))):this.referExtraHeaders(this.referToString(e)),this._refer(r.onNotify,s,a)}},{key:"_bye",value:function(e,t){var n=this;if(!this.dialog)return i.reject(new Error("Session dialog undefined."));var r=this.dialog;switch(r.sessionState){case Ke.Initial:case Ke.Early:throw new Error("Invalid dialog state ".concat(r.sessionState));case Ke.AckWait:return this.stateTransition(ot.Terminating),new i(function(s){r.delegate={onAck:function(){var a=r.bye(e,t);return n.stateTransition(ot.Terminated),s(a),i.resolve()},onAckTimeout:function(){var i=r.bye(e,t);n.stateTransition(ot.Terminated),s(i)}}});case Ke.Confirmed:var s=r.bye(e,t);return this.stateTransition(ot.Terminated),i.resolve(s);case Ke.Terminated:throw new Error("Invalid dialog state ".concat(r.sessionState));default:throw new Error("Unrecognized state.")}}},{key:"_info",value:function(e,t){return this.dialog?i.resolve(this.dialog.info(e,t)):i.reject(new Error("Session dialog undefined."))}},{key:"_message",value:function(e,t){return this.dialog?i.resolve(this.dialog.message(e,t)):i.reject(new Error("Session dialog undefined."))}},{key:"_refer",value:function(e,t,n){return this.dialog?(this.onNotify=e,i.resolve(this.dialog.refer(t,n))):i.reject(new Error("Session dialog undefined."))}},{key:"ackAndBye",value:function(e,t,n){e.ack();var i=[];t&&i.push("Reason: "+this.getReasonHeaderValue(t,n)),e.session.bye(void 0,{extraHeaders:i})}},{key:"onAckRequest",value:function(e){var t=this;if(this.logger.log("Session.onAckRequest"),this.state!==ot.Established&&this.state!==ot.Terminating)return this.logger.error("ACK received while in state ".concat(this.state,", dropping request")),i.resolve();var n=this.dialog;if(!n)throw new Error("Dialog undefined.");var r={sessionDescriptionHandlerOptions:this.pendingReinviteAck?this.sessionDescriptionHandlerOptionsReInvite:this.sessionDescriptionHandlerOptions,sessionDescriptionHandlerModifiers:this.pendingReinviteAck?this._sessionDescriptionHandlerModifiersReInvite:this._sessionDescriptionHandlerModifiers};if(this.delegate&&this.delegate.onAck){var s=new me(e);this.delegate.onAck(s)}switch(this.pendingReinviteAck=!1,n.signalingState){case ze.Initial:this.logger.error("Invalid signaling state ".concat(n.signalingState,"."));var a=["Reason: "+this.getReasonHeaderValue(488,"Bad Media Description")];return n.bye(void 0,{extraHeaders:a}),this.stateTransition(ot.Terminated),i.resolve();case ze.Stable:var o=et(e.message);return o?"render"===o.contentDisposition?(this._renderbody=o.content,this._rendertype=o.contentType,i.resolve()):"session"!==o.contentDisposition?i.resolve():this.setAnswer(o,r).catch(function(e){t.logger.error(e.message);var i=["Reason: "+t.getReasonHeaderValue(488,"Bad Media Description")];n.bye(void 0,{extraHeaders:i}),t.stateTransition(ot.Terminated)}):i.resolve();case ze.HaveLocalOffer:this.logger.error("Invalid signaling state ".concat(n.signalingState,"."));var c=["Reason: "+this.getReasonHeaderValue(488,"Bad Media Description")];return n.bye(void 0,{extraHeaders:c}),this.stateTransition(ot.Terminated),i.resolve();case ze.HaveRemoteOffer:this.logger.error("Invalid signaling state ".concat(n.signalingState,"."));var l=["Reason: "+this.getReasonHeaderValue(488,"Bad Media Description")];return n.bye(void 0,{extraHeaders:l}),this.stateTransition(ot.Terminated),i.resolve();case ze.Closed:default:throw new Error("Invalid signaling state ".concat(n.signalingState,"."))}}},{key:"onByeRequest",value:function(e){if(this.logger.log("Session.onByeRequest"),this.state===ot.Established){if(this.delegate&&this.delegate.onBye){var t=new be(e);this.delegate.onBye(t)}else e.accept();this.stateTransition(ot.Terminated)}else this.logger.error("BYE received while in state ".concat(this.state,", dropping request"))}},{key:"onInfoRequest",value:function(e){if(this.logger.log("Session.onInfoRequest"),this.state===ot.Established)if(this.delegate&&this.delegate.onInfo){var t=new ke(e);this.delegate.onInfo(t)}else e.accept();else this.logger.error("INFO received while in state ".concat(this.state,", dropping request"))}},{key:"onInviteRequest",value:function(e){var t=this;if(this.logger.log("Session.onInviteRequest"),this.state===ot.Established){this.pendingReinviteAck=!0;var n=["Contact: "+this._contact];if(e.message.hasHeader("P-Asserted-Identity")){var i=e.message.getHeader("P-Asserted-Identity");if(!i)throw new Error("Header undefined.");this._assertedIdentity=He.nameAddrHeaderParse(i)}var r={sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptionsReInvite,sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiersReInvite};this.generateResponseOfferAnswerInDialog(r,e).then(function(i){var r=e.accept({statusCode:200,extraHeaders:n,body:i});t.delegate&&t.delegate.onInvite&&t.delegate.onInvite(e.message,r.message,200)}).catch(function(n){if(t.logger.error(n.message),t.logger.error("Failed to handle to re-INVITE request"),!t.dialog)throw new Error("Dialog undefined.");if(t.logger.error(t.dialog.signalingState),t.dialog.signalingState!==ze.Stable)t.rollbackOffer().then(function(){var n=e.reject({statusCode:488});t.delegate&&t.delegate.onInvite&&t.delegate.onInvite(e.message,n.message,488)}).catch(function(n){t.logger.error(n.message),t.logger.error("Failed to rollback offer on re-INVITE request");var i=e.reject({statusCode:488});if(t.state!==ot.Terminated){if(!t.dialog)throw new Error("Dialog undefined.");var r=[];r.push("Reason: "+t.getReasonHeaderValue(500,"Internal Server Error")),t.dialog.bye(void 0,{extraHeaders:r}),t.stateTransition(ot.Terminated)}t.delegate&&t.delegate.onInvite&&t.delegate.onInvite(e.message,i.message,488)});else{var i=e.reject({statusCode:488});t.delegate&&t.delegate.onInvite&&t.delegate.onInvite(e.message,i.message,488)}})}else this.logger.error("INVITE received while in state ".concat(this.state,", dropping request"))}},{key:"onMessageRequest",value:function(e){if(this.logger.log("Session.onMessageRequest"),this.state===ot.Established)if(this.delegate&&this.delegate.onMessage){var t=new lt(e);this.delegate.onMessage(t)}else e.accept();else this.logger.error("MESSAGE received while in state ".concat(this.state,", dropping request"))}},{key:"onNotifyRequest",value:function(e){if(this.logger.log("Session.onNotifyRequest"),this.state===ot.Established)if(this.onNotify){var t=new ut(e);this.onNotify(t)}else if(this.delegate&&this.delegate.onNotify){var n=new ut(e);this.delegate.onNotify(n)}else e.accept();else this.logger.error("NOTIFY received while in state ".concat(this.state,", dropping request"))}},{key:"onPrackRequest",value:function(e){if(this.logger.log("Session.onPrackRequest"),this.state===ot.Established)throw new Error("Unimplemented.");this.logger.error("PRACK received while in state ".concat(this.state,", dropping request"))}},{key:"onReferRequest",value:function(e){var t=this;if(this.logger.log("Session.onReferRequest"),this.state===ot.Established){if(!e.message.hasHeader("refer-to"))return this.logger.warn("Invalid REFER packet. A refer-to header is required. Rejecting."),void e.reject();var n=new dt(e,this);this.delegate&&this.delegate.onRefer?this.delegate.onRefer(n):(this.logger.log("No delegate available to handle REFER, automatically accepting and following."),n.accept().then(function(){return n.makeInviter(t._referralInviterOptions).invite()}).catch(function(e){t.logger.error(e.message)}))}else this.logger.error("REFER received while in state ".concat(this.state,", dropping request"))}},{key:"generateResponseOfferAnswer",value:function(e,t){var n=this;if(this.dialog)return this.generateResponseOfferAnswerInDialog(t,e).catch(function(t){var i;throw null===(i=n.userAgent.configuration)||void 0===i||i.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ht(),CALLID:e.message.callId,INVITE:e.message.toString(),ENTRY:"session: generateResponseOfferAnswer generateResponseOfferAnswerInDialog catch"}),t});var i=et(e.message);return i&&"session"===i.contentDisposition?this.setOfferAndGetAnswer(i,t,e).catch(function(t){var i;throw null===(i=n.userAgent.configuration)||void 0===i||i.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ht(),CALLID:e.message.callId,INVITE:e.message.toString(),ENTRY:"session: generateResponseOfferAnswer setOfferAndGetAnswer catch"}),t}):this.getOffer(t,e).catch(function(t){var i;throw null===(i=n.userAgent.configuration)||void 0===i||i.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ht(),CALLID:e.message.callId,INVITE:e.message.toString(),ENTRY:"session: generateResponseOfferAnswer getOffer catch"}),t})}},{key:"generateResponseOfferAnswerInDialog",value:function(e,t){var n=this;if(!this.dialog)throw new Error("Dialog undefined.");switch(this.dialog.signalingState){case ze.Initial:return this.getOffer(e,t).catch(function(e){var i;throw null===(i=n.userAgent.configuration)||void 0===i||i.errorCallback({ERR_MESSAGE:e.message,CODE:"480",TIMESTAMP:ht(),CALLID:(null==t?void 0:t.message.callId)||"",INVITE:(null==t?void 0:t.message.toString())||"",ENTRY:"session: generateResponseOfferAnswerInDialog SignalingState.Initial getOffer catch"}),e});case ze.HaveLocalOffer:return i.resolve(void 0);case ze.HaveRemoteOffer:if(!this.dialog.offer)throw new Error("Session offer undefined in signaling state ".concat(this.dialog.signalingState,"."));return this.setOfferAndGetAnswer(this.dialog.offer,e,t).catch(function(e){var i;throw null===(i=n.userAgent.configuration)||void 0===i||i.errorCallback({ERR_MESSAGE:e.message,CODE:"480",TIMESTAMP:ht(),CALLID:(null==t?void 0:t.message.callId)||"",INVITE:(null==t?void 0:t.message.toString())||"",ENTRY:"session: generateResponseOfferAnswerInDialog setOfferAndGetAnswer catch"}),e});case ze.Stable:return this.state!==ot.Established?i.resolve(void 0):this.getOffer(e,t).catch(function(e){var i;throw null===(i=n.userAgent.configuration)||void 0===i||i.errorCallback({ERR_MESSAGE:e.message,CODE:"480",TIMESTAMP:ht(),CALLID:(null==t?void 0:t.message.callId)||"",INVITE:(null==t?void 0:t.message.toString())||"",ENTRY:"session: generateResponseOfferAnswerInDialog SignalingState.Stable getOffer catch"}),e});case ze.Closed:default:throw new Error("Invalid signaling state ".concat(this.dialog.signalingState,"."))}}},{key:"getOffer",value:function(e,t){var n,r=this;try{var s=this.setupSessionDescriptionHandler(),a=e.sessionDescriptionHandlerOptions,o=e.sessionDescriptionHandlerModifiers;return s.getDescription(a,o).catch(function(e){var n;throw null===(n=r.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:e.message,CODE:"480",TIMESTAMP:ht(),CALLID:(null==t?void 0:t.message.callId)||"",INVITE:(null==t?void 0:t.message.toString())||"",ENTRY:"session: getOffer sdh.getDescription catch"}),e}).then(function(e){return Xe(e)}).catch(function(e){r.logger.error("Session.getOffer: SDH getDescription rejected...");var t=e instanceof Error?e:new Error("Session.getOffer unknown error.");throw r.logger.error(t.message),t})}catch(e){this.logger.error("Session.getOffer: SDH getDescription threw...");var c=e instanceof Error?e:new Error(e);return this.logger.error(c.message),null===(n=this.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:c.message,CODE:"480",TIMESTAMP:ht(),CALLID:(null==t?void 0:t.message.callId)||"",INVITE:(null==t?void 0:t.message.toString())||"",ENTRY:"session: getOffer setupSessionDescriptionHandler catch"}),i.reject(c)}}},{key:"rollbackOffer",value:function(){var e=this;try{var t=this.setupSessionDescriptionHandler();return void 0===t.rollbackDescription?i.resolve():t.rollbackDescription().catch(function(t){e.logger.error("Session.rollbackOffer: SDH rollbackDescription rejected...");var n=t instanceof Error?t:new Error("Session.rollbackOffer unknown error.");throw e.logger.error(n.message),n})}catch(e){this.logger.error("Session.rollbackOffer: SDH rollbackDescription threw...");var n=e instanceof Error?e:new Error(e);return this.logger.error(n.message),i.reject(n)}}},{key:"setAnswer",value:function(e,t){var n,r,s,a=this;try{if(n=this.setupSessionDescriptionHandler(),r=t.sessionDescriptionHandlerOptions,s=t.sessionDescriptionHandlerModifiers,!n.hasDescription(e.contentType))return i.reject(new ce)}catch(e){this.logger.error("Session.setAnswer: SDH hasDescription threw...");var o=e instanceof Error?e:new Error(e);return this.logger.error(o.message),i.reject(o)}try{return n.setDescription(e.content,r,s).catch(function(e){a.logger.error("Session.setAnswer: SDH setDescription rejected...");var t=e instanceof Error?e:new Error("Session.setAnswer unknown error.");throw a.logger.error(t.message),t})}catch(e){this.logger.error("Session.setAnswer: SDH setDescription threw...");var c=e instanceof Error?e:new Error(e);return this.logger.error(c.message),i.reject(c)}}},{key:"setOfferAndGetAnswer",value:function(e,t,n){var r,s,a,o,c=this;try{if(s=this.setupSessionDescriptionHandler(),a=t.sessionDescriptionHandlerOptions,o=t.sessionDescriptionHandlerModifiers,!s.hasDescription(e.contentType))return i.reject(new ce)}catch(e){this.logger.error("Session.setOfferAndGetAnswer: SDH hasDescription threw...");var l=e instanceof Error?e:new Error(e);return this.logger.error(l.message),null===(r=this.userAgent.configuration)||void 0===r||r.errorCallback({ERR_MESSAGE:l.message,CODE:"480",TIMESTAMP:ht(),CALLID:(null==n?void 0:n.message.callId)||"",INVITE:(null==n?void 0:n.message.toString())||"",ENTRY:"session: setOfferAndGetAnswer setupSessionDescriptionHandler catch"}),i.reject(l)}try{return s.setDescription(e.content,a,o).catch(function(e){var t;throw null===(t=c.userAgent.configuration)||void 0===t||t.errorCallback({ERR_MESSAGE:e.message,CODE:"480",TIMESTAMP:ht(),CALLID:(null==n?void 0:n.message.callId)||"",INVITE:(null==n?void 0:n.message.toString())||"",ENTRY:"session: setOfferAndGetAnswer sdh.setDescription catch"}),e}).then(function(){return s.getDescription(a,o)}).catch(function(e){var t;throw null===(t=c.userAgent.configuration)||void 0===t||t.errorCallback({ERR_MESSAGE:e.message,CODE:"480",TIMESTAMP:ht(),CALLID:(null==n?void 0:n.message.callId)||"",INVITE:(null==n?void 0:n.message.toString())||"",ENTRY:"session: setOfferAndGetAnswer sdh.getDescription catch"}),e}).then(function(e){return Xe(e)}).catch(function(e){c.logger.error("Session.setOfferAndGetAnswer: SDH setDescription or getDescription rejected...");var t=e instanceof Error?e:new Error("Session.setOfferAndGetAnswer unknown error.");throw c.logger.error(t.message),t})}catch(e){this.logger.error("Session.setOfferAndGetAnswer: SDH setDescription or getDescription threw...");var u=e instanceof Error?e:new Error(e);return this.logger.error(u.message),i.reject(u)}}},{key:"setSessionDescriptionHandler",value:function(e){if(this._sessionDescriptionHandler)throw new Error("Session description handler defined.");this._sessionDescriptionHandler=e}},{key:"setupSessionDescriptionHandler",value:function(){var e;return this._sessionDescriptionHandler||(this._sessionDescriptionHandler=this.sessionDescriptionHandlerFactory(this,this.userAgent.configuration.sessionDescriptionHandlerFactoryOptions),(null===(e=this.delegate)||void 0===e?void 0:e.onSessionDescriptionHandler)&&this.delegate.onSessionDescriptionHandler(this._sessionDescriptionHandler,!1)),this._sessionDescriptionHandler}},{key:"stateTransition",value:function(e){var t,n=this,i=function(){var t;throw new Error(E(t="Invalid state transition from ".concat(n._state," to ")).call(t,e))};switch(this._state){case ot.Initial:e!==ot.Establishing&&e!==ot.Established&&e!==ot.Terminating&&e!==ot.Terminated&&i();break;case ot.Establishing:e!==ot.Established&&e!==ot.Terminating&&e!==ot.Terminated&&i();break;case ot.Established:e!==ot.Terminating&&e!==ot.Terminated&&i();break;case ot.Terminating:e!==ot.Terminated&&i();break;case ot.Terminated:i();break;default:throw new Error("Unrecognized state.")}this._state=e,this.logger.log(E(t="Session ".concat(this.id," transitioned to state ")).call(t,this._state)),this._stateEventEmitter.emit(this._state),e===ot.Terminated&&this.dispose()}},{key:"copyRequestOptions",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{extraHeaders:t.extraHeaders?g(e=t.extraHeaders).call(e):void 0,body:t.body?{contentDisposition:t.body.contentDisposition||"render",contentType:t.body.contentType||"text/plain",content:t.body.content||""}:void 0}}},{key:"getReasonHeaderValue",value:function(e,t){var n=e,i=Me(e);return!i&&t&&(i=t),"SIP;cause="+n+';text="'+i+'"'}},{key:"referExtraHeaders",value:function(e){var t=[];return t.push("Referred-By: <"+this.userAgent.configuration.uri+">"),t.push("Contact: "+this._contact),t.push("Allow: "+["ACK","CANCEL","INVITE","MESSAGE","BYE","OPTIONS","INFO","NOTIFY","REFER"].toString()),t.push("Refer-To: "+e),t}},{key:"referToString",value:function(e){var t;if(e instanceof Ee)t=e.toString();else{var n,i,r,s;if(!e.dialog)throw new Error("Dialog undefined.");var a=e.remoteIdentity.friendlyName,o=e.dialog.remoteTarget.toString(),c=e.dialog.callId,l=e.dialog.remoteTag,u=e.dialog.localTag,d=encodeURIComponent(E(n=E(i="".concat(c,";to-tag=")).call(i,l,";from-tag=")).call(n,u));t=E(r=E(s='"'.concat(a,'" <')).call(s,o,"?Replaces=")).call(r,d,">")}return t}}])}();!function(e){e.Required="Required",e.Supported="Supported",e.Unsupported="Unsupported"}(ft||(ft={}));var pt={"100rel":!0,199:!0,answermode:!0,"early-session":!0,eventlist:!0,explicitsub:!0,"from-change":!0,"geolocation-http":!0,"geolocation-sip":!0,gin:!0,gruu:!0,histinfo:!0,ice:!0,join:!0,"multiple-refer":!0,norefersub:!0,nosub:!0,outbound:!0,path:!0,policy:!0,precondition:!0,pref:!0,privacy:!0,"recipient-list-invite":!0,"recipient-list-message":!0,"recipient-list-subscribe":!0,replaces:!0,"resource-priority":!0,"sdp-anat":!0,"sec-agree":!0,tdialog:!0,timer:!0,uui:!0};function mt(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(mt=function(){return!!e})()}function bt(e,t,n,i){var r=v(o(1&i?e.prototype:e),t,n);return 2&i&&"function"==typeof r?function(e){return r.apply(n,e)}:r}var wt=function(){function n(t,i){var r,c,l,u,h,g;e(this,n),u=this,g=[t],h=o(h=n),l=a(u,mt()?s(h,g||[],o(u).constructor):h.apply(u,g)),d(l,"incomingInviteRequest",{enumerable:!0,configurable:!0,writable:!0,value:i}),d(l,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"_id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"disposed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(l,"expiresTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"isCanceled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(l,"rel100",{enumerable:!0,configurable:!0,writable:!0,value:"none"}),d(l,"rseq",{enumerable:!0,configurable:!0,writable:!0,value:Math.floor(1e4*Math.random())}),d(l,"userNoAnswerTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"waitingForPrack",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(l,"waitingForPrackPromise",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"waitingForPrackResolve",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"waitingForPrackReject",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),l.logger=t.getLogger("sip.Invitation");var f=l.incomingInviteRequest.message,v=f.getHeader("require");v&&p(r=v.toLowerCase()).call(r,"100rel")&&(l.rel100="required");var b=f.getHeader("supported");if(b&&p(c=b.toLowerCase()).call(c,"100rel")&&(l.rel100="supported"),f.toTag=i.toTag,"string"!=typeof f.toTag)throw new TypeError("toTag should have been a string.");if(l.userNoAnswerTimer=m(function(){var e;null===(e=l.userAgent.configuration)||void 0===e||e.errorCallback({ERR_MESSAGE:"NOT ERROR",CODE:"480",TIMESTAMP:ht(),CALLID:l.incomingInviteRequest.message.callId,INVITE:l.incomingInviteRequest.message.toString(),ENTRY:"invitation: constructor userNoAnswerTimer ".concat(l.userAgent.configuration.noAnswerTimeout?1e3*l.userAgent.configuration.noAnswerTimeout:6e4)}),i.reject({statusCode:480}),l.stateTransition(ot.Terminated)},l.userAgent.configuration.noAnswerTimeout?1e3*l.userAgent.configuration.noAnswerTimeout:6e4),f.hasHeader("expires")){var w=1e3*Number(f.getHeader("expires")||0);l.expiresTimer=m(function(){l.state===ot.Initial&&(i.reject({statusCode:487}),l.stateTransition(ot.Terminated))},w)}var y=l.request.getHeader("P-Asserted-Identity");y&&(l._assertedIdentity=He.nameAddrHeaderParse(y)),l._contact=l.userAgent.contact.toString();var k=f.parseHeader("Content-Disposition");return k&&"render"===k.type&&(l._renderbody=f.body,l._rendertype=f.getHeader("Content-Type")),l._id=f.callId+f.fromTag,l.userAgent._sessions[l._id]=l,l}return c(n,vt),t(n,[{key:"dispose",value:function(){var e=this;if(this.disposed)return i.resolve();switch(this.disposed=!0,this.expiresTimer&&(clearTimeout(this.expiresTimer),this.expiresTimer=void 0),this.userNoAnswerTimer&&(clearTimeout(this.userNoAnswerTimer),this.userNoAnswerTimer=void 0),this.prackNeverArrived(),this.state){case ot.Initial:case ot.Establishing:return this.reject().then(function(){return bt(n,"dispose",e,3)([])});case ot.Established:case ot.Terminating:case ot.Terminated:return bt(n,"dispose",this,3)([]);default:throw new Error("Unknown state.")}}},{key:"autoSendAnInitialProvisionalResponse",get:function(){return"required"!==this.rel100&&this.userAgent.configuration.sendInitialProvisionalResponse}},{key:"body",get:function(){return this.incomingInviteRequest.message.body}},{key:"localIdentity",get:function(){return this.request.to}},{key:"remoteIdentity",get:function(){return this.request.from}},{key:"request",get:function(){return this.incomingInviteRequest.message}},{key:"accept",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("Invitation.accept"),this.state!==ot.Initial){var n=new Error("Invalid session state ".concat(this.state));return this.logger.error(n.message),i.reject(n)}return t.sessionDescriptionHandlerModifiers&&(this.sessionDescriptionHandlerModifiers=t.sessionDescriptionHandlerModifiers),t.sessionDescriptionHandlerOptions&&(this.sessionDescriptionHandlerOptions=t.sessionDescriptionHandlerOptions),this.stateTransition(ot.Establishing),this.sendAccept(t).then(function(n){n.message;var i=n.session;i.delegate={onAck:function(n){var i=e.onAckRequest(n);return t.onAck&&t.onAck(n),i},onAckTimeout:function(){e.onAckTimeout(),t.onAckTimeout&&t.onAckTimeout()},onBye:function(t){return e.onByeRequest(t)},onInfo:function(t){return e.onInfoRequest(t)},onInvite:function(t){return e.onInviteRequest(t)},onMessage:function(t){return e.onMessageRequest(t)},onNotify:function(t){return e.onNotifyRequest(t)},onPrack:function(t){return e.onPrackRequest(t)},onRefer:function(t){return e.onReferRequest(t)}},e._dialog=i,e.stateTransition(ot.Established),e._replacee&&e._replacee._bye()}).catch(function(t){var n;return null===(n=e.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ht(),CALLID:e.incomingInviteRequest.message.callId,INVITE:e.incomingInviteRequest.message.toString(),ENTRY:"invitation: accept sendAccept catch"}),e.handleResponseError(t)})}},{key:"progress",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("Invitation.progress"),this.state!==ot.Initial){var n=new Error("Invalid session state ".concat(this.state));return this.logger.error(n.message),i.reject(n)}var r=t.statusCode||180;if(r<100||r>199)throw new TypeError("Invalid statusCode: "+r);return t.sessionDescriptionHandlerModifiers&&(this.sessionDescriptionHandlerModifiers=t.sessionDescriptionHandlerModifiers),t.sessionDescriptionHandlerOptions&&(this.sessionDescriptionHandlerOptions=t.sessionDescriptionHandlerOptions),this.waitingForPrack?(this.logger.warn("Unexpected call for progress while waiting for prack, ignoring"),i.resolve()):100===t.statusCode?this.sendProgressTrying().then(function(){}).catch(function(t){var n;return null===(n=e.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ht(),CALLID:e.incomingInviteRequest.message.callId,INVITE:e.incomingInviteRequest.message.toString(),ENTRY:"invitation: progress sendProgressTrying catch"}),e.handleResponseError(t)}):"required"===this.rel100||"supported"===this.rel100&&t.rel100||"supported"===this.rel100&&this.userAgent.configuration.sipExtension100rel===ft.Required?this.sendProgressReliableWaitForPrack(t).then(function(){}).catch(function(t){var n;return null===(n=e.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ht(),CALLID:e.incomingInviteRequest.message.callId,INVITE:e.incomingInviteRequest.message.toString(),ENTRY:"invitation: progress sendProgressReliableWaitForPrack catch"}),e.handleResponseError(t)}):this.sendProgress(t).then(function(){}).catch(function(t){var n;return null===(n=e.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ht(),CALLID:e.incomingInviteRequest.message.callId,INVITE:e.incomingInviteRequest.message.toString(),ENTRY:"invitation: progress rel100 sendProgress catch"}),e.handleResponseError(t)})}},{key:"reject",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("Invitation.reject"),this.state!==ot.Initial&&this.state!==ot.Establishing){var t=new Error("Invalid session state ".concat(this.state));return this.logger.error(t.message),i.reject(t)}var n=e.statusCode||480,r=e.reasonPhrase?e.reasonPhrase:Me(n),s=e.extraHeaders||[];if(n<300||n>699)throw new TypeError("Invalid statusCode: "+n);var a=e.body?Xe(e.body):void 0;return n<400?this.incomingInviteRequest.redirect([],{statusCode:n,reasonPhrase:r,extraHeaders:s,body:a}):this.incomingInviteRequest.reject({statusCode:n,reasonPhrase:r,extraHeaders:s,body:a}),this.stateTransition(ot.Terminated),i.resolve()}},{key:"_onCancel",value:function(e){if(this.logger.log("Invitation._onCancel"),this.state===ot.Initial||this.state===ot.Establishing){if(this.delegate&&this.delegate.onCancel){var t=new we(e);this.delegate.onCancel(t)}this.isCanceled=!0,this.incomingInviteRequest.reject({statusCode:487}),this.stateTransition(ot.Terminated)}else this.logger.error("CANCEL received while in state ".concat(this.state,", dropping request"))}},{key:"handlePrackOfferAnswer",value:function(e){if(!this.dialog)throw new Error("Dialog undefined.");var t=et(e.message);if(!t||"session"!==t.contentDisposition)return i.resolve(void 0);var n={sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions,sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers};switch(this.dialog.signalingState){case ze.Initial:throw new Error("Invalid signaling state ".concat(this.dialog.signalingState,"."));case ze.Stable:return this.setAnswer(t,n).then(function(){});case ze.HaveLocalOffer:throw new Error("Invalid signaling state ".concat(this.dialog.signalingState,"."));case ze.HaveRemoteOffer:return this.setOfferAndGetAnswer(t,n);case ze.Closed:default:throw new Error("Invalid signaling state ".concat(this.dialog.signalingState,"."))}}},{key:"handleResponseError",value:function(e){var t=480;if(e instanceof Error?this.logger.error(e.message):this.logger.error(e),e instanceof ce?(this.logger.error("A session description handler occurred while sending response (content type unsupported"),t=415):e instanceof he?this.logger.error("A session description handler occurred while sending response"):e instanceof fe?this.logger.error("Session ended before response could be formulated and sent (while waiting for PRACK)"):e instanceof at&&this.logger.error("Session changed state before response could be formulated and sent"),this.state===ot.Initial||this.state===ot.Establishing)try{this.incomingInviteRequest.reject({statusCode:t}),this.stateTransition(ot.Terminated)}catch(e){throw this.logger.error("An error occurred attempting to reject the request while handling another error"),e}if(!this.isCanceled)throw e;this.logger.warn("An error occurred while attempting to formulate and send a response to an incoming INVITE. However a CANCEL was received and processed while doing so which can (and often does) result in errors occurring as the session terminates in the meantime. Said error is being ignored.")}},{key:"onAckTimeout",value:function(){if(this.logger.log("Invitation.onAckTimeout"),!this.dialog)throw new Error("Dialog undefined.");this.logger.log("No ACK received for an extended period of time, terminating session"),this.dialog.bye(),this.stateTransition(ot.Terminated)}},{key:"sendAccept",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n={sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions,sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers},i=t.extraHeaders||[];return this.waitingForPrack?this.waitForArrivalOfPrack().then(function(){return clearTimeout(e.userNoAnswerTimer)}).then(function(){return e.generateResponseOfferAnswer(e.incomingInviteRequest,n)}).catch(function(t){var n;throw null===(n=e.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ht(),CALLID:e.incomingInviteRequest.message.callId,INVITE:e.incomingInviteRequest.message.toString(),ENTRY:"invitation: sendAccept waitForArrivalOfPrack generateResponseOfferAnswer catch"}),t}).then(function(t){return e.incomingInviteRequest.accept({statusCode:200,body:t,extraHeaders:i})}):(clearTimeout(this.userNoAnswerTimer),this.generateResponseOfferAnswer(this.incomingInviteRequest,n).catch(function(t){var n;throw null===(n=e.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ht(),CALLID:e.incomingInviteRequest.message.callId,INVITE:e.incomingInviteRequest.message.toString(),ENTRY:"invitation: sendAccept generateResponseOfferAnswer catch"}),t}).then(function(t){return e.incomingInviteRequest.accept({statusCode:200,body:t,extraHeaders:i})}))}},{key:"sendProgress",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.statusCode||180,r=t.reasonPhrase,s=g(e=t.extraHeaders||[]).call(e),a=t.body?Xe(t.body):void 0;if(183===n&&!a)return this.sendProgressWithSDP(t);try{var o=this.incomingInviteRequest.progress({statusCode:n,reasonPhrase:r,extraHeaders:s,body:a});return this._dialog=o.session,i.resolve(o)}catch(e){return i.reject(e)}}},{key:"sendProgressWithSDP",value:function(){var e,t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i={sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions,sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers},r=n.statusCode||183,s=n.reasonPhrase,a=g(e=n.extraHeaders||[]).call(e);return this.generateResponseOfferAnswer(this.incomingInviteRequest,i).then(function(e){return t.incomingInviteRequest.progress({statusCode:r,reasonPhrase:s,extraHeaders:a,body:e})}).then(function(e){return t._dialog=e.session,e})}},{key:"sendProgressReliable",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return t.extraHeaders=g(e=t.extraHeaders||[]).call(e),t.extraHeaders.push("Require: 100rel"),t.extraHeaders.push("RSeq: "+Math.floor(1e4*Math.random())),this.sendProgressWithSDP(t)}},{key:"sendProgressReliableWaitForPrack",value:function(){var e,t,n=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},s={sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions,sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers},a=r.statusCode||183,o=r.reasonPhrase,c=g(e=r.extraHeaders||[]).call(e);return c.push("Require: 100rel"),c.push("RSeq: "+this.rseq++),new i(function(e,i){n.waitingForPrack=!0,n.generateResponseOfferAnswer(n.incomingInviteRequest,s).then(function(e){return t=e,n.incomingInviteRequest.progress({statusCode:a,reasonPhrase:o,extraHeaders:c,body:t})}).then(function(r){var s,l;n._dialog=r.session,r.session.delegate={onPrack:function(t){s=t,clearTimeout(u),clearTimeout(g),n.waitingForPrack&&(n.waitingForPrack=!1,n.handlePrackOfferAnswer(s).then(function(t){try{l=s.accept({statusCode:200,body:t}),n.prackArrived(),e({prackRequest:s,prackResponse:l,progressResponse:r})}catch(e){i(e)}}).catch(function(e){return i(e)}))}};var u=m(function(){n.waitingForPrack&&(n.waitingForPrack=!1,n.logger.warn("No PRACK received, rejecting INVITE."),clearTimeout(g),n.reject({statusCode:504}).then(function(){return i(new fe)}).catch(function(e){return i(e)}))},64*it.T1),d=function(){try{n.incomingInviteRequest.progress({statusCode:a,reasonPhrase:o,extraHeaders:c,body:t})}catch(e){return n.waitingForPrack=!1,void i(e)}g=m(d,h*=2)},h=it.T1,g=m(d,h)}).catch(function(e){n.waitingForPrack=!1,i(e)})})}},{key:"sendProgressTrying",value:function(){try{var e=this.incomingInviteRequest.trying();return i.resolve(e)}catch(e){return i.reject(e)}}},{key:"waitForArrivalOfPrack",value:function(){var e=this;if(this.waitingForPrackPromise)throw new Error("Already waiting for PRACK");return this.waitingForPrackPromise=new i(function(t,n){e.waitingForPrackResolve=t,e.waitingForPrackReject=n}),this.waitingForPrackPromise}},{key:"prackArrived",value:function(){this.waitingForPrackResolve&&this.waitingForPrackResolve(),this.waitingForPrackPromise=void 0,this.waitingForPrackResolve=void 0,this.waitingForPrackReject=void 0}},{key:"prackNeverArrived",value:function(){this.waitingForPrackReject&&this.waitingForPrackReject(new fe),this.waitingForPrackPromise=void 0,this.waitingForPrackResolve=void 0,this.waitingForPrackReject=void 0}}])}();function yt(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(yt=function(){return!!e})()}function kt(e,t,n,i){var r=v(o(1&i?e.prototype:e),t,n);return 2&i&&"function"==typeof r?function(e){return r.apply(n,e)}:r}var Tt,Rt,St=function(){function n(t,i){var r,c,l,u,h,f=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};e(this,n),l=this,h=[t,f],u=o(u=n),c=a(l,yt()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"_referred",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"_id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"disposed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(c,"earlyMedia",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(c,"earlyMediaDialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"earlyMediaSessionDescriptionHandlers",{enumerable:!0,configurable:!0,writable:!0,value:new M}),d(c,"fromTag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"isCanceled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(c,"inviteWithoutSdp",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(c,"outgoingInviteRequest",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"outgoingRequestMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c.logger=t.getLogger("sip.Inviter"),c.earlyMedia=void 0!==f.earlyMedia?f.earlyMedia:c.earlyMedia,c.fromTag=Pe(),c.inviteWithoutSdp=void 0!==f.inviteWithoutSdp?f.inviteWithoutSdp:c.inviteWithoutSdp;var v=$({},f);v.params=$({},f.params);var p=f.anonymous||!1,m=t.contact.toString({anonymous:p,outbound:p?!t.contact.tempGruu:!t.contact.pubGruu});p&&t.configuration.uri&&(v.params.fromDisplayName="Anonymous",v.params.fromUri="sip:anonymous@anonymous.invalid");var b=t.userAgentCore.configuration.aor;if(v.params.fromUri&&(b="string"==typeof v.params.fromUri?He.URIParse(v.params.fromUri):v.params.fromUri),!b)throw new TypeError("Invalid from URI: "+v.params.fromUri);var w=i;if(v.params.toUri&&(w="string"==typeof v.params.toUri?He.URIParse(v.params.toUri):v.params.toUri),!w)throw new TypeError("Invalid to URI: "+v.params.toUri);var y=$({},v.params);y.fromTag=c.fromTag;var k=g(r=v.extraHeaders||[]).call(r);p&&t.configuration.uri&&(k.push("P-Preferred-Identity: "+t.configuration.uri.toString()),k.push("Privacy: id")),k.push("Contact: "+m),k.push("Allow: "+["ACK","CANCEL","INVITE","MESSAGE","BYE","OPTIONS","INFO","NOTIFY","REFER"].toString()),t.configuration.sipExtension100rel===ft.Required&&k.push("Require: 100rel"),t.configuration.sipExtensionReplaces===ft.Required&&k.push("Require: replaces"),v.extraHeaders=k;return c.outgoingRequestMessage=t.userAgentCore.makeOutgoingRequestMessage(st.INVITE,i,b,w,y,k,undefined),c._contact=m,c._referralInviterOptions=v,c._renderbody=f.renderbody,c._rendertype=f.rendertype,f.sessionDescriptionHandlerModifiers&&(c.sessionDescriptionHandlerModifiers=f.sessionDescriptionHandlerModifiers),f.sessionDescriptionHandlerOptions&&(c.sessionDescriptionHandlerOptions=f.sessionDescriptionHandlerOptions),f.sessionDescriptionHandlerModifiersReInvite&&(c.sessionDescriptionHandlerModifiersReInvite=f.sessionDescriptionHandlerModifiersReInvite),f.sessionDescriptionHandlerOptionsReInvite&&(c.sessionDescriptionHandlerOptionsReInvite=f.sessionDescriptionHandlerOptionsReInvite),c._id=c.outgoingRequestMessage.callId+c.fromTag,c.userAgent._sessions[c._id]=c,c}return c(n,vt),t(n,[{key:"dispose",value:function(){var e=this;if(this.disposed)return i.resolve();switch(this.disposed=!0,this.disposeEarlyMedia(),this.state){case ot.Initial:case ot.Establishing:return this.cancel().then(function(){return kt(n,"dispose",e,3)([])});case ot.Established:case ot.Terminating:case ot.Terminated:return kt(n,"dispose",this,3)([]);default:throw new Error("Unknown state.")}}},{key:"body",get:function(){return this.outgoingRequestMessage.body}},{key:"localIdentity",get:function(){return this.outgoingRequestMessage.from}},{key:"remoteIdentity",get:function(){return this.outgoingRequestMessage.to}},{key:"request",get:function(){return this.outgoingRequestMessage}},{key:"cancel",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("Inviter.cancel"),this.state!==ot.Initial&&this.state!==ot.Establishing){var n=new Error("Invalid session state ".concat(this.state));return this.logger.error(n.message),i.reject(n)}(this.isCanceled=!0,this.stateTransition(ot.Terminating),this.outgoingInviteRequest)?(t.statusCode&&t.reasonPhrase&&(e=function(e,t){if(e&&e<200||e>699)throw new TypeError("Invalid statusCode: "+e);if(e)return"SIP;cause="+e+';text="'+(Me(e)||t)+'"'}(t.statusCode,t.reasonPhrase)),this.outgoingInviteRequest.cancel(e,t)):(this.logger.warn("Canceled session before INVITE was sent"),this.stateTransition(ot.Terminated));return i.resolve()}},{key:"invite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("Inviter.invite"),this.state!==ot.Initial)return kt(n,"invite",this,3)([t]);if(t.sessionDescriptionHandlerModifiers&&(this.sessionDescriptionHandlerModifiers=t.sessionDescriptionHandlerModifiers),t.sessionDescriptionHandlerOptions&&(this.sessionDescriptionHandlerOptions=t.sessionDescriptionHandlerOptions),t.withoutSdp||this.inviteWithoutSdp)return this._renderbody&&this._rendertype&&(this.outgoingRequestMessage.body={contentType:this._rendertype,body:this._renderbody}),this.stateTransition(ot.Establishing),i.resolve(this.sendInvite(t));var r={sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers,sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions};return this.getOffer(r).then(function(n){return e.outgoingRequestMessage.body={body:n.content,contentType:n.contentType},e.stateTransition(ot.Establishing),e.sendInvite(t)}).catch(function(t){throw e.logger.log(t.message),e.state!==ot.Terminated&&e.stateTransition(ot.Terminated),t})}},{key:"sendInvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.outgoingInviteRequest=this.userAgent.userAgentCore.invite(this.outgoingRequestMessage,{onAccept:function(n){return e.dialog?(e.logger.log("Additional confirmed dialog, sending ACK and BYE"),void e.ackAndBye(n)):e.isCanceled?(e.logger.log("Canceled session accepted, sending ACK and BYE"),e.ackAndBye(n),void e.stateTransition(ot.Terminated)):(e.notifyReferer(n),void e.onAccept(n).then(function(){e.disposeEarlyMedia()}).catch(function(){e.disposeEarlyMedia()}).then(function(){t.requestDelegate&&t.requestDelegate.onAccept&&t.requestDelegate.onAccept(n)}))},onProgress:function(n){e.isCanceled||(e.notifyReferer(n),e.onProgress(n).catch(function(){e.disposeEarlyMedia()}).then(function(){t.requestDelegate&&t.requestDelegate.onProgress&&t.requestDelegate.onProgress(n)}))},onRedirect:function(n){e.notifyReferer(n),e.onRedirect(n),t.requestDelegate&&t.requestDelegate.onRedirect&&t.requestDelegate.onRedirect(n)},onReject:function(n){e.notifyReferer(n),e.onReject(n),t.requestDelegate&&t.requestDelegate.onReject&&t.requestDelegate.onReject(n)},onTrying:function(n){e.notifyReferer(n),e.onTrying(n),t.requestDelegate&&t.requestDelegate.onTrying&&t.requestDelegate.onTrying(n)}}),this.outgoingInviteRequest}},{key:"disposeEarlyMedia",value:function(){var e;h(e=this.earlyMediaSessionDescriptionHandlers).call(e,function(e){e.close()}),this.earlyMediaSessionDescriptionHandlers.clear()}},{key:"notifyReferer",value:function(e){var t,n,i=this;if(this._referred){if(!(this._referred instanceof vt))throw new Error("Referred session not instance of session");if(this._referred.dialog){if(!e.message.statusCode)throw new Error("Status code undefined.");if(!e.message.reasonPhrase)throw new Error("Reason phrase undefined.");var r=e.message.statusCode,s=e.message.reasonPhrase,a=R(t=E(n="SIP/2.0 ".concat(r," ")).call(n,s)).call(t);this._referred.dialog.notify(void 0,{extraHeaders:["Event: refer","Subscription-State: terminated"],body:{contentDisposition:"render",contentType:"message/sipfrag",content:a}}).delegate={onReject:function(){i._referred=void 0}}}}}},{key:"onAccept",value:function(e){var t=this;if(this.logger.log("Inviter.onAccept"),this.state!==ot.Establishing)return this.logger.error("Accept received while in state ".concat(this.state,", dropping response")),i.reject(new Error("Invalid session state ".concat(this.state)));var n=e.message,r=e.session;switch(n.hasHeader("P-Asserted-Identity")&&(this._assertedIdentity=He.nameAddrHeaderParse(n.getHeader("P-Asserted-Identity"))),r.delegate={onAck:function(e){return t.onAckRequest(e)},onBye:function(e){return t.onByeRequest(e)},onInfo:function(e){return t.onInfoRequest(e)},onInvite:function(e){return t.onInviteRequest(e)},onMessage:function(e){return t.onMessageRequest(e)},onNotify:function(e){return t.onNotifyRequest(e)},onPrack:function(e){return t.onPrackRequest(e)},onRefer:function(e){return t.onReferRequest(e)}},this._dialog=r,r.signalingState){case ze.Initial:case ze.HaveLocalOffer:return this.logger.error("Received 2xx response to INVITE without a session description"),this.ackAndBye(e,400,"Missing session description"),this.stateTransition(ot.Terminated),i.reject(new Error("Bad Media Description"));case ze.HaveRemoteOffer:if(!this._dialog.offer)throw new Error("Session offer undefined in signaling state ".concat(this._dialog.signalingState,"."));var s={sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers,sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions};return this.setOfferAndGetAnswer(this._dialog.offer,s).then(function(n){e.ack({body:n}),t.stateTransition(ot.Established)}).catch(function(n){throw t.ackAndBye(e,488,"Invalid session description"),t.stateTransition(ot.Terminated),n});case ze.Stable:if(this.earlyMediaSessionDescriptionHandlers.size>0){var a=this.earlyMediaSessionDescriptionHandlers.get(r.id);if(!a)throw new Error("Session description handler undefined.");return this.setSessionDescriptionHandler(a),this.earlyMediaSessionDescriptionHandlers.delete(r.id),e.ack(),this.stateTransition(ot.Established),i.resolve()}if(this.earlyMediaDialog){if(this.earlyMediaDialog!==r){if(this.earlyMedia){this.logger.error("You have set the 'earlyMedia' option to 'true' which requires that your INVITE requests do not fork and yet this INVITE request did in fact fork. Consequentially and not surprisingly the end point which accepted the INVITE (confirmed dialog) does not match the end point with which early media has been setup (early dialog) and thus this session is unable to proceed. In accordance with the SIP specifications, the SIP servers your end point is connected to determine if an INVITE forks and the forking behavior of those servers cannot be controlled by this library. If you wish to use early media with this library you must configure those servers accordingly. Alternatively you may set the 'earlyMedia' to 'false' which will allow this library to function with any INVITE requests which do fork.")}var o=new Error("Early media dialog does not equal confirmed dialog, terminating session");return this.logger.error(o.message),this.ackAndBye(e,488,"Not Acceptable Here"),this.stateTransition(ot.Terminated),i.reject(o)}return e.ack(),this.stateTransition(ot.Established),i.resolve()}var c=r.answer;if(!c)throw new Error("Answer is undefined.");var l={sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers,sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions};return this.setAnswer(c,l).then(function(){var n;t._renderbody&&t._rendertype&&(n={body:{contentDisposition:"render",contentType:t._rendertype,content:t._renderbody}}),e.ack(n),t.stateTransition(ot.Established)}).catch(function(n){throw t.logger.error(n.message),t.ackAndBye(e,488,"Not Acceptable Here"),t.stateTransition(ot.Terminated),n});case ze.Closed:return i.reject(new Error("Terminated."));default:throw new Error("Unknown session signaling state.")}}},{key:"onProgress",value:function(e){var t,n=this;if(this.logger.log("Inviter.onProgress"),this.state!==ot.Establishing)return this.logger.error("Progress received while in state ".concat(this.state,", dropping response")),i.reject(new Error("Invalid session state ".concat(this.state)));if(!this.outgoingInviteRequest)throw new Error("Outgoing INVITE request undefined.");var r=e.message,s=e.session;r.hasHeader("P-Asserted-Identity")&&(this._assertedIdentity=He.nameAddrHeaderParse(r.getHeader("P-Asserted-Identity")));var a=r.getHeader("require"),o=r.getHeader("rseq"),c=!!(a&&p(a).call(a,"100rel")&&o?Number(o):void 0),l=[];switch(c&&l.push("RAck: "+r.getHeader("rseq")+" "+r.getHeader("cseq")),s.signalingState){case ze.Initial:return c&&(this.logger.warn("First reliable provisional response received MUST contain an offer when INVITE does not contain an offer."),e.prack({extraHeaders:l})),i.resolve();case ze.HaveLocalOffer:return c&&e.prack({extraHeaders:l}),i.resolve();case ze.HaveRemoteOffer:if(!c)return this.logger.warn("Non-reliable provisional response MUST NOT contain an initial offer, discarding response."),i.resolve();var u=this.sessionDescriptionHandlerFactory(this,this.userAgent.configuration.sessionDescriptionHandlerFactoryOptions||{});return(null===(t=this.delegate)||void 0===t?void 0:t.onSessionDescriptionHandler)&&this.delegate.onSessionDescriptionHandler(u,!0),this.earlyMediaSessionDescriptionHandlers.set(s.id,u),u.setDescription(r.body,this.sessionDescriptionHandlerOptions,this.sessionDescriptionHandlerModifiers).then(function(){return u.getDescription(n.sessionDescriptionHandlerOptions,n.sessionDescriptionHandlerModifiers)}).then(function(t){var n={contentDisposition:"session",contentType:t.contentType,content:t.body};e.prack({extraHeaders:l,body:n})}).catch(function(e){throw n.stateTransition(ot.Terminated),e});case ze.Stable:if(c&&e.prack({extraHeaders:l}),this.earlyMedia&&!this.earlyMediaDialog){this.earlyMediaDialog=s;var d=s.answer;if(!d)throw new Error("Answer is undefined.");var h={sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers,sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions};return this.setAnswer(d,h).catch(function(e){throw n.stateTransition(ot.Terminated),e})}return i.resolve();case ze.Closed:return i.reject(new Error("Terminated."));default:throw new Error("Unknown session signaling state.")}}},{key:"onRedirect",value:function(e){this.logger.log("Inviter.onRedirect"),this.state===ot.Establishing||this.state===ot.Terminating?this.stateTransition(ot.Terminated):this.logger.error("Redirect received while in state ".concat(this.state,", dropping response"))}},{key:"onReject",value:function(e){this.logger.log("Inviter.onReject"),this.state===ot.Establishing||this.state===ot.Terminating?this.stateTransition(ot.Terminated):this.logger.error("Reject received while in state ".concat(this.state,", dropping response"))}},{key:"onTrying",value:function(e){this.logger.log("Inviter.onTrying"),this.state===ot.Establishing||this.logger.error("Trying received while in state ".concat(this.state,", dropping response"))}}])}(),It=function(){return t(function t(n,i,r){var s,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"text/plain",o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};e(this,t),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"userAgent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.logger=n.getLogger("sip.Messager"),o.params=o.params||{};var c=n.userAgentCore.configuration.aor;if(o.params.fromUri&&(c="string"==typeof o.params.fromUri?He.URIParse(o.params.fromUri):o.params.fromUri),!c)throw new TypeError("Invalid from URI: "+o.params.fromUri);var l=i;if(o.params.toUri&&(l="string"==typeof o.params.toUri?He.URIParse(o.params.toUri):o.params.toUri),!l)throw new TypeError("Invalid to URI: "+o.params.toUri);var u=o.params?$({},o.params):{},h=g(s=o.extraHeaders||[]).call(s),f={contentDisposition:"render",contentType:a,content:r};this.request=n.userAgentCore.makeOutgoingRequestMessage(st.MESSAGE,i,c,l,u,h,f),this.userAgent=n},[{key:"message",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.userAgent.userAgentCore.request(this.request,e.requestDelegate),i.resolve()}}])}();!function(e){e.Initial="Initial",e.Published="Published",e.Unpublished="Unpublished",e.Terminated="Terminated"}(Tt||(Tt={})),function(e){e.Initial="Initial",e.Registered="Registered",e.Unregistered="Unregistered",e.Terminated="Terminated"}(Rt||(Rt={}));var Et,Ct,At,xt,Dt=function(){function n(t){var i,r,s,a=this,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,n),d(this,"disposed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"expires",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"refreshFrequency",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"userAgent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"registrationExpiredTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"registrationTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_contacts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),d(this,"_retryAfter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:Rt.Initial}),d(this,"_stateEventEmitter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_waiting",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"_waitingEventEmitter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._stateEventEmitter=new ye,this._waitingEventEmitter=new ye,this.userAgent=t;var c=t.configuration.uri.clone();if(c.user=void 0,this.options=$($($({},n.defaultOptions()),{registrar:c}),n.stripUndefinedProperties(o)),this.options.extraContactHeaderParams=g(i=this.options.extraContactHeaderParams||[]).call(i),this.options.extraHeaders=g(r=this.options.extraHeaders||[]).call(r),!this.options.registrar)throw new Error("Registrar undefined.");if(this.options.registrar=this.options.registrar.clone(),this.options.regId&&!this.options.instanceId?this.options.instanceId=this.userAgent.instanceId:!this.options.regId&&this.options.instanceId&&(this.options.regId=1),this.options.instanceId&&-1===He.parse(this.options.instanceId,"uuid"))throw new Error("Invalid instanceId.");if(this.options.regId&&this.options.regId<0)throw new Error("Invalid regId.");var l,u=this.options.registrar,f=this.options.params&&this.options.params.fromUri||t.userAgentCore.configuration.aor,v=this.options.params&&this.options.params.toUri||t.configuration.uri,p=this.options.params||{},m=g(s=o.extraHeaders||[]).call(s);if(this.request=t.userAgentCore.makeOutgoingRequestMessage(st.REGISTER,u,f,v,p,m,void 0),this.expires=this.options.expires||n.defaultExpires,this.expires<0)throw new Error("Invalid expires.");if(this.refreshFrequency=this.options.refreshFrequency||n.defaultRefreshFrequency,this.refreshFrequency<50||this.refreshFrequency>99)throw new Error("Invalid refresh frequency. The value represents a percentage of the expiration time and should be between 50 and 99.");(this.logger=t.getLogger("sip.Registerer"),this.options.logConfiguration)&&(this.logger.log("Configuration:"),h(l=A(this.options)).call(l,function(e){var t=a.options[e];if("registrar"===e)a.logger.log("· "+e+": "+t);else a.logger.log("· "+e+": "+C(t))}));this.id=this.request.callId+this.request.from.parameters.tag,this.userAgent._registerers[this.id]=this}return t(n,[{key:"contacts",get:function(){var e;return g(e=this._contacts).call(e)}},{key:"retryAfter",get:function(){return this._retryAfter}},{key:"state",get:function(){return this._state}},{key:"stateChange",get:function(){return this._stateEventEmitter}},{key:"dispose",value:function(){var e,t=this;return this.disposed?i.resolve():(this.disposed=!0,this.logger.log(E(e="Registerer ".concat(this.id," in state ")).call(e,this.state," is being disposed")),delete this.userAgent._registerers[this.id],new i(function(e){var n=function(){if(!t.waiting&&t._state===Rt.Registered)return t.stateChange.addListener(function(){t.terminated(),e()},{once:!0}),void t.unregister();t.terminated(),e()};t.waiting?t.waitingChange.addListener(function(){n()},{once:!0}):n()}))}},{key:"register",value:function(){var e,t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.state===Rt.Terminated)throw this.stateError(),new Error("Registerer terminated. Unable to register.");if(this.disposed)throw this.stateError(),new Error("Registerer disposed. Unable to register.");if(this.waiting){this.waitingWarning();var r=new ue("REGISTER request already in progress, waiting for final response");return i.reject(r)}n.requestOptions&&(this.options=$($({},this.options),n.requestOptions));var s=g(e=this.options.extraHeaders||[]).call(e);s.push("Contact: "+this.generateContactHeader(this.expires)),s.push("Allow: "+["ACK","CANCEL","INVITE","MESSAGE","BYE","OPTIONS","INFO","NOTIFY","REFER"].toString()),this.request.cseq++,this.request.setHeader("cseq",this.request.cseq+" REGISTER"),this.request.extraHeaders=s,this.waitingToggle(!0);var a=this.userAgent.userAgentCore.register(this.request,{onAccept:function(e){var i;e.message.hasHeader("expires")&&(i=Number(e.message.getHeader("expires"))),t._contacts=e.message.getHeaders("contact");var r,s=t._contacts.length;if(!s)return t.logger.error("No Contact header in response to REGISTER, dropping response."),void t.unregistered();for(;s--;){if(!(r=e.message.parseHeader("contact",s)))throw new Error("Contact undefined");if(t.userAgent.contact.pubGruu&&Ce(r.uri,t.userAgent.contact.pubGruu)){i=Number(r.getParam("expires"));break}if(""===t.userAgent.configuration.contactName){if(r.uri.user===t.userAgent.contact.uri.user){i=Number(r.getParam("expires"));break}}else if(Ce(r.uri,t.userAgent.contact.uri)){i=Number(r.getParam("expires"));break}r=void 0}if(void 0===r)return t.logger.error("No Contact header pointing to us, dropping response"),t.unregistered(),void t.waitingToggle(!1);if(void 0===i)return t.logger.error("Contact pointing to us is missing expires parameter, dropping response"),t.unregistered(),void t.waitingToggle(!1);if(r.hasParam("temp-gruu")){var a=r.getParam("temp-gruu");a&&(t.userAgent.contact.tempGruu=He.URIParse(a.replace(/"/g,"")))}if(r.hasParam("pub-gruu")){var o=r.getParam("pub-gruu");o&&(t.userAgent.contact.pubGruu=He.URIParse(o.replace(/"/g,"")))}t.registered(i),n.requestDelegate&&n.requestDelegate.onAccept&&n.requestDelegate.onAccept(e),t.waitingToggle(!1)},onProgress:function(e){n.requestDelegate&&n.requestDelegate.onProgress&&n.requestDelegate.onProgress(e)},onRedirect:function(e){t.logger.error("Redirect received. Not supported."),t.unregistered(),n.requestDelegate&&n.requestDelegate.onRedirect&&n.requestDelegate.onRedirect(e),t.waitingToggle(!1)},onReject:function(e){if(423===e.message.statusCode)return e.message.hasHeader("min-expires")?(t.expires=Number(e.message.getHeader("min-expires")),t.waitingToggle(!1),void t.register()):(t.logger.error("423 response received for REGISTER without Min-Expires, dropping response"),t.unregistered(),void t.waitingToggle(!1));t.logger.warn("Failed to register, status code ".concat(e.message.statusCode));var i=NaN;if(500===e.message.statusCode||503===e.message.statusCode){var r=e.message.getHeader("retry-after");r&&(i=P(r,void 0))}t._retryAfter=isNaN(i)?void 0:i,t.unregistered(),n.requestDelegate&&n.requestDelegate.onReject&&n.requestDelegate.onReject(e),t._retryAfter=void 0,t.waitingToggle(!1)},onTrying:function(e){n.requestDelegate&&n.requestDelegate.onTrying&&n.requestDelegate.onTrying(e)}});return i.resolve(a)}},{key:"unregister",value:function(){var e,t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.state===Rt.Terminated)throw this.stateError(),new Error("Registerer terminated. Unable to register.");if(this.disposed&&this.state!==Rt.Registered)throw this.stateError(),new Error("Registerer disposed. Unable to register.");if(this.waiting){this.waitingWarning();var r=new ue("REGISTER request already in progress, waiting for final response");return i.reject(r)}this._state===Rt.Registered||n.all||this.logger.warn("Not currently registered, but sending an unregister anyway.");var s=g(e=n.requestOptions&&n.requestOptions.extraHeaders||[]).call(e);this.request.extraHeaders=s,n.all?(s.push("Contact: *"),s.push("Expires: 0")):s.push("Contact: "+this.generateContactHeader(0)),this.request.cseq++,this.request.setHeader("cseq",this.request.cseq+" REGISTER"),void 0!==this.registrationTimer&&(clearTimeout(this.registrationTimer),this.registrationTimer=void 0),this.waitingToggle(!0);var a=this.userAgent.userAgentCore.register(this.request,{onAccept:function(e){t._contacts=e.message.getHeaders("contact"),t.unregistered(),n.requestDelegate&&n.requestDelegate.onAccept&&n.requestDelegate.onAccept(e),t.waitingToggle(!1)},onProgress:function(e){n.requestDelegate&&n.requestDelegate.onProgress&&n.requestDelegate.onProgress(e)},onRedirect:function(e){t.logger.error("Unregister redirected. Not currently supported."),t.unregistered(),n.requestDelegate&&n.requestDelegate.onRedirect&&n.requestDelegate.onRedirect(e),t.waitingToggle(!1)},onReject:function(e){t.logger.error("Unregister rejected with status code ".concat(e.message.statusCode)),t.unregistered(),n.requestDelegate&&n.requestDelegate.onReject&&n.requestDelegate.onReject(e),t.waitingToggle(!1)},onTrying:function(e){n.requestDelegate&&n.requestDelegate.onTrying&&n.requestDelegate.onTrying(e)}});return i.resolve(a)}},{key:"clearTimers",value:function(){void 0!==this.registrationTimer&&(clearTimeout(this.registrationTimer),this.registrationTimer=void 0),void 0!==this.registrationExpiredTimer&&(clearTimeout(this.registrationExpiredTimer),this.registrationExpiredTimer=void 0)}},{key:"generateContactHeader",value:function(e){var t,n=this.userAgent.contact.toString({register:!0});(this.options.regId&&this.options.instanceId&&(n+=";reg-id="+this.options.regId,n+=';+sip.instance="<urn:uuid:'+this.options.instanceId+'>"'),this.options.extraContactHeaderParams)&&h(t=this.options.extraContactHeaderParams).call(t,function(e){n+=";"+e});return n+=";expires="+e}},{key:"registered",value:function(e){var t=this;this.clearTimers(),this.registrationTimer=m(function(){t.registrationTimer=void 0,t.register()},this.refreshFrequency/100*e*1e3),this.registrationExpiredTimer=m(function(){t.logger.warn("Registration expired"),t.unregistered()},1e3*e),this._state!==Rt.Registered&&this.stateTransition(Rt.Registered)}},{key:"unregistered",value:function(){this.clearTimers(),this._state!==Rt.Unregistered&&this.stateTransition(Rt.Unregistered)}},{key:"terminated",value:function(){this.clearTimers(),this._state!==Rt.Terminated&&this.stateTransition(Rt.Terminated)}},{key:"stateTransition",value:function(e){var t=this,n=function(){var n;throw new Error(E(n="Invalid state transition from ".concat(t._state," to ")).call(n,e))};switch(this._state){case Rt.Initial:e!==Rt.Registered&&e!==Rt.Unregistered&&e!==Rt.Terminated&&n();break;case Rt.Registered:e!==Rt.Unregistered&&e!==Rt.Terminated&&n();break;case Rt.Unregistered:e!==Rt.Registered&&e!==Rt.Terminated&&n();break;case Rt.Terminated:n();break;default:throw new Error("Unrecognized state.")}this._state=e,this.logger.log("Registration transitioned to state ".concat(this._state)),this._stateEventEmitter.emit(this._state),e===Rt.Terminated&&this.dispose()}},{key:"waiting",get:function(){return this._waiting}},{key:"waitingChange",get:function(){return this._waitingEventEmitter}},{key:"waitingToggle",value:function(e){var t;if(this._waiting===e)throw new Error(E(t="Invalid waiting transition from ".concat(this._waiting," to ")).call(t,e));this._waiting=e,this.logger.log("Waiting toggled to ".concat(this._waiting)),this._waitingEventEmitter.emit(this._waiting)}},{key:"waitingWarning",value:function(){this.logger.warn("An attempt was made to send a REGISTER request while a prior one was still in progress. RFC 3261 requires UAs MUST NOT send a new registration until they have received a final response from the registrar for the previous one or the previous REGISTER request has timed out. Note that if the transport disconnects, you still must wait for the prior request to time out before sending a new REGISTER request or alternatively dispose of the current Registerer and create a new Registerer.")}},{key:"stateError",value:function(){var e=this.state===Rt.Terminated?"is in 'Terminated' state":"has been disposed",t="An attempt was made to send a REGISTER request when the Registerer ".concat(e,".");t+=" The Registerer transitions to 'Terminated' when Registerer.dispose() is called.",t+=" Perhaps you called UserAgent.stop() which dipsoses of all Registerers?",this.logger.error(t)}}],[{key:"defaultOptions",value:function(){return{expires:n.defaultExpires,extraContactHeaderParams:[],extraHeaders:[],logConfiguration:!0,instanceId:"",params:{},regId:0,registrar:new Ee("sip","anonymous","anonymous.invalid"),refreshFrequency:n.defaultRefreshFrequency}}},{key:"stripUndefinedProperties",value:function(e){var t;return O(t=A(e)).call(t,function(t,n){return void 0!==e[n]&&(t[n]=e[n]),t},{})}}])}();d(Dt,"defaultExpires",{enumerable:!0,configurable:!0,writable:!0,value:600}),d(Dt,"defaultRefreshFrequency",{enumerable:!0,configurable:!0,writable:!0,value:99}),function(e){e.Initial="Initial",e.NotifyWait="NotifyWait",e.Pending="Pending",e.Active="Active",e.Terminated="Terminated"}(Et||(Et={})),function(e){e.Initial="Initial",e.NotifyWait="NotifyWait",e.Subscribed="Subscribed",e.Terminated="Terminated"}(Ct||(Ct={})),function(e){e.Connecting="Connecting",e.Connected="Connected",e.Disconnecting="Disconnecting",e.Disconnected="Disconnected"}(At||(At={})),function(e){e.Started="Started",e.Stopped="Stopped"}(xt||(xt={}));var Ht=function(){function n(){e(this,n),d(this,"_dataLength",{enumerable:!0,configurable:!0,writable:!0,value:0}),d(this,"_bufferLength",{enumerable:!0,configurable:!0,writable:!0,value:0}),d(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:new Int32Array(4)}),d(this,"_buffer",{enumerable:!0,configurable:!0,writable:!0,value:new ArrayBuffer(68)}),d(this,"_buffer8",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_buffer32",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._buffer8=new Uint8Array(this._buffer,0,68),this._buffer32=new Uint32Array(this._buffer,0,17),this.start()}return t(n,[{key:"start",value:function(){return this._dataLength=0,this._bufferLength=0,this._state.set(n.stateIdentity),this}},{key:"appendStr",value:function(e){var t,i,r=this._buffer8,s=this._buffer32,a=this._bufferLength;for(i=0;i<e.length;i+=1){if((t=e.charCodeAt(i))<128)r[a++]=t;else if(t<2048)r[a++]=(t>>>6)+192,r[a++]=63&t|128;else if(t<55296||t>56319)r[a++]=(t>>>12)+224,r[a++]=t>>>6&63|128,r[a++]=63&t|128;else{if((t=1024*(t-55296)+(e.charCodeAt(++i)-56320)+65536)>1114111)throw new Error("Unicode standard supports code points up to U+10FFFF");r[a++]=(t>>>18)+240,r[a++]=t>>>12&63|128,r[a++]=t>>>6&63|128,r[a++]=63&t|128}a>=64&&(this._dataLength+=64,n._md5cycle(this._state,s),a-=64,s[0]=s[16])}return this._bufferLength=a,this}},{key:"appendAsciiStr",value:function(e){for(var t,i=this._buffer8,r=this._buffer32,s=this._bufferLength,a=0;;){for(t=Math.min(e.length-a,64-s);t--;)i[s++]=e.charCodeAt(a++);if(s<64)break;this._dataLength+=64,n._md5cycle(this._state,r),s=0}return this._bufferLength=s,this}},{key:"appendByteArray",value:function(e){for(var t,i=this._buffer8,r=this._buffer32,s=this._bufferLength,a=0;;){for(t=Math.min(e.length-a,64-s);t--;)i[s++]=e[a++];if(s<64)break;this._dataLength+=64,n._md5cycle(this._state,r),s=0}return this._bufferLength=s,this}},{key:"getState",value:function(){var e=this,t=e._state;return{buffer:String.fromCharCode.apply(null,e._buffer8),buflen:e._bufferLength,length:e._dataLength,state:[t[0],t[1],t[2],t[3]]}}},{key:"setState",value:function(e){var t,n=e.buffer,i=e.state,r=this._state;for(this._dataLength=e.length,this._bufferLength=e.buflen,r[0]=i[0],r[1]=i[1],r[2]=i[2],r[3]=i[3],t=0;t<n.length;t+=1)this._buffer8[t]=n.charCodeAt(t)}},{key:"end",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],i=this._bufferLength,r=this._buffer8,s=this._buffer32,a=1+(i>>2);if(this._dataLength+=i,r[i]=128,r[i+1]=r[i+2]=r[i+3]=0,s.set(n.buffer32Identity.subarray(a),a),i>55&&(n._md5cycle(this._state,s),s.set(n.buffer32Identity)),(e=8*this._dataLength)<=4294967295)s[14]=e;else{var o=e.toString(16).match(/(.*?)(.{0,8})$/);if(null===o)return;var c=T(o[2],16),l=T(o[1],16)||0;s[14]=c,s[15]=l}return n._md5cycle(this._state,s),t?this._state:n._hex(this._state)}}],[{key:"hashStr",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.onePassHasher.start().appendStr(e).end(t)}},{key:"hashAsciiStr",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.onePassHasher.start().appendAsciiStr(e).end(t)}},{key:"_hex",value:function(e){var t,i,r,s,a=n.hexChars,o=n.hexOut;for(s=0;s<4;s+=1)for(i=8*s,t=e[s],r=0;r<8;r+=2)o[i+1+r]=a.charAt(15&t),t>>>=4,o[i+0+r]=a.charAt(15&t),t>>>=4;return o.join("")}},{key:"_md5cycle",value:function(e,t){var n=e[0],i=e[1],r=e[2],s=e[3];i=((i+=((r=((r+=((s=((s+=((n=((n+=(i&r|~i&s)+t[0]-680876936|0)<<7|n>>>25)+i|0)&i|~n&r)+t[1]-389564586|0)<<12|s>>>20)+n|0)&n|~s&i)+t[2]+606105819|0)<<17|r>>>15)+s|0)&s|~r&n)+t[3]-1044525330|0)<<22|i>>>10)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i&r|~i&s)+t[4]-176418897|0)<<7|n>>>25)+i|0)&i|~n&r)+t[5]+1200080426|0)<<12|s>>>20)+n|0)&n|~s&i)+t[6]-1473231341|0)<<17|r>>>15)+s|0)&s|~r&n)+t[7]-45705983|0)<<22|i>>>10)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i&r|~i&s)+t[8]+1770035416|0)<<7|n>>>25)+i|0)&i|~n&r)+t[9]-1958414417|0)<<12|s>>>20)+n|0)&n|~s&i)+t[10]-42063|0)<<17|r>>>15)+s|0)&s|~r&n)+t[11]-1990404162|0)<<22|i>>>10)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i&r|~i&s)+t[12]+1804603682|0)<<7|n>>>25)+i|0)&i|~n&r)+t[13]-40341101|0)<<12|s>>>20)+n|0)&n|~s&i)+t[14]-1502002290|0)<<17|r>>>15)+s|0)&s|~r&n)+t[15]+1236535329|0)<<22|i>>>10)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i&s|r&~s)+t[1]-165796510|0)<<5|n>>>27)+i|0)&r|i&~r)+t[6]-1069501632|0)<<9|s>>>23)+n|0)&i|n&~i)+t[11]+643717713|0)<<14|r>>>18)+s|0)&n|s&~n)+t[0]-373897302|0)<<20|i>>>12)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i&s|r&~s)+t[5]-701558691|0)<<5|n>>>27)+i|0)&r|i&~r)+t[10]+38016083|0)<<9|s>>>23)+n|0)&i|n&~i)+t[15]-660478335|0)<<14|r>>>18)+s|0)&n|s&~n)+t[4]-405537848|0)<<20|i>>>12)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i&s|r&~s)+t[9]+568446438|0)<<5|n>>>27)+i|0)&r|i&~r)+t[14]-1019803690|0)<<9|s>>>23)+n|0)&i|n&~i)+t[3]-187363961|0)<<14|r>>>18)+s|0)&n|s&~n)+t[8]+1163531501|0)<<20|i>>>12)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i&s|r&~s)+t[13]-1444681467|0)<<5|n>>>27)+i|0)&r|i&~r)+t[2]-51403784|0)<<9|s>>>23)+n|0)&i|n&~i)+t[7]+1735328473|0)<<14|r>>>18)+s|0)&n|s&~n)+t[12]-1926607734|0)<<20|i>>>12)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i^r^s)+t[5]-378558|0)<<4|n>>>28)+i|0)^i^r)+t[8]-2022574463|0)<<11|s>>>21)+n|0)^n^i)+t[11]+1839030562|0)<<16|r>>>16)+s|0)^s^n)+t[14]-35309556|0)<<23|i>>>9)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i^r^s)+t[1]-1530992060|0)<<4|n>>>28)+i|0)^i^r)+t[4]+1272893353|0)<<11|s>>>21)+n|0)^n^i)+t[7]-155497632|0)<<16|r>>>16)+s|0)^s^n)+t[10]-1094730640|0)<<23|i>>>9)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i^r^s)+t[13]+681279174|0)<<4|n>>>28)+i|0)^i^r)+t[0]-358537222|0)<<11|s>>>21)+n|0)^n^i)+t[3]-722521979|0)<<16|r>>>16)+s|0)^s^n)+t[6]+76029189|0)<<23|i>>>9)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i^r^s)+t[9]-640364487|0)<<4|n>>>28)+i|0)^i^r)+t[12]-421815835|0)<<11|s>>>21)+n|0)^n^i)+t[15]+530742520|0)<<16|r>>>16)+s|0)^s^n)+t[2]-995338651|0)<<23|i>>>9)+r|0,i=((i+=((s=((s+=(i^((n=((n+=(r^(i|~s))+t[0]-198630844|0)<<6|n>>>26)+i|0)|~r))+t[7]+1126891415|0)<<10|s>>>22)+n|0)^((r=((r+=(n^(s|~i))+t[14]-1416354905|0)<<15|r>>>17)+s|0)|~n))+t[5]-57434055|0)<<21|i>>>11)+r|0,i=((i+=((s=((s+=(i^((n=((n+=(r^(i|~s))+t[12]+1700485571|0)<<6|n>>>26)+i|0)|~r))+t[3]-1894986606|0)<<10|s>>>22)+n|0)^((r=((r+=(n^(s|~i))+t[10]-1051523|0)<<15|r>>>17)+s|0)|~n))+t[1]-2054922799|0)<<21|i>>>11)+r|0,i=((i+=((s=((s+=(i^((n=((n+=(r^(i|~s))+t[8]+1873313359|0)<<6|n>>>26)+i|0)|~r))+t[15]-30611744|0)<<10|s>>>22)+n|0)^((r=((r+=(n^(s|~i))+t[6]-1560198380|0)<<15|r>>>17)+s|0)|~n))+t[13]+1309151649|0)<<21|i>>>11)+r|0,i=((i+=((s=((s+=(i^((n=((n+=(r^(i|~s))+t[4]-145523070|0)<<6|n>>>26)+i|0)|~r))+t[11]-1120210379|0)<<10|s>>>22)+n|0)^((r=((r+=(n^(s|~i))+t[2]+718787259|0)<<15|r>>>17)+s|0)|~n))+t[9]-343485551|0)<<21|i>>>11)+r|0,e[0]=n+e[0]|0,e[1]=i+e[1]|0,e[2]=r+e[2]|0,e[3]=s+e[3]|0}}])}();function _t(e){return Ht.hashStr(e)}d(Ht,"stateIdentity",{enumerable:!0,configurable:!0,writable:!0,value:new Int32Array([1732584193,-271733879,-1732584194,271733878])}),d(Ht,"buffer32Identity",{enumerable:!0,configurable:!0,writable:!0,value:new Int32Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])}),d(Ht,"hexChars",{enumerable:!0,configurable:!0,writable:!0,value:"0123456789abcdef"}),d(Ht,"hexOut",{enumerable:!0,configurable:!0,writable:!0,value:[]}),d(Ht,"onePassHasher",{enumerable:!0,configurable:!0,writable:!0,value:new Ht}),"5d41402abc4b2a76b9719d911017c592"!==Ht.hashStr("hello")&&console.error("Md5 self test failed.");var $t,qt=function(){return t(function t(n,i,r,s){e(this,t),d(this,"stale",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"ha1",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"username",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"password",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"cnonce",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"nc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"ncHex",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"response",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"algorithm",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"realm",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"nonce",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"opaque",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"qop",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"method",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"uri",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.logger=n.getLogger("sipjs.digestauthentication"),this.username=r,this.password=s,this.ha1=i,this.nc=0,this.ncHex="00000000"},[{key:"authenticate",value:function(e,t,n){if(this.algorithm=t.algorithm,this.realm=t.realm,this.nonce=t.nonce,this.opaque=t.opaque,this.stale=t.stale,this.algorithm){if("MD5"!==this.algorithm)return this.logger.warn("challenge with Digest algorithm different than 'MD5', authentication aborted"),!1}else this.algorithm="MD5";if(!this.realm)return this.logger.warn("challenge without Digest realm, authentication aborted"),!1;if(!this.nonce)return this.logger.warn("challenge without Digest nonce, authentication aborted"),!1;var i,r;if(t.qop)if(q(i=t.qop).call(i,"auth")>-1)this.qop="auth";else{if(!(q(r=t.qop).call(r,"auth-int")>-1))return this.logger.warn("challenge without Digest qop different than 'auth' or 'auth-int', authentication aborted"),!1;this.qop="auth-int"}else this.qop=void 0;return this.method=e.method,this.uri=e.ruri,this.cnonce=qe(12),this.nc+=1,this.updateNcHex(),4294967296===this.nc&&(this.nc=1,this.ncHex="00000001"),this.calculateResponse(n),!0}},{key:"toString",value:function(){var e=[];if(!this.response)throw new Error("response field does not exist, cannot generate Authorization header");return e.push("algorithm="+this.algorithm),e.push('username="'+this.username+'"'),e.push('realm="'+this.realm+'"'),e.push('nonce="'+this.nonce+'"'),e.push('uri="'+this.uri+'"'),e.push('response="'+this.response+'"'),this.opaque&&e.push('opaque="'+this.opaque+'"'),this.qop&&(e.push("qop="+this.qop),e.push('cnonce="'+this.cnonce+'"'),e.push("nc="+this.ncHex)),"Digest "+e.join(", ")}},{key:"updateNcHex",value:function(){var e=Number(this.nc).toString(16);this.ncHex="00000000".substr(0,8-e.length)+e}},{key:"calculateResponse",value:function(e){var t,n;""!==(t=this.ha1)&&void 0!==t||(t=_t(this.username+":"+this.realm+":"+this.password)),"auth"===this.qop?(n=_t(this.method+":"+this.uri),this.response=_t(t+":"+this.nonce+":"+this.ncHex+":"+this.cnonce+":auth:"+n)):"auth-int"===this.qop?(n=_t(this.method+":"+this.uri+":"+_t(e||"")),this.response=_t(t+":"+this.nonce+":"+this.ncHex+":"+this.cnonce+":auth-int:"+n)):void 0===this.qop&&(n=_t(this.method+":"+this.uri),this.response=_t(t+":"+this.nonce+":"+n))}}])}();!function(e){e[e.error=0]="error",e[e.warn=1]="warn",e[e.log=2]="log",e[e.debug=3]="debug"}($t||($t={}));var Mt,Pt=function(){return t(function t(n,i,r){e(this,t),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"category",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"label",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.logger=n,this.category=i,this.label=r},[{key:"error",value:function(e){this.genericLog($t.error,e)}},{key:"warn",value:function(e){this.genericLog($t.warn,e)}},{key:"log",value:function(e){this.genericLog($t.log,e)}},{key:"debug",value:function(e){this.genericLog($t.debug,e)}},{key:"genericLog",value:function(e,t){this.logger.genericLog(e,this.category,this.label,t)}},{key:"level",get:function(){return this.logger.level},set:function(e){this.logger.level=e}}])}(),Ot=function(){return t(function t(){e(this,t),d(this,"builtinEnabled",{enumerable:!0,configurable:!0,writable:!0,value:!0}),d(this,"_level",{enumerable:!0,configurable:!0,writable:!0,value:$t.log}),d(this,"_connector",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"loggers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.logger=this.getLogger("sip:loggerfactory")},[{key:"level",get:function(){return this._level},set:function(e){e>=0&&e<=3?this._level=e:e>3?this._level=3:$t.hasOwnProperty(e)?this._level=e:this.logger.error("invalid 'level' parameter value: "+C(e))}},{key:"connector",get:function(){return this._connector},set:function(e){e?"function"==typeof e?this._connector=e:this.logger.error("invalid 'connector' parameter value: "+C(e)):this._connector=void 0}},{key:"getLogger",value:function(e,t){if(t&&3===this.level)return new Pt(this,e,t);if(this.loggers[e])return this.loggers[e];var n=new Pt(this,e);return this.loggers[e]=n,n}},{key:"genericLog",value:function(e,t,n,i){this.level>=e&&this.builtinEnabled&&this.print(e,t,n,i),this.connector&&this.connector($t[e],t,n,i)}},{key:"print",value:function(e,t,n,i){if("string"==typeof i){var r=[new Date,t];n&&r.push(n),i=E(r).call(r,i).join(" | ")}switch(e){case $t.error:console.error(i);break;case $t.warn:console.warn(i);break;case $t.log:console.log(i);break;case $t.debug:console.debug(i)}}}])}();function Nt(e,t){var n,i="\r\n";if(t.statusCode<100||t.statusCode>699)throw new TypeError("Invalid statusCode: "+t.statusCode);var r=t.reasonPhrase?t.reasonPhrase:Me(t.statusCode),s="SIP/2.0 "+t.statusCode+" "+r+i;t.statusCode>=100&&t.statusCode,t.statusCode;var a="From: "+e.getHeader("From")+i,o="Call-ID: "+e.callId+i,c="CSeq: "+e.cseq+" "+e.method+i,l=O(n=e.getHeaders("via")).call(n,function(e,t){return e+"Via: "+t+i},""),u="To: "+e.getHeader("to");if(t.statusCode>100&&!e.parseHeader("to").hasParam("tag")){var d=t.toTag;d||(d=Pe()),u+=";tag="+d}u+=i;var h="";t.supported&&(h="Supported: "+t.supported.join(", ")+i);var g="";t.userAgent&&(g="User-Agent: "+t.userAgent+i);var f,v="";t.extraHeaders&&(v=O(f=t.extraHeaders).call(f,function(e,t){return e+R(t).call(t)+i},""));return s+=l,s+=a,s+=u,s+=c,s+=o,s+=h,s+=g,s+=v,t.body?(s+="Content-Type: "+t.body.contentType+i,s+="Content-Length: "+Ne(t.body.content)+i+i,s+=t.body.content):s+="Content-Length: 0\r\n\r\n",{message:s}}function jt(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(jt=function(){return!!e})()}!function(e){function t(e,t){var n=t,i=0,r=0;if(e.substring(n,n+2).match(/(^\r\n)/))return-2;for(;0===i;){if(-1===(r=q(e).call(e,"\r\n",n)))return r;!e.substring(r+2,r+4).match(/(^\r\n)/)&&e.charAt(r+2).match(/(^\s+)/)?n=r+2:i=r}return i}function n(e,t,n,i){var r,s,a,o=q(t).call(t,":",n),c=R(r=t.substring(n,o)).call(r),l=R(s=t.substring(o+1,i)).call(s);switch(c.toLowerCase()){case"via":case"v":e.addHeader("via",l),1===e.getHeaders("via").length?(a=e.parseHeader("Via"))&&(e.via=a,e.viaBranch=a.branch):a=0;break;case"from":case"f":e.setHeader("from",l),(a=e.parseHeader("from"))&&(e.from=a,e.fromTag=a.getParam("tag"));break;case"to":case"t":e.setHeader("to",l),(a=e.parseHeader("to"))&&(e.to=a,e.toTag=a.getParam("tag"));break;case"record-route":if(-1===(a=He.parse(l,"Record_Route"))){a=void 0;break}if(!(a instanceof Array)){a=void 0;break}h(a).call(a,function(t){e.addHeader("record-route",l.substring(t.position,t.offset)),e.headers["Record-Route"][e.getHeaders("record-route").length-1].parsed=t.parsed});break;case"call-id":case"i":e.setHeader("call-id",l),(a=e.parseHeader("call-id"))&&(e.callId=l);break;case"contact":case"m":if(-1===(a=He.parse(l,"Contact"))){a=void 0;break}if(!(a instanceof Array)){a=void 0;break}h(a).call(a,function(t){e.addHeader("contact",l.substring(t.position,t.offset)),e.headers.Contact[e.getHeaders("contact").length-1].parsed=t.parsed});break;case"content-length":case"l":e.setHeader("content-length",l),a=e.parseHeader("content-length");break;case"content-type":case"c":e.setHeader("content-type",l),a=e.parseHeader("content-type");break;case"cseq":e.setHeader("cseq",l),(a=e.parseHeader("cseq"))&&(e.cseq=a.value),e instanceof Ve&&(e.method=a.method);break;case"max-forwards":e.setHeader("max-forwards",l),a=e.parseHeader("max-forwards");break;case"www-authenticate":e.setHeader("www-authenticate",l),a=e.parseHeader("www-authenticate");break;case"proxy-authenticate":e.setHeader("proxy-authenticate",l),a=e.parseHeader("proxy-authenticate");break;case"refer-to":case"r":e.setHeader("refer-to",l),(a=e.parseHeader("refer-to"))&&(e.referTo=a);break;default:e.addHeader(c.toLowerCase(),l),a=0}return void 0!==a||{error:"error parsing header '"+c+"'"}}e.getHeader=t,e.parseHeader=n,e.parseMessage=function(e,i){var r=0,s=q(e).call(e,"\r\n");if(-1!==s){var a,o=e.substring(0,s),c=He.parse(o,"Request_Response");if(-1!==c){var l;for(c.status_code?((a=new Ve).statusCode=c.status_code,a.reasonPhrase=c.reason_phrase):((a=new Le).method=c.method,a.ruri=c.uri),a.data=e,r=s+2;;){if(-2===(s=t(e,r))){l=r+2;break}if(-1===s)return void i.error("malformed message");var u=n(a,e,r,s);if(u&&!0!==u)return void i.error(u.error);r=s+2}return a.hasHeader("content-length")?a.body=e.substr(l,Number(a.getHeader("content-length"))):a.body=e.substring(l),a}i.warn('error parsing first line of SIP message: "'+o+'"')}else i.warn("no CRLF found, not a SIP message, discarded")}}(Mt||(Mt={}));var Ft=function(){function n(t){return e(this,n),i=this,c=[t||"Unspecified transport error."],r=o(r=n),a(i,jt()?s(r,c||[],o(i).constructor):r.apply(i,c));var i,r,c}return c(n,ae),t(n)}(),Ut=function(){return t(function t(n,i,r,s,a){var o;e(this,t),d(this,"_transport",{enumerable:!0,configurable:!0,writable:!0,value:n}),d(this,"_user",{enumerable:!0,configurable:!0,writable:!0,value:i}),d(this,"_id",{enumerable:!0,configurable:!0,writable:!0,value:r}),d(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:s}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"listeners",{enumerable:!0,configurable:!0,writable:!0,value:new Array}),this.logger=i.loggerFactory.getLogger(a,r),this.logger.debug(E(o="Constructing ".concat(this.typeToString()," with id ")).call(o,this.id,"."))},[{key:"dispose",value:function(){var e;this.logger.debug(E(e="Destroyed ".concat(this.typeToString()," with id ")).call(e,this.id,"."))}},{key:"id",get:function(){return this._id}},{key:"kind",get:function(){throw new Error("Invalid kind.")}},{key:"state",get:function(){return this._state}},{key:"transport",get:function(){return this._transport}},{key:"addStateChangeListener",value:function(e,t){var n=this,i=function(){n.removeStateChangeListener(i),e()};!0===(null==t?void 0:t.once)?this.listeners.push(i):this.listeners.push(e)}},{key:"notifyStateChangeListeners",value:function(){var e,t;h(e=g(t=this.listeners).call(t)).call(e,function(e){return e()})}},{key:"removeStateChangeListener",value:function(e){var t;this.listeners=f(t=this.listeners).call(t,function(t){return t!==e})}},{key:"logTransportError",value:function(e,t){var n;this.logger.error(e.message),this.logger.error(E(n="Transport error occurred in ".concat(this.typeToString()," with id ")).call(n,this.id,".")),this.logger.error(t)}},{key:"send",value:function(e){var t=this;return this.transport.send(e).catch(function(e){if(e instanceof Ft)throw t.onTransportError(e),e;var n;throw n=e&&"string"==typeof e.message?new Ft(e.message):new Ft,t.onTransportError(n),n})}},{key:"setState",value:function(e){var t,n;this.logger.debug(E(t=E(n='State change to "'.concat(e,'" on ')).call(n,this.typeToString()," with id ")).call(t,this.id,".")),this._state=e,this._user.onStateChange&&this._user.onStateChange(e),this.notifyStateChangeListeners()}},{key:"typeToString",value:function(){return"UnknownType"}}])}();function Bt(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Bt=function(){return!!e})()}var Lt,Gt=function(){function n(t,i,r,c,l){var u,h,g,f;return e(this,n),h=this,g=n,f=[i,r,t.viaBranch,c,l],g=o(g),u=a(h,Bt()?s(g,f||[],o(h).constructor):g.apply(h,f)),d(u,"_request",{enumerable:!0,configurable:!0,writable:!0,value:t}),d(u,"user",{enumerable:!0,configurable:!0,writable:!0,value:r}),u}return c(n,Ut),t(n,[{key:"request",get:function(){return this._request}}])}();function Vt(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Vt=function(){return!!e})()}!function(e){e.Accepted="Accepted",e.Calling="Calling",e.Completed="Completed",e.Confirmed="Confirmed",e.Proceeding="Proceeding",e.Terminated="Terminated",e.Trying="Trying"}(Lt||(Lt={}));var Wt=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,u=n,h=[t,i,r,Lt.Proceeding,"sip.transaction.ist"],u=o(u),c=a(l,Vt()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"lastFinalResponse",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"lastProvisionalResponse",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"H",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"I",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"L",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"progressExtensionTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c}return c(n,Gt),t(n,[{key:"dispose",value:function(){var e,t,i,r,s;this.stopProgressExtensionTimer(),this.H&&(clearTimeout(this.H),this.H=void 0),this.I&&(clearTimeout(this.I),this.I=void 0),this.L&&(clearTimeout(this.L),this.L=void 0),(e=n,t="dispose",i=this,s=v(o(1&(r=3)?e.prototype:e),t,i),2&r&&"function"==typeof s?function(e){return s.apply(i,e)}:s)([])}},{key:"kind",get:function(){return"ist"}},{key:"receiveRequest",value:function(e){var t,n=this;switch(this.state){case Lt.Proceeding:if(e.method===st.INVITE)return void(this.lastProvisionalResponse&&this.send(this.lastProvisionalResponse).catch(function(e){n.logTransportError(e,"Failed to send retransmission of provisional response.")}));break;case Lt.Accepted:if(e.method===st.INVITE)return;break;case Lt.Completed:if(e.method===st.INVITE){if(!this.lastFinalResponse)throw new Error("Last final response undefined.");return void this.send(this.lastFinalResponse).catch(function(e){n.logTransportError(e,"Failed to send retransmission of final response.")})}if(e.method===st.ACK)return void this.stateTransition(Lt.Confirmed);break;case Lt.Confirmed:case Lt.Terminated:if(e.method===st.INVITE||e.method===st.ACK)return;break;default:throw new Error("Invalid state ".concat(this.state))}var i=E(t="INVITE server transaction received unexpected ".concat(e.method," request while in state ")).call(t,this.state,".");this.logger.warn(i)}},{key:"receiveResponse",value:function(e,t){var n,i=this;if(e<100||e>699)throw new Error("Invalid status code ".concat(e));switch(this.state){case Lt.Proceeding:if(e>=100&&e<=199)return this.lastProvisionalResponse=t,e>100&&this.startProgressExtensionTimer(),void this.send(t).catch(function(e){i.logTransportError(e,"Failed to send 1xx response.")});if(e>=200&&e<=299)return this.lastFinalResponse=t,this.stateTransition(Lt.Accepted),void this.send(t).catch(function(e){i.logTransportError(e,"Failed to send 2xx response.")});if(e>=300&&e<=699)return this.lastFinalResponse=t,this.stateTransition(Lt.Completed),void this.send(t).catch(function(e){i.logTransportError(e,"Failed to send non-2xx final response.")});break;case Lt.Accepted:if(e>=200&&e<=299)return void this.send(t).catch(function(e){i.logTransportError(e,"Failed to send 2xx response.")});break;case Lt.Completed:case Lt.Confirmed:case Lt.Terminated:break;default:throw new Error("Invalid state ".concat(this.state))}var r=E(n="INVITE server transaction received unexpected ".concat(e," response from TU while in state ")).call(n,this.state,".");throw this.logger.error(r),new Error(r)}},{key:"retransmitAcceptedResponse",value:function(){var e=this;this.state===Lt.Accepted&&this.lastFinalResponse&&this.send(this.lastFinalResponse).catch(function(t){e.logTransportError(t,"Failed to send 2xx response.")})}},{key:"onTransportError",value:function(e){this.user.onTransportError&&this.user.onTransportError(e)}},{key:"typeToString",value:function(){return"INVITE server transaction"}},{key:"stateTransition",value:function(e){var t=this,n=function(){var n;throw new Error(E(n="Invalid state transition from ".concat(t.state," to ")).call(n,e))};switch(e){case Lt.Proceeding:n();break;case Lt.Accepted:case Lt.Completed:this.state!==Lt.Proceeding&&n();break;case Lt.Confirmed:this.state!==Lt.Completed&&n();break;case Lt.Terminated:this.state!==Lt.Accepted&&this.state!==Lt.Completed&&this.state!==Lt.Confirmed&&n();break;default:n()}this.stopProgressExtensionTimer(),e===Lt.Accepted&&(this.L=m(function(){return t.timerL()},it.TIMER_L)),e===Lt.Completed&&(this.H=m(function(){return t.timerH()},it.TIMER_H)),e===Lt.Confirmed&&(this.I=m(function(){return t.timerI()},it.TIMER_I)),e===Lt.Terminated&&this.dispose(),this.setState(e)}},{key:"startProgressExtensionTimer",value:function(){var e=this;void 0===this.progressExtensionTimer&&(this.progressExtensionTimer=L(function(){if(e.logger.debug("Progress extension timer expired for INVITE server transaction ".concat(e.id,".")),!e.lastProvisionalResponse)throw new Error("Last provisional response undefined.");e.send(e.lastProvisionalResponse).catch(function(t){e.logTransportError(t,"Failed to send retransmission of provisional response.")})},it.PROVISIONAL_RESPONSE_INTERVAL))}},{key:"stopProgressExtensionTimer",value:function(){void 0!==this.progressExtensionTimer&&(clearInterval(this.progressExtensionTimer),this.progressExtensionTimer=void 0)}},{key:"timerG",value:function(){}},{key:"timerH",value:function(){this.logger.debug("Timer H expired for INVITE server transaction ".concat(this.id,".")),this.state===Lt.Completed&&(this.logger.warn("ACK to negative final response was never received, terminating transaction."),this.stateTransition(Lt.Terminated))}},{key:"timerI",value:function(){this.logger.debug("Timer I expired for INVITE server transaction ".concat(this.id,".")),this.stateTransition(Lt.Terminated)}},{key:"timerL",value:function(){this.logger.debug("Timer L expired for INVITE server transaction ".concat(this.id,".")),this.state===Lt.Accepted&&this.stateTransition(Lt.Terminated)}}])}();function Yt(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Yt=function(){return!!e})()}var Kt=function(){function n(t,i,r,c,l){var u,h,g,f;return e(this,n),h=this,g=n,f=[i,r,n.makeId(t),c,l],g=o(g),u=a(h,Yt()?s(g,f||[],o(h).constructor):g.apply(h,f)),d(u,"_request",{enumerable:!0,configurable:!0,writable:!0,value:t}),d(u,"user",{enumerable:!0,configurable:!0,writable:!0,value:r}),t.setViaHeader(u.id,i.protocol),u}return c(n,Ut),t(n,[{key:"request",get:function(){return this._request}},{key:"onRequestTimeout",value:function(){this.user.onRequestTimeout&&this.user.onRequestTimeout()}}],[{key:"makeId",value:function(e){if("CANCEL"===e.method){if(!e.branch)throw new Error("Outgoing CANCEL request without a branch.");return e.branch}return"z9hG4bK"+Math.floor(1e7*Math.random())}}])}();function zt(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(zt=function(){return!!e})()}var Zt=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,u=n,h=[t,i,r,Lt.Trying,"sip.transaction.nict"],u=o(u),c=a(l,zt()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"F",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"K",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c.F=m(function(){return c.timerF()},it.TIMER_F),c.send(t.toString()).catch(function(e){c.logTransportError(e,"Failed to send initial outgoing request.")}),c}return c(n,Kt),t(n,[{key:"dispose",value:function(){var e,t,i,r,s;this.F&&(clearTimeout(this.F),this.F=void 0),this.K&&(clearTimeout(this.K),this.K=void 0),(e=n,t="dispose",i=this,s=v(o(1&(r=3)?e.prototype:e),t,i),2&r&&"function"==typeof s?function(e){return s.apply(i,e)}:s)([])}},{key:"kind",get:function(){return"nict"}},{key:"receiveResponse",value:function(e){var t,n=e.statusCode;if(!n||n<100||n>699)throw new Error("Invalid status code ".concat(n));switch(this.state){case Lt.Trying:if(n>=100&&n<=199)return this.stateTransition(Lt.Proceeding),void(this.user.receiveResponse&&this.user.receiveResponse(e));if(n>=200&&n<=699)return this.stateTransition(Lt.Completed),408===n?void this.onRequestTimeout():void(this.user.receiveResponse&&this.user.receiveResponse(e));break;case Lt.Proceeding:if(n>=100&&n<=199&&this.user.receiveResponse)return this.user.receiveResponse(e);if(n>=200&&n<=699)return this.stateTransition(Lt.Completed),408===n?void this.onRequestTimeout():void(this.user.receiveResponse&&this.user.receiveResponse(e));break;case Lt.Completed:case Lt.Terminated:return;default:throw new Error("Invalid state ".concat(this.state))}var i=E(t="Non-INVITE client transaction received unexpected ".concat(n," response while in state ")).call(t,this.state,".");this.logger.warn(i)}},{key:"onTransportError",value:function(e){this.user.onTransportError&&this.user.onTransportError(e),this.stateTransition(Lt.Terminated,!0)}},{key:"typeToString",value:function(){return"non-INVITE client transaction"}},{key:"stateTransition",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=function(){var n;throw new Error(E(n="Invalid state transition from ".concat(t.state," to ")).call(n,e))};switch(e){case Lt.Trying:i();break;case Lt.Proceeding:this.state!==Lt.Trying&&i();break;case Lt.Completed:this.state!==Lt.Trying&&this.state!==Lt.Proceeding&&i();break;case Lt.Terminated:this.state!==Lt.Trying&&this.state!==Lt.Proceeding&&this.state!==Lt.Completed&&(n||i());break;default:i()}e===Lt.Completed&&(this.F&&(clearTimeout(this.F),this.F=void 0),this.K=m(function(){return t.timerK()},it.TIMER_K)),e===Lt.Terminated&&this.dispose(),this.setState(e)}},{key:"timerF",value:function(){this.logger.debug("Timer F expired for non-INVITE client transaction ".concat(this.id,".")),this.state!==Lt.Trying&&this.state!==Lt.Proceeding||(this.onRequestTimeout(),this.stateTransition(Lt.Terminated))}},{key:"timerK",value:function(){this.state===Lt.Completed&&this.stateTransition(Lt.Terminated)}}])}(),Jt=function(){return t(function t(n,i){e(this,t),d(this,"core",{enumerable:!0,configurable:!0,writable:!0,value:n}),d(this,"dialogState",{enumerable:!0,configurable:!0,writable:!0,value:i}),this.core.dialogs.set(this.id,this)},[{key:"dispose",value:function(){this.core.dialogs.delete(this.id)}},{key:"id",get:function(){return this.dialogState.id}},{key:"early",get:function(){return this.dialogState.early}},{key:"callId",get:function(){return this.dialogState.callId}},{key:"localTag",get:function(){return this.dialogState.localTag}},{key:"remoteTag",get:function(){return this.dialogState.remoteTag}},{key:"localSequenceNumber",get:function(){return this.dialogState.localSequenceNumber}},{key:"remoteSequenceNumber",get:function(){return this.dialogState.remoteSequenceNumber}},{key:"localURI",get:function(){return this.dialogState.localURI}},{key:"remoteURI",get:function(){return this.dialogState.remoteURI}},{key:"remoteTarget",get:function(){return this.dialogState.remoteTarget}},{key:"routeSet",get:function(){return this.dialogState.routeSet}},{key:"secure",get:function(){return this.dialogState.secure}},{key:"userAgentCore",get:function(){return this.core}},{key:"confirm",value:function(){this.dialogState.early=!1}},{key:"receiveRequest",value:function(e){if(e.method!==st.ACK){if(this.remoteSequenceNumber){if(e.cseq<=this.remoteSequenceNumber)throw new Error("Out of sequence in dialog request. Did you forget to call sequenceGuard()?");this.dialogState.remoteSequenceNumber=e.cseq}this.remoteSequenceNumber||(this.dialogState.remoteSequenceNumber=e.cseq)}}},{key:"recomputeRouteSet",value:function(e){var t;this.dialogState.routeSet=G(t=e.getHeaders("record-route")).call(t)}},{key:"createOutgoingRequestMessage",value:function(e,t){var n,i=this.remoteURI,r=this.remoteTag,s=this.localURI,a=this.localTag,o=this.callId;n=t&&t.cseq?t.cseq:this.dialogState.localSequenceNumber?this.dialogState.localSequenceNumber+=1:this.dialogState.localSequenceNumber=1;var c=this.remoteTarget,l=this.routeSet,u=t&&t.extraHeaders,d=t&&t.body;return this.userAgentCore.makeOutgoingRequestMessage(e,c,s,i,{callId:o,cseq:n,fromTag:a,toTag:r,routeSet:l},u,d)}},{key:"incrementLocalSequenceNumber",value:function(){if(!this.dialogState.localSequenceNumber)throw new Error("Local sequence number undefined.");this.dialogState.localSequenceNumber+=1}},{key:"sequenceGuard",value:function(e){return e.method===st.ACK||(!(this.remoteSequenceNumber&&e.cseq<=this.remoteSequenceNumber)||(this.core.replyStateless(e,{statusCode:500}),!1))}}],[{key:"initialDialogStateForUserAgentClient",value:function(e,t){var n,i=G(n=t.getHeaders("record-route")).call(n),r=t.parseHeader("contact");if(!r)throw new Error("Contact undefined.");if(!(r instanceof Se))throw new Error("Contact not instance of NameAddrHeader.");var s=r.uri,a=e.cseq,o=e.callId,c=e.fromTag,l=t.toTag;if(!o)throw new Error("Call id undefined.");if(!c)throw new Error("From tag undefined.");if(!l)throw new Error("To tag undefined.");if(!e.from)throw new Error("From undefined.");if(!e.to)throw new Error("To undefined.");var u=e.from.uri,d=e.to.uri;if(!t.statusCode)throw new Error("Incoming response status code undefined.");return{id:o+c+l,early:t.statusCode<200,callId:o,localTag:c,remoteTag:l,localSequenceNumber:a,remoteSequenceNumber:undefined,localURI:u,remoteURI:d,remoteTarget:s,routeSet:i,secure:!1}}},{key:"initialDialogStateForUserAgentServer",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=e.getHeaders("record-route"),r=e.parseHeader("contact");if(!r)throw new Error("Contact undefined.");if(!(r instanceof Se))throw new Error("Contact not instance of NameAddrHeader.");var s=r.uri,a=e.cseq,o=e.callId,c=t,l=e.fromTag,u=e.from.uri;return{id:o+c+l,early:n,callId:o,localTag:c,remoteTag:l,localSequenceNumber:undefined,remoteSequenceNumber:a,localURI:e.to.uri,remoteURI:u,remoteTarget:s,routeSet:i,secure:!1}}}])}();function Xt(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Xt=function(){return!!e})()}var Qt=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,u=n,h=[t,i,r,Lt.Calling,"sip.transaction.ict"],u=o(u),c=a(l,Xt()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"B",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"D",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"M",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"ackRetransmissionCache",{enumerable:!0,configurable:!0,writable:!0,value:new M}),c.B=m(function(){return c.timerB()},it.TIMER_B),c.send(t.toString()).catch(function(e){c.logTransportError(e,"Failed to send initial outgoing request.")}),c}return c(n,Kt),t(n,[{key:"dispose",value:function(){var e,t,i,r,s;this.B&&(clearTimeout(this.B),this.B=void 0),this.D&&(clearTimeout(this.D),this.D=void 0),this.M&&(clearTimeout(this.M),this.M=void 0),(e=n,t="dispose",i=this,s=v(o(1&(r=3)?e.prototype:e),t,i),2&r&&"function"==typeof s?function(e){return s.apply(i,e)}:s)([])}},{key:"kind",get:function(){return"ict"}},{key:"ackResponse",value:function(e){var t=this,n=e.toTag;if(!n)throw new Error("To tag undefined.");var i="z9hG4bK"+Math.floor(1e7*Math.random());e.setViaHeader(i,this.transport.protocol),this.ackRetransmissionCache.set(n,e),this.send(e.toString()).catch(function(e){t.logTransportError(e,"Failed to send ACK to 2xx response.")})}},{key:"receiveResponse",value:function(e){var t,n=this,i=e.statusCode;if(!i||i<100||i>699)throw new Error("Invalid status code ".concat(i));switch(this.state){case Lt.Calling:if(i>=100&&i<=199)return this.stateTransition(Lt.Proceeding),void(this.user.receiveResponse&&this.user.receiveResponse(e));if(i>=200&&i<=299)return this.ackRetransmissionCache.set(e.toTag,void 0),this.stateTransition(Lt.Accepted),void(this.user.receiveResponse&&this.user.receiveResponse(e));if(i>=300&&i<=699)return this.stateTransition(Lt.Completed),this.ack(e),void(this.user.receiveResponse&&this.user.receiveResponse(e));break;case Lt.Proceeding:if(i>=100&&i<=199)return void(this.user.receiveResponse&&this.user.receiveResponse(e));if(i>=200&&i<=299)return this.ackRetransmissionCache.set(e.toTag,void 0),this.stateTransition(Lt.Accepted),void(this.user.receiveResponse&&this.user.receiveResponse(e));if(i>=300&&i<=699)return this.stateTransition(Lt.Completed),this.ack(e),void(this.user.receiveResponse&&this.user.receiveResponse(e));break;case Lt.Accepted:if(i>=200&&i<=299){if(!this.ackRetransmissionCache.has(e.toTag))return this.ackRetransmissionCache.set(e.toTag,void 0),void(this.user.receiveResponse&&this.user.receiveResponse(e));var r=this.ackRetransmissionCache.get(e.toTag);return r?void this.send(r.toString()).catch(function(e){n.logTransportError(e,"Failed to send retransmission of ACK to 2xx response.")}):void 0}break;case Lt.Completed:if(i>=300&&i<=699)return void this.ack(e);break;case Lt.Terminated:break;default:throw new Error("Invalid state ".concat(this.state))}var s=E(t="Received unexpected ".concat(i," response while in state ")).call(t,this.state,".");this.logger.warn(s)}},{key:"onTransportError",value:function(e){this.user.onTransportError&&this.user.onTransportError(e),this.stateTransition(Lt.Terminated,!0)}},{key:"typeToString",value:function(){return"INVITE client transaction"}},{key:"ack",value:function(e){var t=this,n=this.request.ruri,i=this.request.callId,r=this.request.cseq,s=this.request.getHeader("from"),a=e.getHeader("to"),o=this.request.getHeader("via"),c=this.request.getHeader("route");if(!s)throw new Error("From undefined.");if(!a)throw new Error("To undefined.");if(!o)throw new Error("Via undefined.");var l="ACK ".concat(n," SIP/2.0\r\n");c&&(l+="Route: ".concat(c,"\r\n")),l+="Via: ".concat(o,"\r\n"),l+="To: ".concat(a,"\r\n"),l+="From: ".concat(s,"\r\n"),l+="Call-ID: ".concat(i,"\r\n"),l+="CSeq: ".concat(r," ACK\r\n"),l+="Max-Forwards: 70\r\n",l+="Content-Length: 0\r\n\r\n",this.send(l).catch(function(e){t.logTransportError(e,"Failed to send ACK to non-2xx response.")})}},{key:"stateTransition",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=function(){var n;throw new Error(E(n="Invalid state transition from ".concat(t.state," to ")).call(n,e))};switch(e){case Lt.Calling:i();break;case Lt.Proceeding:this.state!==Lt.Calling&&i();break;case Lt.Accepted:case Lt.Completed:this.state!==Lt.Calling&&this.state!==Lt.Proceeding&&i();break;case Lt.Terminated:this.state!==Lt.Calling&&this.state!==Lt.Accepted&&this.state!==Lt.Completed&&(n||i());break;default:i()}this.B&&(clearTimeout(this.B),this.B=void 0),Lt.Proceeding,e===Lt.Completed&&(this.D=m(function(){return t.timerD()},it.TIMER_D)),e===Lt.Accepted&&(this.M=m(function(){return t.timerM()},it.TIMER_M)),e===Lt.Terminated&&this.dispose(),this.setState(e)}},{key:"timerA",value:function(){}},{key:"timerB",value:function(){this.logger.debug("Timer B expired for INVITE client transaction ".concat(this.id,".")),this.state===Lt.Calling&&(this.onRequestTimeout(),this.stateTransition(Lt.Terminated))}},{key:"timerD",value:function(){this.logger.debug("Timer D expired for INVITE client transaction ".concat(this.id,".")),this.state===Lt.Completed&&this.stateTransition(Lt.Terminated)}},{key:"timerM",value:function(){this.logger.debug("Timer M expired for INVITE client transaction ".concat(this.id,".")),this.state===Lt.Accepted&&this.stateTransition(Lt.Terminated)}}])}(),en=function(){function n(t,i,r,s){e(this,n),d(this,"transactionConstructor",{enumerable:!0,configurable:!0,writable:!0,value:t}),d(this,"core",{enumerable:!0,configurable:!0,writable:!0,value:i}),d(this,"message",{enumerable:!0,configurable:!0,writable:!0,value:r}),d(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:s}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_transaction",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"credentials",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"challenged",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"stale",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this.logger=this.loggerFactory.getLogger("sip.user-agent-client"),this.init()}return t(n,[{key:"dispose",value:function(){this.transaction.dispose()}},{key:"loggerFactory",get:function(){return this.core.loggerFactory}},{key:"transaction",get:function(){if(!this._transaction)throw new Error("Transaction undefined.");return this._transaction}},{key:"cancel",value:function(e){var t=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!this.transaction)throw new Error("Transaction undefined.");if(!this.message.to)throw new Error("To undefined.");if(!this.message.from)throw new Error("From undefined.");var r=this.core.makeOutgoingRequestMessage(st.CANCEL,this.message.ruri,this.message.from.uri,this.message.to.uri,{toTag:this.message.toTag,fromTag:this.message.fromTag,callId:this.message.callId,cseq:this.message.cseq},i.extraHeaders);return r.branch=this.message.branch,this.message.headers.Route&&(r.headers.Route=this.message.headers.Route),e&&r.setHeader("Reason",e),this.transaction.state===Lt.Proceeding?new n(Zt,this.core,r):this.transaction.addStateChangeListener(function(){t.transaction&&t.transaction.state===Lt.Proceeding&&new n(Zt,t.core,r)},{once:!0}),r}},{key:"authenticationGuard",value:function(e,t){var n,i,r=e.statusCode;if(!r)throw new Error("Response status code undefined.");if(401!==r&&407!==r)return!0;if(401===r?(n=e.parseHeader("www-authenticate"),i="authorization"):(n=e.parseHeader("proxy-authenticate"),i="proxy-authorization"),!n)return this.logger.warn(r+" with wrong or missing challenge, cannot authenticate"),!0;if(this.challenged&&(this.stale||!0!==n.stale))return this.logger.warn(r+" apparently in authentication loop, cannot authenticate"),!0;if(!this.credentials&&(this.credentials=this.core.configuration.authenticationFactory(),!this.credentials))return this.logger.warn("Unable to obtain credentials, cannot authenticate"),!0;if(!this.credentials.authenticate(this.message,n))return!0;this.challenged=!0,n.stale&&(this.stale=!0);var s=this.message.cseq+=1;return t&&t.localSequenceNumber&&(t.incrementLocalSequenceNumber(),s=this.message.cseq=t.localSequenceNumber),this.message.setHeader("cseq",s+" "+this.message.method),this.message.setHeader(i,this.credentials.toString()),this.init(),!1}},{key:"onRequestTimeout",value:function(){this.logger.warn("User agent client request timed out. Generating internal 408 Request Timeout.");var e=new Ve;e.statusCode=408,e.reasonPhrase="Request Timeout",this.receiveResponse(e)}},{key:"onTransportError",value:function(e){this.logger.error(e.message),this.logger.error("User agent client request transport error. Generating internal 503 Service Unavailable.");var t=new Ve;t.statusCode=503,t.reasonPhrase="Service Unavailable",this.receiveResponse(t)}},{key:"receiveResponse",value:function(e){if(this.authenticationGuard(e)){var t=e.statusCode?e.statusCode.toString():"";if(!t)throw new Error("Response status code undefined.");switch(!0){case/^100$/.test(t):this.delegate&&this.delegate.onTrying&&this.delegate.onTrying({message:e});break;case/^1[0-9]{2}$/.test(t):this.delegate&&this.delegate.onProgress&&this.delegate.onProgress({message:e});break;case/^2[0-9]{2}$/.test(t):this.delegate&&this.delegate.onAccept&&this.delegate.onAccept({message:e});break;case/^3[0-9]{2}$/.test(t):this.delegate&&this.delegate.onRedirect&&this.delegate.onRedirect({message:e});break;case/^[4-6][0-9]{2}$/.test(t):this.delegate&&this.delegate.onReject&&this.delegate.onReject({message:e});break;default:throw new Error("Invalid status code ".concat(t))}}}},{key:"init",value:function(){var e=this,t={loggerFactory:this.loggerFactory,onRequestTimeout:function(){return e.onRequestTimeout()},onStateChange:function(t){t===Lt.Terminated&&(e.core.userAgentClients.delete(i),n===e._transaction&&e.dispose())},onTransportError:function(t){return e.onTransportError(t)},receiveResponse:function(t){return e.receiveResponse(t)}},n=new this.transactionConstructor(this.message,this.core.transport,t);this._transaction=n;var i=n.id+n.request.method;this.core.userAgentClients.set(i,this)}}])}();function tn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(tn=function(){return!!e})()}var nn=function(){function n(t,i,r){var c;e(this,n);var l,u,d,h=t.createOutgoingRequestMessage(st.BYE,r);return l=this,u=n,d=[Zt,t.userAgentCore,h,i],u=o(u),c=a(l,tn()?s(u,d||[],o(l).constructor):u.apply(l,d)),t.dispose(),c}return c(n,en),t(n)}();function rn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(rn=function(){return!!e})()}var sn=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,u=n,h=[t,i,r,Lt.Trying,"sip.transaction.nist"],u=o(u),c=a(l,rn()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"lastResponse",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"J",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c}return c(n,Gt),t(n,[{key:"dispose",value:function(){var e,t,i,r,s;this.J&&(clearTimeout(this.J),this.J=void 0),(e=n,t="dispose",i=this,s=v(o(1&(r=3)?e.prototype:e),t,i),2&r&&"function"==typeof s?function(e){return s.apply(i,e)}:s)([])}},{key:"kind",get:function(){return"nist"}},{key:"receiveRequest",value:function(e){var t=this;switch(this.state){case Lt.Trying:break;case Lt.Proceeding:if(!this.lastResponse)throw new Error("Last response undefined.");this.send(this.lastResponse).catch(function(e){t.logTransportError(e,"Failed to send retransmission of provisional response.")});break;case Lt.Completed:if(!this.lastResponse)throw new Error("Last response undefined.");this.send(this.lastResponse).catch(function(e){t.logTransportError(e,"Failed to send retransmission of final response.")});break;case Lt.Terminated:break;default:throw new Error("Invalid state ".concat(this.state))}}},{key:"receiveResponse",value:function(e,t){var n,i=this;if(e<100||e>699)throw new Error("Invalid status code ".concat(e));if(e>100&&e<=199)throw new Error("Provisional response other than 100 not allowed.");switch(this.state){case Lt.Trying:if(this.lastResponse=t,e>=100&&e<200)return this.stateTransition(Lt.Proceeding),void this.send(t).catch(function(e){i.logTransportError(e,"Failed to send provisional response.")});if(e>=200&&e<=699)return this.stateTransition(Lt.Completed),void this.send(t).catch(function(e){i.logTransportError(e,"Failed to send final response.")});break;case Lt.Proceeding:if(this.lastResponse=t,e>=200&&e<=699)return this.stateTransition(Lt.Completed),void this.send(t).catch(function(e){i.logTransportError(e,"Failed to send final response.")});break;case Lt.Completed:return;case Lt.Terminated:break;default:throw new Error("Invalid state ".concat(this.state))}var r=E(n="Non-INVITE server transaction received unexpected ".concat(e," response from TU while in state ")).call(n,this.state,".");throw this.logger.error(r),new Error(r)}},{key:"onTransportError",value:function(e){this.user.onTransportError&&this.user.onTransportError(e),this.stateTransition(Lt.Terminated,!0)}},{key:"typeToString",value:function(){return"non-INVITE server transaction"}},{key:"stateTransition",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=function(){var n;throw new Error(E(n="Invalid state transition from ".concat(t.state," to ")).call(n,e))};switch(e){case Lt.Trying:i();break;case Lt.Proceeding:this.state!==Lt.Trying&&i();break;case Lt.Completed:this.state!==Lt.Trying&&this.state!==Lt.Proceeding&&i();break;case Lt.Terminated:this.state!==Lt.Proceeding&&this.state!==Lt.Completed&&(n||i());break;default:i()}e===Lt.Completed&&(this.J=m(function(){return t.timerJ()},it.TIMER_J)),e===Lt.Terminated&&this.dispose(),this.setState(e)}},{key:"timerJ",value:function(){this.logger.debug("Timer J expired for NON-INVITE server transaction ".concat(this.id,".")),this.state===Lt.Completed&&this.stateTransition(Lt.Terminated)}}])}(),an=function(){return t(function t(n,i,r,s){e(this,t),d(this,"transactionConstructor",{enumerable:!0,configurable:!0,writable:!0,value:n}),d(this,"core",{enumerable:!0,configurable:!0,writable:!0,value:i}),d(this,"message",{enumerable:!0,configurable:!0,writable:!0,value:r}),d(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:s}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"toTag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_transaction",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.logger=this.loggerFactory.getLogger("sip.user-agent-server"),this.toTag=r.toTag?r.toTag:Pe(),this.init()},[{key:"dispose",value:function(){this.transaction.dispose()}},{key:"loggerFactory",get:function(){return this.core.loggerFactory}},{key:"transaction",get:function(){if(!this._transaction)throw new Error("Transaction undefined.");return this._transaction}},{key:"accept",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:200};if(!this.acceptable)throw new at(E(e="".concat(this.message.method," not acceptable in state ")).call(e,this.transaction.state,"."));var n=t.statusCode;if(n<200||n>299)throw new TypeError("Invalid statusCode: ".concat(n));return this.reply(t)}},{key:"progress",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:180};if(!this.progressable)throw new at(E(e="".concat(this.message.method," not progressable in state ")).call(e,this.transaction.state,"."));var n=t.statusCode;if(n<101||n>199)throw new TypeError("Invalid statusCode: ".concat(n));return this.reply(t)}},{key:"redirect",value:function(e){var t,n,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{statusCode:302};if(!this.redirectable)throw new at(E(n="".concat(this.message.method," not redirectable in state ")).call(n,this.transaction.state,"."));var r=i.statusCode;if(r<300||r>399)throw new TypeError("Invalid statusCode: ".concat(r));var s=new Array;return h(e).call(e,function(e){return s.push("Contact: ".concat(e.toString()))}),i.extraHeaders=E(t=i.extraHeaders||[]).call(t,s),this.reply(i)}},{key:"reject",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:480};if(!this.rejectable)throw new at(E(e="".concat(this.message.method," not rejectable in state ")).call(e,this.transaction.state,"."));var n=t.statusCode;if(n<400||n>699)throw new TypeError("Invalid statusCode: ".concat(n));return this.reply(t)}},{key:"trying",value:function(e){var t;if(!this.tryingable)throw new at(E(t="".concat(this.message.method," not tryingable in state ")).call(t,this.transaction.state,"."));return this.reply({statusCode:100})}},{key:"receiveCancel",value:function(e){this.delegate&&this.delegate.onCancel&&this.delegate.onCancel(e)}},{key:"acceptable",get:function(){if(this.transaction instanceof Wt)return this.transaction.state===Lt.Proceeding||this.transaction.state===Lt.Accepted;if(this.transaction instanceof sn)return this.transaction.state===Lt.Trying||this.transaction.state===Lt.Proceeding;throw new Error("Unknown transaction type.")}},{key:"progressable",get:function(){if(this.transaction instanceof Wt)return this.transaction.state===Lt.Proceeding;if(this.transaction instanceof sn)return!1;throw new Error("Unknown transaction type.")}},{key:"redirectable",get:function(){if(this.transaction instanceof Wt)return this.transaction.state===Lt.Proceeding;if(this.transaction instanceof sn)return this.transaction.state===Lt.Trying||this.transaction.state===Lt.Proceeding;throw new Error("Unknown transaction type.")}},{key:"rejectable",get:function(){if(this.transaction instanceof Wt)return this.transaction.state===Lt.Proceeding;if(this.transaction instanceof sn)return this.transaction.state===Lt.Trying||this.transaction.state===Lt.Proceeding;throw new Error("Unknown transaction type.")}},{key:"tryingable",get:function(){if(this.transaction instanceof Wt)return this.transaction.state===Lt.Proceeding;if(this.transaction instanceof sn)return this.transaction.state===Lt.Trying;throw new Error("Unknown transaction type.")}},{key:"reply",value:function(e){e.toTag||100===e.statusCode||(e.toTag=this.toTag),e.userAgent=e.userAgent||this.core.configuration.userAgentHeaderFieldValue,e.supported=e.supported||this.core.configuration.supportedOptionTagsResponse;var t=Nt(this.message,e);return this.transaction.receiveResponse(e.statusCode,t.message),t}},{key:"init",value:function(){var e=this,t={loggerFactory:this.loggerFactory,onStateChange:function(t){t===Lt.Terminated&&(e.core.userAgentServers.delete(i),e.dispose())},onTransportError:function(t){e.logger.error(t.message),e.delegate&&e.delegate.onTransportError?e.delegate.onTransportError(t):e.logger.error("User agent server response transport error.")}},n=new this.transactionConstructor(this.message,this.core.transport,t);this._transaction=n;var i=n.id;this.core.userAgentServers.set(n.id,this)}}])}();function on(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(on=function(){return!!e})()}var cn=function(){function n(t,i,r){return e(this,n),c=this,l=n,u=[sn,t.userAgentCore,i,r],l=o(l),a(c,on()?s(l,u||[],o(c).constructor):l.apply(c,u));var c,l,u}return c(n,an),t(n)}();function ln(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(ln=function(){return!!e})()}var un=function(){function n(t,i,r){e(this,n);var c,l,u,d=t.createOutgoingRequestMessage(st.INFO,r);return c=this,l=n,u=[Zt,t.userAgentCore,d,i],l=o(l),a(c,ln()?s(l,u||[],o(c).constructor):l.apply(c,u))}return c(n,en),t(n)}();function dn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(dn=function(){return!!e})()}var hn=function(){function n(t,i,r){return e(this,n),c=this,l=n,u=[sn,t.userAgentCore,i,r],l=o(l),a(c,dn()?s(l,u||[],o(c).constructor):l.apply(c,u));var c,l,u}return c(n,an),t(n)}();function gn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(gn=function(){return!!e})()}var fn=function(){function n(t,i,r){return e(this,n),c=this,u=[Zt,t,i,r],l=o(l=n),a(c,gn()?s(l,u||[],o(c).constructor):l.apply(c,u));var c,l,u}return c(n,en),t(n)}();function vn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(vn=function(){return!!e})()}var pn=function(){function n(t,i,r){return e(this,n),c=this,u=[sn,t,i,r],l=o(l=n),a(c,vn()?s(l,u||[],o(c).constructor):l.apply(c,u));var c,l,u}return c(n,an),t(n)}();function mn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(mn=function(){return!!e})()}var bn=function(){function n(t,i,r){e(this,n);var c,l,u,d=t.createOutgoingRequestMessage(st.NOTIFY,r);return c=this,l=n,u=[Zt,t.userAgentCore,d,i],l=o(l),a(c,mn()?s(l,u||[],o(c).constructor):l.apply(c,u))}return c(n,en),t(n)}();function wn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(wn=function(){return!!e})()}var yn=function(){function n(t,i,r){e(this,n);var c,l,u,d=void 0!==t.userAgentCore?t.userAgentCore:t;return c=this,u=[sn,d,i,r],l=o(l=n),a(c,wn()?s(l,u||[],o(c).constructor):l.apply(c,u))}return c(n,an),t(n)}();function kn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(kn=function(){return!!e})()}var Tn=function(){function n(t,i,r){var c;e(this,n);var l,u,d,h=t.createOutgoingRequestMessage(st.PRACK,r);return l=this,u=n,d=[Zt,t.userAgentCore,h,i],u=o(u),c=a(l,kn()?s(u,d||[],o(l).constructor):u.apply(l,d)),t.signalingStateTransition(h),c}return c(n,en),t(n)}();function Rn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Rn=function(){return!!e})()}var Sn=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,u=n,h=[sn,t.userAgentCore,i,r],u=o(u),c=a(l,Rn()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"dialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),t.signalingStateTransition(i),c.dialog=t,c}return c(n,an),t(n,[{key:"accept",value:function(){var e,t,i,r,s,a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:200};return a.body&&this.dialog.signalingStateTransition(a.body),(e=n,t="accept",i=this,s=v(o(1&(r=3)?e.prototype:e),t,i),2&r&&"function"==typeof s?function(e){return s.apply(i,e)}:s)([a])}}])}();function In(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(In=function(){return!!e})()}var En=function(){function n(t,i,r){var c;e(this,n);var l,u,h,g=t.createOutgoingRequestMessage(st.INVITE,r);return l=this,u=n,h=[Qt,t.userAgentCore,g,i],u=o(u),c=a(l,In()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"dialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c.delegate=i,t.signalingStateTransition(g),t.reinviteUserAgentClient=c,c.dialog=t,c}return c(n,en),t(n,[{key:"receiveResponse",value:function(e){var t=this;if(this.authenticationGuard(e,this.dialog)){var n=e.statusCode?e.statusCode.toString():"";if(!n)throw new Error("Response status code undefined.");switch(!0){case/^100$/.test(n):this.delegate&&this.delegate.onTrying&&this.delegate.onTrying({message:e});break;case/^1[0-9]{2}$/.test(n):this.delegate&&this.delegate.onProgress&&this.delegate.onProgress({message:e,session:this.dialog,prack:function(e){throw new Error("Unimplemented.")}});break;case/^2[0-9]{2}$/.test(n):this.dialog.signalingStateTransition(e),this.delegate&&this.delegate.onAccept&&this.delegate.onAccept({message:e,session:this.dialog,ack:function(e){return t.dialog.ack(e)}});break;case/^3[0-9]{2}$/.test(n):this.dialog.signalingStateRollback(),this.dialog.reinviteUserAgentClient=void 0,this.delegate&&this.delegate.onRedirect&&this.delegate.onRedirect({message:e});break;case/^[4-6][0-9]{2}$/.test(n):this.dialog.signalingStateRollback(),this.dialog.reinviteUserAgentClient=void 0,this.delegate&&this.delegate.onReject&&this.delegate.onReject({message:e});break;default:throw new Error("Invalid status code ".concat(n))}}}}])}();function Cn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Cn=function(){return!!e})()}function An(e,t,n,i){var r=v(o(1&i?e.prototype:e),t,n);return 2&i&&"function"==typeof r?function(e){return r.apply(n,e)}:r}var xn=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,u=n,h=[Wt,t.userAgentCore,i,r],u=o(u),c=a(l,Cn()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"dialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),t.reinviteUserAgentServer=c,c.dialog=t,c}return c(n,an),t(n,[{key:"accept",value:function(){var e,t,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:200};i.extraHeaders=i.extraHeaders||[],i.extraHeaders=E(e=i.extraHeaders).call(e,w(t=this.dialog.routeSet).call(t,function(e){return"Record-Route: ".concat(e)}));var r=An(n,"accept",this,3)([i]),s=this.dialog,a=$($({},r),{session:s});return i.body&&this.dialog.signalingStateTransition(i.body),this.dialog.reConfirm(),a}},{key:"progress",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:180},t=An(n,"progress",this,3)([e]),i=this.dialog,r=$($({},t),{session:i});return e.body&&this.dialog.signalingStateTransition(e.body),r}},{key:"redirect",value:function(e){throw this.dialog.signalingStateRollback(),this.dialog.reinviteUserAgentServer=void 0,new Error("Unimplemented.")}},{key:"reject",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:488};return this.dialog.signalingStateRollback(),this.dialog.reinviteUserAgentServer=void 0,An(n,"reject",this,3)([e])}}])}();function Dn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Dn=function(){return!!e})()}var Hn=function(){function n(t,i,r){e(this,n);var c,l,u,d=t.createOutgoingRequestMessage(st.REFER,r);return c=this,l=n,u=[Zt,t.userAgentCore,d,i],l=o(l),a(c,Dn()?s(l,u||[],o(c).constructor):l.apply(c,u))}return c(n,en),t(n)}();function _n(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(_n=function(){return!!e})()}var $n=function(){function n(t,i,r){e(this,n);var c,l,u,d=void 0!==t.userAgentCore?t.userAgentCore:t;return c=this,u=[sn,d,i,r],l=o(l=n),a(c,_n()?s(l,u||[],o(c).constructor):l.apply(c,u))}return c(n,an),t(n)}();function qn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(qn=function(){return!!e})()}function Mn(e,t,n,i){var r=v(o(1&i?e.prototype:e),t,n);return 2&i&&"function"==typeof r?function(e){return r.apply(n,e)}:r}var Pn=function(){function n(t,i,r,c){var l,u,h,g;return e(this,n),u=this,g=[i,r],h=o(h=n),l=a(u,qn()?s(h,g||[],o(u).constructor):h.apply(u,g)),d(l,"initialTransaction",{enumerable:!0,configurable:!0,writable:!0,value:t}),d(l,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"reinviteUserAgentClient",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"reinviteUserAgentServer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"_signalingState",{enumerable:!0,configurable:!0,writable:!0,value:ze.Initial}),d(l,"_offer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"_answer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"_rollbackOffer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"_rollbackAnswer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"ackWait",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(l,"ackProcessing",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(l,"invite2xxTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"rseq",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),l.delegate=c,t instanceof Wt&&(l.ackWait=!0),l.early||l.start2xxRetransmissionTimer(),l.signalingStateTransition(t.request),l.logger=i.loggerFactory.getLogger("sip.invite-dialog"),l.logger.log("INVITE dialog ".concat(l.id," constructed")),l}return c(n,Jt),t(n,[{key:"dispose",value:function(){Mn(n,"dispose",this,3)([]),this._signalingState=ze.Closed,this._offer=void 0,this._answer=void 0,this.invite2xxTimer&&(clearTimeout(this.invite2xxTimer),this.invite2xxTimer=void 0),this.logger.log("INVITE dialog ".concat(this.id," destroyed"))}},{key:"sessionState",get:function(){return this.early?Ke.Early:this.ackWait?Ke.AckWait:this._signalingState===ze.Closed?Ke.Terminated:Ke.Confirmed}},{key:"signalingState",get:function(){return this._signalingState}},{key:"offer",get:function(){return this._offer}},{key:"answer",get:function(){return this._answer}},{key:"confirm",value:function(){this.early&&this.start2xxRetransmissionTimer(),Mn(n,"confirm",this,3)([])}},{key:"reConfirm",value:function(){this.reinviteUserAgentServer&&this.startReInvite2xxRetransmissionTimer()}},{key:"ack",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("INVITE dialog ".concat(this.id," sending ACK request")),this.reinviteUserAgentClient){if(!(this.reinviteUserAgentClient.transaction instanceof Qt))throw new Error("Transaction not instance of InviteClientTransaction.");e=this.reinviteUserAgentClient.transaction,this.reinviteUserAgentClient=void 0}else{if(!(this.initialTransaction instanceof Qt))throw new Error("Initial transaction not instance of InviteClientTransaction.");e=this.initialTransaction}var n=this.createOutgoingRequestMessage(st.ACK,{cseq:e.request.cseq,extraHeaders:t.extraHeaders,body:t.body});return e.ackResponse(n),this.signalingStateTransition(n),{message:n}}},{key:"bye",value:function(e,t){if(this.logger.log("INVITE dialog ".concat(this.id," sending BYE request")),this.initialTransaction instanceof Wt){if(this.early)throw new Error("UAS MUST NOT send a BYE on early dialogs.");if(this.ackWait&&this.initialTransaction.state!==Lt.Terminated)throw new Error("UAS MUST NOT send a BYE on a confirmed dialog until it has received an ACK for its 2xx response or until the server transaction times out.")}return new nn(this,e,t)}},{key:"info",value:function(e,t){if(this.logger.log("INVITE dialog ".concat(this.id," sending INFO request")),this.early)throw new Error("Dialog not confirmed.");return new un(this,e,t)}},{key:"invite",value:function(e,t){if(this.logger.log("INVITE dialog ".concat(this.id," sending INVITE request")),this.early)throw new Error("Dialog not confirmed.");if(this.reinviteUserAgentClient)throw new Error("There is an ongoing re-INVITE client transaction.");if(this.reinviteUserAgentServer)throw new Error("There is an ongoing re-INVITE server transaction.");return new En(this,e,t)}},{key:"message",value:function(e,t){if(this.logger.log("INVITE dialog ".concat(this.id," sending MESSAGE request")),this.early)throw new Error("Dialog not confirmed.");var n=this.createOutgoingRequestMessage(st.MESSAGE,t);return new fn(this.core,n,e)}},{key:"notify",value:function(e,t){if(this.logger.log("INVITE dialog ".concat(this.id," sending NOTIFY request")),this.early)throw new Error("Dialog not confirmed.");return new bn(this,e,t)}},{key:"prack",value:function(e,t){return this.logger.log("INVITE dialog ".concat(this.id," sending PRACK request")),new Tn(this,e,t)}},{key:"refer",value:function(e,t){if(this.logger.log("INVITE dialog ".concat(this.id," sending REFER request")),this.early)throw new Error("Dialog not confirmed.");return new Hn(this,e,t)}},{key:"receiveRequest",value:function(e){var t,r=this;if(this.logger.log(E(t="INVITE dialog ".concat(this.id," received ")).call(t,e.method," request")),e.method!==st.ACK)if(this.sequenceGuard(e)){if(Mn(n,"receiveRequest",this,3)([e]),e.method===st.INVITE){var s=function(){var e,t=r.ackWait?"waiting for initial ACK":"processing initial ACK";r.logger.warn(E(e="INVITE dialog ".concat(r.id," received re-INVITE while ")).call(e,t));r.logger.warn("RFC 5407 suggests the following to avoid this race condition... Note: Implementation issues are outside the scope of this document, but the following tip is provided for avoiding race conditions of this type. The caller can delay sending re-INVITE F6 for some period of time (2 seconds, perhaps), after which the caller can reasonably assume that its ACK has been received. Implementors can decouple the actions of the user (e.g., pressing the hold button) from the actions of the protocol (the sending of re-INVITE F6), so that the UA can behave like this. In this case, it is the implementor's choice as to how long to wait. In most cases, such an implementation may be useful to prevent the type of race condition shown in this section. This document expresses no preference about whether or not they should wait for an ACK to be delivered. After considering the impact on user experience, implementors should decide whether or not to wait for a while, because the user experience depends on the implementation and has no direct bearing on protocol behavior.")},a=Math.floor(10*Math.random())+1,o=["Retry-After: ".concat(a)];if(this.ackProcessing)return this.core.replyStateless(e,{statusCode:500,extraHeaders:o}),void s();if(this.ackWait&&this.signalingState!==ze.Stable)return this.core.replyStateless(e,{statusCode:500,extraHeaders:o}),void s();if(this.reinviteUserAgentServer)return void this.core.replyStateless(e,{statusCode:500,extraHeaders:o});if(this.reinviteUserAgentClient)return void this.core.replyStateless(e,{statusCode:491})}if(e.method===st.INVITE){var c=e.parseHeader("contact");if(!c)throw new Error("Contact undefined.");if(!(c instanceof Se))throw new Error("Contact not instance of NameAddrHeader.");this.dialogState.remoteTarget=c.uri}switch(e.method){case st.BYE:var l=new cn(this,e);this.delegate&&this.delegate.onBye?this.delegate.onBye(l):l.accept(),this.dispose();break;case st.INFO:var u=new hn(this,e);this.delegate&&this.delegate.onInfo?this.delegate.onInfo(u):u.reject({statusCode:469,extraHeaders:["Recv-Info:"]});break;case st.INVITE:var d=new xn(this,e);this.signalingStateTransition(e),this.delegate&&this.delegate.onInvite?this.delegate.onInvite(d):d.reject({statusCode:488});break;case st.MESSAGE:var h=new pn(this.core,e);this.delegate&&this.delegate.onMessage?this.delegate.onMessage(h):h.accept();break;case st.NOTIFY:var g=new yn(this,e);this.delegate&&this.delegate.onNotify?this.delegate.onNotify(g):g.accept();break;case st.PRACK:var f=new Sn(this,e);this.delegate&&this.delegate.onPrack?this.delegate.onPrack(f):f.accept();break;case st.REFER:var v=new $n(this,e);this.delegate&&this.delegate.onRefer?this.delegate.onRefer(v):v.reject();break;default:var p;this.logger.log(E(p="INVITE dialog ".concat(this.id," received unimplemented ")).call(p,e.method," request")),this.core.replyStateless(e,{statusCode:501})}}else{var m;this.logger.log(E(m="INVITE dialog ".concat(this.id," rejected out of order ")).call(m,e.method," request."))}else{if(this.ackWait){var b,w;if(this.initialTransaction instanceof Qt)return void this.logger.warn(E(b="INVITE dialog ".concat(this.id," received unexpected ")).call(b,e.method," request, dropping."));if(this.initialTransaction.request.cseq!==e.cseq)return void this.logger.warn(E(w="INVITE dialog ".concat(this.id," received unexpected ")).call(w,e.method," request, dropping."));this.ackWait=!1}else{var y,k;if(!this.reinviteUserAgentServer)return void this.logger.warn(E(y="INVITE dialog ".concat(this.id," received unexpected ")).call(y,e.method," request, dropping."));if(this.reinviteUserAgentServer.transaction.request.cseq!==e.cseq)return void this.logger.warn(E(k="INVITE dialog ".concat(this.id," received unexpected ")).call(k,e.method," request, dropping."));this.reinviteUserAgentServer=void 0}if(this.signalingStateTransition(e),this.delegate&&this.delegate.onAck){var T=this.delegate.onAck({message:e});T instanceof i&&(this.ackProcessing=!0,T.then(function(){return r.ackProcessing=!1}).catch(function(){return r.ackProcessing=!1}))}}}},{key:"reliableSequenceGuard",value:function(e){var t=e.statusCode;if(!t)throw new Error("Status code undefined");if(t>100&&t<200){var n=e.getHeader("require"),i=e.getHeader("rseq"),r=n&&p(n).call(n,"100rel")&&i?Number(i):void 0;if(r){if(this.rseq&&this.rseq+1!==r)return!1;this.rseq=this.rseq?this.rseq+1:r}}return!0}},{key:"signalingStateRollback",value:function(){this._signalingState!==ze.HaveLocalOffer&&this.signalingState!==ze.HaveRemoteOffer||this._rollbackOffer&&this._rollbackAnswer&&(this._signalingState=ze.Stable,this._offer=this._rollbackOffer,this._answer=this._rollbackAnswer)}},{key:"signalingStateTransition",value:function(e){var t=et(e);if(t&&"session"===t.contentDisposition){if(this._signalingState===ze.Stable&&(this._rollbackOffer=this._offer,this._rollbackAnswer=this._answer),e instanceof Le)switch(this._signalingState){case ze.Initial:case ze.Stable:this._signalingState=ze.HaveRemoteOffer,this._offer=t,this._answer=void 0;break;case ze.HaveLocalOffer:this._signalingState=ze.Stable,this._answer=t;break;case ze.HaveRemoteOffer:case ze.Closed:break;default:throw new Error("Unexpected signaling state.")}if(e instanceof Ve)switch(this._signalingState){case ze.Initial:case ze.Stable:this._signalingState=ze.HaveRemoteOffer,this._offer=t,this._answer=void 0;break;case ze.HaveLocalOffer:this._signalingState=ze.Stable,this._answer=t;break;case ze.HaveRemoteOffer:case ze.Closed:break;default:throw new Error("Unexpected signaling state.")}if(e instanceof Ze)switch(this._signalingState){case ze.Initial:case ze.Stable:this._signalingState=ze.HaveLocalOffer,this._offer=t,this._answer=void 0;break;case ze.HaveLocalOffer:break;case ze.HaveRemoteOffer:this._signalingState=ze.Stable,this._answer=t;break;case ze.Closed:break;default:throw new Error("Unexpected signaling state.")}if(Qe(e))switch(this._signalingState){case ze.Initial:case ze.Stable:this._signalingState=ze.HaveLocalOffer,this._offer=t,this._answer=void 0;break;case ze.HaveLocalOffer:break;case ze.HaveRemoteOffer:this._signalingState=ze.Stable,this._answer=t;break;case ze.Closed:break;default:throw new Error("Unexpected signaling state.")}}}},{key:"start2xxRetransmissionTimer",value:function(){var e=this;if(this.initialTransaction instanceof Wt){var t=this.initialTransaction,n=it.T1,i=function(){e.ackWait?(e.logger.log("No ACK for 2xx response received, attempting retransmission"),t.retransmitAcceptedResponse(),n=Math.min(2*n,it.T2),e.invite2xxTimer=m(i,n)):e.invite2xxTimer=void 0};this.invite2xxTimer=m(i,n);var r=function(){t.state===Lt.Terminated&&(t.removeStateChangeListener(r),e.invite2xxTimer&&(clearTimeout(e.invite2xxTimer),e.invite2xxTimer=void 0),e.ackWait&&(e.delegate&&e.delegate.onAckTimeout?e.delegate.onAckTimeout():e.bye()))};t.addStateChangeListener(r)}}},{key:"startReInvite2xxRetransmissionTimer",value:function(){var e=this;if(this.reinviteUserAgentServer&&this.reinviteUserAgentServer.transaction instanceof Wt){var t=this.reinviteUserAgentServer.transaction,n=it.T1,i=function(){e.reinviteUserAgentServer?(e.logger.log("No ACK for 2xx response received, attempting retransmission"),t.retransmitAcceptedResponse(),n=Math.min(2*n,it.T2),e.invite2xxTimer=m(i,n)):e.invite2xxTimer=void 0};this.invite2xxTimer=m(i,n);var r=function(){t.state===Lt.Terminated&&(t.removeStateChangeListener(r),e.invite2xxTimer&&(clearTimeout(e.invite2xxTimer),e.invite2xxTimer=void 0),e.reinviteUserAgentServer)};t.addStateChangeListener(r)}}}])}();function On(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(On=function(){return!!e})()}function Nn(e,t,n,i){var r=v(o(1&i?e.prototype:e),t,n);return 2&i&&"function"==typeof r?function(e){return r.apply(n,e)}:r}var jn=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,h=[Qt,t,i,r],u=o(u=n),c=a(l,On()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"confirmedDialogAcks",{enumerable:!0,configurable:!0,writable:!0,value:new M}),d(c,"confirmedDialogs",{enumerable:!0,configurable:!0,writable:!0,value:new M}),d(c,"earlyDialogs",{enumerable:!0,configurable:!0,writable:!0,value:new M}),c.delegate=r,c}return c(n,en),t(n,[{key:"dispose",value:function(){var e;h(e=this.earlyDialogs).call(e,function(e){return e.dispose()}),this.earlyDialogs.clear(),Nn(n,"dispose",this,3)([])}},{key:"onTransportError",value:function(e){if(this.transaction.state===Lt.Calling)return Nn(n,"onTransportError",this,3)([e]);this.logger.error(e.message),this.logger.error("User agent client request transport error while sending ACK.")}},{key:"receiveResponse",value:function(e){var t,n,i=this;if(this.authenticationGuard(e)){var r=e.statusCode?e.statusCode.toString():"";if(!r)throw new Error("Response status code undefined.");switch(!0){case/^100$/.test(r):return void(this.delegate&&this.delegate.onTrying&&this.delegate.onTrying({message:e}));case/^1[0-9]{2}$/.test(r):if(!e.toTag)return void this.logger.warn("Non-100 1xx INVITE response received without a to tag, dropping.");if(!e.parseHeader("contact"))return void this.logger.error("Non-100 1xx INVITE response received without a Contact header field, dropping.");var s=Jt.initialDialogStateForUserAgentClient(this.message,e),a=this.earlyDialogs.get(s.id);if(!a){var o=this.transaction;if(!(o instanceof Qt))throw new Error("Transaction not instance of InviteClientTransaction.");a=new Pn(o,this.core,s),this.earlyDialogs.set(a.id,a)}if(!a.reliableSequenceGuard(e))return void this.logger.warn("1xx INVITE reliable response received out of order or is a retransmission, dropping.");a.signalingState!==ze.Initial&&a.signalingState!==ze.HaveLocalOffer||a.signalingStateTransition(e);var c=a;return void(this.delegate&&this.delegate.onProgress&&this.delegate.onProgress({message:e,session:c,prack:function(e){return c.prack(void 0,e)}}));case/^2[0-9]{2}$/.test(r):if(!e.toTag)return void this.logger.error("2xx INVITE response received without a to tag, dropping.");if(!e.parseHeader("contact"))return void this.logger.error("2xx INVITE response received without a Contact header field, dropping.");var l=Jt.initialDialogStateForUserAgentClient(this.message,e),u=this.confirmedDialogs.get(l.id);if(u){var d=this.confirmedDialogAcks.get(l.id);if(d){var g=this.transaction;if(!(g instanceof Qt))throw new Error("Client transaction not instance of InviteClientTransaction.");g.ackResponse(d.message)}return}if(u=this.earlyDialogs.get(l.id))u.confirm(),u.recomputeRouteSet(e),this.earlyDialogs.delete(u.id),this.confirmedDialogs.set(u.id,u);else{var f=this.transaction;if(!(f instanceof Qt))throw new Error("Transaction not instance of InviteClientTransaction.");u=new Pn(f,this.core,l),this.confirmedDialogs.set(u.id,u)}u.signalingState!==ze.Initial&&u.signalingState!==ze.HaveLocalOffer||u.signalingStateTransition(e);var v=u;if(this.delegate&&this.delegate.onAccept)this.delegate.onAccept({message:e,session:v,ack:function(e){var t=v.ack(e);return i.confirmedDialogAcks.set(v.id,t),t}});else{var p=v.ack();this.confirmedDialogAcks.set(v.id,p)}return;case/^3[0-9]{2}$/.test(r):return h(t=this.earlyDialogs).call(t,function(e){return e.dispose()}),this.earlyDialogs.clear(),void(this.delegate&&this.delegate.onRedirect&&this.delegate.onRedirect({message:e}));case/^[4-6][0-9]{2}$/.test(r):return h(n=this.earlyDialogs).call(n,function(e){return e.dispose()}),this.earlyDialogs.clear(),void(this.delegate&&this.delegate.onReject&&this.delegate.onReject({message:e}));default:throw new Error("Invalid status code ".concat(r))}}}}])}();function Fn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Fn=function(){return!!e})()}function Un(e,t,n,i){var r=v(o(1&i?e.prototype:e),t,n);return 2&i&&"function"==typeof r?function(e){return r.apply(n,e)}:r}var Bn=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,h=[Wt,t,i,r],u=o(u=n),c=a(l,Fn()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"core",{enumerable:!0,configurable:!0,writable:!0,value:t}),d(c,"confirmedDialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"earlyDialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c}return c(n,an),t(n,[{key:"dispose",value:function(){this.earlyDialog&&this.earlyDialog.dispose(),Un(n,"dispose",this,3)([])}},{key:"accept",value:function(){var e,t,i,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:200};if(!this.acceptable)throw new at(E(i="".concat(this.message.method," not acceptable in state ")).call(i,this.transaction.state,"."));if(!this.confirmedDialog)if(this.earlyDialog)this.earlyDialog.confirm(),this.confirmedDialog=this.earlyDialog,this.earlyDialog=void 0;else{var s=this.transaction;if(!(s instanceof Wt))throw new Error("Transaction not instance of InviteClientTransaction.");var a=Jt.initialDialogStateForUserAgentServer(this.message,this.toTag);this.confirmedDialog=new Pn(s,this.core,a)}var o=w(e=this.message.getHeaders("record-route")).call(e,function(e){return"Record-Route: ".concat(e)}),c="Contact: ".concat(this.core.configuration.contact.toString()),l="Allow: "+ct.toString();if(!r.body)if(this.confirmedDialog.signalingState===ze.Stable)r.body=this.confirmedDialog.answer;else if(this.confirmedDialog.signalingState===ze.Initial||this.confirmedDialog.signalingState===ze.HaveRemoteOffer)throw new Error("Response must have a body.");r.statusCode=r.statusCode||200,r.extraHeaders=r.extraHeaders||[],r.extraHeaders=E(t=r.extraHeaders).call(t,o),r.extraHeaders.push(l),r.extraHeaders.push(c);var u=Un(n,"accept",this,3)([r]),d=this.confirmedDialog,h=$($({},u),{session:d});return r.body&&this.confirmedDialog.signalingState!==ze.Stable&&this.confirmedDialog.signalingStateTransition(r.body),h}},{key:"progress",value:function(){var e,t,i,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:180};if(!this.progressable)throw new at(E(i="".concat(this.message.method," not progressable in state ")).call(i,this.transaction.state,"."));if(!this.earlyDialog){var s=this.transaction;if(!(s instanceof Wt))throw new Error("Transaction not instance of InviteClientTransaction.");var a=Jt.initialDialogStateForUserAgentServer(this.message,this.toTag,!0);this.earlyDialog=new Pn(s,this.core,a)}var o=w(e=this.message.getHeaders("record-route")).call(e,function(e){return"Record-Route: ".concat(e)}),c="Contact: ".concat(this.core.configuration.contact);r.extraHeaders=r.extraHeaders||[],r.extraHeaders=E(t=r.extraHeaders).call(t,o),r.extraHeaders.push(c);var l=Un(n,"progress",this,3)([r]),u=this.earlyDialog,d=$($({},l),{session:u});return r.body&&this.earlyDialog.signalingState!==ze.Stable&&this.earlyDialog.signalingStateTransition(r.body),d}},{key:"redirect",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{statusCode:302};return Un(n,"redirect",this,3)([e,t])}},{key:"reject",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:486};return Un(n,"reject",this,3)([e])}}])}();function Ln(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Ln=function(){return!!e})()}var Gn=function(){function n(t,i,r){return e(this,n),c=this,u=[Zt,t,i,r],l=o(l=n),a(c,Ln()?s(l,u||[],o(c).constructor):l.apply(c,u));var c,l,u}return c(n,en),t(n)}();function Vn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Vn=function(){return!!e})()}var Wn=function(){function n(t,i,r){return e(this,n),c=this,u=[Zt,t,i,r],l=o(l=n),a(c,Vn()?s(l,u||[],o(c).constructor):l.apply(c,u));var c,l,u}return c(n,en),t(n)}();function Yn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Yn=function(){return!!e})()}var Kn=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,h=[sn,t,i,r],u=o(u=n),c=a(l,Yn()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"core",{enumerable:!0,configurable:!0,writable:!0,value:t}),c}return c(n,an),t(n)}();function zn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(zn=function(){return!!e})()}var Zn=function(){function n(t,i,r){var c;e(this,n);var l,u,h,g=t.createOutgoingRequestMessage(st.SUBSCRIBE,r);return l=this,u=n,h=[Zt,t.userAgentCore,g,i],u=o(u),c=a(l,zn()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"dialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c.dialog=t,c}return c(n,en),t(n,[{key:"waitNotifyStop",value:function(){}},{key:"receiveResponse",value:function(e){if(e.statusCode&&e.statusCode>=200&&e.statusCode<300){var t=e.getHeader("Expires");if(t){var i=Number(t);this.dialog.subscriptionExpires>i&&(this.dialog.subscriptionExpires=i)}else this.logger.warn("Expires header missing in a 200-class response to SUBSCRIBE")}if(e.statusCode&&e.statusCode>=400&&e.statusCode<700){var r=[404,405,410,416,480,481,482,483,484,485,489,501,604];p(r).call(r,e.statusCode)&&this.dialog.terminate()}var s,a,c,l,u;(s=n,a="receiveResponse",c=this,u=v(o(1&(l=3)?s.prototype:s),a,c),2&l&&"function"==typeof u?function(e){return u.apply(c,e)}:u)([e])}}])}();function Jn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Jn=function(){return!!e})()}function Xn(e,t,n,i){var r=v(o(1&i?e.prototype:e),t,n);return 2&i&&"function"==typeof r?function(e){return r.apply(n,e)}:r}var Qn=function(){function n(t,i,c,l,u,h){var g,f,v,p;return e(this,n),f=this,p=[l,u],v=o(v=n),g=a(f,Jn()?s(v,p||[],o(f).constructor):v.apply(f,p)),d(g,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"_autoRefresh",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"_subscriptionEvent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"_subscriptionExpires",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"_subscriptionExpiresInitial",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"_subscriptionExpiresLastSet",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"_subscriptionRefresh",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"_subscriptionRefreshLastSet",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"_subscriptionState",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"N",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"refreshTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),g.delegate=h,g._autoRefresh=!1,g._subscriptionEvent=t,g._subscriptionExpires=i,g._subscriptionExpiresInitial=i,g._subscriptionExpiresLastSet=Math.floor(r()/1e3),g._subscriptionRefresh=void 0,g._subscriptionRefreshLastSet=void 0,g._subscriptionState=c,g.logger=l.loggerFactory.getLogger("sip.subscribe-dialog"),g.logger.log("SUBSCRIBE dialog ".concat(g.id," constructed")),g}return c(n,Jt),t(n,[{key:"dispose",value:function(){Xn(n,"dispose",this,3)([]),this.N&&(clearTimeout(this.N),this.N=void 0),this.refreshTimerClear(),this.logger.log("SUBSCRIBE dialog ".concat(this.id," destroyed"))}},{key:"autoRefresh",get:function(){return this._autoRefresh},set:function(e){this._autoRefresh=!0,this.refreshTimerSet()}},{key:"subscriptionEvent",get:function(){return this._subscriptionEvent}},{key:"subscriptionExpires",get:function(){var e=Math.floor(r()/1e3)-this._subscriptionExpiresLastSet,t=this._subscriptionExpires-e;return Math.max(t,0)},set:function(e){if(e<0)throw new Error("Expires must be greater than or equal to zero.");if(this._subscriptionExpires=e,this._subscriptionExpiresLastSet=Math.floor(r()/1e3),this.autoRefresh){var t=this.subscriptionRefresh;(void 0===t||t>=e)&&this.refreshTimerSet()}}},{key:"subscriptionExpiresInitial",get:function(){return this._subscriptionExpiresInitial}},{key:"subscriptionRefresh",get:function(){if(void 0!==this._subscriptionRefresh&&void 0!==this._subscriptionRefreshLastSet){var e=Math.floor(r()/1e3)-this._subscriptionRefreshLastSet,t=this._subscriptionRefresh-e;return Math.max(t,0)}}},{key:"subscriptionState",get:function(){return this._subscriptionState}},{key:"receiveRequest",value:function(e){var t,i,r;if(this.logger.log(E(t="SUBSCRIBE dialog ".concat(this.id," received ")).call(t,e.method," request")),this.sequenceGuard(e))if(Xn(n,"receiveRequest",this,3)([e]),e.method===st.NOTIFY)this.onNotify(e);else this.logger.log(E(i="SUBSCRIBE dialog ".concat(this.id," received unimplemented ")).call(i,e.method," request")),this.core.replyStateless(e,{statusCode:501});else this.logger.log(E(r="SUBSCRIBE dialog ".concat(this.id," rejected out of order ")).call(r,e.method," request."))}},{key:"refresh",value:function(){var e,t="Allow: "+ct.toString(),n={};return n.extraHeaders=g(e=n.extraHeaders||[]).call(e),n.extraHeaders.push(t),n.extraHeaders.push("Event: "+this.subscriptionEvent),n.extraHeaders.push("Expires: "+this.subscriptionExpiresInitial),n.extraHeaders.push("Contact: "+this.core.configuration.contact.toString()),this.subscribe(void 0,n)}},{key:"subscribe",value:function(e){var t,n=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.subscriptionState!==Et.Pending&&this.subscriptionState!==Et.Active)throw new Error("Invalid state ".concat(this.subscriptionState,'. May only re-subscribe while in state "pending" or "active".'));this.logger.log("SUBSCRIBE dialog ".concat(this.id," sending SUBSCRIBE request"));var r=new Zn(this,e,i);return this.N&&(clearTimeout(this.N),this.N=void 0),(null===(t=i.extraHeaders)||void 0===t?void 0:p(t).call(t,"Expires: 0"))||(this.N=m(function(){return n.timerN()},it.TIMER_N)),r}},{key:"terminate",value:function(){this.stateTransition(Et.Terminated),this.onTerminated()}},{key:"unsubscribe",value:function(){var e,t="Allow: "+ct.toString(),n={};return n.extraHeaders=g(e=n.extraHeaders||[]).call(e),n.extraHeaders.push(t),n.extraHeaders.push("Event: "+this.subscriptionEvent),n.extraHeaders.push("Expires: 0"),n.extraHeaders.push("Contact: "+this.core.configuration.contact.toString()),this.subscribe(void 0,n)}},{key:"onNotify",value:function(e){var t=e.parseHeader("Event").event;if(t&&t===this.subscriptionEvent){this.N&&(clearTimeout(this.N),this.N=void 0);var n=e.parseHeader("Subscription-State");if(n&&n.state){var i=n.state,r=n.expires?Math.max(n.expires,0):void 0;switch(i){case"pending":this.stateTransition(Et.Pending,r);break;case"active":this.stateTransition(Et.Active,r);break;case"terminated":this.stateTransition(Et.Terminated,r);break;default:this.logger.warn("Unrecognized subscription state.")}var s=new yn(this,e);this.delegate&&this.delegate.onNotify?this.delegate.onNotify(s):s.accept()}else this.core.replyStateless(e,{statusCode:489})}else this.core.replyStateless(e,{statusCode:489})}},{key:"onRefresh",value:function(e){this.delegate&&this.delegate.onRefresh&&this.delegate.onRefresh(e)}},{key:"onTerminated",value:function(){this.delegate&&this.delegate.onTerminated&&this.delegate.onTerminated()}},{key:"refreshTimerClear",value:function(){this.refreshTimer&&(clearTimeout(this.refreshTimer),this.refreshTimer=void 0)}},{key:"refreshTimerSet",value:function(){var e=this;if(this.refreshTimerClear(),this.autoRefresh&&this.subscriptionExpires>0){var t=900*this.subscriptionExpires;this._subscriptionRefresh=Math.floor(t/1e3),this._subscriptionRefreshLastSet=Math.floor(r()/1e3),this.refreshTimer=m(function(){e.refreshTimer=void 0,e._subscriptionRefresh=void 0,e._subscriptionRefreshLastSet=void 0,e.onRefresh(e.refresh())},t)}}},{key:"stateTransition",value:function(e,t){var n=this,i=function(){var t;n.logger.warn(E(t="Invalid subscription state transition from ".concat(n.subscriptionState," to ")).call(t,e))};switch(e){case Et.Initial:case Et.NotifyWait:return void i();case Et.Pending:if(this.subscriptionState!==Et.NotifyWait&&this.subscriptionState!==Et.Pending)return void i();break;case Et.Active:case Et.Terminated:if(this.subscriptionState!==Et.NotifyWait&&this.subscriptionState!==Et.Pending&&this.subscriptionState!==Et.Active)return void i();break;default:return void i()}e===Et.Pending&&t&&(this.subscriptionExpires=t),e===Et.Active&&t&&(this.subscriptionExpires=t),e===Et.Terminated&&this.dispose(),this._subscriptionState=e}},{key:"timerN",value:function(){this.logger.warn("Timer N expired for SUBSCRIBE dialog. Timed out waiting for NOTIFY."),this.subscriptionState!==Et.Terminated&&(this.stateTransition(Et.Terminated),this.onTerminated())}}],[{key:"initialDialogStateForSubscription",value:function(e,t){var n=t.getHeaders("record-route"),i=t.parseHeader("contact");if(!i)throw new Error("Contact undefined.");if(!(i instanceof Se))throw new Error("Contact not instance of NameAddrHeader.");var r=i.uri,s=e.cseq,a=e.callId,o=e.fromTag,c=t.fromTag;if(!a)throw new Error("Call id undefined.");if(!o)throw new Error("From tag undefined.");if(!c)throw new Error("To tag undefined.");if(!e.from)throw new Error("From undefined.");if(!e.to)throw new Error("To undefined.");return{id:a+o+c,early:!1,callId:a,localTag:o,remoteTag:c,localSequenceNumber:s,remoteSequenceNumber:undefined,localURI:e.from.uri,remoteURI:e.to.uri,remoteTarget:r,routeSet:n,secure:!1}}}])}();function ei(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(ei=function(){return!!e})()}function ti(e,t,n,i){var r=v(o(1&i?e.prototype:e),t,n);return 2&i&&"function"==typeof r?function(e){return r.apply(n,e)}:r}var ni=function(){function n(t,i,r){var c;e(this,n);var l=i.getHeader("Event");if(!l)throw new Error("Event undefined");var u,h,g,f=i.getHeader("Expires");if(!f)throw new Error("Expires undefined");return u=this,g=[Zt,t,i,r],h=o(h=n),c=a(u,ei()?s(h,g||[],o(u).constructor):h.apply(u,g)),d(c,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"dialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"subscriberId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"subscriptionExpires",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"subscriptionExpiresRequested",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"subscriptionEvent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"subscriptionState",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"N",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c.delegate=r,c.subscriberId=i.callId+i.fromTag+l,c.subscriptionExpiresRequested=c.subscriptionExpires=Number(f),c.subscriptionEvent=l,c.subscriptionState=Et.NotifyWait,c.waitNotifyStart(),c}return c(n,en),t(n,[{key:"dispose",value:function(){ti(n,"dispose",this,3)([])}},{key:"onNotify",value:function(e){var t=e.message.parseHeader("Event").event;if(!t||t!==this.subscriptionEvent)return this.logger.warn("Failed to parse event."),void e.reject({statusCode:489});var n=e.message.parseHeader("Subscription-State");if(!n||!n.state)return this.logger.warn("Failed to parse subscription state."),void e.reject({statusCode:489});var i=n.state;switch(i){case"pending":case"active":case"terminated":break;default:return this.logger.warn("Invalid subscription state ".concat(i)),void e.reject({statusCode:489})}if("terminated"!==i&&!e.message.parseHeader("contact"))return this.logger.warn("Failed to parse contact."),void e.reject({statusCode:489});if(this.dialog)throw new Error("Dialog already created. This implementation only supports install of single subscriptions.");switch(this.waitNotifyStop(),this.subscriptionExpires=n.expires?Math.min(this.subscriptionExpires,Math.max(n.expires,0)):this.subscriptionExpires,i){case"pending":this.subscriptionState=Et.Pending;break;case"active":this.subscriptionState=Et.Active;break;case"terminated":this.subscriptionState=Et.Terminated;break;default:throw new Error("Unrecognized state ".concat(i,"."))}if(this.subscriptionState!==Et.Terminated){var r=Qn.initialDialogStateForSubscription(this.message,e.message);this.dialog=new Qn(this.subscriptionEvent,this.subscriptionExpires,this.subscriptionState,this.core,r)}if(this.delegate&&this.delegate.onNotify){var s=e,a=this.dialog;this.delegate.onNotify({request:s,subscription:a})}else e.accept()}},{key:"waitNotifyStart",value:function(){var e=this;this.N||(this.core.subscribers.set(this.subscriberId,this),this.N=m(function(){return e.timerN()},it.TIMER_N))}},{key:"waitNotifyStop",value:function(){this.N&&(this.core.subscribers.delete(this.subscriberId),clearTimeout(this.N),this.N=void 0)}},{key:"receiveResponse",value:function(e){if(this.authenticationGuard(e)){if(e.statusCode&&e.statusCode>=200&&e.statusCode<300){var t=e.getHeader("Expires");if(t){var i=Number(t);i>this.subscriptionExpiresRequested&&this.logger.warn("Expires header in a 200-class response to SUBSCRIBE with a higher value than the one in the request"),i<this.subscriptionExpires&&(this.subscriptionExpires=i)}else this.logger.warn("Expires header missing in a 200-class response to SUBSCRIBE");this.dialog&&this.dialog.subscriptionExpires>this.subscriptionExpires&&(this.dialog.subscriptionExpires=this.subscriptionExpires)}e.statusCode&&e.statusCode>=300&&e.statusCode<700&&this.waitNotifyStop(),ti(n,"receiveResponse",this,3)([e])}}},{key:"timerN",value:function(){this.logger.warn("Timer N expired for SUBSCRIBE user agent client. Timed out waiting for NOTIFY."),this.waitNotifyStop(),this.delegate&&this.delegate.onNotifyTimeout&&this.delegate.onNotifyTimeout()}}])}();function ii(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(ii=function(){return!!e})()}var ri=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,h=[sn,t,i,r],u=o(u=n),c=a(l,ii()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"core",{enumerable:!0,configurable:!0,writable:!0,value:t}),c}return c(n,an),t(n)}(),si=["application/sdp","application/dtmf-relay"],ai=function(){return t(function t(n){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,t),d(this,"configuration",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"dialogs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"subscribers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"userAgentClients",{enumerable:!0,configurable:!0,writable:!0,value:new M}),d(this,"userAgentServers",{enumerable:!0,configurable:!0,writable:!0,value:new M}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.configuration=n,this.delegate=i,this.dialogs=new M,this.subscribers=new M,this.logger=n.loggerFactory.getLogger("sip.user-agent-core")},[{key:"dispose",value:function(){this.reset()}},{key:"reset",value:function(){var e,t,n,i;h(e=this.dialogs).call(e,function(e){return e.dispose()}),this.dialogs.clear(),h(t=this.subscribers).call(t,function(e){return e.dispose()}),this.subscribers.clear(),h(n=this.userAgentClients).call(n,function(e){return e.dispose()}),this.userAgentClients.clear(),h(i=this.userAgentServers).call(i,function(e){return e.dispose()}),this.userAgentServers.clear()}},{key:"loggerFactory",get:function(){return this.configuration.loggerFactory}},{key:"transport",get:function(){var e=this.configuration.transportAccessor();if(!e)throw new Error("Transport undefined.");return e}},{key:"invite",value:function(e,t){return new jn(this,e,t)}},{key:"message",value:function(e,t){return new fn(this,e,t)}},{key:"publish",value:function(e,t){return new Gn(this,e,t)}},{key:"register",value:function(e,t){return new Wn(this,e,t)}},{key:"subscribe",value:function(e,t){return new ni(this,e,t)}},{key:"request",value:function(e,t){return new en(Zt,this,e,t)}},{key:"makeOutgoingRequestMessage",value:function(e,t,n,i,r,s,a){var o,c=this.configuration.sipjsId,l=this.configuration.displayName,u=this.configuration.viaForceRport,d=this.configuration.hackViaTcp,h=g(o=this.configuration.supportedOptionTags).call(o);e===st.REGISTER&&h.push("path","gruu"),e===st.INVITE&&(this.configuration.contact.pubGruu||this.configuration.contact.tempGruu)&&h.push("gruu");var f=this.configuration.routeSet,v=this.configuration.userAgentHeaderFieldValue,p=this.configuration.viaHost,m=$($({},{callIdPrefix:c,forceRport:u,fromDisplayName:l,hackViaTcp:d,optionTags:h,routeSet:f,userAgentString:v,viaHost:p}),r);return new Ze(e,t,n,i,m,s,a)}},{key:"receiveIncomingRequestFromTransport",value:function(e){this.receiveRequestFromTransport(e)}},{key:"receiveIncomingResponseFromTransport",value:function(e){this.receiveResponseFromTransport(e)}},{key:"replyStateless",value:function(e,t){var n=this,i=this.configuration.userAgentHeaderFieldValue,r=this.configuration.supportedOptionTagsResponse;t=$($({},t),{userAgent:i,supported:r});var s=Nt(e,t);return this.transport.send(s.message).catch(function(t){t instanceof Error&&n.logger.error(t.message),n.logger.error("Transport error occurred sending stateless reply to ".concat(e.method," request."))}),s}},{key:"receiveRequestFromTransport",value:function(e){var t=e.viaBranch,n=this.userAgentServers.get(t);e.method===st.ACK&&n&&n.transaction.state===Lt.Accepted&&n instanceof Bn?this.logger.warn("Discarding out of dialog ACK after 2xx response sent on transaction ".concat(t,".")):e.method!==st.CANCEL?n?n.transaction.receiveRequest(e):this.receiveRequest(e):n?(this.replyStateless(e,{statusCode:200}),n.transaction instanceof Wt&&n.transaction.state===Lt.Proceeding&&n instanceof Bn&&n.receiveCancel(e)):this.replyStateless(e,{statusCode:481})}},{key:"receiveRequest",value:function(e){if(p(ct).call(ct,e.method)){if(!e.ruri)throw new Error("Request-URI undefined.");if("sip"===e.ruri.scheme){var t=e.ruri,n=function(e){return!!e&&e.user===t.user};if(!n(this.configuration.aor)&&!(n(this.configuration.contact.uri)||n(this.configuration.contact.pubGruu)||n(this.configuration.contact.tempGruu)))return this.logger.warn("Request-URI does not point to us."),void(e.method!==st.ACK&&this.replyStateless(e,{statusCode:404}));if(e.method!==st.INVITE||e.hasHeader("Contact")){if(!e.toTag){var i,r,s=e.viaBranch;if(!this.userAgentServers.has(s))if(U(i=D(B(r=this.userAgentServers).call(r))).call(i,function(t){return t.transaction.request.fromTag===e.fromTag&&t.transaction.request.callId===e.callId&&t.transaction.request.cseq===e.cseq}))return void this.replyStateless(e,{statusCode:482})}e.toTag?this.receiveInsideDialogRequest(e):this.receiveOutsideDialogRequest(e)}else this.replyStateless(e,{statusCode:400,reasonPhrase:"Missing Contact Header"})}else this.replyStateless(e,{statusCode:416})}else{var a="Allow: "+ct.toString();this.replyStateless(e,{statusCode:405,extraHeaders:[a]})}}},{key:"receiveInsideDialogRequest",value:function(e){if(e.method===st.NOTIFY){var t=e.parseHeader("Event");if(!t||!t.event)return void this.replyStateless(e,{statusCode:489});var n=e.callId+e.toTag+t.event,i=this.subscribers.get(n);if(i){var r=new yn(this,e);return void i.onNotify(r)}}var s=e.callId+e.toTag+e.fromTag,a=this.dialogs.get(s);if(a){if(e.method===st.OPTIONS){var o="Allow: "+ct.toString(),c="Accept: "+si.toString();return void this.replyStateless(e,{statusCode:200,extraHeaders:[o,c]})}a.receiveRequest(e)}else e.method!==st.ACK&&this.replyStateless(e,{statusCode:481})}},{key:"receiveOutsideDialogRequest",value:function(e){switch(e.method){case st.ACK:break;case st.BYE:this.replyStateless(e,{statusCode:481});break;case st.CANCEL:throw new Error("Unexpected out of dialog request method ".concat(e.method,"."));case st.INFO:this.replyStateless(e,{statusCode:405});break;case st.INVITE:var t=new Bn(this,e);this.delegate.onInvite?this.delegate.onInvite(t):t.reject();break;case st.MESSAGE:var n=new pn(this,e);this.delegate.onMessage?this.delegate.onMessage(n):n.accept();break;case st.NOTIFY:var i=new yn(this,e);this.delegate.onNotify?this.delegate.onNotify(i):i.reject({statusCode:405});break;case st.OPTIONS:var r="Allow: "+ct.toString(),s="Accept: "+si.toString();this.replyStateless(e,{statusCode:200,extraHeaders:[r,s]});break;case st.REFER:var a=new $n(this,e);this.delegate.onRefer?this.delegate.onRefer(a):a.reject({statusCode:405});break;case st.REGISTER:var o=new Kn(this,e);this.delegate.onRegister?this.delegate.onRegister(o):o.reject({statusCode:405});break;case st.SUBSCRIBE:var c=new ri(this,e);this.delegate.onSubscribe?this.delegate.onSubscribe(c):c.reject({statusCode:480});break;default:throw new Error("Unexpected out of dialog request method ".concat(e.method,"."))}}},{key:"receiveResponseFromTransport",value:function(e){if(e.getHeaders("via").length>1)this.logger.warn("More than one Via header field present in the response, dropping");else{var t,n,i=e.viaBranch+e.method,r=this.userAgentClients.get(i);if(r)r.transaction.receiveResponse(e);else this.logger.warn(E(t=E(n="Discarding unmatched ".concat(e.statusCode," response to ")).call(n,e.method," ")).call(t,i,"."))}}}])}();var oi=function(){function r(t,n,i){e(this,r),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"mediaStreamFactory",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"sessionDescriptionHandlerConfiguration",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_localMediaStream",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_remoteMediaStream",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_dataChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_peerConnection",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_peerConnectionDelegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"iceGatheringCompletePromise",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"iceGatheringCompleteTimeoutId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"iceGatheringCompleteResolve",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"iceGatheringCompleteReject",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"localMediaStreamConstraints",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"onDataChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),t.debug("SessionDescriptionHandler.constructor"),this.logger=t,this.mediaStreamFactory=n,this.sessionDescriptionHandlerConfiguration=i,this._localMediaStream=new MediaStream,this._remoteMediaStream=new MediaStream,this._peerConnection=new RTCPeerConnection(null==i?void 0:i.peerConnectionConfiguration),this.initPeerConnectionEventHandlers()}return t(r,[{key:"localMediaStream",get:function(){return this._localMediaStream}},{key:"remoteMediaStream",get:function(){return this._remoteMediaStream}},{key:"dataChannel",get:function(){return this._dataChannel}},{key:"peerConnection",get:function(){return this._peerConnection}},{key:"peerConnectionDelegate",get:function(){return this._peerConnectionDelegate},set:function(e){this._peerConnectionDelegate=e}},{key:"close",value:function(){var e,t;this.logger.debug("SessionDescriptionHandler.close"),void 0!==this._peerConnection&&(h(e=this._peerConnection.getReceivers()).call(e,function(e){e.track&&e.track.stop()}),h(t=this._peerConnection.getSenders()).call(t,function(e){e.track&&e.track.stop()}),this._dataChannel&&this._dataChannel.close(),this._peerConnection.close(),this._peerConnection=void 0)}},{key:"enableReceiverTracks",value:function(e){var t,n=this.peerConnection;if(!n)throw new Error("Peer connection closed.");h(t=n.getReceivers()).call(t,function(t){t.track&&(t.track.enabled=e)})}},{key:"enableSenderTracks",value:function(e){var t,n=this.peerConnection;if(!n)throw new Error("Peer connection closed.");h(t=n.getSenders()).call(t,function(t){t.track&&(t.track.enabled=e)})}},{key:"getDescription",value:function(e,t){var n,r,s=this;if(this.logger.debug("SessionDescriptionHandler.getDescription"),void 0===this._peerConnection)return i.reject(new Error("Peer connection closed."));this.onDataChannel=null==e?void 0:e.onDataChannel;var a=null===(n=null==e?void 0:e.offerOptions)||void 0===n?void 0:n.iceRestart,o=void 0===(null==e?void 0:e.iceGatheringTimeout)?null===(r=this.sessionDescriptionHandlerConfiguration)||void 0===r?void 0:r.iceGatheringTimeout:null==e?void 0:e.iceGatheringTimeout;return this.getLocalMediaStream(e).then(function(){return s.updateDirection(e)}).then(function(){return s.createDataChannel(e)}).then(function(){return s.createLocalOfferOrAnswer(e)}).then(function(e){return s.applyModifiers(e,t)}).then(function(e){return s.setLocalSessionDescription(e)}).then(function(){return s.waitForIceGatheringComplete(a,o)}).then(function(){return s.getLocalSessionDescription()}).then(function(t){var n=null==e?void 0:e.finalModifiers;return n&&0!==n.length?(s.logger.debug("SessionDescriptionHandler.getDescription - applying final SDP modifiers"),s.applyFinalModifiers(t,n)):t}).then(function(e){var t=e.sdp||"";return s.logger.log("SessionDescriptionHandler.getDescription - final SDP "+C({hasRecoveryReason:p(t).call(t,"a=x-recovery-reason:"),hasReinviteReason:p(t).call(t,"a=x-reinvite-reason:")})),{body:t,contentType:"application/sdp"}}).catch(function(e){throw s.logger.error("SessionDescriptionHandler.getDescription failed - "+e),e})}},{key:"hasDescription",value:function(e){return this.logger.debug("SessionDescriptionHandler.hasDescription"),"application/sdp"===e}},{key:"iceGatheringComplete",value:function(){this.logger.debug("SessionDescriptionHandler.iceGatheringComplete"),void 0!==this.iceGatheringCompleteTimeoutId&&(this.logger.debug("SessionDescriptionHandler.iceGatheringComplete - clearing timeout"),clearTimeout(this.iceGatheringCompleteTimeoutId),this.iceGatheringCompleteTimeoutId=void 0),void 0!==this.iceGatheringCompletePromise&&(this.logger.debug("SessionDescriptionHandler.iceGatheringComplete - resolving promise"),this.iceGatheringCompleteResolve&&this.iceGatheringCompleteResolve(),this.iceGatheringCompletePromise=void 0,this.iceGatheringCompleteResolve=void 0,this.iceGatheringCompleteReject=void 0)}},{key:"sendDtmf",value:function(e,t){if(this.logger.debug("SessionDescriptionHandler.sendDtmf"),void 0===this._peerConnection)return this.logger.error("SessionDescriptionHandler.sendDtmf failed - peer connection closed"),!1;var n=this._peerConnection.getSenders();if(0===n.length)return this.logger.error("SessionDescriptionHandler.sendDtmf failed - no senders"),!1;var i=n[0].dtmf;if(!i)return this.logger.error("SessionDescriptionHandler.sendDtmf failed - no DTMF sender"),!1;var r=null==t?void 0:t.duration,s=null==t?void 0:t.interToneGap;try{i.insertDTMF(e,r,s)}catch(e){return this.logger.error(e.toString()),!1}return this.logger.log("SessionDescriptionHandler.sendDtmf sent via RTP: "+e.toString()),!0}},{key:"setDescription",value:function(e,t,n){var r=this;if(this.logger.debug("SessionDescriptionHandler.setDescription"),void 0===this._peerConnection)return i.reject(new Error("Peer connection closed."));this.onDataChannel=null==t?void 0:t.onDataChannel;var s="have-local-offer"===this._peerConnection.signalingState?"answer":"offer";return this.getLocalMediaStream(t).then(function(){return r.applyModifiers({sdp:e,type:s},n)}).then(function(e){return r.setRemoteSessionDescription(e)}).catch(function(e){throw r.logger.error("SessionDescriptionHandler.setDescription failed - "+e),e})}},{key:"applyFinalModifiers",value:function(e,t){var r=this;return this.logger.debug("SessionDescriptionHandler.applyFinalModifiers"),t&&0!==t.length?O(t).call(t,function(e,t){return e.then(function(e){return ne(r,void 0,void 0,n.mark(function i(){var r,s;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=1,t(e);case 1:if((s=n.sent)&&s.sdp){n.next=2;break}throw new Error("Invalid final SDP.");case 2:return n.abrupt("return",{sdp:s.sdp,type:null!==(r=s.type)&&void 0!==r?r:e.type});case 3:case"end":return n.stop()}},i)}))})},i.resolve({sdp:e.sdp,type:e.type})):i.resolve(e)}},{key:"applyModifiers",value:function(e,t){var n=this;return this.logger.debug("SessionDescriptionHandler.applyModifiers"),t&&0!==t.length?O(t).call(t,function(e,t){return e.then(t)},i.resolve(e)).then(function(e){if(n.logger.debug("SessionDescriptionHandler.applyModifiers - modified sdp"),!e.sdp||!e.type)throw new Error("Invalid SDP.");return{sdp:e.sdp,type:e.type}}):i.resolve(e)}},{key:"createDataChannel",value:function(e){if(void 0===this._peerConnection)return i.reject(new Error("Peer connection closed."));if(!0!==(null==e?void 0:e.dataChannel))return i.resolve();if(this._dataChannel)return i.resolve();switch(this._peerConnection.signalingState){case"stable":this.logger.debug("SessionDescriptionHandler.createDataChannel - creating data channel");try{return this._dataChannel=this._peerConnection.createDataChannel((null==e?void 0:e.dataChannelLabel)||"",null==e?void 0:e.dataChannelOptions),this.onDataChannel&&this.onDataChannel(this._dataChannel),i.resolve()}catch(e){return i.reject(e)}case"have-remote-offer":return i.resolve();default:return i.reject(new Error("Invalid signaling state "+this._peerConnection.signalingState))}}},{key:"createLocalOfferOrAnswer",value:function(e){if(void 0===this._peerConnection)return i.reject(new Error("Peer connection closed."));switch(this._peerConnection.signalingState){case"stable":return this.logger.debug("SessionDescriptionHandler.createLocalOfferOrAnswer - creating SDP offer"),this._peerConnection.createOffer(null==e?void 0:e.offerOptions);case"have-remote-offer":return this.logger.debug("SessionDescriptionHandler.createLocalOfferOrAnswer - creating SDP answer"),this._peerConnection.createAnswer(null==e?void 0:e.answerOptions);default:return i.reject(new Error("Invalid signaling state "+this._peerConnection.signalingState))}}},{key:"getLocalMediaStream",value:function(e){var t=this;if(this.logger.debug("SessionDescriptionHandler.getLocalMediaStream"),void 0===this._peerConnection)return i.reject(new Error("Peer connection closed."));var n=$({},null==e?void 0:e.constraints);if(this.localMediaStreamConstraints){if(n.audio=n.audio||this.localMediaStreamConstraints.audio,n.video=n.video||this.localMediaStreamConstraints.video,C(this.localMediaStreamConstraints.audio)===C(n.audio)&&C(this.localMediaStreamConstraints.video)===C(n.video))return i.resolve()}else void 0===n.audio&&void 0===n.video&&(n={audio:!0});return this.localMediaStreamConstraints=n,this.mediaStreamFactory(n,this,e).then(function(e){return t.setLocalMediaStream(e)})}},{key:"setLocalMediaStream",value:function(e){var t=this;if(this.logger.debug("SessionDescriptionHandler.setLocalMediaStream"),!this._peerConnection)throw new Error("Peer connection undefined.");var n=this._peerConnection,s=this._localMediaStream,a=[],o=function(e){var o,c=e.kind;if("audio"!==c&&"video"!==c)throw new Error("Unknown new track kind ".concat(c,"."));var l=V(o=n.getSenders()).call(o,function(e){return e.track&&e.track.kind===c});l?a.push(new i(function(e){t.logger.debug("SessionDescriptionHandler.setLocalMediaStream - replacing sender ".concat(c," track")),e()}).then(function(){return l.replaceTrack(e).then(function(){var t,n=V(t=s.getTracks()).call(t,function(e){return e.kind===c});n&&(n.stop(),s.removeTrack(n),r.dispatchRemoveTrackEvent(s,n)),s.addTrack(e),r.dispatchAddTrackEvent(s,e)}).catch(function(e){throw t.logger.error("SessionDescriptionHandler.setLocalMediaStream - failed to replace sender ".concat(c," track")),e})})):a.push(new i(function(e){t.logger.debug("SessionDescriptionHandler.setLocalMediaStream - adding sender ".concat(c," track")),e()}).then(function(){try{n.addTrack(e,s)}catch(e){throw t.logger.error("SessionDescriptionHandler.setLocalMediaStream - failed to add sender ".concat(c," track")),e}s.addTrack(e),r.dispatchAddTrackEvent(s,e)}))},c=e.getAudioTracks();c.length&&o(c[0]);var l=e.getVideoTracks();return l.length&&o(l[0]),O(a).call(a,function(e,t){return e.then(function(){return t})},i.resolve())}},{key:"getLocalSessionDescription",value:function(){if(this.logger.debug("SessionDescriptionHandler.getLocalSessionDescription"),void 0===this._peerConnection)return i.reject(new Error("Peer connection closed."));var e=this._peerConnection.localDescription;return e?i.resolve(e):i.reject(new Error("Failed to get local session description"))}},{key:"setLocalSessionDescription",value:function(e){return this.logger.debug("SessionDescriptionHandler.setLocalSessionDescription"),void 0===this._peerConnection?i.reject(new Error("Peer connection closed.")):this._peerConnection.setLocalDescription(e)}},{key:"setRemoteSessionDescription",value:function(e){if(this.logger.debug("SessionDescriptionHandler.setRemoteSessionDescription"),void 0===this._peerConnection)return i.reject(new Error("Peer connection closed."));var t,n=e.sdp;switch(this._peerConnection.signalingState){case"stable":t="offer";break;case"have-local-offer":t="answer";break;default:return i.reject(new Error("Invalid signaling state "+this._peerConnection.signalingState))}return n?this._peerConnection.setRemoteDescription({sdp:n,type:t}):(this.logger.error("SessionDescriptionHandler.setRemoteSessionDescription failed - cannot set null sdp"),i.reject(new Error("SDP is undefined")))}},{key:"setRemoteTrack",value:function(e){this.logger.debug("SessionDescriptionHandler.setRemoteTrack");var t=this._remoteMediaStream;if(t.getTrackById(e.id))this.logger.debug("SessionDescriptionHandler.setRemoteTrack - have remote ".concat(e.kind," track"));else if("audio"===e.kind){var n;this.logger.debug("SessionDescriptionHandler.setRemoteTrack - adding remote ".concat(e.kind," track")),h(n=t.getAudioTracks()).call(n,function(e){e.stop(),t.removeTrack(e),r.dispatchRemoveTrackEvent(t,e)}),t.addTrack(e),r.dispatchAddTrackEvent(t,e)}else if("video"===e.kind){var i;this.logger.debug("SessionDescriptionHandler.setRemoteTrack - adding remote ".concat(e.kind," track")),h(i=t.getVideoTracks()).call(i,function(e){e.stop(),t.removeTrack(e),r.dispatchRemoveTrackEvent(t,e)}),t.addTrack(e),r.dispatchAddTrackEvent(t,e)}}},{key:"updateDirection",value:function(e){var t=this;if(void 0===this._peerConnection)return i.reject(new Error("Peer connection closed."));switch(this._peerConnection.signalingState){case"stable":this.logger.debug("SessionDescriptionHandler.updateDirection - setting offer direction");var n;h(n=this._peerConnection.getTransceivers()).call(n,function(t){if(t.direction){var n=function(t){switch(t){case"inactive":case"recvonly":return(null==e?void 0:e.hold)?"inactive":"recvonly";case"sendonly":case"sendrecv":return(null==e?void 0:e.hold)?"sendonly":"sendrecv";case"stopped":return"stopped";default:throw new Error("Should never happen")}}(t.direction);t.direction!==n&&(t.direction=n)}});break;case"have-remote-offer":this.logger.debug("SessionDescriptionHandler.updateDirection - setting answer direction");var r,s=function(){var e=t._peerConnection.remoteDescription;if(!e)throw new Error("Failed to read remote offer");var n=/a=sendrecv\r\n|a=sendonly\r\n|a=recvonly\r\n|a=inactive\r\n/.exec(e.sdp);if(n)switch(n[0]){case"a=inactive\r\n":return"inactive";case"a=recvonly\r\n":return"recvonly";case"a=sendonly\r\n":return"sendonly";case"a=sendrecv\r\n":return"sendrecv";default:throw new Error("Should never happen")}return"sendrecv"}(),a=function(){switch(s){case"inactive":return"inactive";case"recvonly":return"sendonly";case"sendonly":return(null==e?void 0:e.hold)?"inactive":"recvonly";case"sendrecv":return(null==e?void 0:e.hold)?"sendonly":"sendrecv";default:throw new Error("Should never happen")}}();h(r=this._peerConnection.getTransceivers()).call(r,function(e){e.direction&&"stopped"!==e.direction&&e.direction!==a&&(e.direction=a)});break;default:return i.reject(new Error("Invalid signaling state "+this._peerConnection.signalingState))}return i.resolve()}},{key:"waitForIceGatheringComplete",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return this.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete"),void 0===this._peerConnection?i.reject("Peer connection closed."):t||"complete"!==this._peerConnection.iceGatheringState?(void 0!==this.iceGatheringCompletePromise&&(this.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete - rejecting prior waiting promise"),this.iceGatheringCompleteReject&&this.iceGatheringCompleteReject(new Error("Promise superseded.")),this.iceGatheringCompletePromise=void 0,this.iceGatheringCompleteResolve=void 0,this.iceGatheringCompleteReject=void 0),this.iceGatheringCompletePromise=new i(function(t,i){e.iceGatheringCompleteResolve=t,e.iceGatheringCompleteReject=i,n>0&&(e.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete - timeout in "+n),e.iceGatheringCompleteTimeoutId=m(function(){e.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete - timeout"),e.iceGatheringComplete()},n))}),this.iceGatheringCompletePromise):(this.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete - already complete"),i.resolve())}},{key:"initPeerConnectionEventHandlers",value:function(){var e=this;if(this.logger.debug("SessionDescriptionHandler.initPeerConnectionEventHandlers"),!this._peerConnection)throw new Error("Peer connection undefined.");var t=this._peerConnection;t.onconnectionstatechange=function(n){var i,r=t.connectionState;e.logger.debug("SessionDescriptionHandler.onconnectionstatechange ".concat(r)),(null===(i=e._peerConnectionDelegate)||void 0===i?void 0:i.onconnectionstatechange)&&e._peerConnectionDelegate.onconnectionstatechange(n)},t.ondatachannel=function(t){var n;e.logger.debug("SessionDescriptionHandler.ondatachannel"),e._dataChannel=t.channel,e.onDataChannel&&e.onDataChannel(e._dataChannel),(null===(n=e._peerConnectionDelegate)||void 0===n?void 0:n.ondatachannel)&&e._peerConnectionDelegate.ondatachannel(t)},t.onicecandidate=function(t){var n;e.logger.debug("SessionDescriptionHandler.onicecandidate"),(null===(n=e._peerConnectionDelegate)||void 0===n?void 0:n.onicecandidate)&&e._peerConnectionDelegate.onicecandidate(t)},t.onicecandidateerror=function(t){var n;e.logger.debug("SessionDescriptionHandler.onicecandidateerror"),(null===(n=e._peerConnectionDelegate)||void 0===n?void 0:n.onicecandidateerror)&&e._peerConnectionDelegate.onicecandidateerror(t)},t.oniceconnectionstatechange=function(n){var i,r=t.iceConnectionState;e.logger.debug("SessionDescriptionHandler.oniceconnectionstatechange ".concat(r)),(null===(i=e._peerConnectionDelegate)||void 0===i?void 0:i.oniceconnectionstatechange)&&e._peerConnectionDelegate.oniceconnectionstatechange(n)},t.onicegatheringstatechange=function(n){var i,r=t.iceGatheringState;e.logger.debug("SessionDescriptionHandler.onicegatheringstatechange ".concat(r)),"complete"===r&&e.iceGatheringComplete(),(null===(i=e._peerConnectionDelegate)||void 0===i?void 0:i.onicegatheringstatechange)&&e._peerConnectionDelegate.onicegatheringstatechange(n)},t.onnegotiationneeded=function(t){var n;e.logger.debug("SessionDescriptionHandler.onnegotiationneeded"),(null===(n=e._peerConnectionDelegate)||void 0===n?void 0:n.onnegotiationneeded)&&e._peerConnectionDelegate.onnegotiationneeded(t)},t.onsignalingstatechange=function(n){var i,r=t.signalingState;e.logger.debug("SessionDescriptionHandler.onsignalingstatechange ".concat(r)),(null===(i=e._peerConnectionDelegate)||void 0===i?void 0:i.onsignalingstatechange)&&e._peerConnectionDelegate.onsignalingstatechange(n)},t.ontrack=function(t){var n,i,r=t.track.kind,s=t.track.enabled?"enabled":"disabled";e.logger.debug(E(n="SessionDescriptionHandler.ontrack ".concat(r," ")).call(n,s)),e.setRemoteTrack(t.track),(null===(i=e._peerConnectionDelegate)||void 0===i?void 0:i.ontrack)&&e._peerConnectionDelegate.ontrack(t)}}}],[{key:"dispatchAddTrackEvent",value:function(e,t){e.dispatchEvent(new MediaStreamTrackEvent("addtrack",{track:t}))}},{key:"dispatchRemoveTrackEvent",value:function(e,t){e.dispatchEvent(new MediaStreamTrackEvent("removetrack",{track:t}))}}])}();function ci(e){return function(t,n){void 0===e&&(e=function(e){return e.audio||e.video?void 0===navigator.mediaDevices?i.reject(new Error("Media devices not available in insecure contexts.")):navigator.mediaDevices.getUserMedia.call(navigator.mediaDevices,e):i.resolve(new MediaStream)});var r={iceGatheringTimeout:void 0!==(null==n?void 0:n.iceGatheringTimeout)?null==n?void 0:n.iceGatheringTimeout:5e3,peerConnectionConfiguration:$($({},{bundlePolicy:"balanced",certificates:void 0,iceCandidatePoolSize:0,iceServers:[{urls:"stun:stun.l.google.com:19302"}],iceTransportPolicy:"all",rtcpMuxPolicy:"require"}),null==n?void 0:n.peerConnectionConfiguration)},s=t.userAgent.getLogger("sip.SessionDescriptionHandler");return new oi(s,e,r)}}var li=function(){return t(function t(n,i){var r;if(e(this,t),d(this,"onConnect",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"onDisconnect",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"onMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_protocol",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:At.Disconnected}),d(this,"_stateEventEmitter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_ws",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"configuration",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"connectPromise",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"connectResolve",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"connectReject",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"connectTimeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"disconnectPromise",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"disconnectResolve",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"disconnectReject",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"keepAliveInterval",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"keepAliveDebounceTimeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"transitioningState",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this._stateEventEmitter=new ye,this.logger=n,i){var s=i,a=null==s?void 0:s.wsServers,o=null==s?void 0:s.maxReconnectionAttempts;if(void 0!==a){this.logger.warn('The transport option "wsServers" as has apparently been specified and has been deprecated. It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.')}if(void 0!==o){this.logger.warn('The transport option "maxReconnectionAttempts" as has apparently been specified and has been deprecated. It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.')}a&&!i.server&&("string"==typeof a&&(i.server=a),a instanceof Array&&(i.server=a[0]))}this.configuration=$($({},t.defaultOptions),i);var c=this.configuration.server,l=He.parse(c,"absoluteURI");if(-1===l)throw this.logger.error('Invalid WebSocket Server URL "'.concat(c,'"')),new Error("Invalid WebSocket Server URL");if(!p(r=["wss","ws","udp"]).call(r,l.scheme))throw this.logger.error('Invalid scheme in WebSocket Server URL "'.concat(c,'"')),new Error("Invalid scheme in WebSocket Server URL");this._protocol=l.scheme.toUpperCase()},[{key:"dispose",value:function(){return this.disconnect()}},{key:"protocol",get:function(){return this._protocol}},{key:"server",get:function(){return this.configuration.server}},{key:"state",get:function(){return this._state}},{key:"stateChange",get:function(){return this._stateEventEmitter}},{key:"ws",get:function(){return this._ws}},{key:"connect",value:function(){return this._connect()}},{key:"disconnect",value:function(){return this._disconnect()}},{key:"isConnected",value:function(){return this.state===At.Connected}},{key:"send",value:function(e){return this._send(e)}},{key:"_connect",value:function(){var e,t=this;switch(this.logger.log("Connecting ".concat(this.server)),this.state){case At.Connecting:if(this.transitioningState)return i.reject(this.transitionLoopDetectedError(At.Connecting));if(!this.connectPromise)throw new Error("Connect promise must be defined.");return this.connectPromise;case At.Connected:if(this.transitioningState)return i.reject(this.transitionLoopDetectedError(At.Connecting));if(this.connectPromise)throw new Error("Connect promise must not be defined.");return i.resolve();case At.Disconnecting:if(this.connectPromise)throw new Error("Connect promise must not be defined.");try{this.transitionState(At.Connecting)}catch(e){if(e instanceof pe)return i.reject(e);throw e}break;case At.Disconnected:if(this.connectPromise)throw new Error("Connect promise must not be defined.");try{this.transitionState(At.Connecting)}catch(e){if(e instanceof pe)return i.reject(e);throw e}break;default:throw new Error("Unknown state")}try{(e=new WebSocket(this.server,"sip")).binaryType="arraybuffer",e.addEventListener("close",function(n){return t.onWebSocketClose(n,e)}),e.addEventListener("error",function(n){return t.onWebSocketError(n,e)}),e.addEventListener("open",function(n){return t.onWebSocketOpen(n,e)}),e.addEventListener("message",function(n){return t.onWebSocketMessage(n,e)}),this._ws=e}catch(e){return this._ws=void 0,this.logger.error("WebSocket construction failed."),this.logger.error(e.toString()),new i(function(n,i){t.connectResolve=n,t.connectReject=i,t.transitionState(At.Disconnected,e)})}return this.connectPromise=new i(function(n,i){t.connectResolve=n,t.connectReject=i,t.connectTimeout=m(function(){t.logger.warn("Connect timed out. Exceeded time set in configuration.connectionTimeout: "+t.configuration.connectionTimeout+"s."),e.close(1e3)},1e3*t.configuration.connectionTimeout)}),this.connectPromise}},{key:"_disconnect",value:function(){var e=this;switch(this.logger.log("Disconnecting ".concat(this.server)),this.state){case At.Connecting:if(this.disconnectPromise)throw new Error("Disconnect promise must not be defined.");try{this.transitionState(At.Disconnecting)}catch(e){if(e instanceof pe)return i.reject(e);throw e}break;case At.Connected:if(this.disconnectPromise)throw new Error("Disconnect promise must not be defined.");try{this.transitionState(At.Disconnecting)}catch(e){if(e instanceof pe)return i.reject(e);throw e}break;case At.Disconnecting:if(this.transitioningState)return i.reject(this.transitionLoopDetectedError(At.Disconnecting));if(!this.disconnectPromise)throw new Error("Disconnect promise must be defined.");return this.disconnectPromise;case At.Disconnected:if(this.transitioningState)return i.reject(this.transitionLoopDetectedError(At.Disconnecting));if(this.disconnectPromise)throw new Error("Disconnect promise must not be defined.");return i.resolve();default:throw new Error("Unknown state")}if(!this._ws)throw new Error("WebSocket must be defined.");var t=this._ws;return this.disconnectPromise=new i(function(n,i){e.disconnectResolve=n,e.disconnectReject=i;try{t.close(1e3)}catch(t){throw e.logger.error("WebSocket close failed."),e.logger.error(t.toString()),t}}),this.disconnectPromise}},{key:"_send",value:function(e){if(!0===this.configuration.traceSip&&this.logger.log("Sending WebSocket message:\n\n"+e+"\n"),this._state!==At.Connected)return i.reject(new Error("Not connected."));if(!this._ws)throw new Error("WebSocket undefined.");try{this._ws.send(e)}catch(e){return e instanceof Error?i.reject(e):i.reject(new Error("WebSocket send failed."))}return i.resolve()}},{key:"onWebSocketClose",value:function(e,t){var n;if(t===this._ws){var i=E(n="WebSocket closed ".concat(this.server," (code: ")).call(n,e.code,")"),r=this.disconnectPromise?void 0:new Error(i);r&&this.logger.warn("WebSocket closed unexpectedly"),this.logger.log(i),this._ws=void 0,this.transitionState(At.Disconnected,r)}}},{key:"onWebSocketError",value:function(e,t){t===this._ws&&this.logger.error("WebSocket error occurred.")}},{key:"onWebSocketMessage",value:function(e,t){if(t===this._ws){var n,i=e.data;if(/^(\r\n)+$/.test(i))return this.clearKeepAliveTimeout(),void(!0===this.configuration.traceSip&&this.logger.log("Received WebSocket message with CRLF Keep Alive response"));if(i){if("string"!=typeof i){try{n=(new TextDecoder).decode(new Uint8Array(i))}catch(e){return this.logger.error(e.toString()),void this.logger.error("Received WebSocket binary message failed to be converted into string, message discarded")}!0===this.configuration.traceSip&&this.logger.log("Received WebSocket binary message:\n\n"+n+"\n")}else n=i,!0===this.configuration.traceSip&&this.logger.log("Received WebSocket text message:\n\n"+n+"\n");if(this.state===At.Connected){if(this.onMessage)try{this.onMessage(n)}catch(e){throw this.logger.error(e.toString()),this.logger.error("Exception thrown by onMessage callback"),e}}else this.logger.warn("Received message while not connected, discarding...")}else this.logger.warn("Received empty message, discarding...")}}},{key:"onWebSocketOpen",value:function(e,t){t===this._ws&&this._state===At.Connecting&&(this.logger.log("WebSocket opened ".concat(this.server)),this.transitionState(At.Connected))}},{key:"transitionLoopDetectedError",value:function(e){var t,n="A state transition loop has been detected.";return n+=E(t=" An attempt to transition from ".concat(this._state," to ")).call(t,e," before the prior transition completed."),n+=" Perhaps you are synchronously calling connect() or disconnect() from a callback or state change handler?",this.logger.error(n),new pe("Loop detected.")}},{key:"transitionState",value:function(e,t){var n,i=this,r=function(){var t;throw new Error(E(t="Invalid state transition from ".concat(i._state," to ")).call(t,e))};if(this.transitioningState)throw this.transitionLoopDetectedError(e);switch(this.transitioningState=!0,this._state){case At.Connecting:e!==At.Connected&&e!==At.Disconnecting&&e!==At.Disconnected&&r();break;case At.Connected:e!==At.Disconnecting&&e!==At.Disconnected&&r();break;case At.Disconnecting:e!==At.Connecting&&e!==At.Disconnected&&r();break;case At.Disconnected:e!==At.Connecting&&r();break;default:throw new Error("Unknown state.")}var s=this._state;this._state=e;var a=this.connectResolve,o=this.connectReject;s===At.Connecting&&(this.connectPromise=void 0,this.connectResolve=void 0,this.connectReject=void 0);var c=this.disconnectResolve,l=this.disconnectReject;if(s===At.Disconnecting&&(this.disconnectPromise=void 0,this.disconnectResolve=void 0,this.disconnectReject=void 0),this.connectTimeout&&(clearTimeout(this.connectTimeout),this.connectTimeout=void 0),this.logger.log(E(n="Transitioned from ".concat(s," to ")).call(n,this._state)),this._stateEventEmitter.emit(this._state),e===At.Connected&&(this.startSendingKeepAlives(),this.onConnect))try{this.onConnect()}catch(e){throw this.logger.error(e.toString()),this.logger.error("Exception thrown by onConnect callback"),e}if(s===At.Connected&&(this.stopSendingKeepAlives(),this.onDisconnect))try{t?this.onDisconnect(t):this.onDisconnect()}catch(e){throw this.logger.error(e.toString()),this.logger.error("Exception thrown by onDisconnect callback"),e}if(s===At.Connecting){if(!a)throw new Error("Connect resolve undefined.");if(!o)throw new Error("Connect reject undefined.");e===At.Connected?a():o(t||new Error("Connect aborted."))}if(s===At.Disconnecting){if(!c)throw new Error("Disconnect resolve undefined.");if(!l)throw new Error("Disconnect reject undefined.");e===At.Disconnected?c():l(t||new Error("Disconnect aborted."))}this.transitioningState=!1}},{key:"clearKeepAliveTimeout",value:function(){this.keepAliveDebounceTimeout&&clearTimeout(this.keepAliveDebounceTimeout),this.keepAliveDebounceTimeout=void 0}},{key:"sendKeepAlive",value:function(){var e=this;return this.keepAliveDebounceTimeout?i.resolve():(this.keepAliveDebounceTimeout=m(function(){e.clearKeepAliveTimeout()},1e3*this.configuration.keepAliveDebounce),this.send("\r\n\r\n"))}},{key:"startSendingKeepAlives",value:function(){var e,t,n=this;this.configuration.keepAliveInterval&&!this.keepAliveInterval&&(this.keepAliveInterval=L(function(){n.sendKeepAlive(),n.startSendingKeepAlives()},(e=this.configuration.keepAliveInterval,t=.8*e,1e3*(Math.random()*(e-t)+t))))}},{key:"stopSendingKeepAlives",value:function(){this.keepAliveInterval&&clearInterval(this.keepAliveInterval),this.keepAliveDebounceTimeout&&clearTimeout(this.keepAliveDebounceTimeout),this.keepAliveInterval=void 0,this.keepAliveDebounceTimeout=void 0}}])}();d(li,"defaultOptions",{enumerable:!0,configurable:!0,writable:!0,value:{server:"",connectionTimeout:5,keepAliveInterval:0,keepAliveDebounce:10,traceSip:!0}});var ui=function(){return t(function t(){var n,i=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e(this,t),d(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_publishers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),d(this,"_registerers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),d(this,"_sessions",{enumerable:!0,configurable:!0,writable:!0,value:{}}),d(this,"_subscriptions",{enumerable:!0,configurable:!0,writable:!0,value:{}}),d(this,"_contact",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_instanceId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:xt.Stopped}),d(this,"_stateEventEmitter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_transport",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_userAgentCore",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"loggerFactory",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._stateEventEmitter=new ye,this.delegate=r.delegate,this.options=$($($($($({},t.defaultOptions()),{sipjsId:qe(5)}),{uri:new Ee("sip","anonymous."+qe(6),"anonymous.invalid")}),{viaHost:qe(12)+".invalid"}),t.stripUndefinedProperties(r)),this.options.hackIpInContact)if("boolean"==typeof this.options.hackIpInContact&&this.options.hackIpInContact){var s=Math.floor(254*Math.random()+1);this.options.viaHost="192.0.2."+s}else this.options.hackIpInContact&&(this.options.viaHost=this.options.hackIpInContact);switch(this.loggerFactory=new Ot,this.logger=this.loggerFactory.getLogger("sip.UserAgent"),this.loggerFactory.builtinEnabled=this.options.logBuiltinEnabled,this.loggerFactory.connector=this.options.logConnector,this.options.logLevel){case"error":this.loggerFactory.level=$t.error;break;case"warn":this.loggerFactory.level=$t.warn;break;case"log":this.loggerFactory.level=$t.log;break;case"debug":this.loggerFactory.level=$t.debug}if(this.options.logConfiguration&&(this.logger.log("Configuration:"),h(n=A(this.options)).call(n,function(e){var t=i.options[e];switch(e){case"uri":case"sessionDescriptionHandlerFactory":i.logger.log("· "+e+": "+t);break;case"authorizationPassword":i.logger.log("· "+e+": NOT SHOWN");break;case"transportConstructor":i.logger.log("· "+e+": "+t.name);break;default:i.logger.log("· "+e+": "+C(t))}})),this.options.transportOptions){var a=this.options.transportOptions,o=a.maxReconnectionAttempts,c=a.reconnectionTimeout;if(void 0!==o){this.logger.warn('The transport option "maxReconnectionAttempts" as has apparently been specified and has been deprecated. It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.')}if(void 0!==c){this.logger.warn('The transport option "reconnectionTimeout" as has apparently been specified and has been deprecated. It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.')}void 0===r.reconnectionDelay&&void 0!==c&&(this.options.reconnectionDelay=c),void 0===r.reconnectionAttempts&&void 0!==o&&(this.options.reconnectionAttempts=o)}if(void 0!==r.reconnectionDelay){this.logger.warn('The user agent option "reconnectionDelay" as has apparently been specified and has been deprecated. It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.')}if(void 0!==r.reconnectionAttempts){this.logger.warn('The user agent option "reconnectionAttempts" as has apparently been specified and has been deprecated. It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.')}if(this._transport=new this.options.transportConstructor(this.getLogger("sip.Transport"),this.options.transportOptions),this.initTransportCallbacks(),this._contact=this.initContact(),this._instanceId=this.options.instanceId?this.options.instanceId:t.newUUID(),-1===He.parse(this._instanceId,"uuid"))throw new Error("Invalid instanceId.");this._userAgentCore=this.initCore()},[{key:"configuration",get:function(){return this.options}},{key:"contact",get:function(){return this._contact}},{key:"instanceId",get:function(){return this._instanceId}},{key:"state",get:function(){return this._state}},{key:"stateChange",get:function(){return this._stateEventEmitter}},{key:"transport",get:function(){return this._transport}},{key:"userAgentCore",get:function(){return this._userAgentCore}},{key:"getLogger",value:function(e,t){return this.loggerFactory.getLogger(e,t)}},{key:"getLoggerFactory",value:function(){return this.loggerFactory}},{key:"isConnected",value:function(){return this.transport.isConnected()}},{key:"reconnect",value:function(){var e=this;return this.state===xt.Stopped?i.reject(new Error("User agent stopped.")):i.resolve().then(function(){return e.transport.connect()})}},{key:"start",value:function(){return this.state===xt.Started?(this.logger.warn("User agent already started"),i.resolve()):(this.logger.log("Starting ".concat(this.configuration.uri)),this.transitionState(xt.Started),this.transport.connect())}},{key:"stop",value:function(){return ne(this,void 0,void 0,n.mark(function e(){var t,r,s,a,o,c,l,u,d,h,g,f,v,p,m,b,w,y,k,T,R,S,I=this;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.state!==xt.Stopped){e.next=1;break}return this.logger.warn("User agent already stopped"),e.abrupt("return",i.resolve());case 1:if(this.logger.log("Stopping ".concat(this.configuration.uri)),this.options.gracefulShutdown){e.next=2;break}return this.logger.log("Dispose of transport"),this.transport.dispose().catch(function(e){throw I.logger.error(e.message),e}),this.logger.log("Dispose of core"),this.userAgentCore.dispose(),this._publishers={},this._registerers={},this._sessions={},this._subscriptions={},this.transitionState(xt.Stopped),e.abrupt("return",i.resolve());case 2:t=$({},this._publishers),r=$({},this._registerers),s=$({},this._sessions),a=$({},this._subscriptions),o=this.transport,c=this.userAgentCore,this.logger.log("Dispose of registerers"),l=n.mark(function e(t){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!r[t]){e.next=1;break}return e.next=1,r[t].dispose().catch(function(e){throw I.logger.error(e.message),delete I._registerers[t],e});case 1:case"end":return e.stop()}},e)}),m=j(n).call(n,r);case 3:if((b=m()).done){e.next=5;break}return u=b.value,e.delegateYield(l(u),"t0",4);case 4:e.next=3;break;case 5:this.logger.log("Dispose of sessions"),d=n.mark(function e(t){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!s[t]){e.next=1;break}return e.next=1,s[t].dispose().catch(function(e){throw I.logger.error(e.message),delete I._sessions[t],e});case 1:case"end":return e.stop()}},e)}),w=j(n).call(n,s);case 6:if((y=w()).done){e.next=8;break}return h=y.value,e.delegateYield(d(h),"t1",7);case 7:e.next=6;break;case 8:this.logger.log("Dispose of subscriptions"),g=n.mark(function e(t){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!a[t]){e.next=1;break}return e.next=1,a[t].dispose().catch(function(e){throw I.logger.error(e.message),delete I._subscriptions[t],e});case 1:case"end":return e.stop()}},e)}),k=j(n).call(n,a);case 9:if((T=k()).done){e.next=11;break}return f=T.value,e.delegateYield(g(f),"t2",10);case 10:e.next=9;break;case 11:this.logger.log("Dispose of publishers"),v=n.mark(function e(i){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!t[i]){e.next=1;break}return e.next=1,t[i].dispose().catch(function(e){throw I.logger.error(e.message),delete I._publishers[i],e});case 1:case"end":return e.stop()}},e)}),R=j(n).call(n,t);case 12:if((S=R()).done){e.next=14;break}return p=S.value,e.delegateYield(v(p),"t3",13);case 13:e.next=12;break;case 14:return this.logger.log("Dispose of transport"),e.next=15,o.dispose().catch(function(e){throw I.logger.error(e.message),e});case 15:this.logger.log("Dispose of core"),c.dispose(),this.transitionState(xt.Stopped);case 16:case"end":return e.stop()}},e,this)}))}},{key:"_makeInviter",value:function(e,t){return new St(this,e,t)}},{key:"attemptReconnection",value:function(){var e,t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,i=this.options.reconnectionAttempts,r=this.options.reconnectionDelay;n>i?this.logger.log("Maximum reconnection attempts reached"):(this.logger.log(E(e="Reconnection attempt ".concat(n," of ")).call(e,i," - trying")),m(function(){t.reconnect().then(function(){var e;t.logger.log(E(e="Reconnection attempt ".concat(n," of ")).call(e,i," - succeeded"))}).catch(function(e){var r;t.logger.error(e.message),t.logger.log(E(r="Reconnection attempt ".concat(n," of ")).call(r,i," - failed")),t.attemptReconnection(++n)})},1===n?0:1e3*r))}},{key:"initContact",value:function(){var e=this,t=""!==this.options.contactName?this.options.contactName:qe(8),n=this.options.contactParams,i={pubGruu:void 0,tempGruu:void 0,uri:new Ee("sip",t,this.options.viaHost,void 0,n),toString:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.anonymous||!1,r=t.outbound||!1,s=t.register||!1,a="<";return a+=i?e.contact.tempGruu||"sip:anonymous@anonymous.invalid;transport=".concat(n.transport?n.transport:"ws"):s?e.contact.uri:e.contact.pubGruu||e.contact.uri,r&&(a+=";ob"),a+=">",e.options.instanceIdAlwaysAdded&&(a+=';+sip.instance="<urn:uuid:'+e._instanceId+'>"'),a}};return i}},{key:"initCore",value:function(){var e,t=this,n=[];(n.push("outbound"),this.options.sipExtension100rel===ft.Supported&&n.push("100rel"),this.options.sipExtensionReplaces===ft.Supported&&n.push("replaces"),this.options.sipExtensionExtraSupported)&&(e=n).push.apply(e,N(this.options.sipExtensionExtraSupported));this.options.hackAllowUnregisteredOptionTags||(n=f(n).call(n,function(e){return pt[e]})),n=D(new F(n));var i=g(n).call(n);(this.contact.pubGruu||this.contact.tempGruu)&&i.push("gruu");var r={aor:this.options.uri,contact:this.contact,displayName:this.options.displayName,loggerFactory:this.loggerFactory,hackViaTcp:this.options.hackViaTcp,routeSet:this.options.preloadedRouteSet,supportedOptionTags:n,supportedOptionTagsResponse:i,sipjsId:this.options.sipjsId,userAgentHeaderFieldValue:this.options.userAgentString,viaForceRport:this.options.forceRport,viaHost:this.options.viaHost,authenticationFactory:function(){var e=t.options.authorizationUsername?t.options.authorizationUsername:t.options.uri.user,n=t.options.authorizationPassword?t.options.authorizationPassword:void 0,i=t.options.authorizationHa1?t.options.authorizationHa1:void 0;return new qt(t.getLoggerFactory(),i,e,n)},transportAccessor:function(){return t.transport}},s={onInvite:function(e){var n,i=new wt(t,e);if(e.delegate={onCancel:function(e){i._onCancel(e)},onTransportError:function(e){t.logger.error("A transport error has occurred while handling an incoming INVITE request.")}},e.trying(),t.options.sipExtensionReplaces!==ft.Unsupported){var r=e.message.parseHeader("replaces");if(r){var s=r.call_id;if("string"!=typeof s)throw new Error("Type of call id is not string");var a=r.replaces_to_tag;if("string"!=typeof a)throw new Error("Type of to tag is not string");var o=r.replaces_from_tag;if("string"!=typeof o)throw new Error("type of from tag is not string");var c=s+a+o,l=t.userAgentCore.dialogs.get(c);if(!l)return void i.reject({statusCode:481});if(!l.early&&!0===r.early_only)return void i.reject({statusCode:486});var u=t._sessions[s+o]||t._sessions[s+a]||void 0;if(!u)throw new Error("Session does not exist.");i._replacee=u}}if(null===(n=t.delegate)||void 0===n?void 0:n.onInvite)return i.autoSendAnInitialProvisionalResponse?void i.progress().then(function(){var e;if(void 0===(null===(e=t.delegate)||void 0===e?void 0:e.onInvite))throw new Error("onInvite undefined.");t.delegate.onInvite(i)}):void t.delegate.onInvite(i);i.reject({statusCode:486})},onMessage:function(e){if(t.delegate&&t.delegate.onMessage){var n=new lt(e);t.delegate.onMessage(n)}else e.accept()},onNotify:function(e){if(t.delegate&&t.delegate.onNotify){var n=new ut(e);t.delegate.onNotify(n)}else t.options.allowLegacyNotifications?e.accept():e.reject({statusCode:481})},onRefer:function(e){t.logger.warn("Received an out of dialog REFER request"),t.delegate&&t.delegate.onReferRequest?t.delegate.onReferRequest(e):e.reject({statusCode:405})},onRegister:function(e){t.logger.warn("Received an out of dialog REGISTER request"),t.delegate&&t.delegate.onRegisterRequest?t.delegate.onRegisterRequest(e):e.reject({statusCode:405})},onSubscribe:function(e){t.logger.warn("Received an out of dialog SUBSCRIBE request"),t.delegate&&t.delegate.onSubscribeRequest?t.delegate.onSubscribeRequest(e):e.reject({statusCode:405})}};return new ai(r,s)}},{key:"initTransportCallbacks",value:function(){var e=this;this.transport.onConnect=function(){return e.onTransportConnect()},this.transport.onDisconnect=function(t){return e.onTransportDisconnect(t)},this.transport.onMessage=function(t){return e.onTransportMessage(t)}}},{key:"onTransportConnect",value:function(){this.state!==xt.Stopped&&this.delegate&&this.delegate.onConnect&&this.delegate.onConnect()}},{key:"onTransportDisconnect",value:function(e){this.state!==xt.Stopped&&(this.delegate&&this.delegate.onDisconnect&&this.delegate.onDisconnect(e),e&&this.options.reconnectionAttempts>0&&this.attemptReconnection())}},{key:"onTransportMessage",value:function(e){var t=this,n=Mt.parseMessage(e,this.getLogger("sip.Parser"));if(n)if(this.state===xt.Stopped&&n instanceof Le)this.logger.warn("Received ".concat(n.method," request while stopped. Dropping."));else{var i=function(){for(var e=0,i=["from","to","call_id","cseq","via"];e<i.length;e++){var r=i[e];if(!n.hasHeader(r))return t.logger.warn("Missing mandatory header field : ".concat(r,".")),!1}return!0};if(n instanceof Le){if(!i())return void this.logger.warn("Request missing mandatory header field. Dropping.");if(!n.toTag&&n.callId.substr(0,5)===this.options.sipjsId)return void this.userAgentCore.replyStateless(n,{statusCode:482});var r=Ne(n.body),s=n.getHeader("content-length");if(s&&r<Number(s))return void this.userAgentCore.replyStateless(n,{statusCode:400})}if(n instanceof Ve){if(!i())return void this.logger.warn("Response missing mandatory header field. Dropping.");if(n.getHeaders("via").length>1)return void this.logger.warn("More than one Via header field present in the response. Dropping.");if(n.via.host!==this.options.viaHost||void 0!==n.via.port)return void this.logger.warn("Via sent-by in the response does not match UA Via host value. Dropping.");var a=Ne(n.body),o=n.getHeader("content-length");if(o&&a<Number(o))return void this.logger.warn("Message body length is lower than the value in Content-Length header field. Dropping.")}if(n instanceof Le)this.userAgentCore.receiveIncomingRequestFromTransport(n);else{if(!(n instanceof Ve))throw new Error("Invalid message type.");this.userAgentCore.receiveIncomingResponseFromTransport(n)}}else this.logger.warn("Failed to parse incoming message. Dropping.")}},{key:"transitionState",value:function(e,t){var n,i=this,r=function(){var t;throw new Error(E(t="Invalid state transition from ".concat(i._state," to ")).call(t,e))};switch(this._state){case xt.Started:e!==xt.Stopped&&r();break;case xt.Stopped:e!==xt.Started&&r();break;default:throw new Error("Unknown state.")}this.logger.log(E(n="Transitioned from ".concat(this._state," to ")).call(n,e)),this._state=e,this._stateEventEmitter.emit(this._state)}}],[{key:"makeURI",value:function(e){return He.URIParse(e)}},{key:"defaultOptions",value:function(){return{errorCallback:function(){},allowLegacyNotifications:!1,authorizationHa1:"",authorizationPassword:"",authorizationUsername:"",delegate:{},contactName:"",contactParams:{transport:"ws"},displayName:"",forceRport:!1,gracefulShutdown:!0,hackAllowUnregisteredOptionTags:!1,hackIpInContact:!1,hackViaTcp:!1,instanceId:"",instanceIdAlwaysAdded:!1,logBuiltinEnabled:!0,logConfiguration:!0,logConnector:function(){},logLevel:"log",noAnswerTimeout:60,preloadedRouteSet:[],reconnectionAttempts:0,reconnectionDelay:4,sendInitialProvisionalResponse:!0,sessionDescriptionHandlerFactory:ci(),sessionDescriptionHandlerFactoryOptions:{},sipExtension100rel:ft.Unsupported,sipExtensionReplaces:ft.Unsupported,sipExtensionExtraSupported:[],sipjsId:"",transportConstructor:li,transportOptions:{},uri:new Ee("sip","anonymous","anonymous.invalid"),userAgentString:"SIP.js/0.21.17",viaHost:""}}},{key:"newUUID",value:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=Math.floor(16*Math.random());return("x"===e?t:t%4+8).toString(16)})}},{key:"stripUndefinedProperties",value:function(e){var t;return O(t=A(e)).call(t,function(t,n){return void 0!==e[n]&&(t[n]=e[n]),t},{})}}])}();var di=function(){return t(function t(i){var r=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,t),d(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"managedSessions",{enumerable:!0,configurable:!0,writable:!0,value:[]}),d(this,"userAgent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"attemptingReconnection",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"optionsPingFailure",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"optionsPingRequest",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"optionsPingRunning",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"optionsPingTimeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"registrationAttemptTimeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"registerer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"registererOptions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"registererRegisterOptions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"shouldBeConnected",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"shouldBeRegistered",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this.delegate=s.delegate,this.options=$({aor:"",autoStop:!0,delegate:{},iceStopWaitingOnServerReflexive:!1,managedSessionFactory:function(e,t){return{session:t,held:!1,muted:!1}},maxSimultaneousSessions:2,media:{},optionsPingInterval:-1,optionsPingRequestURI:"",reconnectionAttempts:3,reconnectionDelay:4,registrationRetry:!1,registrationRetryInterval:3,registerGuard:null,registererOptions:{},registererRegisterOptions:{},sendDTMFUsingSessionDescriptionHandler:!1,userAgentOptions:{}},t.stripUndefinedProperties(s));var a=$({},s.userAgentOptions);if(a.transportConstructor||(a.transportConstructor=li),a.transportOptions||(a.transportOptions={server:i}),!a.uri&&s.aor){var o=ui.makeURI(s.aor);if(!o)throw new Error("Failed to create valid URI from ".concat(s.aor));a.uri=o}if(this.userAgent=new ui(a),this.userAgent.delegate={onConnect:function(){r.logger.log("Connected"),r.delegate&&r.delegate.onServerConnect&&r.delegate.onServerConnect(),r.shouldBeRegistered&&r.register(),r.options.optionsPingInterval>0&&r.optionsPingStart()},onDisconnect:function(e){return ne(r,void 0,void 0,n.mark(function t(){var i,r,s,a,o=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:this.logger.log("Disconnected"),i=!1,this.options.optionsPingInterval>0&&(i=this.optionsPingFailure,this.optionsPingFailure=!1,this.optionsPingStop()),this.delegate&&this.delegate.onServerDisconnect&&this.delegate.onServerDisconnect(e),(e||i)&&(this.registerer&&(this.logger.log("Disposing of registerer..."),this.registerer.dispose().catch(function(e){o.logger.debug("Error occurred disposing of registerer after connection with server was lost."),o.logger.debug(e.toString())}),this.registerer=void 0),h(r=w(s=g(a=this.managedSessions).call(a)).call(s,function(e){return e.session})).call(r,function(e){return ne(o,void 0,void 0,n.mark(function t(){var i=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:this.logger.log("Disposing of session..."),e.dispose().catch(function(e){i.logger.debug("Error occurred disposing of a session after connection with server was lost."),i.logger.debug(e.toString())});case 1:case"end":return t.stop()}},t,this)}))}),this.shouldBeConnected&&this.attemptReconnection());case 1:case"end":return t.stop()}},t,this)}))},onInvite:function(e){r.logger.log("[".concat(e.id,"] Received INVITE"));var t=r.options.maxSimultaneousSessions;if(0!==t&&r.managedSessions.length>t)return r.logger.warn("[".concat(e.id,"] Session already in progress, rejecting INVITE...")),void e.reject().then(function(){r.logger.log("[".concat(e.id,"] Rejected INVITE"))}).catch(function(t){r.logger.error("[".concat(e.id,"] Failed to reject INVITE")),r.logger.error(t.toString())});var n={sessionDescriptionHandlerOptions:{constraints:r.constraints}};r.initSession(e,n),r.delegate&&r.delegate.onCallReceived?r.delegate.onCallReceived(e):(r.logger.warn("[".concat(e.id,"] No handler available, rejecting INVITE...")),e.reject().then(function(){r.logger.log("[".concat(e.id,"] Rejected INVITE"))}).catch(function(t){r.logger.error("[".concat(e.id,"] Failed to reject INVITE")),r.logger.error(t.toString())}))},onMessage:function(e){e.accept().then(function(){r.delegate&&r.delegate.onMessageReceived&&r.delegate.onMessageReceived(e)})},onNotify:function(e){e.accept().then(function(){r.delegate&&r.delegate.onNotificationReceived&&r.delegate.onNotificationReceived(e)})}},this.registererOptions=$({},s.registererOptions),this.registererRegisterOptions=$({},s.registererRegisterOptions),this.options.registrationRetry){this.registererRegisterOptions.requestDelegate=this.registererRegisterOptions.requestDelegate||{};var c=this.registererRegisterOptions.requestDelegate.onReject;this.registererRegisterOptions.requestDelegate.onReject=function(e){c&&c(e),r.attemptRegistration()}}this.logger=this.userAgent.getLogger("sip.SessionManager"),window.addEventListener("online",function(){r.logger.log("Online"),r.shouldBeConnected&&r.connect()}),this.options.autoStop&&window.addEventListener("beforeunload",function(){return ne(r,void 0,void 0,n.mark(function e(){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.shouldBeConnected=!1,this.shouldBeRegistered=!1,this.userAgent.state===xt.Stopped){e.next=1;break}return e.next=1,this.userAgent.stop();case 1:case"end":return e.stop()}},e,this)}))})},[{key:"getLocalMediaStream",value:function(e){var t=e.sessionDescriptionHandler;if(t){if(!(t instanceof oi))throw new Error("Session description handler not instance of web SessionDescriptionHandler");return t.localMediaStream}}},{key:"getRemoteMediaStream",value:function(e){var t=e.sessionDescriptionHandler;if(t){if(!(t instanceof oi))throw new Error("Session description handler not instance of web SessionDescriptionHandler");return t.remoteMediaStream}}},{key:"getLocalAudioTrack",value:function(e){var t,n;return null===(n=this.getLocalMediaStream(e))||void 0===n?void 0:V(t=n.getTracks()).call(t,function(e){return"audio"===e.kind})}},{key:"getLocalVideoTrack",value:function(e){var t,n;return null===(n=this.getLocalMediaStream(e))||void 0===n?void 0:V(t=n.getTracks()).call(t,function(e){return"video"===e.kind})}},{key:"getRemoteAudioTrack",value:function(e){var t,n;return null===(n=this.getRemoteMediaStream(e))||void 0===n?void 0:V(t=n.getTracks()).call(t,function(e){return"audio"===e.kind})}},{key:"getRemoteVideoTrack",value:function(e){var t,n;return null===(n=this.getRemoteMediaStream(e))||void 0===n?void 0:V(t=n.getTracks()).call(t,function(e){return"video"===e.kind})}},{key:"connect",value:function(){return ne(this,void 0,void 0,n.mark(function e(){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.logger.log("Connecting UserAgent..."),this.shouldBeConnected=!0,this.userAgent.state===xt.Started){e.next=1;break}return e.abrupt("return",this.userAgent.start());case 1:return e.abrupt("return",this.userAgent.reconnect());case 2:case"end":return e.stop()}},e,this)}))}},{key:"disconnect",value:function(){return ne(this,void 0,void 0,n.mark(function e(){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.logger.log("Disconnecting UserAgent..."),this.userAgent.state!==xt.Stopped){e.next=1;break}return e.abrupt("return",i.resolve());case 1:return this.shouldBeConnected=!1,this.shouldBeRegistered=!1,this.registerer=void 0,e.abrupt("return",this.userAgent.stop());case 2:case"end":return e.stop()}},e,this)}))}},{key:"isConnected",value:function(){return this.userAgent.isConnected()}},{key:"register",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){var i=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.logger.log("Registering UserAgent..."),this.shouldBeRegistered=!0,void 0!==e&&(this.registererRegisterOptions=$({},e)),this.registerer||(this.registerer=new Dt(this.userAgent,this.registererOptions),this.registerer.stateChange.addListener(function(e){switch(e){case Rt.Initial:break;case Rt.Registered:i.delegate&&i.delegate.onRegistered&&i.delegate.onRegistered();break;case Rt.Unregistered:i.delegate&&i.delegate.onUnregistered&&i.delegate.onUnregistered(),i.shouldBeRegistered&&i.attemptRegistration();break;case Rt.Terminated:break;default:throw new Error("Unknown registerer state.")}})),t.abrupt("return",this.attemptRegistration(!0));case 1:case"end":return t.stop()}},t,this)}))}},{key:"unregister",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.logger.log("Unregistering UserAgent..."),this.shouldBeRegistered=!1,this.registerer){t.next=1;break}return this.logger.warn("No registerer to unregister."),t.abrupt("return",i.resolve());case 1:return t.abrupt("return",this.registerer.unregister(e).then(function(){}));case 2:case"end":return t.stop()}},t,this)}))}},{key:"call",value:function(e,t,r){return ne(this,void 0,void 0,n.mark(function s(){var a,o,c,l,u=this;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.logger.log("Beginning Session..."),!(0!==(a=this.options.maxSimultaneousSessions)&&this.managedSessions.length>a)){n.next=1;break}return n.abrupt("return",i.reject(new Error("Maximum number of sessions already exists.")));case 1:if(o=ui.makeURI(e)){n.next=2;break}return n.abrupt("return",i.reject(new Error('Failed to create a valid URI from "'.concat(e,'"'))));case 2:return t||(t={}),t.sessionDescriptionHandlerOptions||(t.sessionDescriptionHandlerOptions={}),t.sessionDescriptionHandlerOptions.constraints||(t.sessionDescriptionHandlerOptions.constraints=this.constraints),t.earlyMedia&&((r=r||{}).requestDelegate=r.requestDelegate||{},c=r.requestDelegate.onProgress,r.requestDelegate.onProgress=function(e){183===e.message.statusCode&&u.setupRemoteMedia(l),c&&c(e)}),this.options.iceStopWaitingOnServerReflexive&&(t.delegate=t.delegate||{},t.delegate.onSessionDescriptionHandler=function(e){if(!(e instanceof oi))throw new Error("Session description handler not instance of SessionDescriptionHandler");e.peerConnectionDelegate={onicecandidate:function(t){var n;"srflx"===(null===(n=t.candidate)||void 0===n?void 0:n.type)&&(u.logger.log("[".concat(l.id,"] Found srflx ICE candidate, stop waiting...")),e.iceGatheringComplete())}}}),l=new St(this.userAgent,o,t),n.abrupt("return",this.sendInvite(l,t,r).then(function(){return l}));case 3:case"end":return n.stop()}},s,this)}))}},{key:"hangup",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.logger.log("[".concat(e.id,"] Hangup...")),this.sessionExists(e)){t.next=1;break}return t.abrupt("return",i.reject(new Error("Session does not exist.")));case 1:return t.abrupt("return",this.terminate(e));case 2:case"end":return t.stop()}},t,this)}))}},{key:"answer",value:function(e,t){return ne(this,void 0,void 0,n.mark(function r(){return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.logger.log("[".concat(e.id,"] Accepting Invitation...")),this.sessionExists(e)){n.next=1;break}return n.abrupt("return",i.reject(new Error("Session does not exist.")));case 1:if(e instanceof wt){n.next=2;break}return n.abrupt("return",i.reject(new Error("Session not instance of Invitation.")));case 2:return t||(t={}),t.sessionDescriptionHandlerOptions||(t.sessionDescriptionHandlerOptions={}),t.sessionDescriptionHandlerOptions.constraints||(t.sessionDescriptionHandlerOptions.constraints=this.constraints),n.abrupt("return",e.accept(t));case 3:case"end":return n.stop()}},r,this)}))}},{key:"decline",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.logger.log("[".concat(e.id,"] Rejecting Invitation...")),this.sessionExists(e)){t.next=1;break}return t.abrupt("return",i.reject(new Error("Session does not exist.")));case 1:if(e instanceof wt){t.next=2;break}return t.abrupt("return",i.reject(new Error("Session not instance of Invitation.")));case 2:return t.abrupt("return",e.reject());case 3:case"end":return t.stop()}},t,this)}))}},{key:"hold",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.logger.log("[".concat(e.id,"] Holding session...")),t.abrupt("return",this.setHold(e,!0));case 1:case"end":return t.stop()}},t,this)}))}},{key:"unhold",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.logger.log("[".concat(e.id,"] Unholding session...")),t.abrupt("return",this.setHold(e,!1));case 1:case"end":return t.stop()}},t,this)}))}},{key:"isHeld",value:function(e){var t=this.sessionManaged(e);return!!t&&t.held}},{key:"mute",value:function(e){this.logger.log("[".concat(e.id,"] Disabling media tracks...")),this.setMute(e,!0)}},{key:"unmute",value:function(e){this.logger.log("[".concat(e.id,"] Enabling media tracks...")),this.setMute(e,!1)}},{key:"isMuted",value:function(e){var t=this.sessionManaged(e);return!!t&&t.muted}},{key:"sendDTMF",value:function(e,t){return ne(this,void 0,void 0,n.mark(function r(){var s,a;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.logger.log("[".concat(e.id,"] Sending DTMF...")),/^[0-9A-D#*,]$/.exec(t)){n.next=1;break}return n.abrupt("return",i.reject(new Error("Invalid DTMF tone.")));case 1:if(this.sessionExists(e)){n.next=2;break}return n.abrupt("return",i.reject(new Error("Session does not exist.")));case 2:if(this.logger.log(E(s="[".concat(e.id,"] Sending DTMF tone: ")).call(s,t)),!this.options.sendDTMFUsingSessionDescriptionHandler){n.next=5;break}if(e.sessionDescriptionHandler){n.next=3;break}return n.abrupt("return",i.reject(new Error("Session desciption handler undefined.")));case 3:if(e.sessionDescriptionHandler.sendDtmf(t)){n.next=4;break}return n.abrupt("return",i.reject(new Error("Failed to send DTMF")));case 4:return n.abrupt("return",i.resolve());case 5:return a={body:{contentDisposition:"render",contentType:"application/dtmf-relay",content:"Signal="+t+"\r\nDuration=2000"}},n.abrupt("return",e.info({requestOptions:a}).then(function(){}));case 6:case"end":return n.stop()}},r,this)}))}},{key:"transfer",value:function(e,t,r){return ne(this,void 0,void 0,n.mark(function s(){var a;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.logger.log("[".concat(e.id,"] Referring session...")),!(t instanceof vt)){n.next=1;break}return n.abrupt("return",e.refer(t,r).then(function(){}));case 1:if(a=ui.makeURI(t)){n.next=2;break}return n.abrupt("return",i.reject(new Error('Failed to create a valid URI from "'.concat(t,'"'))));case 2:return n.abrupt("return",e.refer(a,r).then(function(){}));case 3:case"end":return n.stop()}},s,this)}))}},{key:"message",value:function(e,t){return ne(this,void 0,void 0,n.mark(function r(){var s;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.logger.log("Sending message..."),s=ui.makeURI(e)){n.next=1;break}return n.abrupt("return",i.reject(new Error('Failed to create a valid URI from "'.concat(e,'"'))));case 1:return n.abrupt("return",new It(this.userAgent,s,t).message());case 2:case"end":return n.stop()}},r,this)}))}},{key:"constraints",get:function(){var e={audio:!0,video:!1};return this.options.media.constraints&&(e=$({},this.options.media.constraints)),e}},{key:"attemptReconnection",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,n=this.options.reconnectionAttempts,i=this.options.reconnectionDelay;if(this.shouldBeConnected)if(this.attemptingReconnection&&this.logger.log("Reconnection attempt already in progress"),t>n)this.logger.log("Reconnection maximum attempts reached");else{var r,s,a;if(1===t)this.logger.log(E(r="Reconnection attempt ".concat(t," of ")).call(r,n," - trying"));else this.logger.log(E(s=E(a="Reconnection attempt ".concat(t," of ")).call(a,n," - trying in ")).call(s,i," seconds"));this.attemptingReconnection=!0,m(function(){var i;if(!e.shouldBeConnected)return e.logger.log(E(i="Reconnection attempt ".concat(t," of ")).call(i,n," - aborted")),void(e.attemptingReconnection=!1);e.userAgent.reconnect().then(function(){var i;e.logger.log(E(i="Reconnection attempt ".concat(t," of ")).call(i,n," - succeeded")),e.attemptingReconnection=!1}).catch(function(i){var r;e.logger.log(E(r="Reconnection attempt ".concat(t," of ")).call(r,n," - failed")),e.logger.error(i.message),e.attemptingReconnection=!1,e.attemptReconnection(++t)})},1===t?0:1e3*i)}else this.logger.log("Should not be connected currently")}},{key:"attemptRegistration",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(this.logger.log("Registration attempt ".concat(t?"without delay":"")),!this.shouldBeRegistered)return this.logger.log("Should not be registered currently"),i.resolve();if(void 0!==this.registrationAttemptTimeout)return this.logger.log("Registration attempt already in progress"),i.resolve();return new i(function(n,r){var s,a;e.registrationAttemptTimeout=m(function(){(e.registerer?e.isConnected()?e.userAgent.state===xt.Stopped?(e.logger.log("User agent stopped"),i.resolve()):e.options.registerGuard?e.options.registerGuard().catch(function(t){throw e.logger.log("Register guard rejected will making registration attempt"),t}).then(function(t){return t||!e.registerer?i.resolve():e.registerer.register(e.registererRegisterOptions).then(function(){})}):e.registerer.register(e.registererRegisterOptions).then(function(){}):(e.logger.log("User agent not connected"),i.resolve()):(e.logger.log("Registerer undefined"),i.resolve())).then(function(){e.registrationAttemptTimeout=void 0,n()}).catch(function(t){e.registrationAttemptTimeout=void 0,t instanceof ue?n():r(t)})},t?0:(s=e.options.registrationRetryInterval,a=2*s,1e3*(Math.random()*(a-s)+s)))})}},{key:"cleanupMedia",value:function(e){var t=this.sessionManaged(e);if(!t)throw new Error("Managed session does not exist.");t.mediaLocal&&t.mediaLocal.video&&(t.mediaLocal.video.srcObject=null,t.mediaLocal.video.pause()),t.mediaRemote&&(t.mediaRemote.audio&&(t.mediaRemote.audio.srcObject=null,t.mediaRemote.audio.pause()),t.mediaRemote.video&&(t.mediaRemote.video.srcObject=null,t.mediaRemote.video.pause()))}},{key:"enableReceiverTracks",value:function(e,t){if(!this.sessionExists(e))throw new Error("Session does not exist.");var n=e.sessionDescriptionHandler;if(!(n instanceof oi))throw new Error("Session's session description handler not instance of SessionDescriptionHandler.");n.enableReceiverTracks(t)}},{key:"enableSenderTracks",value:function(e,t){if(!this.sessionExists(e))throw new Error("Session does not exist.");var n=e.sessionDescriptionHandler;if(!(n instanceof oi))throw new Error("Session's session description handler not instance of SessionDescriptionHandler.");n.enableSenderTracks(t)}},{key:"initSession",value:function(e,t){var n=this;this.sessionAdd(e),this.delegate&&this.delegate.onCallCreated&&this.delegate.onCallCreated(e),e.stateChange.addListener(function(t){var i;switch(n.logger.log(E(i="[".concat(e.id,"] Session state changed to ")).call(i,t)),t){case ot.Initial:case ot.Establishing:break;case ot.Established:n.setupLocalMedia(e),n.setupRemoteMedia(e),n.delegate&&n.delegate.onCallAnswered&&n.delegate.onCallAnswered(e);break;case ot.Terminating:case ot.Terminated:n.sessionExists(e)&&(n.cleanupMedia(e),n.sessionRemove(e),n.delegate&&n.delegate.onCallHangup&&n.delegate.onCallHangup(e));break;default:throw new Error("Unknown session state.")}}),e.delegate=e.delegate||{},e.delegate.onInfo=function(t){var i;if(void 0!==(null===(i=n.delegate)||void 0===i?void 0:i.onCallDTMFReceived)){var r=t.request.getHeader("content-type");if(r&&/^application\/dtmf-relay/i.exec(r)){var s=t.request.body.split("\r\n",2);if(2===s.length){var a,o=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/;if(void 0!==s[0]&&o.test(s[0])&&(a=s[0].replace(o,"$2")),a){var c,l=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;void 0!==s[1]&&l.test(s[1])&&(c=T(s[1].replace(l,"$2"),10)),c?t.accept().then(function(){if(n.delegate&&n.delegate.onCallDTMFReceived){if(!a||!c)throw new Error("Tone or duration undefined.");n.delegate.onCallDTMFReceived(e,a,c)}}).catch(function(e){n.logger.error(e.message)}):t.reject()}else t.reject()}else t.reject()}else t.reject()}else t.reject()},e.delegate.onRefer=function(e){e.accept().then(function(){return n.sendInvite(e.makeInviter(t),t)}).catch(function(e){n.logger.error(e.message)})}}},{key:"optionsPingRun",value:function(e,t,n){var i=this;if(this.options.optionsPingInterval<1)throw new Error("Invalid options ping interval.");this.optionsPingRunning||(this.optionsPingRunning=!0,this.optionsPingTimeout=m(function(){i.optionsPingTimeout=void 0;var r=function(){i.optionsPingFailure=!1,i.optionsPingRunning&&(i.optionsPingRunning=!1,i.optionsPingRun(e,t,n))},s=i.userAgent.userAgentCore,a=s.makeOutgoingRequestMessage("OPTIONS",e,t,n,{});i.optionsPingRequest=s.request(a,{onAccept:function(){i.optionsPingRequest=void 0,r()},onReject:function(e){i.optionsPingRequest=void 0,408===e.message.statusCode||503===e.message.statusCode?(i.logger.error("OPTIONS ping failed"),i.optionsPingFailure=!0,i.optionsPingRunning=!1,i.userAgent.transport.disconnect().catch(function(e){return i.logger.error(e)})):r()}})},1e3*this.options.optionsPingInterval))}},{key:"optionsPingStart",value:function(){var e,t,n;if(this.logger.log("OPTIONS pings started"),this.options.optionsPingRequestURI){if(!(e=ui.makeURI(this.options.optionsPingRequestURI)))throw new Error("Failed to create Request URI.");t=this.userAgent.contact.uri.clone(),n=this.userAgent.contact.uri.clone()}else{if(!this.options.aor)return void this.logger.error("You have enabled sending OPTIONS pings and as such you must provide either a) an AOR to register, or b) an RURI to use for the target of the OPTIONS ping requests. ");var i=ui.makeURI(this.options.aor);if(!i)throw new Error("Failed to create URI.");(e=i.clone()).user=void 0,t=i.clone(),n=i.clone()}this.optionsPingRun(e,t,n)}},{key:"optionsPingStop",value:function(){this.logger.log("OPTIONS pings stopped"),this.optionsPingRunning=!1,this.optionsPingFailure=!1,this.optionsPingRequest&&(this.optionsPingRequest.dispose(),this.optionsPingRequest=void 0),this.optionsPingTimeout&&(clearTimeout(this.optionsPingTimeout),this.optionsPingTimeout=void 0)}},{key:"sendInvite",value:function(e,t,i){return ne(this,void 0,void 0,n.mark(function r(){var s=this;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return this.initSession(e,t),n.abrupt("return",e.invite(i).then(function(){s.logger.log("[".concat(e.id,"] Sent INVITE"))}));case 1:case"end":return n.stop()}},r,this)}))}},{key:"sessionAdd",value:function(e){var t=this.options.managedSessionFactory(this,e);this.managedSessions.push(t)}},{key:"sessionExists",value:function(e){return void 0!==this.sessionManaged(e)}},{key:"sessionManaged",value:function(e){var t;return V(t=this.managedSessions).call(t,function(t){return t.session.id===e.id})}},{key:"sessionRemove",value:function(e){var t;this.managedSessions=f(t=this.managedSessions).call(t,function(t){return t.session.id!==e.id})}},{key:"setHold",value:function(e,t){return ne(this,void 0,void 0,n.mark(function r(){var s,a,o,c=this;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.sessionExists(e)){n.next=1;break}return n.abrupt("return",i.reject(new Error("Session does not exist.")));case 1:if(this.isHeld(e)!==t){n.next=2;break}return n.abrupt("return",i.resolve());case 2:if(e.sessionDescriptionHandler instanceof oi){n.next=3;break}throw new Error("Session's session description handler not instance of SessionDescriptionHandler.");case 3:if(s={requestDelegate:{onAccept:function(){var n=c.sessionManaged(e);void 0!==n&&(n.held=t,c.enableReceiverTracks(e,!n.held),c.enableSenderTracks(e,!n.held&&!n.muted),c.delegate&&c.delegate.onCallHold&&c.delegate.onCallHold(e,n.held))},onReject:function(){c.logger.warn("[".concat(e.id,"] Re-invite request was rejected"));var n=c.sessionManaged(e);void 0!==n&&(n.held=!t,c.enableReceiverTracks(e,!n.held),c.enableSenderTracks(e,!n.held&&!n.muted),c.delegate&&c.delegate.onCallHold&&c.delegate.onCallHold(e,n.held))}}},(a=e.sessionDescriptionHandlerOptionsReInvite).hold=t,e.sessionDescriptionHandlerOptionsReInvite=a,o=this.sessionManaged(e)){n.next=4;break}throw new Error("Managed session is undefiend.");case 4:return o.held=t,n.abrupt("return",e.invite(s).then(function(){var t=c.sessionManaged(e);void 0!==t&&(c.enableReceiverTracks(e,!t.held),c.enableSenderTracks(e,!t.held&&!t.muted))}).catch(function(n){throw o.held=!t,n instanceof ue&&c.logger.error("[".concat(e.id,"] A hold request is already in progress.")),n}));case 5:case"end":return n.stop()}},r,this)}))}},{key:"setMute",value:function(e,t){if(this.sessionExists(e))if(e.state===ot.Established){var n=this.sessionManaged(e);void 0!==n&&(n.muted=t,this.enableSenderTracks(e,!n.held&&!n.muted))}else this.logger.warn("[".concat(e.id,"] An established session is required to enable/disable media tracks"));else this.logger.warn("[".concat(e.id,"] A session is required to enabled/disable media tracks"))}},{key:"setupLocalMedia",value:function(e){var t=this,n=this.sessionManaged(e);if(!n)throw new Error("Managed session does not exist.");var i="function"==typeof this.options.media.local?this.options.media.local(e):this.options.media.local;n.mediaLocal=i;var r=null==i?void 0:i.video;if(r){var s=this.getLocalMediaStream(e);if(!s)throw new Error("Local media stream undefiend.");r.srcObject=s,r.volume=0,r.play().catch(function(n){t.logger.error("[".concat(e.id,"] Failed to play local media")),t.logger.error(n.message)})}}},{key:"setupRemoteMedia",value:function(e){var t=this,n=this.sessionManaged(e);if(!n)throw new Error("Managed session does not exist.");var i="function"==typeof this.options.media.remote?this.options.media.remote(e):this.options.media.remote;n.mediaRemote=i;var r=(null==i?void 0:i.video)||(null==i?void 0:i.audio);if(r){var s=this.getRemoteMediaStream(e);if(!s)throw new Error("Remote media stream undefiend.");r.autoplay=!0,r.srcObject=s,r.play().catch(function(n){t.logger.error("[".concat(e.id,"] Failed to play remote media")),t.logger.error(n.message)}),s.onaddtrack=function(){t.logger.log("Remote media onaddtrack"),r.load(),r.play().catch(function(n){t.logger.error("[".concat(e.id,"] Failed to play remote media")),t.logger.error(n.message)})}}}},{key:"terminate",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){var r,s,a=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:this.logger.log("[".concat(e.id,"] Terminating...")),s=e.state,t.next=s===ot.Initial?1:s===ot.Establishing?4:s===ot.Established?7:s===ot.Terminating?8:s===ot.Terminated?9:10;break;case 1:if(!(e instanceof St)){t.next=2;break}return t.abrupt("return",e.cancel().then(function(){a.logger.log("[".concat(e.id,"] Inviter never sent INVITE (canceled)"))}));case 2:if(!(e instanceof wt)){t.next=3;break}return t.abrupt("return",e.reject().then(function(){a.logger.log("[".concat(e.id,"] Invitation rejected (sent 480)"))}));case 3:case 6:throw new Error("Unknown session type.");case 4:if(!(e instanceof St)){t.next=5;break}return t.abrupt("return",e.cancel().then(function(){a.logger.log("[".concat(e.id,"] Inviter canceled (sent CANCEL)"))}));case 5:if(!(e instanceof wt)){t.next=6;break}return t.abrupt("return",e.reject().then(function(){a.logger.log("[".concat(e.id,"] Invitation rejected (sent 480)"))}));case 7:return t.abrupt("return",e.bye().then(function(){a.logger.log("[".concat(e.id,"] Session ended (sent BYE)"))}));case 8:case 9:return t.abrupt("continue",11);case 10:throw new Error("Unknown state");case 11:return this.logger.log(E(r="[".concat(e.id,"] Terminating in state ")).call(r,e.state,", no action taken")),t.abrupt("return",i.resolve());case 12:case"end":return t.stop()}},t,this)}))}}],[{key:"stripUndefinedProperties",value:function(e){var t;return O(t=A(e)).call(t,function(t,n){return void 0!==e[n]&&(t[n]=e[n]),t},{})}}])}(),hi=function(){return t(function t(n){var i=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,t),d(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"session",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"sessionManager",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.delegate=r.delegate,this.options=$({},r);var s={aor:this.options.aor,delegate:{onCallAnswered:function(){var e,t;return null===(t=null===(e=i.delegate)||void 0===e?void 0:e.onCallAnswered)||void 0===t?void 0:t.call(e)},onCallCreated:function(e){var t,n;i.session=e,null===(n=null===(t=i.delegate)||void 0===t?void 0:t.onCallCreated)||void 0===n||n.call(t)},onCallReceived:function(){var e,t;return null===(t=null===(e=i.delegate)||void 0===e?void 0:e.onCallReceived)||void 0===t?void 0:t.call(e)},onCallHangup:function(){var e,t;i.session=void 0,(null===(e=i.delegate)||void 0===e?void 0:e.onCallHangup)&&(null===(t=i.delegate)||void 0===t||t.onCallHangup())},onCallHold:function(e,t){var n,r;return null===(r=null===(n=i.delegate)||void 0===n?void 0:n.onCallHold)||void 0===r?void 0:r.call(n,t)},onCallDTMFReceived:function(e,t,n){var r,s;return null===(s=null===(r=i.delegate)||void 0===r?void 0:r.onCallDTMFReceived)||void 0===s?void 0:s.call(r,t,n)},onMessageReceived:function(e){var t,n;return null===(n=null===(t=i.delegate)||void 0===t?void 0:t.onMessageReceived)||void 0===n?void 0:n.call(t,e.request.body)},onRegistered:function(){var e,t;return null===(t=null===(e=i.delegate)||void 0===e?void 0:e.onRegistered)||void 0===t?void 0:t.call(e)},onUnregistered:function(){var e,t;return null===(t=null===(e=i.delegate)||void 0===e?void 0:e.onUnregistered)||void 0===t?void 0:t.call(e)},onServerConnect:function(){var e,t;return null===(t=null===(e=i.delegate)||void 0===e?void 0:e.onServerConnect)||void 0===t?void 0:t.call(e)},onServerDisconnect:function(){var e,t;return null===(t=null===(e=i.delegate)||void 0===e?void 0:e.onServerDisconnect)||void 0===t?void 0:t.call(e)}},maxSimultaneousSessions:1,media:this.options.media,reconnectionAttempts:this.options.reconnectionAttempts,reconnectionDelay:this.options.reconnectionDelay,registererOptions:this.options.registererOptions,sendDTMFUsingSessionDescriptionHandler:this.options.sendDTMFUsingSessionDescriptionHandler,userAgentOptions:this.options.userAgentOptions};this.sessionManager=new di(n,s),this.logger=this.sessionManager.userAgent.getLogger("sip.SimpleUser")},[{key:"id",get:function(){return this.options.userAgentOptions&&this.options.userAgentOptions.displayName||"Anonymous"}},{key:"localMediaStream",get:function(){return this.session&&this.sessionManager.getLocalMediaStream(this.session)}},{key:"remoteMediaStream",get:function(){return this.session&&this.sessionManager.getRemoteMediaStream(this.session)}},{key:"localAudioTrack",get:function(){return this.session&&this.sessionManager.getLocalAudioTrack(this.session)}},{key:"localVideoTrack",get:function(){return this.session&&this.sessionManager.getLocalVideoTrack(this.session)}},{key:"remoteAudioTrack",get:function(){return this.session&&this.sessionManager.getRemoteAudioTrack(this.session)}},{key:"remoteVideoTrack",get:function(){return this.session&&this.sessionManager.getRemoteVideoTrack(this.session)}},{key:"connect",value:function(){return this.logger.log("[".concat(this.id,"] Connecting UserAgent...")),this.sessionManager.connect()}},{key:"disconnect",value:function(){return this.logger.log("[".concat(this.id,"] Disconnecting UserAgent...")),this.sessionManager.disconnect()}},{key:"isConnected",value:function(){return this.sessionManager.isConnected()}},{key:"register",value:function(e){return this.logger.log("[".concat(this.id,"] Registering UserAgent...")),this.sessionManager.register(e)}},{key:"unregister",value:function(e){return this.logger.log("[".concat(this.id,"] Unregistering UserAgent...")),this.sessionManager.unregister(e)}},{key:"call",value:function(e,t,n){return this.logger.log("[".concat(this.id,"] Beginning Session...")),this.session?i.reject(new Error("Session already exists.")):this.sessionManager.call(e,t,n).then(function(){})}},{key:"hangup",value:function(){var e=this;return this.logger.log("[".concat(this.id,"] Hangup...")),this.session?this.sessionManager.hangup(this.session).then(function(){e.session=void 0}):i.reject(new Error("Session does not exist."))}},{key:"answer",value:function(e){return this.logger.log("[".concat(this.id,"] Accepting Invitation...")),this.session?this.sessionManager.answer(this.session,e):i.reject(new Error("Session does not exist."))}},{key:"decline",value:function(){return this.logger.log("[".concat(this.id,"] rejecting Invitation...")),this.session?this.sessionManager.decline(this.session):i.reject(new Error("Session does not exist."))}},{key:"hold",value:function(){return this.logger.log("[".concat(this.id,"] holding session...")),this.session?this.sessionManager.hold(this.session):i.reject(new Error("Session does not exist."))}},{key:"unhold",value:function(){return this.logger.log("[".concat(this.id,"] unholding session...")),this.session?this.sessionManager.unhold(this.session):i.reject(new Error("Session does not exist."))}},{key:"isHeld",value:function(){return!!this.session&&this.sessionManager.isHeld(this.session)}},{key:"mute",value:function(){return this.logger.log("[".concat(this.id,"] disabling media tracks...")),this.session&&this.sessionManager.mute(this.session)}},{key:"unmute",value:function(){return this.logger.log("[".concat(this.id,"] enabling media tracks...")),this.session&&this.sessionManager.unmute(this.session)}},{key:"isMuted",value:function(){return!!this.session&&this.sessionManager.isMuted(this.session)}},{key:"sendDTMF",value:function(e){return this.logger.log("[".concat(this.id,"] sending DTMF...")),this.session?this.sessionManager.sendDTMF(this.session,e):i.reject(new Error("Session does not exist."))}},{key:"message",value:function(e,t){return this.logger.log("[".concat(this.id,"] sending message...")),this.sessionManager.message(e,t)}}])}();function gi(e){return document.getElementById(e)}function fi(e){if(e&&e.getTracks)try{var t=e.getTracks();h(t).call(t,function(e){try{e.stop()}catch(e){}})}catch(e){}}function vi(e){return navigator.mediaDevices.getUserMedia(e).then(function(e){return e?(fi(e),!0):i.reject(new Error("EmptyStreamError"))}).catch(function(e){return(!e||"NotAllowedError"!==e.name)&&i.reject(e)})}function pi(){try{var e;if(-1===q(e=navigator.userAgent).call(e,"Firefox"))return vi({video:!1,audio:!0}).catch(function(){return!0})}catch(e){console.log(e)}}function mi(e){var t=gi(e);t&&(t.currentTime=0,t.play())}function bi(e){var t=gi(e);t&&(t.currentTime=0,t.pause())}function wi(e){var t=gi(e);t&&(t.srcObject=null,t.pause())}var yi,ki,Ti=function(e){var t,n,i;return Y(t=e.getHours().toString()).call(t,2,"0")+":"+Y(n=e.getMinutes().toString()).call(n,2,"0")+":"+Y(i=e.getSeconds().toString()).call(i,2,"0")},Ri=function(){return new Date(new Date((new Date).toLocaleDateString()).getTime())},Si=function(e){return new Date(e.setSeconds(e.getSeconds()+1))};function Ii(e){var t=Ri();e(Ti(t));var n=L(function(){var n=Si(t),i=Ti(n);e(i)},1e3);return function(){clearInterval(n),n=null}}function Ei(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!=q(r).call(r,"json")?e(JSON.parse(i.responseText)):-1!=q(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",l=r,u=null;return s&&("GET"===c?l=l+"?"+function(e){var t=[];for(var n in e)t.push(n+"="+e[n]);return t.join("&")}(s):"POST"===c&&(u=C(s))),i.open(c,l,!0),{xhr:i,ajaxData:u,contentType:o}}function Ci(){var e,t,n,i,r,s=new Date,a=s.getUTCFullYear(),o=s.getUTCMonth()+1,c=s.getUTCDate(),l=s.getUTCHours(),u=s.getUTCMinutes(),d=s.getUTCSeconds(),h=new Date(Date.UTC(a,o-1,c,l+8,u,d)),g=function(e){var t;return Y(t=String(e)).call(t,2,"0")},f=h.getUTCFullYear(),v=g(h.getUTCMonth()+1),p=g(h.getUTCDate()),m=g(h.getUTCHours()),b=g(h.getUTCMinutes()),w=g(h.getUTCSeconds());return E(e=E(t=E(n=E(i=E(r="".concat(f,"-")).call(r,v,"-")).call(i,p," ")).call(n,m,":")).call(t,b,":")).call(e,w)}var Ai,xi,Di,Hi,_i,$i,qi,Mi,Pi=E(yi="sip:".concat("","@")).call(yi,""),Oi=E(ki="".concat("","://")).call(ki,""),Ni={authorizationPassword:"",authorizationUsername:"",viaHost:"",uri:ui.makeURI(Pi),logLevel:"error",transportOptions:{server:Oi},contactName:""},ji={connectStatus:!1,registerStatus:!1,invitatingStatus:!1,incomingStatus:!1,answerStatus:!1,reconnectStatus:!1};!function(e){e.NO="0",e.YES="1"}(Ai||(Ai={})),function(e){e.NO="0",e.YES="1"}(xi||(xi={})),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",e.VOICE_TEST="7",e.CALL_IN_AI="8",e.CALL_IN_LABOUR="9",e.MOVIE_CALL="10",e.GATEWAY_TEST_CALL="11"}(Di||(Di={})),function(e){e.DIRECT_ANSWER="1",e.LISTEN_FIRST_AND_THEN_ANSWER_MANUALLY="2"}(Hi||(Hi={}));var Fi=function(){function n(){e(this,n)}return t(n,null,[{key:"getAliArms",value:function(e){var t=e&&e!==ie(this,_i,"f",qi);return t&&re(this,_i,e,"f",qi),ie(this,_i,"f",$i)&&!t||(re(this,_i,new te({uid:ie(this,_i,"f",qi),pid:"jjn8k2jk90@aa39edd52601f08",appType:"web",imgUrl:"https://arms-retcode.aliyuncs.com/r.png?",release:"6.0.10",environment:"prod",sendResource:!1,autoSendPerf:!1,useFmp:!1,autoSendPv:!1,enableSPA:!1,jsReport:!1,behavior:!1,enableConsole:!1,disableHook:!0,ignore:{ignoreErrors:[function(){return!0}],ignoreResErrors:[function(){return!0}]}}),"f",$i),ie(this,_i,"f",Mi).push({uid:ie(this,_i,"f",qi),aliArms:ie(this,_i,"f",$i)})),ie(this,_i,"f",$i)}},{key:"getAliArmsList",value:function(){return ie(this,_i,"f",Mi)}},{key:"errReport",value:function(e,t){var i;null===(i=n.getAliArms(t))||void 0===i||i.errReport(e)}}])}();_i=Fi,$i={value:void 0},qi={value:void 0},Mi={value:[]};var Ui,Bi,Li,Gi,Vi,Wi,Yi,Ki,zi,Zi,Ji,Xi,Qi,er,tr,nr,ir,rr,sr,ar,or,cr,lr,ur,dr,hr,gr,fr,vr,pr,mr,br,wr,yr,kr,Tr,Rr,Sr,Ir,Er,Cr,Ar,xr,Dr,Hr,_r,$r,qr,Mr,Pr,Or,Nr,jr,Fr,Ur,Br,Lr,Gr,Vr,Wr,Yr,Kr,zr,Zr,Jr,Xr,Qr,es,ts,ns,is,rs,ss,as,os,cs,ls,us,ds,hs,gs,fs,vs,ps,ms,bs,ws,ys,ks,Ts,Rs,Ss,Is,Es,Cs,As,xs,Ds,Hs,_s,$s,qs,Ms,Ps,Os,Ns,js,Fs,Us,Bs,Ls,Gs,Vs,Ws,Ys,Ks,zs,Zs,Js,Xs,Qs,ea,ta,na,ia,ra,sa,aa,oa,ca,la,ua,da,ha,ga=function(){return t(function t(i,s){var a,o,c,l,u,h,g,f,v,p,b,w,y,k,T,R,S,I,E,C,A,x,D,H,_=this,$=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};e(this,t),d(this,"session",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"userAgentManager",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:"idle"}),d(this,"destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"bound",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"hardFailed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"retryCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),d(this,"signalingBusyCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),d(this,"disconnectedTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"retryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"signalingBusyTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"negotiationTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"iceRecoveryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"rtpStatsTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"onlineTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"transportRecoveryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"registrationRecoveryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"transportWaitStartedAt",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"pendingTransportRecoveryReason",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"registrationWaitStartedAt",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"pendingRegistrationRecoveryReason",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"lastRtpSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"lastRtpProgressAt",{enumerable:!0,configurable:!0,writable:!0,value:r()}),d(this,"lastRtpRecoveryAt",{enumerable:!0,configurable:!0,writable:!0,value:0}),d(this,"recoveryGeneration",{enumerable:!0,configurable:!0,writable:!0,value:0}),d(this,"acceptedRecoveryGeneration",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"recoveryReason",{enumerable:!0,configurable:!0,writable:!0,value:""}),d(this,"reinviteReason",{enumerable:!0,configurable:!0,writable:!0,value:"unknown"}),d(this,"permanentRecoverySdpModifier",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return ne(_,void 0,void 0,n.mark(function t(){return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.applyRecoveryReasonToSdp(e));case 1:case"end":return t.stop()}},t,this)}))}}),d(this,"handleSessionStateChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e){switch(_.logInfo("SIP session state:",e),e){case ot.Established:_.handleEstablished();break;case ot.Terminating:case ot.Terminated:_.destroy()}}}),d(this,"handleOffline",{enumerable:!0,configurable:!0,writable:!0,value:function(){_.destroyed||_.hardFailed||(_.logInfo("browser offline"),_.clearDisconnectedTimer(),_.clearRetryTimer(),_.clearSignalingBusyTimer(),_.clearIceRecoveryTimer(),_.clearTransportRecoveryTimer(),"sending-reinvite"!==_.state&&(_.state="idle"))}}),d(this,"handleOnline",{enumerable:!0,configurable:!0,writable:!0,value:function(){_.destroyed||_.hardFailed||(_.logInfo("browser online"),_.onlineTimer&&clearTimeout(_.onlineTimer),_.onlineTimer=m(function(){if(_.onlineTimer=void 0,!_.destroyed&&!_.hardFailed&&_.session.state===ot.Established)if(_.isTransportAvailable()){var e=_.getPeerConnection();if(e)if("stable"===e.signalingState)switch(e.iceConnectionState){case"failed":case"disconnected":_.state="idle",_.recover("network-online")}else _.scheduleSignalingBusyRetry("network-online:".concat(e.signalingState))}else _.waitForTransport("network-online")},_.options.onlineRecoveryDelayMs))}}),this.session=i,this.userAgentManager=s,this.options={disconnectedTimeoutMs:null!==(a=$.disconnectedTimeoutMs)&&void 0!==a?a:3e3,negotiationTimeoutMs:null!==(o=$.negotiationTimeoutMs)&&void 0!==o?o:1e4,iceRecoveryTimeoutMs:null!==(c=$.iceRecoveryTimeoutMs)&&void 0!==c?c:1e4,iceGatheringTimeoutMs:null!==(l=$.iceGatheringTimeoutMs)&&void 0!==l?l:5e3,maxRetries:null!==(u=$.maxRetries)&&void 0!==u?u:3,retryBaseDelayMs:null!==(h=$.retryBaseDelayMs)&&void 0!==h?h:1e3,retryMaxDelayMs:null!==(g=$.retryMaxDelayMs)&&void 0!==g?g:1e4,maxSignalingBusyRetries:null!==(f=$.maxSignalingBusyRetries)&&void 0!==f?f:3,signalingBusyRetryDelayMs:null!==(v=$.signalingBusyRetryDelayMs)&&void 0!==v?v:1e3,enableRtpWatchdog:null===(p=$.enableRtpWatchdog)||void 0===p||p,rtpStatsIntervalMs:null!==(b=$.rtpStatsIntervalMs)&&void 0!==b?b:1e3,rtpStallTimeoutMs:null!==(w=$.rtpStallTimeoutMs)&&void 0!==w?w:5e3,recoverOnRtpStallWhenIceConnected:null===(y=$.recoverOnRtpStallWhenIceConnected)||void 0===y||y,rtpRecoveryCooldownMs:null!==(k=$.rtpRecoveryCooldownMs)&&void 0!==k?k:1e4,onlineRecoveryDelayMs:null!==(T=$.onlineRecoveryDelayMs)&&void 0!==T?T:800,transportRecoveryPollMs:null!==(R=$.transportRecoveryPollMs)&&void 0!==R?R:1e3,transportRecoveryTimeoutMs:null!==(S=$.transportRecoveryTimeoutMs)&&void 0!==S?S:6e4,registrationRecoveryPollMs:null!==(I=$.registrationRecoveryPollMs)&&void 0!==I?I:1e3,registrationRecoveryTimeoutMs:null!==(E=$.registrationRecoveryTimeoutMs)&&void 0!==E?E:6e4,debugIceCredentials:null!==(C=$.debugIceCredentials)&&void 0!==C&&C,includeRecoveryReasonInSdp:null===(A=$.includeRecoveryReasonInSdp)||void 0===A||A,recoveryReasonSdpAttribute:null!==(x=$.recoveryReasonSdpAttribute)&&void 0!==x?x:"x-recovery-reason",reinviteReasonSdpAttribute:null!==(D=$.reinviteReasonSdpAttribute)&&void 0!==D?D:"x-reinvite-reason",isSignalingAvailable:$.isSignalingAvailable,isRegistrationAvailable:$.isRegistrationAvailable,logger:null!==(H=$.logger)&&void 0!==H?H:console,onRecoveryStart:$.onRecoveryStart,onRecovered:$.onRecovered,onRecoveryFailed:$.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===ot.Established&&this.handleEstablished())}},{key:"restartNow",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"manual";return ne(this,void 0,void 0,n.mark(function t(){return n.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=m(function(){if(e.disconnectedTimer=void 0,!e.destroyed&&!e.hardFailed){var t=e.getPeerConnection();if(t){if("disconnected"===t.iceConnectionState)return e.state="idle",void e.recover("ice-disconnected-timeout");e.logInfo("ICE self recovered:",t.iceConnectionState),e.state="idle"}}},this.options.disconnectedTimeoutMs)))}},{key:"handleIceRecovered",value:function(){var e,t;if(!this.destroyed&&!this.hardFailed){var n="idle"!==this.state||this.retryCount>0;!n||"sending-reinvite"!==this.state&&"waiting-ice"!==this.state||this.acceptedRecoveryGeneration===this.recoveryGeneration?(this.clearDisconnectedTimer(),this.clearRetryTimer(),this.clearSignalingBusyTimer(),this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.clearTransportRecoveryTimer(),this.clearRegistrationRecoveryTimer(),this.transportWaitStartedAt=void 0,this.pendingTransportRecoveryReason=void 0,this.registrationWaitStartedAt=void 0,this.pendingRegistrationRecoveryReason=void 0,this.state="idle",this.retryCount=0,this.signalingBusyCount=0,this.acceptedRecoveryGeneration=void 0,this.recoveryReason="",this.reinviteReason="unknown",this.lastRtpProgressAt=r(),this.lastRtpSnapshot=void 0,this.logInfo("ICE healthy"),n&&(this.logInfo("ICE recovery succeeded"),null===(t=(e=this.options).onRecovered)||void 0===t||t.call(e))):this.logInfo("ICE healthy, waiting for re-INVITE acceptance")}}},{key:"getIceCandidates",value:function(){return ne(this,void 0,void 0,n.mark(function e(){var t,i,r,s;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this.getPeerConnection()){e.next=1;break}return e.abrupt("return");case 1:return e.next=2,t.getStats();case 2:return i=e.sent,r=[],s=[],h(i).call(i,function(e){if("local-candidate"===e.type||"remote-candidate"===e.type){var t={address:e.address,port:e.port,protocol:e.protocol,candidateType:e.candidateType};"local-candidate"===e.type?r.push(t):s.push(t)}}),e.abrupt("return",{localCandidates:r,remoteCandidates:s,iceGatheringState:t.iceGatheringState,iceConnectionState:t.iceConnectionState});case 3:case"end":return e.stop()}},e,this)}))}},{key:"recover",value:function(e){var t,i,s,a,o;return ne(this,void 0,void 0,n.mark(function c(){var l,u,d,h,g,f,v,p=this;return n.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if(!this.destroyed&&!this.hardFailed){c.next=1;break}return c.abrupt("return");case 1:if(this.session.state===ot.Established){c.next=2;break}return this.logWarn("skip recovery: session not established",this.session.state),c.abrupt("return");case 2:if("undefined"==typeof navigator||!1!==navigator.onLine){c.next=3;break}return this.logWarn("skip recovery: browser offline"),this.state="idle",c.abrupt("return");case 3:if(this.isTransportAvailable()){c.next=4;break}return this.waitForTransport(e),c.abrupt("return");case 4:if(this.isRegistrationAvailable()){c.next=5;break}return this.waitForRegistration(e),c.abrupt("return");case 5:if("sending-reinvite"!==this.state&&"waiting-ice"!==this.state){c.next=6;break}return this.logDebug("skip recovery: recovery already running"),c.abrupt("return");case 6:if(l=this.getPeerConnection()){c.next=7;break}return c.abrupt("return");case 7:if("stable"===l.signalingState){c.next=8;break}return this.logWarn("skip recovery: signalingState not stable",l.signalingState),this.state="waiting-signaling",this.scheduleSignalingBusyRetry("signaling-busy:".concat(l.signalingState)),c.abrupt("return");case 8:if(this.signalingBusyCount=0,this.clearSignalingBusyTimer(),!(this.retryCount>=this.options.maxRetries)){c.next=9;break}return this.failRecovery("".concat(e,":max-retries")),c.abrupt("return");case 9:return this.clearDisconnectedTimer(),this.clearRetryTimer(),this.retryCount++,u=++this.recoveryGeneration,this.state="sending-reinvite",d=this.readIceCredentials(null===(t=l.localDescription)||void 0===t?void 0:t.sdp),this.recoveryReason||(this.reinviteReason=this.resolveReinviteReason(e),this.recoveryReason=this.normalizeRecoveryReason(e,this.reinviteReason)),this.acceptedRecoveryGeneration=void 0,this.logInfo("ICE recovery #".concat(this.retryCount),{recoveryReason:this.recoveryReason,reinviteReason:this.reinviteReason}),null===(s=(i=this.options).onRecoveryStart)||void 0===s||s.call(i,this.recoveryReason,this.retryCount),this.startNegotiationTimeout(u,e),c.prev=10,h={offerOptions:{iceRestart:!0},iceGatheringTimeout:this.options.iceGatheringTimeoutMs,finalModifiers:this.options.includeRecoveryReasonInSdp?[this.permanentRecoverySdpModifier]:[]},this.session.sessionDescriptionHandlerOptionsReInvite=h,this.session.sessionDescriptionHandlerModifiersReInvite=[],this.logDebug("re-INVITE Final SDP configured",{recoveryReason:this.recoveryReason,reinviteReason:this.reinviteReason,includeRecoveryReasonInSdp:this.options.includeRecoveryReasonInSdp,finalModifierCount:null!==(o=null===(a=h.finalModifiers)||void 0===a?void 0:a.length)&&void 0!==o?o:0}),g=r(),c.next=11,this.session.invite({requestDelegate:{onTrying:function(){p.isCurrentGeneration(u)&&p.logDebug("ICE re-INVITE trying")},onProgress:function(e){p.isCurrentGeneration(u)&&p.logDebug("ICE re-INVITE progress:",e.message.statusCode)},onAccept:function(){return ne(p,void 0,void 0,n.mark(function t(){var i,s,a,o,c,l,h,f,v,p,m,b,w,y,k,T,R,S;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.isCurrentGeneration(u)){t.next=1;break}return t.abrupt("return");case 1:if(this.logInfo("ICE re-INVITE accepted"),!this.userAgentManager.armsReportFlag){t.next=8;break}if(t.prev=2,c=r(),null!==(s=null===(i=Fi.getAliArms())||void 0===i?void 0:i.getInstance())&&void 0!==s){t.next=3;break}t.next=6;break;case 3:return f=s,v=E(o="softphone-sdk-re-invite-".concat(this.userAgentManager.appKey,"-")).call(o,this.userAgentManager.agentExtension),p=C,m=$,b=$,w={businessAttribute:A(this.userAgentManager.businessAttribute).length?this.userAgentManager.businessAttribute:void 0,appKey:this.userAgentManager.appKey||void 0,agentId:this.userAgentManager.agentId||void 0,agentTag:this.userAgentManager.agentTag||void 0,agentExtension:this.userAgentManager.agentExtension||void 0,recoveryReason:this.recoveryReason||void 0,reinviteReason:this.reinviteReason||void 0},t.next=4,this.getIceCandidates();case 4:if(y=t.sent){t.next=5;break}y={};case 5:k=p(m(b(w,y),{bjDate:Ci(),timestamp:r()})),T=this.userAgentManager.businessAttribute.callId||this.userAgentManager.businessAttribute.cid,R=c-g,S=g,f.api.call(f,{api:v,msg:k,traceId:T,code:200,success:!0,time:R,begin:S});case 6:t.next=8;break;case 7:t.prev=7,t.catch(2);case 8:this.clearNegotiationTimer(),this.acceptedRecoveryGeneration=u,(l=this.getPeerConnection())&&"stable"!==l.signalingState&&this.logWarn("re-INVITE accepted but signalingState is not stable",l.signalingState),this.state="waiting-ice",this.options.debugIceCredentials&&(h=this.readIceCredentials(null===(a=null==l?void 0:l.localDescription)||void 0===a?void 0:a.sdp),this.logInfo("ICE credentials:",{old:d,new:h,changed:this.hasIceCredentialsChanged(d,h)})),this.startIceRecoveryTimeout(u,e);case 9:case"end":return t.stop()}},t,this,[[2,7]])}))},onReject:function(t){return ne(p,void 0,void 0,n.mark(function i(){var s,a,o,c,l,d,h,f,v,p,m,b,w,y,k,T;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(!this.userAgentManager.armsReportFlag){n.next=7;break}if(n.prev=1,c=r(),null!==(a=null===(s=Fi.getAliArms())||void 0===s?void 0:s.getInstance())&&void 0!==a){n.next=2;break}n.next=5;break;case 2:return l=a,d=E(o="softphone-sdk-re-invite-".concat(this.userAgentManager.appKey,"-")).call(o,this.userAgentManager.agentExtension),h=C,f=$,v=$,p={businessAttribute:A(this.userAgentManager.businessAttribute).length?this.userAgentManager.businessAttribute:void 0,appKey:this.userAgentManager.appKey||void 0,agentId:this.userAgentManager.agentId||void 0,agentTag:this.userAgentManager.agentTag||void 0,agentExtension:this.userAgentManager.agentExtension||void 0,recoveryReason:this.recoveryReason||void 0,reinviteReason:this.reinviteReason||void 0},n.next=3,this.getIceCandidates();case 3:if(m=n.sent){n.next=4;break}m={};case 4:b=h(f(v(p,m),{bjDate:Ci(),reasonPhrase:t.message.reasonPhrase||void 0,timestamp:r()})),w=this.userAgentManager.businessAttribute.callId||this.userAgentManager.businessAttribute.cid,y=t.message.statusCode,k=c-g,T=g,l.api.call(l,{api:d,msg:b,traceId:w,code:y,success:!1,time:k,begin:T});case 5:n.next=7;break;case 6:n.prev=6,n.catch(1);case 7:this.handleReinviteRejected(u,e,t.message.statusCode,t.message.reasonPhrase);case 8:case"end":return n.stop()}},i,this,[[1,6]])}))}}});case 11:c.next=19;break;case 12:if(c.prev=12,v=c.catch(10),this.isCurrentGeneration(u)){c.next=13;break}return c.abrupt("return");case 13:return this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.logWarn("ICE re-INVITE error:",v),c.next=14,this.rollbackLocalOffer("invite-exception");case 14:if(f=c.sent,this.isCurrentGeneration(u)){c.next=15;break}return c.abrupt("return");case 15:if(f){c.next=16;break}return this.failRecovery("".concat(e,":rollback-failed:exception")),c.abrupt("return");case 16:if(this.state="idle",this.signalingBusyCount=0,this.isTransportAvailable()){c.next=17;break}return this.waitForTransport("".concat(e,":invite-exception")),c.abrupt("return");case 17:if(!this.isRequestPendingError(v)){c.next=18;break}return this.scheduleRetry("".concat(e,":request-pending"),1500),c.abrupt("return");case 18:this.scheduleRetry("".concat(e,":exception"));case 19:case"end":return c.stop()}},c,this,[[10,12]])}))}},{key:"rollbackLocalOffer",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){var i,r,s,a;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(i=this.getPeerConnection()){t.next=1;break}return t.abrupt("return",!1);case 1:if("stable"!==i.signalingState){t.next=2;break}return t.abrupt("return",!0);case 2:if("have-local-offer"===i.signalingState){t.next=3;break}return this.logWarn("cannot rollback current signaling state",{reason:e,signalingState:i.signalingState}),t.abrupt("return",!1);case 3:return t.prev=3,this.logWarn("rollback local offer",{reason:e,signalingState:i.signalingState}),t.next=4,i.setLocalDescription({type:"rollback"});case 4:return r=i.signalingState,s="stable"===r,this.logInfo("local offer rollback result",{success:s,signalingState:r}),t.abrupt("return",s);case 5:return t.prev=5,a=t.catch(3),this.logError("local offer rollback failed",{reason:e,error:a,signalingState:i.signalingState}),t.abrupt("return",!1);case 6:case"end":return t.stop()}},t,this,[[3,5]])}))}},{key:"normalizeRecoveryReason",value:function(e,t){var n=e.toLowerCase();return p(n).call(n,"transport-restored")?"transport-restored:".concat(t):"unknown"!==t?t:"unknown"}},{key:"resolveReinviteReason",value:function(e){var t=e.toLowerCase();return p(t).call(t,"rtp-stalled")?"rtp-stalled":p(t).call(t,"ice-failed")?"ice-failed":p(t).call(t,"ice-disconnected")||p(t).call(t,"disconnected-timeout")?"ice-disconnected":p(t).call(t,"network-changed")?"network-changed":p(t).call(t,"transport-restored")?"transport-restored":p(t).call(t,"manual")?"manual":"unknown"}},{key:"sanitizeSdpReason",value:function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:256;return g(t=e.replace(/[\r\n]/g,"").replace(/[^a-zA-Z0-9._:-]/g,"_")).call(t,0,n)}},{key:"sanitizeSdpAttributeName",value:function(e){var t;return g(t=e.replace(/[^a-zA-Z0-9_-]/g,"")).call(t,0,64)||"x-reinvite-reason"}},{key:"applyRecoveryReasonToSdp",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){var i,r,s,a,o,c,l,u,d,h,g,v,m,b,w,y,k;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e.sdp&&this.options.includeRecoveryReasonInSdp){t.next=1;break}return t.abrupt("return",e);case 1:for(u=this.sanitizeSdpAttributeName(this.options.recoveryReasonSdpAttribute),d=this.sanitizeSdpAttributeName(this.options.reinviteReasonSdpAttribute),h=this.sanitizeSdpReason(this.recoveryReason||"unknown"),g=this.sanitizeSdpReason(this.reinviteReason||"unknown",64),v=f(i=e.sdp.split(/\r?\n/)).call(i,function(e){return!Q(e).call(e,"a=".concat(u,":"))&&!Q(e).call(e,"a=".concat(d,":"))});v.length>0&&""===v[v.length-1];)v.pop();return m=ee(v).call(v,function(e){return Q(e).call(e,"m=")}),b=m>=0?m:v.length,I(v).call(v,b,0,E(r="a=".concat(u,":")).call(r,h),E(s="a=".concat(d,":")).call(s,g)),w="".concat(v.join("\r\n"),"\r\n"),y=p(w).call(w,E(a="a=".concat(u,":")).call(a,h)),k=p(w).call(w,E(o="a=".concat(d,":")).call(o,g)),this.logInfo("SDP modifier RESULT",{recoveryReason:h,reinviteReason:g,containsRecoveryReason:y,containsReinviteReason:k,insertedBeforeFirstMedia:m>=0}),this.logDebug("SDP custom reason lines",{recoveryLine:E(c="a=".concat(u,":")).call(c,h),reinviteLine:E(l="a=".concat(d,":")).call(l,g)}),t.abrupt("return",$($({},e),{sdp:w}));case 2:case"end":return t.stop()}},t,this)}))}},{key:"createRecoveryReasonSdpModifier",value:function(e,t){var i=this;return function(r){return ne(i,void 0,void 0,n.mark(function i(){return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return this.recoveryReason=e,this.reinviteReason=t,n.abrupt("return",this.applyRecoveryReasonToSdp(r));case 1:case"end":return n.stop()}},i,this)}))}}},{key:"handleReinviteRejected",value:function(e,t,i,r){return ne(this,void 0,void 0,n.mark(function s(){var a,o,c,l;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.isCurrentGeneration(e)){n.next=1;break}return n.abrupt("return");case 1:return this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.logWarn("ICE re-INVITE rejected:",i,r),n.next=2,this.rollbackLocalOffer("sip-".concat(i));case 2:if(o=n.sent,this.isCurrentGeneration(e)){n.next=3;break}return n.abrupt("return");case 3:if(o){n.next=4;break}return this.failRecovery(E(c="".concat(t,":rollback-failed:sip-")).call(c,i)),n.abrupt("return");case 4:if(this.state="idle",this.signalingBusyCount=0,481!==i){n.next=5;break}return this.failRecovery("".concat(t,":sip-481")),n.abrupt("return");case 5:if(this.isTransportAvailable()){n.next=6;break}return this.waitForTransport(E(l="".concat(t,":sip-")).call(l,i)),n.abrupt("return");case 6:if(491!==i){n.next=7;break}return this.scheduleRetry("".concat(t,":sip-491"),1500),n.abrupt("return");case 7:if(503!==i){n.next=8;break}return this.scheduleRetry("".concat(t,":sip-503"),3e3),n.abrupt("return");case 8:this.scheduleRetry(E(a="".concat(t,":sip-")).call(a,i));case 9:case"end":return n.stop()}},s,this)}))}},{key:"startNegotiationTimeout",value:function(e,t){var n=this;this.clearNegotiationTimer(),this.negotiationTimer=m(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=m(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=m(function(){if(t.retryTimer=void 0,!t.destroyed&&!t.hardFailed)if(t.isTransportAvailable()){var n=t.getPeerConnection();if(n)if("connected"!==n.iceConnectionState&&"completed"!==n.iceConnectionState){if("stable"!==n.signalingState)return t.state="waiting-signaling",void t.scheduleSignalingBusyRetry("retry-signaling-busy:".concat(n.signalingState));t.state="idle",t.recover(t.recoveryReason||e)}else t.handleIceRecovered()}else t.waitForTransport(t.recoveryReason||e)},a)}}},{key:"scheduleSignalingBusyRetry",value:function(e){var t,n=this;if(!this.destroyed&&!this.hardFailed)if(this.isTransportAvailable()){if(!this.signalingBusyTimer){this.signalingBusyCount++;var i=this.getPeerConnection();if(this.logWarn("signalingState still busy",{reason:e,signalingState:null==i?void 0:i.signalingState,count:this.signalingBusyCount,max:this.options.maxSignalingBusyRetries}),this.signalingBusyCount>this.options.maxSignalingBusyRetries)this.failRecovery("signaling-stuck:".concat(null!==(t=null==i?void 0:i.signalingState)&&void 0!==t?t:"unknown"));else{this.state="waiting-signaling";var r=Math.floor(500*Math.random()),s=this.options.signalingBusyRetryDelayMs+r;this.logInfo("schedule signaling retry in ".concat(s,"ms")),this.signalingBusyTimer=m(function(){if(n.signalingBusyTimer=void 0,!n.destroyed&&!n.hardFailed&&n.session.state===ot.Established)if(n.isTransportAvailable()){var e=n.getPeerConnection();if(e)return"stable"===e.signalingState?(n.signalingBusyCount=0,n.state="idle","connected"===e.iceConnectionState||"completed"===e.iceConnectionState?void n.handleIceRecovered():void n.recover("signaling-recovered")):void n.scheduleSignalingBusyRetry("signaling-busy:".concat(e.signalingState))}else n.waitForTransport("signaling-unavailable")},s)}}}else this.waitForTransport(e)}},{key:"isTransportAvailable",value:function(){var e=this.options.isSignalingAvailable;if(!e)return!0;try{return e()}catch(e){return this.logWarn("isSignalingAvailable() threw",e),!1}}},{key:"isRegistrationAvailable",value:function(){var e=this.options.isRegistrationAvailable;if(!e)return!0;try{return e()}catch(e){return this.logWarn("isRegistrationAvailable() threw",e),!1}}},{key:"waitForRegistration",value:function(e){var t=this;if(!this.destroyed&&!this.hardFailed){if(!this.isTransportAvailable())return this.clearRegistrationRecoveryTimer(),this.registrationWaitStartedAt=void 0,this.pendingRegistrationRecoveryReason=void 0,void this.waitForTransport(e);if(this.isRegistrationAvailable()){var n=void 0===this.registrationWaitStartedAt?0:r()-this.registrationWaitStartedAt;return this.clearRegistrationRecoveryTimer(),this.registrationWaitStartedAt=void 0,this.pendingRegistrationRecoveryReason=void 0,this.state="idle",this.logInfo("SIP registration recovered",{waitedMs:n,reason:e}),void this.resumeAfterRegistrationRecovery(e)}if(this.state="waiting-registration",this.pendingRegistrationRecoveryReason=e,void 0===this.registrationWaitStartedAt&&(this.registrationWaitStartedAt=r(),this.logWarn("SIP registration unavailable; pause ICE restart",{reason:e,timeoutMs:this.options.registrationRecoveryTimeoutMs})),!this.registrationRecoveryTimer)r()-this.registrationWaitStartedAt>=this.options.registrationRecoveryTimeoutMs?this.failRecovery("registration-recovery-timeout:".concat(e)):this.registrationRecoveryTimer=m(function(){var n;t.registrationRecoveryTimer=void 0,t.destroyed||t.hardFailed||t.session.state===ot.Established&&t.waitForRegistration(null!==(n=t.pendingRegistrationRecoveryReason)&&void 0!==n?n:e)},this.options.registrationRecoveryPollMs)}}},{key:"resumeAfterRegistrationRecovery",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){var i;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.destroyed&&!this.hardFailed&&this.session.state===ot.Established){t.next=1;break}return t.abrupt("return");case 1:if(this.isTransportAvailable()){t.next=2;break}return this.waitForTransport(e),t.abrupt("return");case 2:if(this.isRegistrationAvailable()){t.next=3;break}return this.waitForRegistration(e),t.abrupt("return");case 3:if(i=this.getPeerConnection()){t.next=4;break}return t.abrupt("return");case 4:if("connected"!==i.iceConnectionState&&"completed"!==i.iceConnectionState){t.next=5;break}return this.handleIceRecovered(),t.abrupt("return");case 5:if("stable"===i.signalingState){t.next=6;break}return this.state="waiting-signaling",this.scheduleSignalingBusyRetry("registration-restored:".concat(i.signalingState)),t.abrupt("return");case 6:return this.state="idle",t.next=7,this.recover("registration-restored:".concat(e));case 7:case"end":return t.stop()}},t,this)}))}},{key:"waitForTransport",value:function(e){var t=this;if(!this.destroyed&&!this.hardFailed){if(this.isTransportAvailable())return this.transportWaitStartedAt=void 0,this.pendingTransportRecoveryReason=void 0,this.clearTransportRecoveryTimer(),this.state="idle",void this.resumeAfterTransportRecovery(e);if(this.state="waiting-transport",void 0===this.transportWaitStartedAt&&(this.transportWaitStartedAt=r(),this.logWarn("SIP Transport unavailable; pause ICE restart",{reason:e,timeoutMs:this.options.transportRecoveryTimeoutMs})),this.pendingTransportRecoveryReason=e,!this.transportRecoveryTimer)r()-this.transportWaitStartedAt>=this.options.transportRecoveryTimeoutMs?this.failRecovery("transport-recovery-timeout:".concat(e)):this.transportRecoveryTimer=m(function(){var n,i;if(t.transportRecoveryTimer=void 0,!t.destroyed&&!t.hardFailed&&t.session.state===ot.Established)if(t.isTransportAvailable()){var s=null!==(i=t.pendingTransportRecoveryReason)&&void 0!==i?i:e,a=void 0===t.transportWaitStartedAt?0:r()-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 ne(this,void 0,void 0,n.mark(function t(){var i;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.destroyed&&!this.hardFailed&&this.session.state===ot.Established){t.next=1;break}return t.abrupt("return");case 1:if(this.isTransportAvailable()){t.next=2;break}return this.waitForTransport(e),t.abrupt("return");case 2:if(this.isRegistrationAvailable()){t.next=3;break}return this.waitForRegistration(e),t.abrupt("return");case 3:if(i=this.getPeerConnection()){t.next=4;break}return t.abrupt("return");case 4:if("connected"!==i.iceConnectionState&&"completed"!==i.iceConnectionState){t.next=5;break}return this.handleIceRecovered(),t.abrupt("return");case 5:if("stable"===i.signalingState){t.next=6;break}return this.state="waiting-signaling",this.scheduleSignalingBusyRetry("transport-restored:".concat(i.signalingState)),t.abrupt("return");case 6:return this.state="idle",t.next=7,this.recover("transport-restored:".concat(e));case 7:case"end":return t.stop()}},t,this)}))}},{key:"failRecovery",value:function(e){var t,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.clearRegistrationRecoveryTimer(),this.transportWaitStartedAt=void 0,this.pendingTransportRecoveryReason=void 0,this.registrationWaitStartedAt=void 0,this.pendingRegistrationRecoveryReason=void 0,this.stopRtpWatchdog(),this.logError("ICE recovery unrecoverable",{reason:e,retryCount:this.retryCount,signalingBusyCount:this.signalingBusyCount,iceConnectionState:null===(t=this.getPeerConnection())||void 0===t?void 0:t.iceConnectionState,connectionState:null===(n=this.getPeerConnection())||void 0===n?void 0:n.connectionState,signalingState:null===(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=r(),this.rtpStatsTimer=L(function(){e.checkRtpHealth()},this.options.rtpStatsIntervalMs))}},{key:"stopRtpWatchdog",value:function(){this.rtpStatsTimer&&(clearInterval(this.rtpStatsTimer),this.rtpStatsTimer=void 0)}},{key:"checkRtpHealth",value:function(){return ne(this,void 0,void 0,n.mark(function e(){var t,i,s,a,o,c,l,u;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.destroyed&&!this.hardFailed&&this.session.state===ot.Established){e.next=1;break}return e.abrupt("return");case 1:if(t=this.getPeerConnection()){e.next=2;break}return e.abrupt("return");case 2:if("connected"===t.iceConnectionState||"completed"===t.iceConnectionState){e.next=3;break}return e.abrupt("return");case 3:if("sending-reinvite"!==this.state&&"waiting-ice"!==this.state&&"waiting-signaling"!==this.state&&"waiting-transport"!==this.state){e.next=4;break}return e.abrupt("return");case 4:return e.prev=4,e.next=5,this.readRtpSnapshot(t);case 5:i=e.sent,e.next=7;break;case 6:return e.prev=6,u=e.catch(4),this.logDebug("getStats failed:",u),e.abrupt("return");case 7:if(i.hasAudio||i.hasVideo){e.next=8;break}return e.abrupt("return");case 8:if(s=this.lastRtpSnapshot,this.lastRtpSnapshot=i,s){e.next=9;break}return this.lastRtpProgressAt=r(),e.abrupt("return");case 9:if(a=i.audioBytes>s.audioBytes||i.audioPackets>s.audioPackets,o=i.videoBytes>s.videoBytes||i.videoPackets>s.videoPackets||i.videoFramesDecoded>s.videoFramesDecoded,!a&&!o){e.next=10;break}return this.lastRtpProgressAt=r(),e.abrupt("return");case 10:if(!((c=r()-this.lastRtpProgressAt)<this.options.rtpStallTimeoutMs)){e.next=11;break}return e.abrupt("return");case 11:if(!((l=r())-this.lastRtpRecoveryAt<this.options.rtpRecoveryCooldownMs)){e.next=12;break}return e.abrupt("return");case 12:if(this.logWarn("RTP stalled for ".concat(c,"ms"),{ice:t.iceConnectionState,connection:t.connectionState,signaling:t.signalingState,audioBytes:i.audioBytes,audioPackets:i.audioPackets,videoBytes:i.videoBytes,videoPackets:i.videoPackets,videoFramesDecoded:i.videoFramesDecoded}),this.options.recoverOnRtpStallWhenIceConnected){e.next=13;break}return e.abrupt("return");case 13:this.lastRtpRecoveryAt=l,this.recover("rtp-stalled");case 14:case"end":return e.stop()}},e,this,[[4,6]])}))}},{key:"readRtpSnapshot",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){var i,s;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=1,e.getStats();case 1:return i=t.sent,s={timestamp:r(),audioBytes:0,audioPackets:0,videoBytes:0,videoPackets:0,videoFramesDecoded:0,hasAudio:!1,hasVideo:!1},h(i).call(i,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&&(s.hasAudio=!0,"number"==typeof e.bytesReceived&&(s.audioBytes+=e.bytesReceived),"number"==typeof e.packetsReceived&&(s.audioPackets+=e.packetsReceived)),"video"===n&&(s.hasVideo=!0,"number"==typeof e.bytesReceived&&(s.videoBytes+=e.bytesReceived),"number"==typeof e.packetsReceived&&(s.videoPackets+=e.packetsReceived),"number"==typeof e.framesDecoded&&(s.videoFramesDecoded+=e.framesDecoded))}}),t.abrupt("return",s);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:R(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:R(r).call(r)}:{}}},{key:"hasIceCredentialsChanged",value:function(e,t){return e.ufrag!==t.ufrag||e.pwd!==t.pwd}},{key:"isRequestPendingError",value:function(e){return e instanceof Error&&("RequestPendingError"===e.name||/request.*pending/i.test(e.message))}},{key:"isCurrentGeneration",value:function(e){return!this.destroyed&&!this.hardFailed&&e===this.recoveryGeneration}},{key:"clearDisconnectedTimer",value:function(){this.disconnectedTimer&&(clearTimeout(this.disconnectedTimer),this.disconnectedTimer=void 0)}},{key:"clearRetryTimer",value:function(){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0)}},{key:"clearSignalingBusyTimer",value:function(){this.signalingBusyTimer&&(clearTimeout(this.signalingBusyTimer),this.signalingBusyTimer=void 0)}},{key:"clearNegotiationTimer",value:function(){this.negotiationTimer&&(clearTimeout(this.negotiationTimer),this.negotiationTimer=void 0)}},{key:"clearIceRecoveryTimer",value:function(){this.iceRecoveryTimer&&(clearTimeout(this.iceRecoveryTimer),this.iceRecoveryTimer=void 0)}},{key:"clearTransportRecoveryTimer",value:function(){this.transportRecoveryTimer&&(clearTimeout(this.transportRecoveryTimer),this.transportRecoveryTimer=void 0)}},{key:"clearRegistrationRecoveryTimer",value:function(){this.registrationRecoveryTimer&&(clearTimeout(this.registrationRecoveryTimer),this.registrationRecoveryTimer=void 0)}},{key:"clearAllTimers",value:function(){this.clearDisconnectedTimer(),this.clearRetryTimer(),this.clearSignalingBusyTimer(),this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.stopRtpWatchdog(),this.onlineTimer&&(clearTimeout(this.onlineTimer),this.onlineTimer=void 0)}},{key:"logDebug",value:function(){for(var e,t,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,E(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,E(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,E(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,E(t=[n,"[SipIceRecovery]"]).call(t,s))}}])}(),fa=function(){return t(function t(n){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:200;e(this,t),d(this,"onAggregateCallback",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"debounceTime",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"pendingCalls",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.onAggregateCallback=n,this.debounceTime=i,this.pendingCalls=new M},[{key:"receive",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){var i,r,s,a,o,c=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:i=e.CALLID,r=e.ENTRY,this.pendingCalls.has(i)?(s=this.pendingCalls.get(i),clearTimeout(s.timer),s.data.ENTRY.push(r),s.count+=1,s.timer=m(function(){return c._flush(i)},this.debounceTime)):((a=JSON.parse(C(e))).ENTRY=[r],o=m(function(){return c._flush(i)},this.debounceTime),this.pendingCalls.set(i,{timer:o,data:a,count:1}));case 1:case"end":return t.stop()}},t,this)}))}},{key:"_flush",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){var i,r;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.pendingCalls.has(e)){t.next=1;break}return i=this.pendingCalls.get(e),r=i.data,this.pendingCalls.delete(e),t.next=1,this.onAggregateCallback(r);case 1:case"end":return t.stop()}},t,this)}))}}])}(),va=function(){return t(function t(){var s=this,a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e(this,t),Ui.add(this),Bi.set(this,void 0),Li.set(this,void 0),Gi.set(this,void 0),Vi.set(this,void 0),Wi.set(this,void 0),Yi.set(this,void 0),Ki.set(this,[]),zi.set(this,[]),Zi.set(this,{}),Ji.set(this,void 0),Xi.set(this,void 0),Qi.set(this,new MediaStream),er.set(this,JSON.parse(C(ji))),tr.set(this,0),nr.set(this,void 0),ir.set(this,void 0),rr.set(this,void 0),d(this,"token",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),sr.set(this,void 0),ar.set(this,48e4),or.set(this,12e6),cr.set(this,{}),lr.set(this,!1),ur.set(this,void 0),dr.set(this,void 0),hr.set(this,void 0),gr.set(this,function(e){}),fr.set(this,function(e){}),vr.set(this,function(e){}),pr.set(this,function(e){}),mr.set(this,function(e){return ne(s,void 0,void 0,n.mark(function t(){var i,s,a,o;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!ie(this,nr,"f")||!ie(this,ir,"f")){t.next=3;break}if(!(r()-ie(this,ir,"f")>e)){t.next=3;break}return t.next=1,ie(this,wr,"f").call(this);case 1:if(o=t.sent){t.next=2;break}o={};case 2:s=(i=o).sign,a=i.timestamp,re(this,nr,null!=s?s:ie(this,nr,"f"),"f"),re(this,ir,null!=a?a:ie(this,ir,"f"),"f");case 3:case"end":return t.stop()}},t,this)}))}),br.set(this,function(e){return ne(s,void 0,void 0,n.mark(function t(){var i,s,a,o,c;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!ie(this,sr,"f")){t.next=4;break}if(!(r()-ie(this,sr,"f")>e)){t.next=4;break}if(!ie(this,rr,"f")){t.next=2;break}return t.next=1,ie(this,Tr,"f").call(this);case 1:i=t.sent,s=i.token,a=i.tokenTimestamp,re(this,rr,null!=s?s:ie(this,rr,"f"),"f"),re(this,sr,null!=a?a:r(),"f"),t.next=4;break;case 2:if(!this.token){t.next=4;break}return t.next=3,this.getGatewayAccessToken({corpId:ie(this,Vr,"f"),sid:ie(this,Qr,"f"),secret:ie(this,Wr,"f"),seatOnline:!1});case 3:o=t.sent,c=o.token,this.token=c,re(this,sr,r(),"f");case 4:case"end":return t.stop()}},t,this)}))}),wr.set(this,function(){}),yr.set(this,function(e){ie(s,lr,"f")&&ie(s,kr,"f").receive(e)}),kr.set(this,new fa(function(e){var t,n,i;delete e.INVITE,null===(i=null===(n=Fi.getAliArms())||void 0===n?void 0:n.getInstance())||void 0===i||i.api({api:E(t="softphone-sdk-auto-ignore-".concat(ie(s,Vr,"f"),"-")).call(t,ie(s,Zi,"f").authorizationUsername),msg:C({errorInfo:e,businessAttribute:A(ie(s,ds,"f")).length?ie(s,ds,"f"):void 0,appKey:ie(s,Vr,"f")||void 0,agentId:ie(s,Qr,"f")||void 0,agentTag:ie(s,Yr,"f")||void 0,agentExtension:ie(s,Zi,"f").authorizationUsername||void 0,bjDate:Ci(),timestamp:r()}),traceId:e.CALLID,code:e.CODE,success:!0,time:0})})),Tr.set(this,function(){}),Rr.set(this,function(e){}),Sr.set(this,function(e){}),Ir.set(this,void 0),Er.set(this,void 0),d(this,"networkSpeed",{enumerable:!0,configurable:!0,writable:!0,value:"0.00Mb/s"}),d(this,"networkDelay",{enumerable:!0,configurable:!0,writable:!0,value:"0ms"}),d(this,"onLine",{enumerable:!0,configurable:!0,writable:!0,value:navigator.onLine}),d(this,"testspeeding",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"goodNetworkSpeed",{enumerable:!0,configurable:!0,writable:!0,value:function(){return 1e3*Number(s.networkSpeed.replace("Mb/s",""))>=30}}),d(this,"goodNetworkDelay",{enumerable:!0,configurable:!0,writable:!0,value:function(){return Number(s.networkDelay.replace("ms",""))<=500&&"0ms"!==s.networkDelay}}),d(this,"authorizedMicrophonePermissions",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"authorizedNotificationPermissions",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Cr.set(this,100),Ar.set(this,3),xr.set(this,8),Dr.set(this,2),Hr.set(this,0),_r.set(this,!1),$r.set(this,void 0),qr.set(this,3),Mr.set(this,3),Pr.set(this,0),Or.set(this,0),Nr.set(this,0),jr.set(this,!1),Fr.set(this,!1),Ur.set(this,!1),Br.set(this,void 0),Lr.set(this,void 0),Gr.set(this,void 0),Vr.set(this,void 0),Wr.set(this,void 0),Yr.set(this,void 0),Kr.set(this,void 0),zr.set(this,void 0),Zr.set(this,void 0),Jr.set(this,void 0),Xr.set(this,void 0),Qr.set(this,void 0),es.set(this,void 0),ts.set(this,void 0),ns.set(this,void 0),is.set(this,void 0),rs.set(this,function(e){ie(s,Ui,"m",aa).call(s)}),ss.set(this,function(){}),as.set(this,void 0),os.set(this,void 0),cs.set(this,!1),ls.set(this,4e3),us.set(this,4e3),ds.set(this,{}),hs.set(this,!1),gs.set(this,!0),d(this,"ifAutoAnswer",{enumerable:!0,configurable:!0,writable:!0,value:function(){return String(ie(s,ds,"f").autoAnswer)===Ai.YES}}),d(this,"notNeedSendStarDtmf",{enumerable:!0,configurable:!0,writable:!0,value:function(){return String(ie(s,ds,"f").afterTransferLabour)===Hi.DIRECT_ANSWER}}),fs.set(this,function(){if(ie(s,gs,"f")){var e;ie(s,vs,"f").call(s);var t=new(window.AudioContext||window.webkitAudioContext);re(s,dr,t.createScriptProcessor(2048,1,1),"f"),ie(s,dr,"f").onaudioprocess=function(e){for(var t=e.inputBuffer.getChannelData(0),n=0,i=0;i<t.length;++i)n+=t[i]*t[i];re(s,tr,Number(Math.sqrt(n/t.length).toFixed(2)),"f"),ie(s,gr,"f").call(s,ie(s,tr,"f"))},re(s,hr,new MediaStream,"f"),h(e=s.getSenders()).call(e,function(e){e.track&&ie(s,hr,"f").addTrack(e.track)}),re(s,ur,t.createMediaStreamSource(ie(s,hr,"f")),"f"),ie(s,ur,"f").connect(ie(s,dr,"f")),ie(s,dr,"f").connect(t.destination)}}),vs.set(this,function(){if(ie(s,gs,"f")){if(ie(s,ur,"f"))try{ie(s,ur,"f").disconnect()}catch(e){console.log(e)}if(ie(s,dr,"f"))try{ie(s,dr,"f").disconnect()}catch(e){console.log(e)}if(ie(s,hr,"f"))try{var e;h(e=ie(s,hr,"f").getTracks()).call(e,function(e){e.stop()})}catch(e){console.log(e)}}re(s,ur,void 0,"f"),re(s,dr,void 0,"f"),re(s,hr,void 0,"f"),re(s,tr,0,"f"),ie(s,gr,"f").call(s,ie(s,tr,"f"))}),d(this,"disposeSoftphoneEnvRequirementCheck",{enumerable:!0,configurable:!0,writable:!0,value:function(){ie(s,ps,"f").call(s),window.removeEventListener("offline",ie(s,ws,"f")),window.removeEventListener("online",ie(s,bs,"f")),window.removeEventListener("unload",s.disposeSoftphoneEnvRequirementCheck)}}),ps.set(this,function(){clearInterval(ie(s,Ir,"f")),re(s,Ir,void 0,"f"),clearTimeout(ie(s,Er,"f")),re(s,Er,void 0,"f"),s.testspeeding=!1}),d(this,"softphoneEnvCheck",{enumerable:!0,configurable:!0,writable:!0,value:function(){return ne(s,void 0,void 0,n.mark(function e(){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:this.testspeeding||(ie(this,ms,"f").call(this),this.oneRoundOfTesting());case 1:case"end":return e.stop()}},e,this)}))}}),ms.set(this,function(){window.addEventListener("offline",ie(s,ws,"f")),window.addEventListener("online",ie(s,bs,"f")),window.addEventListener("unload",s.disposeSoftphoneEnvRequirementCheck)}),d(this,"oneRoundOfTesting",{enumerable:!0,configurable:!0,writable:!0,value:function(){return ne(s,void 0,void 0,n.mark(function e(){var t=this;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:this.testspeeding=!0,this.detectNavigatorPermissions(),this.onLine?(ie(this,ys,"f").call(this,this),re(this,Er,m(function(){t.testspeeding=!1,t.disposeSoftphoneEnvRequirementCheck()},4e3),"f")):this.testspeeding=!1;case 1:case"end":return e.stop()}},e,this)}))}}),bs.set(this,function(){s.onLine=!0,s.oneRoundOfTesting()}),ws.set(this,function(){s.onLine=!1,s.networkSpeed="0.00Mb/s",s.networkDelay="0ms",ie(s,Sr,"f").call(s,{networkSpeed:s.networkSpeed,networkDelay:s.networkDelay,authorizedMicrophonePermissions:s.authorizedMicrophonePermissions,authorizedNotificationPermissions:s.authorizedNotificationPermissions}),ie(s,ps,"f").call(s)}),ys.set(this,function(e){return ne(s,void 0,void 0,n.mark(function t(){var i,r,s=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return i=e||this,clearInterval(ie(i,Ir,"f")),re(i,Ir,void 0,"f"),r=function(){return ne(s,void 0,void 0,n.mark(function e(){var t;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!i.onLine){e.next=5;break}return e.prev=1,e.next=2,ie(i,ks,"f").call(i,"1"===ie(i,ns,"f")?"https://seat.teleai.com/favicon.png":void 0);case 2:t=e.sent,i.networkSpeed=t.networkSpeed,i.networkDelay=t.networkDelay,e.next=4;break;case 3:e.prev=3,e.catch(1),i.networkSpeed="0.00Mb/s",i.networkDelay="0ms";case 4:e.next=6;break;case 5:i.networkSpeed="0.00Mb/s",i.networkDelay="0ms";case 6:ie(this,Sr,"f").call(this,{networkSpeed:this.networkSpeed,networkDelay:this.networkDelay,authorizedMicrophonePermissions:this.authorizedMicrophonePermissions,authorizedNotificationPermissions:this.authorizedNotificationPermissions}),ie(this,Er,"f")||(this.testspeeding=!1,this.disposeSoftphoneEnvRequirementCheck());case 7:case"end":return e.stop()}},e,this,[[1,3]])}))},t.next=1,r();case 1:ie(this,Er,"f")&&re(i,Ir,L(function(){return ne(this,void 0,void 0,n.mark(function e(){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,r();case 1:case"end":return e.stop()}},e)}))},1e3),"f");case 2:case"end":return t.stop()}},t,this)}))}),ks.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,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;return ne(s,void 0,void 0,n.mark(function s(){var o,c;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:for(o=[],c=0;c<a;c++)o.push(ie(this,Ts,"f").call(this,e+"?d="+r()+c,t));return n.abrupt("return",i.all(o).then(function(e){var t=0,n=0;return h(e).call(e,function(e){t+=Number(e[0]),n+=Number(e[1])}),{networkDelay:(n/a).toFixed(2)+"ms",networkSpeed:(t/a).toFixed(2)+"Mb/s"}}));case 1:case"end":return n.stop()}},s,this)}))}),Ts.set(this,function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"https://seat.94ai.com/favicon.png?d="+r(),t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:63491;return new i(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})}),d(this,"openApiAjax",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return new i(function(t,i){return ne(s,void 0,void 0,n.mark(function s(){var a,o,c,l,u,d,h,g,f,v,p,m,b,w,y,k,T;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(n.prev=0,f=ie(this,Vr,"f")||(null===(a=e.data)||void 0===a?void 0:a.appKey),v=ie(this,Wr,"f")||(null===(o=e.data)||void 0===o?void 0:o.appSecret),p=ie(this,nr,"f")||(null===(c=e.data)||void 0===c?void 0:c.sign),m=ie(this,ir,"f")||(null===(l=e.data)||void 0===l?void 0:l.timestamp),null===(u=e.data)||void 0===u||delete u.appKey,null===(d=e.data)||void 0===d||delete d.appSecret,null===(h=e.data)||void 0===h||delete h.sign,null===(g=e.data)||void 0===g||delete g.timestamp,f){n.next=1;break}throw new Error("缺少appKey");case 1:if(!v){n.next=2;break}m=r(),p=J.enc.Base64.stringify(J.HmacSHA1(f+m,v)),n.next=5;break;case 2:if(!p||!m){n.next=4;break}return n.next=3,ie(this,mr,"f").call(this,ie(this,ar,"f"));case 3:p=ie(this,nr,"f")||p,m=ie(this,ir,"f")||m,n.next=5;break;case 4:throw new Error("缺少appSecret或sign+timestamp");case 5:return b=Ei(t,i,e),w=b.xhr,y=b.ajaxData,k=b.contentType,w.setRequestHeader("appKey",f),w.setRequestHeader("timestamp",String(m)),w.setRequestHeader("sign",p),w.setRequestHeader("Content-type",k||"application/json"),n.next=6,ie(this,vr,"f").call(this,w);case 6:w.send(y),n.next=8;break;case 7:throw n.prev=7,T=n.catch(0),i(T.message),T;case 8:case"end":return n.stop()}},s,this,[[0,7]])}))})}}),d(this,"requestGateway",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return s.gatewayApiAjax($($({},e),{url:s.getGateway()+e.url}),t)}}),d(this,"gatewayApiAjax",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return new i(function(i,r){return ne(s,void 0,void 0,n.mark(function s(){var a,o,c,l,u,d;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(n.prev=0,a=Ei(i,r,e),o=a.xhr,c=a.ajaxData,l=a.contentType,!t){n.next=2;break}return n.next=1,this.getGatewayToken();case 1:u=n.sent,o.setRequestHeader("x-token",u),o.setRequestHeader("seatsToken",u),o.setRequestHeader("x-authority-token",u);case 2:return o.setRequestHeader("x-app-code",3),o.setRequestHeader("content-type",l||"application/json"),n.next=3,ie(this,pr,"f").call(this,o);case 3:o.send(c),n.next=5;break;case 4:throw n.prev=4,d=n.catch(0),r(d.message),d;case 5:case"end":return n.stop()}},s,this,[[0,4]])}))})}}),d(this,"requestOpenApi",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return s.openApiAjax($($({},e),{url:s.getOpenApi()+e.url}))}}),d(this,"getDeviceId",{enumerable:!0,configurable:!0,writable:!0,value:function(){return ne(s,void 0,void 0,n.mark(function e(){var t,i;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!ie(this,is,"f")){e.next=1;break}return e.abrupt("return",ie(this,is,"f"));case 1:return e.next=2,X.load();case 2:return t=e.sent,e.next=3,t.get();case 3:return i=e.sent,re(this,is,i.visitorId,"f"),e.abrupt("return",ie(this,is,"f"));case 4:case"end":return e.stop()}},e,this)}))}}),Ds.set(this,function(){return ne(s,void 0,void 0,n.mark(function e(){var t,i,r,s,a,o,c=this;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!ie(this,Ui,"m",xs).call(this)||ie(this,Zi,"f").authorizationUsername&&ie(this,Zi,"f").uri&&ie(this,Zi,"f").authorizationPassword&&ie(this,Zi,"f").transportOptions.server){e.next=3;break}return e.next=1,this.getAgentInfo();case 1:if(200!=(r=e.sent).code){e.next=2;break}o=r.data,ie(this,Zi,"f").authorizationUsername=o.agentExtension,ie(this,Zi,"f").authorizationPassword=o.extensionPwd,ie(this,Zi,"f").contactName||(ie(this,Zi,"f").contactName=o.agentExtension),ie(this,Zi,"f").uri=ui.makeURI(E(s="sip:".concat(o.agentExtension,"@")).call(s,o.wsRegisterAddress)),ie(this,Zi,"f").transportOptions.server=E(a="".concat(o.wsProtocol,"://")).call(a,o.wsRegisterAddress),re(this,Qr,o.agentId,"f"),re(this,Yr,o.agentTag,"f"),re(this,Kr,o.agentName,"f"),re(this,zr,o.agentAccount,"f"),re(this,Zr,o.agentActive,"f"),re(this,Jr,o.agentGroupIds,"f"),re(this,Xr,o.agentStatus,"f"),null===(i=null===(t=Fi.getAliArms())||void 0===t?void 0:t.getInstance())||void 0===i||i.setConfig({setUsername:function(){return ie(c,Vr,"f")+"-"+ie(c,Zi,"f").authorizationUsername}}),e.next=3;break;case 2:throw new Error(C(r));case 3:case"end":return e.stop()}},e,this)}))}),Hs.set(this,function(){return ne(s,void 0,void 0,n.mark(function e(){var t;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(ie(this,Zi,"f").viaHost){e.next=2;break}return t="",e.next=1,this.getDeviceId();case 1:ie(this,Zi,"f").viaHost=E(t).call(t,e.sent,".sip");case 2:case"end":return e.stop()}},e,this)}))}),$s.set(this,function(e){var t,n,i,r,a,o,c,l,u,d,h,g,f,v,p,m,b,y,k,T,R,S,I;ie(s,ds,"f").popWindow=null===(a=e["X-Popwindow"])||void 0===a?void 0:a[0].raw,ie(s,ds,"f").afterTransferLabour=null===(o=e["X-Aftertransferlabour"])||void 0===o?void 0:o[0].raw,ie(s,ds,"f").callId=null===(c=e["X-94callid"])||void 0===c?void 0:c[0].raw,ie(s,ds,"f").cid=null===(l=e["X-Cid"])||void 0===l?void 0:l[0].raw,ie(s,ds,"f").numberId=null===(u=e["X-Numberid"])||void 0===u?void 0:u[0].raw,ie(s,ds,"f").tag=(null===(d=e["X-Tag"])||void 0===d?void 0:d[0].raw)&&"null"!==(null===(h=e["X-Tag"])||void 0===h?void 0:h[0].raw)?w(t=e["X-Tag"][0].raw.split("-")).call(t,function(e){return String.fromCharCode(e)}).join(""):"",ie(s,ds,"f").numberTag=(null===(g=e["X-Numbertag"])||void 0===g?void 0:g[0].raw)&&"null"!==(null===(f=e["X-Numbertag"])||void 0===f?void 0:f[0].raw)?decodeURIComponent(e["X-Numbertag"][0].raw):"",ie(s,ds,"f").taskId=null===(v=e["X-Taskid"])||void 0===v?void 0:v[0].raw,ie(s,ds,"f").voiceType=null===(p=e["X-Voicetype"])||void 0===p?void 0:p[0].raw,ie(s,ds,"f").processTime=null===(m=e["X-Processtime"])||void 0===m?void 0:m[0].raw,ie(s,ds,"f").userPhone=null===(b=e["X-Userphone"])||void 0===b?void 0:b[0].raw,ie(s,ds,"f").autoAnswer=null===(y=e["X-94autoanswer"])||void 0===y?void 0:y[0].raw,ie(s,ds,"f").nodeTitle=null===(k=e["X-Nodetitle"])||void 0===k?void 0:w(n=k[0].raw.split("-")).call(n,function(e){return String.fromCharCode(e)}).join(""),ie(s,ds,"f").taskName=null===(T=e["X-Taskname"])||void 0===T?void 0:w(i=T[0].raw.split("-")).call(i,function(e){return String.fromCharCode(e)}).join(""),ie(s,ds,"f").templateTitle=null===(R=e["X-Templatetitle"])||void 0===R?void 0:w(r=R[0].raw.split("-")).call(r,function(e){return String.fromCharCode(e)}).join(""),ie(s,ds,"f").phoneNumber=(null===(S=e["X-Phonenumber"])||void 0===S?void 0:S[0].raw)||(null===(I=e.From)||void 0===I?void 0:I[0].parsed.uri.normal.user)}),Ys.set(this,function(e){switch(e){case ot.Initial:case ot.Establishing:break;case ot.Established:ie(s,Ui,"m",Ws).call(s);break;case ot.Terminating:case ot.Terminated:s.clearIceAutoDetection();var t=m(function(){clearTimeout(t),t=void 0,ie(s,er,"f").incomingStatus=!1,ie(s,er,"f").answerStatus=!1},10);ie(s,vs,"f").call(s);break;default:throw new Error("Unknown session state.")}}),zs.set(this,function(e,t,n){ie(s,xr,"f")&&(re(s,_r,!1,"f"),ie(s,er,"f").reconnectStatus=!1,ie(s,Fr,"f")&&(re(s,Fr,!1,"f"),ie(s,Xs,"f").call(s,e,t,n)))}),Zs.set(this,function(){return ne(s,void 0,void 0,n.mark(function e(){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(ie(this,xr,"f")){re(this,_r,!0,"f"),re(this,Fr,!1,"f");try{this.getUserAgent().transport.disconnect().catch(function(e){return console.error(e)})}catch(e){}console.log("sip transport disconnect");try{ie(this,Ui,"m",Ks).call(this)}catch(e){}ie(this,Qs,"f").call(this),ie(this,Ui,"m",aa).call(this)}case 1:case"end":return e.stop()}},e,this)}))}),Js.set(this,function(){if(ie(s,xr,"f")){var e=ie(s,Zi,"f").uri.clone(),t=ie(s,Zi,"f").uri.clone(),n=ie(s,Zi,"f").uri.clone();n.user=void 0,ie(s,Xs,"f").call(s,n,e,t)}}),Xs.set(this,function(e,t,n){if(ie(s,xr,"f")){if(ie(s,Fr,"f"))return;re(s,Fr,!0,"f"),re(s,Lr,m(function(){ie(s,Ui,"m",ra).call(s);var i=s.getUserAgent().userAgentCore,r=i.makeOutgoingRequestMessage("OPTIONS",e,t,n,{});re(s,$r,i.request(r,{onAccept:function(){console.log("sip ping ok"),re(s,Hr,0,"f"),re(s,$r,void 0,"f"),ie(s,zs,"f").call(s,e,t,n)},onReject:function(i){var r;if(re(s,$r,void 0,"f"),408===i.message.statusCode||503===i.message.statusCode)if(console.log("sip ping error with code "+i.message.statusCode),ie(s,Dr,"f")>0&&ie(s,Hr,"f")>=ie(s,Dr,"f"))console.log("sip maximum ping attempts reached"),ie(s,Zs,"f").call(s);else{var a,o;if(ie(s,Hr,"f")>0)console.log(E(o="sip ping retry ".concat(ie(s,Hr,"f")," of ")).call(o,ie(s,Dr,"f")," fail"));re(s,Hr,(r=ie(s,Hr,"f"),++r),"f"),console.log(E(a="sip ping retry ".concat(ie(s,Hr,"f")," of ")).call(a,ie(s,Dr,"f"))),ie(s,zs,"f").call(s,e,t,n)}else re(s,Hr,0,"f"),ie(s,zs,"f").call(s,e,t,n)}}),"f")},1e3*ie(s,xr,"f")),"f")}}),Qs.set(this,function(){if(ie(s,xr,"f")){if(re(s,Fr,!1,"f"),re(s,_r,!1,"f"),ie(s,$r,"f")){try{ie(s,$r,"f").dispose()}catch(e){}re(s,$r,void 0,"f")}ie(s,Lr,"f")&&ie(s,Ui,"m",ra).call(s)}}),sa.set(this,function(){if(ie(s,qr,"f")){if(ie(s,Ur,"f"))return;re(s,Ur,!0,"f"),ie(s,er,"f").reconnectStatus=!0,re(s,Gr,m(function(){return ne(s,void 0,void 0,n.mark(function e(){var t,i=this;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,ie(this,Ui,"m",na).call(this),0===ie(this,Pr,"f")&&console.log("sip reconnect success then register start"),e.next=1,ie(this,Vi,"f").register({requestDelegate:{onAccept:function(e){console.log("sip reconnect success and register ok"),re(i,Pr,0,"f"),re(i,Ur,!1,"f"),ie(i,er,"f").registerStatus=!0,ie(i,er,"f").reconnectStatus=!1,ie(i,Js,"f").call(i)},onReject:function(e){return ne(i,void 0,void 0,n.mark(function t(){var i,r;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(console.log("sip reconnect success but register fail with code "+e.message.statusCode),re(this,Ur,!1,"f"),!(ie(this,Mr,"f")<=ie(this,Pr,"f"))){t.next=2;break}return console.log("sip maximum register attempts reached"),re(this,Pr,0,"f"),t.next=1,this.getUserAgent().transport.disconnect().catch(function(e){return console.error(e)});case 1:ie(this,Ui,"m",aa).call(this),t.next=3;break;case 2:re(this,Pr,(i=ie(this,Pr,"f"),++i),"f"),console.log(E(r="sip reconnect success and register retry ".concat(ie(this,Pr,"f")," of ")).call(r,ie(this,Mr,"f"))),ie(this,sa,"f").call(this);case 3:case"end":return t.stop()}},t,this)}))}},requestOptions:{extraHeaders:ie(this,Li,"f")}});case 1:e.next=3;break;case 2:e.prev=2,t=e.catch(0),console.log("sip reconnect then registerer register error",t),re(this,Pr,0,"f"),re(this,Ur,!1,"f");case 3:case"end":return e.stop()}},e,this,[[0,2]])}))},1e3*ie(s,qr,"f")),"f")}}),"object"!==K(a))throw new Error("userAgentOption must be plain object");ie(this,Ui,"m",Es).call(this,a),ie(this,Ui,"m",Cs).call(this,a),ie(this,Ui,"m",Is).call(this,a),ie(this,Ui,"m",As).call(this,a),ie(this,Ui,"m",Ms).call(this,a),ie(this,Ui,"m",Ss).call(this,a),ie(this,Ui,"m",Rs).call(this,a),re(this,Zi,ie(this,Ui,"m",Os).call(this,a),"f")},[{key:"armsReportFlag",get:function(){return ie(this,lr,"f")},set:function(e){re(this,lr,e,"f")}},{key:"volumeValue",get:function(){return ie(this,tr,"f")}},{key:"getToken",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return ne(this,void 0,void 0,n.mark(function t(){var i,r,s,a,o,c,l,u,d,h,g,f;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=(i=e||{}).appKey,s=i.appSecret,a=i.agentId,o=i.agentTag,c=a||ie(this,Qr,"f"),l=o||ie(this,Yr,"f"),u=s||ie(this,Wr,"f"),d=r||ie(this,Vr,"f"),c||!l||!u||!d){t.next=3;break}return t.next=1,this.getAgentInfo({agentTag:l,appSecret:u,appKey:d});case 1:if(200!=(h=t.sent).code){t.next=2;break}re(this,Qr,c=h.data.agentId,"f"),t.next=3;break;case 2:throw new Error(h.message);case 3:return t.next=4,this.getGatewayAccessToken({corpId:d,secret:u,sid:c,seatOnline:!1});case 4:return g=t.sent,f=g.token,t.abrupt("return",f);case 5:case"end":return t.stop()}},t,this)}))}},{key:"armsReport",value:function(e){var t,n,i,s,a=e.api,o=e.traceId,c=e.code,l=e.success,u=e.begin,d=e.time,h=e.businessInfo;"softphone-sdk-hangup"!==e.api&&"softphone-sdk-seats-status-change"!==e.api&&"softphone-sdk-accept"!==e.api&&"softphone-sdk-connect"!==e.api&&"softphone-sdk-send-star-dtmf"!==e.api&&"softphone-sdk-ignore"!==e.api&&"softphone-sdk-manual-call"!==e.api||(null===(n=null===(t=Fi.getAliArms())||void 0===t?void 0:t.getInstance())||void 0===n||n.api({api:E(i=E(s="".concat(a,"-")).call(s,ie(this,Vr,"f"),"-")).call(i,ie(this,Zi,"f").authorizationUsername),msg:C({appKey:ie(this,Vr,"f")||void 0,agentId:ie(this,Qr,"f")||void 0,agentTag:ie(this,Yr,"f")||void 0,agentExtension:ie(this,Zi,"f").authorizationUsername||void 0,businessAttribute:A(ie(this,ds,"f")).length?ie(this,ds,"f"):void 0,businessInfo:A(h||{}).length?h:void 0,bjDate:Ci(),timestamp:r()}),traceId:o,code:c,success:l,time:d,begin:u}))}},{key:"appKey",get:function(){return ie(this,Vr,"f")}},{key:"agentTag",get:function(){return ie(this,Yr,"f")}},{key:"agentExtension",get:function(){return ie(this,Zi,"f").authorizationUsername}},{key:"agentId",get:function(){return ie(this,Qr,"f")}},{key:"businessAttribute",get:function(){return ie(this,ds,"f")}},{key:"getFastOutboundCall",value:function(){return ie(this,ds,"f").voiceType===Di.LABOUR}},{key:"getSitOutboundCall",value:function(){return ie(this,ds,"f").voiceType===Di.AI}},{key:"detectNavigatorPermissions",value:function(){var e,t=this;-1===q(e=navigator.userAgent).call(e,"Firefox")?navigator.permissions.query({name:"microphone"}).then(function(e){"granted"===e.state?t.authorizedMicrophonePermissions=!0:t.authorizedMicrophonePermissions=!1}).catch(function(e){console.log("Got error :",e),t.authorizedMicrophonePermissions=!1}):navigator.mediaDevices.enumerateDevices().then(function(e){""!==f(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"===ie(this,ns,"f")?"https://gateway.teleai.com":"https://gateway.94ai.com"}},{key:"getGatewayToken",value:function(){return ne(this,void 0,void 0,n.mark(function e(){var t,i;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,ie(this,br,"f").call(this,ie(this,or,"f"));case 1:if(!ie(this,rr,"f")){e.next=2;break}return e.abrupt("return",ie(this,rr,"f"));case 2:if(this.token){e.next=5;break}return e.next=3,ie(this,Ds,"f").call(this);case 3:return e.next=4,this.getGatewayAccessToken({corpId:ie(this,Vr,"f"),sid:ie(this,Qr,"f"),secret:ie(this,Wr,"f"),seatOnline:!1});case 4:t=e.sent,i=t.token,this.token=i,re(this,sr,r(),"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 ne(this,void 0,void 0,n.mark(function e(){var t,r,s,a=this;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t=$({},ie(this,ds,"f")),r=function(){return ne(a,void 0,void 0,n.mark(function e(){var i,r,s,a,o,c,l,u,d,h,g,f,v,p,m,b,y,k,T,R;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.numberId||!t.taskId){e.next=13;break}return i={},e.prev=1,e.next=2,this.getCallNumberDetail({id:t.numberId,taskId:t.taskId});case 2:if(200===(i=e.sent).code){e.next=3;break}return console.error(i.message),t.stop=!0,ie(this,Rr,"f").call(this,i.message),e.abrupt("return");case 3:e.next=5;break;case 4:return e.prev=4,e.catch(1),a=E(r=E(s="当前会话callid:".concat(t.callId,",根据numberId:")).call(s,t.numberId,",taskId:")).call(r,t.taskId,":查询坐席接听状态异常"),console.error(a),t.stop=!0,ie(this,Rr,"f").call(this,i.message),e.abrupt("return");case 5:if(o=i.data,c=o.callType,l=o.newIntentTag,u=o.intentTag,d=o.number,h=o.numberMd5,g=o.sid,f=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=c),t.intentTag=l||u,t.number||(t.number=d),t.numberMD5||(t.numberMD5=h),t.agentId||(t.agentId=g),t.tag||(t.tag=v),t.templateId||f&&"string"==typeof f&&(p=JSON.parse(f))&&p.templateId&&(t.templateId=p.templateId),!t.callId){e.next=12;break}return b={},e.prev=7,e.next=8,this.getCallNumberChats({callId:t.callId,taskId:t.taskId});case 8:if(200===(b=e.sent).code){e.next=9;break}return console.error(b.message),t.stop=!0,ie(this,Rr,"f").call(this,b.message),e.abrupt("return");case 9:e.next=11;break;case 10:return e.prev=10,e.catch(7),k=E(y="当前会话根据callId:".concat(t.callId,",taskId:")).call(y,t.taskId,":查询会话对话记录异常"),console.error(k),t.stop=!0,ie(this,Rr,"f").call(this,k),e.abrupt("return");case 11:t.chats=w(m=b.data).call(m,function(e){return e.matchinfo&&(e.matchinfo=JSON.parse(e.matchinfo)),e}),ie(this,cr,"f")[t.callId]=t;case 12:try{ie(this,fr,"f").call(this,ie(this,cr,"f")[t.callId])}catch(e){console.log(e)}e.next=14;break;case 13:t.stop=!0,t.taskId||(T="当前会话callid:".concat(t.callId,"的taskId不存在,无法查询通话记录"),console.error(T),ie(this,Rr,"f").call(this,T)),t.numberId||(R="当前会话callid:".concat(t.callId,"的numberId不存在,无法查询通话记录"),console.error(R),ie(this,Rr,"f").call(this,R));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,r();case 4:if(!t.stop){e.next=5;break}return e.abrupt("continue",7);case 5:return e.next=6,new i(function(e){var t=m(function(){return ne(a,void 0,void 0,n.mark(function i(){return n.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()}},i)}))},3e3)});case 6:e.next=2;break;case 7:e.next=9;break;case 8:e.prev=8,s=e.catch(1),ie(this,Rr,"f").call(this,s);case 9:case"end":return e.stop()}},e,this,[[1,8]])}))}},{key:"refreshCallChatInfo",value:function(){return ne(this,void 0,void 0,n.mark(function e(){var t,i=this;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if("string"==typeof(t=ie(this,hs,"f"))?t=t===ie(this,ds,"f").voiceType:y(t)&&(t=!!V(t).call(t,function(e){return e===ie(i,ds,"f").voiceType})),!(ie(this,ds,"f").numberId&&ie(this,ds,"f").callId&&ie(this,ds,"f").taskId&&t)){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)||("//"===g(e).call(e,0,2)?t.test(g(e).call(e,2,e.length)):"http://"===g(e).call(e,0,7)?t.test(g(e).call(e,7,e.length)):"https://"===g(e).call(e,0,8)?t.test(g(e).call(e,8,e.length)):t.test(e))}(ie(this,es,"f"))?ie(this,es,"f"):"1"===ie(this,ns,"f")?"1"===ie(this,ts,"f")?"https://seat.teleai.com/teleaiopenapi":"https://seat.teleai.com/openapi":"1"===ie(this,ts,"f")?"https://seat.94ai.com/teleaiopenapi":"https://seat.94ai.com/openapi"}},{key:"getAgentInfo",value:function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})||{},t=e.agentTag,n=e.agentId,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["agentTag","agentId"]);return this.requestOpenApi({url:"/v1/agent/getAgent",data:$({agentTag:t||ie(this,Yr,"f"),agentId:n||ie(this,Qr,"f")},i)})}},{key:"updateOpenApiAgentStatus",value:function(e){return this.requestOpenApi({url:"/v1/agent/updateAgentStatus",data:{agentTag:ie(this,Yr,"f"),agentId:ie(this,Qr,"f"),agentStatus:e}})}},{key:"importOpenApiAgentCustomer",value:function(e){return this.requestOpenApi({url:"/v1/task/importAgentCustomer",data:{agentTag:ie(this,Yr,"f"),agentId:ie(this,Qr,"f"),callType:1001,customers:[{number:e}]}})}},{key:"callNumber",value:function(e){return this.importOpenApiAgentCustomer(e)}},{key:"toggleNap",value:function(e){return e?this.updateOpenApiAgentStatus(3):this.updateOpenApiAgentStatus(1)}},{key:"refreshSign",value:function(e){re(this,nr,e,"f")}},{key:"refreshTimestamp",value:function(e){re(this,ir,e,"f")}},{key:"prepareUserAgent",value:function(e,t){var i;return ne(this,void 0,void 0,n.mark(function r(){var s,a,o,c,l,u,d,h,g,f,v,p;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return a=(s=e||{}).refresh,o=s.registererOptions,c=s.registererRegisterOptions,l=s.extraHeaders,u=s.authorizationUsername,d=s.authorizationPassword,h=s.uri,g=s.contactName,f=s.transportOptions,n.next=1,this.dispose();case 1:return ie(this,Zi,"f").uri=null!=h?h:ie(this,Zi,"f").uri,ie(this,Zi,"f").authorizationUsername=null!=u?u:ie(this,Zi,"f").authorizationUsername,ie(this,Zi,"f").authorizationPassword=null!=d?d:ie(this,Zi,"f").authorizationPassword,ie(this,Zi,"f").contactName=null!==(i=null!=g?g:u)&&void 0!==i?i:ie(this,Zi,"f").contactName,f&&(ie(this,Zi,"f").transportOptions=$($({},ie(this,Zi,"f").transportOptions),f)),n.prev=2,ie(this,Ui,"m",Cs).call(this,e),n.next=3,ie(this,Ds,"f").call(this);case 3:return n.next=4,ie(this,Hs,"f").call(this);case 4:return ie(this,Ui,"m",qs).call(this,{refresh:a}),n.next=5,ie(this,Ui,"m",la).call(this);case 5:return t&&ie(this,Ui,"m",ca).call(this,t),n.next=6,ie(this,Ui,"m",ua).call(this,{registererOptions:o,registererRegisterOptions:c,extraHeaders:l},ie(this,cs,"f"));case 6:return v=n.sent,n.abrupt("return",v);case 7:return n.prev=7,p=n.catch(2),n.next=8,this.dispose();case 8:throw p;case 9:case"end":return n.stop()}},r,this,[[2,7]])}))}},{key:"dispose",value:function(){return ne(this,void 0,void 0,n.mark(function e(){var t;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,ie(this,Ui,"m",_s).call(this),e.next=1,ie(this,Ui,"m",js).call(this);case 1:e.next=3;break;case 2:e.prev=2,t=e.catch(0),ie(this,Ui,"m",Us).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 ne(this,void 0,void 0,n.mark(function t(){return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return ie(this,er,"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 ne(this,void 0,void 0,n.mark(function t(){var r,s=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=1,new i(function(t,i){ne(s,void 0,void 0,n.mark(function r(){var s,a,o;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,s=null==e?void 0:e.onAck,a=null==e?void 0:e.onAckTimeout,null==e||delete e.onAck,null==e||delete e.onAckTimeout,n.next=1,this.getCurrentInvitation().accept($({sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}},onAck:function(e){t(e),null==s||s()},onAckTimeout:function(){null==a||a(),i("接听响应超时")}},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()}},r,this,[[0,2]])}))});case 1:ie(this,er,"f").incomingStatus&&(ie(this,er,"f").incomingStatus=!1,ie(this,er,"f").answerStatus=!0),t.next=3;break;case 2:throw t.prev=2,r=t.catch(0),ie(this,er,"f").incomingStatus=!1,r;case 3:case"end":return t.stop()}},t,this,[[0,2]])}))}},{key:"hangUpInvite",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){var r,s,a,o,c,l=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return s=(r=e||{}).rejectOptions,a=r.byeOptions,o=r.extraHeaders,c=r.scoutResponse,t.abrupt("return",new i(function(e,t){return ne(l,void 0,void 0,n.mark(function i(){var r,l,u,d,h,g,f,v,p,m,b;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:n.prev=0,f=null===(r=(g=a||{}).requestDelegate)||void 0===r?void 0:r.onAccept,v=null===(l=g.requestDelegate)||void 0===l?void 0:l.onReject,null===(u=g.requestDelegate)||void 0===u||delete u.onAccept,null===(d=g.requestDelegate)||void 0===d||delete d.onReject,p=ie(this,Ui,"m",Ps).call(this,{onAccept:function(t){console.log("sip bye success"),e(t),null==f||f(t)},onReject:function(e){null==v||v(e),t("sip bye fail with code "+e.message.statusCode)}},g.requestDelegate),delete g.requestDelegate,m=null===(h=ie(this,Ji,"f"))||void 0===h?void 0:h.state,n.next=m===ot.Initial||m===ot.Establishing?1:m===ot.Established?3:m===ot.Terminating||m===ot.Terminated?5:6;break;case 1:return n.next=2,ie(this,Ji,"f").reject($({extraHeaders:o},s||{}));case 2:return e(!0),n.abrupt("continue",6);case 3:return n.next=4,ie(this,Ji,"f").bye($({requestDelegate:p,requestOptions:{extraHeaders:o}},g));case 4:return c||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,b=n.catch(0),t(b);case 8:return n.prev=8,ie(this,er,"f").incomingStatus=!1,ie(this,er,"f").answerStatus=!1,n.finish(8);case 9:case"end":return n.stop()}},i,this,[[0,7,8,9]])}))}));case 1:case"end":return t.stop()}},t)}))}},{key:"sendStarDtmf",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return ne(this,void 0,void 0,n.mark(function t(){var r=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new i(function(t,i){return ne(r,void 0,void 0,n.mark(function r(){var s,a,o,c,l;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,a=(s=e||{}).extraHeaders,o=s.requestDelegate,c=ie(this,Ui,"m",Ps).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 s.requestDelegate,n.next=1,this.getCurrentInvitation().info($({requestOptions:{body:{contentDisposition:"render",contentType:"application/dtmf-relay",content:"Signal=*\r\nDuration=100"},extraHeaders:a},requestDelegate:c},s));case 1:ie(this,fs,"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()}},r,this,[[0,2]])}))}));case 1:case"end":return t.stop()}},t)}))}},{key:"muteRemoteAudio",value:function(){var e;h(e=ie(this,Yi,"f").getReceivers()).call(e,function(e){e.track.enabled=!1})}},{key:"unMuteRemoteAudio",value:function(){var e;h(e=ie(this,Yi,"f").getReceivers()).call(e,function(e){e.track.enabled=!0})}},{key:"muteLocalAudio",value:function(){var e;h(e=ie(this,Yi,"f").getSenders()).call(e,function(e){e.track.enabled=!1})}},{key:"unMuteLocalAudio",value:function(){var e;h(e=ie(this,Yi,"f").getSenders()).call(e,function(e){e.track.enabled=!0})}},{key:"getUserAgentStatue",value:function(){return ie(this,er,"f")}},{key:"getUserAgent",value:function(){return ie(this,Gi,"f")||re(this,Gi,new ui(ie(this,Zi,"f")),"f"),ie(this,Gi,"f")}},{key:"getSessionDescriptionHandler",value:function(){return ie(this,Wi,"f")}},{key:"getPeerConnection",value:function(){return ie(this,Yi,"f")}},{key:"getSenders",value:function(){return ie(this,zi,"f")}},{key:"getReceivers",value:function(){return ie(this,Ki,"f")}},{key:"getStream",value:function(){var e,t=this;return ie(this,Qi,"f")||re(this,Qi,new MediaStream,"f"),h(e=ie(this,Ki,"f")).call(e,function(e){e.track&&ie(t,Qi,"f").addTrack(e.track)}),ie(this,Qi,"f")}},{key:"getCurrentInviter",value:function(){if(!ie(this,Xi,"f"))throw new Error("No currentInviter...");return ie(this,Xi,"f")}},{key:"getCurrentInvitation",value:function(){return ie(this,Ji,"f")}},{key:"clearIceAutoDetection",value:function(){var e;null===(e=ie(this,Bi,"f"))||void 0===e||e.destroy(),re(this,Bi,void 0,"f")}},{key:"iceAutoDetectRecovery",value:function(e){var t,n=this;null===(t=ie(this,Bi,"f"))||void 0===t||t.destroy(),re(this,Bi,new ga(e,this,{debugIceCredentials:!0,onRecoveryStart:function(e,t){console.log("开始 ICE 恢复",e,t)},onRecovered:function(){console.log("媒体连接已恢复")},isSignalingAvailable:function(){return ie(n,Gi,"f").isConnected()},isRegistrationAvailable:function(){return ie(n,Vi,"f").state===Rt.Registered},onRecoveryFailed:function(e,t){console.error("ICE 恢复失败",e,t)}}),"f"),ie(this,Bi,"f").start()}},{key:"invite",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return ne(this,void 0,void 0,n.mark(function i(){var r,s,a;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(s=ui.makeURI(e.uri?e.uri:E(r="sip:".concat(e.extension,"@")).call(r,ie(this,Zi,"f").transportOptions.server.split("://")[1]))){n.next=1;break}throw new Error("Failed to create target URI.");case 1:return re(this,Xi,new St(this.getUserAgent(),s,{sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}}}),"f"),a=(t||{}).extraHeaders,n.next=2,this.getCurrentInviter().invite($({requestOptions:{extraHeaders:a}},t));case 2:return n.abrupt("return",ie(this,Xi,"f"));case 3:case"end":return n.stop()}},i,this)}))}}])}();Bi=new z,Li=new z,Gi=new z,Vi=new z,Wi=new z,Yi=new z,Ki=new z,zi=new z,Zi=new z,Ji=new z,Xi=new z,Qi=new z,er=new z,tr=new z,nr=new z,ir=new z,rr=new z,sr=new z,ar=new z,or=new z,cr=new z,lr=new z,ur=new z,dr=new z,hr=new z,gr=new z,fr=new z,vr=new z,pr=new z,mr=new z,br=new z,wr=new z,yr=new z,kr=new z,Tr=new z,Rr=new z,Sr=new z,Ir=new z,Er=new z,Cr=new z,Ar=new z,xr=new z,Dr=new z,Hr=new z,_r=new z,$r=new z,qr=new z,Mr=new z,Pr=new z,Or=new z,Nr=new z,jr=new z,Fr=new z,Ur=new z,Br=new z,Lr=new z,Gr=new z,Vr=new z,Wr=new z,Yr=new z,Kr=new z,zr=new z,Zr=new z,Jr=new z,Xr=new z,Qr=new z,es=new z,ts=new z,ns=new z,is=new z,rs=new z,ss=new z,as=new z,os=new z,cs=new z,ls=new z,us=new z,ds=new z,hs=new z,gs=new z,fs=new z,vs=new z,ps=new z,ms=new z,bs=new z,ws=new z,ys=new z,ks=new z,Ts=new z,Ds=new z,Hs=new z,$s=new z,Ys=new z,zs=new z,Zs=new z,Js=new z,Xs=new z,Qs=new z,sa=new z,Ui=new Z,Rs=function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};re(this,vr,null!==(e=n.openXhrIntercept)&&void 0!==e?e:ie(this,vr,"f"),"f"),re(this,pr,null!==(t=n.gatewayXhrIntercept)&&void 0!==t?t:ie(this,pr,"f"),"f")},Ss=function(){var e,t,i,r,s,a,o=this,c=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};re(this,hs,null!==(e=c.enableChatInfoPush)&&void 0!==e?e:ie(this,hs,"f"),"f"),re(this,gs,null!==(t=c.enableVolumnTrack)&&void 0!==t?t:ie(this,gs,"f"),"f"),re(this,gr,null!==(i=c.refreshSpeekVolumn)&&void 0!==i?i:ie(this,gr,"f"),"f"),re(this,Sr,null!==(r=c.refreshRequirementCheck)&&void 0!==r?r:ie(this,Sr,"f"),"f"),re(this,fr,null!==(s=c.refreshChat)&&void 0!==s?s:ie(this,fr,"f"),"f"),re(this,Rr,null!==(a=c.refreshChatErrorCallback)&&void 0!==a?a:ie(this,Rr,"f"),"f");var l=c.errorCallback;c.errorCallback=function(e){return ne(o,void 0,void 0,n.mark(function t(){return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=1,ie(this,yr,"f").call(this,e);case 1:t.next=3;break;case 2:t.prev=2,t.catch(0);case 3:return t.prev=3,null==l||l(e),t.finish(3);case 4:case"end":return t.stop()}},t,this,[[0,2,3,4]])}))}},Is=function(){var e,t,n,i,s,a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};re(this,rr,null!==(e=a.token)&&void 0!==e?e:ie(this,rr,"f"),"f"),re(this,sr,null!==(t=a.tokenTimestamp)&&void 0!==t?t:ie(this,sr,"f"),"f"),re(this,or,null!==(n=a.tokenExpirationTime)&&void 0!==n?n:ie(this,or,"f"),"f"),ie(this,rr,"f")&&!ie(this,sr,"f")&&re(this,sr,r(),"f"),re(this,br,null!==(i=a.tokenCheck)&&void 0!==i?i:ie(this,br,"f"),"f"),re(this,Tr,null!==(s=a.tokenOverdued)&&void 0!==s?s:ie(this,Tr,"f"),"f")},Es=function(){var e,t,n,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};re(this,cs,null!==(e=i.clusterMode)&&void 0!==e?e:ie(this,cs,"f"),"f"),re(this,ls,null!==(t=i.reClusterRegisterTimeout)&&void 0!==t?t:ie(this,ls,"f"),"f"),re(this,us,null!==(n=i.reClusterConnectTimeout)&&void 0!==n?n:ie(this,us,"f"),"f")},Cs=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,d=i.sign,h=i.armsReport,g=i.timestamp;re(this,Qr,null!=r?r:ie(this,Qr,"f"),"f"),re(this,Yr,null!=s?s:ie(this,Yr,"f"),"f"),re(this,Vr,null!=a?a:ie(this,Vr,"f"),"f"),re(this,Wr,null!=o?o:ie(this,Wr,"f"),"f"),re(this,es,null!=c?c:ie(this,es,"f"),"f"),re(this,lr,null!=h?h:ie(this,lr,"f"),"f"),re(this,ns,null!=l?l:ie(this,ns,"f"),"f"),re(this,ts,null!=u?u:ie(this,ts,"f"),"f"),re(this,nr,null!=d?d:ie(this,nr,"f"),"f"),re(this,ir,null!=g?g:ie(this,ir,"f"),"f"),re(this,ar,null!==(e=i.signExpirationTime)&&void 0!==e?e:ie(this,ar,"f"),"f"),re(this,mr,null!==(t=i.signCheck)&&void 0!==t?t:ie(this,mr,"f"),"f"),re(this,wr,null!==(n=i.signOverdued)&&void 0!==n?n:ie(this,wr,"f"),"f")},As=function(e){e.sipHeaders&&(re(this,Li,e.sipHeaders,"f"),delete e.sipHeaders)},xs=function(){return!(!ie(this,Qr,"f")&&!ie(this,Yr,"f")||!(ie(this,Vr,"f")&&ie(this,Wr,"f")||ie(this,nr,"f")&&ie(this,ir,"f")))},_s=function(){ie(this,Ui,"m",Fs).call(this),ie(this,Ui,"m",Gs).call(this),ie(this,Ui,"m",Vs).call(this),ie(this,Ui,"m",Ls).call(this),ie(this,Ui,"m",Bs).call(this),ie(this,Ui,"m",ea).call(this),ie(this,Ui,"m",ta).call(this),ie(this,Ui,"m",Us).call(this),ie(this,vs,"f").call(this),this.clearIceAutoDetection(),re(this,ds,{},"f"),re(this,cr,{},"f")},qs=function(e){re(this,er,W(JSON.parse(C(ji)),"function"==typeof e.refresh?e.refresh:ie(this,ss,"f")),"f")},Ms=function(e){var t,n,i,r,s,a,o,c,l,u,d,h,g,f,v;re(this,Cr,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:ie(this,Cr,"f"),"f"),re(this,Ar,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:ie(this,Ar,"f"),"f"),re(this,Or,null!==(l=null===(c=e.transportOptions)||void 0===c?void 0:c.keepAliveInterval)&&void 0!==l?l:ie(this,Or,"f"),"f"),re(this,Nr,null!==(d=null===(u=e.transportOptions)||void 0===u?void 0:u.keepAliveDebounce)&&void 0!==d?d:ie(this,Nr,"f"),"f"),re(this,qr,null!==(h=e.registerInterval)&&void 0!==h?h:ie(this,qr,"f"),"f"),re(this,xr,null!==(g=e.optionsPingInterval)&&void 0!==g?g:ie(this,xr,"f"),"f"),re(this,Dr,null!==(f=e.optionsPingAttempts)&&void 0!==f?f:ie(this,Dr,"f"),"f"),re(this,Mr,null!==(v=e.registerAttempts)&&void 0!==v?v:ie(this,Mr,"f"),"f")},Ps=function(e,t){var i,r=this;return t?(h(i=A(t)).call(i,function(i){if(t[i]&&"function"==typeof t[i])if(e[i]){if("function"==typeof e[i]){var s=e[i];e[i]=function(e){return ne(r,void 0,void 0,n.mark(function r(){return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=1,t[i](e);case 1:return n.next=2,s(e);case 2:case"end":return n.stop()}},r)}))}}}else e[i]=t[i]}),e):e},Os=function(e){var t,i=this,r={delegate:{onConnect:function(){return ne(i,void 0,void 0,n.mark(function e(){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:console.log("sip connected"),ie(this,Js,"f").call(this);case 1:case"end":return e.stop()}},e,this)}))},onInvite:function(e){ie(i,$s,"f").call(i,e.incomingInviteRequest.message.headers),i.refreshCallChatInfo(),ie(i,Ui,"m",Ns).call(i),re(i,Ji,e,"f"),ie(i,er,"f").incomingStatus=!0,i.iceAutoDetectRecovery(e),e.stateChange.addListener(ie(i,Ys,"f"))},onDisconnect:function(e){return ne(i,void 0,void 0,n.mark(function t(){var i;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return console.log("sip disconnected"),i=!1,ie(this,xr,"f")>0&&(i=ie(this,_r,"f"),ie(this,Qs,"f").call(this)),t.prev=1,t.next=2,ie(this,Ui,"m",Ks).call(this);case 2:t.next=4;break;case 3:t.prev=3,t.catch(1);case 4:(e||i)&&ie(this,Ui,"m",aa).call(this);case 5:case"end":return t.stop()}},t,this,[[1,3]])}))}}};e.delegate?h(t=A(e.delegate)).call(t,function(t){var s=t;if(e.delegate[s]&&"function"==typeof e.delegate[s]){var a=e.delegate[s];e.delegate[s]=function(e){return ne(i,void 0,void 0,n.mark(function t(){var i,o;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return null===(o=(i=r.delegate)[s])||void 0===o||o.call(i,e),t.next=1,a(e);case 1:case"end":return t.stop()}},t)}))}}}):e.delegate=r.delegate;return e.reconnectionAttempts=0,e.transportOptions=$($({},e.transportOptions||{}),{keepAliveInterval:ie(this,Or,"f"),keepAliveDebounce:ie(this,Nr,"f")}),void 0===e.sessionDescriptionHandlerFactoryOptions&&(e.sessionDescriptionHandlerFactoryOptions={iceGatheringTimeout:2e3,peerConnectionConfiguration:{iceServers:[]}}),$($({},Ni),e)},Ns=function(){ie(this,Ji,"f")&&(ie(this,Ji,"f").dispose(),re(this,Ji,void 0,"f"))},js=function(){return ne(this,void 0,void 0,n.mark(function e(){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!ie(this,Gi,"f")){e.next=2;break}return e.next=1,ie(this,Gi,"f").stop();case 1:re(this,Gi,void 0,"f");case 2:case"end":return e.stop()}},e,this)}))},Fs=function(){var e;ie(this,Qi,"f")&&(h(e=ie(this,Qi,"f").getTracks()).call(e,function(e){e.stop()}),re(this,Qi,void 0,"f"))},Us=function(){var e,t=this;h(e=A(ji)).call(e,function(e){var n=e;ie(t,er,"f")[n]=ji[n]})},Bs=function(){ie(this,Wi,"f")&&(ie(this,Wi,"f").close(),re(this,Wi,void 0,"f"))},Ls=function(){ie(this,Yi,"f")&&(ie(this,Yi,"f").close(),re(this,Yi,void 0,"f"))},Gs=function(){re(this,zi,[],"f")},Vs=function(){re(this,Ki,[],"f")},Ws=function(){var e=this.getCurrentInvitation().sessionDescriptionHandler;ie(this,Ui,"m",Ls).call(this),ie(this,Ui,"m",Bs).call(this),ie(this,Ui,"m",Gs).call(this),ie(this,Ui,"m",Vs).call(this),re(this,Wi,e,"f"),re(this,Yi,e.peerConnection,"f"),re(this,zi,ie(this,Yi,"f").getSenders(),"f"),re(this,Ki,ie(this,Yi,"f").getReceivers(),"f"),(this.getFastOutboundCall()||!this.getSitOutboundCall()&&this.notNeedSendStarDtmf())&&ie(this,fs,"f").call(this)},Ks=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return ne(this,void 0,void 0,n.mark(function t(){var r=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!ie(this,Vi,"f")){t.next=1;break}return console.log("sip due to disconnection, unregistered"),t.abrupt("return",new i(function(t,i){return ne(r,void 0,void 0,n.mark(function r(){var s,a,o;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,s=e||{},a=ie(this,Ui,"m",Ps).call(this,{onAccept:function(e){console.log("sip unregister successed"),t(e)},onReject:function(e){i("sip unregister fail with code "+e.message.statusCode)}},s.requestDelegate),delete e.requestDelegate,n.next=1,ie(this,Vi,"f").unregister($({requestDelegate:a},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()}},r,this,[[0,2]])}))}));case 1:case"end":return t.stop()}},t,this)}))},ea=function(){ie(this,Ui,"m",na).call(this),ie(this,Ui,"m",ia).call(this),ie(this,Ui,"m",ra).call(this),re(this,Ur,!1,"f"),re(this,jr,!1,"f"),re(this,Fr,!1,"f")},ta=function(){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])&&(clearTimeout(ie(this,as,"f")),re(this,as,void 0,"f")),e&&(clearTimeout(ie(this,os,"f")),re(this,os,void 0,"f"))},na=function(){clearTimeout(ie(this,Gr,"f")),re(this,Gr,void 0,"f")},ia=function(){clearTimeout(ie(this,Br,"f")),re(this,Br,void 0,"f")},ra=function(){clearTimeout(ie(this,Lr,"f")),re(this,Lr,void 0,"f")},aa=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return ne(this,void 0,void 0,n.mark(function i(){var r=this;return n.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(!ie(this,Ar,"f")){i.next=4;break}if(ie(this,er,"f").reconnectStatus=!0,!ie(this,jr,"f")){i.next=1;break}return i.abrupt("return");case 1:if(!(t>ie(this,Cr,"f"))){i.next=3;break}return console.log("sip maximum reconnection attempts reached"),i.next=2,this.dispose();case 2:return i.abrupt("return");case 3:console.log("sip reconnection attempt..."),re(this,jr,!0,"f"),re(this,Br,m(function(){ie(r,Ui,"m",ia).call(r),r.getUserAgent().reconnect().then(function(){return ne(r,void 0,void 0,n.mark(function e(){var i;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:console.log(E(i="sip reconnection attempt ".concat(t," of ")).call(i,ie(this,Cr,"f")," - succeeded")),re(this,jr,!1,"f"),ie(this,sa,"f").call(this);case 1:case"end":return e.stop()}},e,this)}))}).catch(function(n){var i;console.error(n),console.log(E(i="sip reconnection attempt ".concat(t," of ")).call(i,ie(r,Cr,"f")," - failed")),re(r,jr,!1,"f"),ie(r,Ui,"m",e).call(r,++t)})},1===t?0:1e3*ie(this,Ar,"f")),"f");case 4:case"end":return i.stop()}},i,this)}))},oa=function(e){var t,i=this;return h(t=A(e)).call(t,function(t){var r=t;if("function"==typeof(null==e?void 0:e[r])){var s=e[r];e[r]=function(e){return ne(i,void 0,void 0,n.mark(function t(){var i,a;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return null===(a=(i=ie(this,Zi,"f").delegate)[r])||void 0===a||a.call(i,e),t.next=1,s(e);case 1:case"end":return t.stop()}},t,this)}))}}}),e},ca=function(e){var t=this.getUserAgent();return t.delegate=ie(this,Ui,"m",oa).call(this,e),t},la=function(){return ne(this,void 0,void 0,n.mark(function e(){var t;return n.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 ie(this,er,"f").connectStatus=!0,e.abrupt("return",t);case 4:case"end":return e.stop()}},e,this)}))},ua=function e(t){var r=this,s=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=t||{},o=a.registererOptions,c=a.registererRegisterOptions,l=a.extraHeaders;return new i(function(t,i){return ne(r,void 0,void 0,n.mark(function r(){var a,u,d,h,g,f=this;return n.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return a=this.getUserAgent(),re(this,Vi,new Dt(a,$({extraHeaders:l||ie(this,Li,"f")},o||{})),"f"),d=c||{},h=ie(this,Ui,"m",Ps).call(this,{onAccept:function(e){u=e,ie(f,Ui,"m",ta).call(f),ie(f,er,"f").registerStatus=!0,t(a)},onReject:function(e){ie(f,Ui,"m",ta).call(f),i("sip register fail with code "+e.message.statusCode)}},d.requestDelegate),delete d.requestDelegate,s&&re(this,as,m(function(){return ne(f,void 0,void 0,n.mark(function r(){var s,g=this;return n.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(u){r.next=4;break}re(this,os,m(function(){return ne(g,void 0,void 0,n.mark(function r(){var s,a;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(ie(this,Ui,"m",ta).call(this,!1,!0),u){n.next=6;break}n.prev=1;try{ie(this,Vi,"f").dispose()}catch(e){}return ie(this,Ui,"m",_s).call(this),ie(this,Qs,"f").call(this),re(this,Hr,0,"f"),re(this,Pr,0,"f"),n.next=2,ie(this,Gi,"f").transport.dispose();case 2:return re(this,Gi,new ui(ie(this,Zi,"f")),"f"),n.next=3,ie(this,Ui,"m",la).call(this);case 3:return n.next=4,ie(this,Ui,"m",e).call(this,{registererOptions:o,registererRegisterOptions:c,extraHeaders:l});case 4:s=n.sent,t(s),n.next=6;break;case 5:n.prev=5,a=n.catch(1),i(a);case 6:case"end":return n.stop()}},r,this,[[1,5]])}))},ie(this,us,"f")),"f");try{ie(this,Vi,"f").dispose()}catch(e){}return re(this,Vi,new Dt(a,$({extraHeaders:l||ie(this,Li,"f")},o||{})),"f"),ie(this,Ui,"m",ta).call(this,!0,!1),r.prev=1,r.next=2,ie(this,Vi,"f").register($({requestDelegate:h,requestOptions:{extraHeaders:l||ie(this,Li,"f")}},d));case 2:r.next=4;break;case 3:r.prev=3,s=r.catch(1),ie(this,Ui,"m",ta).call(this),i(s);case 4:case"end":return r.stop()}},r,this,[[1,3]])}))},ie(this,ls,"f")),"f"),r.prev=1,r.next=2,ie(this,Vi,"f").register($({requestDelegate:h,requestOptions:{extraHeaders:l||ie(this,Li,"f")}},d));case 2:r.next=4;break;case 3:r.prev=3,g=r.catch(1),ie(this,Ui,"m",ta).call(this),i(g);case 4:case"end":return r.stop()}},r,this,[[1,3]])}))})};var pa=function(){return t(function t(){e(this,t)},null,[{key:"getToken",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return ne(this,void 0,void 0,n.mark(function t(){var s,a,o,c,l,u,d,h,g,f=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(a=(s=e||{}).appKey,o=s.appSecret,c=s.agentId,l=s.agentTag,u=s.teleai,(d=c)||!l||!o||!a){t.next=3;break}return t.next=1,new i(function(e,t){try{var n=r(),i=J.enc.Base64.stringify(J.HmacSHA1(a+n,o)),s=Ei(e,t,{url:(u?"https://seat.teleai.com/teleaiopenapi":"https://seat.94ai.com/openapi")+"/v1/agent/getAgent",data:{agentTag:l,agentId:c}}),d=s.xhr,h=s.ajaxData,g=s.contentType;d.setRequestHeader("appKey",a),d.setRequestHeader("timestamp",String(n)),d.setRequestHeader("sign",i),d.setRequestHeader("Content-type",g||"application/json"),d.send(h)}catch(e){t(e.message)}});case 1:if(200!=(h=t.sent).code){t.next=2;break}d=h.data.agentId,t.next=3;break;case 2:throw new Error(h.message);case 3:return t.next=4,new i(function(e,t){return ne(f,void 0,void 0,n.mark(function i(){var r,s,c,l;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:try{r=Ei(e,t,{url:(u?"https://gateway.teleai.com":"https://gateway.94ai.com")+"/authority/accessToken/openApi",data:{corpId:a,secret:o,sid:d,seatOnline:!1}}),s=r.xhr,c=r.ajaxData,l=r.contentType,s.setRequestHeader("x-app-code",3),s.setRequestHeader("content-type",l||"application/json"),s.send(c)}catch(e){t(e.message)}case 1:case"end":return n.stop()}},i)}))});case 4:return g=t.sent,t.abrupt("return",g.token);case 5:case"end":return t.stop()}},t)}))}},{key:"getUserAgentManager",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return ie(this,da,"f",ha)||re(this,da,new va(e),"f",ha),ie(this,da,"f",ha)}},{key:"hasUserAgentManager",value:function(){return!!ie(this,da,"f",ha)}},{key:"newUserAgentManager",value:function(){return new va(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})}},{key:"dispose",value:function(){if(ie(this,da,"f",ha))try{ie(this,da,"f",ha).dispose()}catch(e){}finally{re(this,da,void 0,"f",ha)}}}])}();da=pa,ha={value:void 0};export{Hi as AfterTransferLabour,Fi as AliArms,fa as CallbackAggregator,St as Inviter,xi as PopWindow,Dt as Registerer,ot as SessionState,hi as SimpleUser,Ee as URI,ui as UserAgent,pa as UserAgentFactory,va as UserAgentManager,Di as VoiceType,Si as accumulateSec,Ii as accumulationTimer,wi as cleanupMedia,Ci as getBeijingTime,vi as getDevicePermission,gi as getMedia,Ti as getTimes,Ri as getZeorTime,bi as pauseMedia,mi as playMedia,pi as requestMicroPhonePermission,fi as stopStreamTracks,Ni as userAgentDefault,ji as userAgentStatus};
|
|
1
|
+
import e from"@babel/runtime-corejs3/helpers/esm/classCallCheck";import t from"@babel/runtime-corejs3/helpers/esm/createClass";import n from"@babel/runtime-corejs3/regenerator";import i from"@babel/runtime-corejs3/core-js/promise";import r from"@babel/runtime-corejs3/core-js/date/now";import s from"@babel/runtime-corejs3/core-js/reflect/construct";import a from"@babel/runtime-corejs3/helpers/esm/possibleConstructorReturn";import o from"@babel/runtime-corejs3/helpers/esm/getPrototypeOf";import c from"@babel/runtime-corejs3/helpers/esm/inherits";import l from"@babel/runtime-corejs3/helpers/esm/wrapNativeSuper";import u from"@babel/runtime-corejs3/core-js/object/set-prototype-of";import d from"@babel/runtime-corejs3/core-js/object/define-property";import h from"@babel/runtime-corejs3/core-js/instance/for-each";import g from"@babel/runtime-corejs3/core-js/instance/slice";import f from"@babel/runtime-corejs3/core-js/instance/filter";import v from"@babel/runtime-corejs3/helpers/esm/get";import p from"@babel/runtime-corejs3/core-js/instance/includes";import m from"@babel/runtime-corejs3/core-js/set-timeout";import b from"@babel/runtime-corejs3/core-js/instance/repeat";import y from"@babel/runtime-corejs3/core-js/instance/map";import w from"@babel/runtime-corejs3/core-js/array/is-array";import k from"@babel/runtime-corejs3/core-js/instance/sort";import T from"@babel/runtime-corejs3/core-js/parse-int";import R from"@babel/runtime-corejs3/core-js/instance/trim";import S from"@babel/runtime-corejs3/core-js/parse-float";import I from"@babel/runtime-corejs3/core-js/instance/splice";import E from"@babel/runtime-corejs3/core-js/instance/concat";import C from"@babel/runtime-corejs3/core-js/json/stringify";import A from"@babel/runtime-corejs3/core-js/object/keys";import x from"@babel/runtime-corejs3/core-js/instance/every";import D from"@babel/runtime-corejs3/core-js/array/from";import H from"@babel/runtime-corejs3/core-js/symbol";import _ from"@babel/runtime-corejs3/core-js/get-iterator-method";import $ from"@babel/runtime-corejs3/core-js/object/assign";import q from"@babel/runtime-corejs3/core-js/instance/index-of";import M from"@babel/runtime-corejs3/core-js/map";import P from"@babel/runtime-corejs3/core-js/number/parse-int";import O from"@babel/runtime-corejs3/core-js/instance/reduce";import N from"@babel/runtime-corejs3/helpers/esm/toConsumableArray";import j from"@babel/runtime-corejs3/core-js/instance/keys";import F from"@babel/runtime-corejs3/core-js/set";import U from"@babel/runtime-corejs3/core-js/instance/some";import B from"@babel/runtime-corejs3/core-js/instance/values";import L from"@babel/runtime-corejs3/core-js/set-interval";import G from"@babel/runtime-corejs3/core-js/instance/reverse";import"@babel/runtime-corejs3/helpers/esm/readOnlyError";import V from"@babel/runtime-corejs3/core-js/instance/find";import"@babel/runtime-corejs3/helpers/esm/slicedToArray";import W from"on-change";export{default as onChange}from"on-change";import K from"@babel/runtime-corejs3/core-js/instance/pad-start";import Y from"@babel/runtime-corejs3/helpers/esm/typeof";import z from"@babel/runtime-corejs3/core-js/weak-map";import Z from"@babel/runtime-corejs3/core-js/weak-set";import J from"crypto-js";import X from"@fingerprintjs/fingerprintjs";import Q from"@babel/runtime-corejs3/core-js/instance/starts-with";import ee from"@babel/runtime-corejs3/core-js/instance/find-index";import{AliArmsManager as te}from"@94ai/arms";function ne(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 ie(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 re(e,t,n,i,r){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?r.call(e,n):r?r.value=n:t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;function se(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(se=function(){return!!e})()}var ae=function(n){function i(t){var n,r,c,l;return e(this,i),r=this,l=[t],c=o(c=i),n=a(r,se()?s(c,l||[],o(r).constructor):c.apply(r,l)),u(n,(this instanceof i?this.constructor:void 0).prototype),n}return c(i,n),t(i)}(l(Error));function oe(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(oe=function(){return!!e})()}var ce=function(){function n(t){return e(this,n),i=this,c=[t||"Unsupported content type."],r=o(r=n),a(i,oe()?s(r,c||[],o(i).constructor):r.apply(i,c));var i,r,c}return c(n,ae),t(n)}();function le(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(le=function(){return!!e})()}var ue=function(){function n(t){return e(this,n),i=this,c=[t||"Request pending."],r=o(r=n),a(i,le()?s(r,c||[],o(i).constructor):r.apply(i,c));var i,r,c}return c(n,ae),t(n)}();function de(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(de=function(){return!!e})()}var he=function(){function n(t){return e(this,n),i=this,c=[t||"Unspecified session description handler error."],r=o(r=n),a(i,de()?s(r,c||[],o(i).constructor):r.apply(i,c));var i,r,c}return c(n,ae),t(n)}();function ge(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(ge=function(){return!!e})()}var fe=function(){function n(){return e(this,n),t=this,r=["The session has terminated."],i=o(i=n),a(t,ge()?s(i,r||[],o(t).constructor):i.apply(t,r));var t,i,r}return c(n,ae),t(n)}();function ve(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(ve=function(){return!!e})()}var pe=function(){function n(t){return e(this,n),i=this,c=[t||"An error occurred during state transition."],r=o(r=n),a(i,ve()?s(r,c||[],o(i).constructor):r.apply(i,c));var i,r,c}return c(n,ae),t(n)}(),me=function(){return t(function t(n){e(this,t),d(this,"incomingAckRequest",{enumerable:!0,configurable:!0,writable:!0,value:n})},[{key:"request",get:function(){return this.incomingAckRequest.message}}])}(),be=function(){return t(function t(n){e(this,t),d(this,"incomingByeRequest",{enumerable:!0,configurable:!0,writable:!0,value:n})},[{key:"request",get:function(){return this.incomingByeRequest.message}},{key:"accept",value:function(e){return this.incomingByeRequest.accept(e),i.resolve()}},{key:"reject",value:function(e){return this.incomingByeRequest.reject(e),i.resolve()}}])}(),ye=function(){return t(function t(n){e(this,t),d(this,"incomingCancelRequest",{enumerable:!0,configurable:!0,writable:!0,value:n})},[{key:"request",get:function(){return this.incomingCancelRequest}}])}(),we=function(){return t(function t(){e(this,t),d(this,"listeners",{enumerable:!0,configurable:!0,writable:!0,value:new Array})},[{key:"addListener",value:function(e,t){var n=this,i=function(t){n.removeListener(i),e(t)};!0===(null==t?void 0:t.once)?this.listeners.push(i):this.listeners.push(e)}},{key:"emit",value:function(e){var t,n;h(t=g(n=this.listeners).call(n)).call(t,function(t){return t(e)})}},{key:"removeAllListeners",value:function(){this.listeners=[]}},{key:"removeListener",value:function(e){var t;this.listeners=f(t=this.listeners).call(t,function(t){return t!==e})}},{key:"on",value:function(e){return this.addListener(e)}},{key:"off",value:function(e){return this.removeListener(e)}},{key:"once",value:function(e){return this.addListener(e,{once:!0})}}])}(),ke=function(){return t(function t(n){e(this,t),d(this,"incomingInfoRequest",{enumerable:!0,configurable:!0,writable:!0,value:n})},[{key:"request",get:function(){return this.incomingInfoRequest.message}},{key:"accept",value:function(e){return this.incomingInfoRequest.accept(e),i.resolve()}},{key:"reject",value:function(e){return this.incomingInfoRequest.reject(e),i.resolve()}}])}(),Te=function(){return t(function t(n){for(var i in e(this,t),d(this,"parameters",{enumerable:!0,configurable:!0,writable:!0,value:{}}),n)n.hasOwnProperty(i)&&this.setParam(i,n[i])},[{key:"setParam",value:function(e,t){e&&(this.parameters[e.toLowerCase()]=null==t?null:t.toString())}},{key:"getParam",value:function(e){if(e)return this.parameters[e.toLowerCase()]}},{key:"hasParam",value:function(e){return!(!e||void 0===this.parameters[e.toLowerCase()])}},{key:"deleteParam",value:function(e){if(e=e.toLowerCase(),this.hasParam(e)){var t=this.parameters[e];return delete this.parameters[e],t}}},{key:"clearParams",value:function(){this.parameters={}}}])}();function Re(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Re=function(){return!!e})()}var Se=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,h=[r],u=o(u=n),c=a(l,Re()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"uri",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"_displayName",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c.uri=t,c._displayName=i,c}return c(n,Te),t(n,[{key:"friendlyName",get:function(){return this.displayName||this.uri.aor}},{key:"displayName",get:function(){return this._displayName},set:function(e){this._displayName=e}},{key:"clone",value:function(){return new n(this.uri.clone(),this._displayName,JSON.parse(C(this.parameters)))}},{key:"toString",value:function(){var e=this.displayName||"0"===this.displayName?'"'+this.displayName+'" ':"";for(var t in e+="<"+this.uri.toString()+">",this.parameters)this.parameters.hasOwnProperty(t)&&(e+=";"+t,null!==this.parameters[t]&&(e+="="+this.parameters[t]));return e}}])}();function Ie(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Ie=function(){return!!e})()}var Ee=function(){function n(){var t,i,r,c,l=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"sip",u=arguments.length>1?arguments[1]:void 0,h=arguments.length>2?arguments[2]:void 0,g=arguments.length>3?arguments[3]:void 0,f=arguments.length>4?arguments[4]:void 0,v=arguments.length>5?arguments[5]:void 0;if(e(this,n),i=this,c=[f||{}],r=o(r=n),t=a(i,Ie()?s(r,c||[],o(i).constructor):r.apply(i,c)),d(t,"headers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),d(t,"normal",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(t,"raw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),!h)throw new TypeError('missing or invalid "host" parameter');for(var p in v)v.hasOwnProperty(p)&&t.setHeader(p,v[p]);return t.raw={scheme:l,user:u,host:h,port:g},t.normal={scheme:l.toLowerCase(),user:u,host:h.toLowerCase(),port:g},t}return c(n,Te),t(n,[{key:"scheme",get:function(){return this.normal.scheme},set:function(e){this.raw.scheme=e,this.normal.scheme=e.toLowerCase()}},{key:"user",get:function(){return this.normal.user},set:function(e){this.normal.user=this.raw.user=e}},{key:"host",get:function(){return this.normal.host},set:function(e){this.raw.host=e,this.normal.host=e.toLowerCase()}},{key:"aor",get:function(){return this.normal.user+"@"+this.normal.host}},{key:"port",get:function(){return this.normal.port},set:function(e){this.normal.port=this.raw.port=e}},{key:"setHeader",value:function(e,t){this.headers[this.headerize(e)]=t instanceof Array?t:[t]}},{key:"getHeader",value:function(e){if(e)return this.headers[this.headerize(e)]}},{key:"hasHeader",value:function(e){return!!e&&!!this.headers.hasOwnProperty(this.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=this.headerize(e),this.headers.hasOwnProperty(e)){var t=this.headers[e];return delete this.headers[e],t}}},{key:"clearHeaders",value:function(){this.headers={}}},{key:"clone",value:function(){return new n(this._raw.scheme,this._raw.user||"",this._raw.host,this._raw.port,JSON.parse(C(this.parameters)),JSON.parse(C(this.headers)))}},{key:"toRaw",value:function(){return this._toString(this._raw)}},{key:"toString",value:function(){return this._toString(this._normal)}},{key:"_normal",get:function(){return this.normal}},{key:"_raw",get:function(){return this.raw}},{key:"_toString",value:function(e){var t=e.scheme+":";for(var n in e.scheme.toLowerCase().match("^sips?$")||(t+="//"),e.user&&(t+=this.escapeUser(e.user)+"@"),t+=e.host,(e.port||0===e.port)&&(t+=":"+e.port),this.parameters)this.parameters.hasOwnProperty(n)&&(t+=";"+n,null!==this.parameters[n]&&(t+="="+this.parameters[n]));var i=[];for(var r in this.headers)if(this.headers.hasOwnProperty(r))for(var s in this.headers[r])this.headers[r].hasOwnProperty(s)&&i.push(r+"="+this.headers[r][s]);return i.length>0&&(t+="?"+i.join("&")),t}},{key:"escapeUser",value:function(e){var t;try{t=decodeURIComponent(e)}catch(e){throw e}return encodeURIComponent(t).replace(/%3A/gi,":").replace(/%2B/gi,"+").replace(/%3F/gi,"?").replace(/%2F/gi,"/")}},{key:"headerize",value:function(e){for(var t={"Call-Id":"Call-ID",Cseq:"CSeq","Min-Se":"Min-SE",Rack:"RAck",Rseq:"RSeq","Www-Authenticate":"WWW-Authenticate"},n=e.toLowerCase().replace(/_/g,"-").split("-"),i=n.length,r="",s=0;s<i;s++)0!==s&&(r+="-"),r+=n[s].charAt(0).toUpperCase()+n[s].substring(1);return t[r]&&(r=t[r]),r}}])}();function Ce(e,t){if(e.scheme!==t.scheme)return!1;if(e.user!==t.user||e.host!==t.host||e.port!==t.port)return!1;if(!function(e,t){var n,i,r=A(e.parameters),s=A(t.parameters),a=f(r).call(r,function(e){return p(s).call(s,e)});return!!x(a).call(a,function(n){return e.parameters[n]===t.parameters[n]})&&(!!x(n=["user","ttl","method","transport"]).call(n,function(n){return e.hasParam(n)&&t.hasParam(n)||!e.hasParam(n)&&!t.hasParam(n)})&&!!x(i=["maddr"]).call(i,function(n){return e.hasParam(n)&&t.hasParam(n)||!e.hasParam(n)&&!t.hasParam(n)}))}(e,t))return!1;var n=A(e.headers),i=A(t.headers);if(0!==n.length||0!==i.length){if(n.length!==i.length)return!1;var r=f(n).call(n,function(e){return p(i).call(i,e)});if(r.length!==i.length)return!1;if(!x(r).call(r,function(n){return e.headers[n].length&&t.headers[n].length&&e.headers[n][0]===t.headers[n][0]}))return!1}return!0}function Ae(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Ae=function(){return!!e})()}function xe(e,t,n){return n=n||" ",e.length>t?e:(t-=e.length,n+=b(n).call(n,t),e+g(n).call(n,0,t))}var De=function(n){function i(t,n,r,c){var l,h,g,f;return e(this,i),h=this,g=o(g=i),l=a(h,Ae()?s(g,f||[],o(h).constructor):g.apply(h,f)),d(l,"message",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"expected",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"found",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"location",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"name",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),l.message=t,l.expected=n,l.found=r,l.location=c,l.name="SyntaxError","function"==typeof u?u(l,i.prototype):l.__proto__=i.prototype,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(l,i),l}return c(i,n),t(i,[{key:"format",value:function(e){var t="Error: "+this.message;if(this.location){var n,i=null;for(n=0;n<e.length;n++)if(e[n].source===this.location.source){i=e[n].text.split(/\r\n|\n|\r/g);break}var r=this.location.start,s=this.location.source+":"+r.line+":"+r.column;if(i){var a=this.location.end,o=xe("",r.line.toString().length," "),c=i[r.line-1],l=r.line===a.line?a.column:c.length+1;t+="\n --\x3e "+s+"\n"+o+" |\n"+r.line+" | "+c+"\n"+o+" | "+xe("",r.column-1," ")+xe("",l-r.column,"^")}else t+="\n at "+s}return t}}],[{key:"buildMessage",value:function(e,t){function n(e){return e.charCodeAt(0).toString(16).toUpperCase()}function i(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+n(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+n(e)})}function r(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+n(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+n(e)})}function s(e){var t;switch(e.type){case"literal":return'"'+i(e.text)+'"';case"class":var n=y(t=e.parts).call(t,function(e){return w(e)?r(e[0])+"-"+r(e[1]):r(e)});return"["+(e.inverted?"^":"")+n+"]";case"any":return"any character";case"end":return"end of input";case"other":return e.description}}return"Expected "+function(e){var t,n,i=y(e).call(e,s);if(k(i).call(i),i.length>0){for(t=1,n=1;t<i.length;t++)i[t-1]!==i[t]&&(i[n]=i[t],n++);i.length=n}switch(i.length){case 1:return i[0];case 2:return i[0]+" or "+i[1];default:return g(i).call(i,0,-1).join(", ")+", or "+i[i.length-1]}}(e)+" but "+(((a=t)?'"'+i(a)+'"':"end of input")+" found.");var a}}])}(l(Error));var He,_e=function(e,t){var n,i,r,s,a={},o=(t=void 0!==t?t:{}).grammarSource,c={Contact:119,Name_Addr_Header:156,Record_Route:176,Request_Response:81,SIP_URI:45,Subscription_State:186,Supported:191,Require:182,Via:194,absoluteURI:84,Call_ID:118,Content_Disposition:130,Content_Length:135,Content_Type:136,CSeq:146,displayName:122,Event:149,From:151,host:52,Max_Forwards:154,Min_SE:213,Proxy_Authenticate:157,quoted_string:40,Refer_To:178,Replaces:179,Session_Expires:210,stun_URI:217,To:192,turn_URI:223,uuid:226,WWW_Authenticate:209,challenge:158,sipfrag:230,Referred_By:231},l=119,u=["\r\n",C("\r\n",!1),/^[0-9]/,A([["0","9"]],!1,!1),/^[a-zA-Z]/,A([["a","z"],["A","Z"]],!1,!1),/^[0-9a-fA-F]/,A([["0","9"],["a","f"],["A","F"]],!1,!1),/^[\0-\xFF]/,A([["\0","ÿ"]],!1,!1),/^["]/,A(['"'],!1,!1)," ",C(" ",!1),"\t",C("\t",!1),/^[a-zA-Z0-9]/,A([["a","z"],["A","Z"],["0","9"]],!1,!1),";",C(";",!1),"/",C("/",!1),"?",C("?",!1),":",C(":",!1),"@",C("@",!1),"&",C("&",!1),"=",C("=",!1),"+",C("+",!1),"$",C("$",!1),",",C(",",!1),"-",C("-",!1),"_",C("_",!1),".",C(".",!1),"!",C("!",!1),"~",C("~",!1),"*",C("*",!1),"'",C("'",!1),"(",C("(",!1),")",C(")",!1),"%",C("%",!1),function(){return" "},function(){return":"},/^[!-~]/,A([["!","~"]],!1,!1),/^[\x80-\uFFFF]/,A([["",""]],!1,!1),/^[\x80-\xBF]/,A([["","¿"]],!1,!1),/^[a-f]/,A([["a","f"]],!1,!1),"`",C("`",!1),"<",C("<",!1),">",C(">",!1),"\\",C("\\",!1),"[",C("[",!1),"]",C("]",!1),"{",C("{",!1),"}",C("}",!1),function(){return"*"},function(){return"/"},function(){return"="},function(){return"("},function(){return")"},function(){return">"},function(){return"<"},function(){return","},function(){return";"},function(){return":"},function(){return'"'},/^[!-']/,A([["!","'"]],!1,!1),/^[*-[]/,A([["*","["]],!1,!1),/^[\]-~]/,A([["]","~"]],!1,!1),function(e){return e},/^[#-[]/,A([["#","["]],!1,!1),/^[\0-\t]/,A([["\0","\t"]],!1,!1),/^[\v-\f]/,A([["\v","\f"]],!1,!1),/^[\x0E-\x7F]/,A([["",""]],!1,!1),function(){(t=t||{data:{}}).data.uri=new Ee(t.data.scheme,t.data.user,t.data.host,t.data.port),delete t.data.scheme,delete t.data.user,delete t.data.host,delete t.data.host_type,delete t.data.port},function(){(t=t||{data:{}}).data.uri=new Ee(t.data.scheme,t.data.user,t.data.host,t.data.port,t.data.uri_params,t.data.uri_headers),delete t.data.scheme,delete t.data.user,delete t.data.host,delete t.data.host_type,delete t.data.port,delete t.data.uri_params,"SIP_URI"===t.startRule&&(t.data=t.data.uri)},"sips",C("sips",!0),"sip",C("sip",!0),function(e){(t=t||{data:{}}).data.scheme=e},function(){var e;(t=t||{data:{}}).data.user=decodeURIComponent(g(e=w()).call(e,0,-1))},function(){(t=t||{data:{}}).data.password=w()},function(){return(t=t||{data:{}}).data.host=w(),t.data.host},function(){return(t=t||{data:{}}).data.host_type="domain",w()},/^[a-zA-Z0-9_\-]/,A([["a","z"],["A","Z"],["0","9"],"_","-"],!1,!1),/^[a-zA-Z0-9\-]/,A([["a","z"],["A","Z"],["0","9"],"-"],!1,!1),function(){return(t=t||{data:{}}).data.host_type="IPv6",w()},"::",C("::",!1),function(){return(t=t||{data:{}}).data.host_type="IPv6",w()},function(){return(t=t||{data:{}}).data.host_type="IPv4",w()},"25",C("25",!1),/^[0-5]/,A([["0","5"]],!1,!1),"2",C("2",!1),/^[0-4]/,A([["0","4"]],!1,!1),"1",C("1",!1),/^[1-9]/,A([["1","9"]],!1,!1),function(e){return t=t||{data:{}},e=T(e.join("")),t.data.port=e,e},"transport=",C("transport=",!0),"udp",C("udp",!0),"tcp",C("tcp",!0),"sctp",C("sctp",!0),"tls",C("tls",!0),function(e){(t=t||{data:{}}).data.uri_params||(t.data.uri_params={}),t.data.uri_params.transport=e.toLowerCase()},"user=",C("user=",!0),"phone",C("phone",!0),"ip",C("ip",!0),function(e){(t=t||{data:{}}).data.uri_params||(t.data.uri_params={}),t.data.uri_params.user=e.toLowerCase()},"method=",C("method=",!0),function(e){(t=t||{data:{}}).data.uri_params||(t.data.uri_params={}),t.data.uri_params.method=e},"ttl=",C("ttl=",!0),function(e){(t=t||{data:{}}).data.params||(t.data.params={}),t.data.params.ttl=e},"maddr=",C("maddr=",!0),function(e){(t=t||{data:{}}).data.uri_params||(t.data.uri_params={}),t.data.uri_params.maddr=e},"lr",C("lr",!0),function(){(t=t||{data:{}}).data.uri_params||(t.data.uri_params={}),t.data.uri_params.lr=void 0},function(e,n){(t=t||{data:{}}).data.uri_params||(t.data.uri_params={}),n=null===n?void 0:n[1],t.data.uri_params[e.toLowerCase()]=n},function(e,n){e=e.join("").toLowerCase(),n=n.join(""),(t=t||{data:{}}).data.uri_headers||(t.data.uri_headers={}),t.data.uri_headers[e]?t.data.uri_headers[e].push(n):t.data.uri_headers[e]=[n]},function(){"Refer_To"===(t=t||{data:{}}).startRule&&(t.data.uri=new Ee(t.data.scheme,t.data.user,t.data.host,t.data.port,t.data.uri_params,t.data.uri_headers),delete t.data.scheme,delete t.data.user,delete t.data.host,delete t.data.host_type,delete t.data.port,delete t.data.uri_params)},"//",C("//",!1),function(){(t=t||{data:{}}).data.scheme=w()},C("SIP",!0),function(){(t=t||{data:{}}).data.sip_version=w()},"INVITE",C("INVITE",!1),"ACK",C("ACK",!1),"VXACH",C("VXACH",!1),"OPTIONS",C("OPTIONS",!1),"BYE",C("BYE",!1),"CANCEL",C("CANCEL",!1),"REGISTER",C("REGISTER",!1),"SUBSCRIBE",C("SUBSCRIBE",!1),"NOTIFY",C("NOTIFY",!1),"REFER",C("REFER",!1),"PUBLISH",C("PUBLISH",!1),function(){return(t=t||{data:{}}).data.method=w(),t.data.method},function(e){(t=t||{data:{}}).data.status_code=T(e.join(""))},function(){(t=t||{data:{}}).data.reason_phrase=w()},function(){(t=t||{data:{}}).data=w()},function(){var e,n;for(n=(t=t||{data:{}}).data.multi_header.length,e=0;e<n;e++)if(null===t.data.multi_header[e].parsed){t.data=null;break}null!==t.data?t.data=t.data.multi_header:t.data=-1},function(){var e;(t=t||{data:{}}).data.multi_header||(t.data.multi_header=[]);try{e=new Se(t.data.uri,t.data.displayName,t.data.params),delete t.data.uri,delete t.data.displayName,delete t.data.params}catch(t){e=null}t.data.multi_header.push({position:h,offset:k().start.offset,parsed:e})},function(e){var n;'"'===(e=R(n=w()).call(n))[0]&&(e=e.substring(1,e.length-1)),(t=t||{data:{}}).data.displayName=e},"q",C("q",!0),function(e){(t=t||{data:{}}).data.params||(t.data.params={}),t.data.params.q=e},"expires",C("expires",!0),function(e){(t=t||{data:{}}).data.params||(t.data.params={}),t.data.params.expires=e},function(e){return T(e.join(""))},"0",C("0",!1),function(){return S(w())},function(e,n){(t=t||{data:{}}).data.params||(t.data.params={}),n=null===n?void 0:n[1],t.data.params[e.toLowerCase()]=n},"render",C("render",!0),"session",C("session",!0),"icon",C("icon",!0),"alert",C("alert",!0),function(){"Content_Disposition"===(t=t||{data:{}}).startRule&&(t.data.type=w().toLowerCase())},"handling",C("handling",!0),"optional",C("optional",!0),"required",C("required",!0),function(e){(t=t||{data:{}}).data=T(e.join(""))},function(){(t=t||{data:{}}).data=w()},"text",C("text",!0),"image",C("image",!0),"audio",C("audio",!0),"video",C("video",!0),"application",C("application",!0),"message",C("message",!0),"multipart",C("multipart",!0),"x-",C("x-",!0),function(e){(t=t||{data:{}}).data.value=T(e.join(""))},function(e){(t=t||{data:{}}).data=e},function(e){(t=t||{data:{}}).data.event=e.toLowerCase()},function(){var e=(t=t||{data:{}}).data.tag;t.data=new Se(t.data.uri,t.data.displayName,t.data.params),e&&t.data.setParam("tag",e)},"tag",C("tag",!0),function(e){(t=t||{data:{}}).data.tag=e},function(e){(t=t||{data:{}}).data=T(e.join(""))},function(e){(t=t||{data:{}}).data=e},function(){(t=t||{data:{}}).data=new Se(t.data.uri,t.data.displayName,t.data.params)},"digest",C("Digest",!0),"realm",C("realm",!0),function(e){(t=t||{data:{}}).data.realm=e},"domain",C("domain",!0),"nonce",C("nonce",!0),function(e){(t=t||{data:{}}).data.nonce=e},"opaque",C("opaque",!0),function(e){(t=t||{data:{}}).data.opaque=e},"stale",C("stale",!0),"true",C("true",!0),function(){(t=t||{data:{}}).data.stale=!0},"false",C("false",!0),function(){(t=t||{data:{}}).data.stale=!1},"algorithm",C("algorithm",!0),"md5",C("MD5",!0),"md5-sess",C("MD5-sess",!0),function(e){(t=t||{data:{}}).data.algorithm=e.toUpperCase()},"qop",C("qop",!0),"auth-int",C("auth-int",!0),"auth",C("auth",!0),function(e){(t=t||{data:{}}).data.qop||(t.data.qop=[]),t.data.qop.push(e.toLowerCase())},function(e){(t=t||{data:{}}).data.value=T(e.join(""))},function(){var e,n;for(n=(t=t||{data:{}}).data.multi_header.length,e=0;e<n;e++)if(null===t.data.multi_header[e].parsed){t.data=null;break}null!==t.data?t.data=t.data.multi_header:t.data=-1},function(){var e;(t=t||{data:{}}).data.multi_header||(t.data.multi_header=[]);try{e=new Se(t.data.uri,t.data.displayName,t.data.params),delete t.data.uri,delete t.data.displayName,delete t.data.params}catch(t){e=null}t.data.multi_header.push({position:h,offset:k().start.offset,parsed:e})},function(){(t=t||{data:{}}).data=new Se(t.data.uri,t.data.displayName,t.data.params)},function(){(t=t||{data:{}}).data.replaces_from_tag&&t.data.replaces_to_tag||(t.data=-1)},function(){(t=t||{data:{}}).data={call_id:t.data}},"from-tag",C("from-tag",!0),function(e){(t=t||{data:{}}).data.replaces_from_tag=e},"to-tag",C("to-tag",!0),function(e){(t=t||{data:{}}).data.replaces_to_tag=e},"early-only",C("early-only",!0),function(){(t=t||{data:{}}).data.early_only=!0},function(e,t){return t},function(e,t){return function(e,t){var n;return E(n=[e]).call(n,t)}(e,t)},function(e){"Require"===(t=t||{data:{}}).startRule&&(t.data=e||[])},function(e){(t=t||{data:{}}).data.value=T(e.join(""))},"active",C("active",!0),"pending",C("pending",!0),"terminated",C("terminated",!0),function(){(t=t||{data:{}}).data.state=w()},"reason",C("reason",!0),function(e){t=t||{data:{}},void 0!==e&&(t.data.reason=e)},function(e){t=t||{data:{}},void 0!==e&&(t.data.expires=e)},"retry_after",C("retry_after",!0),function(e){t=t||{data:{}},void 0!==e&&(t.data.retry_after=e)},"deactivated",C("deactivated",!0),"probation",C("probation",!0),"rejected",C("rejected",!0),"timeout",C("timeout",!0),"giveup",C("giveup",!0),"noresource",C("noresource",!0),"invariant",C("invariant",!0),function(e){"Supported"===(t=t||{data:{}}).startRule&&(t.data=e||[])},function(){var e=(t=t||{data:{}}).data.tag;t.data=new Se(t.data.uri,t.data.displayName,t.data.params),e&&t.data.setParam("tag",e)},"ttl",C("ttl",!0),function(e){(t=t||{data:{}}).data.ttl=e},"maddr",C("maddr",!0),function(e){(t=t||{data:{}}).data.maddr=e},"received",C("received",!0),function(e){(t=t||{data:{}}).data.received=e},"branch",C("branch",!0),function(e){(t=t||{data:{}}).data.branch=e},"rport",C("rport",!0),function(e){t=t||{data:{}},void 0!==e&&(t.data.rport=e.join(""))},function(e){(t=t||{data:{}}).data.protocol=e},C("UDP",!0),C("TCP",!0),C("TLS",!0),C("SCTP",!0),function(e){(t=t||{data:{}}).data.transport=e},function(){(t=t||{data:{}}).data.host=w()},function(e){(t=t||{data:{}}).data.port=T(e.join(""))},function(e){return T(e.join(""))},function(e){"Session_Expires"===(t=t||{data:{}}).startRule&&(t.data.deltaSeconds=e)},"refresher",C("refresher",!1),"uas",C("uas",!1),"uac",C("uac",!1),function(e){"Session_Expires"===(t=t||{data:{}}).startRule&&(t.data.refresher=e)},function(e){"Min_SE"===(t=t||{data:{}}).startRule&&(t.data=e)},"stuns",C("stuns",!0),"stun",C("stun",!0),function(e){(t=t||{data:{}}).data.scheme=e},function(e){(t=t||{data:{}}).data.host=e},"?transport=",C("?transport=",!1),"turns",C("turns",!0),"turn",C("turn",!0),function(e){(t=t||{data:{}}).data.transport=e},function(){(t=t||{data:{}}).data=w()},"Referred-By",C("Referred-By",!1),"b",C("b",!1),"cid",C("cid",!1)],d=[_('2 ""6 7!'),_('4"""5!7#'),_('4$""5!7%'),_('4&""5!7\''),_(";'.# &;("),_('4(""5!7)'),_('4*""5!7+'),_('2,""6,7-'),_('2.""6.7/'),_('40""5!71'),_('22""6273. &24""6475.} &26""6677.q &28""6879.e &2:""6:7;.Y &2<""6<7=.M &2>""6>7?.A &2@""6@7A.5 &2B""6B7C.) &2D""6D7E'),_(";).# &;,"),_('2F""6F7G.} &2H""6H7I.q &2J""6J7K.e &2L""6L7M.Y &2N""6N7O.M &2P""6P7Q.A &2R""6R7S.5 &2T""6T7U.) &2V""6V7W'),_('%%2X""6X7Y/5#;#/,$;#/#$+#)(#\'#("\'#&\'#/"!&,)'),_('%%$;$0#*;$&/,#; /#$+")("\'#&\'#." &"/=#$;$/�#*;$&&&#/\'$8":Z" )("\'#&\'#'),_(';.." &"'),_("%$;'.# &;(0)*;'.# &;(&/?#28\"\"6879/0$;//'$8#:[# )(#'#(\"'#&'#"),_('%%$;2/�#*;2&&&#/g#$%$;.0#*;.&/,#;2/#$+")("\'#&\'#0=*%$;.0#*;.&/,#;2/#$+")("\'#&\'#&/#$+")("\'#&\'#/"!&,)'),_('4\\""5!7].# &;3'),_('4^""5!7_'),_('4`""5!7a'),_(';!.) &4b""5!7c'),_('%$;). &2F""6F7G. &2J""6J7K.} &2L""6L7M.q &2X""6X7Y.e &2P""6P7Q.Y &2H""6H7I.M &2@""6@7A.A &2d""6d7e.5 &2R""6R7S.) &2N""6N7O/#0*;). &2F""6F7G. &2J""6J7K.} &2L""6L7M.q &2X""6X7Y.e &2P""6P7Q.Y &2H""6H7I.M &2@""6@7A.A &2d""6d7e.5 &2R""6R7S.) &2N""6N7O&&&#/"!&,)'),_('%$;). &2F""6F7G.} &2L""6L7M.q &2X""6X7Y.e &2P""6P7Q.Y &2H""6H7I.M &2@""6@7A.A &2d""6d7e.5 &2R""6R7S.) &2N""6N7O/#0*;). &2F""6F7G.} &2L""6L7M.q &2X""6X7Y.e &2P""6P7Q.Y &2H""6H7I.M &2@""6@7A.A &2d""6d7e.5 &2R""6R7S.) &2N""6N7O&&&#/"!&,)'),_('2T""6T7U.ã &2V""6V7W.× &2f""6f7g.Ë &2h""6h7i.¿ &2:""6:7;.³ &2D""6D7E.§ &22""6273. &28""6879. &2j""6j7k. &;&.} &24""6475.q &2l""6l7m.e &2n""6n7o.Y &26""6677.M &2>""6>7?.A &2p""6p7q.5 &2r""6r7s.) &;\'.# &;('),_('%$;).ī &2F""6F7G.ğ &2J""6J7K.ē &2L""6L7M.ć &2X""6X7Y.û &2P""6P7Q.ï &2H""6H7I.ã &2@""6@7A.× &2d""6d7e.Ë &2R""6R7S.¿ &2N""6N7O.³ &2T""6T7U.§ &2V""6V7W. &2f""6f7g. &2h""6h7i. &28""6879.w &2j""6j7k.k &;&.e &24""6475.Y &2l""6l7m.M &2n""6n7o.A &26""6677.5 &2p""6p7q.) &2r""6r7s/Ĵ#0ı*;).ī &2F""6F7G.ğ &2J""6J7K.ē &2L""6L7M.ć &2X""6X7Y.û &2P""6P7Q.ï &2H""6H7I.ã &2@""6@7A.× &2d""6d7e.Ë &2R""6R7S.¿ &2N""6N7O.³ &2T""6T7U.§ &2V""6V7W. &2f""6f7g. &2h""6h7i. &28""6879.w &2j""6j7k.k &;&.e &24""6475.Y &2l""6l7m.M &2n""6n7o.A &26""6677.5 &2p""6p7q.) &2r""6r7s&&&#/"!&,)'),_("%;//?#2P\"\"6P7Q/0$;//'$8#:t# )(#'#(\"'#&'#"),_("%;//?#24\"\"6475/0$;//'$8#:u# )(#'#(\"'#&'#"),_("%;//?#2>\"\"6>7?/0$;//'$8#:v# )(#'#(\"'#&'#"),_("%;//?#2T\"\"6T7U/0$;//'$8#:w# )(#'#(\"'#&'#"),_("%;//?#2V\"\"6V7W/0$;//'$8#:x# )(#'#(\"'#&'#"),_('%2h""6h7i/0#;//\'$8":y" )("\'#&\'#'),_('%;//6#2f""6f7g/\'$8":z" )("\'#&\'#'),_("%;//?#2D\"\"6D7E/0$;//'$8#:{# )(#'#(\"'#&'#"),_("%;//?#22\"\"6273/0$;//'$8#:|# )(#'#(\"'#&'#"),_("%;//?#28\"\"6879/0$;//'$8#:}# )(#'#(\"'#&'#"),_("%;//0#;&/'$8\":~\" )(\"'#&'#"),_("%;&/0#;//'$8\":~\" )(\"'#&'#"),_("%;=/T#$;G.) &;K.# &;F0/*;G.) &;K.# &;F&/,$;>/#$+#)(#'#(\"'#&'#"),_('4""5!7.A &4""5!7.5 &4""5!7.) &;3.# &;.'),_("%%;//Q#;&/H$$;J.# &;K0)*;J.# &;K&/,$;&/#$+$)($'#(#'#(\"'#&'#/\"!&,)"),_("%;//]#;&/T$%$;J.# &;K0)*;J.# &;K&/\"!&,)/1$;&/($8$:
$!!)($'#(#'#(\"'#&'#"),_(';..G &2L""6L7M.; &4""5!7./ &4""5!7.# &;3'),_('%2j""6j7k/J#4""5!7.5 &4""5!7.) &4""5!7/#$+")("\'#&\'#'),_("%;N/M#28\"\"6879/>$;O.\" &\"/0$;S/'$8$:$ )($'#(#'#(\"'#&'#"),_("%;N/d#28\"\"6879/U$;O.\" &\"/G$;S/>$;_/5$;l.\" &\"/'$8&:& )(&'#(%'#($'#(#'#(\"'#&'#"),_('%3""5$7.) &3""5#7/\' 8!:!! )'),_('%;P/]#%28""6879/,#;R/#$+")("\'#&\'#." &"/6$2:""6:7;/\'$8#:# )(#\'#("\'#&\'#'),_("$;+.) &;-.# &;Q/2#0/*;+.) &;-.# &;Q&&&#"),_('2<""6<7=.q &2>""6>7?.e &2@""6@7A.Y &2B""6B7C.M &2D""6D7E.A &22""6273.5 &26""6677.) &24""6475'),_('%$;+._ &;-.Y &2<""6<7=.M &2>""6>7?.A &2@""6@7A.5 &2B""6B7C.) &2D""6D7E0e*;+._ &;-.Y &2<""6<7=.M &2>""6>7?.A &2@""6@7A.5 &2B""6B7C.) &2D""6D7E&/& 8!:! )'),_('%;T/J#%28""6879/,#;^/#$+")("\'#&\'#." &"/#$+")("\'#&\'#'),_("%;U.) &;\\.# &;X/& 8!:! )"),_('%$%;V/2#2J""6J7K/#$+")("\'#&\'#0<*%;V/2#2J""6J7K/#$+")("\'#&\'#&/D#;W/;$2J""6J7K." &"/\'$8#:# )(#\'#("\'#&\'#'),_('$4""5!7/,#0)*4""5!7&&&#'),_('%4$""5!7%/?#$4""5!70)*4""5!7&/#$+")("\'#&\'#'),_('%2l""6l7m/?#;Y/6$2n""6n7o/\'$8#:# )(#\'#("\'#&\'#'),_('%%;Z/³#28""6879/¤$;Z/$28""6879/$;Z/$28""6879/t$;Z/k$28""6879/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+-)(-\'#(,\'#(+\'#(*\'#()\'#((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.ސ &%2""67/¤#;Z/$28""6879/$;Z/$28""6879/t$;Z/k$28""6879/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+,)(,\'#(+\'#(*\'#()\'#((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.۹ &%2""67/#;Z/$28""6879/t$;Z/k$28""6879/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+*)(*\'#()\'#((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.ٺ &%2""67/t#;Z/k$28""6879/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+()((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.ؓ &%2""67/\\#;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+&)(&\'#(%\'#($\'#(#\'#("\'#&\'#.ׄ &%2""67/D#;Z/;$28""6879/,$;[/#$+$)($\'#(#\'#("\'#&\'#.֍ &%2""67/,#;[/#$+")("\'#&\'#.ծ &%2""67/,#;Z/#$+")("\'#&\'#.Տ &%;Z/#2""67/$;Z/$28""6879/t$;Z/k$28""6879/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$++)(+\'#(*\'#()\'#((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.Ӈ &%;Z/ª#%28""6879/,#;Z/#$+")("\'#&\'#." &"/$2""67/t$;Z/k$28""6879/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+*)(*\'#()\'#((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.а &%;Z/¹#%28""6879/,#;Z/#$+")("\'#&\'#." &"/$%28""6879/,#;Z/#$+")("\'#&\'#." &"/k$2""67/\\$;Z/S$28""6879/D$;Z/;$28""6879/,$;[/#$+))()\'#((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.Ί &%;Z/È#%28""6879/,#;Z/#$+")("\'#&\'#." &"/¡$%28""6879/,#;Z/#$+")("\'#&\'#." &"/z$%28""6879/,#;Z/#$+")("\'#&\'#." &"/S$2""67/D$;Z/;$28""6879/,$;[/#$+()((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.˕ &%;Z/×#%28""6879/,#;Z/#$+")("\'#&\'#." &"/°$%28""6879/,#;Z/#$+")("\'#&\'#." &"/$%28""6879/,#;Z/#$+")("\'#&\'#." &"/b$%28""6879/,#;Z/#$+")("\'#&\'#." &"/;$2""67/,$;[/#$+\')(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.ȑ &%;Z/þ#%28""6879/,#;Z/#$+")("\'#&\'#." &"/×$%28""6879/,#;Z/#$+")("\'#&\'#." &"/°$%28""6879/,#;Z/#$+")("\'#&\'#." &"/$%28""6879/,#;Z/#$+")("\'#&\'#." &"/b$%28""6879/,#;Z/#$+")("\'#&\'#." &"/;$2""67/,$;Z/#$+()((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#.Ħ &%;Z/Ĝ#%28""6879/,#;Z/#$+")("\'#&\'#." &"/õ$%28""6879/,#;Z/#$+")("\'#&\'#." &"/Î$%28""6879/,#;Z/#$+")("\'#&\'#." &"/§$%28""6879/,#;Z/#$+")("\'#&\'#." &"/$%28""6879/,#;Z/#$+")("\'#&\'#." &"/Y$%28""6879/,#;Z/#$+")("\'#&\'#." &"/2$2""67/#$+()((\'#(\'\'#(&\'#(%\'#($\'#(#\'#("\'#&\'#/& 8!: ! )'),_('%;#/M#;#." &"/?$;#." &"/1$;#." &"/#$+$)($\'#(#\'#("\'#&\'#'),_("%;Z/;#28\"\"6879/,$;Z/#$+#)(#'#(\"'#&'#.# &;\\"),_("%;]/o#2J\"\"6J7K/`$;]/W$2J\"\"6J7K/H$;]/?$2J\"\"6J7K/0$;]/'$8':¡' )(''#(&'#(%'#($'#(#'#(\"'#&'#"),_('%2¢""6¢7£/2#4¤""5!7¥/#$+")("\'#&\'#. &%2¦""6¦7§/;#4¨""5!7©/,$;!/#$+#)(#\'#("\'#&\'#.j &%2ª""6ª7«/5#;!/,$;!/#$+#)(#\'#("\'#&\'#.B &%4¬""5!7/,#;!/#$+")("\'#&\'#.# &;!'),_('%%;!." &"/[#;!." &"/M$;!." &"/?$;!." &"/1$;!." &"/#$+%)(%\'#($\'#(#\'#("\'#&\'#/\' 8!:®!! )'),_('$%22""6273/,#;`/#$+")("\'#&\'#0<*%22""6273/,#;`/#$+")("\'#&\'#&'),_(";a.A &;b.; &;c.5 &;d./ &;e.) &;f.# &;g"),_('%3¯""5*7°/a#3±""5#7².G &3³""5#7´.; &3µ""5$7¶./ &3·""5#7¸.# &;6/($8":¹"! )("\'#&\'#'),_('%3º""5%7»/I#3¼""5%7½./ &3¾""5"7¿.# &;6/($8":À"! )("\'#&\'#'),_('%3Á""5\'7Â/1#;/($8":Ã"! )("\'#&\'#'),_('%3Ä""5$7Å/1#;ð/($8":Æ"! )("\'#&\'#'),_('%3Ç""5&7È/1#;T/($8":É"! )("\'#&\'#'),_('%3Ê""5"7Ë/N#%2>""6>7?/,#;6/#$+")("\'#&\'#." &"/\'$8":Ì" )("\'#&\'#'),_('%;h/P#%2>""6>7?/,#;i/#$+")("\'#&\'#." &"/)$8":Í""! )("\'#&\'#'),_('%$;j/�#*;j&&&#/"!&,)'),_('%$;j/�#*;j&&&#/"!&,)'),_(";k.) &;+.# &;-"),_('2l""6l7m.e &2n""6n7o.Y &24""6475.M &28""6879.A &2<""6<7=.5 &2@""6@7A.) &2B""6B7C'),_('%26""6677/n#;m/e$$%2<""6<7=/,#;m/#$+")("\'#&\'#0<*%2<""6<7=/,#;m/#$+")("\'#&\'#&/#$+#)(#\'#("\'#&\'#'),_('%;n/A#2>""6>7?/2$;o/)$8#:Î#"" )(#\'#("\'#&\'#'),_("$;p.) &;+.# &;-/2#0/*;p.) &;+.# &;-&&&#"),_("$;p.) &;+.# &;-0/*;p.) &;+.# &;-&"),_('2l""6l7m.e &2n""6n7o.Y &24""6475.M &26""6677.A &28""6879.5 &2@""6@7A.) &2B""6B7C'),_(";.# &;r"),_("%;/G#;'/>$;s/5$;'/,$;/#$+%)(%'#($'#(#'#(\"'#&'#"),_(";M.# &;t"),_("%;/E#28\"\"6879/6$;u.# &;x/'$8#:Ï# )(#'#(\"'#&'#"),_('%;v.# &;w/J#%26""6677/,#;/#$+")("\'#&\'#." &"/#$+")("\'#&\'#'),_('%2Ð""6Ð7Ñ/:#;/1$;w." &"/#$+#)(#\'#("\'#&\'#'),_('%24""6475/,#;{/#$+")("\'#&\'#'),_("%;z/3#$;y0#*;y&/#$+\")(\"'#&'#"),_(";*.) &;+.# &;-"),_(';+. &;-. &22""6273.} &26""6677.q &28""6879.e &2:""6:7;.Y &2<""6<7=.M &2>""6>7?.A &2@""6@7A.5 &2B""6B7C.) &2D""6D7E'),_('%;|/e#$%24""6475/,#;|/#$+")("\'#&\'#0<*%24""6475/,#;|/#$+")("\'#&\'#&/#$+")("\'#&\'#'),_('%$;~0#*;~&/e#$%22""6273/,#;}/#$+")("\'#&\'#0<*%22""6273/,#;}/#$+")("\'#&\'#&/#$+")("\'#&\'#'),_("$;~0#*;~&"),_(';+.w &;-.q &28""6879.e &2:""6:7;.Y &2<""6<7=.M &2>""6>7?.A &2@""6@7A.5 &2B""6B7C.) &2D""6D7E'),_('%%;"/#$;".G &;!.A &2@""6@7A.5 &2F""6F7G.) &2J""6J7K0M*;".G &;!.A &2@""6@7A.5 &2F""6F7G.) &2J""6J7K&/#$+")("\'#&\'#/& 8!:Ò! )'),_(";.# &;"),_('%%;O/2#2:""6:7;/#$+")("\'#&\'#." &"/,#;S/#$+")("\'#&\'#." &"'),_('$;+. &;-.} &2B""6B7C.q &2D""6D7E.e &22""6273.Y &28""6879.M &2:""6:7;.A &2<""6<7=.5 &2>""6>7?.) &2@""6@7A/#0*;+. &;-.} &2B""6B7C.q &2D""6D7E.e &22""6273.Y &28""6879.M &2:""6:7;.A &2<""6<7=.5 &2>""6>7?.) &2@""6@7A&&&#'),_("$;y0#*;y&"),_('%3""5#7Ó/q#24""6475/b$$;!/�#*;!&&&#/L$2J""6J7K/=$$;!/�#*;!&&&#/\'$8%:Ô% )(%\'#($\'#(#\'#("\'#&\'#'),_('2Õ""6Õ7Ö'),_('2×""6×7Ø'),_('2Ù""6Ù7Ú'),_('2Û""6Û7Ü'),_('2Ý""6Ý7Þ'),_('2ß""6ß7à'),_('2á""6á7â'),_('2ã""6ã7ä'),_('2å""6å7æ'),_('2ç""6ç7è'),_('2é""6é7ê'),_("%;
.Y &;.S &;.M &;.G &;.A &;.; &;.5 &;./ &;.) &;.# &;6/& 8!:ë! )"),_("%;/G#;'/>$;/5$;'/,$;/#$+%)(%'#($'#(#'#(\"'#&'#"),_("%;/' 8!:ì!! )"),_("%;!/5#;!/,$;!/#$+#)(#'#(\"'#&'#"),_("%$;*.A &;+.; &;-.5 &;3./ &;4.) &;'.# &;(0G*;*.A &;+.; &;-.5 &;3./ &;4.) &;'.# &;(&/& 8!:í! )"),_("%;¶/Y#$%;A/,#;¶/#$+\")(\"'#&'#06*%;A/,#;¶/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),_('%;9/N#%2:""6:7;/,#;9/#$+")("\'#&\'#." &"/\'$8":î" )("\'#&\'#'),_("%;:.c &%;/Y#$%;A/,#;/#$+\")(\"'#&'#06*%;A/,#;/#$+\")(\"'#&'#&/#$+\")(\"'#&'#/& 8!:ï! )"),_("%;L.# &;/]#$%;B/,#;/#$+\")(\"'#&'#06*%;B/,#;/#$+\")(\"'#&'#&/'$8\":ð\" )(\"'#&'#"),_("%;.\" &\"/>#;@/5$;M/,$;?/#$+$)($'#(#'#(\"'#&'#"),_("%%;6/Y#$%;./,#;6/#$+\")(\"'#&'#06*%;./,#;6/#$+\")(\"'#&'#&/#$+\")(\"'#&'#.# &;H/' 8!:ñ!! )"),_(";.) &;.# &; "),_("%3ò\"\"5!7ó/:#;</1$;/($8#:ô#! )(#'#(\"'#&'#"),_("%3õ\"\"5'7ö/:#;</1$;/($8#:÷#! )(#'#(\"'#&'#"),_("%$;!/�#*;!&&&#/' 8!:ø!! )"),_('%2ù""6ù7ú/o#%2J""6J7K/M#;!." &"/?$;!." &"/1$;!." &"/#$+$)($\'#(#\'#("\'#&\'#." &"/\'$8":û" )("\'#&\'#'),_('%;6/J#%;</,#;¡/#$+")("\'#&\'#." &"/)$8":ü""! )("\'#&\'#'),_(";6.) &;T.# &;H"),_("%;£/Y#$%;B/,#;¤/#$+\")(\"'#&'#06*%;B/,#;¤/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),_('%3ý""5&7þ.G &3ÿ""5\'7Ā.; &3ā""5$7Ă./ &3ă""5%7Ą.# &;6/& 8!:ą! )'),_(";¥.# &; "),_('%3Ć""5(7ć/M#;</D$3Ĉ""5(7ĉ./ &3Ċ""5(7ċ.# &;6/#$+#)(#\'#("\'#&\'#'),_("%;6/Y#$%;A/,#;6/#$+\")(\"'#&'#06*%;A/,#;6/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),_("%$;!/�#*;!&&&#/' 8!:Č!! )"),_("%;©/& 8!:č! )"),_("%;ª/k#;;/b$;¯/Y$$%;B/,#;°/#$+\")(\"'#&'#06*%;B/,#;°/#$+\")(\"'#&'#&/#$+$)($'#(#'#(\"'#&'#"),_(";«.# &;¬"),_('3Ď""5$7ď.S &3Đ""5%7đ.G &3Ē""5%7ē.; &3Ĕ""5%7ĕ./ &3Ė""5+7ė.# &;'),_('3Ę""5\'7ę./ &3Ě""5)7ě.# &;'),_(";6.# &;®"),_('%3Ĝ""5"7ĝ/,#;6/#$+")("\'#&\'#'),_(";.# &;6"),_("%;6/5#;</,$;±/#$+#)(#'#(\"'#&'#"),_(";6.# &;H"),_("%;³/5#;./,$;/#$+#)(#'#(\"'#&'#"),_("%$;!/�#*;!&&&#/' 8!:Ğ!! )"),_("%;/' 8!:ğ!! )"),_('%;¶/^#$%;B/,#; /#$+")("\'#&\'#06*%;B/,#; /#$+")("\'#&\'#&/($8":Ġ"!!)("\'#&\'#'),_('%%;7/e#$%2J""6J7K/,#;7/#$+")("\'#&\'#0<*%2J""6J7K/,#;7/#$+")("\'#&\'#&/#$+")("\'#&\'#/"!&,)'),_("%;L.# &;/]#$%;B/,#;¸/#$+\")(\"'#&'#06*%;B/,#;¸/#$+\")(\"'#&'#&/'$8\":ġ\" )(\"'#&'#"),_(";¹.# &; "),_("%3Ģ\"\"5#7ģ/:#;</1$;6/($8#:Ĥ#! )(#'#(\"'#&'#"),_("%$;!/�#*;!&&&#/' 8!:ĥ!! )"),_("%;/' 8!:Ħ!! )"),_("%$;0#*;&/x#;@/o$;M/f$;?/]$$%;B/,#; /#$+\")(\"'#&'#06*%;B/,#; /#$+\")(\"'#&'#&/'$8%:ħ% )(%'#($'#(#'#(\"'#&'#"),_(";¾"),_("%3Ĩ\"\"5&7ĩ/k#;./b$;Á/Y$$%;A/,#;Á/#$+\")(\"'#&'#06*%;A/,#;Á/#$+\")(\"'#&'#&/#$+$)($'#(#'#(\"'#&'#.# &;¿"),_("%;6/k#;./b$;À/Y$$%;A/,#;À/#$+\")(\"'#&'#06*%;A/,#;À/#$+\")(\"'#&'#&/#$+$)($'#(#'#(\"'#&'#"),_("%;6/;#;</2$;6.# &;H/#$+#)(#'#(\"'#&'#"),_(";Â.G &;Ä.A &;Æ.; &;È.5 &;É./ &;Ê.) &;Ë.# &;À"),_("%3Ī\"\"5%7ī/5#;</,$;Ã/#$+#)(#'#(\"'#&'#"),_("%;I/' 8!:Ĭ!! )"),_("%3ĭ\"\"5&7Į/#;</$;D/
$;Å/|$$%$;'/�#*;'&&&#/,#;Å/#$+\")(\"'#&'#0C*%$;'/�#*;'&&&#/,#;Å/#$+\")(\"'#&'#&/,$;E/#$+&)(&'#(%'#($'#(#'#(\"'#&'#"),_(";t.# &;w"),_("%3į\"\"5%7İ/5#;</,$;Ç/#$+#)(#'#(\"'#&'#"),_("%;I/' 8!:ı!! )"),_("%3IJ\"\"5&7ij/:#;</1$;I/($8#:Ĵ#! )(#'#(\"'#&'#"),_('%3ĵ""5%7Ķ/]#;</T$%3ķ""5$7ĸ/& 8!:Ĺ! ).4 &%3ĺ""5%7Ļ/& 8!:ļ! )/#$+#)(#\'#("\'#&\'#'),_('%3Ľ""5)7ľ/R#;</I$3Ŀ""5#7ŀ./ &3Ł""5(7ł.# &;6/($8#:Ń#! )(#\'#("\'#&\'#'),_('%3ń""5#7Ņ/#;</$;D/$%;Ì/e#$%2D""6D7E/,#;Ì/#$+")("\'#&\'#0<*%2D""6D7E/,#;Ì/#$+")("\'#&\'#&/#$+")("\'#&\'#/,$;E/#$+%)(%\'#($\'#(#\'#("\'#&\'#'),_('%3ņ""5(7Ň./ &3ň""5$7ʼn.# &;6/\' 8!:Ŋ!! )'),_("%;6/Y#$%;A/,#;6/#$+\")(\"'#&'#06*%;A/,#;6/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),_("%;Ï/G#;./>$;Ï/5$;./,$;/#$+%)(%'#($'#(#'#(\"'#&'#"),_("%$;!/�#*;!&&&#/' 8!:ŋ!! )"),_("%;Ñ/]#$%;A/,#;Ñ/#$+\")(\"'#&'#06*%;A/,#;Ñ/#$+\")(\"'#&'#&/'$8\":Ō\" )(\"'#&'#"),_("%;/]#$%;B/,#; /#$+\")(\"'#&'#06*%;B/,#; /#$+\")(\"'#&'#&/'$8\":ō\" )(\"'#&'#"),_('%;L.O &;.I &%;@." &"/:#;t/1$;?." &"/#$+#)(#\'#("\'#&\'#/]#$%;B/,#; /#$+")("\'#&\'#06*%;B/,#; /#$+")("\'#&\'#&/\'$8":Ŏ" )("\'#&\'#'),_("%;Ô/]#$%;B/,#;Õ/#$+\")(\"'#&'#06*%;B/,#;Õ/#$+\")(\"'#&'#&/'$8\":ŏ\" )(\"'#&'#"),_("%;/& 8!:Ő! )"),_('%3ő""5(7Œ/:#;</1$;6/($8#:œ#! )(#\'#("\'#&\'#.g &%3Ŕ""5&7ŕ/:#;</1$;6/($8#:Ŗ#! )(#\'#("\'#&\'#.: &%3ŗ""5*7Ř/& 8!:ř! ).# &; '),_('%%;6/k#$%;A/2#;6/)$8":Ś""$ )("\'#&\'#0<*%;A/2#;6/)$8":Ś""$ )("\'#&\'#&/)$8":ś""! )("\'#&\'#." &"/\' 8!:Ŝ!! )'),_("%;Ø/Y#$%;A/,#;Ø/#$+\")(\"'#&'#06*%;A/,#;Ø/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),_("%;/Y#$%;B/,#; /#$+\")(\"'#&'#06*%;B/,#; /#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),_("%$;!/�#*;!&&&#/' 8!:ŝ!! )"),_("%;Û/Y#$%;B/,#;Ü/#$+\")(\"'#&'#06*%;B/,#;Ü/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),_('%3Ş""5&7ş.; &3Š""5\'7š./ &3Ţ""5*7ţ.# &;6/& 8!:Ť! )'),_("%3ť\"\"5&7Ŧ/:#;</1$;Ý/($8#:ŧ#! )(#'#(\"'#&'#.} &%3õ\"\"5'7ö/:#;</1$;/($8#:Ũ#! )(#'#(\"'#&'#.P &%3ũ\"\"5+7Ū/:#;</1$;/($8#:ū#! )(#'#(\"'#&'#.# &; "),_('3Ŭ""5+7ŭ.k &3Ů""5)7ů._ &3Ű""5(7ű.S &3Ų""5\'7ų.G &3Ŵ""5&7ŵ.; &3Ŷ""5*7ŷ./ &3Ÿ""5)7Ź.# &;6'),_(';1." &"'),_('%%;6/k#$%;A/2#;6/)$8":Ś""$ )("\'#&\'#0<*%;A/2#;6/)$8":Ś""$ )("\'#&\'#&/)$8":ś""! )("\'#&\'#." &"/\' 8!:ź!! )'),_("%;L.# &;/]#$%;B/,#;á/#$+\")(\"'#&'#06*%;B/,#;á/#$+\")(\"'#&'#&/'$8\":Ż\" )(\"'#&'#"),_(";¹.# &; "),_("%;ã/Y#$%;A/,#;ã/#$+\")(\"'#&'#06*%;A/,#;ã/#$+\")(\"'#&'#&/#$+\")(\"'#&'#"),_("%;ê/k#;./b$;í/Y$$%;B/,#;ä/#$+\")(\"'#&'#06*%;B/,#;ä/#$+\")(\"'#&'#&/#$+$)($'#(#'#(\"'#&'#"),_(";å.; &;æ.5 &;ç./ &;è.) &;é.# &; "),_("%3ż\"\"5#7Ž/:#;</1$;ð/($8#:ž#! )(#'#(\"'#&'#"),_("%3ſ\"\"5%7ƀ/:#;</1$;T/($8#:Ɓ#! )(#'#(\"'#&'#"),_("%3Ƃ\"\"5(7ƃ/F#;</=$;\\.) &;Y.# &;X/($8#:Ƅ#! )(#'#(\"'#&'#"),_("%3ƅ\"\"5&7Ɔ/:#;</1$;6/($8#:Ƈ#! )(#'#(\"'#&'#"),_("%3ƈ\"\"5%7Ɖ/A#;</8$$;!0#*;!&/($8#:Ɗ#! )(#'#(\"'#&'#"),_("%;ë/G#;;/>$;6/5$;;/,$;ì/#$+%)(%'#($'#(#'#(\"'#&'#"),_('%3""5#7Ó.# &;6/\' 8!:Ƌ!! )'),_('%3±""5#7ƌ.G &3³""5#7ƍ.; &3·""5#7Ǝ./ &3µ""5$7Ə.# &;6/\' 8!:Ɛ!! )'),_('%;î/D#%;C/,#;ï/#$+")("\'#&\'#." &"/#$+")("\'#&\'#'),_("%;U.) &;\\.# &;X/& 8!:Ƒ! )"),_('%%;!." &"/[#;!." &"/M$;!." &"/?$;!." &"/1$;!." &"/#$+%)(%\'#($\'#(#\'#("\'#&\'#/\' 8!:ƒ!! )'),_('%%;!/?#;!." &"/1$;!." &"/#$+#)(#\'#("\'#&\'#/\' 8!:Ɠ!! )'),_(";¾"),_('%;/^#$%;B/,#;ó/#$+")("\'#&\'#06*%;B/,#;ó/#$+")("\'#&\'#&/($8":Ɣ"!!)("\'#&\'#'),_(";ô.# &; "),_('%2ƕ""6ƕ7Ɩ/L#;</C$2Ɨ""6Ɨ7Ƙ.) &2ƙ""6ƙ7ƚ/($8#:ƛ#! )(#\'#("\'#&\'#'),_('%;/^#$%;B/,#; /#$+")("\'#&\'#06*%;B/,#; /#$+")("\'#&\'#&/($8":Ɯ"!!)("\'#&\'#'),_("%;6/5#;0/,$;÷/#$+#)(#'#(\"'#&'#"),_("$;2.) &;4.# &;.0/*;2.) &;4.# &;.&"),_("$;%0#*;%&"),_("%;ú/;#28\"\"6879/,$;û/#$+#)(#'#(\"'#&'#"),_('%3Ɲ""5%7ƞ.) &3Ɵ""5$7Ơ/\' 8!:ơ!! )'),_('%;ü/J#%28""6879/,#;^/#$+")("\'#&\'#." &"/#$+")("\'#&\'#'),_("%;\\.) &;X.# &;/' 8!:Ƣ!! )"),_(';".S &;!.M &2F""6F7G.A &2J""6J7K.5 &2H""6H7I.) &2N""6N7O'),_('2L""6L7M. &2B""6B7C. &2<""6<7=.} &2R""6R7S.q &2T""6T7U.e &2V""6V7W.Y &2P""6P7Q.M &2@""6@7A.A &2D""6D7E.5 &22""6273.) &2>""6>7?'),_('%;Ā/b#28""6879/S$;û/J$%2ƣ""6ƣ7Ƥ/,#;ì/#$+")("\'#&\'#." &"/#$+$)($\'#(#\'#("\'#&\'#'),_('%3ƥ""5%7Ʀ.) &3Ƨ""5$7ƨ/\' 8!:ơ!! )'),_('%3±""5#7².6 &3³""5#7´.* &$;+0#*;+&/\' 8!:Ʃ!! )'),_("%;Ą/#2F\"\"6F7G/x$;ă/o$2F\"\"6F7G/`$;ă/W$2F\"\"6F7G/H$;ă/?$2F\"\"6F7G/0$;ą/'$8):ƪ) )()'#(('#(''#(&'#(%'#($'#(#'#(\"'#&'#"),_("%;#/>#;#/5$;#/,$;#/#$+$)($'#(#'#(\"'#&'#"),_("%;ă/,#;ă/#$+\")(\"'#&'#"),_("%;ă/5#;ă/,$;ă/#$+#)(#'#(\"'#&'#"),_("%;q/T#$;m0#*;m&/D$%; /,#;ø/#$+\")(\"'#&'#.\" &\"/#$+#)(#'#(\"'#&'#"),_('%2ƫ""6ƫ7Ƭ.) &2ƭ""6ƭ7Ʈ/w#;0/n$;Ĉ/e$$%;B/2#;ĉ.# &; /#$+")("\'#&\'#0<*%;B/2#;ĉ.# &; /#$+")("\'#&\'#&/#$+$)($\'#(#\'#("\'#&\'#'),_(";.# &;L"),_("%2Ư\"\"6Ư7ư/5#;</,$;Ċ/#$+#)(#'#(\"'#&'#"),_("%;D/S#;,/J$2:\"\"6:7;/;$;,.# &;T/,$;E/#$+%)(%'#($'#(#'#(\"'#&'#")],h=0,f=0,v=[{line:1,column:1}],p=0,m=[],b=0;if(void 0!==t.startRule){if(!(t.startRule in c))throw new Error("Can't start parsing from rule \""+t.startRule+'".');l=c[t.startRule]}function w(){return e.substring(f,h)}function k(){return D(f,h)}function C(e,t){return{type:"literal",text:e,ignoreCase:t}}function A(e,t,n){return{type:"class",parts:e,inverted:t,ignoreCase:n}}function x(t){var n,i=v[t];if(i)return i;for(n=t-1;!v[n];)n--;for(i={line:(i=v[n]).line,column:i.column};n<t;)10===e.charCodeAt(n)?(i.line++,i.column=1):i.column++,n++;return v[t]=i,i}function D(e,t){var n=x(e),i=x(t);return{source:o,start:{offset:e,line:n.line,column:n.column},end:{offset:t,line:i.line,column:i.column}}}function H(e){h<p||(h>p&&(p=h,m=[]),m.push(e))}function _(e){var t;return y(t=e.split("")).call(t,function(e){return e.charCodeAt(0)-32})}if(t.data={},n=function t(n){for(var i,r,s=d[n],o=0,c=[],l=s.length,v=[],p=[];;){for(;o<l;)switch(s[o]){case 0:p.push(u[s[o+1]]),o+=2;break;case 1:p.push(void 0),o++;break;case 2:p.push(null),o++;break;case 3:p.push(a),o++;break;case 4:p.push([]),o++;break;case 5:p.push(h),o++;break;case 6:p.pop(),o++;break;case 7:h=p.pop(),o++;break;case 8:p.length-=s[o+1],o+=2;break;case 9:I(p).call(p,-2,1),o++;break;case 10:p[p.length-2].push(p.pop()),o++;break;case 11:p.push(I(p).call(p,p.length-s[o+1],s[o+1])),o+=2;break;case 12:p.push(e.substring(p.pop(),h)),o++;break;case 13:v.push(l),c.push(o+3+s[o+1]+s[o+2]),p[p.length-1]?(l=o+3+s[o+1],o+=3):(l=o+3+s[o+1]+s[o+2],o+=3+s[o+1]);break;case 14:v.push(l),c.push(o+3+s[o+1]+s[o+2]),p[p.length-1]===a?(l=o+3+s[o+1],o+=3):(l=o+3+s[o+1]+s[o+2],o+=3+s[o+1]);break;case 15:v.push(l),c.push(o+3+s[o+1]+s[o+2]),p[p.length-1]!==a?(l=o+3+s[o+1],o+=3):(l=o+3+s[o+1]+s[o+2],o+=3+s[o+1]);break;case 16:p[p.length-1]!==a?(v.push(l),c.push(o),l=o+2+s[o+1],o+=2):o+=2+s[o+1];break;case 17:v.push(l),c.push(o+3+s[o+1]+s[o+2]),e.length>h?(l=o+3+s[o+1],o+=3):(l=o+3+s[o+1]+s[o+2],o+=3+s[o+1]);break;case 18:v.push(l),c.push(o+4+s[o+2]+s[o+3]),e.substr(h,u[s[o+1]].length)===u[s[o+1]]?(l=o+4+s[o+2],o+=4):(l=o+4+s[o+2]+s[o+3],o+=4+s[o+2]);break;case 19:v.push(l),c.push(o+4+s[o+2]+s[o+3]),e.substr(h,u[s[o+1]].length).toLowerCase()===u[s[o+1]]?(l=o+4+s[o+2],o+=4):(l=o+4+s[o+2]+s[o+3],o+=4+s[o+2]);break;case 20:v.push(l),c.push(o+4+s[o+2]+s[o+3]),u[s[o+1]].test(e.charAt(h))?(l=o+4+s[o+2],o+=4):(l=o+4+s[o+2]+s[o+3],o+=4+s[o+2]);break;case 21:p.push(e.substr(h,s[o+1])),h+=s[o+1],o+=2;break;case 22:p.push(u[s[o+1]]),h+=u[s[o+1]].length,o+=2;break;case 23:p.push(a),0===b&&H(u[s[o+1]]),o+=2;break;case 24:f=p[p.length-1-s[o+1]],o+=2;break;case 25:f=h,o++;break;case 26:r=y(i=g(s).call(s,o+4,o+4+s[o+3])).call(i,function(e){return p[p.length-1-e]}),I(p).call(p,p.length-s[o+2],s[o+2],u[s[o+1]].apply(null,r)),o+=4+s[o+3];break;case 27:p.push(t(s[o+1])),o+=2;break;case 28:b++,o++;break;case 29:b--,o++;break;default:throw new Error("Invalid opcode: "+s[o]+".")}if(!(v.length>0))break;l=v.pop(),o=c.pop()}return p[0]}(l),n!==a&&h===e.length)return n;throw n!==a&&h<e.length&&H({type:"end"}),i=m,r=p<e.length?e.charAt(p):null,s=p<e.length?D(p,p+1):D(p,p),new De(De.buildMessage(i,r),i,r,s)};!function(e){e.parse=function(e,t){var n={startRule:t};try{_e(e,n)}catch(e){n.data=-1}return n.data},e.nameAddrHeaderParse=function(t){var n=e.parse(t,"Name_Addr_Header");return-1!==n?n:void 0},e.URIParse=function(t){var n=e.parse(t,"SIP_URI");return-1!==n?n:void 0}}(He||(He={}));var $e={100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"};function qe(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:32,n="",i=0;i<e;i++){n+=Math.floor(Math.random()*t).toString(t)}return n}function Me(e){return $e[e]||""}function Pe(){return qe(10)}function Oe(e){for(var t={"Call-Id":"Call-ID",Cseq:"CSeq","Min-Se":"Min-SE",Rack:"RAck",Rseq:"RSeq","Www-Authenticate":"WWW-Authenticate"},n=e.toLowerCase().replace(/_/g,"-").split("-"),i=n.length,r="",s=0;s<i;s++)0!==s&&(r+="-"),r+=n[s].charAt(0).toUpperCase()+n[s].substring(1);return t[r]&&(r=t[r]),r}function Ne(e){return encodeURIComponent(e).replace(/%[A-F\d]{2}/g,"U").length}function je(e,t){var n=void 0!==H&&_(e)||e["@@iterator"];if(!n){if(w(e)||(n=function(e,t){if(e){var n;if("string"==typeof e)return Fe(e,t);var i=g(n={}.toString.call(e)).call(n,8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?D(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?Fe(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var i=0,r=function(){};return{s:r,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){o=!0,s=e},f:function(){try{a||null==n.return||n.return()}finally{if(o)throw s}}}}function Fe(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=Array(t);n<t;n++)i[n]=e[n];return i}var Ue=function(){return t(function t(){e(this,t),d(this,"viaBranch",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"method",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"toTag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"to",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"fromTag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"from",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"callId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"cseq",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"via",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"headers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),d(this,"referTo",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0})},[{key:"addHeader",value:function(e,t){var n={raw:t};e=Oe(e),this.headers[e]?this.headers[e].push(n):this.headers[e]=[n]}},{key:"getHeader",value:function(e){var t=this.headers[Oe(e)];if(t)return t[0]?t[0].raw:void 0}},{key:"getHeaders",value:function(e){var t=this.headers[Oe(e)],n=[];if(!t)return[];var i,r=je(t);try{for(r.s();!(i=r.n()).done;){var s=i.value;n.push(s.raw)}}catch(e){r.e(e)}finally{r.f()}return n}},{key:"hasHeader",value:function(e){return!!this.headers[Oe(e)]}},{key:"parseHeader",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(e=Oe(e),this.headers[e]&&!(t>=this.headers[e].length)){var n=this.headers[e][t],i=n.raw;if(n.parsed)return n.parsed;var r,s=He.parse(i,e.replace(/-/g,"_"));return-1===s?void I(r=this.headers[e]).call(r,t,1):(n.parsed=s,s)}}},{key:"s",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return this.parseHeader(e,t)}},{key:"setHeader",value:function(e,t){this.headers[Oe(e)]=[{raw:t}]}},{key:"toString",value:function(){return this.data}}])}();function Be(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Be=function(){return!!e})()}var Le=function(){function n(){var t,i,r,c;return e(this,n),i=this,r=o(r=n),t=a(i,Be()?s(r,c||[],o(i).constructor):r.apply(i,c)),d(t,"ruri",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),t}return c(n,Ue),t(n)}();function Ge(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Ge=function(){return!!e})()}var Ve=function(){function n(){var t,i,r,c;return e(this,n),i=this,r=o(r=n),t=a(i,Ge()?s(r,c||[],o(i).constructor):r.apply(i,c)),d(t,"statusCode",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(t,"reasonPhrase",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),t}return c(n,Ue),t(n)}();function We(e,t){var n=void 0!==H&&_(e)||e["@@iterator"];if(!n){if(w(e)||(n=function(e,t){if(e){var n;if("string"==typeof e)return Ke(e,t);var i=g(n={}.toString.call(e)).call(n,8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?D(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?Ke(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var i=0,r=function(){};return{s:r,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){o=!0,s=e},f:function(){try{a||null==n.return||n.return()}finally{if(o)throw s}}}}function Ke(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=Array(t);n<t;n++)i[n]=e[n];return i}var Ye,ze,Ze=function(){return t(function t(n,i,r,s,a,o,c){if(e(this,t),d(this,"headers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),d(this,"method",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"ruri",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"from",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"fromTag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"fromURI",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"to",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"toTag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"toURI",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"branch",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"callId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"cseq",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"extraHeaders",{enumerable:!0,configurable:!0,writable:!0,value:[]}),d(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.options=t.getDefaultOptions(),a){var l,u;if(this.options=$($({},this.options),a),this.options.optionTags&&this.options.optionTags.length)this.options.optionTags=g(l=this.options.optionTags).call(l);if(this.options.routeSet&&this.options.routeSet.length)this.options.routeSet=g(u=this.options.routeSet).call(u)}o&&o.length&&(this.extraHeaders=g(o).call(o)),c&&(this.body={body:c.content,contentType:c.contentType}),this.method=n,this.ruri=i.clone(),this.fromURI=r.clone(),this.fromTag=this.options.fromTag?this.options.fromTag:Pe(),this.from=t.makeNameAddrHeader(this.fromURI,this.options.fromDisplayName,this.fromTag),this.toURI=s.clone(),this.toTag=this.options.toTag,this.to=t.makeNameAddrHeader(this.toURI,this.options.toDisplayName,this.toTag),this.callId=this.options.callId?this.options.callId:this.options.callIdPrefix+qe(15),this.cseq=this.options.cseq,this.setHeader("route",this.options.routeSet),this.setHeader("via",""),this.setHeader("to",this.to.toString()),this.setHeader("from",this.from.toString()),this.setHeader("cseq",this.cseq+" "+this.method),this.setHeader("call-id",this.callId),this.setHeader("max-forwards","70")},[{key:"getHeader",value:function(e){var t=this.headers[Oe(e)];if(t){if(t[0])return t[0]}else{var n,i=new RegExp("^\\s*"+e+"\\s*:","i"),r=We(this.extraHeaders);try{for(r.s();!(n=r.n()).done;){var s,a=n.value;if(i.test(a))return R(s=a.substring(q(a).call(a,":")+1)).call(s)}}catch(e){r.e(e)}finally{r.f()}}}},{key:"getHeaders",value:function(e){var t=[],n=this.headers[Oe(e)];if(n){var i,r=We(n);try{for(r.s();!(i=r.n()).done;){var s=i.value;t.push(s)}}catch(e){r.e(e)}finally{r.f()}}else{var a,o=new RegExp("^\\s*"+e+"\\s*:","i"),c=We(this.extraHeaders);try{for(c.s();!(a=c.n()).done;){var l,u=a.value;if(o.test(u))t.push(R(l=u.substring(q(u).call(u,":")+1)).call(l))}}catch(e){c.e(e)}finally{c.f()}}return t}},{key:"hasHeader",value:function(e){if(this.headers[Oe(e)])return!0;var t,n=new RegExp("^\\s*"+e+"\\s*:","i"),i=We(this.extraHeaders);try{for(i.s();!(t=i.n()).done;){var r=t.value;if(n.test(r))return!0}}catch(e){i.e(e)}finally{i.f()}return!1}},{key:"setHeader",value:function(e,t){this.headers[Oe(e)]=t instanceof Array?t:[t]}},{key:"setViaHeader",value:function(e,t){this.options.hackViaTcp&&(t="TCP");var n="SIP/2.0/"+t;n+=" "+this.options.viaHost+";branch="+e,this.options.forceRport&&(n+=";rport"),this.setHeader("via",n),this.branch=e}},{key:"toString",value:function(){var e="";for(var t in e+=this.method+" "+this.ruri.toRaw()+" SIP/2.0\r\n",this.headers)if(this.headers[t]){var n,i=We(this.headers[t]);try{for(i.s();!(n=i.n()).done;){e+=t+": "+n.value+"\r\n"}}catch(e){i.e(e)}finally{i.f()}}var r,s=We(this.extraHeaders);try{for(s.s();!(r=s.n()).done;){var a=r.value;e+=R(a).call(a)+"\r\n"}}catch(e){s.e(e)}finally{s.f()}return e+="Supported: "+this.options.optionTags.join(", ")+"\r\n",e+="User-Agent: "+this.options.userAgentString+"\r\n",this.body?"string"==typeof this.body?(e+="Content-Length: "+Ne(this.body)+"\r\n\r\n",e+=this.body):this.body.body&&this.body.contentType?(e+="Content-Type: "+this.body.contentType+"\r\n",e+="Content-Length: "+Ne(this.body.body)+"\r\n\r\n",e+=this.body.body):e+="Content-Length: 0\r\n\r\n":e+="Content-Length: 0\r\n\r\n",e}}],[{key:"getDefaultOptions",value:function(){return{callId:"",callIdPrefix:"",cseq:1,toDisplayName:"",toTag:"",fromDisplayName:"",fromTag:"",forceRport:!1,hackViaTcp:!1,optionTags:["outbound"],routeSet:[],userAgentString:"sip.js",viaHost:""}}},{key:"makeNameAddrHeader",value:function(e,t,n){var i={};return n&&(i.tag=n),new Se(e,t,i)}}])}();function Je(e){return"application/sdp"===e?"session":"render"}function Xe(e){var t="string"==typeof e?e:e.body,n="string"==typeof e?"application/sdp":e.contentType;return{contentDisposition:Je(n),contentType:n,content:t}}function Qe(e){return!(!e||"string"!=typeof e.content||"string"!=typeof e.contentType||void 0!==e.contentDisposition)||"string"==typeof e.contentDisposition}function et(e){var t,n,i;if(e instanceof Le&&e.body){var r=e.parseHeader("Content-Disposition");t=r?r.type:void 0,n=e.parseHeader("Content-Type"),i=e.body}if(e instanceof Ve&&e.body){var s=e.parseHeader("Content-Disposition");t=s?s.type:void 0,n=e.parseHeader("Content-Type"),i=e.body}if(e instanceof Ze&&e.body)if(t=e.getHeader("Content-Disposition"),n=e.getHeader("Content-Type"),"string"==typeof e.body){if(!n)throw new Error("Header content type header does not equal body content type.");i=e.body}else{if(n&&n!==e.body.contentType)throw new Error("Header content type header does not equal body content type.");n=e.body.contentType,i=e.body.body}if(Qe(e)&&(t=e.contentDisposition,n=e.contentType,i=e.content),i){if(n&&!t&&(t=Je(n)),!t)throw new Error("Content disposition undefined.");if(!n)throw new Error("Content type undefined.");return{contentDisposition:t,contentType:n,content:i}}}!function(e){e.Initial="Initial",e.Early="Early",e.AckWait="AckWait",e.Confirmed="Confirmed",e.Terminated="Terminated"}(Ye||(Ye={})),function(e){e.Initial="Initial",e.HaveLocalOffer="HaveLocalOffer",e.HaveRemoteOffer="HaveRemoteOffer",e.Stable="Stable",e.Closed="Closed"}(ze||(ze={}));var tt=500,nt=5e3,it={T1:tt,T2:4e3,T4:nt,TIMER_B:32e3,TIMER_D:0,TIMER_F:32e3,TIMER_H:32e3,TIMER_I:0,TIMER_J:0,TIMER_K:0,TIMER_L:32e3,TIMER_M:32e3,TIMER_N:32e3,PROVISIONAL_RESPONSE_INTERVAL:6e4};function rt(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(rt=function(){return!!e})()}var st,at=function(){function n(t){return e(this,n),i=this,c=[t||"Transaction state error."],r=o(r=n),a(i,rt()?s(r,c||[],o(i).constructor):r.apply(i,c));var i,r,c}return c(n,ae),t(n)}();!function(e){e.ACK="ACK",e.BYE="BYE",e.CANCEL="CANCEL",e.INFO="INFO",e.INVITE="INVITE",e.MESSAGE="MESSAGE",e.NOTIFY="NOTIFY",e.OPTIONS="OPTIONS",e.REGISTER="REGISTER",e.UPDATE="UPDATE",e.SUBSCRIBE="SUBSCRIBE",e.PUBLISH="PUBLISH",e.REFER="REFER",e.PRACK="PRACK"}(st||(st={}));var ot,ct=[st.ACK,st.BYE,st.CANCEL,st.INFO,st.INVITE,st.MESSAGE,st.NOTIFY,st.OPTIONS,st.PRACK,st.REFER,st.REGISTER,st.SUBSCRIBE],lt=function(){return t(function t(n){e(this,t),d(this,"incomingMessageRequest",{enumerable:!0,configurable:!0,writable:!0,value:n})},[{key:"request",get:function(){return this.incomingMessageRequest.message}},{key:"accept",value:function(e){return this.incomingMessageRequest.accept(e),i.resolve()}},{key:"reject",value:function(e){return this.incomingMessageRequest.reject(e),i.resolve()}}])}(),ut=function(){return t(function t(n){e(this,t),d(this,"incomingNotifyRequest",{enumerable:!0,configurable:!0,writable:!0,value:n})},[{key:"request",get:function(){return this.incomingNotifyRequest.message}},{key:"accept",value:function(e){return this.incomingNotifyRequest.accept(e),i.resolve()}},{key:"reject",value:function(e){return this.incomingNotifyRequest.reject(e),i.resolve()}}])}(),dt=function(){return t(function t(n,i){e(this,t),d(this,"incomingReferRequest",{enumerable:!0,configurable:!0,writable:!0,value:n}),d(this,"session",{enumerable:!0,configurable:!0,writable:!0,value:i}),d(this,"inviter",{enumerable:!0,configurable:!0,writable:!0,value:void 0})},[{key:"referTo",get:function(){var e=this.incomingReferRequest.message.parseHeader("refer-to");if(!(e instanceof Se))throw new Error("Failed to parse Refer-To header.");return e}},{key:"referredBy",get:function(){return this.incomingReferRequest.message.getHeader("referred-by")}},{key:"replaces",get:function(){var e=this.referTo.uri.getHeader("replaces");return e instanceof Array?e[0]:e}},{key:"request",get:function(){return this.incomingReferRequest.message}},{key:"accept",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:202};return this.incomingReferRequest.accept(e),i.resolve()}},{key:"reject",value:function(e){return this.incomingReferRequest.reject(e),i.resolve()}},{key:"makeInviter",value:function(e){var t;if(this.inviter)return this.inviter;var n=this.referTo.uri.clone();n.clearHeaders();var i=g(t=(e=e||{}).extraHeaders||[]).call(t),r=this.replaces;r&&i.push("Replaces: "+decodeURIComponent(r));var s=this.referredBy;return s&&i.push("Referred-By: "+s),e.extraHeaders=i,this.inviter=this.session.userAgent._makeInviter(n,e),this.inviter._referred=this.session,this.session._referral=this.inviter,this.inviter}}])}();function ht(){var e=new Date,t=e.getFullYear(),n=e.getMonth()+1,i=e.getDate(),r=e.getHours(),s=e.getMinutes(),a=e.getSeconds();return t+"-"+gt(n)+"-"+gt(i)+" "+gt(r)+":"+gt(s)+":"+gt(a)}function gt(e){return e<10?"0"+e:e}!function(e){e.Initial="Initial",e.Establishing="Establishing",e.Established="Established",e.Terminating="Terminating",e.Terminated="Terminated"}(ot||(ot={}));var ft,vt=function(){function n(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,n),d(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_contact",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_referral",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_replacee",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_assertedIdentity",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_dialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_referralInviterOptions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_renderbody",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_rendertype",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"onNotify",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"pendingReinvite",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"pendingReinviteAck",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"_sessionDescriptionHandler",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_sessionDescriptionHandlerModifiers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_sessionDescriptionHandlerOptions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_sessionDescriptionHandlerModifiersReInvite",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_sessionDescriptionHandlerOptionsReInvite",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:ot.Initial}),d(this,"_stateEventEmitter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_userAgent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.delegate=i.delegate,this._stateEventEmitter=new we,this._userAgent=t}return t(n,[{key:"dispose",value:function(){var e,t=this;switch(this.logger.log(E(e="Session ".concat(this.id," in state ")).call(e,this._state," is being disposed")),delete this.userAgent._sessions[this.id],this._sessionDescriptionHandler&&this._sessionDescriptionHandler.close(),this.state){case ot.Initial:case ot.Establishing:break;case ot.Established:return new i(function(e){t._bye({onAccept:function(){return e()},onRedirect:function(){return e()},onReject:function(){return e()}})});case ot.Terminating:case ot.Terminated:break;default:throw new Error("Unknown state.")}return i.resolve()}},{key:"assertedIdentity",get:function(){return this._assertedIdentity}},{key:"dialog",get:function(){return this._dialog}},{key:"id",get:function(){return this._id}},{key:"replacee",get:function(){return this._replacee}},{key:"sessionDescriptionHandler",get:function(){return this._sessionDescriptionHandler}},{key:"sessionDescriptionHandlerFactory",get:function(){return this.userAgent.configuration.sessionDescriptionHandlerFactory}},{key:"sessionDescriptionHandlerModifiers",get:function(){return this._sessionDescriptionHandlerModifiers||[]},set:function(e){this._sessionDescriptionHandlerModifiers=g(e).call(e)}},{key:"sessionDescriptionHandlerOptions",get:function(){return this._sessionDescriptionHandlerOptions||{}},set:function(e){this._sessionDescriptionHandlerOptions=$({},e)}},{key:"sessionDescriptionHandlerModifiersReInvite",get:function(){return this._sessionDescriptionHandlerModifiersReInvite||[]},set:function(e){this._sessionDescriptionHandlerModifiersReInvite=g(e).call(e)}},{key:"sessionDescriptionHandlerOptionsReInvite",get:function(){return this._sessionDescriptionHandlerOptionsReInvite||{}},set:function(e){this._sessionDescriptionHandlerOptionsReInvite=$({},e)}},{key:"state",get:function(){return this._state}},{key:"stateChange",get:function(){return this._stateEventEmitter}},{key:"userAgent",get:function(){return this._userAgent}},{key:"bye",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t="Session.bye() may only be called if established session.";switch(this.state){case ot.Initial:"function"==typeof this.cancel?(t+=" However Inviter.invite() has not yet been called.",t+=" Perhaps you should have called Inviter.cancel()?"):"function"==typeof this.reject&&(t+=" However Invitation.accept() has not yet been called.",t+=" Perhaps you should have called Invitation.reject()?");break;case ot.Establishing:"function"==typeof this.cancel?(t+=" However a dialog does not yet exist.",t+=" Perhaps you should have called Inviter.cancel()?"):"function"==typeof this.reject&&(t+=" However Invitation.accept() has not yet been called (or not yet resolved).",t+=" Perhaps you should have called Invitation.reject()?");break;case ot.Established:var n=e.requestDelegate,r=this.copyRequestOptions(e.requestOptions);return this._bye(n,r);case ot.Terminating:t+=" However this session is already terminating.","function"==typeof this.cancel?t+=" Perhaps you have already called Inviter.cancel()?":"function"==typeof this.reject&&(t+=" Perhaps you have already called Session.bye()?");break;case ot.Terminated:t+=" However this session is already terminated.";break;default:throw new Error("Unknown state")}return this.logger.error(t),i.reject(new Error("Invalid session state ".concat(this.state)))}},{key:"info",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.state!==ot.Established){return this.logger.error("Session.info() may only be called if established session."),i.reject(new Error("Invalid session state ".concat(this.state)))}var t=e.requestDelegate,n=this.copyRequestOptions(e.requestOptions);return this._info(t,n)}},{key:"invite",value:function(){var e,t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("Session.invite"),this.state!==ot.Established)return i.reject(new Error("Invalid session state ".concat(this.state)));if(this.pendingReinvite)return i.reject(new ue("Reinvite in progress. Please wait until complete, then try again."));this.pendingReinvite=!0,n.sessionDescriptionHandlerModifiers&&(this.sessionDescriptionHandlerModifiersReInvite=n.sessionDescriptionHandlerModifiers),n.sessionDescriptionHandlerOptions&&(this.sessionDescriptionHandlerOptionsReInvite=n.sessionDescriptionHandlerOptions);var r={onAccept:function(e){var i=et(e.message);if(!i)return t.logger.error("Received 2xx response to re-INVITE without a session description"),t.ackAndBye(e,400,"Missing session description"),t.stateTransition(ot.Terminated),void(t.pendingReinvite=!1);if(n.withoutSdp){var r={sessionDescriptionHandlerOptions:t.sessionDescriptionHandlerOptionsReInvite,sessionDescriptionHandlerModifiers:t.sessionDescriptionHandlerModifiersReInvite};t.setOfferAndGetAnswer(i,r).then(function(t){e.ack({body:t})}).catch(function(n){t.logger.error("Failed to handle offer in 2xx response to re-INVITE"),t.logger.error(n.message),t.state===ot.Terminated?e.ack():(t.ackAndBye(e,488,"Bad Media Description"),t.stateTransition(ot.Terminated))}).then(function(){t.pendingReinvite=!1,n.requestDelegate&&n.requestDelegate.onAccept&&n.requestDelegate.onAccept(e)})}else{var s={sessionDescriptionHandlerOptions:t.sessionDescriptionHandlerOptionsReInvite,sessionDescriptionHandlerModifiers:t.sessionDescriptionHandlerModifiersReInvite};t.setAnswer(i,s).then(function(){e.ack()}).catch(function(n){t.logger.error("Failed to handle answer in 2xx response to re-INVITE"),t.logger.error(n.message),t.state!==ot.Terminated?(t.ackAndBye(e,488,"Bad Media Description"),t.stateTransition(ot.Terminated)):e.ack()}).then(function(){t.pendingReinvite=!1,n.requestDelegate&&n.requestDelegate.onAccept&&n.requestDelegate.onAccept(e)})}},onProgress:function(e){},onRedirect:function(e){},onReject:function(e){t.logger.warn("Received a non-2xx response to re-INVITE"),t.pendingReinvite=!1,n.withoutSdp?n.requestDelegate&&n.requestDelegate.onReject&&n.requestDelegate.onReject(e):t.rollbackOffer().catch(function(e){if(t.logger.error("Failed to rollback offer on non-2xx response to re-INVITE"),t.logger.error(e.message),t.state!==ot.Terminated){if(!t.dialog)throw new Error("Dialog undefined.");var n=[];n.push("Reason: "+t.getReasonHeaderValue(500,"Internal Server Error")),t.dialog.bye(void 0,{extraHeaders:n}),t.stateTransition(ot.Terminated)}}).then(function(){n.requestDelegate&&n.requestDelegate.onReject&&n.requestDelegate.onReject(e)})},onTrying:function(e){}},s=n.requestOptions||{};if(s.extraHeaders=g(e=s.extraHeaders||[]).call(e),s.extraHeaders.push("Allow: "+ct.toString()),s.extraHeaders.push("Contact: "+this._contact),n.withoutSdp){if(!this.dialog)throw this.pendingReinvite=!1,new Error("Dialog undefined.");return i.resolve(this.dialog.invite(r,s))}var a={sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptionsReInvite,sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiersReInvite};return this.getOffer(a).then(function(e){if(!t.dialog)throw t.pendingReinvite=!1,new Error("Dialog undefined.");return s.body=e,t.dialog.invite(r,s)}).catch(function(e){throw t.logger.error(e.message),t.logger.error("Failed to send re-INVITE"),t.pendingReinvite=!1,e})}},{key:"message",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.state!==ot.Established){return this.logger.error("Session.message() may only be called if established session."),i.reject(new Error("Invalid session state ".concat(this.state)))}var t=e.requestDelegate,n=this.copyRequestOptions(e.requestOptions);return this._message(t,n)}},{key:"refer",value:function(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.state!==ot.Established){return this.logger.error("Session.refer() may only be called if established session."),i.reject(new Error("Invalid session state ".concat(this.state)))}if(e instanceof n&&!e.dialog){return this.logger.error("Session.refer() may only be called with session which is established. You are perhaps attempting to attended transfer to a target for which there is not dialog yet established. Perhaps you are attempting a 'semi-attended' tansfer? Regardless, this is not supported. The recommended approached is to check to see if the target Session is in the Established state before calling refer(); if the state is not Established you may proceed by falling back using a URI as the target (blind transfer)."),i.reject(new Error("Invalid session state ".concat(this.state)))}var s=r.requestDelegate,a=this.copyRequestOptions(r.requestOptions);return a.extraHeaders=a.extraHeaders?E(t=a.extraHeaders).call(t,this.referExtraHeaders(this.referToString(e))):this.referExtraHeaders(this.referToString(e)),this._refer(r.onNotify,s,a)}},{key:"_bye",value:function(e,t){var n=this;if(!this.dialog)return i.reject(new Error("Session dialog undefined."));var r=this.dialog;switch(r.sessionState){case Ye.Initial:case Ye.Early:throw new Error("Invalid dialog state ".concat(r.sessionState));case Ye.AckWait:return this.stateTransition(ot.Terminating),new i(function(s){r.delegate={onAck:function(){var a=r.bye(e,t);return n.stateTransition(ot.Terminated),s(a),i.resolve()},onAckTimeout:function(){var i=r.bye(e,t);n.stateTransition(ot.Terminated),s(i)}}});case Ye.Confirmed:var s=r.bye(e,t);return this.stateTransition(ot.Terminated),i.resolve(s);case Ye.Terminated:throw new Error("Invalid dialog state ".concat(r.sessionState));default:throw new Error("Unrecognized state.")}}},{key:"_info",value:function(e,t){return this.dialog?i.resolve(this.dialog.info(e,t)):i.reject(new Error("Session dialog undefined."))}},{key:"_message",value:function(e,t){return this.dialog?i.resolve(this.dialog.message(e,t)):i.reject(new Error("Session dialog undefined."))}},{key:"_refer",value:function(e,t,n){return this.dialog?(this.onNotify=e,i.resolve(this.dialog.refer(t,n))):i.reject(new Error("Session dialog undefined."))}},{key:"ackAndBye",value:function(e,t,n){e.ack();var i=[];t&&i.push("Reason: "+this.getReasonHeaderValue(t,n)),e.session.bye(void 0,{extraHeaders:i})}},{key:"onAckRequest",value:function(e){var t=this;if(this.logger.log("Session.onAckRequest"),this.state!==ot.Established&&this.state!==ot.Terminating)return this.logger.error("ACK received while in state ".concat(this.state,", dropping request")),i.resolve();var n=this.dialog;if(!n)throw new Error("Dialog undefined.");var r={sessionDescriptionHandlerOptions:this.pendingReinviteAck?this.sessionDescriptionHandlerOptionsReInvite:this.sessionDescriptionHandlerOptions,sessionDescriptionHandlerModifiers:this.pendingReinviteAck?this._sessionDescriptionHandlerModifiersReInvite:this._sessionDescriptionHandlerModifiers};if(this.delegate&&this.delegate.onAck){var s=new me(e);this.delegate.onAck(s)}switch(this.pendingReinviteAck=!1,n.signalingState){case ze.Initial:this.logger.error("Invalid signaling state ".concat(n.signalingState,"."));var a=["Reason: "+this.getReasonHeaderValue(488,"Bad Media Description")];return n.bye(void 0,{extraHeaders:a}),this.stateTransition(ot.Terminated),i.resolve();case ze.Stable:var o=et(e.message);return o?"render"===o.contentDisposition?(this._renderbody=o.content,this._rendertype=o.contentType,i.resolve()):"session"!==o.contentDisposition?i.resolve():this.setAnswer(o,r).catch(function(e){t.logger.error(e.message);var i=["Reason: "+t.getReasonHeaderValue(488,"Bad Media Description")];n.bye(void 0,{extraHeaders:i}),t.stateTransition(ot.Terminated)}):i.resolve();case ze.HaveLocalOffer:this.logger.error("Invalid signaling state ".concat(n.signalingState,"."));var c=["Reason: "+this.getReasonHeaderValue(488,"Bad Media Description")];return n.bye(void 0,{extraHeaders:c}),this.stateTransition(ot.Terminated),i.resolve();case ze.HaveRemoteOffer:this.logger.error("Invalid signaling state ".concat(n.signalingState,"."));var l=["Reason: "+this.getReasonHeaderValue(488,"Bad Media Description")];return n.bye(void 0,{extraHeaders:l}),this.stateTransition(ot.Terminated),i.resolve();case ze.Closed:default:throw new Error("Invalid signaling state ".concat(n.signalingState,"."))}}},{key:"onByeRequest",value:function(e){if(this.logger.log("Session.onByeRequest"),this.state===ot.Established){if(this.delegate&&this.delegate.onBye){var t=new be(e);this.delegate.onBye(t)}else e.accept();this.stateTransition(ot.Terminated)}else this.logger.error("BYE received while in state ".concat(this.state,", dropping request"))}},{key:"onInfoRequest",value:function(e){if(this.logger.log("Session.onInfoRequest"),this.state===ot.Established)if(this.delegate&&this.delegate.onInfo){var t=new ke(e);this.delegate.onInfo(t)}else e.accept();else this.logger.error("INFO received while in state ".concat(this.state,", dropping request"))}},{key:"onInviteRequest",value:function(e){var t=this;if(this.logger.log("Session.onInviteRequest"),this.state===ot.Established){this.pendingReinviteAck=!0;var n=["Contact: "+this._contact];if(e.message.hasHeader("P-Asserted-Identity")){var i=e.message.getHeader("P-Asserted-Identity");if(!i)throw new Error("Header undefined.");this._assertedIdentity=He.nameAddrHeaderParse(i)}var r={sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptionsReInvite,sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiersReInvite};this.generateResponseOfferAnswerInDialog(r,e).then(function(i){var r=e.accept({statusCode:200,extraHeaders:n,body:i});t.delegate&&t.delegate.onInvite&&t.delegate.onInvite(e.message,r.message,200)}).catch(function(n){if(t.logger.error(n.message),t.logger.error("Failed to handle to re-INVITE request"),!t.dialog)throw new Error("Dialog undefined.");if(t.logger.error(t.dialog.signalingState),t.dialog.signalingState!==ze.Stable)t.rollbackOffer().then(function(){var n=e.reject({statusCode:488});t.delegate&&t.delegate.onInvite&&t.delegate.onInvite(e.message,n.message,488)}).catch(function(n){t.logger.error(n.message),t.logger.error("Failed to rollback offer on re-INVITE request");var i=e.reject({statusCode:488});if(t.state!==ot.Terminated){if(!t.dialog)throw new Error("Dialog undefined.");var r=[];r.push("Reason: "+t.getReasonHeaderValue(500,"Internal Server Error")),t.dialog.bye(void 0,{extraHeaders:r}),t.stateTransition(ot.Terminated)}t.delegate&&t.delegate.onInvite&&t.delegate.onInvite(e.message,i.message,488)});else{var i=e.reject({statusCode:488});t.delegate&&t.delegate.onInvite&&t.delegate.onInvite(e.message,i.message,488)}})}else this.logger.error("INVITE received while in state ".concat(this.state,", dropping request"))}},{key:"onMessageRequest",value:function(e){if(this.logger.log("Session.onMessageRequest"),this.state===ot.Established)if(this.delegate&&this.delegate.onMessage){var t=new lt(e);this.delegate.onMessage(t)}else e.accept();else this.logger.error("MESSAGE received while in state ".concat(this.state,", dropping request"))}},{key:"onNotifyRequest",value:function(e){if(this.logger.log("Session.onNotifyRequest"),this.state===ot.Established)if(this.onNotify){var t=new ut(e);this.onNotify(t)}else if(this.delegate&&this.delegate.onNotify){var n=new ut(e);this.delegate.onNotify(n)}else e.accept();else this.logger.error("NOTIFY received while in state ".concat(this.state,", dropping request"))}},{key:"onPrackRequest",value:function(e){if(this.logger.log("Session.onPrackRequest"),this.state===ot.Established)throw new Error("Unimplemented.");this.logger.error("PRACK received while in state ".concat(this.state,", dropping request"))}},{key:"onReferRequest",value:function(e){var t=this;if(this.logger.log("Session.onReferRequest"),this.state===ot.Established){if(!e.message.hasHeader("refer-to"))return this.logger.warn("Invalid REFER packet. A refer-to header is required. Rejecting."),void e.reject();var n=new dt(e,this);this.delegate&&this.delegate.onRefer?this.delegate.onRefer(n):(this.logger.log("No delegate available to handle REFER, automatically accepting and following."),n.accept().then(function(){return n.makeInviter(t._referralInviterOptions).invite()}).catch(function(e){t.logger.error(e.message)}))}else this.logger.error("REFER received while in state ".concat(this.state,", dropping request"))}},{key:"generateResponseOfferAnswer",value:function(e,t){var n=this;if(this.dialog)return this.generateResponseOfferAnswerInDialog(t,e).catch(function(t){var i;throw null===(i=n.userAgent.configuration)||void 0===i||i.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ht(),CALLID:e.message.callId,INVITE:e.message.toString(),ENTRY:"session: generateResponseOfferAnswer generateResponseOfferAnswerInDialog catch"}),t});var i=et(e.message);return i&&"session"===i.contentDisposition?this.setOfferAndGetAnswer(i,t,e).catch(function(t){var i;throw null===(i=n.userAgent.configuration)||void 0===i||i.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ht(),CALLID:e.message.callId,INVITE:e.message.toString(),ENTRY:"session: generateResponseOfferAnswer setOfferAndGetAnswer catch"}),t}):this.getOffer(t,e).catch(function(t){var i;throw null===(i=n.userAgent.configuration)||void 0===i||i.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ht(),CALLID:e.message.callId,INVITE:e.message.toString(),ENTRY:"session: generateResponseOfferAnswer getOffer catch"}),t})}},{key:"generateResponseOfferAnswerInDialog",value:function(e,t){var n=this;if(!this.dialog)throw new Error("Dialog undefined.");switch(this.dialog.signalingState){case ze.Initial:return this.getOffer(e,t).catch(function(e){var i;throw null===(i=n.userAgent.configuration)||void 0===i||i.errorCallback({ERR_MESSAGE:e.message,CODE:"480",TIMESTAMP:ht(),CALLID:(null==t?void 0:t.message.callId)||"",INVITE:(null==t?void 0:t.message.toString())||"",ENTRY:"session: generateResponseOfferAnswerInDialog SignalingState.Initial getOffer catch"}),e});case ze.HaveLocalOffer:return i.resolve(void 0);case ze.HaveRemoteOffer:if(!this.dialog.offer)throw new Error("Session offer undefined in signaling state ".concat(this.dialog.signalingState,"."));return this.setOfferAndGetAnswer(this.dialog.offer,e,t).catch(function(e){var i;throw null===(i=n.userAgent.configuration)||void 0===i||i.errorCallback({ERR_MESSAGE:e.message,CODE:"480",TIMESTAMP:ht(),CALLID:(null==t?void 0:t.message.callId)||"",INVITE:(null==t?void 0:t.message.toString())||"",ENTRY:"session: generateResponseOfferAnswerInDialog setOfferAndGetAnswer catch"}),e});case ze.Stable:return this.state!==ot.Established?i.resolve(void 0):this.getOffer(e,t).catch(function(e){var i;throw null===(i=n.userAgent.configuration)||void 0===i||i.errorCallback({ERR_MESSAGE:e.message,CODE:"480",TIMESTAMP:ht(),CALLID:(null==t?void 0:t.message.callId)||"",INVITE:(null==t?void 0:t.message.toString())||"",ENTRY:"session: generateResponseOfferAnswerInDialog SignalingState.Stable getOffer catch"}),e});case ze.Closed:default:throw new Error("Invalid signaling state ".concat(this.dialog.signalingState,"."))}}},{key:"getOffer",value:function(e,t){var n,r=this;try{var s=this.setupSessionDescriptionHandler(),a=e.sessionDescriptionHandlerOptions,o=e.sessionDescriptionHandlerModifiers;return s.getDescription(a,o).catch(function(e){var n;throw null===(n=r.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:e.message,CODE:"480",TIMESTAMP:ht(),CALLID:(null==t?void 0:t.message.callId)||"",INVITE:(null==t?void 0:t.message.toString())||"",ENTRY:"session: getOffer sdh.getDescription catch"}),e}).then(function(e){return Xe(e)}).catch(function(e){r.logger.error("Session.getOffer: SDH getDescription rejected...");var t=e instanceof Error?e:new Error("Session.getOffer unknown error.");throw r.logger.error(t.message),t})}catch(e){this.logger.error("Session.getOffer: SDH getDescription threw...");var c=e instanceof Error?e:new Error(e);return this.logger.error(c.message),null===(n=this.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:c.message,CODE:"480",TIMESTAMP:ht(),CALLID:(null==t?void 0:t.message.callId)||"",INVITE:(null==t?void 0:t.message.toString())||"",ENTRY:"session: getOffer setupSessionDescriptionHandler catch"}),i.reject(c)}}},{key:"rollbackOffer",value:function(){var e=this;try{var t=this.setupSessionDescriptionHandler();return void 0===t.rollbackDescription?i.resolve():t.rollbackDescription().catch(function(t){e.logger.error("Session.rollbackOffer: SDH rollbackDescription rejected...");var n=t instanceof Error?t:new Error("Session.rollbackOffer unknown error.");throw e.logger.error(n.message),n})}catch(e){this.logger.error("Session.rollbackOffer: SDH rollbackDescription threw...");var n=e instanceof Error?e:new Error(e);return this.logger.error(n.message),i.reject(n)}}},{key:"setAnswer",value:function(e,t){var n,r,s,a=this;try{if(n=this.setupSessionDescriptionHandler(),r=t.sessionDescriptionHandlerOptions,s=t.sessionDescriptionHandlerModifiers,!n.hasDescription(e.contentType))return i.reject(new ce)}catch(e){this.logger.error("Session.setAnswer: SDH hasDescription threw...");var o=e instanceof Error?e:new Error(e);return this.logger.error(o.message),i.reject(o)}try{return n.setDescription(e.content,r,s).catch(function(e){a.logger.error("Session.setAnswer: SDH setDescription rejected...");var t=e instanceof Error?e:new Error("Session.setAnswer unknown error.");throw a.logger.error(t.message),t})}catch(e){this.logger.error("Session.setAnswer: SDH setDescription threw...");var c=e instanceof Error?e:new Error(e);return this.logger.error(c.message),i.reject(c)}}},{key:"setOfferAndGetAnswer",value:function(e,t,n){var r,s,a,o,c=this;try{if(s=this.setupSessionDescriptionHandler(),a=t.sessionDescriptionHandlerOptions,o=t.sessionDescriptionHandlerModifiers,!s.hasDescription(e.contentType))return i.reject(new ce)}catch(e){this.logger.error("Session.setOfferAndGetAnswer: SDH hasDescription threw...");var l=e instanceof Error?e:new Error(e);return this.logger.error(l.message),null===(r=this.userAgent.configuration)||void 0===r||r.errorCallback({ERR_MESSAGE:l.message,CODE:"480",TIMESTAMP:ht(),CALLID:(null==n?void 0:n.message.callId)||"",INVITE:(null==n?void 0:n.message.toString())||"",ENTRY:"session: setOfferAndGetAnswer setupSessionDescriptionHandler catch"}),i.reject(l)}try{return s.setDescription(e.content,a,o).catch(function(e){var t;throw null===(t=c.userAgent.configuration)||void 0===t||t.errorCallback({ERR_MESSAGE:e.message,CODE:"480",TIMESTAMP:ht(),CALLID:(null==n?void 0:n.message.callId)||"",INVITE:(null==n?void 0:n.message.toString())||"",ENTRY:"session: setOfferAndGetAnswer sdh.setDescription catch"}),e}).then(function(){return s.getDescription(a,o)}).catch(function(e){var t;throw null===(t=c.userAgent.configuration)||void 0===t||t.errorCallback({ERR_MESSAGE:e.message,CODE:"480",TIMESTAMP:ht(),CALLID:(null==n?void 0:n.message.callId)||"",INVITE:(null==n?void 0:n.message.toString())||"",ENTRY:"session: setOfferAndGetAnswer sdh.getDescription catch"}),e}).then(function(e){return Xe(e)}).catch(function(e){c.logger.error("Session.setOfferAndGetAnswer: SDH setDescription or getDescription rejected...");var t=e instanceof Error?e:new Error("Session.setOfferAndGetAnswer unknown error.");throw c.logger.error(t.message),t})}catch(e){this.logger.error("Session.setOfferAndGetAnswer: SDH setDescription or getDescription threw...");var u=e instanceof Error?e:new Error(e);return this.logger.error(u.message),i.reject(u)}}},{key:"setSessionDescriptionHandler",value:function(e){if(this._sessionDescriptionHandler)throw new Error("Session description handler defined.");this._sessionDescriptionHandler=e}},{key:"setupSessionDescriptionHandler",value:function(){var e;return this._sessionDescriptionHandler||(this._sessionDescriptionHandler=this.sessionDescriptionHandlerFactory(this,this.userAgent.configuration.sessionDescriptionHandlerFactoryOptions),(null===(e=this.delegate)||void 0===e?void 0:e.onSessionDescriptionHandler)&&this.delegate.onSessionDescriptionHandler(this._sessionDescriptionHandler,!1)),this._sessionDescriptionHandler}},{key:"stateTransition",value:function(e){var t,n=this,i=function(){var t;throw new Error(E(t="Invalid state transition from ".concat(n._state," to ")).call(t,e))};switch(this._state){case ot.Initial:e!==ot.Establishing&&e!==ot.Established&&e!==ot.Terminating&&e!==ot.Terminated&&i();break;case ot.Establishing:e!==ot.Established&&e!==ot.Terminating&&e!==ot.Terminated&&i();break;case ot.Established:e!==ot.Terminating&&e!==ot.Terminated&&i();break;case ot.Terminating:e!==ot.Terminated&&i();break;case ot.Terminated:i();break;default:throw new Error("Unrecognized state.")}this._state=e,this.logger.log(E(t="Session ".concat(this.id," transitioned to state ")).call(t,this._state)),this._stateEventEmitter.emit(this._state),e===ot.Terminated&&this.dispose()}},{key:"copyRequestOptions",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{extraHeaders:t.extraHeaders?g(e=t.extraHeaders).call(e):void 0,body:t.body?{contentDisposition:t.body.contentDisposition||"render",contentType:t.body.contentType||"text/plain",content:t.body.content||""}:void 0}}},{key:"getReasonHeaderValue",value:function(e,t){var n=e,i=Me(e);return!i&&t&&(i=t),"SIP;cause="+n+';text="'+i+'"'}},{key:"referExtraHeaders",value:function(e){var t=[];return t.push("Referred-By: <"+this.userAgent.configuration.uri+">"),t.push("Contact: "+this._contact),t.push("Allow: "+["ACK","CANCEL","INVITE","MESSAGE","BYE","OPTIONS","INFO","NOTIFY","REFER"].toString()),t.push("Refer-To: "+e),t}},{key:"referToString",value:function(e){var t;if(e instanceof Ee)t=e.toString();else{var n,i,r,s;if(!e.dialog)throw new Error("Dialog undefined.");var a=e.remoteIdentity.friendlyName,o=e.dialog.remoteTarget.toString(),c=e.dialog.callId,l=e.dialog.remoteTag,u=e.dialog.localTag,d=encodeURIComponent(E(n=E(i="".concat(c,";to-tag=")).call(i,l,";from-tag=")).call(n,u));t=E(r=E(s='"'.concat(a,'" <')).call(s,o,"?Replaces=")).call(r,d,">")}return t}}])}();!function(e){e.Required="Required",e.Supported="Supported",e.Unsupported="Unsupported"}(ft||(ft={}));var pt={"100rel":!0,199:!0,answermode:!0,"early-session":!0,eventlist:!0,explicitsub:!0,"from-change":!0,"geolocation-http":!0,"geolocation-sip":!0,gin:!0,gruu:!0,histinfo:!0,ice:!0,join:!0,"multiple-refer":!0,norefersub:!0,nosub:!0,outbound:!0,path:!0,policy:!0,precondition:!0,pref:!0,privacy:!0,"recipient-list-invite":!0,"recipient-list-message":!0,"recipient-list-subscribe":!0,replaces:!0,"resource-priority":!0,"sdp-anat":!0,"sec-agree":!0,tdialog:!0,timer:!0,uui:!0};function mt(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(mt=function(){return!!e})()}function bt(e,t,n,i){var r=v(o(1&i?e.prototype:e),t,n);return 2&i&&"function"==typeof r?function(e){return r.apply(n,e)}:r}var yt=function(){function n(t,i){var r,c,l,u,h,g;e(this,n),u=this,g=[t],h=o(h=n),l=a(u,mt()?s(h,g||[],o(u).constructor):h.apply(u,g)),d(l,"incomingInviteRequest",{enumerable:!0,configurable:!0,writable:!0,value:i}),d(l,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"_id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"disposed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(l,"expiresTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"isCanceled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(l,"rel100",{enumerable:!0,configurable:!0,writable:!0,value:"none"}),d(l,"rseq",{enumerable:!0,configurable:!0,writable:!0,value:Math.floor(1e4*Math.random())}),d(l,"userNoAnswerTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"waitingForPrack",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(l,"waitingForPrackPromise",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"waitingForPrackResolve",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"waitingForPrackReject",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),l.logger=t.getLogger("sip.Invitation");var f=l.incomingInviteRequest.message,v=f.getHeader("require");v&&p(r=v.toLowerCase()).call(r,"100rel")&&(l.rel100="required");var b=f.getHeader("supported");if(b&&p(c=b.toLowerCase()).call(c,"100rel")&&(l.rel100="supported"),f.toTag=i.toTag,"string"!=typeof f.toTag)throw new TypeError("toTag should have been a string.");if(l.userNoAnswerTimer=m(function(){var e;null===(e=l.userAgent.configuration)||void 0===e||e.errorCallback({ERR_MESSAGE:"NOT ERROR",CODE:"480",TIMESTAMP:ht(),CALLID:l.incomingInviteRequest.message.callId,INVITE:l.incomingInviteRequest.message.toString(),ENTRY:"invitation: constructor userNoAnswerTimer ".concat(l.userAgent.configuration.noAnswerTimeout?1e3*l.userAgent.configuration.noAnswerTimeout:6e4)}),i.reject({statusCode:480}),l.stateTransition(ot.Terminated)},l.userAgent.configuration.noAnswerTimeout?1e3*l.userAgent.configuration.noAnswerTimeout:6e4),f.hasHeader("expires")){var y=1e3*Number(f.getHeader("expires")||0);l.expiresTimer=m(function(){l.state===ot.Initial&&(i.reject({statusCode:487}),l.stateTransition(ot.Terminated))},y)}var w=l.request.getHeader("P-Asserted-Identity");w&&(l._assertedIdentity=He.nameAddrHeaderParse(w)),l._contact=l.userAgent.contact.toString();var k=f.parseHeader("Content-Disposition");return k&&"render"===k.type&&(l._renderbody=f.body,l._rendertype=f.getHeader("Content-Type")),l._id=f.callId+f.fromTag,l.userAgent._sessions[l._id]=l,l}return c(n,vt),t(n,[{key:"dispose",value:function(){var e=this;if(this.disposed)return i.resolve();switch(this.disposed=!0,this.expiresTimer&&(clearTimeout(this.expiresTimer),this.expiresTimer=void 0),this.userNoAnswerTimer&&(clearTimeout(this.userNoAnswerTimer),this.userNoAnswerTimer=void 0),this.prackNeverArrived(),this.state){case ot.Initial:case ot.Establishing:return this.reject().then(function(){return bt(n,"dispose",e,3)([])});case ot.Established:case ot.Terminating:case ot.Terminated:return bt(n,"dispose",this,3)([]);default:throw new Error("Unknown state.")}}},{key:"autoSendAnInitialProvisionalResponse",get:function(){return"required"!==this.rel100&&this.userAgent.configuration.sendInitialProvisionalResponse}},{key:"body",get:function(){return this.incomingInviteRequest.message.body}},{key:"localIdentity",get:function(){return this.request.to}},{key:"remoteIdentity",get:function(){return this.request.from}},{key:"request",get:function(){return this.incomingInviteRequest.message}},{key:"accept",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("Invitation.accept"),this.state!==ot.Initial){var n=new Error("Invalid session state ".concat(this.state));return this.logger.error(n.message),i.reject(n)}return t.sessionDescriptionHandlerModifiers&&(this.sessionDescriptionHandlerModifiers=t.sessionDescriptionHandlerModifiers),t.sessionDescriptionHandlerOptions&&(this.sessionDescriptionHandlerOptions=t.sessionDescriptionHandlerOptions),this.stateTransition(ot.Establishing),this.sendAccept(t).then(function(n){n.message;var i=n.session;i.delegate={onAck:function(n){var i=e.onAckRequest(n);return t.onAck&&t.onAck(n),i},onAckTimeout:function(){e.onAckTimeout(),t.onAckTimeout&&t.onAckTimeout()},onBye:function(t){return e.onByeRequest(t)},onInfo:function(t){return e.onInfoRequest(t)},onInvite:function(t){return e.onInviteRequest(t)},onMessage:function(t){return e.onMessageRequest(t)},onNotify:function(t){return e.onNotifyRequest(t)},onPrack:function(t){return e.onPrackRequest(t)},onRefer:function(t){return e.onReferRequest(t)}},e._dialog=i,e.stateTransition(ot.Established),e._replacee&&e._replacee._bye()}).catch(function(t){var n;return null===(n=e.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ht(),CALLID:e.incomingInviteRequest.message.callId,INVITE:e.incomingInviteRequest.message.toString(),ENTRY:"invitation: accept sendAccept catch"}),e.handleResponseError(t)})}},{key:"progress",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("Invitation.progress"),this.state!==ot.Initial){var n=new Error("Invalid session state ".concat(this.state));return this.logger.error(n.message),i.reject(n)}var r=t.statusCode||180;if(r<100||r>199)throw new TypeError("Invalid statusCode: "+r);return t.sessionDescriptionHandlerModifiers&&(this.sessionDescriptionHandlerModifiers=t.sessionDescriptionHandlerModifiers),t.sessionDescriptionHandlerOptions&&(this.sessionDescriptionHandlerOptions=t.sessionDescriptionHandlerOptions),this.waitingForPrack?(this.logger.warn("Unexpected call for progress while waiting for prack, ignoring"),i.resolve()):100===t.statusCode?this.sendProgressTrying().then(function(){}).catch(function(t){var n;return null===(n=e.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ht(),CALLID:e.incomingInviteRequest.message.callId,INVITE:e.incomingInviteRequest.message.toString(),ENTRY:"invitation: progress sendProgressTrying catch"}),e.handleResponseError(t)}):"required"===this.rel100||"supported"===this.rel100&&t.rel100||"supported"===this.rel100&&this.userAgent.configuration.sipExtension100rel===ft.Required?this.sendProgressReliableWaitForPrack(t).then(function(){}).catch(function(t){var n;return null===(n=e.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ht(),CALLID:e.incomingInviteRequest.message.callId,INVITE:e.incomingInviteRequest.message.toString(),ENTRY:"invitation: progress sendProgressReliableWaitForPrack catch"}),e.handleResponseError(t)}):this.sendProgress(t).then(function(){}).catch(function(t){var n;return null===(n=e.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ht(),CALLID:e.incomingInviteRequest.message.callId,INVITE:e.incomingInviteRequest.message.toString(),ENTRY:"invitation: progress rel100 sendProgress catch"}),e.handleResponseError(t)})}},{key:"reject",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("Invitation.reject"),this.state!==ot.Initial&&this.state!==ot.Establishing){var t=new Error("Invalid session state ".concat(this.state));return this.logger.error(t.message),i.reject(t)}var n=e.statusCode||480,r=e.reasonPhrase?e.reasonPhrase:Me(n),s=e.extraHeaders||[];if(n<300||n>699)throw new TypeError("Invalid statusCode: "+n);var a=e.body?Xe(e.body):void 0;return n<400?this.incomingInviteRequest.redirect([],{statusCode:n,reasonPhrase:r,extraHeaders:s,body:a}):this.incomingInviteRequest.reject({statusCode:n,reasonPhrase:r,extraHeaders:s,body:a}),this.stateTransition(ot.Terminated),i.resolve()}},{key:"_onCancel",value:function(e){if(this.logger.log("Invitation._onCancel"),this.state===ot.Initial||this.state===ot.Establishing){if(this.delegate&&this.delegate.onCancel){var t=new ye(e);this.delegate.onCancel(t)}this.isCanceled=!0,this.incomingInviteRequest.reject({statusCode:487}),this.stateTransition(ot.Terminated)}else this.logger.error("CANCEL received while in state ".concat(this.state,", dropping request"))}},{key:"handlePrackOfferAnswer",value:function(e){if(!this.dialog)throw new Error("Dialog undefined.");var t=et(e.message);if(!t||"session"!==t.contentDisposition)return i.resolve(void 0);var n={sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions,sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers};switch(this.dialog.signalingState){case ze.Initial:throw new Error("Invalid signaling state ".concat(this.dialog.signalingState,"."));case ze.Stable:return this.setAnswer(t,n).then(function(){});case ze.HaveLocalOffer:throw new Error("Invalid signaling state ".concat(this.dialog.signalingState,"."));case ze.HaveRemoteOffer:return this.setOfferAndGetAnswer(t,n);case ze.Closed:default:throw new Error("Invalid signaling state ".concat(this.dialog.signalingState,"."))}}},{key:"handleResponseError",value:function(e){var t=480;if(e instanceof Error?this.logger.error(e.message):this.logger.error(e),e instanceof ce?(this.logger.error("A session description handler occurred while sending response (content type unsupported"),t=415):e instanceof he?this.logger.error("A session description handler occurred while sending response"):e instanceof fe?this.logger.error("Session ended before response could be formulated and sent (while waiting for PRACK)"):e instanceof at&&this.logger.error("Session changed state before response could be formulated and sent"),this.state===ot.Initial||this.state===ot.Establishing)try{this.incomingInviteRequest.reject({statusCode:t}),this.stateTransition(ot.Terminated)}catch(e){throw this.logger.error("An error occurred attempting to reject the request while handling another error"),e}if(!this.isCanceled)throw e;this.logger.warn("An error occurred while attempting to formulate and send a response to an incoming INVITE. However a CANCEL was received and processed while doing so which can (and often does) result in errors occurring as the session terminates in the meantime. Said error is being ignored.")}},{key:"onAckTimeout",value:function(){if(this.logger.log("Invitation.onAckTimeout"),!this.dialog)throw new Error("Dialog undefined.");this.logger.log("No ACK received for an extended period of time, terminating session"),this.dialog.bye(),this.stateTransition(ot.Terminated)}},{key:"sendAccept",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n={sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions,sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers},i=t.extraHeaders||[];return this.waitingForPrack?this.waitForArrivalOfPrack().then(function(){return clearTimeout(e.userNoAnswerTimer)}).then(function(){return e.generateResponseOfferAnswer(e.incomingInviteRequest,n)}).catch(function(t){var n;throw null===(n=e.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ht(),CALLID:e.incomingInviteRequest.message.callId,INVITE:e.incomingInviteRequest.message.toString(),ENTRY:"invitation: sendAccept waitForArrivalOfPrack generateResponseOfferAnswer catch"}),t}).then(function(t){return e.incomingInviteRequest.accept({statusCode:200,body:t,extraHeaders:i})}):(clearTimeout(this.userNoAnswerTimer),this.generateResponseOfferAnswer(this.incomingInviteRequest,n).catch(function(t){var n;throw null===(n=e.userAgent.configuration)||void 0===n||n.errorCallback({ERR_MESSAGE:t.message,CODE:"480",TIMESTAMP:ht(),CALLID:e.incomingInviteRequest.message.callId,INVITE:e.incomingInviteRequest.message.toString(),ENTRY:"invitation: sendAccept generateResponseOfferAnswer catch"}),t}).then(function(t){return e.incomingInviteRequest.accept({statusCode:200,body:t,extraHeaders:i})}))}},{key:"sendProgress",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.statusCode||180,r=t.reasonPhrase,s=g(e=t.extraHeaders||[]).call(e),a=t.body?Xe(t.body):void 0;if(183===n&&!a)return this.sendProgressWithSDP(t);try{var o=this.incomingInviteRequest.progress({statusCode:n,reasonPhrase:r,extraHeaders:s,body:a});return this._dialog=o.session,i.resolve(o)}catch(e){return i.reject(e)}}},{key:"sendProgressWithSDP",value:function(){var e,t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i={sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions,sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers},r=n.statusCode||183,s=n.reasonPhrase,a=g(e=n.extraHeaders||[]).call(e);return this.generateResponseOfferAnswer(this.incomingInviteRequest,i).then(function(e){return t.incomingInviteRequest.progress({statusCode:r,reasonPhrase:s,extraHeaders:a,body:e})}).then(function(e){return t._dialog=e.session,e})}},{key:"sendProgressReliable",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return t.extraHeaders=g(e=t.extraHeaders||[]).call(e),t.extraHeaders.push("Require: 100rel"),t.extraHeaders.push("RSeq: "+Math.floor(1e4*Math.random())),this.sendProgressWithSDP(t)}},{key:"sendProgressReliableWaitForPrack",value:function(){var e,t,n=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},s={sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions,sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers},a=r.statusCode||183,o=r.reasonPhrase,c=g(e=r.extraHeaders||[]).call(e);return c.push("Require: 100rel"),c.push("RSeq: "+this.rseq++),new i(function(e,i){n.waitingForPrack=!0,n.generateResponseOfferAnswer(n.incomingInviteRequest,s).then(function(e){return t=e,n.incomingInviteRequest.progress({statusCode:a,reasonPhrase:o,extraHeaders:c,body:t})}).then(function(r){var s,l;n._dialog=r.session,r.session.delegate={onPrack:function(t){s=t,clearTimeout(u),clearTimeout(g),n.waitingForPrack&&(n.waitingForPrack=!1,n.handlePrackOfferAnswer(s).then(function(t){try{l=s.accept({statusCode:200,body:t}),n.prackArrived(),e({prackRequest:s,prackResponse:l,progressResponse:r})}catch(e){i(e)}}).catch(function(e){return i(e)}))}};var u=m(function(){n.waitingForPrack&&(n.waitingForPrack=!1,n.logger.warn("No PRACK received, rejecting INVITE."),clearTimeout(g),n.reject({statusCode:504}).then(function(){return i(new fe)}).catch(function(e){return i(e)}))},64*it.T1),d=function(){try{n.incomingInviteRequest.progress({statusCode:a,reasonPhrase:o,extraHeaders:c,body:t})}catch(e){return n.waitingForPrack=!1,void i(e)}g=m(d,h*=2)},h=it.T1,g=m(d,h)}).catch(function(e){n.waitingForPrack=!1,i(e)})})}},{key:"sendProgressTrying",value:function(){try{var e=this.incomingInviteRequest.trying();return i.resolve(e)}catch(e){return i.reject(e)}}},{key:"waitForArrivalOfPrack",value:function(){var e=this;if(this.waitingForPrackPromise)throw new Error("Already waiting for PRACK");return this.waitingForPrackPromise=new i(function(t,n){e.waitingForPrackResolve=t,e.waitingForPrackReject=n}),this.waitingForPrackPromise}},{key:"prackArrived",value:function(){this.waitingForPrackResolve&&this.waitingForPrackResolve(),this.waitingForPrackPromise=void 0,this.waitingForPrackResolve=void 0,this.waitingForPrackReject=void 0}},{key:"prackNeverArrived",value:function(){this.waitingForPrackReject&&this.waitingForPrackReject(new fe),this.waitingForPrackPromise=void 0,this.waitingForPrackResolve=void 0,this.waitingForPrackReject=void 0}}])}();function wt(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(wt=function(){return!!e})()}function kt(e,t,n,i){var r=v(o(1&i?e.prototype:e),t,n);return 2&i&&"function"==typeof r?function(e){return r.apply(n,e)}:r}var Tt,Rt,St=function(){function n(t,i){var r,c,l,u,h,f=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};e(this,n),l=this,h=[t,f],u=o(u=n),c=a(l,wt()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"_referred",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"_id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"disposed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(c,"earlyMedia",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(c,"earlyMediaDialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"earlyMediaSessionDescriptionHandlers",{enumerable:!0,configurable:!0,writable:!0,value:new M}),d(c,"fromTag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"isCanceled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(c,"inviteWithoutSdp",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(c,"outgoingInviteRequest",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"outgoingRequestMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c.logger=t.getLogger("sip.Inviter"),c.earlyMedia=void 0!==f.earlyMedia?f.earlyMedia:c.earlyMedia,c.fromTag=Pe(),c.inviteWithoutSdp=void 0!==f.inviteWithoutSdp?f.inviteWithoutSdp:c.inviteWithoutSdp;var v=$({},f);v.params=$({},f.params);var p=f.anonymous||!1,m=t.contact.toString({anonymous:p,outbound:p?!t.contact.tempGruu:!t.contact.pubGruu});p&&t.configuration.uri&&(v.params.fromDisplayName="Anonymous",v.params.fromUri="sip:anonymous@anonymous.invalid");var b=t.userAgentCore.configuration.aor;if(v.params.fromUri&&(b="string"==typeof v.params.fromUri?He.URIParse(v.params.fromUri):v.params.fromUri),!b)throw new TypeError("Invalid from URI: "+v.params.fromUri);var y=i;if(v.params.toUri&&(y="string"==typeof v.params.toUri?He.URIParse(v.params.toUri):v.params.toUri),!y)throw new TypeError("Invalid to URI: "+v.params.toUri);var w=$({},v.params);w.fromTag=c.fromTag;var k=g(r=v.extraHeaders||[]).call(r);p&&t.configuration.uri&&(k.push("P-Preferred-Identity: "+t.configuration.uri.toString()),k.push("Privacy: id")),k.push("Contact: "+m),k.push("Allow: "+["ACK","CANCEL","INVITE","MESSAGE","BYE","OPTIONS","INFO","NOTIFY","REFER"].toString()),t.configuration.sipExtension100rel===ft.Required&&k.push("Require: 100rel"),t.configuration.sipExtensionReplaces===ft.Required&&k.push("Require: replaces"),v.extraHeaders=k;return c.outgoingRequestMessage=t.userAgentCore.makeOutgoingRequestMessage(st.INVITE,i,b,y,w,k,undefined),c._contact=m,c._referralInviterOptions=v,c._renderbody=f.renderbody,c._rendertype=f.rendertype,f.sessionDescriptionHandlerModifiers&&(c.sessionDescriptionHandlerModifiers=f.sessionDescriptionHandlerModifiers),f.sessionDescriptionHandlerOptions&&(c.sessionDescriptionHandlerOptions=f.sessionDescriptionHandlerOptions),f.sessionDescriptionHandlerModifiersReInvite&&(c.sessionDescriptionHandlerModifiersReInvite=f.sessionDescriptionHandlerModifiersReInvite),f.sessionDescriptionHandlerOptionsReInvite&&(c.sessionDescriptionHandlerOptionsReInvite=f.sessionDescriptionHandlerOptionsReInvite),c._id=c.outgoingRequestMessage.callId+c.fromTag,c.userAgent._sessions[c._id]=c,c}return c(n,vt),t(n,[{key:"dispose",value:function(){var e=this;if(this.disposed)return i.resolve();switch(this.disposed=!0,this.disposeEarlyMedia(),this.state){case ot.Initial:case ot.Establishing:return this.cancel().then(function(){return kt(n,"dispose",e,3)([])});case ot.Established:case ot.Terminating:case ot.Terminated:return kt(n,"dispose",this,3)([]);default:throw new Error("Unknown state.")}}},{key:"body",get:function(){return this.outgoingRequestMessage.body}},{key:"localIdentity",get:function(){return this.outgoingRequestMessage.from}},{key:"remoteIdentity",get:function(){return this.outgoingRequestMessage.to}},{key:"request",get:function(){return this.outgoingRequestMessage}},{key:"cancel",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("Inviter.cancel"),this.state!==ot.Initial&&this.state!==ot.Establishing){var n=new Error("Invalid session state ".concat(this.state));return this.logger.error(n.message),i.reject(n)}(this.isCanceled=!0,this.stateTransition(ot.Terminating),this.outgoingInviteRequest)?(t.statusCode&&t.reasonPhrase&&(e=function(e,t){if(e&&e<200||e>699)throw new TypeError("Invalid statusCode: "+e);if(e)return"SIP;cause="+e+';text="'+(Me(e)||t)+'"'}(t.statusCode,t.reasonPhrase)),this.outgoingInviteRequest.cancel(e,t)):(this.logger.warn("Canceled session before INVITE was sent"),this.stateTransition(ot.Terminated));return i.resolve()}},{key:"invite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("Inviter.invite"),this.state!==ot.Initial)return kt(n,"invite",this,3)([t]);if(t.sessionDescriptionHandlerModifiers&&(this.sessionDescriptionHandlerModifiers=t.sessionDescriptionHandlerModifiers),t.sessionDescriptionHandlerOptions&&(this.sessionDescriptionHandlerOptions=t.sessionDescriptionHandlerOptions),t.withoutSdp||this.inviteWithoutSdp)return this._renderbody&&this._rendertype&&(this.outgoingRequestMessage.body={contentType:this._rendertype,body:this._renderbody}),this.stateTransition(ot.Establishing),i.resolve(this.sendInvite(t));var r={sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers,sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions};return this.getOffer(r).then(function(n){return e.outgoingRequestMessage.body={body:n.content,contentType:n.contentType},e.stateTransition(ot.Establishing),e.sendInvite(t)}).catch(function(t){throw e.logger.log(t.message),e.state!==ot.Terminated&&e.stateTransition(ot.Terminated),t})}},{key:"sendInvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.outgoingInviteRequest=this.userAgent.userAgentCore.invite(this.outgoingRequestMessage,{onAccept:function(n){return e.dialog?(e.logger.log("Additional confirmed dialog, sending ACK and BYE"),void e.ackAndBye(n)):e.isCanceled?(e.logger.log("Canceled session accepted, sending ACK and BYE"),e.ackAndBye(n),void e.stateTransition(ot.Terminated)):(e.notifyReferer(n),void e.onAccept(n).then(function(){e.disposeEarlyMedia()}).catch(function(){e.disposeEarlyMedia()}).then(function(){t.requestDelegate&&t.requestDelegate.onAccept&&t.requestDelegate.onAccept(n)}))},onProgress:function(n){e.isCanceled||(e.notifyReferer(n),e.onProgress(n).catch(function(){e.disposeEarlyMedia()}).then(function(){t.requestDelegate&&t.requestDelegate.onProgress&&t.requestDelegate.onProgress(n)}))},onRedirect:function(n){e.notifyReferer(n),e.onRedirect(n),t.requestDelegate&&t.requestDelegate.onRedirect&&t.requestDelegate.onRedirect(n)},onReject:function(n){e.notifyReferer(n),e.onReject(n),t.requestDelegate&&t.requestDelegate.onReject&&t.requestDelegate.onReject(n)},onTrying:function(n){e.notifyReferer(n),e.onTrying(n),t.requestDelegate&&t.requestDelegate.onTrying&&t.requestDelegate.onTrying(n)}}),this.outgoingInviteRequest}},{key:"disposeEarlyMedia",value:function(){var e;h(e=this.earlyMediaSessionDescriptionHandlers).call(e,function(e){e.close()}),this.earlyMediaSessionDescriptionHandlers.clear()}},{key:"notifyReferer",value:function(e){var t,n,i=this;if(this._referred){if(!(this._referred instanceof vt))throw new Error("Referred session not instance of session");if(this._referred.dialog){if(!e.message.statusCode)throw new Error("Status code undefined.");if(!e.message.reasonPhrase)throw new Error("Reason phrase undefined.");var r=e.message.statusCode,s=e.message.reasonPhrase,a=R(t=E(n="SIP/2.0 ".concat(r," ")).call(n,s)).call(t);this._referred.dialog.notify(void 0,{extraHeaders:["Event: refer","Subscription-State: terminated"],body:{contentDisposition:"render",contentType:"message/sipfrag",content:a}}).delegate={onReject:function(){i._referred=void 0}}}}}},{key:"onAccept",value:function(e){var t=this;if(this.logger.log("Inviter.onAccept"),this.state!==ot.Establishing)return this.logger.error("Accept received while in state ".concat(this.state,", dropping response")),i.reject(new Error("Invalid session state ".concat(this.state)));var n=e.message,r=e.session;switch(n.hasHeader("P-Asserted-Identity")&&(this._assertedIdentity=He.nameAddrHeaderParse(n.getHeader("P-Asserted-Identity"))),r.delegate={onAck:function(e){return t.onAckRequest(e)},onBye:function(e){return t.onByeRequest(e)},onInfo:function(e){return t.onInfoRequest(e)},onInvite:function(e){return t.onInviteRequest(e)},onMessage:function(e){return t.onMessageRequest(e)},onNotify:function(e){return t.onNotifyRequest(e)},onPrack:function(e){return t.onPrackRequest(e)},onRefer:function(e){return t.onReferRequest(e)}},this._dialog=r,r.signalingState){case ze.Initial:case ze.HaveLocalOffer:return this.logger.error("Received 2xx response to INVITE without a session description"),this.ackAndBye(e,400,"Missing session description"),this.stateTransition(ot.Terminated),i.reject(new Error("Bad Media Description"));case ze.HaveRemoteOffer:if(!this._dialog.offer)throw new Error("Session offer undefined in signaling state ".concat(this._dialog.signalingState,"."));var s={sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers,sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions};return this.setOfferAndGetAnswer(this._dialog.offer,s).then(function(n){e.ack({body:n}),t.stateTransition(ot.Established)}).catch(function(n){throw t.ackAndBye(e,488,"Invalid session description"),t.stateTransition(ot.Terminated),n});case ze.Stable:if(this.earlyMediaSessionDescriptionHandlers.size>0){var a=this.earlyMediaSessionDescriptionHandlers.get(r.id);if(!a)throw new Error("Session description handler undefined.");return this.setSessionDescriptionHandler(a),this.earlyMediaSessionDescriptionHandlers.delete(r.id),e.ack(),this.stateTransition(ot.Established),i.resolve()}if(this.earlyMediaDialog){if(this.earlyMediaDialog!==r){if(this.earlyMedia){this.logger.error("You have set the 'earlyMedia' option to 'true' which requires that your INVITE requests do not fork and yet this INVITE request did in fact fork. Consequentially and not surprisingly the end point which accepted the INVITE (confirmed dialog) does not match the end point with which early media has been setup (early dialog) and thus this session is unable to proceed. In accordance with the SIP specifications, the SIP servers your end point is connected to determine if an INVITE forks and the forking behavior of those servers cannot be controlled by this library. If you wish to use early media with this library you must configure those servers accordingly. Alternatively you may set the 'earlyMedia' to 'false' which will allow this library to function with any INVITE requests which do fork.")}var o=new Error("Early media dialog does not equal confirmed dialog, terminating session");return this.logger.error(o.message),this.ackAndBye(e,488,"Not Acceptable Here"),this.stateTransition(ot.Terminated),i.reject(o)}return e.ack(),this.stateTransition(ot.Established),i.resolve()}var c=r.answer;if(!c)throw new Error("Answer is undefined.");var l={sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers,sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions};return this.setAnswer(c,l).then(function(){var n;t._renderbody&&t._rendertype&&(n={body:{contentDisposition:"render",contentType:t._rendertype,content:t._renderbody}}),e.ack(n),t.stateTransition(ot.Established)}).catch(function(n){throw t.logger.error(n.message),t.ackAndBye(e,488,"Not Acceptable Here"),t.stateTransition(ot.Terminated),n});case ze.Closed:return i.reject(new Error("Terminated."));default:throw new Error("Unknown session signaling state.")}}},{key:"onProgress",value:function(e){var t,n=this;if(this.logger.log("Inviter.onProgress"),this.state!==ot.Establishing)return this.logger.error("Progress received while in state ".concat(this.state,", dropping response")),i.reject(new Error("Invalid session state ".concat(this.state)));if(!this.outgoingInviteRequest)throw new Error("Outgoing INVITE request undefined.");var r=e.message,s=e.session;r.hasHeader("P-Asserted-Identity")&&(this._assertedIdentity=He.nameAddrHeaderParse(r.getHeader("P-Asserted-Identity")));var a=r.getHeader("require"),o=r.getHeader("rseq"),c=!!(a&&p(a).call(a,"100rel")&&o?Number(o):void 0),l=[];switch(c&&l.push("RAck: "+r.getHeader("rseq")+" "+r.getHeader("cseq")),s.signalingState){case ze.Initial:return c&&(this.logger.warn("First reliable provisional response received MUST contain an offer when INVITE does not contain an offer."),e.prack({extraHeaders:l})),i.resolve();case ze.HaveLocalOffer:return c&&e.prack({extraHeaders:l}),i.resolve();case ze.HaveRemoteOffer:if(!c)return this.logger.warn("Non-reliable provisional response MUST NOT contain an initial offer, discarding response."),i.resolve();var u=this.sessionDescriptionHandlerFactory(this,this.userAgent.configuration.sessionDescriptionHandlerFactoryOptions||{});return(null===(t=this.delegate)||void 0===t?void 0:t.onSessionDescriptionHandler)&&this.delegate.onSessionDescriptionHandler(u,!0),this.earlyMediaSessionDescriptionHandlers.set(s.id,u),u.setDescription(r.body,this.sessionDescriptionHandlerOptions,this.sessionDescriptionHandlerModifiers).then(function(){return u.getDescription(n.sessionDescriptionHandlerOptions,n.sessionDescriptionHandlerModifiers)}).then(function(t){var n={contentDisposition:"session",contentType:t.contentType,content:t.body};e.prack({extraHeaders:l,body:n})}).catch(function(e){throw n.stateTransition(ot.Terminated),e});case ze.Stable:if(c&&e.prack({extraHeaders:l}),this.earlyMedia&&!this.earlyMediaDialog){this.earlyMediaDialog=s;var d=s.answer;if(!d)throw new Error("Answer is undefined.");var h={sessionDescriptionHandlerModifiers:this.sessionDescriptionHandlerModifiers,sessionDescriptionHandlerOptions:this.sessionDescriptionHandlerOptions};return this.setAnswer(d,h).catch(function(e){throw n.stateTransition(ot.Terminated),e})}return i.resolve();case ze.Closed:return i.reject(new Error("Terminated."));default:throw new Error("Unknown session signaling state.")}}},{key:"onRedirect",value:function(e){this.logger.log("Inviter.onRedirect"),this.state===ot.Establishing||this.state===ot.Terminating?this.stateTransition(ot.Terminated):this.logger.error("Redirect received while in state ".concat(this.state,", dropping response"))}},{key:"onReject",value:function(e){this.logger.log("Inviter.onReject"),this.state===ot.Establishing||this.state===ot.Terminating?this.stateTransition(ot.Terminated):this.logger.error("Reject received while in state ".concat(this.state,", dropping response"))}},{key:"onTrying",value:function(e){this.logger.log("Inviter.onTrying"),this.state===ot.Establishing||this.logger.error("Trying received while in state ".concat(this.state,", dropping response"))}}])}(),It=function(){return t(function t(n,i,r){var s,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"text/plain",o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};e(this,t),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"userAgent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.logger=n.getLogger("sip.Messager"),o.params=o.params||{};var c=n.userAgentCore.configuration.aor;if(o.params.fromUri&&(c="string"==typeof o.params.fromUri?He.URIParse(o.params.fromUri):o.params.fromUri),!c)throw new TypeError("Invalid from URI: "+o.params.fromUri);var l=i;if(o.params.toUri&&(l="string"==typeof o.params.toUri?He.URIParse(o.params.toUri):o.params.toUri),!l)throw new TypeError("Invalid to URI: "+o.params.toUri);var u=o.params?$({},o.params):{},h=g(s=o.extraHeaders||[]).call(s),f={contentDisposition:"render",contentType:a,content:r};this.request=n.userAgentCore.makeOutgoingRequestMessage(st.MESSAGE,i,c,l,u,h,f),this.userAgent=n},[{key:"message",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.userAgent.userAgentCore.request(this.request,e.requestDelegate),i.resolve()}}])}();!function(e){e.Initial="Initial",e.Published="Published",e.Unpublished="Unpublished",e.Terminated="Terminated"}(Tt||(Tt={})),function(e){e.Initial="Initial",e.Registered="Registered",e.Unregistered="Unregistered",e.Terminated="Terminated"}(Rt||(Rt={}));var Et,Ct,At,xt,Dt=function(){function n(t){var i,r,s,a=this,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,n),d(this,"disposed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"expires",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"refreshFrequency",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"userAgent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"registrationExpiredTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"registrationTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_contacts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),d(this,"_retryAfter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:Rt.Initial}),d(this,"_stateEventEmitter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_waiting",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"_waitingEventEmitter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._stateEventEmitter=new we,this._waitingEventEmitter=new we,this.userAgent=t;var c=t.configuration.uri.clone();if(c.user=void 0,this.options=$($($({},n.defaultOptions()),{registrar:c}),n.stripUndefinedProperties(o)),this.options.extraContactHeaderParams=g(i=this.options.extraContactHeaderParams||[]).call(i),this.options.extraHeaders=g(r=this.options.extraHeaders||[]).call(r),!this.options.registrar)throw new Error("Registrar undefined.");if(this.options.registrar=this.options.registrar.clone(),this.options.regId&&!this.options.instanceId?this.options.instanceId=this.userAgent.instanceId:!this.options.regId&&this.options.instanceId&&(this.options.regId=1),this.options.instanceId&&-1===He.parse(this.options.instanceId,"uuid"))throw new Error("Invalid instanceId.");if(this.options.regId&&this.options.regId<0)throw new Error("Invalid regId.");var l,u=this.options.registrar,f=this.options.params&&this.options.params.fromUri||t.userAgentCore.configuration.aor,v=this.options.params&&this.options.params.toUri||t.configuration.uri,p=this.options.params||{},m=g(s=o.extraHeaders||[]).call(s);if(this.request=t.userAgentCore.makeOutgoingRequestMessage(st.REGISTER,u,f,v,p,m,void 0),this.expires=this.options.expires||n.defaultExpires,this.expires<0)throw new Error("Invalid expires.");if(this.refreshFrequency=this.options.refreshFrequency||n.defaultRefreshFrequency,this.refreshFrequency<50||this.refreshFrequency>99)throw new Error("Invalid refresh frequency. The value represents a percentage of the expiration time and should be between 50 and 99.");(this.logger=t.getLogger("sip.Registerer"),this.options.logConfiguration)&&(this.logger.log("Configuration:"),h(l=A(this.options)).call(l,function(e){var t=a.options[e];if("registrar"===e)a.logger.log("· "+e+": "+t);else a.logger.log("· "+e+": "+C(t))}));this.id=this.request.callId+this.request.from.parameters.tag,this.userAgent._registerers[this.id]=this}return t(n,[{key:"contacts",get:function(){var e;return g(e=this._contacts).call(e)}},{key:"retryAfter",get:function(){return this._retryAfter}},{key:"state",get:function(){return this._state}},{key:"stateChange",get:function(){return this._stateEventEmitter}},{key:"dispose",value:function(){var e,t=this;return this.disposed?i.resolve():(this.disposed=!0,this.logger.log(E(e="Registerer ".concat(this.id," in state ")).call(e,this.state," is being disposed")),delete this.userAgent._registerers[this.id],new i(function(e){var n=function(){if(!t.waiting&&t._state===Rt.Registered)return t.stateChange.addListener(function(){t.terminated(),e()},{once:!0}),void t.unregister();t.terminated(),e()};t.waiting?t.waitingChange.addListener(function(){n()},{once:!0}):n()}))}},{key:"register",value:function(){var e,t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.state===Rt.Terminated)throw this.stateError(),new Error("Registerer terminated. Unable to register.");if(this.disposed)throw this.stateError(),new Error("Registerer disposed. Unable to register.");if(this.waiting){this.waitingWarning();var r=new ue("REGISTER request already in progress, waiting for final response");return i.reject(r)}n.requestOptions&&(this.options=$($({},this.options),n.requestOptions));var s=g(e=this.options.extraHeaders||[]).call(e);s.push("Contact: "+this.generateContactHeader(this.expires)),s.push("Allow: "+["ACK","CANCEL","INVITE","MESSAGE","BYE","OPTIONS","INFO","NOTIFY","REFER"].toString()),this.request.cseq++,this.request.setHeader("cseq",this.request.cseq+" REGISTER"),this.request.extraHeaders=s,this.waitingToggle(!0);var a=this.userAgent.userAgentCore.register(this.request,{onAccept:function(e){var i;e.message.hasHeader("expires")&&(i=Number(e.message.getHeader("expires"))),t._contacts=e.message.getHeaders("contact");var r,s=t._contacts.length;if(!s)return t.logger.error("No Contact header in response to REGISTER, dropping response."),void t.unregistered();for(;s--;){if(!(r=e.message.parseHeader("contact",s)))throw new Error("Contact undefined");if(t.userAgent.contact.pubGruu&&Ce(r.uri,t.userAgent.contact.pubGruu)){i=Number(r.getParam("expires"));break}if(""===t.userAgent.configuration.contactName){if(r.uri.user===t.userAgent.contact.uri.user){i=Number(r.getParam("expires"));break}}else if(Ce(r.uri,t.userAgent.contact.uri)){i=Number(r.getParam("expires"));break}r=void 0}if(void 0===r)return t.logger.error("No Contact header pointing to us, dropping response"),t.unregistered(),void t.waitingToggle(!1);if(void 0===i)return t.logger.error("Contact pointing to us is missing expires parameter, dropping response"),t.unregistered(),void t.waitingToggle(!1);if(r.hasParam("temp-gruu")){var a=r.getParam("temp-gruu");a&&(t.userAgent.contact.tempGruu=He.URIParse(a.replace(/"/g,"")))}if(r.hasParam("pub-gruu")){var o=r.getParam("pub-gruu");o&&(t.userAgent.contact.pubGruu=He.URIParse(o.replace(/"/g,"")))}t.registered(i),n.requestDelegate&&n.requestDelegate.onAccept&&n.requestDelegate.onAccept(e),t.waitingToggle(!1)},onProgress:function(e){n.requestDelegate&&n.requestDelegate.onProgress&&n.requestDelegate.onProgress(e)},onRedirect:function(e){t.logger.error("Redirect received. Not supported."),t.unregistered(),n.requestDelegate&&n.requestDelegate.onRedirect&&n.requestDelegate.onRedirect(e),t.waitingToggle(!1)},onReject:function(e){if(423===e.message.statusCode)return e.message.hasHeader("min-expires")?(t.expires=Number(e.message.getHeader("min-expires")),t.waitingToggle(!1),void t.register()):(t.logger.error("423 response received for REGISTER without Min-Expires, dropping response"),t.unregistered(),void t.waitingToggle(!1));t.logger.warn("Failed to register, status code ".concat(e.message.statusCode));var i=NaN;if(500===e.message.statusCode||503===e.message.statusCode){var r=e.message.getHeader("retry-after");r&&(i=P(r,void 0))}t._retryAfter=isNaN(i)?void 0:i,t.unregistered(),n.requestDelegate&&n.requestDelegate.onReject&&n.requestDelegate.onReject(e),t._retryAfter=void 0,t.waitingToggle(!1)},onTrying:function(e){n.requestDelegate&&n.requestDelegate.onTrying&&n.requestDelegate.onTrying(e)}});return i.resolve(a)}},{key:"unregister",value:function(){var e,t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.state===Rt.Terminated)throw this.stateError(),new Error("Registerer terminated. Unable to register.");if(this.disposed&&this.state!==Rt.Registered)throw this.stateError(),new Error("Registerer disposed. Unable to register.");if(this.waiting){this.waitingWarning();var r=new ue("REGISTER request already in progress, waiting for final response");return i.reject(r)}this._state===Rt.Registered||n.all||this.logger.warn("Not currently registered, but sending an unregister anyway.");var s=g(e=n.requestOptions&&n.requestOptions.extraHeaders||[]).call(e);this.request.extraHeaders=s,n.all?(s.push("Contact: *"),s.push("Expires: 0")):s.push("Contact: "+this.generateContactHeader(0)),this.request.cseq++,this.request.setHeader("cseq",this.request.cseq+" REGISTER"),void 0!==this.registrationTimer&&(clearTimeout(this.registrationTimer),this.registrationTimer=void 0),this.waitingToggle(!0);var a=this.userAgent.userAgentCore.register(this.request,{onAccept:function(e){t._contacts=e.message.getHeaders("contact"),t.unregistered(),n.requestDelegate&&n.requestDelegate.onAccept&&n.requestDelegate.onAccept(e),t.waitingToggle(!1)},onProgress:function(e){n.requestDelegate&&n.requestDelegate.onProgress&&n.requestDelegate.onProgress(e)},onRedirect:function(e){t.logger.error("Unregister redirected. Not currently supported."),t.unregistered(),n.requestDelegate&&n.requestDelegate.onRedirect&&n.requestDelegate.onRedirect(e),t.waitingToggle(!1)},onReject:function(e){t.logger.error("Unregister rejected with status code ".concat(e.message.statusCode)),t.unregistered(),n.requestDelegate&&n.requestDelegate.onReject&&n.requestDelegate.onReject(e),t.waitingToggle(!1)},onTrying:function(e){n.requestDelegate&&n.requestDelegate.onTrying&&n.requestDelegate.onTrying(e)}});return i.resolve(a)}},{key:"clearTimers",value:function(){void 0!==this.registrationTimer&&(clearTimeout(this.registrationTimer),this.registrationTimer=void 0),void 0!==this.registrationExpiredTimer&&(clearTimeout(this.registrationExpiredTimer),this.registrationExpiredTimer=void 0)}},{key:"generateContactHeader",value:function(e){var t,n=this.userAgent.contact.toString({register:!0});(this.options.regId&&this.options.instanceId&&(n+=";reg-id="+this.options.regId,n+=';+sip.instance="<urn:uuid:'+this.options.instanceId+'>"'),this.options.extraContactHeaderParams)&&h(t=this.options.extraContactHeaderParams).call(t,function(e){n+=";"+e});return n+=";expires="+e}},{key:"registered",value:function(e){var t=this;this.clearTimers(),this.registrationTimer=m(function(){t.registrationTimer=void 0,t.register()},this.refreshFrequency/100*e*1e3),this.registrationExpiredTimer=m(function(){t.logger.warn("Registration expired"),t.unregistered()},1e3*e),this._state!==Rt.Registered&&this.stateTransition(Rt.Registered)}},{key:"unregistered",value:function(){this.clearTimers(),this._state!==Rt.Unregistered&&this.stateTransition(Rt.Unregistered)}},{key:"terminated",value:function(){this.clearTimers(),this._state!==Rt.Terminated&&this.stateTransition(Rt.Terminated)}},{key:"stateTransition",value:function(e){var t=this,n=function(){var n;throw new Error(E(n="Invalid state transition from ".concat(t._state," to ")).call(n,e))};switch(this._state){case Rt.Initial:e!==Rt.Registered&&e!==Rt.Unregistered&&e!==Rt.Terminated&&n();break;case Rt.Registered:e!==Rt.Unregistered&&e!==Rt.Terminated&&n();break;case Rt.Unregistered:e!==Rt.Registered&&e!==Rt.Terminated&&n();break;case Rt.Terminated:n();break;default:throw new Error("Unrecognized state.")}this._state=e,this.logger.log("Registration transitioned to state ".concat(this._state)),this._stateEventEmitter.emit(this._state),e===Rt.Terminated&&this.dispose()}},{key:"waiting",get:function(){return this._waiting}},{key:"waitingChange",get:function(){return this._waitingEventEmitter}},{key:"waitingToggle",value:function(e){var t;if(this._waiting===e)throw new Error(E(t="Invalid waiting transition from ".concat(this._waiting," to ")).call(t,e));this._waiting=e,this.logger.log("Waiting toggled to ".concat(this._waiting)),this._waitingEventEmitter.emit(this._waiting)}},{key:"waitingWarning",value:function(){this.logger.warn("An attempt was made to send a REGISTER request while a prior one was still in progress. RFC 3261 requires UAs MUST NOT send a new registration until they have received a final response from the registrar for the previous one or the previous REGISTER request has timed out. Note that if the transport disconnects, you still must wait for the prior request to time out before sending a new REGISTER request or alternatively dispose of the current Registerer and create a new Registerer.")}},{key:"stateError",value:function(){var e=this.state===Rt.Terminated?"is in 'Terminated' state":"has been disposed",t="An attempt was made to send a REGISTER request when the Registerer ".concat(e,".");t+=" The Registerer transitions to 'Terminated' when Registerer.dispose() is called.",t+=" Perhaps you called UserAgent.stop() which dipsoses of all Registerers?",this.logger.error(t)}}],[{key:"defaultOptions",value:function(){return{expires:n.defaultExpires,extraContactHeaderParams:[],extraHeaders:[],logConfiguration:!0,instanceId:"",params:{},regId:0,registrar:new Ee("sip","anonymous","anonymous.invalid"),refreshFrequency:n.defaultRefreshFrequency}}},{key:"stripUndefinedProperties",value:function(e){var t;return O(t=A(e)).call(t,function(t,n){return void 0!==e[n]&&(t[n]=e[n]),t},{})}}])}();d(Dt,"defaultExpires",{enumerable:!0,configurable:!0,writable:!0,value:600}),d(Dt,"defaultRefreshFrequency",{enumerable:!0,configurable:!0,writable:!0,value:99}),function(e){e.Initial="Initial",e.NotifyWait="NotifyWait",e.Pending="Pending",e.Active="Active",e.Terminated="Terminated"}(Et||(Et={})),function(e){e.Initial="Initial",e.NotifyWait="NotifyWait",e.Subscribed="Subscribed",e.Terminated="Terminated"}(Ct||(Ct={})),function(e){e.Connecting="Connecting",e.Connected="Connected",e.Disconnecting="Disconnecting",e.Disconnected="Disconnected"}(At||(At={})),function(e){e.Started="Started",e.Stopped="Stopped"}(xt||(xt={}));var Ht=function(){function n(){e(this,n),d(this,"_dataLength",{enumerable:!0,configurable:!0,writable:!0,value:0}),d(this,"_bufferLength",{enumerable:!0,configurable:!0,writable:!0,value:0}),d(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:new Int32Array(4)}),d(this,"_buffer",{enumerable:!0,configurable:!0,writable:!0,value:new ArrayBuffer(68)}),d(this,"_buffer8",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_buffer32",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._buffer8=new Uint8Array(this._buffer,0,68),this._buffer32=new Uint32Array(this._buffer,0,17),this.start()}return t(n,[{key:"start",value:function(){return this._dataLength=0,this._bufferLength=0,this._state.set(n.stateIdentity),this}},{key:"appendStr",value:function(e){var t,i,r=this._buffer8,s=this._buffer32,a=this._bufferLength;for(i=0;i<e.length;i+=1){if((t=e.charCodeAt(i))<128)r[a++]=t;else if(t<2048)r[a++]=(t>>>6)+192,r[a++]=63&t|128;else if(t<55296||t>56319)r[a++]=(t>>>12)+224,r[a++]=t>>>6&63|128,r[a++]=63&t|128;else{if((t=1024*(t-55296)+(e.charCodeAt(++i)-56320)+65536)>1114111)throw new Error("Unicode standard supports code points up to U+10FFFF");r[a++]=(t>>>18)+240,r[a++]=t>>>12&63|128,r[a++]=t>>>6&63|128,r[a++]=63&t|128}a>=64&&(this._dataLength+=64,n._md5cycle(this._state,s),a-=64,s[0]=s[16])}return this._bufferLength=a,this}},{key:"appendAsciiStr",value:function(e){for(var t,i=this._buffer8,r=this._buffer32,s=this._bufferLength,a=0;;){for(t=Math.min(e.length-a,64-s);t--;)i[s++]=e.charCodeAt(a++);if(s<64)break;this._dataLength+=64,n._md5cycle(this._state,r),s=0}return this._bufferLength=s,this}},{key:"appendByteArray",value:function(e){for(var t,i=this._buffer8,r=this._buffer32,s=this._bufferLength,a=0;;){for(t=Math.min(e.length-a,64-s);t--;)i[s++]=e[a++];if(s<64)break;this._dataLength+=64,n._md5cycle(this._state,r),s=0}return this._bufferLength=s,this}},{key:"getState",value:function(){var e=this,t=e._state;return{buffer:String.fromCharCode.apply(null,e._buffer8),buflen:e._bufferLength,length:e._dataLength,state:[t[0],t[1],t[2],t[3]]}}},{key:"setState",value:function(e){var t,n=e.buffer,i=e.state,r=this._state;for(this._dataLength=e.length,this._bufferLength=e.buflen,r[0]=i[0],r[1]=i[1],r[2]=i[2],r[3]=i[3],t=0;t<n.length;t+=1)this._buffer8[t]=n.charCodeAt(t)}},{key:"end",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],i=this._bufferLength,r=this._buffer8,s=this._buffer32,a=1+(i>>2);if(this._dataLength+=i,r[i]=128,r[i+1]=r[i+2]=r[i+3]=0,s.set(n.buffer32Identity.subarray(a),a),i>55&&(n._md5cycle(this._state,s),s.set(n.buffer32Identity)),(e=8*this._dataLength)<=4294967295)s[14]=e;else{var o=e.toString(16).match(/(.*?)(.{0,8})$/);if(null===o)return;var c=T(o[2],16),l=T(o[1],16)||0;s[14]=c,s[15]=l}return n._md5cycle(this._state,s),t?this._state:n._hex(this._state)}}],[{key:"hashStr",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.onePassHasher.start().appendStr(e).end(t)}},{key:"hashAsciiStr",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.onePassHasher.start().appendAsciiStr(e).end(t)}},{key:"_hex",value:function(e){var t,i,r,s,a=n.hexChars,o=n.hexOut;for(s=0;s<4;s+=1)for(i=8*s,t=e[s],r=0;r<8;r+=2)o[i+1+r]=a.charAt(15&t),t>>>=4,o[i+0+r]=a.charAt(15&t),t>>>=4;return o.join("")}},{key:"_md5cycle",value:function(e,t){var n=e[0],i=e[1],r=e[2],s=e[3];i=((i+=((r=((r+=((s=((s+=((n=((n+=(i&r|~i&s)+t[0]-680876936|0)<<7|n>>>25)+i|0)&i|~n&r)+t[1]-389564586|0)<<12|s>>>20)+n|0)&n|~s&i)+t[2]+606105819|0)<<17|r>>>15)+s|0)&s|~r&n)+t[3]-1044525330|0)<<22|i>>>10)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i&r|~i&s)+t[4]-176418897|0)<<7|n>>>25)+i|0)&i|~n&r)+t[5]+1200080426|0)<<12|s>>>20)+n|0)&n|~s&i)+t[6]-1473231341|0)<<17|r>>>15)+s|0)&s|~r&n)+t[7]-45705983|0)<<22|i>>>10)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i&r|~i&s)+t[8]+1770035416|0)<<7|n>>>25)+i|0)&i|~n&r)+t[9]-1958414417|0)<<12|s>>>20)+n|0)&n|~s&i)+t[10]-42063|0)<<17|r>>>15)+s|0)&s|~r&n)+t[11]-1990404162|0)<<22|i>>>10)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i&r|~i&s)+t[12]+1804603682|0)<<7|n>>>25)+i|0)&i|~n&r)+t[13]-40341101|0)<<12|s>>>20)+n|0)&n|~s&i)+t[14]-1502002290|0)<<17|r>>>15)+s|0)&s|~r&n)+t[15]+1236535329|0)<<22|i>>>10)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i&s|r&~s)+t[1]-165796510|0)<<5|n>>>27)+i|0)&r|i&~r)+t[6]-1069501632|0)<<9|s>>>23)+n|0)&i|n&~i)+t[11]+643717713|0)<<14|r>>>18)+s|0)&n|s&~n)+t[0]-373897302|0)<<20|i>>>12)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i&s|r&~s)+t[5]-701558691|0)<<5|n>>>27)+i|0)&r|i&~r)+t[10]+38016083|0)<<9|s>>>23)+n|0)&i|n&~i)+t[15]-660478335|0)<<14|r>>>18)+s|0)&n|s&~n)+t[4]-405537848|0)<<20|i>>>12)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i&s|r&~s)+t[9]+568446438|0)<<5|n>>>27)+i|0)&r|i&~r)+t[14]-1019803690|0)<<9|s>>>23)+n|0)&i|n&~i)+t[3]-187363961|0)<<14|r>>>18)+s|0)&n|s&~n)+t[8]+1163531501|0)<<20|i>>>12)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i&s|r&~s)+t[13]-1444681467|0)<<5|n>>>27)+i|0)&r|i&~r)+t[2]-51403784|0)<<9|s>>>23)+n|0)&i|n&~i)+t[7]+1735328473|0)<<14|r>>>18)+s|0)&n|s&~n)+t[12]-1926607734|0)<<20|i>>>12)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i^r^s)+t[5]-378558|0)<<4|n>>>28)+i|0)^i^r)+t[8]-2022574463|0)<<11|s>>>21)+n|0)^n^i)+t[11]+1839030562|0)<<16|r>>>16)+s|0)^s^n)+t[14]-35309556|0)<<23|i>>>9)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i^r^s)+t[1]-1530992060|0)<<4|n>>>28)+i|0)^i^r)+t[4]+1272893353|0)<<11|s>>>21)+n|0)^n^i)+t[7]-155497632|0)<<16|r>>>16)+s|0)^s^n)+t[10]-1094730640|0)<<23|i>>>9)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i^r^s)+t[13]+681279174|0)<<4|n>>>28)+i|0)^i^r)+t[0]-358537222|0)<<11|s>>>21)+n|0)^n^i)+t[3]-722521979|0)<<16|r>>>16)+s|0)^s^n)+t[6]+76029189|0)<<23|i>>>9)+r|0,i=((i+=((r=((r+=((s=((s+=((n=((n+=(i^r^s)+t[9]-640364487|0)<<4|n>>>28)+i|0)^i^r)+t[12]-421815835|0)<<11|s>>>21)+n|0)^n^i)+t[15]+530742520|0)<<16|r>>>16)+s|0)^s^n)+t[2]-995338651|0)<<23|i>>>9)+r|0,i=((i+=((s=((s+=(i^((n=((n+=(r^(i|~s))+t[0]-198630844|0)<<6|n>>>26)+i|0)|~r))+t[7]+1126891415|0)<<10|s>>>22)+n|0)^((r=((r+=(n^(s|~i))+t[14]-1416354905|0)<<15|r>>>17)+s|0)|~n))+t[5]-57434055|0)<<21|i>>>11)+r|0,i=((i+=((s=((s+=(i^((n=((n+=(r^(i|~s))+t[12]+1700485571|0)<<6|n>>>26)+i|0)|~r))+t[3]-1894986606|0)<<10|s>>>22)+n|0)^((r=((r+=(n^(s|~i))+t[10]-1051523|0)<<15|r>>>17)+s|0)|~n))+t[1]-2054922799|0)<<21|i>>>11)+r|0,i=((i+=((s=((s+=(i^((n=((n+=(r^(i|~s))+t[8]+1873313359|0)<<6|n>>>26)+i|0)|~r))+t[15]-30611744|0)<<10|s>>>22)+n|0)^((r=((r+=(n^(s|~i))+t[6]-1560198380|0)<<15|r>>>17)+s|0)|~n))+t[13]+1309151649|0)<<21|i>>>11)+r|0,i=((i+=((s=((s+=(i^((n=((n+=(r^(i|~s))+t[4]-145523070|0)<<6|n>>>26)+i|0)|~r))+t[11]-1120210379|0)<<10|s>>>22)+n|0)^((r=((r+=(n^(s|~i))+t[2]+718787259|0)<<15|r>>>17)+s|0)|~n))+t[9]-343485551|0)<<21|i>>>11)+r|0,e[0]=n+e[0]|0,e[1]=i+e[1]|0,e[2]=r+e[2]|0,e[3]=s+e[3]|0}}])}();function _t(e){return Ht.hashStr(e)}d(Ht,"stateIdentity",{enumerable:!0,configurable:!0,writable:!0,value:new Int32Array([1732584193,-271733879,-1732584194,271733878])}),d(Ht,"buffer32Identity",{enumerable:!0,configurable:!0,writable:!0,value:new Int32Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])}),d(Ht,"hexChars",{enumerable:!0,configurable:!0,writable:!0,value:"0123456789abcdef"}),d(Ht,"hexOut",{enumerable:!0,configurable:!0,writable:!0,value:[]}),d(Ht,"onePassHasher",{enumerable:!0,configurable:!0,writable:!0,value:new Ht}),"5d41402abc4b2a76b9719d911017c592"!==Ht.hashStr("hello")&&console.error("Md5 self test failed.");var $t,qt=function(){return t(function t(n,i,r,s){e(this,t),d(this,"stale",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"ha1",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"username",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"password",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"cnonce",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"nc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"ncHex",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"response",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"algorithm",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"realm",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"nonce",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"opaque",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"qop",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"method",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"uri",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.logger=n.getLogger("sipjs.digestauthentication"),this.username=r,this.password=s,this.ha1=i,this.nc=0,this.ncHex="00000000"},[{key:"authenticate",value:function(e,t,n){if(this.algorithm=t.algorithm,this.realm=t.realm,this.nonce=t.nonce,this.opaque=t.opaque,this.stale=t.stale,this.algorithm){if("MD5"!==this.algorithm)return this.logger.warn("challenge with Digest algorithm different than 'MD5', authentication aborted"),!1}else this.algorithm="MD5";if(!this.realm)return this.logger.warn("challenge without Digest realm, authentication aborted"),!1;if(!this.nonce)return this.logger.warn("challenge without Digest nonce, authentication aborted"),!1;var i,r;if(t.qop)if(q(i=t.qop).call(i,"auth")>-1)this.qop="auth";else{if(!(q(r=t.qop).call(r,"auth-int")>-1))return this.logger.warn("challenge without Digest qop different than 'auth' or 'auth-int', authentication aborted"),!1;this.qop="auth-int"}else this.qop=void 0;return this.method=e.method,this.uri=e.ruri,this.cnonce=qe(12),this.nc+=1,this.updateNcHex(),4294967296===this.nc&&(this.nc=1,this.ncHex="00000001"),this.calculateResponse(n),!0}},{key:"toString",value:function(){var e=[];if(!this.response)throw new Error("response field does not exist, cannot generate Authorization header");return e.push("algorithm="+this.algorithm),e.push('username="'+this.username+'"'),e.push('realm="'+this.realm+'"'),e.push('nonce="'+this.nonce+'"'),e.push('uri="'+this.uri+'"'),e.push('response="'+this.response+'"'),this.opaque&&e.push('opaque="'+this.opaque+'"'),this.qop&&(e.push("qop="+this.qop),e.push('cnonce="'+this.cnonce+'"'),e.push("nc="+this.ncHex)),"Digest "+e.join(", ")}},{key:"updateNcHex",value:function(){var e=Number(this.nc).toString(16);this.ncHex="00000000".substr(0,8-e.length)+e}},{key:"calculateResponse",value:function(e){var t,n;""!==(t=this.ha1)&&void 0!==t||(t=_t(this.username+":"+this.realm+":"+this.password)),"auth"===this.qop?(n=_t(this.method+":"+this.uri),this.response=_t(t+":"+this.nonce+":"+this.ncHex+":"+this.cnonce+":auth:"+n)):"auth-int"===this.qop?(n=_t(this.method+":"+this.uri+":"+_t(e||"")),this.response=_t(t+":"+this.nonce+":"+this.ncHex+":"+this.cnonce+":auth-int:"+n)):void 0===this.qop&&(n=_t(this.method+":"+this.uri),this.response=_t(t+":"+this.nonce+":"+n))}}])}();!function(e){e[e.error=0]="error",e[e.warn=1]="warn",e[e.log=2]="log",e[e.debug=3]="debug"}($t||($t={}));var Mt,Pt=function(){return t(function t(n,i,r){e(this,t),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"category",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"label",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.logger=n,this.category=i,this.label=r},[{key:"error",value:function(e){this.genericLog($t.error,e)}},{key:"warn",value:function(e){this.genericLog($t.warn,e)}},{key:"log",value:function(e){this.genericLog($t.log,e)}},{key:"debug",value:function(e){this.genericLog($t.debug,e)}},{key:"genericLog",value:function(e,t){this.logger.genericLog(e,this.category,this.label,t)}},{key:"level",get:function(){return this.logger.level},set:function(e){this.logger.level=e}}])}(),Ot=function(){return t(function t(){e(this,t),d(this,"builtinEnabled",{enumerable:!0,configurable:!0,writable:!0,value:!0}),d(this,"_level",{enumerable:!0,configurable:!0,writable:!0,value:$t.log}),d(this,"_connector",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"loggers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.logger=this.getLogger("sip:loggerfactory")},[{key:"level",get:function(){return this._level},set:function(e){e>=0&&e<=3?this._level=e:e>3?this._level=3:$t.hasOwnProperty(e)?this._level=e:this.logger.error("invalid 'level' parameter value: "+C(e))}},{key:"connector",get:function(){return this._connector},set:function(e){e?"function"==typeof e?this._connector=e:this.logger.error("invalid 'connector' parameter value: "+C(e)):this._connector=void 0}},{key:"getLogger",value:function(e,t){if(t&&3===this.level)return new Pt(this,e,t);if(this.loggers[e])return this.loggers[e];var n=new Pt(this,e);return this.loggers[e]=n,n}},{key:"genericLog",value:function(e,t,n,i){this.level>=e&&this.builtinEnabled&&this.print(e,t,n,i),this.connector&&this.connector($t[e],t,n,i)}},{key:"print",value:function(e,t,n,i){if("string"==typeof i){var r=[new Date,t];n&&r.push(n),i=E(r).call(r,i).join(" | ")}switch(e){case $t.error:console.error(i);break;case $t.warn:console.warn(i);break;case $t.log:console.log(i);break;case $t.debug:console.debug(i)}}}])}();function Nt(e,t){var n,i="\r\n";if(t.statusCode<100||t.statusCode>699)throw new TypeError("Invalid statusCode: "+t.statusCode);var r=t.reasonPhrase?t.reasonPhrase:Me(t.statusCode),s="SIP/2.0 "+t.statusCode+" "+r+i;t.statusCode>=100&&t.statusCode,t.statusCode;var a="From: "+e.getHeader("From")+i,o="Call-ID: "+e.callId+i,c="CSeq: "+e.cseq+" "+e.method+i,l=O(n=e.getHeaders("via")).call(n,function(e,t){return e+"Via: "+t+i},""),u="To: "+e.getHeader("to");if(t.statusCode>100&&!e.parseHeader("to").hasParam("tag")){var d=t.toTag;d||(d=Pe()),u+=";tag="+d}u+=i;var h="";t.supported&&(h="Supported: "+t.supported.join(", ")+i);var g="";t.userAgent&&(g="User-Agent: "+t.userAgent+i);var f,v="";t.extraHeaders&&(v=O(f=t.extraHeaders).call(f,function(e,t){return e+R(t).call(t)+i},""));return s+=l,s+=a,s+=u,s+=c,s+=o,s+=h,s+=g,s+=v,t.body?(s+="Content-Type: "+t.body.contentType+i,s+="Content-Length: "+Ne(t.body.content)+i+i,s+=t.body.content):s+="Content-Length: 0\r\n\r\n",{message:s}}function jt(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(jt=function(){return!!e})()}!function(e){function t(e,t){var n=t,i=0,r=0;if(e.substring(n,n+2).match(/(^\r\n)/))return-2;for(;0===i;){if(-1===(r=q(e).call(e,"\r\n",n)))return r;!e.substring(r+2,r+4).match(/(^\r\n)/)&&e.charAt(r+2).match(/(^\s+)/)?n=r+2:i=r}return i}function n(e,t,n,i){var r,s,a,o=q(t).call(t,":",n),c=R(r=t.substring(n,o)).call(r),l=R(s=t.substring(o+1,i)).call(s);switch(c.toLowerCase()){case"via":case"v":e.addHeader("via",l),1===e.getHeaders("via").length?(a=e.parseHeader("Via"))&&(e.via=a,e.viaBranch=a.branch):a=0;break;case"from":case"f":e.setHeader("from",l),(a=e.parseHeader("from"))&&(e.from=a,e.fromTag=a.getParam("tag"));break;case"to":case"t":e.setHeader("to",l),(a=e.parseHeader("to"))&&(e.to=a,e.toTag=a.getParam("tag"));break;case"record-route":if(-1===(a=He.parse(l,"Record_Route"))){a=void 0;break}if(!(a instanceof Array)){a=void 0;break}h(a).call(a,function(t){e.addHeader("record-route",l.substring(t.position,t.offset)),e.headers["Record-Route"][e.getHeaders("record-route").length-1].parsed=t.parsed});break;case"call-id":case"i":e.setHeader("call-id",l),(a=e.parseHeader("call-id"))&&(e.callId=l);break;case"contact":case"m":if(-1===(a=He.parse(l,"Contact"))){a=void 0;break}if(!(a instanceof Array)){a=void 0;break}h(a).call(a,function(t){e.addHeader("contact",l.substring(t.position,t.offset)),e.headers.Contact[e.getHeaders("contact").length-1].parsed=t.parsed});break;case"content-length":case"l":e.setHeader("content-length",l),a=e.parseHeader("content-length");break;case"content-type":case"c":e.setHeader("content-type",l),a=e.parseHeader("content-type");break;case"cseq":e.setHeader("cseq",l),(a=e.parseHeader("cseq"))&&(e.cseq=a.value),e instanceof Ve&&(e.method=a.method);break;case"max-forwards":e.setHeader("max-forwards",l),a=e.parseHeader("max-forwards");break;case"www-authenticate":e.setHeader("www-authenticate",l),a=e.parseHeader("www-authenticate");break;case"proxy-authenticate":e.setHeader("proxy-authenticate",l),a=e.parseHeader("proxy-authenticate");break;case"refer-to":case"r":e.setHeader("refer-to",l),(a=e.parseHeader("refer-to"))&&(e.referTo=a);break;default:e.addHeader(c.toLowerCase(),l),a=0}return void 0!==a||{error:"error parsing header '"+c+"'"}}e.getHeader=t,e.parseHeader=n,e.parseMessage=function(e,i){var r=0,s=q(e).call(e,"\r\n");if(-1!==s){var a,o=e.substring(0,s),c=He.parse(o,"Request_Response");if(-1!==c){var l;for(c.status_code?((a=new Ve).statusCode=c.status_code,a.reasonPhrase=c.reason_phrase):((a=new Le).method=c.method,a.ruri=c.uri),a.data=e,r=s+2;;){if(-2===(s=t(e,r))){l=r+2;break}if(-1===s)return void i.error("malformed message");var u=n(a,e,r,s);if(u&&!0!==u)return void i.error(u.error);r=s+2}return a.hasHeader("content-length")?a.body=e.substr(l,Number(a.getHeader("content-length"))):a.body=e.substring(l),a}i.warn('error parsing first line of SIP message: "'+o+'"')}else i.warn("no CRLF found, not a SIP message, discarded")}}(Mt||(Mt={}));var Ft=function(){function n(t){return e(this,n),i=this,c=[t||"Unspecified transport error."],r=o(r=n),a(i,jt()?s(r,c||[],o(i).constructor):r.apply(i,c));var i,r,c}return c(n,ae),t(n)}(),Ut=function(){return t(function t(n,i,r,s,a){var o;e(this,t),d(this,"_transport",{enumerable:!0,configurable:!0,writable:!0,value:n}),d(this,"_user",{enumerable:!0,configurable:!0,writable:!0,value:i}),d(this,"_id",{enumerable:!0,configurable:!0,writable:!0,value:r}),d(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:s}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"listeners",{enumerable:!0,configurable:!0,writable:!0,value:new Array}),this.logger=i.loggerFactory.getLogger(a,r),this.logger.debug(E(o="Constructing ".concat(this.typeToString()," with id ")).call(o,this.id,"."))},[{key:"dispose",value:function(){var e;this.logger.debug(E(e="Destroyed ".concat(this.typeToString()," with id ")).call(e,this.id,"."))}},{key:"id",get:function(){return this._id}},{key:"kind",get:function(){throw new Error("Invalid kind.")}},{key:"state",get:function(){return this._state}},{key:"transport",get:function(){return this._transport}},{key:"addStateChangeListener",value:function(e,t){var n=this,i=function(){n.removeStateChangeListener(i),e()};!0===(null==t?void 0:t.once)?this.listeners.push(i):this.listeners.push(e)}},{key:"notifyStateChangeListeners",value:function(){var e,t;h(e=g(t=this.listeners).call(t)).call(e,function(e){return e()})}},{key:"removeStateChangeListener",value:function(e){var t;this.listeners=f(t=this.listeners).call(t,function(t){return t!==e})}},{key:"logTransportError",value:function(e,t){var n;this.logger.error(e.message),this.logger.error(E(n="Transport error occurred in ".concat(this.typeToString()," with id ")).call(n,this.id,".")),this.logger.error(t)}},{key:"send",value:function(e){var t=this;return this.transport.send(e).catch(function(e){if(e instanceof Ft)throw t.onTransportError(e),e;var n;throw n=e&&"string"==typeof e.message?new Ft(e.message):new Ft,t.onTransportError(n),n})}},{key:"setState",value:function(e){var t,n;this.logger.debug(E(t=E(n='State change to "'.concat(e,'" on ')).call(n,this.typeToString()," with id ")).call(t,this.id,".")),this._state=e,this._user.onStateChange&&this._user.onStateChange(e),this.notifyStateChangeListeners()}},{key:"typeToString",value:function(){return"UnknownType"}}])}();function Bt(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Bt=function(){return!!e})()}var Lt,Gt=function(){function n(t,i,r,c,l){var u,h,g,f;return e(this,n),h=this,g=n,f=[i,r,t.viaBranch,c,l],g=o(g),u=a(h,Bt()?s(g,f||[],o(h).constructor):g.apply(h,f)),d(u,"_request",{enumerable:!0,configurable:!0,writable:!0,value:t}),d(u,"user",{enumerable:!0,configurable:!0,writable:!0,value:r}),u}return c(n,Ut),t(n,[{key:"request",get:function(){return this._request}}])}();function Vt(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Vt=function(){return!!e})()}!function(e){e.Accepted="Accepted",e.Calling="Calling",e.Completed="Completed",e.Confirmed="Confirmed",e.Proceeding="Proceeding",e.Terminated="Terminated",e.Trying="Trying"}(Lt||(Lt={}));var Wt=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,u=n,h=[t,i,r,Lt.Proceeding,"sip.transaction.ist"],u=o(u),c=a(l,Vt()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"lastFinalResponse",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"lastProvisionalResponse",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"H",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"I",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"L",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"progressExtensionTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c}return c(n,Gt),t(n,[{key:"dispose",value:function(){var e,t,i,r,s;this.stopProgressExtensionTimer(),this.H&&(clearTimeout(this.H),this.H=void 0),this.I&&(clearTimeout(this.I),this.I=void 0),this.L&&(clearTimeout(this.L),this.L=void 0),(e=n,t="dispose",i=this,s=v(o(1&(r=3)?e.prototype:e),t,i),2&r&&"function"==typeof s?function(e){return s.apply(i,e)}:s)([])}},{key:"kind",get:function(){return"ist"}},{key:"receiveRequest",value:function(e){var t,n=this;switch(this.state){case Lt.Proceeding:if(e.method===st.INVITE)return void(this.lastProvisionalResponse&&this.send(this.lastProvisionalResponse).catch(function(e){n.logTransportError(e,"Failed to send retransmission of provisional response.")}));break;case Lt.Accepted:if(e.method===st.INVITE)return;break;case Lt.Completed:if(e.method===st.INVITE){if(!this.lastFinalResponse)throw new Error("Last final response undefined.");return void this.send(this.lastFinalResponse).catch(function(e){n.logTransportError(e,"Failed to send retransmission of final response.")})}if(e.method===st.ACK)return void this.stateTransition(Lt.Confirmed);break;case Lt.Confirmed:case Lt.Terminated:if(e.method===st.INVITE||e.method===st.ACK)return;break;default:throw new Error("Invalid state ".concat(this.state))}var i=E(t="INVITE server transaction received unexpected ".concat(e.method," request while in state ")).call(t,this.state,".");this.logger.warn(i)}},{key:"receiveResponse",value:function(e,t){var n,i=this;if(e<100||e>699)throw new Error("Invalid status code ".concat(e));switch(this.state){case Lt.Proceeding:if(e>=100&&e<=199)return this.lastProvisionalResponse=t,e>100&&this.startProgressExtensionTimer(),void this.send(t).catch(function(e){i.logTransportError(e,"Failed to send 1xx response.")});if(e>=200&&e<=299)return this.lastFinalResponse=t,this.stateTransition(Lt.Accepted),void this.send(t).catch(function(e){i.logTransportError(e,"Failed to send 2xx response.")});if(e>=300&&e<=699)return this.lastFinalResponse=t,this.stateTransition(Lt.Completed),void this.send(t).catch(function(e){i.logTransportError(e,"Failed to send non-2xx final response.")});break;case Lt.Accepted:if(e>=200&&e<=299)return void this.send(t).catch(function(e){i.logTransportError(e,"Failed to send 2xx response.")});break;case Lt.Completed:case Lt.Confirmed:case Lt.Terminated:break;default:throw new Error("Invalid state ".concat(this.state))}var r=E(n="INVITE server transaction received unexpected ".concat(e," response from TU while in state ")).call(n,this.state,".");throw this.logger.error(r),new Error(r)}},{key:"retransmitAcceptedResponse",value:function(){var e=this;this.state===Lt.Accepted&&this.lastFinalResponse&&this.send(this.lastFinalResponse).catch(function(t){e.logTransportError(t,"Failed to send 2xx response.")})}},{key:"onTransportError",value:function(e){this.user.onTransportError&&this.user.onTransportError(e)}},{key:"typeToString",value:function(){return"INVITE server transaction"}},{key:"stateTransition",value:function(e){var t=this,n=function(){var n;throw new Error(E(n="Invalid state transition from ".concat(t.state," to ")).call(n,e))};switch(e){case Lt.Proceeding:n();break;case Lt.Accepted:case Lt.Completed:this.state!==Lt.Proceeding&&n();break;case Lt.Confirmed:this.state!==Lt.Completed&&n();break;case Lt.Terminated:this.state!==Lt.Accepted&&this.state!==Lt.Completed&&this.state!==Lt.Confirmed&&n();break;default:n()}this.stopProgressExtensionTimer(),e===Lt.Accepted&&(this.L=m(function(){return t.timerL()},it.TIMER_L)),e===Lt.Completed&&(this.H=m(function(){return t.timerH()},it.TIMER_H)),e===Lt.Confirmed&&(this.I=m(function(){return t.timerI()},it.TIMER_I)),e===Lt.Terminated&&this.dispose(),this.setState(e)}},{key:"startProgressExtensionTimer",value:function(){var e=this;void 0===this.progressExtensionTimer&&(this.progressExtensionTimer=L(function(){if(e.logger.debug("Progress extension timer expired for INVITE server transaction ".concat(e.id,".")),!e.lastProvisionalResponse)throw new Error("Last provisional response undefined.");e.send(e.lastProvisionalResponse).catch(function(t){e.logTransportError(t,"Failed to send retransmission of provisional response.")})},it.PROVISIONAL_RESPONSE_INTERVAL))}},{key:"stopProgressExtensionTimer",value:function(){void 0!==this.progressExtensionTimer&&(clearInterval(this.progressExtensionTimer),this.progressExtensionTimer=void 0)}},{key:"timerG",value:function(){}},{key:"timerH",value:function(){this.logger.debug("Timer H expired for INVITE server transaction ".concat(this.id,".")),this.state===Lt.Completed&&(this.logger.warn("ACK to negative final response was never received, terminating transaction."),this.stateTransition(Lt.Terminated))}},{key:"timerI",value:function(){this.logger.debug("Timer I expired for INVITE server transaction ".concat(this.id,".")),this.stateTransition(Lt.Terminated)}},{key:"timerL",value:function(){this.logger.debug("Timer L expired for INVITE server transaction ".concat(this.id,".")),this.state===Lt.Accepted&&this.stateTransition(Lt.Terminated)}}])}();function Kt(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Kt=function(){return!!e})()}var Yt=function(){function n(t,i,r,c,l){var u,h,g,f;return e(this,n),h=this,g=n,f=[i,r,n.makeId(t),c,l],g=o(g),u=a(h,Kt()?s(g,f||[],o(h).constructor):g.apply(h,f)),d(u,"_request",{enumerable:!0,configurable:!0,writable:!0,value:t}),d(u,"user",{enumerable:!0,configurable:!0,writable:!0,value:r}),t.setViaHeader(u.id,i.protocol),u}return c(n,Ut),t(n,[{key:"request",get:function(){return this._request}},{key:"onRequestTimeout",value:function(){this.user.onRequestTimeout&&this.user.onRequestTimeout()}}],[{key:"makeId",value:function(e){if("CANCEL"===e.method){if(!e.branch)throw new Error("Outgoing CANCEL request without a branch.");return e.branch}return"z9hG4bK"+Math.floor(1e7*Math.random())}}])}();function zt(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(zt=function(){return!!e})()}var Zt=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,u=n,h=[t,i,r,Lt.Trying,"sip.transaction.nict"],u=o(u),c=a(l,zt()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"F",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"K",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c.F=m(function(){return c.timerF()},it.TIMER_F),c.send(t.toString()).catch(function(e){c.logTransportError(e,"Failed to send initial outgoing request.")}),c}return c(n,Yt),t(n,[{key:"dispose",value:function(){var e,t,i,r,s;this.F&&(clearTimeout(this.F),this.F=void 0),this.K&&(clearTimeout(this.K),this.K=void 0),(e=n,t="dispose",i=this,s=v(o(1&(r=3)?e.prototype:e),t,i),2&r&&"function"==typeof s?function(e){return s.apply(i,e)}:s)([])}},{key:"kind",get:function(){return"nict"}},{key:"receiveResponse",value:function(e){var t,n=e.statusCode;if(!n||n<100||n>699)throw new Error("Invalid status code ".concat(n));switch(this.state){case Lt.Trying:if(n>=100&&n<=199)return this.stateTransition(Lt.Proceeding),void(this.user.receiveResponse&&this.user.receiveResponse(e));if(n>=200&&n<=699)return this.stateTransition(Lt.Completed),408===n?void this.onRequestTimeout():void(this.user.receiveResponse&&this.user.receiveResponse(e));break;case Lt.Proceeding:if(n>=100&&n<=199&&this.user.receiveResponse)return this.user.receiveResponse(e);if(n>=200&&n<=699)return this.stateTransition(Lt.Completed),408===n?void this.onRequestTimeout():void(this.user.receiveResponse&&this.user.receiveResponse(e));break;case Lt.Completed:case Lt.Terminated:return;default:throw new Error("Invalid state ".concat(this.state))}var i=E(t="Non-INVITE client transaction received unexpected ".concat(n," response while in state ")).call(t,this.state,".");this.logger.warn(i)}},{key:"onTransportError",value:function(e){this.user.onTransportError&&this.user.onTransportError(e),this.stateTransition(Lt.Terminated,!0)}},{key:"typeToString",value:function(){return"non-INVITE client transaction"}},{key:"stateTransition",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=function(){var n;throw new Error(E(n="Invalid state transition from ".concat(t.state," to ")).call(n,e))};switch(e){case Lt.Trying:i();break;case Lt.Proceeding:this.state!==Lt.Trying&&i();break;case Lt.Completed:this.state!==Lt.Trying&&this.state!==Lt.Proceeding&&i();break;case Lt.Terminated:this.state!==Lt.Trying&&this.state!==Lt.Proceeding&&this.state!==Lt.Completed&&(n||i());break;default:i()}e===Lt.Completed&&(this.F&&(clearTimeout(this.F),this.F=void 0),this.K=m(function(){return t.timerK()},it.TIMER_K)),e===Lt.Terminated&&this.dispose(),this.setState(e)}},{key:"timerF",value:function(){this.logger.debug("Timer F expired for non-INVITE client transaction ".concat(this.id,".")),this.state!==Lt.Trying&&this.state!==Lt.Proceeding||(this.onRequestTimeout(),this.stateTransition(Lt.Terminated))}},{key:"timerK",value:function(){this.state===Lt.Completed&&this.stateTransition(Lt.Terminated)}}])}(),Jt=function(){return t(function t(n,i){e(this,t),d(this,"core",{enumerable:!0,configurable:!0,writable:!0,value:n}),d(this,"dialogState",{enumerable:!0,configurable:!0,writable:!0,value:i}),this.core.dialogs.set(this.id,this)},[{key:"dispose",value:function(){this.core.dialogs.delete(this.id)}},{key:"id",get:function(){return this.dialogState.id}},{key:"early",get:function(){return this.dialogState.early}},{key:"callId",get:function(){return this.dialogState.callId}},{key:"localTag",get:function(){return this.dialogState.localTag}},{key:"remoteTag",get:function(){return this.dialogState.remoteTag}},{key:"localSequenceNumber",get:function(){return this.dialogState.localSequenceNumber}},{key:"remoteSequenceNumber",get:function(){return this.dialogState.remoteSequenceNumber}},{key:"localURI",get:function(){return this.dialogState.localURI}},{key:"remoteURI",get:function(){return this.dialogState.remoteURI}},{key:"remoteTarget",get:function(){return this.dialogState.remoteTarget}},{key:"routeSet",get:function(){return this.dialogState.routeSet}},{key:"secure",get:function(){return this.dialogState.secure}},{key:"userAgentCore",get:function(){return this.core}},{key:"confirm",value:function(){this.dialogState.early=!1}},{key:"receiveRequest",value:function(e){if(e.method!==st.ACK){if(this.remoteSequenceNumber){if(e.cseq<=this.remoteSequenceNumber)throw new Error("Out of sequence in dialog request. Did you forget to call sequenceGuard()?");this.dialogState.remoteSequenceNumber=e.cseq}this.remoteSequenceNumber||(this.dialogState.remoteSequenceNumber=e.cseq)}}},{key:"recomputeRouteSet",value:function(e){var t;this.dialogState.routeSet=G(t=e.getHeaders("record-route")).call(t)}},{key:"createOutgoingRequestMessage",value:function(e,t){var n,i=this.remoteURI,r=this.remoteTag,s=this.localURI,a=this.localTag,o=this.callId;n=t&&t.cseq?t.cseq:this.dialogState.localSequenceNumber?this.dialogState.localSequenceNumber+=1:this.dialogState.localSequenceNumber=1;var c=this.remoteTarget,l=this.routeSet,u=t&&t.extraHeaders,d=t&&t.body;return this.userAgentCore.makeOutgoingRequestMessage(e,c,s,i,{callId:o,cseq:n,fromTag:a,toTag:r,routeSet:l},u,d)}},{key:"incrementLocalSequenceNumber",value:function(){if(!this.dialogState.localSequenceNumber)throw new Error("Local sequence number undefined.");this.dialogState.localSequenceNumber+=1}},{key:"sequenceGuard",value:function(e){return e.method===st.ACK||(!(this.remoteSequenceNumber&&e.cseq<=this.remoteSequenceNumber)||(this.core.replyStateless(e,{statusCode:500}),!1))}}],[{key:"initialDialogStateForUserAgentClient",value:function(e,t){var n,i=G(n=t.getHeaders("record-route")).call(n),r=t.parseHeader("contact");if(!r)throw new Error("Contact undefined.");if(!(r instanceof Se))throw new Error("Contact not instance of NameAddrHeader.");var s=r.uri,a=e.cseq,o=e.callId,c=e.fromTag,l=t.toTag;if(!o)throw new Error("Call id undefined.");if(!c)throw new Error("From tag undefined.");if(!l)throw new Error("To tag undefined.");if(!e.from)throw new Error("From undefined.");if(!e.to)throw new Error("To undefined.");var u=e.from.uri,d=e.to.uri;if(!t.statusCode)throw new Error("Incoming response status code undefined.");return{id:o+c+l,early:t.statusCode<200,callId:o,localTag:c,remoteTag:l,localSequenceNumber:a,remoteSequenceNumber:undefined,localURI:u,remoteURI:d,remoteTarget:s,routeSet:i,secure:!1}}},{key:"initialDialogStateForUserAgentServer",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=e.getHeaders("record-route"),r=e.parseHeader("contact");if(!r)throw new Error("Contact undefined.");if(!(r instanceof Se))throw new Error("Contact not instance of NameAddrHeader.");var s=r.uri,a=e.cseq,o=e.callId,c=t,l=e.fromTag,u=e.from.uri;return{id:o+c+l,early:n,callId:o,localTag:c,remoteTag:l,localSequenceNumber:undefined,remoteSequenceNumber:a,localURI:e.to.uri,remoteURI:u,remoteTarget:s,routeSet:i,secure:!1}}}])}();function Xt(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Xt=function(){return!!e})()}var Qt=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,u=n,h=[t,i,r,Lt.Calling,"sip.transaction.ict"],u=o(u),c=a(l,Xt()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"B",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"D",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"M",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"ackRetransmissionCache",{enumerable:!0,configurable:!0,writable:!0,value:new M}),c.B=m(function(){return c.timerB()},it.TIMER_B),c.send(t.toString()).catch(function(e){c.logTransportError(e,"Failed to send initial outgoing request.")}),c}return c(n,Yt),t(n,[{key:"dispose",value:function(){var e,t,i,r,s;this.B&&(clearTimeout(this.B),this.B=void 0),this.D&&(clearTimeout(this.D),this.D=void 0),this.M&&(clearTimeout(this.M),this.M=void 0),(e=n,t="dispose",i=this,s=v(o(1&(r=3)?e.prototype:e),t,i),2&r&&"function"==typeof s?function(e){return s.apply(i,e)}:s)([])}},{key:"kind",get:function(){return"ict"}},{key:"ackResponse",value:function(e){var t=this,n=e.toTag;if(!n)throw new Error("To tag undefined.");var i="z9hG4bK"+Math.floor(1e7*Math.random());e.setViaHeader(i,this.transport.protocol),this.ackRetransmissionCache.set(n,e),this.send(e.toString()).catch(function(e){t.logTransportError(e,"Failed to send ACK to 2xx response.")})}},{key:"receiveResponse",value:function(e){var t,n=this,i=e.statusCode;if(!i||i<100||i>699)throw new Error("Invalid status code ".concat(i));switch(this.state){case Lt.Calling:if(i>=100&&i<=199)return this.stateTransition(Lt.Proceeding),void(this.user.receiveResponse&&this.user.receiveResponse(e));if(i>=200&&i<=299)return this.ackRetransmissionCache.set(e.toTag,void 0),this.stateTransition(Lt.Accepted),void(this.user.receiveResponse&&this.user.receiveResponse(e));if(i>=300&&i<=699)return this.stateTransition(Lt.Completed),this.ack(e),void(this.user.receiveResponse&&this.user.receiveResponse(e));break;case Lt.Proceeding:if(i>=100&&i<=199)return void(this.user.receiveResponse&&this.user.receiveResponse(e));if(i>=200&&i<=299)return this.ackRetransmissionCache.set(e.toTag,void 0),this.stateTransition(Lt.Accepted),void(this.user.receiveResponse&&this.user.receiveResponse(e));if(i>=300&&i<=699)return this.stateTransition(Lt.Completed),this.ack(e),void(this.user.receiveResponse&&this.user.receiveResponse(e));break;case Lt.Accepted:if(i>=200&&i<=299){if(!this.ackRetransmissionCache.has(e.toTag))return this.ackRetransmissionCache.set(e.toTag,void 0),void(this.user.receiveResponse&&this.user.receiveResponse(e));var r=this.ackRetransmissionCache.get(e.toTag);return r?void this.send(r.toString()).catch(function(e){n.logTransportError(e,"Failed to send retransmission of ACK to 2xx response.")}):void 0}break;case Lt.Completed:if(i>=300&&i<=699)return void this.ack(e);break;case Lt.Terminated:break;default:throw new Error("Invalid state ".concat(this.state))}var s=E(t="Received unexpected ".concat(i," response while in state ")).call(t,this.state,".");this.logger.warn(s)}},{key:"onTransportError",value:function(e){this.user.onTransportError&&this.user.onTransportError(e),this.stateTransition(Lt.Terminated,!0)}},{key:"typeToString",value:function(){return"INVITE client transaction"}},{key:"ack",value:function(e){var t=this,n=this.request.ruri,i=this.request.callId,r=this.request.cseq,s=this.request.getHeader("from"),a=e.getHeader("to"),o=this.request.getHeader("via"),c=this.request.getHeader("route");if(!s)throw new Error("From undefined.");if(!a)throw new Error("To undefined.");if(!o)throw new Error("Via undefined.");var l="ACK ".concat(n," SIP/2.0\r\n");c&&(l+="Route: ".concat(c,"\r\n")),l+="Via: ".concat(o,"\r\n"),l+="To: ".concat(a,"\r\n"),l+="From: ".concat(s,"\r\n"),l+="Call-ID: ".concat(i,"\r\n"),l+="CSeq: ".concat(r," ACK\r\n"),l+="Max-Forwards: 70\r\n",l+="Content-Length: 0\r\n\r\n",this.send(l).catch(function(e){t.logTransportError(e,"Failed to send ACK to non-2xx response.")})}},{key:"stateTransition",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=function(){var n;throw new Error(E(n="Invalid state transition from ".concat(t.state," to ")).call(n,e))};switch(e){case Lt.Calling:i();break;case Lt.Proceeding:this.state!==Lt.Calling&&i();break;case Lt.Accepted:case Lt.Completed:this.state!==Lt.Calling&&this.state!==Lt.Proceeding&&i();break;case Lt.Terminated:this.state!==Lt.Calling&&this.state!==Lt.Accepted&&this.state!==Lt.Completed&&(n||i());break;default:i()}this.B&&(clearTimeout(this.B),this.B=void 0),Lt.Proceeding,e===Lt.Completed&&(this.D=m(function(){return t.timerD()},it.TIMER_D)),e===Lt.Accepted&&(this.M=m(function(){return t.timerM()},it.TIMER_M)),e===Lt.Terminated&&this.dispose(),this.setState(e)}},{key:"timerA",value:function(){}},{key:"timerB",value:function(){this.logger.debug("Timer B expired for INVITE client transaction ".concat(this.id,".")),this.state===Lt.Calling&&(this.onRequestTimeout(),this.stateTransition(Lt.Terminated))}},{key:"timerD",value:function(){this.logger.debug("Timer D expired for INVITE client transaction ".concat(this.id,".")),this.state===Lt.Completed&&this.stateTransition(Lt.Terminated)}},{key:"timerM",value:function(){this.logger.debug("Timer M expired for INVITE client transaction ".concat(this.id,".")),this.state===Lt.Accepted&&this.stateTransition(Lt.Terminated)}}])}(),en=function(){function n(t,i,r,s){e(this,n),d(this,"transactionConstructor",{enumerable:!0,configurable:!0,writable:!0,value:t}),d(this,"core",{enumerable:!0,configurable:!0,writable:!0,value:i}),d(this,"message",{enumerable:!0,configurable:!0,writable:!0,value:r}),d(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:s}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_transaction",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"credentials",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"challenged",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"stale",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this.logger=this.loggerFactory.getLogger("sip.user-agent-client"),this.init()}return t(n,[{key:"dispose",value:function(){this.transaction.dispose()}},{key:"loggerFactory",get:function(){return this.core.loggerFactory}},{key:"transaction",get:function(){if(!this._transaction)throw new Error("Transaction undefined.");return this._transaction}},{key:"cancel",value:function(e){var t=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!this.transaction)throw new Error("Transaction undefined.");if(!this.message.to)throw new Error("To undefined.");if(!this.message.from)throw new Error("From undefined.");var r=this.core.makeOutgoingRequestMessage(st.CANCEL,this.message.ruri,this.message.from.uri,this.message.to.uri,{toTag:this.message.toTag,fromTag:this.message.fromTag,callId:this.message.callId,cseq:this.message.cseq},i.extraHeaders);return r.branch=this.message.branch,this.message.headers.Route&&(r.headers.Route=this.message.headers.Route),e&&r.setHeader("Reason",e),this.transaction.state===Lt.Proceeding?new n(Zt,this.core,r):this.transaction.addStateChangeListener(function(){t.transaction&&t.transaction.state===Lt.Proceeding&&new n(Zt,t.core,r)},{once:!0}),r}},{key:"authenticationGuard",value:function(e,t){var n,i,r=e.statusCode;if(!r)throw new Error("Response status code undefined.");if(401!==r&&407!==r)return!0;if(401===r?(n=e.parseHeader("www-authenticate"),i="authorization"):(n=e.parseHeader("proxy-authenticate"),i="proxy-authorization"),!n)return this.logger.warn(r+" with wrong or missing challenge, cannot authenticate"),!0;if(this.challenged&&(this.stale||!0!==n.stale))return this.logger.warn(r+" apparently in authentication loop, cannot authenticate"),!0;if(!this.credentials&&(this.credentials=this.core.configuration.authenticationFactory(),!this.credentials))return this.logger.warn("Unable to obtain credentials, cannot authenticate"),!0;if(!this.credentials.authenticate(this.message,n))return!0;this.challenged=!0,n.stale&&(this.stale=!0);var s=this.message.cseq+=1;return t&&t.localSequenceNumber&&(t.incrementLocalSequenceNumber(),s=this.message.cseq=t.localSequenceNumber),this.message.setHeader("cseq",s+" "+this.message.method),this.message.setHeader(i,this.credentials.toString()),this.init(),!1}},{key:"onRequestTimeout",value:function(){this.logger.warn("User agent client request timed out. Generating internal 408 Request Timeout.");var e=new Ve;e.statusCode=408,e.reasonPhrase="Request Timeout",this.receiveResponse(e)}},{key:"onTransportError",value:function(e){this.logger.error(e.message),this.logger.error("User agent client request transport error. Generating internal 503 Service Unavailable.");var t=new Ve;t.statusCode=503,t.reasonPhrase="Service Unavailable",this.receiveResponse(t)}},{key:"receiveResponse",value:function(e){if(this.authenticationGuard(e)){var t=e.statusCode?e.statusCode.toString():"";if(!t)throw new Error("Response status code undefined.");switch(!0){case/^100$/.test(t):this.delegate&&this.delegate.onTrying&&this.delegate.onTrying({message:e});break;case/^1[0-9]{2}$/.test(t):this.delegate&&this.delegate.onProgress&&this.delegate.onProgress({message:e});break;case/^2[0-9]{2}$/.test(t):this.delegate&&this.delegate.onAccept&&this.delegate.onAccept({message:e});break;case/^3[0-9]{2}$/.test(t):this.delegate&&this.delegate.onRedirect&&this.delegate.onRedirect({message:e});break;case/^[4-6][0-9]{2}$/.test(t):this.delegate&&this.delegate.onReject&&this.delegate.onReject({message:e});break;default:throw new Error("Invalid status code ".concat(t))}}}},{key:"init",value:function(){var e=this,t={loggerFactory:this.loggerFactory,onRequestTimeout:function(){return e.onRequestTimeout()},onStateChange:function(t){t===Lt.Terminated&&(e.core.userAgentClients.delete(i),n===e._transaction&&e.dispose())},onTransportError:function(t){return e.onTransportError(t)},receiveResponse:function(t){return e.receiveResponse(t)}},n=new this.transactionConstructor(this.message,this.core.transport,t);this._transaction=n;var i=n.id+n.request.method;this.core.userAgentClients.set(i,this)}}])}();function tn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(tn=function(){return!!e})()}var nn=function(){function n(t,i,r){var c;e(this,n);var l,u,d,h=t.createOutgoingRequestMessage(st.BYE,r);return l=this,u=n,d=[Zt,t.userAgentCore,h,i],u=o(u),c=a(l,tn()?s(u,d||[],o(l).constructor):u.apply(l,d)),t.dispose(),c}return c(n,en),t(n)}();function rn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(rn=function(){return!!e})()}var sn=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,u=n,h=[t,i,r,Lt.Trying,"sip.transaction.nist"],u=o(u),c=a(l,rn()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"lastResponse",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"J",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c}return c(n,Gt),t(n,[{key:"dispose",value:function(){var e,t,i,r,s;this.J&&(clearTimeout(this.J),this.J=void 0),(e=n,t="dispose",i=this,s=v(o(1&(r=3)?e.prototype:e),t,i),2&r&&"function"==typeof s?function(e){return s.apply(i,e)}:s)([])}},{key:"kind",get:function(){return"nist"}},{key:"receiveRequest",value:function(e){var t=this;switch(this.state){case Lt.Trying:break;case Lt.Proceeding:if(!this.lastResponse)throw new Error("Last response undefined.");this.send(this.lastResponse).catch(function(e){t.logTransportError(e,"Failed to send retransmission of provisional response.")});break;case Lt.Completed:if(!this.lastResponse)throw new Error("Last response undefined.");this.send(this.lastResponse).catch(function(e){t.logTransportError(e,"Failed to send retransmission of final response.")});break;case Lt.Terminated:break;default:throw new Error("Invalid state ".concat(this.state))}}},{key:"receiveResponse",value:function(e,t){var n,i=this;if(e<100||e>699)throw new Error("Invalid status code ".concat(e));if(e>100&&e<=199)throw new Error("Provisional response other than 100 not allowed.");switch(this.state){case Lt.Trying:if(this.lastResponse=t,e>=100&&e<200)return this.stateTransition(Lt.Proceeding),void this.send(t).catch(function(e){i.logTransportError(e,"Failed to send provisional response.")});if(e>=200&&e<=699)return this.stateTransition(Lt.Completed),void this.send(t).catch(function(e){i.logTransportError(e,"Failed to send final response.")});break;case Lt.Proceeding:if(this.lastResponse=t,e>=200&&e<=699)return this.stateTransition(Lt.Completed),void this.send(t).catch(function(e){i.logTransportError(e,"Failed to send final response.")});break;case Lt.Completed:return;case Lt.Terminated:break;default:throw new Error("Invalid state ".concat(this.state))}var r=E(n="Non-INVITE server transaction received unexpected ".concat(e," response from TU while in state ")).call(n,this.state,".");throw this.logger.error(r),new Error(r)}},{key:"onTransportError",value:function(e){this.user.onTransportError&&this.user.onTransportError(e),this.stateTransition(Lt.Terminated,!0)}},{key:"typeToString",value:function(){return"non-INVITE server transaction"}},{key:"stateTransition",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=function(){var n;throw new Error(E(n="Invalid state transition from ".concat(t.state," to ")).call(n,e))};switch(e){case Lt.Trying:i();break;case Lt.Proceeding:this.state!==Lt.Trying&&i();break;case Lt.Completed:this.state!==Lt.Trying&&this.state!==Lt.Proceeding&&i();break;case Lt.Terminated:this.state!==Lt.Proceeding&&this.state!==Lt.Completed&&(n||i());break;default:i()}e===Lt.Completed&&(this.J=m(function(){return t.timerJ()},it.TIMER_J)),e===Lt.Terminated&&this.dispose(),this.setState(e)}},{key:"timerJ",value:function(){this.logger.debug("Timer J expired for NON-INVITE server transaction ".concat(this.id,".")),this.state===Lt.Completed&&this.stateTransition(Lt.Terminated)}}])}(),an=function(){return t(function t(n,i,r,s){e(this,t),d(this,"transactionConstructor",{enumerable:!0,configurable:!0,writable:!0,value:n}),d(this,"core",{enumerable:!0,configurable:!0,writable:!0,value:i}),d(this,"message",{enumerable:!0,configurable:!0,writable:!0,value:r}),d(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:s}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"toTag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_transaction",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.logger=this.loggerFactory.getLogger("sip.user-agent-server"),this.toTag=r.toTag?r.toTag:Pe(),this.init()},[{key:"dispose",value:function(){this.transaction.dispose()}},{key:"loggerFactory",get:function(){return this.core.loggerFactory}},{key:"transaction",get:function(){if(!this._transaction)throw new Error("Transaction undefined.");return this._transaction}},{key:"accept",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:200};if(!this.acceptable)throw new at(E(e="".concat(this.message.method," not acceptable in state ")).call(e,this.transaction.state,"."));var n=t.statusCode;if(n<200||n>299)throw new TypeError("Invalid statusCode: ".concat(n));return this.reply(t)}},{key:"progress",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:180};if(!this.progressable)throw new at(E(e="".concat(this.message.method," not progressable in state ")).call(e,this.transaction.state,"."));var n=t.statusCode;if(n<101||n>199)throw new TypeError("Invalid statusCode: ".concat(n));return this.reply(t)}},{key:"redirect",value:function(e){var t,n,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{statusCode:302};if(!this.redirectable)throw new at(E(n="".concat(this.message.method," not redirectable in state ")).call(n,this.transaction.state,"."));var r=i.statusCode;if(r<300||r>399)throw new TypeError("Invalid statusCode: ".concat(r));var s=new Array;return h(e).call(e,function(e){return s.push("Contact: ".concat(e.toString()))}),i.extraHeaders=E(t=i.extraHeaders||[]).call(t,s),this.reply(i)}},{key:"reject",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:480};if(!this.rejectable)throw new at(E(e="".concat(this.message.method," not rejectable in state ")).call(e,this.transaction.state,"."));var n=t.statusCode;if(n<400||n>699)throw new TypeError("Invalid statusCode: ".concat(n));return this.reply(t)}},{key:"trying",value:function(e){var t;if(!this.tryingable)throw new at(E(t="".concat(this.message.method," not tryingable in state ")).call(t,this.transaction.state,"."));return this.reply({statusCode:100})}},{key:"receiveCancel",value:function(e){this.delegate&&this.delegate.onCancel&&this.delegate.onCancel(e)}},{key:"acceptable",get:function(){if(this.transaction instanceof Wt)return this.transaction.state===Lt.Proceeding||this.transaction.state===Lt.Accepted;if(this.transaction instanceof sn)return this.transaction.state===Lt.Trying||this.transaction.state===Lt.Proceeding;throw new Error("Unknown transaction type.")}},{key:"progressable",get:function(){if(this.transaction instanceof Wt)return this.transaction.state===Lt.Proceeding;if(this.transaction instanceof sn)return!1;throw new Error("Unknown transaction type.")}},{key:"redirectable",get:function(){if(this.transaction instanceof Wt)return this.transaction.state===Lt.Proceeding;if(this.transaction instanceof sn)return this.transaction.state===Lt.Trying||this.transaction.state===Lt.Proceeding;throw new Error("Unknown transaction type.")}},{key:"rejectable",get:function(){if(this.transaction instanceof Wt)return this.transaction.state===Lt.Proceeding;if(this.transaction instanceof sn)return this.transaction.state===Lt.Trying||this.transaction.state===Lt.Proceeding;throw new Error("Unknown transaction type.")}},{key:"tryingable",get:function(){if(this.transaction instanceof Wt)return this.transaction.state===Lt.Proceeding;if(this.transaction instanceof sn)return this.transaction.state===Lt.Trying;throw new Error("Unknown transaction type.")}},{key:"reply",value:function(e){e.toTag||100===e.statusCode||(e.toTag=this.toTag),e.userAgent=e.userAgent||this.core.configuration.userAgentHeaderFieldValue,e.supported=e.supported||this.core.configuration.supportedOptionTagsResponse;var t=Nt(this.message,e);return this.transaction.receiveResponse(e.statusCode,t.message),t}},{key:"init",value:function(){var e=this,t={loggerFactory:this.loggerFactory,onStateChange:function(t){t===Lt.Terminated&&(e.core.userAgentServers.delete(i),e.dispose())},onTransportError:function(t){e.logger.error(t.message),e.delegate&&e.delegate.onTransportError?e.delegate.onTransportError(t):e.logger.error("User agent server response transport error.")}},n=new this.transactionConstructor(this.message,this.core.transport,t);this._transaction=n;var i=n.id;this.core.userAgentServers.set(n.id,this)}}])}();function on(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(on=function(){return!!e})()}var cn=function(){function n(t,i,r){return e(this,n),c=this,l=n,u=[sn,t.userAgentCore,i,r],l=o(l),a(c,on()?s(l,u||[],o(c).constructor):l.apply(c,u));var c,l,u}return c(n,an),t(n)}();function ln(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(ln=function(){return!!e})()}var un=function(){function n(t,i,r){e(this,n);var c,l,u,d=t.createOutgoingRequestMessage(st.INFO,r);return c=this,l=n,u=[Zt,t.userAgentCore,d,i],l=o(l),a(c,ln()?s(l,u||[],o(c).constructor):l.apply(c,u))}return c(n,en),t(n)}();function dn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(dn=function(){return!!e})()}var hn=function(){function n(t,i,r){return e(this,n),c=this,l=n,u=[sn,t.userAgentCore,i,r],l=o(l),a(c,dn()?s(l,u||[],o(c).constructor):l.apply(c,u));var c,l,u}return c(n,an),t(n)}();function gn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(gn=function(){return!!e})()}var fn=function(){function n(t,i,r){return e(this,n),c=this,u=[Zt,t,i,r],l=o(l=n),a(c,gn()?s(l,u||[],o(c).constructor):l.apply(c,u));var c,l,u}return c(n,en),t(n)}();function vn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(vn=function(){return!!e})()}var pn=function(){function n(t,i,r){return e(this,n),c=this,u=[sn,t,i,r],l=o(l=n),a(c,vn()?s(l,u||[],o(c).constructor):l.apply(c,u));var c,l,u}return c(n,an),t(n)}();function mn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(mn=function(){return!!e})()}var bn=function(){function n(t,i,r){e(this,n);var c,l,u,d=t.createOutgoingRequestMessage(st.NOTIFY,r);return c=this,l=n,u=[Zt,t.userAgentCore,d,i],l=o(l),a(c,mn()?s(l,u||[],o(c).constructor):l.apply(c,u))}return c(n,en),t(n)}();function yn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(yn=function(){return!!e})()}var wn=function(){function n(t,i,r){e(this,n);var c,l,u,d=void 0!==t.userAgentCore?t.userAgentCore:t;return c=this,u=[sn,d,i,r],l=o(l=n),a(c,yn()?s(l,u||[],o(c).constructor):l.apply(c,u))}return c(n,an),t(n)}();function kn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(kn=function(){return!!e})()}var Tn=function(){function n(t,i,r){var c;e(this,n);var l,u,d,h=t.createOutgoingRequestMessage(st.PRACK,r);return l=this,u=n,d=[Zt,t.userAgentCore,h,i],u=o(u),c=a(l,kn()?s(u,d||[],o(l).constructor):u.apply(l,d)),t.signalingStateTransition(h),c}return c(n,en),t(n)}();function Rn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Rn=function(){return!!e})()}var Sn=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,u=n,h=[sn,t.userAgentCore,i,r],u=o(u),c=a(l,Rn()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"dialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),t.signalingStateTransition(i),c.dialog=t,c}return c(n,an),t(n,[{key:"accept",value:function(){var e,t,i,r,s,a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:200};return a.body&&this.dialog.signalingStateTransition(a.body),(e=n,t="accept",i=this,s=v(o(1&(r=3)?e.prototype:e),t,i),2&r&&"function"==typeof s?function(e){return s.apply(i,e)}:s)([a])}}])}();function In(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(In=function(){return!!e})()}var En=function(){function n(t,i,r){var c;e(this,n);var l,u,h,g=t.createOutgoingRequestMessage(st.INVITE,r);return l=this,u=n,h=[Qt,t.userAgentCore,g,i],u=o(u),c=a(l,In()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"dialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c.delegate=i,t.signalingStateTransition(g),t.reinviteUserAgentClient=c,c.dialog=t,c}return c(n,en),t(n,[{key:"receiveResponse",value:function(e){var t=this;if(this.authenticationGuard(e,this.dialog)){var n=e.statusCode?e.statusCode.toString():"";if(!n)throw new Error("Response status code undefined.");switch(!0){case/^100$/.test(n):this.delegate&&this.delegate.onTrying&&this.delegate.onTrying({message:e});break;case/^1[0-9]{2}$/.test(n):this.delegate&&this.delegate.onProgress&&this.delegate.onProgress({message:e,session:this.dialog,prack:function(e){throw new Error("Unimplemented.")}});break;case/^2[0-9]{2}$/.test(n):this.dialog.signalingStateTransition(e),this.delegate&&this.delegate.onAccept&&this.delegate.onAccept({message:e,session:this.dialog,ack:function(e){return t.dialog.ack(e)}});break;case/^3[0-9]{2}$/.test(n):this.dialog.signalingStateRollback(),this.dialog.reinviteUserAgentClient=void 0,this.delegate&&this.delegate.onRedirect&&this.delegate.onRedirect({message:e});break;case/^[4-6][0-9]{2}$/.test(n):this.dialog.signalingStateRollback(),this.dialog.reinviteUserAgentClient=void 0,this.delegate&&this.delegate.onReject&&this.delegate.onReject({message:e});break;default:throw new Error("Invalid status code ".concat(n))}}}}])}();function Cn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Cn=function(){return!!e})()}function An(e,t,n,i){var r=v(o(1&i?e.prototype:e),t,n);return 2&i&&"function"==typeof r?function(e){return r.apply(n,e)}:r}var xn=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,u=n,h=[Wt,t.userAgentCore,i,r],u=o(u),c=a(l,Cn()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"dialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),t.reinviteUserAgentServer=c,c.dialog=t,c}return c(n,an),t(n,[{key:"accept",value:function(){var e,t,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:200};i.extraHeaders=i.extraHeaders||[],i.extraHeaders=E(e=i.extraHeaders).call(e,y(t=this.dialog.routeSet).call(t,function(e){return"Record-Route: ".concat(e)}));var r=An(n,"accept",this,3)([i]),s=this.dialog,a=$($({},r),{session:s});return i.body&&this.dialog.signalingStateTransition(i.body),this.dialog.reConfirm(),a}},{key:"progress",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:180},t=An(n,"progress",this,3)([e]),i=this.dialog,r=$($({},t),{session:i});return e.body&&this.dialog.signalingStateTransition(e.body),r}},{key:"redirect",value:function(e){throw this.dialog.signalingStateRollback(),this.dialog.reinviteUserAgentServer=void 0,new Error("Unimplemented.")}},{key:"reject",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:488};return this.dialog.signalingStateRollback(),this.dialog.reinviteUserAgentServer=void 0,An(n,"reject",this,3)([e])}}])}();function Dn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Dn=function(){return!!e})()}var Hn=function(){function n(t,i,r){e(this,n);var c,l,u,d=t.createOutgoingRequestMessage(st.REFER,r);return c=this,l=n,u=[Zt,t.userAgentCore,d,i],l=o(l),a(c,Dn()?s(l,u||[],o(c).constructor):l.apply(c,u))}return c(n,en),t(n)}();function _n(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(_n=function(){return!!e})()}var $n=function(){function n(t,i,r){e(this,n);var c,l,u,d=void 0!==t.userAgentCore?t.userAgentCore:t;return c=this,u=[sn,d,i,r],l=o(l=n),a(c,_n()?s(l,u||[],o(c).constructor):l.apply(c,u))}return c(n,an),t(n)}();function qn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(qn=function(){return!!e})()}function Mn(e,t,n,i){var r=v(o(1&i?e.prototype:e),t,n);return 2&i&&"function"==typeof r?function(e){return r.apply(n,e)}:r}var Pn=function(){function n(t,i,r,c){var l,u,h,g;return e(this,n),u=this,g=[i,r],h=o(h=n),l=a(u,qn()?s(h,g||[],o(u).constructor):h.apply(u,g)),d(l,"initialTransaction",{enumerable:!0,configurable:!0,writable:!0,value:t}),d(l,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"reinviteUserAgentClient",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"reinviteUserAgentServer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"_signalingState",{enumerable:!0,configurable:!0,writable:!0,value:ze.Initial}),d(l,"_offer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"_answer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"_rollbackOffer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"_rollbackAnswer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"ackWait",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(l,"ackProcessing",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(l,"invite2xxTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"rseq",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(l,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),l.delegate=c,t instanceof Wt&&(l.ackWait=!0),l.early||l.start2xxRetransmissionTimer(),l.signalingStateTransition(t.request),l.logger=i.loggerFactory.getLogger("sip.invite-dialog"),l.logger.log("INVITE dialog ".concat(l.id," constructed")),l}return c(n,Jt),t(n,[{key:"dispose",value:function(){Mn(n,"dispose",this,3)([]),this._signalingState=ze.Closed,this._offer=void 0,this._answer=void 0,this.invite2xxTimer&&(clearTimeout(this.invite2xxTimer),this.invite2xxTimer=void 0),this.logger.log("INVITE dialog ".concat(this.id," destroyed"))}},{key:"sessionState",get:function(){return this.early?Ye.Early:this.ackWait?Ye.AckWait:this._signalingState===ze.Closed?Ye.Terminated:Ye.Confirmed}},{key:"signalingState",get:function(){return this._signalingState}},{key:"offer",get:function(){return this._offer}},{key:"answer",get:function(){return this._answer}},{key:"confirm",value:function(){this.early&&this.start2xxRetransmissionTimer(),Mn(n,"confirm",this,3)([])}},{key:"reConfirm",value:function(){this.reinviteUserAgentServer&&this.startReInvite2xxRetransmissionTimer()}},{key:"ack",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.logger.log("INVITE dialog ".concat(this.id," sending ACK request")),this.reinviteUserAgentClient){if(!(this.reinviteUserAgentClient.transaction instanceof Qt))throw new Error("Transaction not instance of InviteClientTransaction.");e=this.reinviteUserAgentClient.transaction,this.reinviteUserAgentClient=void 0}else{if(!(this.initialTransaction instanceof Qt))throw new Error("Initial transaction not instance of InviteClientTransaction.");e=this.initialTransaction}var n=this.createOutgoingRequestMessage(st.ACK,{cseq:e.request.cseq,extraHeaders:t.extraHeaders,body:t.body});return e.ackResponse(n),this.signalingStateTransition(n),{message:n}}},{key:"bye",value:function(e,t){if(this.logger.log("INVITE dialog ".concat(this.id," sending BYE request")),this.initialTransaction instanceof Wt){if(this.early)throw new Error("UAS MUST NOT send a BYE on early dialogs.");if(this.ackWait&&this.initialTransaction.state!==Lt.Terminated)throw new Error("UAS MUST NOT send a BYE on a confirmed dialog until it has received an ACK for its 2xx response or until the server transaction times out.")}return new nn(this,e,t)}},{key:"info",value:function(e,t){if(this.logger.log("INVITE dialog ".concat(this.id," sending INFO request")),this.early)throw new Error("Dialog not confirmed.");return new un(this,e,t)}},{key:"invite",value:function(e,t){if(this.logger.log("INVITE dialog ".concat(this.id," sending INVITE request")),this.early)throw new Error("Dialog not confirmed.");if(this.reinviteUserAgentClient)throw new Error("There is an ongoing re-INVITE client transaction.");if(this.reinviteUserAgentServer)throw new Error("There is an ongoing re-INVITE server transaction.");return new En(this,e,t)}},{key:"message",value:function(e,t){if(this.logger.log("INVITE dialog ".concat(this.id," sending MESSAGE request")),this.early)throw new Error("Dialog not confirmed.");var n=this.createOutgoingRequestMessage(st.MESSAGE,t);return new fn(this.core,n,e)}},{key:"notify",value:function(e,t){if(this.logger.log("INVITE dialog ".concat(this.id," sending NOTIFY request")),this.early)throw new Error("Dialog not confirmed.");return new bn(this,e,t)}},{key:"prack",value:function(e,t){return this.logger.log("INVITE dialog ".concat(this.id," sending PRACK request")),new Tn(this,e,t)}},{key:"refer",value:function(e,t){if(this.logger.log("INVITE dialog ".concat(this.id," sending REFER request")),this.early)throw new Error("Dialog not confirmed.");return new Hn(this,e,t)}},{key:"receiveRequest",value:function(e){var t,r=this;if(this.logger.log(E(t="INVITE dialog ".concat(this.id," received ")).call(t,e.method," request")),e.method!==st.ACK)if(this.sequenceGuard(e)){if(Mn(n,"receiveRequest",this,3)([e]),e.method===st.INVITE){var s=function(){var e,t=r.ackWait?"waiting for initial ACK":"processing initial ACK";r.logger.warn(E(e="INVITE dialog ".concat(r.id," received re-INVITE while ")).call(e,t));r.logger.warn("RFC 5407 suggests the following to avoid this race condition... Note: Implementation issues are outside the scope of this document, but the following tip is provided for avoiding race conditions of this type. The caller can delay sending re-INVITE F6 for some period of time (2 seconds, perhaps), after which the caller can reasonably assume that its ACK has been received. Implementors can decouple the actions of the user (e.g., pressing the hold button) from the actions of the protocol (the sending of re-INVITE F6), so that the UA can behave like this. In this case, it is the implementor's choice as to how long to wait. In most cases, such an implementation may be useful to prevent the type of race condition shown in this section. This document expresses no preference about whether or not they should wait for an ACK to be delivered. After considering the impact on user experience, implementors should decide whether or not to wait for a while, because the user experience depends on the implementation and has no direct bearing on protocol behavior.")},a=Math.floor(10*Math.random())+1,o=["Retry-After: ".concat(a)];if(this.ackProcessing)return this.core.replyStateless(e,{statusCode:500,extraHeaders:o}),void s();if(this.ackWait&&this.signalingState!==ze.Stable)return this.core.replyStateless(e,{statusCode:500,extraHeaders:o}),void s();if(this.reinviteUserAgentServer)return void this.core.replyStateless(e,{statusCode:500,extraHeaders:o});if(this.reinviteUserAgentClient)return void this.core.replyStateless(e,{statusCode:491})}if(e.method===st.INVITE){var c=e.parseHeader("contact");if(!c)throw new Error("Contact undefined.");if(!(c instanceof Se))throw new Error("Contact not instance of NameAddrHeader.");this.dialogState.remoteTarget=c.uri}switch(e.method){case st.BYE:var l=new cn(this,e);this.delegate&&this.delegate.onBye?this.delegate.onBye(l):l.accept(),this.dispose();break;case st.INFO:var u=new hn(this,e);this.delegate&&this.delegate.onInfo?this.delegate.onInfo(u):u.reject({statusCode:469,extraHeaders:["Recv-Info:"]});break;case st.INVITE:var d=new xn(this,e);this.signalingStateTransition(e),this.delegate&&this.delegate.onInvite?this.delegate.onInvite(d):d.reject({statusCode:488});break;case st.MESSAGE:var h=new pn(this.core,e);this.delegate&&this.delegate.onMessage?this.delegate.onMessage(h):h.accept();break;case st.NOTIFY:var g=new wn(this,e);this.delegate&&this.delegate.onNotify?this.delegate.onNotify(g):g.accept();break;case st.PRACK:var f=new Sn(this,e);this.delegate&&this.delegate.onPrack?this.delegate.onPrack(f):f.accept();break;case st.REFER:var v=new $n(this,e);this.delegate&&this.delegate.onRefer?this.delegate.onRefer(v):v.reject();break;default:var p;this.logger.log(E(p="INVITE dialog ".concat(this.id," received unimplemented ")).call(p,e.method," request")),this.core.replyStateless(e,{statusCode:501})}}else{var m;this.logger.log(E(m="INVITE dialog ".concat(this.id," rejected out of order ")).call(m,e.method," request."))}else{if(this.ackWait){var b,y;if(this.initialTransaction instanceof Qt)return void this.logger.warn(E(b="INVITE dialog ".concat(this.id," received unexpected ")).call(b,e.method," request, dropping."));if(this.initialTransaction.request.cseq!==e.cseq)return void this.logger.warn(E(y="INVITE dialog ".concat(this.id," received unexpected ")).call(y,e.method," request, dropping."));this.ackWait=!1}else{var w,k;if(!this.reinviteUserAgentServer)return void this.logger.warn(E(w="INVITE dialog ".concat(this.id," received unexpected ")).call(w,e.method," request, dropping."));if(this.reinviteUserAgentServer.transaction.request.cseq!==e.cseq)return void this.logger.warn(E(k="INVITE dialog ".concat(this.id," received unexpected ")).call(k,e.method," request, dropping."));this.reinviteUserAgentServer=void 0}if(this.signalingStateTransition(e),this.delegate&&this.delegate.onAck){var T=this.delegate.onAck({message:e});T instanceof i&&(this.ackProcessing=!0,T.then(function(){return r.ackProcessing=!1}).catch(function(){return r.ackProcessing=!1}))}}}},{key:"reliableSequenceGuard",value:function(e){var t=e.statusCode;if(!t)throw new Error("Status code undefined");if(t>100&&t<200){var n=e.getHeader("require"),i=e.getHeader("rseq"),r=n&&p(n).call(n,"100rel")&&i?Number(i):void 0;if(r){if(this.rseq&&this.rseq+1!==r)return!1;this.rseq=this.rseq?this.rseq+1:r}}return!0}},{key:"signalingStateRollback",value:function(){this._signalingState!==ze.HaveLocalOffer&&this.signalingState!==ze.HaveRemoteOffer||this._rollbackOffer&&this._rollbackAnswer&&(this._signalingState=ze.Stable,this._offer=this._rollbackOffer,this._answer=this._rollbackAnswer)}},{key:"signalingStateTransition",value:function(e){var t=et(e);if(t&&"session"===t.contentDisposition){if(this._signalingState===ze.Stable&&(this._rollbackOffer=this._offer,this._rollbackAnswer=this._answer),e instanceof Le)switch(this._signalingState){case ze.Initial:case ze.Stable:this._signalingState=ze.HaveRemoteOffer,this._offer=t,this._answer=void 0;break;case ze.HaveLocalOffer:this._signalingState=ze.Stable,this._answer=t;break;case ze.HaveRemoteOffer:case ze.Closed:break;default:throw new Error("Unexpected signaling state.")}if(e instanceof Ve)switch(this._signalingState){case ze.Initial:case ze.Stable:this._signalingState=ze.HaveRemoteOffer,this._offer=t,this._answer=void 0;break;case ze.HaveLocalOffer:this._signalingState=ze.Stable,this._answer=t;break;case ze.HaveRemoteOffer:case ze.Closed:break;default:throw new Error("Unexpected signaling state.")}if(e instanceof Ze)switch(this._signalingState){case ze.Initial:case ze.Stable:this._signalingState=ze.HaveLocalOffer,this._offer=t,this._answer=void 0;break;case ze.HaveLocalOffer:break;case ze.HaveRemoteOffer:this._signalingState=ze.Stable,this._answer=t;break;case ze.Closed:break;default:throw new Error("Unexpected signaling state.")}if(Qe(e))switch(this._signalingState){case ze.Initial:case ze.Stable:this._signalingState=ze.HaveLocalOffer,this._offer=t,this._answer=void 0;break;case ze.HaveLocalOffer:break;case ze.HaveRemoteOffer:this._signalingState=ze.Stable,this._answer=t;break;case ze.Closed:break;default:throw new Error("Unexpected signaling state.")}}}},{key:"start2xxRetransmissionTimer",value:function(){var e=this;if(this.initialTransaction instanceof Wt){var t=this.initialTransaction,n=it.T1,i=function(){e.ackWait?(e.logger.log("No ACK for 2xx response received, attempting retransmission"),t.retransmitAcceptedResponse(),n=Math.min(2*n,it.T2),e.invite2xxTimer=m(i,n)):e.invite2xxTimer=void 0};this.invite2xxTimer=m(i,n);var r=function(){t.state===Lt.Terminated&&(t.removeStateChangeListener(r),e.invite2xxTimer&&(clearTimeout(e.invite2xxTimer),e.invite2xxTimer=void 0),e.ackWait&&(e.delegate&&e.delegate.onAckTimeout?e.delegate.onAckTimeout():e.bye()))};t.addStateChangeListener(r)}}},{key:"startReInvite2xxRetransmissionTimer",value:function(){var e=this;if(this.reinviteUserAgentServer&&this.reinviteUserAgentServer.transaction instanceof Wt){var t=this.reinviteUserAgentServer.transaction,n=it.T1,i=function(){e.reinviteUserAgentServer?(e.logger.log("No ACK for 2xx response received, attempting retransmission"),t.retransmitAcceptedResponse(),n=Math.min(2*n,it.T2),e.invite2xxTimer=m(i,n)):e.invite2xxTimer=void 0};this.invite2xxTimer=m(i,n);var r=function(){t.state===Lt.Terminated&&(t.removeStateChangeListener(r),e.invite2xxTimer&&(clearTimeout(e.invite2xxTimer),e.invite2xxTimer=void 0),e.reinviteUserAgentServer)};t.addStateChangeListener(r)}}}])}();function On(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(On=function(){return!!e})()}function Nn(e,t,n,i){var r=v(o(1&i?e.prototype:e),t,n);return 2&i&&"function"==typeof r?function(e){return r.apply(n,e)}:r}var jn=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,h=[Qt,t,i,r],u=o(u=n),c=a(l,On()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"confirmedDialogAcks",{enumerable:!0,configurable:!0,writable:!0,value:new M}),d(c,"confirmedDialogs",{enumerable:!0,configurable:!0,writable:!0,value:new M}),d(c,"earlyDialogs",{enumerable:!0,configurable:!0,writable:!0,value:new M}),c.delegate=r,c}return c(n,en),t(n,[{key:"dispose",value:function(){var e;h(e=this.earlyDialogs).call(e,function(e){return e.dispose()}),this.earlyDialogs.clear(),Nn(n,"dispose",this,3)([])}},{key:"onTransportError",value:function(e){if(this.transaction.state===Lt.Calling)return Nn(n,"onTransportError",this,3)([e]);this.logger.error(e.message),this.logger.error("User agent client request transport error while sending ACK.")}},{key:"receiveResponse",value:function(e){var t,n,i=this;if(this.authenticationGuard(e)){var r=e.statusCode?e.statusCode.toString():"";if(!r)throw new Error("Response status code undefined.");switch(!0){case/^100$/.test(r):return void(this.delegate&&this.delegate.onTrying&&this.delegate.onTrying({message:e}));case/^1[0-9]{2}$/.test(r):if(!e.toTag)return void this.logger.warn("Non-100 1xx INVITE response received without a to tag, dropping.");if(!e.parseHeader("contact"))return void this.logger.error("Non-100 1xx INVITE response received without a Contact header field, dropping.");var s=Jt.initialDialogStateForUserAgentClient(this.message,e),a=this.earlyDialogs.get(s.id);if(!a){var o=this.transaction;if(!(o instanceof Qt))throw new Error("Transaction not instance of InviteClientTransaction.");a=new Pn(o,this.core,s),this.earlyDialogs.set(a.id,a)}if(!a.reliableSequenceGuard(e))return void this.logger.warn("1xx INVITE reliable response received out of order or is a retransmission, dropping.");a.signalingState!==ze.Initial&&a.signalingState!==ze.HaveLocalOffer||a.signalingStateTransition(e);var c=a;return void(this.delegate&&this.delegate.onProgress&&this.delegate.onProgress({message:e,session:c,prack:function(e){return c.prack(void 0,e)}}));case/^2[0-9]{2}$/.test(r):if(!e.toTag)return void this.logger.error("2xx INVITE response received without a to tag, dropping.");if(!e.parseHeader("contact"))return void this.logger.error("2xx INVITE response received without a Contact header field, dropping.");var l=Jt.initialDialogStateForUserAgentClient(this.message,e),u=this.confirmedDialogs.get(l.id);if(u){var d=this.confirmedDialogAcks.get(l.id);if(d){var g=this.transaction;if(!(g instanceof Qt))throw new Error("Client transaction not instance of InviteClientTransaction.");g.ackResponse(d.message)}return}if(u=this.earlyDialogs.get(l.id))u.confirm(),u.recomputeRouteSet(e),this.earlyDialogs.delete(u.id),this.confirmedDialogs.set(u.id,u);else{var f=this.transaction;if(!(f instanceof Qt))throw new Error("Transaction not instance of InviteClientTransaction.");u=new Pn(f,this.core,l),this.confirmedDialogs.set(u.id,u)}u.signalingState!==ze.Initial&&u.signalingState!==ze.HaveLocalOffer||u.signalingStateTransition(e);var v=u;if(this.delegate&&this.delegate.onAccept)this.delegate.onAccept({message:e,session:v,ack:function(e){var t=v.ack(e);return i.confirmedDialogAcks.set(v.id,t),t}});else{var p=v.ack();this.confirmedDialogAcks.set(v.id,p)}return;case/^3[0-9]{2}$/.test(r):return h(t=this.earlyDialogs).call(t,function(e){return e.dispose()}),this.earlyDialogs.clear(),void(this.delegate&&this.delegate.onRedirect&&this.delegate.onRedirect({message:e}));case/^[4-6][0-9]{2}$/.test(r):return h(n=this.earlyDialogs).call(n,function(e){return e.dispose()}),this.earlyDialogs.clear(),void(this.delegate&&this.delegate.onReject&&this.delegate.onReject({message:e}));default:throw new Error("Invalid status code ".concat(r))}}}}])}();function Fn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Fn=function(){return!!e})()}function Un(e,t,n,i){var r=v(o(1&i?e.prototype:e),t,n);return 2&i&&"function"==typeof r?function(e){return r.apply(n,e)}:r}var Bn=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,h=[Wt,t,i,r],u=o(u=n),c=a(l,Fn()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"core",{enumerable:!0,configurable:!0,writable:!0,value:t}),d(c,"confirmedDialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"earlyDialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c}return c(n,an),t(n,[{key:"dispose",value:function(){this.earlyDialog&&this.earlyDialog.dispose(),Un(n,"dispose",this,3)([])}},{key:"accept",value:function(){var e,t,i,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:200};if(!this.acceptable)throw new at(E(i="".concat(this.message.method," not acceptable in state ")).call(i,this.transaction.state,"."));if(!this.confirmedDialog)if(this.earlyDialog)this.earlyDialog.confirm(),this.confirmedDialog=this.earlyDialog,this.earlyDialog=void 0;else{var s=this.transaction;if(!(s instanceof Wt))throw new Error("Transaction not instance of InviteClientTransaction.");var a=Jt.initialDialogStateForUserAgentServer(this.message,this.toTag);this.confirmedDialog=new Pn(s,this.core,a)}var o=y(e=this.message.getHeaders("record-route")).call(e,function(e){return"Record-Route: ".concat(e)}),c="Contact: ".concat(this.core.configuration.contact.toString()),l="Allow: "+ct.toString();if(!r.body)if(this.confirmedDialog.signalingState===ze.Stable)r.body=this.confirmedDialog.answer;else if(this.confirmedDialog.signalingState===ze.Initial||this.confirmedDialog.signalingState===ze.HaveRemoteOffer)throw new Error("Response must have a body.");r.statusCode=r.statusCode||200,r.extraHeaders=r.extraHeaders||[],r.extraHeaders=E(t=r.extraHeaders).call(t,o),r.extraHeaders.push(l),r.extraHeaders.push(c);var u=Un(n,"accept",this,3)([r]),d=this.confirmedDialog,h=$($({},u),{session:d});return r.body&&this.confirmedDialog.signalingState!==ze.Stable&&this.confirmedDialog.signalingStateTransition(r.body),h}},{key:"progress",value:function(){var e,t,i,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:180};if(!this.progressable)throw new at(E(i="".concat(this.message.method," not progressable in state ")).call(i,this.transaction.state,"."));if(!this.earlyDialog){var s=this.transaction;if(!(s instanceof Wt))throw new Error("Transaction not instance of InviteClientTransaction.");var a=Jt.initialDialogStateForUserAgentServer(this.message,this.toTag,!0);this.earlyDialog=new Pn(s,this.core,a)}var o=y(e=this.message.getHeaders("record-route")).call(e,function(e){return"Record-Route: ".concat(e)}),c="Contact: ".concat(this.core.configuration.contact);r.extraHeaders=r.extraHeaders||[],r.extraHeaders=E(t=r.extraHeaders).call(t,o),r.extraHeaders.push(c);var l=Un(n,"progress",this,3)([r]),u=this.earlyDialog,d=$($({},l),{session:u});return r.body&&this.earlyDialog.signalingState!==ze.Stable&&this.earlyDialog.signalingStateTransition(r.body),d}},{key:"redirect",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{statusCode:302};return Un(n,"redirect",this,3)([e,t])}},{key:"reject",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{statusCode:486};return Un(n,"reject",this,3)([e])}}])}();function Ln(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Ln=function(){return!!e})()}var Gn=function(){function n(t,i,r){return e(this,n),c=this,u=[Zt,t,i,r],l=o(l=n),a(c,Ln()?s(l,u||[],o(c).constructor):l.apply(c,u));var c,l,u}return c(n,en),t(n)}();function Vn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Vn=function(){return!!e})()}var Wn=function(){function n(t,i,r){return e(this,n),c=this,u=[Zt,t,i,r],l=o(l=n),a(c,Vn()?s(l,u||[],o(c).constructor):l.apply(c,u));var c,l,u}return c(n,en),t(n)}();function Kn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Kn=function(){return!!e})()}var Yn=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,h=[sn,t,i,r],u=o(u=n),c=a(l,Kn()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"core",{enumerable:!0,configurable:!0,writable:!0,value:t}),c}return c(n,an),t(n)}();function zn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(zn=function(){return!!e})()}var Zn=function(){function n(t,i,r){var c;e(this,n);var l,u,h,g=t.createOutgoingRequestMessage(st.SUBSCRIBE,r);return l=this,u=n,h=[Zt,t.userAgentCore,g,i],u=o(u),c=a(l,zn()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"dialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c.dialog=t,c}return c(n,en),t(n,[{key:"waitNotifyStop",value:function(){}},{key:"receiveResponse",value:function(e){if(e.statusCode&&e.statusCode>=200&&e.statusCode<300){var t=e.getHeader("Expires");if(t){var i=Number(t);this.dialog.subscriptionExpires>i&&(this.dialog.subscriptionExpires=i)}else this.logger.warn("Expires header missing in a 200-class response to SUBSCRIBE")}if(e.statusCode&&e.statusCode>=400&&e.statusCode<700){var r=[404,405,410,416,480,481,482,483,484,485,489,501,604];p(r).call(r,e.statusCode)&&this.dialog.terminate()}var s,a,c,l,u;(s=n,a="receiveResponse",c=this,u=v(o(1&(l=3)?s.prototype:s),a,c),2&l&&"function"==typeof u?function(e){return u.apply(c,e)}:u)([e])}}])}();function Jn(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(Jn=function(){return!!e})()}function Xn(e,t,n,i){var r=v(o(1&i?e.prototype:e),t,n);return 2&i&&"function"==typeof r?function(e){return r.apply(n,e)}:r}var Qn=function(){function n(t,i,c,l,u,h){var g,f,v,p;return e(this,n),f=this,p=[l,u],v=o(v=n),g=a(f,Jn()?s(v,p||[],o(f).constructor):v.apply(f,p)),d(g,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"_autoRefresh",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"_subscriptionEvent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"_subscriptionExpires",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"_subscriptionExpiresInitial",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"_subscriptionExpiresLastSet",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"_subscriptionRefresh",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"_subscriptionRefreshLastSet",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"_subscriptionState",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"N",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(g,"refreshTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),g.delegate=h,g._autoRefresh=!1,g._subscriptionEvent=t,g._subscriptionExpires=i,g._subscriptionExpiresInitial=i,g._subscriptionExpiresLastSet=Math.floor(r()/1e3),g._subscriptionRefresh=void 0,g._subscriptionRefreshLastSet=void 0,g._subscriptionState=c,g.logger=l.loggerFactory.getLogger("sip.subscribe-dialog"),g.logger.log("SUBSCRIBE dialog ".concat(g.id," constructed")),g}return c(n,Jt),t(n,[{key:"dispose",value:function(){Xn(n,"dispose",this,3)([]),this.N&&(clearTimeout(this.N),this.N=void 0),this.refreshTimerClear(),this.logger.log("SUBSCRIBE dialog ".concat(this.id," destroyed"))}},{key:"autoRefresh",get:function(){return this._autoRefresh},set:function(e){this._autoRefresh=!0,this.refreshTimerSet()}},{key:"subscriptionEvent",get:function(){return this._subscriptionEvent}},{key:"subscriptionExpires",get:function(){var e=Math.floor(r()/1e3)-this._subscriptionExpiresLastSet,t=this._subscriptionExpires-e;return Math.max(t,0)},set:function(e){if(e<0)throw new Error("Expires must be greater than or equal to zero.");if(this._subscriptionExpires=e,this._subscriptionExpiresLastSet=Math.floor(r()/1e3),this.autoRefresh){var t=this.subscriptionRefresh;(void 0===t||t>=e)&&this.refreshTimerSet()}}},{key:"subscriptionExpiresInitial",get:function(){return this._subscriptionExpiresInitial}},{key:"subscriptionRefresh",get:function(){if(void 0!==this._subscriptionRefresh&&void 0!==this._subscriptionRefreshLastSet){var e=Math.floor(r()/1e3)-this._subscriptionRefreshLastSet,t=this._subscriptionRefresh-e;return Math.max(t,0)}}},{key:"subscriptionState",get:function(){return this._subscriptionState}},{key:"receiveRequest",value:function(e){var t,i,r;if(this.logger.log(E(t="SUBSCRIBE dialog ".concat(this.id," received ")).call(t,e.method," request")),this.sequenceGuard(e))if(Xn(n,"receiveRequest",this,3)([e]),e.method===st.NOTIFY)this.onNotify(e);else this.logger.log(E(i="SUBSCRIBE dialog ".concat(this.id," received unimplemented ")).call(i,e.method," request")),this.core.replyStateless(e,{statusCode:501});else this.logger.log(E(r="SUBSCRIBE dialog ".concat(this.id," rejected out of order ")).call(r,e.method," request."))}},{key:"refresh",value:function(){var e,t="Allow: "+ct.toString(),n={};return n.extraHeaders=g(e=n.extraHeaders||[]).call(e),n.extraHeaders.push(t),n.extraHeaders.push("Event: "+this.subscriptionEvent),n.extraHeaders.push("Expires: "+this.subscriptionExpiresInitial),n.extraHeaders.push("Contact: "+this.core.configuration.contact.toString()),this.subscribe(void 0,n)}},{key:"subscribe",value:function(e){var t,n=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.subscriptionState!==Et.Pending&&this.subscriptionState!==Et.Active)throw new Error("Invalid state ".concat(this.subscriptionState,'. May only re-subscribe while in state "pending" or "active".'));this.logger.log("SUBSCRIBE dialog ".concat(this.id," sending SUBSCRIBE request"));var r=new Zn(this,e,i);return this.N&&(clearTimeout(this.N),this.N=void 0),(null===(t=i.extraHeaders)||void 0===t?void 0:p(t).call(t,"Expires: 0"))||(this.N=m(function(){return n.timerN()},it.TIMER_N)),r}},{key:"terminate",value:function(){this.stateTransition(Et.Terminated),this.onTerminated()}},{key:"unsubscribe",value:function(){var e,t="Allow: "+ct.toString(),n={};return n.extraHeaders=g(e=n.extraHeaders||[]).call(e),n.extraHeaders.push(t),n.extraHeaders.push("Event: "+this.subscriptionEvent),n.extraHeaders.push("Expires: 0"),n.extraHeaders.push("Contact: "+this.core.configuration.contact.toString()),this.subscribe(void 0,n)}},{key:"onNotify",value:function(e){var t=e.parseHeader("Event").event;if(t&&t===this.subscriptionEvent){this.N&&(clearTimeout(this.N),this.N=void 0);var n=e.parseHeader("Subscription-State");if(n&&n.state){var i=n.state,r=n.expires?Math.max(n.expires,0):void 0;switch(i){case"pending":this.stateTransition(Et.Pending,r);break;case"active":this.stateTransition(Et.Active,r);break;case"terminated":this.stateTransition(Et.Terminated,r);break;default:this.logger.warn("Unrecognized subscription state.")}var s=new wn(this,e);this.delegate&&this.delegate.onNotify?this.delegate.onNotify(s):s.accept()}else this.core.replyStateless(e,{statusCode:489})}else this.core.replyStateless(e,{statusCode:489})}},{key:"onRefresh",value:function(e){this.delegate&&this.delegate.onRefresh&&this.delegate.onRefresh(e)}},{key:"onTerminated",value:function(){this.delegate&&this.delegate.onTerminated&&this.delegate.onTerminated()}},{key:"refreshTimerClear",value:function(){this.refreshTimer&&(clearTimeout(this.refreshTimer),this.refreshTimer=void 0)}},{key:"refreshTimerSet",value:function(){var e=this;if(this.refreshTimerClear(),this.autoRefresh&&this.subscriptionExpires>0){var t=900*this.subscriptionExpires;this._subscriptionRefresh=Math.floor(t/1e3),this._subscriptionRefreshLastSet=Math.floor(r()/1e3),this.refreshTimer=m(function(){e.refreshTimer=void 0,e._subscriptionRefresh=void 0,e._subscriptionRefreshLastSet=void 0,e.onRefresh(e.refresh())},t)}}},{key:"stateTransition",value:function(e,t){var n=this,i=function(){var t;n.logger.warn(E(t="Invalid subscription state transition from ".concat(n.subscriptionState," to ")).call(t,e))};switch(e){case Et.Initial:case Et.NotifyWait:return void i();case Et.Pending:if(this.subscriptionState!==Et.NotifyWait&&this.subscriptionState!==Et.Pending)return void i();break;case Et.Active:case Et.Terminated:if(this.subscriptionState!==Et.NotifyWait&&this.subscriptionState!==Et.Pending&&this.subscriptionState!==Et.Active)return void i();break;default:return void i()}e===Et.Pending&&t&&(this.subscriptionExpires=t),e===Et.Active&&t&&(this.subscriptionExpires=t),e===Et.Terminated&&this.dispose(),this._subscriptionState=e}},{key:"timerN",value:function(){this.logger.warn("Timer N expired for SUBSCRIBE dialog. Timed out waiting for NOTIFY."),this.subscriptionState!==Et.Terminated&&(this.stateTransition(Et.Terminated),this.onTerminated())}}],[{key:"initialDialogStateForSubscription",value:function(e,t){var n=t.getHeaders("record-route"),i=t.parseHeader("contact");if(!i)throw new Error("Contact undefined.");if(!(i instanceof Se))throw new Error("Contact not instance of NameAddrHeader.");var r=i.uri,s=e.cseq,a=e.callId,o=e.fromTag,c=t.fromTag;if(!a)throw new Error("Call id undefined.");if(!o)throw new Error("From tag undefined.");if(!c)throw new Error("To tag undefined.");if(!e.from)throw new Error("From undefined.");if(!e.to)throw new Error("To undefined.");return{id:a+o+c,early:!1,callId:a,localTag:o,remoteTag:c,localSequenceNumber:s,remoteSequenceNumber:undefined,localURI:e.from.uri,remoteURI:e.to.uri,remoteTarget:r,routeSet:n,secure:!1}}}])}();function ei(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(ei=function(){return!!e})()}function ti(e,t,n,i){var r=v(o(1&i?e.prototype:e),t,n);return 2&i&&"function"==typeof r?function(e){return r.apply(n,e)}:r}var ni=function(){function n(t,i,r){var c;e(this,n);var l=i.getHeader("Event");if(!l)throw new Error("Event undefined");var u,h,g,f=i.getHeader("Expires");if(!f)throw new Error("Expires undefined");return u=this,g=[Zt,t,i,r],h=o(h=n),c=a(u,ei()?s(h,g||[],o(u).constructor):h.apply(u,g)),d(c,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"dialog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"subscriberId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"subscriptionExpires",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"subscriptionExpiresRequested",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"subscriptionEvent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"subscriptionState",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(c,"N",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),c.delegate=r,c.subscriberId=i.callId+i.fromTag+l,c.subscriptionExpiresRequested=c.subscriptionExpires=Number(f),c.subscriptionEvent=l,c.subscriptionState=Et.NotifyWait,c.waitNotifyStart(),c}return c(n,en),t(n,[{key:"dispose",value:function(){ti(n,"dispose",this,3)([])}},{key:"onNotify",value:function(e){var t=e.message.parseHeader("Event").event;if(!t||t!==this.subscriptionEvent)return this.logger.warn("Failed to parse event."),void e.reject({statusCode:489});var n=e.message.parseHeader("Subscription-State");if(!n||!n.state)return this.logger.warn("Failed to parse subscription state."),void e.reject({statusCode:489});var i=n.state;switch(i){case"pending":case"active":case"terminated":break;default:return this.logger.warn("Invalid subscription state ".concat(i)),void e.reject({statusCode:489})}if("terminated"!==i&&!e.message.parseHeader("contact"))return this.logger.warn("Failed to parse contact."),void e.reject({statusCode:489});if(this.dialog)throw new Error("Dialog already created. This implementation only supports install of single subscriptions.");switch(this.waitNotifyStop(),this.subscriptionExpires=n.expires?Math.min(this.subscriptionExpires,Math.max(n.expires,0)):this.subscriptionExpires,i){case"pending":this.subscriptionState=Et.Pending;break;case"active":this.subscriptionState=Et.Active;break;case"terminated":this.subscriptionState=Et.Terminated;break;default:throw new Error("Unrecognized state ".concat(i,"."))}if(this.subscriptionState!==Et.Terminated){var r=Qn.initialDialogStateForSubscription(this.message,e.message);this.dialog=new Qn(this.subscriptionEvent,this.subscriptionExpires,this.subscriptionState,this.core,r)}if(this.delegate&&this.delegate.onNotify){var s=e,a=this.dialog;this.delegate.onNotify({request:s,subscription:a})}else e.accept()}},{key:"waitNotifyStart",value:function(){var e=this;this.N||(this.core.subscribers.set(this.subscriberId,this),this.N=m(function(){return e.timerN()},it.TIMER_N))}},{key:"waitNotifyStop",value:function(){this.N&&(this.core.subscribers.delete(this.subscriberId),clearTimeout(this.N),this.N=void 0)}},{key:"receiveResponse",value:function(e){if(this.authenticationGuard(e)){if(e.statusCode&&e.statusCode>=200&&e.statusCode<300){var t=e.getHeader("Expires");if(t){var i=Number(t);i>this.subscriptionExpiresRequested&&this.logger.warn("Expires header in a 200-class response to SUBSCRIBE with a higher value than the one in the request"),i<this.subscriptionExpires&&(this.subscriptionExpires=i)}else this.logger.warn("Expires header missing in a 200-class response to SUBSCRIBE");this.dialog&&this.dialog.subscriptionExpires>this.subscriptionExpires&&(this.dialog.subscriptionExpires=this.subscriptionExpires)}e.statusCode&&e.statusCode>=300&&e.statusCode<700&&this.waitNotifyStop(),ti(n,"receiveResponse",this,3)([e])}}},{key:"timerN",value:function(){this.logger.warn("Timer N expired for SUBSCRIBE user agent client. Timed out waiting for NOTIFY."),this.waitNotifyStop(),this.delegate&&this.delegate.onNotifyTimeout&&this.delegate.onNotifyTimeout()}}])}();function ii(){try{var e=!Boolean.prototype.valueOf.call(s(Boolean,[],function(){}))}catch(e){}return(ii=function(){return!!e})()}var ri=function(){function n(t,i,r){var c,l,u,h;return e(this,n),l=this,h=[sn,t,i,r],u=o(u=n),c=a(l,ii()?s(u,h||[],o(l).constructor):u.apply(l,h)),d(c,"core",{enumerable:!0,configurable:!0,writable:!0,value:t}),c}return c(n,an),t(n)}(),si=["application/sdp","application/dtmf-relay"],ai=function(){return t(function t(n){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,t),d(this,"configuration",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"dialogs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"subscribers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"userAgentClients",{enumerable:!0,configurable:!0,writable:!0,value:new M}),d(this,"userAgentServers",{enumerable:!0,configurable:!0,writable:!0,value:new M}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.configuration=n,this.delegate=i,this.dialogs=new M,this.subscribers=new M,this.logger=n.loggerFactory.getLogger("sip.user-agent-core")},[{key:"dispose",value:function(){this.reset()}},{key:"reset",value:function(){var e,t,n,i;h(e=this.dialogs).call(e,function(e){return e.dispose()}),this.dialogs.clear(),h(t=this.subscribers).call(t,function(e){return e.dispose()}),this.subscribers.clear(),h(n=this.userAgentClients).call(n,function(e){return e.dispose()}),this.userAgentClients.clear(),h(i=this.userAgentServers).call(i,function(e){return e.dispose()}),this.userAgentServers.clear()}},{key:"loggerFactory",get:function(){return this.configuration.loggerFactory}},{key:"transport",get:function(){var e=this.configuration.transportAccessor();if(!e)throw new Error("Transport undefined.");return e}},{key:"invite",value:function(e,t){return new jn(this,e,t)}},{key:"message",value:function(e,t){return new fn(this,e,t)}},{key:"publish",value:function(e,t){return new Gn(this,e,t)}},{key:"register",value:function(e,t){return new Wn(this,e,t)}},{key:"subscribe",value:function(e,t){return new ni(this,e,t)}},{key:"request",value:function(e,t){return new en(Zt,this,e,t)}},{key:"makeOutgoingRequestMessage",value:function(e,t,n,i,r,s,a){var o,c=this.configuration.sipjsId,l=this.configuration.displayName,u=this.configuration.viaForceRport,d=this.configuration.hackViaTcp,h=g(o=this.configuration.supportedOptionTags).call(o);e===st.REGISTER&&h.push("path","gruu"),e===st.INVITE&&(this.configuration.contact.pubGruu||this.configuration.contact.tempGruu)&&h.push("gruu");var f=this.configuration.routeSet,v=this.configuration.userAgentHeaderFieldValue,p=this.configuration.viaHost,m=$($({},{callIdPrefix:c,forceRport:u,fromDisplayName:l,hackViaTcp:d,optionTags:h,routeSet:f,userAgentString:v,viaHost:p}),r);return new Ze(e,t,n,i,m,s,a)}},{key:"receiveIncomingRequestFromTransport",value:function(e){this.receiveRequestFromTransport(e)}},{key:"receiveIncomingResponseFromTransport",value:function(e){this.receiveResponseFromTransport(e)}},{key:"replyStateless",value:function(e,t){var n=this,i=this.configuration.userAgentHeaderFieldValue,r=this.configuration.supportedOptionTagsResponse;t=$($({},t),{userAgent:i,supported:r});var s=Nt(e,t);return this.transport.send(s.message).catch(function(t){t instanceof Error&&n.logger.error(t.message),n.logger.error("Transport error occurred sending stateless reply to ".concat(e.method," request."))}),s}},{key:"receiveRequestFromTransport",value:function(e){var t=e.viaBranch,n=this.userAgentServers.get(t);e.method===st.ACK&&n&&n.transaction.state===Lt.Accepted&&n instanceof Bn?this.logger.warn("Discarding out of dialog ACK after 2xx response sent on transaction ".concat(t,".")):e.method!==st.CANCEL?n?n.transaction.receiveRequest(e):this.receiveRequest(e):n?(this.replyStateless(e,{statusCode:200}),n.transaction instanceof Wt&&n.transaction.state===Lt.Proceeding&&n instanceof Bn&&n.receiveCancel(e)):this.replyStateless(e,{statusCode:481})}},{key:"receiveRequest",value:function(e){if(p(ct).call(ct,e.method)){if(!e.ruri)throw new Error("Request-URI undefined.");if("sip"===e.ruri.scheme){var t=e.ruri,n=function(e){return!!e&&e.user===t.user};if(!n(this.configuration.aor)&&!(n(this.configuration.contact.uri)||n(this.configuration.contact.pubGruu)||n(this.configuration.contact.tempGruu)))return this.logger.warn("Request-URI does not point to us."),void(e.method!==st.ACK&&this.replyStateless(e,{statusCode:404}));if(e.method!==st.INVITE||e.hasHeader("Contact")){if(!e.toTag){var i,r,s=e.viaBranch;if(!this.userAgentServers.has(s))if(U(i=D(B(r=this.userAgentServers).call(r))).call(i,function(t){return t.transaction.request.fromTag===e.fromTag&&t.transaction.request.callId===e.callId&&t.transaction.request.cseq===e.cseq}))return void this.replyStateless(e,{statusCode:482})}e.toTag?this.receiveInsideDialogRequest(e):this.receiveOutsideDialogRequest(e)}else this.replyStateless(e,{statusCode:400,reasonPhrase:"Missing Contact Header"})}else this.replyStateless(e,{statusCode:416})}else{var a="Allow: "+ct.toString();this.replyStateless(e,{statusCode:405,extraHeaders:[a]})}}},{key:"receiveInsideDialogRequest",value:function(e){if(e.method===st.NOTIFY){var t=e.parseHeader("Event");if(!t||!t.event)return void this.replyStateless(e,{statusCode:489});var n=e.callId+e.toTag+t.event,i=this.subscribers.get(n);if(i){var r=new wn(this,e);return void i.onNotify(r)}}var s=e.callId+e.toTag+e.fromTag,a=this.dialogs.get(s);if(a){if(e.method===st.OPTIONS){var o="Allow: "+ct.toString(),c="Accept: "+si.toString();return void this.replyStateless(e,{statusCode:200,extraHeaders:[o,c]})}a.receiveRequest(e)}else e.method!==st.ACK&&this.replyStateless(e,{statusCode:481})}},{key:"receiveOutsideDialogRequest",value:function(e){switch(e.method){case st.ACK:break;case st.BYE:this.replyStateless(e,{statusCode:481});break;case st.CANCEL:throw new Error("Unexpected out of dialog request method ".concat(e.method,"."));case st.INFO:this.replyStateless(e,{statusCode:405});break;case st.INVITE:var t=new Bn(this,e);this.delegate.onInvite?this.delegate.onInvite(t):t.reject();break;case st.MESSAGE:var n=new pn(this,e);this.delegate.onMessage?this.delegate.onMessage(n):n.accept();break;case st.NOTIFY:var i=new wn(this,e);this.delegate.onNotify?this.delegate.onNotify(i):i.reject({statusCode:405});break;case st.OPTIONS:var r="Allow: "+ct.toString(),s="Accept: "+si.toString();this.replyStateless(e,{statusCode:200,extraHeaders:[r,s]});break;case st.REFER:var a=new $n(this,e);this.delegate.onRefer?this.delegate.onRefer(a):a.reject({statusCode:405});break;case st.REGISTER:var o=new Yn(this,e);this.delegate.onRegister?this.delegate.onRegister(o):o.reject({statusCode:405});break;case st.SUBSCRIBE:var c=new ri(this,e);this.delegate.onSubscribe?this.delegate.onSubscribe(c):c.reject({statusCode:480});break;default:throw new Error("Unexpected out of dialog request method ".concat(e.method,"."))}}},{key:"receiveResponseFromTransport",value:function(e){if(e.getHeaders("via").length>1)this.logger.warn("More than one Via header field present in the response, dropping");else{var t,n,i=e.viaBranch+e.method,r=this.userAgentClients.get(i);if(r)r.transaction.receiveResponse(e);else this.logger.warn(E(t=E(n="Discarding unmatched ".concat(e.statusCode," response to ")).call(n,e.method," ")).call(t,i,"."))}}}])}();var oi=function(){function r(t,n,i){e(this,r),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"mediaStreamFactory",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"sessionDescriptionHandlerConfiguration",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_localMediaStream",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_remoteMediaStream",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_dataChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_peerConnection",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_peerConnectionDelegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"iceGatheringCompletePromise",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"iceGatheringCompleteTimeoutId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"iceGatheringCompleteResolve",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"iceGatheringCompleteReject",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"localMediaStreamConstraints",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"onDataChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),t.debug("SessionDescriptionHandler.constructor"),this.logger=t,this.mediaStreamFactory=n,this.sessionDescriptionHandlerConfiguration=i,this._localMediaStream=new MediaStream,this._remoteMediaStream=new MediaStream,this._peerConnection=new RTCPeerConnection(null==i?void 0:i.peerConnectionConfiguration),this.initPeerConnectionEventHandlers()}return t(r,[{key:"localMediaStream",get:function(){return this._localMediaStream}},{key:"remoteMediaStream",get:function(){return this._remoteMediaStream}},{key:"dataChannel",get:function(){return this._dataChannel}},{key:"peerConnection",get:function(){return this._peerConnection}},{key:"peerConnectionDelegate",get:function(){return this._peerConnectionDelegate},set:function(e){this._peerConnectionDelegate=e}},{key:"close",value:function(){var e,t;this.logger.debug("SessionDescriptionHandler.close"),void 0!==this._peerConnection&&(h(e=this._peerConnection.getReceivers()).call(e,function(e){e.track&&e.track.stop()}),h(t=this._peerConnection.getSenders()).call(t,function(e){e.track&&e.track.stop()}),this._dataChannel&&this._dataChannel.close(),this._peerConnection.close(),this._peerConnection=void 0)}},{key:"enableReceiverTracks",value:function(e){var t,n=this.peerConnection;if(!n)throw new Error("Peer connection closed.");h(t=n.getReceivers()).call(t,function(t){t.track&&(t.track.enabled=e)})}},{key:"enableSenderTracks",value:function(e){var t,n=this.peerConnection;if(!n)throw new Error("Peer connection closed.");h(t=n.getSenders()).call(t,function(t){t.track&&(t.track.enabled=e)})}},{key:"getDescription",value:function(e,t){var n,r,s=this;if(this.logger.debug("SessionDescriptionHandler.getDescription"),void 0===this._peerConnection)return i.reject(new Error("Peer connection closed."));this.onDataChannel=null==e?void 0:e.onDataChannel;var a=null===(n=null==e?void 0:e.offerOptions)||void 0===n?void 0:n.iceRestart,o=void 0===(null==e?void 0:e.iceGatheringTimeout)?null===(r=this.sessionDescriptionHandlerConfiguration)||void 0===r?void 0:r.iceGatheringTimeout:null==e?void 0:e.iceGatheringTimeout;return this.getLocalMediaStream(e).then(function(){return s.updateDirection(e)}).then(function(){return s.createDataChannel(e)}).then(function(){return s.createLocalOfferOrAnswer(e)}).then(function(e){return s.applyModifiers(e,t)}).then(function(e){return s.setLocalSessionDescription(e)}).then(function(){return s.waitForIceGatheringComplete(a,o)}).then(function(){return s.getLocalSessionDescription()}).then(function(t){var n=null==e?void 0:e.finalModifiers;return n&&0!==n.length?(s.logger.debug("SessionDescriptionHandler.getDescription - applying final SDP modifiers"),s.applyFinalModifiers(t,n)):t}).then(function(e){var t=e.sdp||"";return s.logger.log("SessionDescriptionHandler.getDescription - final SDP "+C({hasRecoveryReason:p(t).call(t,"a=x-recovery-reason:"),hasReinviteReason:p(t).call(t,"a=x-reinvite-reason:")})),{body:t,contentType:"application/sdp"}}).catch(function(e){throw s.logger.error("SessionDescriptionHandler.getDescription failed - "+e),e})}},{key:"hasDescription",value:function(e){return this.logger.debug("SessionDescriptionHandler.hasDescription"),"application/sdp"===e}},{key:"iceGatheringComplete",value:function(){this.logger.debug("SessionDescriptionHandler.iceGatheringComplete"),void 0!==this.iceGatheringCompleteTimeoutId&&(this.logger.debug("SessionDescriptionHandler.iceGatheringComplete - clearing timeout"),clearTimeout(this.iceGatheringCompleteTimeoutId),this.iceGatheringCompleteTimeoutId=void 0),void 0!==this.iceGatheringCompletePromise&&(this.logger.debug("SessionDescriptionHandler.iceGatheringComplete - resolving promise"),this.iceGatheringCompleteResolve&&this.iceGatheringCompleteResolve(),this.iceGatheringCompletePromise=void 0,this.iceGatheringCompleteResolve=void 0,this.iceGatheringCompleteReject=void 0)}},{key:"sendDtmf",value:function(e,t){if(this.logger.debug("SessionDescriptionHandler.sendDtmf"),void 0===this._peerConnection)return this.logger.error("SessionDescriptionHandler.sendDtmf failed - peer connection closed"),!1;var n=this._peerConnection.getSenders();if(0===n.length)return this.logger.error("SessionDescriptionHandler.sendDtmf failed - no senders"),!1;var i=n[0].dtmf;if(!i)return this.logger.error("SessionDescriptionHandler.sendDtmf failed - no DTMF sender"),!1;var r=null==t?void 0:t.duration,s=null==t?void 0:t.interToneGap;try{i.insertDTMF(e,r,s)}catch(e){return this.logger.error(e.toString()),!1}return this.logger.log("SessionDescriptionHandler.sendDtmf sent via RTP: "+e.toString()),!0}},{key:"setDescription",value:function(e,t,n){var r=this;if(this.logger.debug("SessionDescriptionHandler.setDescription"),void 0===this._peerConnection)return i.reject(new Error("Peer connection closed."));this.onDataChannel=null==t?void 0:t.onDataChannel;var s="have-local-offer"===this._peerConnection.signalingState?"answer":"offer";return this.getLocalMediaStream(t).then(function(){return r.applyModifiers({sdp:e,type:s},n)}).then(function(e){return r.setRemoteSessionDescription(e)}).catch(function(e){throw r.logger.error("SessionDescriptionHandler.setDescription failed - "+e),e})}},{key:"applyFinalModifiers",value:function(e,t){var r=this;return this.logger.debug("SessionDescriptionHandler.applyFinalModifiers"),t&&0!==t.length?O(t).call(t,function(e,t){return e.then(function(e){return ne(r,void 0,void 0,n.mark(function i(){var r,s;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=1,t(e);case 1:if((s=n.sent)&&s.sdp){n.next=2;break}throw new Error("Invalid final SDP.");case 2:return n.abrupt("return",{sdp:s.sdp,type:null!==(r=s.type)&&void 0!==r?r:e.type});case 3:case"end":return n.stop()}},i)}))})},i.resolve({sdp:e.sdp,type:e.type})):i.resolve(e)}},{key:"applyModifiers",value:function(e,t){var n=this;return this.logger.debug("SessionDescriptionHandler.applyModifiers"),t&&0!==t.length?O(t).call(t,function(e,t){return e.then(t)},i.resolve(e)).then(function(e){if(n.logger.debug("SessionDescriptionHandler.applyModifiers - modified sdp"),!e.sdp||!e.type)throw new Error("Invalid SDP.");return{sdp:e.sdp,type:e.type}}):i.resolve(e)}},{key:"createDataChannel",value:function(e){if(void 0===this._peerConnection)return i.reject(new Error("Peer connection closed."));if(!0!==(null==e?void 0:e.dataChannel))return i.resolve();if(this._dataChannel)return i.resolve();switch(this._peerConnection.signalingState){case"stable":this.logger.debug("SessionDescriptionHandler.createDataChannel - creating data channel");try{return this._dataChannel=this._peerConnection.createDataChannel((null==e?void 0:e.dataChannelLabel)||"",null==e?void 0:e.dataChannelOptions),this.onDataChannel&&this.onDataChannel(this._dataChannel),i.resolve()}catch(e){return i.reject(e)}case"have-remote-offer":return i.resolve();default:return i.reject(new Error("Invalid signaling state "+this._peerConnection.signalingState))}}},{key:"createLocalOfferOrAnswer",value:function(e){if(void 0===this._peerConnection)return i.reject(new Error("Peer connection closed."));switch(this._peerConnection.signalingState){case"stable":return this.logger.debug("SessionDescriptionHandler.createLocalOfferOrAnswer - creating SDP offer"),this._peerConnection.createOffer(null==e?void 0:e.offerOptions);case"have-remote-offer":return this.logger.debug("SessionDescriptionHandler.createLocalOfferOrAnswer - creating SDP answer"),this._peerConnection.createAnswer(null==e?void 0:e.answerOptions);default:return i.reject(new Error("Invalid signaling state "+this._peerConnection.signalingState))}}},{key:"getLocalMediaStream",value:function(e){var t=this;if(this.logger.debug("SessionDescriptionHandler.getLocalMediaStream"),void 0===this._peerConnection)return i.reject(new Error("Peer connection closed."));var n=$({},null==e?void 0:e.constraints);if(this.localMediaStreamConstraints){if(n.audio=n.audio||this.localMediaStreamConstraints.audio,n.video=n.video||this.localMediaStreamConstraints.video,C(this.localMediaStreamConstraints.audio)===C(n.audio)&&C(this.localMediaStreamConstraints.video)===C(n.video))return i.resolve()}else void 0===n.audio&&void 0===n.video&&(n={audio:!0});return this.localMediaStreamConstraints=n,this.mediaStreamFactory(n,this,e).then(function(e){return t.setLocalMediaStream(e)})}},{key:"setLocalMediaStream",value:function(e){var t=this;if(this.logger.debug("SessionDescriptionHandler.setLocalMediaStream"),!this._peerConnection)throw new Error("Peer connection undefined.");var n=this._peerConnection,s=this._localMediaStream,a=[],o=function(e){var o,c=e.kind;if("audio"!==c&&"video"!==c)throw new Error("Unknown new track kind ".concat(c,"."));var l=V(o=n.getSenders()).call(o,function(e){return e.track&&e.track.kind===c});l?a.push(new i(function(e){t.logger.debug("SessionDescriptionHandler.setLocalMediaStream - replacing sender ".concat(c," track")),e()}).then(function(){return l.replaceTrack(e).then(function(){var t,n=V(t=s.getTracks()).call(t,function(e){return e.kind===c});n&&(n.stop(),s.removeTrack(n),r.dispatchRemoveTrackEvent(s,n)),s.addTrack(e),r.dispatchAddTrackEvent(s,e)}).catch(function(e){throw t.logger.error("SessionDescriptionHandler.setLocalMediaStream - failed to replace sender ".concat(c," track")),e})})):a.push(new i(function(e){t.logger.debug("SessionDescriptionHandler.setLocalMediaStream - adding sender ".concat(c," track")),e()}).then(function(){try{n.addTrack(e,s)}catch(e){throw t.logger.error("SessionDescriptionHandler.setLocalMediaStream - failed to add sender ".concat(c," track")),e}s.addTrack(e),r.dispatchAddTrackEvent(s,e)}))},c=e.getAudioTracks();c.length&&o(c[0]);var l=e.getVideoTracks();return l.length&&o(l[0]),O(a).call(a,function(e,t){return e.then(function(){return t})},i.resolve())}},{key:"getLocalSessionDescription",value:function(){if(this.logger.debug("SessionDescriptionHandler.getLocalSessionDescription"),void 0===this._peerConnection)return i.reject(new Error("Peer connection closed."));var e=this._peerConnection.localDescription;return e?i.resolve(e):i.reject(new Error("Failed to get local session description"))}},{key:"setLocalSessionDescription",value:function(e){return this.logger.debug("SessionDescriptionHandler.setLocalSessionDescription"),void 0===this._peerConnection?i.reject(new Error("Peer connection closed.")):this._peerConnection.setLocalDescription(e)}},{key:"setRemoteSessionDescription",value:function(e){if(this.logger.debug("SessionDescriptionHandler.setRemoteSessionDescription"),void 0===this._peerConnection)return i.reject(new Error("Peer connection closed."));var t,n=e.sdp;switch(this._peerConnection.signalingState){case"stable":t="offer";break;case"have-local-offer":t="answer";break;default:return i.reject(new Error("Invalid signaling state "+this._peerConnection.signalingState))}return n?this._peerConnection.setRemoteDescription({sdp:n,type:t}):(this.logger.error("SessionDescriptionHandler.setRemoteSessionDescription failed - cannot set null sdp"),i.reject(new Error("SDP is undefined")))}},{key:"setRemoteTrack",value:function(e){this.logger.debug("SessionDescriptionHandler.setRemoteTrack");var t=this._remoteMediaStream;if(t.getTrackById(e.id))this.logger.debug("SessionDescriptionHandler.setRemoteTrack - have remote ".concat(e.kind," track"));else if("audio"===e.kind){var n;this.logger.debug("SessionDescriptionHandler.setRemoteTrack - adding remote ".concat(e.kind," track")),h(n=t.getAudioTracks()).call(n,function(e){e.stop(),t.removeTrack(e),r.dispatchRemoveTrackEvent(t,e)}),t.addTrack(e),r.dispatchAddTrackEvent(t,e)}else if("video"===e.kind){var i;this.logger.debug("SessionDescriptionHandler.setRemoteTrack - adding remote ".concat(e.kind," track")),h(i=t.getVideoTracks()).call(i,function(e){e.stop(),t.removeTrack(e),r.dispatchRemoveTrackEvent(t,e)}),t.addTrack(e),r.dispatchAddTrackEvent(t,e)}}},{key:"updateDirection",value:function(e){var t=this;if(void 0===this._peerConnection)return i.reject(new Error("Peer connection closed."));switch(this._peerConnection.signalingState){case"stable":this.logger.debug("SessionDescriptionHandler.updateDirection - setting offer direction");var n;h(n=this._peerConnection.getTransceivers()).call(n,function(t){if(t.direction){var n=function(t){switch(t){case"inactive":case"recvonly":return(null==e?void 0:e.hold)?"inactive":"recvonly";case"sendonly":case"sendrecv":return(null==e?void 0:e.hold)?"sendonly":"sendrecv";case"stopped":return"stopped";default:throw new Error("Should never happen")}}(t.direction);t.direction!==n&&(t.direction=n)}});break;case"have-remote-offer":this.logger.debug("SessionDescriptionHandler.updateDirection - setting answer direction");var r,s=function(){var e=t._peerConnection.remoteDescription;if(!e)throw new Error("Failed to read remote offer");var n=/a=sendrecv\r\n|a=sendonly\r\n|a=recvonly\r\n|a=inactive\r\n/.exec(e.sdp);if(n)switch(n[0]){case"a=inactive\r\n":return"inactive";case"a=recvonly\r\n":return"recvonly";case"a=sendonly\r\n":return"sendonly";case"a=sendrecv\r\n":return"sendrecv";default:throw new Error("Should never happen")}return"sendrecv"}(),a=function(){switch(s){case"inactive":return"inactive";case"recvonly":return"sendonly";case"sendonly":return(null==e?void 0:e.hold)?"inactive":"recvonly";case"sendrecv":return(null==e?void 0:e.hold)?"sendonly":"sendrecv";default:throw new Error("Should never happen")}}();h(r=this._peerConnection.getTransceivers()).call(r,function(e){e.direction&&"stopped"!==e.direction&&e.direction!==a&&(e.direction=a)});break;default:return i.reject(new Error("Invalid signaling state "+this._peerConnection.signalingState))}return i.resolve()}},{key:"waitForIceGatheringComplete",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return this.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete"),void 0===this._peerConnection?i.reject("Peer connection closed."):t||"complete"!==this._peerConnection.iceGatheringState?(void 0!==this.iceGatheringCompletePromise&&(this.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete - rejecting prior waiting promise"),this.iceGatheringCompleteReject&&this.iceGatheringCompleteReject(new Error("Promise superseded.")),this.iceGatheringCompletePromise=void 0,this.iceGatheringCompleteResolve=void 0,this.iceGatheringCompleteReject=void 0),this.iceGatheringCompletePromise=new i(function(t,i){e.iceGatheringCompleteResolve=t,e.iceGatheringCompleteReject=i,n>0&&(e.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete - timeout in "+n),e.iceGatheringCompleteTimeoutId=m(function(){e.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete - timeout"),e.iceGatheringComplete()},n))}),this.iceGatheringCompletePromise):(this.logger.debug("SessionDescriptionHandler.waitForIceGatheringToComplete - already complete"),i.resolve())}},{key:"initPeerConnectionEventHandlers",value:function(){var e=this;if(this.logger.debug("SessionDescriptionHandler.initPeerConnectionEventHandlers"),!this._peerConnection)throw new Error("Peer connection undefined.");var t=this._peerConnection;t.onconnectionstatechange=function(n){var i,r=t.connectionState;e.logger.debug("SessionDescriptionHandler.onconnectionstatechange ".concat(r)),(null===(i=e._peerConnectionDelegate)||void 0===i?void 0:i.onconnectionstatechange)&&e._peerConnectionDelegate.onconnectionstatechange(n)},t.ondatachannel=function(t){var n;e.logger.debug("SessionDescriptionHandler.ondatachannel"),e._dataChannel=t.channel,e.onDataChannel&&e.onDataChannel(e._dataChannel),(null===(n=e._peerConnectionDelegate)||void 0===n?void 0:n.ondatachannel)&&e._peerConnectionDelegate.ondatachannel(t)},t.onicecandidate=function(t){var n;e.logger.debug("SessionDescriptionHandler.onicecandidate"),(null===(n=e._peerConnectionDelegate)||void 0===n?void 0:n.onicecandidate)&&e._peerConnectionDelegate.onicecandidate(t)},t.onicecandidateerror=function(t){var n;e.logger.debug("SessionDescriptionHandler.onicecandidateerror"),(null===(n=e._peerConnectionDelegate)||void 0===n?void 0:n.onicecandidateerror)&&e._peerConnectionDelegate.onicecandidateerror(t)},t.oniceconnectionstatechange=function(n){var i,r=t.iceConnectionState;e.logger.debug("SessionDescriptionHandler.oniceconnectionstatechange ".concat(r)),(null===(i=e._peerConnectionDelegate)||void 0===i?void 0:i.oniceconnectionstatechange)&&e._peerConnectionDelegate.oniceconnectionstatechange(n)},t.onicegatheringstatechange=function(n){var i,r=t.iceGatheringState;e.logger.debug("SessionDescriptionHandler.onicegatheringstatechange ".concat(r)),"complete"===r&&e.iceGatheringComplete(),(null===(i=e._peerConnectionDelegate)||void 0===i?void 0:i.onicegatheringstatechange)&&e._peerConnectionDelegate.onicegatheringstatechange(n)},t.onnegotiationneeded=function(t){var n;e.logger.debug("SessionDescriptionHandler.onnegotiationneeded"),(null===(n=e._peerConnectionDelegate)||void 0===n?void 0:n.onnegotiationneeded)&&e._peerConnectionDelegate.onnegotiationneeded(t)},t.onsignalingstatechange=function(n){var i,r=t.signalingState;e.logger.debug("SessionDescriptionHandler.onsignalingstatechange ".concat(r)),(null===(i=e._peerConnectionDelegate)||void 0===i?void 0:i.onsignalingstatechange)&&e._peerConnectionDelegate.onsignalingstatechange(n)},t.ontrack=function(t){var n,i,r=t.track.kind,s=t.track.enabled?"enabled":"disabled";e.logger.debug(E(n="SessionDescriptionHandler.ontrack ".concat(r," ")).call(n,s)),e.setRemoteTrack(t.track),(null===(i=e._peerConnectionDelegate)||void 0===i?void 0:i.ontrack)&&e._peerConnectionDelegate.ontrack(t)}}}],[{key:"dispatchAddTrackEvent",value:function(e,t){e.dispatchEvent(new MediaStreamTrackEvent("addtrack",{track:t}))}},{key:"dispatchRemoveTrackEvent",value:function(e,t){e.dispatchEvent(new MediaStreamTrackEvent("removetrack",{track:t}))}}])}();function ci(e){return function(t,n){void 0===e&&(e=function(e){return e.audio||e.video?void 0===navigator.mediaDevices?i.reject(new Error("Media devices not available in insecure contexts.")):navigator.mediaDevices.getUserMedia.call(navigator.mediaDevices,e):i.resolve(new MediaStream)});var r={iceGatheringTimeout:void 0!==(null==n?void 0:n.iceGatheringTimeout)?null==n?void 0:n.iceGatheringTimeout:5e3,peerConnectionConfiguration:$($({},{bundlePolicy:"balanced",certificates:void 0,iceCandidatePoolSize:0,iceServers:[{urls:"stun:stun.l.google.com:19302"}],iceTransportPolicy:"all",rtcpMuxPolicy:"require"}),null==n?void 0:n.peerConnectionConfiguration)},s=t.userAgent.getLogger("sip.SessionDescriptionHandler");return new oi(s,e,r)}}var li=function(){return t(function t(n,i){var r;if(e(this,t),d(this,"onConnect",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"onDisconnect",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"onMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_protocol",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:At.Disconnected}),d(this,"_stateEventEmitter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_ws",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"configuration",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"connectPromise",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"connectResolve",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"connectReject",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"connectTimeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"disconnectPromise",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"disconnectResolve",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"disconnectReject",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"keepAliveInterval",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"keepAliveDebounceTimeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"transitioningState",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this._stateEventEmitter=new we,this.logger=n,i){var s=i,a=null==s?void 0:s.wsServers,o=null==s?void 0:s.maxReconnectionAttempts;if(void 0!==a){this.logger.warn('The transport option "wsServers" as has apparently been specified and has been deprecated. It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.')}if(void 0!==o){this.logger.warn('The transport option "maxReconnectionAttempts" as has apparently been specified and has been deprecated. It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.')}a&&!i.server&&("string"==typeof a&&(i.server=a),a instanceof Array&&(i.server=a[0]))}this.configuration=$($({},t.defaultOptions),i);var c=this.configuration.server,l=He.parse(c,"absoluteURI");if(-1===l)throw this.logger.error('Invalid WebSocket Server URL "'.concat(c,'"')),new Error("Invalid WebSocket Server URL");if(!p(r=["wss","ws","udp"]).call(r,l.scheme))throw this.logger.error('Invalid scheme in WebSocket Server URL "'.concat(c,'"')),new Error("Invalid scheme in WebSocket Server URL");this._protocol=l.scheme.toUpperCase()},[{key:"dispose",value:function(){return this.disconnect()}},{key:"protocol",get:function(){return this._protocol}},{key:"server",get:function(){return this.configuration.server}},{key:"state",get:function(){return this._state}},{key:"stateChange",get:function(){return this._stateEventEmitter}},{key:"ws",get:function(){return this._ws}},{key:"connect",value:function(){return this._connect()}},{key:"disconnect",value:function(){return this._disconnect()}},{key:"isConnected",value:function(){return this.state===At.Connected}},{key:"send",value:function(e){return this._send(e)}},{key:"_connect",value:function(){var e,t=this;switch(this.logger.log("Connecting ".concat(this.server)),this.state){case At.Connecting:if(this.transitioningState)return i.reject(this.transitionLoopDetectedError(At.Connecting));if(!this.connectPromise)throw new Error("Connect promise must be defined.");return this.connectPromise;case At.Connected:if(this.transitioningState)return i.reject(this.transitionLoopDetectedError(At.Connecting));if(this.connectPromise)throw new Error("Connect promise must not be defined.");return i.resolve();case At.Disconnecting:if(this.connectPromise)throw new Error("Connect promise must not be defined.");try{this.transitionState(At.Connecting)}catch(e){if(e instanceof pe)return i.reject(e);throw e}break;case At.Disconnected:if(this.connectPromise)throw new Error("Connect promise must not be defined.");try{this.transitionState(At.Connecting)}catch(e){if(e instanceof pe)return i.reject(e);throw e}break;default:throw new Error("Unknown state")}try{(e=new WebSocket(this.server,"sip")).binaryType="arraybuffer",e.addEventListener("close",function(n){return t.onWebSocketClose(n,e)}),e.addEventListener("error",function(n){return t.onWebSocketError(n,e)}),e.addEventListener("open",function(n){return t.onWebSocketOpen(n,e)}),e.addEventListener("message",function(n){return t.onWebSocketMessage(n,e)}),this._ws=e}catch(e){return this._ws=void 0,this.logger.error("WebSocket construction failed."),this.logger.error(e.toString()),new i(function(n,i){t.connectResolve=n,t.connectReject=i,t.transitionState(At.Disconnected,e)})}return this.connectPromise=new i(function(n,i){t.connectResolve=n,t.connectReject=i,t.connectTimeout=m(function(){t.logger.warn("Connect timed out. Exceeded time set in configuration.connectionTimeout: "+t.configuration.connectionTimeout+"s."),e.close(1e3)},1e3*t.configuration.connectionTimeout)}),this.connectPromise}},{key:"_disconnect",value:function(){var e=this;switch(this.logger.log("Disconnecting ".concat(this.server)),this.state){case At.Connecting:if(this.disconnectPromise)throw new Error("Disconnect promise must not be defined.");try{this.transitionState(At.Disconnecting)}catch(e){if(e instanceof pe)return i.reject(e);throw e}break;case At.Connected:if(this.disconnectPromise)throw new Error("Disconnect promise must not be defined.");try{this.transitionState(At.Disconnecting)}catch(e){if(e instanceof pe)return i.reject(e);throw e}break;case At.Disconnecting:if(this.transitioningState)return i.reject(this.transitionLoopDetectedError(At.Disconnecting));if(!this.disconnectPromise)throw new Error("Disconnect promise must be defined.");return this.disconnectPromise;case At.Disconnected:if(this.transitioningState)return i.reject(this.transitionLoopDetectedError(At.Disconnecting));if(this.disconnectPromise)throw new Error("Disconnect promise must not be defined.");return i.resolve();default:throw new Error("Unknown state")}if(!this._ws)throw new Error("WebSocket must be defined.");var t=this._ws;return this.disconnectPromise=new i(function(n,i){e.disconnectResolve=n,e.disconnectReject=i;try{t.close(1e3)}catch(t){throw e.logger.error("WebSocket close failed."),e.logger.error(t.toString()),t}}),this.disconnectPromise}},{key:"_send",value:function(e){if(!0===this.configuration.traceSip&&this.logger.log("Sending WebSocket message:\n\n"+e+"\n"),this._state!==At.Connected)return i.reject(new Error("Not connected."));if(!this._ws)throw new Error("WebSocket undefined.");try{this._ws.send(e)}catch(e){return e instanceof Error?i.reject(e):i.reject(new Error("WebSocket send failed."))}return i.resolve()}},{key:"onWebSocketClose",value:function(e,t){var n;if(t===this._ws){var i=E(n="WebSocket closed ".concat(this.server," (code: ")).call(n,e.code,")"),r=this.disconnectPromise?void 0:new Error(i);r&&this.logger.warn("WebSocket closed unexpectedly"),this.logger.log(i),this._ws=void 0,this.transitionState(At.Disconnected,r)}}},{key:"onWebSocketError",value:function(e,t){t===this._ws&&this.logger.error("WebSocket error occurred.")}},{key:"onWebSocketMessage",value:function(e,t){if(t===this._ws){var n,i=e.data;if(/^(\r\n)+$/.test(i))return this.clearKeepAliveTimeout(),void(!0===this.configuration.traceSip&&this.logger.log("Received WebSocket message with CRLF Keep Alive response"));if(i){if("string"!=typeof i){try{n=(new TextDecoder).decode(new Uint8Array(i))}catch(e){return this.logger.error(e.toString()),void this.logger.error("Received WebSocket binary message failed to be converted into string, message discarded")}!0===this.configuration.traceSip&&this.logger.log("Received WebSocket binary message:\n\n"+n+"\n")}else n=i,!0===this.configuration.traceSip&&this.logger.log("Received WebSocket text message:\n\n"+n+"\n");if(this.state===At.Connected){if(this.onMessage)try{this.onMessage(n)}catch(e){throw this.logger.error(e.toString()),this.logger.error("Exception thrown by onMessage callback"),e}}else this.logger.warn("Received message while not connected, discarding...")}else this.logger.warn("Received empty message, discarding...")}}},{key:"onWebSocketOpen",value:function(e,t){t===this._ws&&this._state===At.Connecting&&(this.logger.log("WebSocket opened ".concat(this.server)),this.transitionState(At.Connected))}},{key:"transitionLoopDetectedError",value:function(e){var t,n="A state transition loop has been detected.";return n+=E(t=" An attempt to transition from ".concat(this._state," to ")).call(t,e," before the prior transition completed."),n+=" Perhaps you are synchronously calling connect() or disconnect() from a callback or state change handler?",this.logger.error(n),new pe("Loop detected.")}},{key:"transitionState",value:function(e,t){var n,i=this,r=function(){var t;throw new Error(E(t="Invalid state transition from ".concat(i._state," to ")).call(t,e))};if(this.transitioningState)throw this.transitionLoopDetectedError(e);switch(this.transitioningState=!0,this._state){case At.Connecting:e!==At.Connected&&e!==At.Disconnecting&&e!==At.Disconnected&&r();break;case At.Connected:e!==At.Disconnecting&&e!==At.Disconnected&&r();break;case At.Disconnecting:e!==At.Connecting&&e!==At.Disconnected&&r();break;case At.Disconnected:e!==At.Connecting&&r();break;default:throw new Error("Unknown state.")}var s=this._state;this._state=e;var a=this.connectResolve,o=this.connectReject;s===At.Connecting&&(this.connectPromise=void 0,this.connectResolve=void 0,this.connectReject=void 0);var c=this.disconnectResolve,l=this.disconnectReject;if(s===At.Disconnecting&&(this.disconnectPromise=void 0,this.disconnectResolve=void 0,this.disconnectReject=void 0),this.connectTimeout&&(clearTimeout(this.connectTimeout),this.connectTimeout=void 0),this.logger.log(E(n="Transitioned from ".concat(s," to ")).call(n,this._state)),this._stateEventEmitter.emit(this._state),e===At.Connected&&(this.startSendingKeepAlives(),this.onConnect))try{this.onConnect()}catch(e){throw this.logger.error(e.toString()),this.logger.error("Exception thrown by onConnect callback"),e}if(s===At.Connected&&(this.stopSendingKeepAlives(),this.onDisconnect))try{t?this.onDisconnect(t):this.onDisconnect()}catch(e){throw this.logger.error(e.toString()),this.logger.error("Exception thrown by onDisconnect callback"),e}if(s===At.Connecting){if(!a)throw new Error("Connect resolve undefined.");if(!o)throw new Error("Connect reject undefined.");e===At.Connected?a():o(t||new Error("Connect aborted."))}if(s===At.Disconnecting){if(!c)throw new Error("Disconnect resolve undefined.");if(!l)throw new Error("Disconnect reject undefined.");e===At.Disconnected?c():l(t||new Error("Disconnect aborted."))}this.transitioningState=!1}},{key:"clearKeepAliveTimeout",value:function(){this.keepAliveDebounceTimeout&&clearTimeout(this.keepAliveDebounceTimeout),this.keepAliveDebounceTimeout=void 0}},{key:"sendKeepAlive",value:function(){var e=this;return this.keepAliveDebounceTimeout?i.resolve():(this.keepAliveDebounceTimeout=m(function(){e.clearKeepAliveTimeout()},1e3*this.configuration.keepAliveDebounce),this.send("\r\n\r\n"))}},{key:"startSendingKeepAlives",value:function(){var e,t,n=this;this.configuration.keepAliveInterval&&!this.keepAliveInterval&&(this.keepAliveInterval=L(function(){n.sendKeepAlive(),n.startSendingKeepAlives()},(e=this.configuration.keepAliveInterval,t=.8*e,1e3*(Math.random()*(e-t)+t))))}},{key:"stopSendingKeepAlives",value:function(){this.keepAliveInterval&&clearInterval(this.keepAliveInterval),this.keepAliveDebounceTimeout&&clearTimeout(this.keepAliveDebounceTimeout),this.keepAliveInterval=void 0,this.keepAliveDebounceTimeout=void 0}}])}();d(li,"defaultOptions",{enumerable:!0,configurable:!0,writable:!0,value:{server:"",connectionTimeout:5,keepAliveInterval:0,keepAliveDebounce:10,traceSip:!0}});var ui=function(){return t(function t(){var n,i=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e(this,t),d(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_publishers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),d(this,"_registerers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),d(this,"_sessions",{enumerable:!0,configurable:!0,writable:!0,value:{}}),d(this,"_subscriptions",{enumerable:!0,configurable:!0,writable:!0,value:{}}),d(this,"_contact",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_instanceId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:xt.Stopped}),d(this,"_stateEventEmitter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_transport",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"_userAgentCore",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"loggerFactory",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._stateEventEmitter=new we,this.delegate=r.delegate,this.options=$($($($($({},t.defaultOptions()),{sipjsId:qe(5)}),{uri:new Ee("sip","anonymous."+qe(6),"anonymous.invalid")}),{viaHost:qe(12)+".invalid"}),t.stripUndefinedProperties(r)),this.options.hackIpInContact)if("boolean"==typeof this.options.hackIpInContact&&this.options.hackIpInContact){var s=Math.floor(254*Math.random()+1);this.options.viaHost="192.0.2."+s}else this.options.hackIpInContact&&(this.options.viaHost=this.options.hackIpInContact);switch(this.loggerFactory=new Ot,this.logger=this.loggerFactory.getLogger("sip.UserAgent"),this.loggerFactory.builtinEnabled=this.options.logBuiltinEnabled,this.loggerFactory.connector=this.options.logConnector,this.options.logLevel){case"error":this.loggerFactory.level=$t.error;break;case"warn":this.loggerFactory.level=$t.warn;break;case"log":this.loggerFactory.level=$t.log;break;case"debug":this.loggerFactory.level=$t.debug}if(this.options.logConfiguration&&(this.logger.log("Configuration:"),h(n=A(this.options)).call(n,function(e){var t=i.options[e];switch(e){case"uri":case"sessionDescriptionHandlerFactory":i.logger.log("· "+e+": "+t);break;case"authorizationPassword":i.logger.log("· "+e+": NOT SHOWN");break;case"transportConstructor":i.logger.log("· "+e+": "+t.name);break;default:i.logger.log("· "+e+": "+C(t))}})),this.options.transportOptions){var a=this.options.transportOptions,o=a.maxReconnectionAttempts,c=a.reconnectionTimeout;if(void 0!==o){this.logger.warn('The transport option "maxReconnectionAttempts" as has apparently been specified and has been deprecated. It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.')}if(void 0!==c){this.logger.warn('The transport option "reconnectionTimeout" as has apparently been specified and has been deprecated. It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.')}void 0===r.reconnectionDelay&&void 0!==c&&(this.options.reconnectionDelay=c),void 0===r.reconnectionAttempts&&void 0!==o&&(this.options.reconnectionAttempts=o)}if(void 0!==r.reconnectionDelay){this.logger.warn('The user agent option "reconnectionDelay" as has apparently been specified and has been deprecated. It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.')}if(void 0!==r.reconnectionAttempts){this.logger.warn('The user agent option "reconnectionAttempts" as has apparently been specified and has been deprecated. It will no longer be available starting with SIP.js release 0.16.0. Please update accordingly.')}if(this._transport=new this.options.transportConstructor(this.getLogger("sip.Transport"),this.options.transportOptions),this.initTransportCallbacks(),this._contact=this.initContact(),this._instanceId=this.options.instanceId?this.options.instanceId:t.newUUID(),-1===He.parse(this._instanceId,"uuid"))throw new Error("Invalid instanceId.");this._userAgentCore=this.initCore()},[{key:"configuration",get:function(){return this.options}},{key:"contact",get:function(){return this._contact}},{key:"instanceId",get:function(){return this._instanceId}},{key:"state",get:function(){return this._state}},{key:"stateChange",get:function(){return this._stateEventEmitter}},{key:"transport",get:function(){return this._transport}},{key:"userAgentCore",get:function(){return this._userAgentCore}},{key:"getLogger",value:function(e,t){return this.loggerFactory.getLogger(e,t)}},{key:"getLoggerFactory",value:function(){return this.loggerFactory}},{key:"isConnected",value:function(){return this.transport.isConnected()}},{key:"reconnect",value:function(){var e=this;return this.state===xt.Stopped?i.reject(new Error("User agent stopped.")):i.resolve().then(function(){return e.transport.connect()})}},{key:"start",value:function(){return this.state===xt.Started?(this.logger.warn("User agent already started"),i.resolve()):(this.logger.log("Starting ".concat(this.configuration.uri)),this.transitionState(xt.Started),this.transport.connect())}},{key:"stop",value:function(){return ne(this,void 0,void 0,n.mark(function e(){var t,r,s,a,o,c,l,u,d,h,g,f,v,p,m,b,y,w,k,T,R,S,I=this;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.state!==xt.Stopped){e.next=1;break}return this.logger.warn("User agent already stopped"),e.abrupt("return",i.resolve());case 1:if(this.logger.log("Stopping ".concat(this.configuration.uri)),this.options.gracefulShutdown){e.next=2;break}return this.logger.log("Dispose of transport"),this.transport.dispose().catch(function(e){throw I.logger.error(e.message),e}),this.logger.log("Dispose of core"),this.userAgentCore.dispose(),this._publishers={},this._registerers={},this._sessions={},this._subscriptions={},this.transitionState(xt.Stopped),e.abrupt("return",i.resolve());case 2:t=$({},this._publishers),r=$({},this._registerers),s=$({},this._sessions),a=$({},this._subscriptions),o=this.transport,c=this.userAgentCore,this.logger.log("Dispose of registerers"),l=n.mark(function e(t){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!r[t]){e.next=1;break}return e.next=1,r[t].dispose().catch(function(e){throw I.logger.error(e.message),delete I._registerers[t],e});case 1:case"end":return e.stop()}},e)}),m=j(n).call(n,r);case 3:if((b=m()).done){e.next=5;break}return u=b.value,e.delegateYield(l(u),"t0",4);case 4:e.next=3;break;case 5:this.logger.log("Dispose of sessions"),d=n.mark(function e(t){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!s[t]){e.next=1;break}return e.next=1,s[t].dispose().catch(function(e){throw I.logger.error(e.message),delete I._sessions[t],e});case 1:case"end":return e.stop()}},e)}),y=j(n).call(n,s);case 6:if((w=y()).done){e.next=8;break}return h=w.value,e.delegateYield(d(h),"t1",7);case 7:e.next=6;break;case 8:this.logger.log("Dispose of subscriptions"),g=n.mark(function e(t){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!a[t]){e.next=1;break}return e.next=1,a[t].dispose().catch(function(e){throw I.logger.error(e.message),delete I._subscriptions[t],e});case 1:case"end":return e.stop()}},e)}),k=j(n).call(n,a);case 9:if((T=k()).done){e.next=11;break}return f=T.value,e.delegateYield(g(f),"t2",10);case 10:e.next=9;break;case 11:this.logger.log("Dispose of publishers"),v=n.mark(function e(i){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!t[i]){e.next=1;break}return e.next=1,t[i].dispose().catch(function(e){throw I.logger.error(e.message),delete I._publishers[i],e});case 1:case"end":return e.stop()}},e)}),R=j(n).call(n,t);case 12:if((S=R()).done){e.next=14;break}return p=S.value,e.delegateYield(v(p),"t3",13);case 13:e.next=12;break;case 14:return this.logger.log("Dispose of transport"),e.next=15,o.dispose().catch(function(e){throw I.logger.error(e.message),e});case 15:this.logger.log("Dispose of core"),c.dispose(),this.transitionState(xt.Stopped);case 16:case"end":return e.stop()}},e,this)}))}},{key:"_makeInviter",value:function(e,t){return new St(this,e,t)}},{key:"attemptReconnection",value:function(){var e,t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,i=this.options.reconnectionAttempts,r=this.options.reconnectionDelay;n>i?this.logger.log("Maximum reconnection attempts reached"):(this.logger.log(E(e="Reconnection attempt ".concat(n," of ")).call(e,i," - trying")),m(function(){t.reconnect().then(function(){var e;t.logger.log(E(e="Reconnection attempt ".concat(n," of ")).call(e,i," - succeeded"))}).catch(function(e){var r;t.logger.error(e.message),t.logger.log(E(r="Reconnection attempt ".concat(n," of ")).call(r,i," - failed")),t.attemptReconnection(++n)})},1===n?0:1e3*r))}},{key:"initContact",value:function(){var e=this,t=""!==this.options.contactName?this.options.contactName:qe(8),n=this.options.contactParams,i={pubGruu:void 0,tempGruu:void 0,uri:new Ee("sip",t,this.options.viaHost,void 0,n),toString:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.anonymous||!1,r=t.outbound||!1,s=t.register||!1,a="<";return a+=i?e.contact.tempGruu||"sip:anonymous@anonymous.invalid;transport=".concat(n.transport?n.transport:"ws"):s?e.contact.uri:e.contact.pubGruu||e.contact.uri,r&&(a+=";ob"),a+=">",e.options.instanceIdAlwaysAdded&&(a+=';+sip.instance="<urn:uuid:'+e._instanceId+'>"'),a}};return i}},{key:"initCore",value:function(){var e,t=this,n=[];(n.push("outbound"),this.options.sipExtension100rel===ft.Supported&&n.push("100rel"),this.options.sipExtensionReplaces===ft.Supported&&n.push("replaces"),this.options.sipExtensionExtraSupported)&&(e=n).push.apply(e,N(this.options.sipExtensionExtraSupported));this.options.hackAllowUnregisteredOptionTags||(n=f(n).call(n,function(e){return pt[e]})),n=D(new F(n));var i=g(n).call(n);(this.contact.pubGruu||this.contact.tempGruu)&&i.push("gruu");var r={aor:this.options.uri,contact:this.contact,displayName:this.options.displayName,loggerFactory:this.loggerFactory,hackViaTcp:this.options.hackViaTcp,routeSet:this.options.preloadedRouteSet,supportedOptionTags:n,supportedOptionTagsResponse:i,sipjsId:this.options.sipjsId,userAgentHeaderFieldValue:this.options.userAgentString,viaForceRport:this.options.forceRport,viaHost:this.options.viaHost,authenticationFactory:function(){var e=t.options.authorizationUsername?t.options.authorizationUsername:t.options.uri.user,n=t.options.authorizationPassword?t.options.authorizationPassword:void 0,i=t.options.authorizationHa1?t.options.authorizationHa1:void 0;return new qt(t.getLoggerFactory(),i,e,n)},transportAccessor:function(){return t.transport}},s={onInvite:function(e){var n,i=new yt(t,e);if(e.delegate={onCancel:function(e){i._onCancel(e)},onTransportError:function(e){t.logger.error("A transport error has occurred while handling an incoming INVITE request.")}},e.trying(),t.options.sipExtensionReplaces!==ft.Unsupported){var r=e.message.parseHeader("replaces");if(r){var s=r.call_id;if("string"!=typeof s)throw new Error("Type of call id is not string");var a=r.replaces_to_tag;if("string"!=typeof a)throw new Error("Type of to tag is not string");var o=r.replaces_from_tag;if("string"!=typeof o)throw new Error("type of from tag is not string");var c=s+a+o,l=t.userAgentCore.dialogs.get(c);if(!l)return void i.reject({statusCode:481});if(!l.early&&!0===r.early_only)return void i.reject({statusCode:486});var u=t._sessions[s+o]||t._sessions[s+a]||void 0;if(!u)throw new Error("Session does not exist.");i._replacee=u}}if(null===(n=t.delegate)||void 0===n?void 0:n.onInvite)return i.autoSendAnInitialProvisionalResponse?void i.progress().then(function(){var e;if(void 0===(null===(e=t.delegate)||void 0===e?void 0:e.onInvite))throw new Error("onInvite undefined.");t.delegate.onInvite(i)}):void t.delegate.onInvite(i);i.reject({statusCode:486})},onMessage:function(e){if(t.delegate&&t.delegate.onMessage){var n=new lt(e);t.delegate.onMessage(n)}else e.accept()},onNotify:function(e){if(t.delegate&&t.delegate.onNotify){var n=new ut(e);t.delegate.onNotify(n)}else t.options.allowLegacyNotifications?e.accept():e.reject({statusCode:481})},onRefer:function(e){t.logger.warn("Received an out of dialog REFER request"),t.delegate&&t.delegate.onReferRequest?t.delegate.onReferRequest(e):e.reject({statusCode:405})},onRegister:function(e){t.logger.warn("Received an out of dialog REGISTER request"),t.delegate&&t.delegate.onRegisterRequest?t.delegate.onRegisterRequest(e):e.reject({statusCode:405})},onSubscribe:function(e){t.logger.warn("Received an out of dialog SUBSCRIBE request"),t.delegate&&t.delegate.onSubscribeRequest?t.delegate.onSubscribeRequest(e):e.reject({statusCode:405})}};return new ai(r,s)}},{key:"initTransportCallbacks",value:function(){var e=this;this.transport.onConnect=function(){return e.onTransportConnect()},this.transport.onDisconnect=function(t){return e.onTransportDisconnect(t)},this.transport.onMessage=function(t){return e.onTransportMessage(t)}}},{key:"onTransportConnect",value:function(){this.state!==xt.Stopped&&this.delegate&&this.delegate.onConnect&&this.delegate.onConnect()}},{key:"onTransportDisconnect",value:function(e){this.state!==xt.Stopped&&(this.delegate&&this.delegate.onDisconnect&&this.delegate.onDisconnect(e),e&&this.options.reconnectionAttempts>0&&this.attemptReconnection())}},{key:"onTransportMessage",value:function(e){var t=this,n=Mt.parseMessage(e,this.getLogger("sip.Parser"));if(n)if(this.state===xt.Stopped&&n instanceof Le)this.logger.warn("Received ".concat(n.method," request while stopped. Dropping."));else{var i=function(){for(var e=0,i=["from","to","call_id","cseq","via"];e<i.length;e++){var r=i[e];if(!n.hasHeader(r))return t.logger.warn("Missing mandatory header field : ".concat(r,".")),!1}return!0};if(n instanceof Le){if(!i())return void this.logger.warn("Request missing mandatory header field. Dropping.");if(!n.toTag&&n.callId.substr(0,5)===this.options.sipjsId)return void this.userAgentCore.replyStateless(n,{statusCode:482});var r=Ne(n.body),s=n.getHeader("content-length");if(s&&r<Number(s))return void this.userAgentCore.replyStateless(n,{statusCode:400})}if(n instanceof Ve){if(!i())return void this.logger.warn("Response missing mandatory header field. Dropping.");if(n.getHeaders("via").length>1)return void this.logger.warn("More than one Via header field present in the response. Dropping.");if(n.via.host!==this.options.viaHost||void 0!==n.via.port)return void this.logger.warn("Via sent-by in the response does not match UA Via host value. Dropping.");var a=Ne(n.body),o=n.getHeader("content-length");if(o&&a<Number(o))return void this.logger.warn("Message body length is lower than the value in Content-Length header field. Dropping.")}if(n instanceof Le)this.userAgentCore.receiveIncomingRequestFromTransport(n);else{if(!(n instanceof Ve))throw new Error("Invalid message type.");this.userAgentCore.receiveIncomingResponseFromTransport(n)}}else this.logger.warn("Failed to parse incoming message. Dropping.")}},{key:"transitionState",value:function(e,t){var n,i=this,r=function(){var t;throw new Error(E(t="Invalid state transition from ".concat(i._state," to ")).call(t,e))};switch(this._state){case xt.Started:e!==xt.Stopped&&r();break;case xt.Stopped:e!==xt.Started&&r();break;default:throw new Error("Unknown state.")}this.logger.log(E(n="Transitioned from ".concat(this._state," to ")).call(n,e)),this._state=e,this._stateEventEmitter.emit(this._state)}}],[{key:"makeURI",value:function(e){return He.URIParse(e)}},{key:"defaultOptions",value:function(){return{errorCallback:function(){},allowLegacyNotifications:!1,authorizationHa1:"",authorizationPassword:"",authorizationUsername:"",delegate:{},contactName:"",contactParams:{transport:"ws"},displayName:"",forceRport:!1,gracefulShutdown:!0,hackAllowUnregisteredOptionTags:!1,hackIpInContact:!1,hackViaTcp:!1,instanceId:"",instanceIdAlwaysAdded:!1,logBuiltinEnabled:!0,logConfiguration:!0,logConnector:function(){},logLevel:"log",noAnswerTimeout:60,preloadedRouteSet:[],reconnectionAttempts:0,reconnectionDelay:4,sendInitialProvisionalResponse:!0,sessionDescriptionHandlerFactory:ci(),sessionDescriptionHandlerFactoryOptions:{},sipExtension100rel:ft.Unsupported,sipExtensionReplaces:ft.Unsupported,sipExtensionExtraSupported:[],sipjsId:"",transportConstructor:li,transportOptions:{},uri:new Ee("sip","anonymous","anonymous.invalid"),userAgentString:"SIP.js/0.21.17",viaHost:""}}},{key:"newUUID",value:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=Math.floor(16*Math.random());return("x"===e?t:t%4+8).toString(16)})}},{key:"stripUndefinedProperties",value:function(e){var t;return O(t=A(e)).call(t,function(t,n){return void 0!==e[n]&&(t[n]=e[n]),t},{})}}])}();var di=function(){return t(function t(i){var r=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,t),d(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"managedSessions",{enumerable:!0,configurable:!0,writable:!0,value:[]}),d(this,"userAgent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"attemptingReconnection",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"optionsPingFailure",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"optionsPingRequest",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"optionsPingRunning",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"optionsPingTimeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"registrationAttemptTimeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"registerer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"registererOptions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"registererRegisterOptions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"shouldBeConnected",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"shouldBeRegistered",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this.delegate=s.delegate,this.options=$({aor:"",autoStop:!0,delegate:{},iceStopWaitingOnServerReflexive:!1,managedSessionFactory:function(e,t){return{session:t,held:!1,muted:!1}},maxSimultaneousSessions:2,media:{},optionsPingInterval:-1,optionsPingRequestURI:"",reconnectionAttempts:3,reconnectionDelay:4,registrationRetry:!1,registrationRetryInterval:3,registerGuard:null,registererOptions:{},registererRegisterOptions:{},sendDTMFUsingSessionDescriptionHandler:!1,userAgentOptions:{}},t.stripUndefinedProperties(s));var a=$({},s.userAgentOptions);if(a.transportConstructor||(a.transportConstructor=li),a.transportOptions||(a.transportOptions={server:i}),!a.uri&&s.aor){var o=ui.makeURI(s.aor);if(!o)throw new Error("Failed to create valid URI from ".concat(s.aor));a.uri=o}if(this.userAgent=new ui(a),this.userAgent.delegate={onConnect:function(){r.logger.log("Connected"),r.delegate&&r.delegate.onServerConnect&&r.delegate.onServerConnect(),r.shouldBeRegistered&&r.register(),r.options.optionsPingInterval>0&&r.optionsPingStart()},onDisconnect:function(e){return ne(r,void 0,void 0,n.mark(function t(){var i,r,s,a,o=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:this.logger.log("Disconnected"),i=!1,this.options.optionsPingInterval>0&&(i=this.optionsPingFailure,this.optionsPingFailure=!1,this.optionsPingStop()),this.delegate&&this.delegate.onServerDisconnect&&this.delegate.onServerDisconnect(e),(e||i)&&(this.registerer&&(this.logger.log("Disposing of registerer..."),this.registerer.dispose().catch(function(e){o.logger.debug("Error occurred disposing of registerer after connection with server was lost."),o.logger.debug(e.toString())}),this.registerer=void 0),h(r=y(s=g(a=this.managedSessions).call(a)).call(s,function(e){return e.session})).call(r,function(e){return ne(o,void 0,void 0,n.mark(function t(){var i=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:this.logger.log("Disposing of session..."),e.dispose().catch(function(e){i.logger.debug("Error occurred disposing of a session after connection with server was lost."),i.logger.debug(e.toString())});case 1:case"end":return t.stop()}},t,this)}))}),this.shouldBeConnected&&this.attemptReconnection());case 1:case"end":return t.stop()}},t,this)}))},onInvite:function(e){r.logger.log("[".concat(e.id,"] Received INVITE"));var t=r.options.maxSimultaneousSessions;if(0!==t&&r.managedSessions.length>t)return r.logger.warn("[".concat(e.id,"] Session already in progress, rejecting INVITE...")),void e.reject().then(function(){r.logger.log("[".concat(e.id,"] Rejected INVITE"))}).catch(function(t){r.logger.error("[".concat(e.id,"] Failed to reject INVITE")),r.logger.error(t.toString())});var n={sessionDescriptionHandlerOptions:{constraints:r.constraints}};r.initSession(e,n),r.delegate&&r.delegate.onCallReceived?r.delegate.onCallReceived(e):(r.logger.warn("[".concat(e.id,"] No handler available, rejecting INVITE...")),e.reject().then(function(){r.logger.log("[".concat(e.id,"] Rejected INVITE"))}).catch(function(t){r.logger.error("[".concat(e.id,"] Failed to reject INVITE")),r.logger.error(t.toString())}))},onMessage:function(e){e.accept().then(function(){r.delegate&&r.delegate.onMessageReceived&&r.delegate.onMessageReceived(e)})},onNotify:function(e){e.accept().then(function(){r.delegate&&r.delegate.onNotificationReceived&&r.delegate.onNotificationReceived(e)})}},this.registererOptions=$({},s.registererOptions),this.registererRegisterOptions=$({},s.registererRegisterOptions),this.options.registrationRetry){this.registererRegisterOptions.requestDelegate=this.registererRegisterOptions.requestDelegate||{};var c=this.registererRegisterOptions.requestDelegate.onReject;this.registererRegisterOptions.requestDelegate.onReject=function(e){c&&c(e),r.attemptRegistration()}}this.logger=this.userAgent.getLogger("sip.SessionManager"),window.addEventListener("online",function(){r.logger.log("Online"),r.shouldBeConnected&&r.connect()}),this.options.autoStop&&window.addEventListener("beforeunload",function(){return ne(r,void 0,void 0,n.mark(function e(){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.shouldBeConnected=!1,this.shouldBeRegistered=!1,this.userAgent.state===xt.Stopped){e.next=1;break}return e.next=1,this.userAgent.stop();case 1:case"end":return e.stop()}},e,this)}))})},[{key:"getLocalMediaStream",value:function(e){var t=e.sessionDescriptionHandler;if(t){if(!(t instanceof oi))throw new Error("Session description handler not instance of web SessionDescriptionHandler");return t.localMediaStream}}},{key:"getRemoteMediaStream",value:function(e){var t=e.sessionDescriptionHandler;if(t){if(!(t instanceof oi))throw new Error("Session description handler not instance of web SessionDescriptionHandler");return t.remoteMediaStream}}},{key:"getLocalAudioTrack",value:function(e){var t,n;return null===(n=this.getLocalMediaStream(e))||void 0===n?void 0:V(t=n.getTracks()).call(t,function(e){return"audio"===e.kind})}},{key:"getLocalVideoTrack",value:function(e){var t,n;return null===(n=this.getLocalMediaStream(e))||void 0===n?void 0:V(t=n.getTracks()).call(t,function(e){return"video"===e.kind})}},{key:"getRemoteAudioTrack",value:function(e){var t,n;return null===(n=this.getRemoteMediaStream(e))||void 0===n?void 0:V(t=n.getTracks()).call(t,function(e){return"audio"===e.kind})}},{key:"getRemoteVideoTrack",value:function(e){var t,n;return null===(n=this.getRemoteMediaStream(e))||void 0===n?void 0:V(t=n.getTracks()).call(t,function(e){return"video"===e.kind})}},{key:"connect",value:function(){return ne(this,void 0,void 0,n.mark(function e(){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.logger.log("Connecting UserAgent..."),this.shouldBeConnected=!0,this.userAgent.state===xt.Started){e.next=1;break}return e.abrupt("return",this.userAgent.start());case 1:return e.abrupt("return",this.userAgent.reconnect());case 2:case"end":return e.stop()}},e,this)}))}},{key:"disconnect",value:function(){return ne(this,void 0,void 0,n.mark(function e(){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.logger.log("Disconnecting UserAgent..."),this.userAgent.state!==xt.Stopped){e.next=1;break}return e.abrupt("return",i.resolve());case 1:return this.shouldBeConnected=!1,this.shouldBeRegistered=!1,this.registerer=void 0,e.abrupt("return",this.userAgent.stop());case 2:case"end":return e.stop()}},e,this)}))}},{key:"isConnected",value:function(){return this.userAgent.isConnected()}},{key:"register",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){var i=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.logger.log("Registering UserAgent..."),this.shouldBeRegistered=!0,void 0!==e&&(this.registererRegisterOptions=$({},e)),this.registerer||(this.registerer=new Dt(this.userAgent,this.registererOptions),this.registerer.stateChange.addListener(function(e){switch(e){case Rt.Initial:break;case Rt.Registered:i.delegate&&i.delegate.onRegistered&&i.delegate.onRegistered();break;case Rt.Unregistered:i.delegate&&i.delegate.onUnregistered&&i.delegate.onUnregistered(),i.shouldBeRegistered&&i.attemptRegistration();break;case Rt.Terminated:break;default:throw new Error("Unknown registerer state.")}})),t.abrupt("return",this.attemptRegistration(!0));case 1:case"end":return t.stop()}},t,this)}))}},{key:"unregister",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.logger.log("Unregistering UserAgent..."),this.shouldBeRegistered=!1,this.registerer){t.next=1;break}return this.logger.warn("No registerer to unregister."),t.abrupt("return",i.resolve());case 1:return t.abrupt("return",this.registerer.unregister(e).then(function(){}));case 2:case"end":return t.stop()}},t,this)}))}},{key:"call",value:function(e,t,r){return ne(this,void 0,void 0,n.mark(function s(){var a,o,c,l,u=this;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.logger.log("Beginning Session..."),!(0!==(a=this.options.maxSimultaneousSessions)&&this.managedSessions.length>a)){n.next=1;break}return n.abrupt("return",i.reject(new Error("Maximum number of sessions already exists.")));case 1:if(o=ui.makeURI(e)){n.next=2;break}return n.abrupt("return",i.reject(new Error('Failed to create a valid URI from "'.concat(e,'"'))));case 2:return t||(t={}),t.sessionDescriptionHandlerOptions||(t.sessionDescriptionHandlerOptions={}),t.sessionDescriptionHandlerOptions.constraints||(t.sessionDescriptionHandlerOptions.constraints=this.constraints),t.earlyMedia&&((r=r||{}).requestDelegate=r.requestDelegate||{},c=r.requestDelegate.onProgress,r.requestDelegate.onProgress=function(e){183===e.message.statusCode&&u.setupRemoteMedia(l),c&&c(e)}),this.options.iceStopWaitingOnServerReflexive&&(t.delegate=t.delegate||{},t.delegate.onSessionDescriptionHandler=function(e){if(!(e instanceof oi))throw new Error("Session description handler not instance of SessionDescriptionHandler");e.peerConnectionDelegate={onicecandidate:function(t){var n;"srflx"===(null===(n=t.candidate)||void 0===n?void 0:n.type)&&(u.logger.log("[".concat(l.id,"] Found srflx ICE candidate, stop waiting...")),e.iceGatheringComplete())}}}),l=new St(this.userAgent,o,t),n.abrupt("return",this.sendInvite(l,t,r).then(function(){return l}));case 3:case"end":return n.stop()}},s,this)}))}},{key:"hangup",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.logger.log("[".concat(e.id,"] Hangup...")),this.sessionExists(e)){t.next=1;break}return t.abrupt("return",i.reject(new Error("Session does not exist.")));case 1:return t.abrupt("return",this.terminate(e));case 2:case"end":return t.stop()}},t,this)}))}},{key:"answer",value:function(e,t){return ne(this,void 0,void 0,n.mark(function r(){return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.logger.log("[".concat(e.id,"] Accepting Invitation...")),this.sessionExists(e)){n.next=1;break}return n.abrupt("return",i.reject(new Error("Session does not exist.")));case 1:if(e instanceof yt){n.next=2;break}return n.abrupt("return",i.reject(new Error("Session not instance of Invitation.")));case 2:return t||(t={}),t.sessionDescriptionHandlerOptions||(t.sessionDescriptionHandlerOptions={}),t.sessionDescriptionHandlerOptions.constraints||(t.sessionDescriptionHandlerOptions.constraints=this.constraints),n.abrupt("return",e.accept(t));case 3:case"end":return n.stop()}},r,this)}))}},{key:"decline",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.logger.log("[".concat(e.id,"] Rejecting Invitation...")),this.sessionExists(e)){t.next=1;break}return t.abrupt("return",i.reject(new Error("Session does not exist.")));case 1:if(e instanceof yt){t.next=2;break}return t.abrupt("return",i.reject(new Error("Session not instance of Invitation.")));case 2:return t.abrupt("return",e.reject());case 3:case"end":return t.stop()}},t,this)}))}},{key:"hold",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.logger.log("[".concat(e.id,"] Holding session...")),t.abrupt("return",this.setHold(e,!0));case 1:case"end":return t.stop()}},t,this)}))}},{key:"unhold",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.logger.log("[".concat(e.id,"] Unholding session...")),t.abrupt("return",this.setHold(e,!1));case 1:case"end":return t.stop()}},t,this)}))}},{key:"isHeld",value:function(e){var t=this.sessionManaged(e);return!!t&&t.held}},{key:"mute",value:function(e){this.logger.log("[".concat(e.id,"] Disabling media tracks...")),this.setMute(e,!0)}},{key:"unmute",value:function(e){this.logger.log("[".concat(e.id,"] Enabling media tracks...")),this.setMute(e,!1)}},{key:"isMuted",value:function(e){var t=this.sessionManaged(e);return!!t&&t.muted}},{key:"sendDTMF",value:function(e,t){return ne(this,void 0,void 0,n.mark(function r(){var s,a;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.logger.log("[".concat(e.id,"] Sending DTMF...")),/^[0-9A-D#*,]$/.exec(t)){n.next=1;break}return n.abrupt("return",i.reject(new Error("Invalid DTMF tone.")));case 1:if(this.sessionExists(e)){n.next=2;break}return n.abrupt("return",i.reject(new Error("Session does not exist.")));case 2:if(this.logger.log(E(s="[".concat(e.id,"] Sending DTMF tone: ")).call(s,t)),!this.options.sendDTMFUsingSessionDescriptionHandler){n.next=5;break}if(e.sessionDescriptionHandler){n.next=3;break}return n.abrupt("return",i.reject(new Error("Session desciption handler undefined.")));case 3:if(e.sessionDescriptionHandler.sendDtmf(t)){n.next=4;break}return n.abrupt("return",i.reject(new Error("Failed to send DTMF")));case 4:return n.abrupt("return",i.resolve());case 5:return a={body:{contentDisposition:"render",contentType:"application/dtmf-relay",content:"Signal="+t+"\r\nDuration=2000"}},n.abrupt("return",e.info({requestOptions:a}).then(function(){}));case 6:case"end":return n.stop()}},r,this)}))}},{key:"transfer",value:function(e,t,r){return ne(this,void 0,void 0,n.mark(function s(){var a;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.logger.log("[".concat(e.id,"] Referring session...")),!(t instanceof vt)){n.next=1;break}return n.abrupt("return",e.refer(t,r).then(function(){}));case 1:if(a=ui.makeURI(t)){n.next=2;break}return n.abrupt("return",i.reject(new Error('Failed to create a valid URI from "'.concat(t,'"'))));case 2:return n.abrupt("return",e.refer(a,r).then(function(){}));case 3:case"end":return n.stop()}},s,this)}))}},{key:"message",value:function(e,t){return ne(this,void 0,void 0,n.mark(function r(){var s;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.logger.log("Sending message..."),s=ui.makeURI(e)){n.next=1;break}return n.abrupt("return",i.reject(new Error('Failed to create a valid URI from "'.concat(e,'"'))));case 1:return n.abrupt("return",new It(this.userAgent,s,t).message());case 2:case"end":return n.stop()}},r,this)}))}},{key:"constraints",get:function(){var e={audio:!0,video:!1};return this.options.media.constraints&&(e=$({},this.options.media.constraints)),e}},{key:"attemptReconnection",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,n=this.options.reconnectionAttempts,i=this.options.reconnectionDelay;if(this.shouldBeConnected)if(this.attemptingReconnection&&this.logger.log("Reconnection attempt already in progress"),t>n)this.logger.log("Reconnection maximum attempts reached");else{var r,s,a;if(1===t)this.logger.log(E(r="Reconnection attempt ".concat(t," of ")).call(r,n," - trying"));else this.logger.log(E(s=E(a="Reconnection attempt ".concat(t," of ")).call(a,n," - trying in ")).call(s,i," seconds"));this.attemptingReconnection=!0,m(function(){var i;if(!e.shouldBeConnected)return e.logger.log(E(i="Reconnection attempt ".concat(t," of ")).call(i,n," - aborted")),void(e.attemptingReconnection=!1);e.userAgent.reconnect().then(function(){var i;e.logger.log(E(i="Reconnection attempt ".concat(t," of ")).call(i,n," - succeeded")),e.attemptingReconnection=!1}).catch(function(i){var r;e.logger.log(E(r="Reconnection attempt ".concat(t," of ")).call(r,n," - failed")),e.logger.error(i.message),e.attemptingReconnection=!1,e.attemptReconnection(++t)})},1===t?0:1e3*i)}else this.logger.log("Should not be connected currently")}},{key:"attemptRegistration",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(this.logger.log("Registration attempt ".concat(t?"without delay":"")),!this.shouldBeRegistered)return this.logger.log("Should not be registered currently"),i.resolve();if(void 0!==this.registrationAttemptTimeout)return this.logger.log("Registration attempt already in progress"),i.resolve();return new i(function(n,r){var s,a;e.registrationAttemptTimeout=m(function(){(e.registerer?e.isConnected()?e.userAgent.state===xt.Stopped?(e.logger.log("User agent stopped"),i.resolve()):e.options.registerGuard?e.options.registerGuard().catch(function(t){throw e.logger.log("Register guard rejected will making registration attempt"),t}).then(function(t){return t||!e.registerer?i.resolve():e.registerer.register(e.registererRegisterOptions).then(function(){})}):e.registerer.register(e.registererRegisterOptions).then(function(){}):(e.logger.log("User agent not connected"),i.resolve()):(e.logger.log("Registerer undefined"),i.resolve())).then(function(){e.registrationAttemptTimeout=void 0,n()}).catch(function(t){e.registrationAttemptTimeout=void 0,t instanceof ue?n():r(t)})},t?0:(s=e.options.registrationRetryInterval,a=2*s,1e3*(Math.random()*(a-s)+s)))})}},{key:"cleanupMedia",value:function(e){var t=this.sessionManaged(e);if(!t)throw new Error("Managed session does not exist.");t.mediaLocal&&t.mediaLocal.video&&(t.mediaLocal.video.srcObject=null,t.mediaLocal.video.pause()),t.mediaRemote&&(t.mediaRemote.audio&&(t.mediaRemote.audio.srcObject=null,t.mediaRemote.audio.pause()),t.mediaRemote.video&&(t.mediaRemote.video.srcObject=null,t.mediaRemote.video.pause()))}},{key:"enableReceiverTracks",value:function(e,t){if(!this.sessionExists(e))throw new Error("Session does not exist.");var n=e.sessionDescriptionHandler;if(!(n instanceof oi))throw new Error("Session's session description handler not instance of SessionDescriptionHandler.");n.enableReceiverTracks(t)}},{key:"enableSenderTracks",value:function(e,t){if(!this.sessionExists(e))throw new Error("Session does not exist.");var n=e.sessionDescriptionHandler;if(!(n instanceof oi))throw new Error("Session's session description handler not instance of SessionDescriptionHandler.");n.enableSenderTracks(t)}},{key:"initSession",value:function(e,t){var n=this;this.sessionAdd(e),this.delegate&&this.delegate.onCallCreated&&this.delegate.onCallCreated(e),e.stateChange.addListener(function(t){var i;switch(n.logger.log(E(i="[".concat(e.id,"] Session state changed to ")).call(i,t)),t){case ot.Initial:case ot.Establishing:break;case ot.Established:n.setupLocalMedia(e),n.setupRemoteMedia(e),n.delegate&&n.delegate.onCallAnswered&&n.delegate.onCallAnswered(e);break;case ot.Terminating:case ot.Terminated:n.sessionExists(e)&&(n.cleanupMedia(e),n.sessionRemove(e),n.delegate&&n.delegate.onCallHangup&&n.delegate.onCallHangup(e));break;default:throw new Error("Unknown session state.")}}),e.delegate=e.delegate||{},e.delegate.onInfo=function(t){var i;if(void 0!==(null===(i=n.delegate)||void 0===i?void 0:i.onCallDTMFReceived)){var r=t.request.getHeader("content-type");if(r&&/^application\/dtmf-relay/i.exec(r)){var s=t.request.body.split("\r\n",2);if(2===s.length){var a,o=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/;if(void 0!==s[0]&&o.test(s[0])&&(a=s[0].replace(o,"$2")),a){var c,l=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;void 0!==s[1]&&l.test(s[1])&&(c=T(s[1].replace(l,"$2"),10)),c?t.accept().then(function(){if(n.delegate&&n.delegate.onCallDTMFReceived){if(!a||!c)throw new Error("Tone or duration undefined.");n.delegate.onCallDTMFReceived(e,a,c)}}).catch(function(e){n.logger.error(e.message)}):t.reject()}else t.reject()}else t.reject()}else t.reject()}else t.reject()},e.delegate.onRefer=function(e){e.accept().then(function(){return n.sendInvite(e.makeInviter(t),t)}).catch(function(e){n.logger.error(e.message)})}}},{key:"optionsPingRun",value:function(e,t,n){var i=this;if(this.options.optionsPingInterval<1)throw new Error("Invalid options ping interval.");this.optionsPingRunning||(this.optionsPingRunning=!0,this.optionsPingTimeout=m(function(){i.optionsPingTimeout=void 0;var r=function(){i.optionsPingFailure=!1,i.optionsPingRunning&&(i.optionsPingRunning=!1,i.optionsPingRun(e,t,n))},s=i.userAgent.userAgentCore,a=s.makeOutgoingRequestMessage("OPTIONS",e,t,n,{});i.optionsPingRequest=s.request(a,{onAccept:function(){i.optionsPingRequest=void 0,r()},onReject:function(e){i.optionsPingRequest=void 0,408===e.message.statusCode||503===e.message.statusCode?(i.logger.error("OPTIONS ping failed"),i.optionsPingFailure=!0,i.optionsPingRunning=!1,i.userAgent.transport.disconnect().catch(function(e){return i.logger.error(e)})):r()}})},1e3*this.options.optionsPingInterval))}},{key:"optionsPingStart",value:function(){var e,t,n;if(this.logger.log("OPTIONS pings started"),this.options.optionsPingRequestURI){if(!(e=ui.makeURI(this.options.optionsPingRequestURI)))throw new Error("Failed to create Request URI.");t=this.userAgent.contact.uri.clone(),n=this.userAgent.contact.uri.clone()}else{if(!this.options.aor)return void this.logger.error("You have enabled sending OPTIONS pings and as such you must provide either a) an AOR to register, or b) an RURI to use for the target of the OPTIONS ping requests. ");var i=ui.makeURI(this.options.aor);if(!i)throw new Error("Failed to create URI.");(e=i.clone()).user=void 0,t=i.clone(),n=i.clone()}this.optionsPingRun(e,t,n)}},{key:"optionsPingStop",value:function(){this.logger.log("OPTIONS pings stopped"),this.optionsPingRunning=!1,this.optionsPingFailure=!1,this.optionsPingRequest&&(this.optionsPingRequest.dispose(),this.optionsPingRequest=void 0),this.optionsPingTimeout&&(clearTimeout(this.optionsPingTimeout),this.optionsPingTimeout=void 0)}},{key:"sendInvite",value:function(e,t,i){return ne(this,void 0,void 0,n.mark(function r(){var s=this;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return this.initSession(e,t),n.abrupt("return",e.invite(i).then(function(){s.logger.log("[".concat(e.id,"] Sent INVITE"))}));case 1:case"end":return n.stop()}},r,this)}))}},{key:"sessionAdd",value:function(e){var t=this.options.managedSessionFactory(this,e);this.managedSessions.push(t)}},{key:"sessionExists",value:function(e){return void 0!==this.sessionManaged(e)}},{key:"sessionManaged",value:function(e){var t;return V(t=this.managedSessions).call(t,function(t){return t.session.id===e.id})}},{key:"sessionRemove",value:function(e){var t;this.managedSessions=f(t=this.managedSessions).call(t,function(t){return t.session.id!==e.id})}},{key:"setHold",value:function(e,t){return ne(this,void 0,void 0,n.mark(function r(){var s,a,o,c=this;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.sessionExists(e)){n.next=1;break}return n.abrupt("return",i.reject(new Error("Session does not exist.")));case 1:if(this.isHeld(e)!==t){n.next=2;break}return n.abrupt("return",i.resolve());case 2:if(e.sessionDescriptionHandler instanceof oi){n.next=3;break}throw new Error("Session's session description handler not instance of SessionDescriptionHandler.");case 3:if(s={requestDelegate:{onAccept:function(){var n=c.sessionManaged(e);void 0!==n&&(n.held=t,c.enableReceiverTracks(e,!n.held),c.enableSenderTracks(e,!n.held&&!n.muted),c.delegate&&c.delegate.onCallHold&&c.delegate.onCallHold(e,n.held))},onReject:function(){c.logger.warn("[".concat(e.id,"] Re-invite request was rejected"));var n=c.sessionManaged(e);void 0!==n&&(n.held=!t,c.enableReceiverTracks(e,!n.held),c.enableSenderTracks(e,!n.held&&!n.muted),c.delegate&&c.delegate.onCallHold&&c.delegate.onCallHold(e,n.held))}}},(a=e.sessionDescriptionHandlerOptionsReInvite).hold=t,e.sessionDescriptionHandlerOptionsReInvite=a,o=this.sessionManaged(e)){n.next=4;break}throw new Error("Managed session is undefiend.");case 4:return o.held=t,n.abrupt("return",e.invite(s).then(function(){var t=c.sessionManaged(e);void 0!==t&&(c.enableReceiverTracks(e,!t.held),c.enableSenderTracks(e,!t.held&&!t.muted))}).catch(function(n){throw o.held=!t,n instanceof ue&&c.logger.error("[".concat(e.id,"] A hold request is already in progress.")),n}));case 5:case"end":return n.stop()}},r,this)}))}},{key:"setMute",value:function(e,t){if(this.sessionExists(e))if(e.state===ot.Established){var n=this.sessionManaged(e);void 0!==n&&(n.muted=t,this.enableSenderTracks(e,!n.held&&!n.muted))}else this.logger.warn("[".concat(e.id,"] An established session is required to enable/disable media tracks"));else this.logger.warn("[".concat(e.id,"] A session is required to enabled/disable media tracks"))}},{key:"setupLocalMedia",value:function(e){var t=this,n=this.sessionManaged(e);if(!n)throw new Error("Managed session does not exist.");var i="function"==typeof this.options.media.local?this.options.media.local(e):this.options.media.local;n.mediaLocal=i;var r=null==i?void 0:i.video;if(r){var s=this.getLocalMediaStream(e);if(!s)throw new Error("Local media stream undefiend.");r.srcObject=s,r.volume=0,r.play().catch(function(n){t.logger.error("[".concat(e.id,"] Failed to play local media")),t.logger.error(n.message)})}}},{key:"setupRemoteMedia",value:function(e){var t=this,n=this.sessionManaged(e);if(!n)throw new Error("Managed session does not exist.");var i="function"==typeof this.options.media.remote?this.options.media.remote(e):this.options.media.remote;n.mediaRemote=i;var r=(null==i?void 0:i.video)||(null==i?void 0:i.audio);if(r){var s=this.getRemoteMediaStream(e);if(!s)throw new Error("Remote media stream undefiend.");r.autoplay=!0,r.srcObject=s,r.play().catch(function(n){t.logger.error("[".concat(e.id,"] Failed to play remote media")),t.logger.error(n.message)}),s.onaddtrack=function(){t.logger.log("Remote media onaddtrack"),r.load(),r.play().catch(function(n){t.logger.error("[".concat(e.id,"] Failed to play remote media")),t.logger.error(n.message)})}}}},{key:"terminate",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){var r,s,a=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:this.logger.log("[".concat(e.id,"] Terminating...")),s=e.state,t.next=s===ot.Initial?1:s===ot.Establishing?4:s===ot.Established?7:s===ot.Terminating?8:s===ot.Terminated?9:10;break;case 1:if(!(e instanceof St)){t.next=2;break}return t.abrupt("return",e.cancel().then(function(){a.logger.log("[".concat(e.id,"] Inviter never sent INVITE (canceled)"))}));case 2:if(!(e instanceof yt)){t.next=3;break}return t.abrupt("return",e.reject().then(function(){a.logger.log("[".concat(e.id,"] Invitation rejected (sent 480)"))}));case 3:case 6:throw new Error("Unknown session type.");case 4:if(!(e instanceof St)){t.next=5;break}return t.abrupt("return",e.cancel().then(function(){a.logger.log("[".concat(e.id,"] Inviter canceled (sent CANCEL)"))}));case 5:if(!(e instanceof yt)){t.next=6;break}return t.abrupt("return",e.reject().then(function(){a.logger.log("[".concat(e.id,"] Invitation rejected (sent 480)"))}));case 7:return t.abrupt("return",e.bye().then(function(){a.logger.log("[".concat(e.id,"] Session ended (sent BYE)"))}));case 8:case 9:return t.abrupt("continue",11);case 10:throw new Error("Unknown state");case 11:return this.logger.log(E(r="[".concat(e.id,"] Terminating in state ")).call(r,e.state,", no action taken")),t.abrupt("return",i.resolve());case 12:case"end":return t.stop()}},t,this)}))}}],[{key:"stripUndefinedProperties",value:function(e){var t;return O(t=A(e)).call(t,function(t,n){return void 0!==e[n]&&(t[n]=e[n]),t},{})}}])}(),hi=function(){return t(function t(n){var i=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,t),d(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"session",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"sessionManager",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.delegate=r.delegate,this.options=$({},r);var s={aor:this.options.aor,delegate:{onCallAnswered:function(){var e,t;return null===(t=null===(e=i.delegate)||void 0===e?void 0:e.onCallAnswered)||void 0===t?void 0:t.call(e)},onCallCreated:function(e){var t,n;i.session=e,null===(n=null===(t=i.delegate)||void 0===t?void 0:t.onCallCreated)||void 0===n||n.call(t)},onCallReceived:function(){var e,t;return null===(t=null===(e=i.delegate)||void 0===e?void 0:e.onCallReceived)||void 0===t?void 0:t.call(e)},onCallHangup:function(){var e,t;i.session=void 0,(null===(e=i.delegate)||void 0===e?void 0:e.onCallHangup)&&(null===(t=i.delegate)||void 0===t||t.onCallHangup())},onCallHold:function(e,t){var n,r;return null===(r=null===(n=i.delegate)||void 0===n?void 0:n.onCallHold)||void 0===r?void 0:r.call(n,t)},onCallDTMFReceived:function(e,t,n){var r,s;return null===(s=null===(r=i.delegate)||void 0===r?void 0:r.onCallDTMFReceived)||void 0===s?void 0:s.call(r,t,n)},onMessageReceived:function(e){var t,n;return null===(n=null===(t=i.delegate)||void 0===t?void 0:t.onMessageReceived)||void 0===n?void 0:n.call(t,e.request.body)},onRegistered:function(){var e,t;return null===(t=null===(e=i.delegate)||void 0===e?void 0:e.onRegistered)||void 0===t?void 0:t.call(e)},onUnregistered:function(){var e,t;return null===(t=null===(e=i.delegate)||void 0===e?void 0:e.onUnregistered)||void 0===t?void 0:t.call(e)},onServerConnect:function(){var e,t;return null===(t=null===(e=i.delegate)||void 0===e?void 0:e.onServerConnect)||void 0===t?void 0:t.call(e)},onServerDisconnect:function(){var e,t;return null===(t=null===(e=i.delegate)||void 0===e?void 0:e.onServerDisconnect)||void 0===t?void 0:t.call(e)}},maxSimultaneousSessions:1,media:this.options.media,reconnectionAttempts:this.options.reconnectionAttempts,reconnectionDelay:this.options.reconnectionDelay,registererOptions:this.options.registererOptions,sendDTMFUsingSessionDescriptionHandler:this.options.sendDTMFUsingSessionDescriptionHandler,userAgentOptions:this.options.userAgentOptions};this.sessionManager=new di(n,s),this.logger=this.sessionManager.userAgent.getLogger("sip.SimpleUser")},[{key:"id",get:function(){return this.options.userAgentOptions&&this.options.userAgentOptions.displayName||"Anonymous"}},{key:"localMediaStream",get:function(){return this.session&&this.sessionManager.getLocalMediaStream(this.session)}},{key:"remoteMediaStream",get:function(){return this.session&&this.sessionManager.getRemoteMediaStream(this.session)}},{key:"localAudioTrack",get:function(){return this.session&&this.sessionManager.getLocalAudioTrack(this.session)}},{key:"localVideoTrack",get:function(){return this.session&&this.sessionManager.getLocalVideoTrack(this.session)}},{key:"remoteAudioTrack",get:function(){return this.session&&this.sessionManager.getRemoteAudioTrack(this.session)}},{key:"remoteVideoTrack",get:function(){return this.session&&this.sessionManager.getRemoteVideoTrack(this.session)}},{key:"connect",value:function(){return this.logger.log("[".concat(this.id,"] Connecting UserAgent...")),this.sessionManager.connect()}},{key:"disconnect",value:function(){return this.logger.log("[".concat(this.id,"] Disconnecting UserAgent...")),this.sessionManager.disconnect()}},{key:"isConnected",value:function(){return this.sessionManager.isConnected()}},{key:"register",value:function(e){return this.logger.log("[".concat(this.id,"] Registering UserAgent...")),this.sessionManager.register(e)}},{key:"unregister",value:function(e){return this.logger.log("[".concat(this.id,"] Unregistering UserAgent...")),this.sessionManager.unregister(e)}},{key:"call",value:function(e,t,n){return this.logger.log("[".concat(this.id,"] Beginning Session...")),this.session?i.reject(new Error("Session already exists.")):this.sessionManager.call(e,t,n).then(function(){})}},{key:"hangup",value:function(){var e=this;return this.logger.log("[".concat(this.id,"] Hangup...")),this.session?this.sessionManager.hangup(this.session).then(function(){e.session=void 0}):i.reject(new Error("Session does not exist."))}},{key:"answer",value:function(e){return this.logger.log("[".concat(this.id,"] Accepting Invitation...")),this.session?this.sessionManager.answer(this.session,e):i.reject(new Error("Session does not exist."))}},{key:"decline",value:function(){return this.logger.log("[".concat(this.id,"] rejecting Invitation...")),this.session?this.sessionManager.decline(this.session):i.reject(new Error("Session does not exist."))}},{key:"hold",value:function(){return this.logger.log("[".concat(this.id,"] holding session...")),this.session?this.sessionManager.hold(this.session):i.reject(new Error("Session does not exist."))}},{key:"unhold",value:function(){return this.logger.log("[".concat(this.id,"] unholding session...")),this.session?this.sessionManager.unhold(this.session):i.reject(new Error("Session does not exist."))}},{key:"isHeld",value:function(){return!!this.session&&this.sessionManager.isHeld(this.session)}},{key:"mute",value:function(){return this.logger.log("[".concat(this.id,"] disabling media tracks...")),this.session&&this.sessionManager.mute(this.session)}},{key:"unmute",value:function(){return this.logger.log("[".concat(this.id,"] enabling media tracks...")),this.session&&this.sessionManager.unmute(this.session)}},{key:"isMuted",value:function(){return!!this.session&&this.sessionManager.isMuted(this.session)}},{key:"sendDTMF",value:function(e){return this.logger.log("[".concat(this.id,"] sending DTMF...")),this.session?this.sessionManager.sendDTMF(this.session,e):i.reject(new Error("Session does not exist."))}},{key:"message",value:function(e,t){return this.logger.log("[".concat(this.id,"] sending message...")),this.sessionManager.message(e,t)}}])}();function gi(e){return document.getElementById(e)}function fi(e){if(e&&e.getTracks)try{var t=e.getTracks();h(t).call(t,function(e){try{e.stop()}catch(e){}})}catch(e){}}function vi(e){return navigator.mediaDevices.getUserMedia(e).then(function(e){return e?(fi(e),!0):i.reject(new Error("EmptyStreamError"))}).catch(function(e){return(!e||"NotAllowedError"!==e.name)&&i.reject(e)})}function pi(){try{var e;if(-1===q(e=navigator.userAgent).call(e,"Firefox"))return vi({video:!1,audio:!0}).catch(function(){return!0})}catch(e){console.log(e)}}function mi(e){var t=gi(e);t&&(t.currentTime=0,t.play())}function bi(e){var t=gi(e);t&&(t.currentTime=0,t.pause())}function yi(e){var t=gi(e);t&&(t.srcObject=null,t.pause())}var wi,ki,Ti=function(e){var t,n,i;return K(t=e.getHours().toString()).call(t,2,"0")+":"+K(n=e.getMinutes().toString()).call(n,2,"0")+":"+K(i=e.getSeconds().toString()).call(i,2,"0")},Ri=function(){return new Date(new Date((new Date).toLocaleDateString()).getTime())},Si=function(e){return new Date(e.setSeconds(e.getSeconds()+1))};function Ii(e){var t=Ri();e(Ti(t));var n=L(function(){var n=Si(t),i=Ti(n);e(i)},1e3);return function(){clearInterval(n),n=null}}function Ei(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!=q(r).call(r,"json")?e(JSON.parse(i.responseText)):-1!=q(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",l=r,u=null;return s&&("GET"===c?l=l+"?"+function(e){var t=[];for(var n in e)t.push(n+"="+e[n]);return t.join("&")}(s):"POST"===c&&(u=C(s))),i.open(c,l,!0),{xhr:i,ajaxData:u,contentType:o}}function Ci(){var e,t,n,i,r,s=new Date,a=s.getUTCFullYear(),o=s.getUTCMonth()+1,c=s.getUTCDate(),l=s.getUTCHours(),u=s.getUTCMinutes(),d=s.getUTCSeconds(),h=new Date(Date.UTC(a,o-1,c,l+8,u,d)),g=function(e){var t;return K(t=String(e)).call(t,2,"0")},f=h.getUTCFullYear(),v=g(h.getUTCMonth()+1),p=g(h.getUTCDate()),m=g(h.getUTCHours()),b=g(h.getUTCMinutes()),y=g(h.getUTCSeconds());return E(e=E(t=E(n=E(i=E(r="".concat(f,"-")).call(r,v,"-")).call(i,p," ")).call(n,m,":")).call(t,b,":")).call(e,y)}var Ai,xi,Di,Hi,_i,$i,qi,Mi,Pi=E(wi="sip:".concat("","@")).call(wi,""),Oi=E(ki="".concat("","://")).call(ki,""),Ni={authorizationPassword:"",authorizationUsername:"",viaHost:"",uri:ui.makeURI(Pi),logLevel:"error",transportOptions:{server:Oi},contactName:""},ji={connectStatus:!1,registerStatus:!1,invitatingStatus:!1,incomingStatus:!1,answerStatus:!1,reconnectStatus:!1};!function(e){e.NO="0",e.YES="1"}(Ai||(Ai={})),function(e){e.NO="0",e.YES="1"}(xi||(xi={})),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",e.VOICE_TEST="7",e.CALL_IN_AI="8",e.CALL_IN_LABOUR="9",e.MOVIE_CALL="10",e.GATEWAY_TEST_CALL="11"}(Di||(Di={})),function(e){e.DIRECT_ANSWER="1",e.LISTEN_FIRST_AND_THEN_ANSWER_MANUALLY="2"}(Hi||(Hi={}));var Fi=function(){function n(){e(this,n)}return t(n,null,[{key:"getAliArms",value:function(e){var t=e&&e!==ie(this,_i,"f",qi);return t&&re(this,_i,e,"f",qi),ie(this,_i,"f",$i)&&!t||(re(this,_i,new te({uid:ie(this,_i,"f",qi),pid:"jjn8k2jk90@aa39edd52601f08",appType:"web",imgUrl:"https://arms-retcode.aliyuncs.com/r.png?",release:"6.0.12",environment:"prod",sendResource:!1,autoSendPerf:!1,useFmp:!1,autoSendPv:!1,enableSPA:!1,jsReport:!1,behavior:!1,enableConsole:!1,disableHook:!0,ignore:{ignoreErrors:[function(){return!0}],ignoreResErrors:[function(){return!0}]}}),"f",$i),ie(this,_i,"f",Mi).push({uid:ie(this,_i,"f",qi),aliArms:ie(this,_i,"f",$i)})),ie(this,_i,"f",$i)}},{key:"getAliArmsList",value:function(){return ie(this,_i,"f",Mi)}},{key:"errReport",value:function(e,t){var i;null===(i=n.getAliArms(t))||void 0===i||i.errReport(e)}}])}();_i=Fi,$i={value:void 0},qi={value:void 0},Mi={value:[]};var Ui,Bi,Li,Gi,Vi,Wi,Ki,Yi,zi,Zi,Ji,Xi,Qi,er,tr,nr,ir,rr,sr,ar,or,cr,lr,ur,dr,hr,gr,fr,vr,pr,mr,br,yr,wr,kr,Tr,Rr,Sr,Ir,Er,Cr,Ar,xr,Dr,Hr,_r,$r,qr,Mr,Pr,Or,Nr,jr,Fr,Ur,Br,Lr,Gr,Vr,Wr,Kr,Yr,zr,Zr,Jr,Xr,Qr,es,ts,ns,is,rs,ss,as,os,cs,ls,us,ds,hs,gs,fs,vs,ps,ms,bs,ys,ws,ks,Ts,Rs,Ss,Is,Es,Cs,As,xs,Ds,Hs,_s,$s,qs,Ms,Ps,Os,Ns,js,Fs,Us,Bs,Ls,Gs,Vs,Ws,Ks,Ys,zs,Zs,Js,Xs,Qs,ea,ta,na,ia,ra,sa,aa,oa,ca,la,ua,da,ha,ga,fa=function(){return t(function t(i,s){var a,o,c,l,u,h,g,f,v,p,b,y,w,k,T,R,S,I,E,C,A,x,D,H,_=this,$=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};e(this,t),d(this,"session",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"userAgentManager",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:"idle"}),d(this,"destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"bound",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"hardFailed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"retryCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),d(this,"signalingBusyCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),d(this,"disconnectedTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"retryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"signalingBusyTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"negotiationTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"iceRecoveryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"rtpStatsTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"onlineTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"transportRecoveryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"registrationRecoveryTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"transportWaitStartedAt",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"pendingTransportRecoveryReason",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"registrationWaitStartedAt",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"pendingRegistrationRecoveryReason",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"lastRtpSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"lastRtpProgressAt",{enumerable:!0,configurable:!0,writable:!0,value:r()}),d(this,"lastRtpRecoveryAt",{enumerable:!0,configurable:!0,writable:!0,value:0}),d(this,"recoveryGeneration",{enumerable:!0,configurable:!0,writable:!0,value:0}),d(this,"acceptedRecoveryGeneration",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"recoveryReason",{enumerable:!0,configurable:!0,writable:!0,value:""}),d(this,"reinviteReason",{enumerable:!0,configurable:!0,writable:!0,value:"unknown"}),d(this,"permanentRecoverySdpModifier",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return ne(_,void 0,void 0,n.mark(function t(){return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.applyRecoveryReasonToSdp(e));case 1:case"end":return t.stop()}},t,this)}))}}),d(this,"handleSessionStateChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e){switch(_.logInfo("SIP session state:",e),e){case ot.Established:_.handleEstablished();break;case ot.Terminating:case ot.Terminated:_.destroy()}}}),d(this,"handleOffline",{enumerable:!0,configurable:!0,writable:!0,value:function(){_.destroyed||_.hardFailed||(_.logInfo("browser offline"),_.clearDisconnectedTimer(),_.clearRetryTimer(),_.clearSignalingBusyTimer(),_.clearIceRecoveryTimer(),_.clearTransportRecoveryTimer(),"sending-reinvite"!==_.state&&(_.state="idle"))}}),d(this,"handleOnline",{enumerable:!0,configurable:!0,writable:!0,value:function(){_.destroyed||_.hardFailed||(_.logInfo("browser online"),_.onlineTimer&&clearTimeout(_.onlineTimer),_.onlineTimer=m(function(){if(_.onlineTimer=void 0,!_.destroyed&&!_.hardFailed&&_.session.state===ot.Established)if(_.isTransportAvailable()){var e=_.getPeerConnection();if(e)if("stable"===e.signalingState)switch(e.iceConnectionState){case"failed":case"disconnected":_.state="idle",_.recover("network-online")}else _.scheduleSignalingBusyRetry("network-online:".concat(e.signalingState))}else _.waitForTransport("network-online")},_.options.onlineRecoveryDelayMs))}}),this.session=i,this.userAgentManager=s,this.options={disconnectedTimeoutMs:null!==(a=$.disconnectedTimeoutMs)&&void 0!==a?a:3e3,negotiationTimeoutMs:null!==(o=$.negotiationTimeoutMs)&&void 0!==o?o:1e4,iceRecoveryTimeoutMs:null!==(c=$.iceRecoveryTimeoutMs)&&void 0!==c?c:1e4,iceGatheringTimeoutMs:null!==(l=$.iceGatheringTimeoutMs)&&void 0!==l?l:5e3,maxRetries:null!==(u=$.maxRetries)&&void 0!==u?u:3,retryBaseDelayMs:null!==(h=$.retryBaseDelayMs)&&void 0!==h?h:1e3,retryMaxDelayMs:null!==(g=$.retryMaxDelayMs)&&void 0!==g?g:1e4,maxSignalingBusyRetries:null!==(f=$.maxSignalingBusyRetries)&&void 0!==f?f:3,signalingBusyRetryDelayMs:null!==(v=$.signalingBusyRetryDelayMs)&&void 0!==v?v:1e3,enableRtpWatchdog:null===(p=$.enableRtpWatchdog)||void 0===p||p,rtpStatsIntervalMs:null!==(b=$.rtpStatsIntervalMs)&&void 0!==b?b:1e3,rtpStallTimeoutMs:null!==(y=$.rtpStallTimeoutMs)&&void 0!==y?y:5e3,recoverOnRtpStallWhenIceConnected:null===(w=$.recoverOnRtpStallWhenIceConnected)||void 0===w||w,rtpRecoveryCooldownMs:null!==(k=$.rtpRecoveryCooldownMs)&&void 0!==k?k:1e4,onlineRecoveryDelayMs:null!==(T=$.onlineRecoveryDelayMs)&&void 0!==T?T:800,transportRecoveryPollMs:null!==(R=$.transportRecoveryPollMs)&&void 0!==R?R:1e3,transportRecoveryTimeoutMs:null!==(S=$.transportRecoveryTimeoutMs)&&void 0!==S?S:6e4,registrationRecoveryPollMs:null!==(I=$.registrationRecoveryPollMs)&&void 0!==I?I:1e3,registrationRecoveryTimeoutMs:null!==(E=$.registrationRecoveryTimeoutMs)&&void 0!==E?E:6e4,debugIceCredentials:null!==(C=$.debugIceCredentials)&&void 0!==C&&C,includeRecoveryReasonInSdp:null===(A=$.includeRecoveryReasonInSdp)||void 0===A||A,recoveryReasonSdpAttribute:null!==(x=$.recoveryReasonSdpAttribute)&&void 0!==x?x:"x-recovery-reason",reinviteReasonSdpAttribute:null!==(D=$.reinviteReasonSdpAttribute)&&void 0!==D?D:"x-reinvite-reason",isSignalingAvailable:$.isSignalingAvailable,isRegistrationAvailable:$.isRegistrationAvailable,logger:null!==(H=$.logger)&&void 0!==H?H:console,onRecoveryStart:$.onRecoveryStart,onRecovered:$.onRecovered,onRecoveryFailed:$.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===ot.Established&&this.handleEstablished())}},{key:"restartNow",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"manual";return ne(this,void 0,void 0,n.mark(function t(){return n.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=m(function(){if(e.disconnectedTimer=void 0,!e.destroyed&&!e.hardFailed){var t=e.getPeerConnection();if(t){if("disconnected"===t.iceConnectionState)return e.state="idle",void e.recover("ice-disconnected-timeout");e.logInfo("ICE self recovered:",t.iceConnectionState),e.state="idle"}}},this.options.disconnectedTimeoutMs)))}},{key:"handleIceRecovered",value:function(){var e,t;if(!this.destroyed&&!this.hardFailed){var n="idle"!==this.state||this.retryCount>0;!n||"sending-reinvite"!==this.state&&"waiting-ice"!==this.state||this.acceptedRecoveryGeneration===this.recoveryGeneration?(this.clearDisconnectedTimer(),this.clearRetryTimer(),this.clearSignalingBusyTimer(),this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.clearTransportRecoveryTimer(),this.clearRegistrationRecoveryTimer(),this.transportWaitStartedAt=void 0,this.pendingTransportRecoveryReason=void 0,this.registrationWaitStartedAt=void 0,this.pendingRegistrationRecoveryReason=void 0,this.state="idle",this.retryCount=0,this.signalingBusyCount=0,this.acceptedRecoveryGeneration=void 0,this.recoveryReason="",this.reinviteReason="unknown",this.lastRtpProgressAt=r(),this.lastRtpSnapshot=void 0,this.logInfo("ICE healthy"),n&&(this.logInfo("ICE recovery succeeded"),null===(t=(e=this.options).onRecovered)||void 0===t||t.call(e))):this.logInfo("ICE healthy, waiting for re-INVITE acceptance")}}},{key:"getIceCandidates",value:function(){return ne(this,void 0,void 0,n.mark(function e(){var t,i,r,s;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this.getPeerConnection()){e.next=1;break}return e.abrupt("return");case 1:return e.next=2,t.getStats();case 2:return i=e.sent,r=[],s=[],h(i).call(i,function(e){if("local-candidate"===e.type||"remote-candidate"===e.type){var t={address:e.address,port:e.port,protocol:e.protocol,candidateType:e.candidateType};"local-candidate"===e.type?r.push(t):s.push(t)}}),e.abrupt("return",{localCandidates:r,remoteCandidates:s,iceGatheringState:t.iceGatheringState,iceConnectionState:t.iceConnectionState});case 3:case"end":return e.stop()}},e,this)}))}},{key:"recover",value:function(e){var t,i,s,a,o;return ne(this,void 0,void 0,n.mark(function c(){var l,u,d,h,g,f,v,p=this;return n.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if(!this.destroyed&&!this.hardFailed){c.next=1;break}return c.abrupt("return");case 1:if(this.session.state===ot.Established){c.next=2;break}return this.logWarn("skip recovery: session not established",this.session.state),c.abrupt("return");case 2:if("undefined"==typeof navigator||!1!==navigator.onLine){c.next=3;break}return this.logWarn("skip recovery: browser offline"),this.state="idle",c.abrupt("return");case 3:if(this.isTransportAvailable()){c.next=4;break}return this.waitForTransport(e),c.abrupt("return");case 4:if(this.isRegistrationAvailable()){c.next=5;break}return this.waitForRegistration(e),c.abrupt("return");case 5:if("sending-reinvite"!==this.state&&"waiting-ice"!==this.state){c.next=6;break}return this.logDebug("skip recovery: recovery already running"),c.abrupt("return");case 6:if(l=this.getPeerConnection()){c.next=7;break}return c.abrupt("return");case 7:if("stable"===l.signalingState){c.next=8;break}return this.logWarn("skip recovery: signalingState not stable",l.signalingState),this.state="waiting-signaling",this.scheduleSignalingBusyRetry("signaling-busy:".concat(l.signalingState)),c.abrupt("return");case 8:if(this.signalingBusyCount=0,this.clearSignalingBusyTimer(),!(this.retryCount>=this.options.maxRetries)){c.next=9;break}return this.failRecovery("".concat(e,":max-retries")),c.abrupt("return");case 9:return this.clearDisconnectedTimer(),this.clearRetryTimer(),this.retryCount++,u=++this.recoveryGeneration,this.state="sending-reinvite",d=this.readIceCredentials(null===(t=l.localDescription)||void 0===t?void 0:t.sdp),this.recoveryReason||(this.reinviteReason=this.resolveReinviteReason(e),this.recoveryReason=this.normalizeRecoveryReason(e,this.reinviteReason)),this.acceptedRecoveryGeneration=void 0,this.logInfo("ICE recovery #".concat(this.retryCount),{recoveryReason:this.recoveryReason,reinviteReason:this.reinviteReason}),null===(s=(i=this.options).onRecoveryStart)||void 0===s||s.call(i,this.recoveryReason,this.retryCount),this.startNegotiationTimeout(u,e),c.prev=10,h={offerOptions:{iceRestart:!0},iceGatheringTimeout:this.options.iceGatheringTimeoutMs,finalModifiers:this.options.includeRecoveryReasonInSdp?[this.permanentRecoverySdpModifier]:[]},this.session.sessionDescriptionHandlerOptionsReInvite=h,this.session.sessionDescriptionHandlerModifiersReInvite=[],this.logDebug("re-INVITE Final SDP configured",{recoveryReason:this.recoveryReason,reinviteReason:this.reinviteReason,includeRecoveryReasonInSdp:this.options.includeRecoveryReasonInSdp,finalModifierCount:null!==(o=null===(a=h.finalModifiers)||void 0===a?void 0:a.length)&&void 0!==o?o:0}),g=r(),c.next=11,this.session.invite({requestDelegate:{onTrying:function(){p.isCurrentGeneration(u)&&p.logDebug("ICE re-INVITE trying")},onProgress:function(e){p.isCurrentGeneration(u)&&p.logDebug("ICE re-INVITE progress:",e.message.statusCode)},onAccept:function(){return ne(p,void 0,void 0,n.mark(function t(){var i,s,a,o,c,l,h,f,v,p,m,b,y,w,k,T,R,S;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.isCurrentGeneration(u)){t.next=1;break}return t.abrupt("return");case 1:if(this.logInfo("ICE re-INVITE accepted"),!this.userAgentManager.armsReportFlag){t.next=8;break}if(t.prev=2,c=r(),null!==(s=null===(i=Fi.getAliArms())||void 0===i?void 0:i.getInstance())&&void 0!==s){t.next=3;break}t.next=6;break;case 3:return f=s,v=E(o="softphone-sdk-re-invite-".concat(this.userAgentManager.appKey||this.userAgentManager.companyId,"-")).call(o,this.userAgentManager.agentExtension),p=C,m=$,b=$,y={businessAttribute:A(this.userAgentManager.businessAttribute).length?this.userAgentManager.businessAttribute:void 0,appKey:this.userAgentManager.appKey||void 0,companyId:this.userAgentManager.companyId||void 0,agentId:this.userAgentManager.agentId||void 0,agentTag:this.userAgentManager.agentTag||void 0,agentExtension:this.userAgentManager.agentExtension||void 0,recoveryReason:this.recoveryReason||void 0,reinviteReason:this.reinviteReason||void 0},t.next=4,this.getIceCandidates();case 4:if(w=t.sent){t.next=5;break}w={};case 5:k=p(m(b(y,w),{bjDate:Ci(),timestamp:r()})),T=this.userAgentManager.businessAttribute.callId||this.userAgentManager.businessAttribute.cid,R=c-g,S=g,f.api.call(f,{api:v,msg:k,traceId:T,code:200,success:!0,time:R,begin:S});case 6:t.next=8;break;case 7:t.prev=7,t.catch(2);case 8:this.clearNegotiationTimer(),this.acceptedRecoveryGeneration=u,(l=this.getPeerConnection())&&"stable"!==l.signalingState&&this.logWarn("re-INVITE accepted but signalingState is not stable",l.signalingState),this.state="waiting-ice",this.options.debugIceCredentials&&(h=this.readIceCredentials(null===(a=null==l?void 0:l.localDescription)||void 0===a?void 0:a.sdp),this.logInfo("ICE credentials:",{old:d,new:h,changed:this.hasIceCredentialsChanged(d,h)})),this.startIceRecoveryTimeout(u,e);case 9:case"end":return t.stop()}},t,this,[[2,7]])}))},onReject:function(t){return ne(p,void 0,void 0,n.mark(function i(){var s,a,o,c,l,d,h,f,v,p,m,b,y,w,k,T;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(!this.userAgentManager.armsReportFlag){n.next=7;break}if(n.prev=1,c=r(),null!==(a=null===(s=Fi.getAliArms())||void 0===s?void 0:s.getInstance())&&void 0!==a){n.next=2;break}n.next=5;break;case 2:return l=a,d=E(o="softphone-sdk-re-invite-".concat(this.userAgentManager.appKey||this.userAgentManager.companyId,"-")).call(o,this.userAgentManager.agentExtension),h=C,f=$,v=$,p={businessAttribute:A(this.userAgentManager.businessAttribute).length?this.userAgentManager.businessAttribute:void 0,appKey:this.userAgentManager.appKey||void 0,companyId:this.userAgentManager.companyId||void 0,agentId:this.userAgentManager.agentId||void 0,agentTag:this.userAgentManager.agentTag||void 0,agentExtension:this.userAgentManager.agentExtension||void 0,recoveryReason:this.recoveryReason||void 0,reinviteReason:this.reinviteReason||void 0},n.next=3,this.getIceCandidates();case 3:if(m=n.sent){n.next=4;break}m={};case 4:b=h(f(v(p,m),{bjDate:Ci(),reasonPhrase:t.message.reasonPhrase||void 0,timestamp:r()})),y=this.userAgentManager.businessAttribute.callId||this.userAgentManager.businessAttribute.cid,w=t.message.statusCode,k=c-g,T=g,l.api.call(l,{api:d,msg:b,traceId:y,code:w,success:!1,time:k,begin:T});case 5:n.next=7;break;case 6:n.prev=6,n.catch(1);case 7:this.handleReinviteRejected(u,e,t.message.statusCode,t.message.reasonPhrase);case 8:case"end":return n.stop()}},i,this,[[1,6]])}))}}});case 11:c.next=19;break;case 12:if(c.prev=12,v=c.catch(10),this.isCurrentGeneration(u)){c.next=13;break}return c.abrupt("return");case 13:return this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.logWarn("ICE re-INVITE error:",v),c.next=14,this.rollbackLocalOffer("invite-exception");case 14:if(f=c.sent,this.isCurrentGeneration(u)){c.next=15;break}return c.abrupt("return");case 15:if(f){c.next=16;break}return this.failRecovery("".concat(e,":rollback-failed:exception")),c.abrupt("return");case 16:if(this.state="idle",this.signalingBusyCount=0,this.isTransportAvailable()){c.next=17;break}return this.waitForTransport("".concat(e,":invite-exception")),c.abrupt("return");case 17:if(!this.isRequestPendingError(v)){c.next=18;break}return this.scheduleRetry("".concat(e,":request-pending"),1500),c.abrupt("return");case 18:this.scheduleRetry("".concat(e,":exception"));case 19:case"end":return c.stop()}},c,this,[[10,12]])}))}},{key:"rollbackLocalOffer",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){var i,r,s,a;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(i=this.getPeerConnection()){t.next=1;break}return t.abrupt("return",!1);case 1:if("stable"!==i.signalingState){t.next=2;break}return t.abrupt("return",!0);case 2:if("have-local-offer"===i.signalingState){t.next=3;break}return this.logWarn("cannot rollback current signaling state",{reason:e,signalingState:i.signalingState}),t.abrupt("return",!1);case 3:return t.prev=3,this.logWarn("rollback local offer",{reason:e,signalingState:i.signalingState}),t.next=4,i.setLocalDescription({type:"rollback"});case 4:return r=i.signalingState,s="stable"===r,this.logInfo("local offer rollback result",{success:s,signalingState:r}),t.abrupt("return",s);case 5:return t.prev=5,a=t.catch(3),this.logError("local offer rollback failed",{reason:e,error:a,signalingState:i.signalingState}),t.abrupt("return",!1);case 6:case"end":return t.stop()}},t,this,[[3,5]])}))}},{key:"normalizeRecoveryReason",value:function(e,t){var n=e.toLowerCase();return p(n).call(n,"transport-restored")?"transport-restored:".concat(t):"unknown"!==t?t:"unknown"}},{key:"resolveReinviteReason",value:function(e){var t=e.toLowerCase();return p(t).call(t,"rtp-stalled")?"rtp-stalled":p(t).call(t,"ice-failed")?"ice-failed":p(t).call(t,"ice-disconnected")||p(t).call(t,"disconnected-timeout")?"ice-disconnected":p(t).call(t,"network-changed")?"network-changed":p(t).call(t,"transport-restored")?"transport-restored":p(t).call(t,"manual")?"manual":"unknown"}},{key:"sanitizeSdpReason",value:function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:256;return g(t=e.replace(/[\r\n]/g,"").replace(/[^a-zA-Z0-9._:-]/g,"_")).call(t,0,n)}},{key:"sanitizeSdpAttributeName",value:function(e){var t;return g(t=e.replace(/[^a-zA-Z0-9_-]/g,"")).call(t,0,64)||"x-reinvite-reason"}},{key:"applyRecoveryReasonToSdp",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){var i,r,s,a,o,c,l,u,d,h,g,v,m,b,y,w,k;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e.sdp&&this.options.includeRecoveryReasonInSdp){t.next=1;break}return t.abrupt("return",e);case 1:for(u=this.sanitizeSdpAttributeName(this.options.recoveryReasonSdpAttribute),d=this.sanitizeSdpAttributeName(this.options.reinviteReasonSdpAttribute),h=this.sanitizeSdpReason(this.recoveryReason||"unknown"),g=this.sanitizeSdpReason(this.reinviteReason||"unknown",64),v=f(i=e.sdp.split(/\r?\n/)).call(i,function(e){return!Q(e).call(e,"a=".concat(u,":"))&&!Q(e).call(e,"a=".concat(d,":"))});v.length>0&&""===v[v.length-1];)v.pop();return m=ee(v).call(v,function(e){return Q(e).call(e,"m=")}),b=m>=0?m:v.length,I(v).call(v,b,0,E(r="a=".concat(u,":")).call(r,h),E(s="a=".concat(d,":")).call(s,g)),y="".concat(v.join("\r\n"),"\r\n"),w=p(y).call(y,E(a="a=".concat(u,":")).call(a,h)),k=p(y).call(y,E(o="a=".concat(d,":")).call(o,g)),this.logInfo("SDP modifier RESULT",{recoveryReason:h,reinviteReason:g,containsRecoveryReason:w,containsReinviteReason:k,insertedBeforeFirstMedia:m>=0}),this.logDebug("SDP custom reason lines",{recoveryLine:E(c="a=".concat(u,":")).call(c,h),reinviteLine:E(l="a=".concat(d,":")).call(l,g)}),t.abrupt("return",$($({},e),{sdp:y}));case 2:case"end":return t.stop()}},t,this)}))}},{key:"createRecoveryReasonSdpModifier",value:function(e,t){var i=this;return function(r){return ne(i,void 0,void 0,n.mark(function i(){return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return this.recoveryReason=e,this.reinviteReason=t,n.abrupt("return",this.applyRecoveryReasonToSdp(r));case 1:case"end":return n.stop()}},i,this)}))}}},{key:"handleReinviteRejected",value:function(e,t,i,r){return ne(this,void 0,void 0,n.mark(function s(){var a,o,c,l;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.isCurrentGeneration(e)){n.next=1;break}return n.abrupt("return");case 1:return this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.logWarn("ICE re-INVITE rejected:",i,r),n.next=2,this.rollbackLocalOffer("sip-".concat(i));case 2:if(o=n.sent,this.isCurrentGeneration(e)){n.next=3;break}return n.abrupt("return");case 3:if(o){n.next=4;break}return this.failRecovery(E(c="".concat(t,":rollback-failed:sip-")).call(c,i)),n.abrupt("return");case 4:if(this.state="idle",this.signalingBusyCount=0,481!==i){n.next=5;break}return this.failRecovery("".concat(t,":sip-481")),n.abrupt("return");case 5:if(this.isTransportAvailable()){n.next=6;break}return this.waitForTransport(E(l="".concat(t,":sip-")).call(l,i)),n.abrupt("return");case 6:if(491!==i){n.next=7;break}return this.scheduleRetry("".concat(t,":sip-491"),1500),n.abrupt("return");case 7:if(503!==i){n.next=8;break}return this.scheduleRetry("".concat(t,":sip-503"),3e3),n.abrupt("return");case 8:this.scheduleRetry(E(a="".concat(t,":sip-")).call(a,i));case 9:case"end":return n.stop()}},s,this)}))}},{key:"startNegotiationTimeout",value:function(e,t){var n=this;this.clearNegotiationTimer(),this.negotiationTimer=m(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=m(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=m(function(){if(t.retryTimer=void 0,!t.destroyed&&!t.hardFailed)if(t.isTransportAvailable()){var n=t.getPeerConnection();if(n)if("connected"!==n.iceConnectionState&&"completed"!==n.iceConnectionState){if("stable"!==n.signalingState)return t.state="waiting-signaling",void t.scheduleSignalingBusyRetry("retry-signaling-busy:".concat(n.signalingState));t.state="idle",t.recover(t.recoveryReason||e)}else t.handleIceRecovered()}else t.waitForTransport(t.recoveryReason||e)},a)}}},{key:"scheduleSignalingBusyRetry",value:function(e){var t,n=this;if(!this.destroyed&&!this.hardFailed)if(this.isTransportAvailable()){if(!this.signalingBusyTimer){this.signalingBusyCount++;var i=this.getPeerConnection();if(this.logWarn("signalingState still busy",{reason:e,signalingState:null==i?void 0:i.signalingState,count:this.signalingBusyCount,max:this.options.maxSignalingBusyRetries}),this.signalingBusyCount>this.options.maxSignalingBusyRetries)this.failRecovery("signaling-stuck:".concat(null!==(t=null==i?void 0:i.signalingState)&&void 0!==t?t:"unknown"));else{this.state="waiting-signaling";var r=Math.floor(500*Math.random()),s=this.options.signalingBusyRetryDelayMs+r;this.logInfo("schedule signaling retry in ".concat(s,"ms")),this.signalingBusyTimer=m(function(){if(n.signalingBusyTimer=void 0,!n.destroyed&&!n.hardFailed&&n.session.state===ot.Established)if(n.isTransportAvailable()){var e=n.getPeerConnection();if(e)return"stable"===e.signalingState?(n.signalingBusyCount=0,n.state="idle","connected"===e.iceConnectionState||"completed"===e.iceConnectionState?void n.handleIceRecovered():void n.recover("signaling-recovered")):void n.scheduleSignalingBusyRetry("signaling-busy:".concat(e.signalingState))}else n.waitForTransport("signaling-unavailable")},s)}}}else this.waitForTransport(e)}},{key:"isTransportAvailable",value:function(){var e=this.options.isSignalingAvailable;if(!e)return!0;try{return e()}catch(e){return this.logWarn("isSignalingAvailable() threw",e),!1}}},{key:"isRegistrationAvailable",value:function(){var e=this.options.isRegistrationAvailable;if(!e)return!0;try{return e()}catch(e){return this.logWarn("isRegistrationAvailable() threw",e),!1}}},{key:"waitForRegistration",value:function(e){var t=this;if(!this.destroyed&&!this.hardFailed){if(!this.isTransportAvailable())return this.clearRegistrationRecoveryTimer(),this.registrationWaitStartedAt=void 0,this.pendingRegistrationRecoveryReason=void 0,void this.waitForTransport(e);if(this.isRegistrationAvailable()){var n=void 0===this.registrationWaitStartedAt?0:r()-this.registrationWaitStartedAt;return this.clearRegistrationRecoveryTimer(),this.registrationWaitStartedAt=void 0,this.pendingRegistrationRecoveryReason=void 0,this.state="idle",this.logInfo("SIP registration recovered",{waitedMs:n,reason:e}),void this.resumeAfterRegistrationRecovery(e)}if(this.state="waiting-registration",this.pendingRegistrationRecoveryReason=e,void 0===this.registrationWaitStartedAt&&(this.registrationWaitStartedAt=r(),this.logWarn("SIP registration unavailable; pause ICE restart",{reason:e,timeoutMs:this.options.registrationRecoveryTimeoutMs})),!this.registrationRecoveryTimer)r()-this.registrationWaitStartedAt>=this.options.registrationRecoveryTimeoutMs?this.failRecovery("registration-recovery-timeout:".concat(e)):this.registrationRecoveryTimer=m(function(){var n;t.registrationRecoveryTimer=void 0,t.destroyed||t.hardFailed||t.session.state===ot.Established&&t.waitForRegistration(null!==(n=t.pendingRegistrationRecoveryReason)&&void 0!==n?n:e)},this.options.registrationRecoveryPollMs)}}},{key:"resumeAfterRegistrationRecovery",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){var i;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.destroyed&&!this.hardFailed&&this.session.state===ot.Established){t.next=1;break}return t.abrupt("return");case 1:if(this.isTransportAvailable()){t.next=2;break}return this.waitForTransport(e),t.abrupt("return");case 2:if(this.isRegistrationAvailable()){t.next=3;break}return this.waitForRegistration(e),t.abrupt("return");case 3:if(i=this.getPeerConnection()){t.next=4;break}return t.abrupt("return");case 4:if("connected"!==i.iceConnectionState&&"completed"!==i.iceConnectionState){t.next=5;break}return this.handleIceRecovered(),t.abrupt("return");case 5:if("stable"===i.signalingState){t.next=6;break}return this.state="waiting-signaling",this.scheduleSignalingBusyRetry("registration-restored:".concat(i.signalingState)),t.abrupt("return");case 6:return this.state="idle",t.next=7,this.recover("registration-restored:".concat(e));case 7:case"end":return t.stop()}},t,this)}))}},{key:"waitForTransport",value:function(e){var t=this;if(!this.destroyed&&!this.hardFailed){if(this.isTransportAvailable())return this.transportWaitStartedAt=void 0,this.pendingTransportRecoveryReason=void 0,this.clearTransportRecoveryTimer(),this.state="idle",void this.resumeAfterTransportRecovery(e);if(this.state="waiting-transport",void 0===this.transportWaitStartedAt&&(this.transportWaitStartedAt=r(),this.logWarn("SIP Transport unavailable; pause ICE restart",{reason:e,timeoutMs:this.options.transportRecoveryTimeoutMs})),this.pendingTransportRecoveryReason=e,!this.transportRecoveryTimer)r()-this.transportWaitStartedAt>=this.options.transportRecoveryTimeoutMs?this.failRecovery("transport-recovery-timeout:".concat(e)):this.transportRecoveryTimer=m(function(){var n,i;if(t.transportRecoveryTimer=void 0,!t.destroyed&&!t.hardFailed&&t.session.state===ot.Established)if(t.isTransportAvailable()){var s=null!==(i=t.pendingTransportRecoveryReason)&&void 0!==i?i:e,a=void 0===t.transportWaitStartedAt?0:r()-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 ne(this,void 0,void 0,n.mark(function t(){var i;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.destroyed&&!this.hardFailed&&this.session.state===ot.Established){t.next=1;break}return t.abrupt("return");case 1:if(this.isTransportAvailable()){t.next=2;break}return this.waitForTransport(e),t.abrupt("return");case 2:if(this.isRegistrationAvailable()){t.next=3;break}return this.waitForRegistration(e),t.abrupt("return");case 3:if(i=this.getPeerConnection()){t.next=4;break}return t.abrupt("return");case 4:if("connected"!==i.iceConnectionState&&"completed"!==i.iceConnectionState){t.next=5;break}return this.handleIceRecovered(),t.abrupt("return");case 5:if("stable"===i.signalingState){t.next=6;break}return this.state="waiting-signaling",this.scheduleSignalingBusyRetry("transport-restored:".concat(i.signalingState)),t.abrupt("return");case 6:return this.state="idle",t.next=7,this.recover("transport-restored:".concat(e));case 7:case"end":return t.stop()}},t,this)}))}},{key:"failRecovery",value:function(e){var t,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.clearRegistrationRecoveryTimer(),this.transportWaitStartedAt=void 0,this.pendingTransportRecoveryReason=void 0,this.registrationWaitStartedAt=void 0,this.pendingRegistrationRecoveryReason=void 0,this.stopRtpWatchdog(),this.logError("ICE recovery unrecoverable",{reason:e,retryCount:this.retryCount,signalingBusyCount:this.signalingBusyCount,iceConnectionState:null===(t=this.getPeerConnection())||void 0===t?void 0:t.iceConnectionState,connectionState:null===(n=this.getPeerConnection())||void 0===n?void 0:n.connectionState,signalingState:null===(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=r(),this.rtpStatsTimer=L(function(){e.checkRtpHealth()},this.options.rtpStatsIntervalMs))}},{key:"stopRtpWatchdog",value:function(){this.rtpStatsTimer&&(clearInterval(this.rtpStatsTimer),this.rtpStatsTimer=void 0)}},{key:"checkRtpHealth",value:function(){return ne(this,void 0,void 0,n.mark(function e(){var t,i,s,a,o,c,l,u;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.destroyed&&!this.hardFailed&&this.session.state===ot.Established){e.next=1;break}return e.abrupt("return");case 1:if(t=this.getPeerConnection()){e.next=2;break}return e.abrupt("return");case 2:if("connected"===t.iceConnectionState||"completed"===t.iceConnectionState){e.next=3;break}return e.abrupt("return");case 3:if("sending-reinvite"!==this.state&&"waiting-ice"!==this.state&&"waiting-signaling"!==this.state&&"waiting-transport"!==this.state){e.next=4;break}return e.abrupt("return");case 4:return e.prev=4,e.next=5,this.readRtpSnapshot(t);case 5:i=e.sent,e.next=7;break;case 6:return e.prev=6,u=e.catch(4),this.logDebug("getStats failed:",u),e.abrupt("return");case 7:if(i.hasAudio||i.hasVideo){e.next=8;break}return e.abrupt("return");case 8:if(s=this.lastRtpSnapshot,this.lastRtpSnapshot=i,s){e.next=9;break}return this.lastRtpProgressAt=r(),e.abrupt("return");case 9:if(a=i.audioBytes>s.audioBytes||i.audioPackets>s.audioPackets,o=i.videoBytes>s.videoBytes||i.videoPackets>s.videoPackets||i.videoFramesDecoded>s.videoFramesDecoded,!a&&!o){e.next=10;break}return this.lastRtpProgressAt=r(),e.abrupt("return");case 10:if(!((c=r()-this.lastRtpProgressAt)<this.options.rtpStallTimeoutMs)){e.next=11;break}return e.abrupt("return");case 11:if(!((l=r())-this.lastRtpRecoveryAt<this.options.rtpRecoveryCooldownMs)){e.next=12;break}return e.abrupt("return");case 12:if(this.logWarn("RTP stalled for ".concat(c,"ms"),{ice:t.iceConnectionState,connection:t.connectionState,signaling:t.signalingState,audioBytes:i.audioBytes,audioPackets:i.audioPackets,videoBytes:i.videoBytes,videoPackets:i.videoPackets,videoFramesDecoded:i.videoFramesDecoded}),this.options.recoverOnRtpStallWhenIceConnected){e.next=13;break}return e.abrupt("return");case 13:this.lastRtpRecoveryAt=l,this.recover("rtp-stalled");case 14:case"end":return e.stop()}},e,this,[[4,6]])}))}},{key:"readRtpSnapshot",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){var i,s;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=1,e.getStats();case 1:return i=t.sent,s={timestamp:r(),audioBytes:0,audioPackets:0,videoBytes:0,videoPackets:0,videoFramesDecoded:0,hasAudio:!1,hasVideo:!1},h(i).call(i,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&&(s.hasAudio=!0,"number"==typeof e.bytesReceived&&(s.audioBytes+=e.bytesReceived),"number"==typeof e.packetsReceived&&(s.audioPackets+=e.packetsReceived)),"video"===n&&(s.hasVideo=!0,"number"==typeof e.bytesReceived&&(s.videoBytes+=e.bytesReceived),"number"==typeof e.packetsReceived&&(s.videoPackets+=e.packetsReceived),"number"==typeof e.framesDecoded&&(s.videoFramesDecoded+=e.framesDecoded))}}),t.abrupt("return",s);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:R(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:R(r).call(r)}:{}}},{key:"hasIceCredentialsChanged",value:function(e,t){return e.ufrag!==t.ufrag||e.pwd!==t.pwd}},{key:"isRequestPendingError",value:function(e){return e instanceof Error&&("RequestPendingError"===e.name||/request.*pending/i.test(e.message))}},{key:"isCurrentGeneration",value:function(e){return!this.destroyed&&!this.hardFailed&&e===this.recoveryGeneration}},{key:"clearDisconnectedTimer",value:function(){this.disconnectedTimer&&(clearTimeout(this.disconnectedTimer),this.disconnectedTimer=void 0)}},{key:"clearRetryTimer",value:function(){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0)}},{key:"clearSignalingBusyTimer",value:function(){this.signalingBusyTimer&&(clearTimeout(this.signalingBusyTimer),this.signalingBusyTimer=void 0)}},{key:"clearNegotiationTimer",value:function(){this.negotiationTimer&&(clearTimeout(this.negotiationTimer),this.negotiationTimer=void 0)}},{key:"clearIceRecoveryTimer",value:function(){this.iceRecoveryTimer&&(clearTimeout(this.iceRecoveryTimer),this.iceRecoveryTimer=void 0)}},{key:"clearTransportRecoveryTimer",value:function(){this.transportRecoveryTimer&&(clearTimeout(this.transportRecoveryTimer),this.transportRecoveryTimer=void 0)}},{key:"clearRegistrationRecoveryTimer",value:function(){this.registrationRecoveryTimer&&(clearTimeout(this.registrationRecoveryTimer),this.registrationRecoveryTimer=void 0)}},{key:"clearAllTimers",value:function(){this.clearDisconnectedTimer(),this.clearRetryTimer(),this.clearSignalingBusyTimer(),this.clearNegotiationTimer(),this.clearIceRecoveryTimer(),this.stopRtpWatchdog(),this.onlineTimer&&(clearTimeout(this.onlineTimer),this.onlineTimer=void 0)}},{key:"logDebug",value:function(){for(var e,t,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,E(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,E(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,E(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,E(t=[n,"[SipIceRecovery]"]).call(t,s))}}])}(),va=function(){return t(function t(n){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:200;e(this,t),d(this,"onAggregateCallback",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"debounceTime",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),d(this,"pendingCalls",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.onAggregateCallback=n,this.debounceTime=i,this.pendingCalls=new M},[{key:"receive",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){var i,r,s,a,o,c=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:i=e.CALLID,r=e.ENTRY,this.pendingCalls.has(i)?(s=this.pendingCalls.get(i),clearTimeout(s.timer),s.data.ENTRY.push(r),s.count+=1,s.timer=m(function(){return c._flush(i)},this.debounceTime)):((a=JSON.parse(C(e))).ENTRY=[r],o=m(function(){return c._flush(i)},this.debounceTime),this.pendingCalls.set(i,{timer:o,data:a,count:1}));case 1:case"end":return t.stop()}},t,this)}))}},{key:"_flush",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){var i,r;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.pendingCalls.has(e)){t.next=1;break}return i=this.pendingCalls.get(e),r=i.data,this.pendingCalls.delete(e),t.next=1,this.onAggregateCallback(r);case 1:case"end":return t.stop()}},t,this)}))}}])}(),pa=function(){return t(function t(){var s=this,a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e(this,t),Ui.add(this),Bi.set(this,void 0),Li.set(this,void 0),Gi.set(this,void 0),Vi.set(this,void 0),Wi.set(this,void 0),Ki.set(this,void 0),Yi.set(this,[]),zi.set(this,[]),Zi.set(this,{}),Ji.set(this,void 0),Xi.set(this,void 0),Qi.set(this,new MediaStream),er.set(this,JSON.parse(C(ji))),tr.set(this,0),nr.set(this,void 0),ir.set(this,void 0),rr.set(this,void 0),d(this,"token",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),sr.set(this,void 0),ar.set(this,48e4),or.set(this,12e6),cr.set(this,{}),lr.set(this,!1),ur.set(this,void 0),dr.set(this,void 0),hr.set(this,void 0),gr.set(this,function(e){}),fr.set(this,function(e){}),vr.set(this,function(e){}),pr.set(this,function(e){}),mr.set(this,function(e){return ne(s,void 0,void 0,n.mark(function t(){var i,s,a,o;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!ie(this,nr,"f")||!ie(this,ir,"f")){t.next=3;break}if(!(r()-ie(this,ir,"f")>e)){t.next=3;break}return t.next=1,ie(this,yr,"f").call(this);case 1:if(o=t.sent){t.next=2;break}o={};case 2:s=(i=o).sign,a=i.timestamp,re(this,nr,null!=s?s:ie(this,nr,"f"),"f"),re(this,ir,null!=a?a:ie(this,ir,"f"),"f");case 3:case"end":return t.stop()}},t,this)}))}),br.set(this,function(e){return ne(s,void 0,void 0,n.mark(function t(){var i,s,a,o,c;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!ie(this,sr,"f")){t.next=4;break}if(!(r()-ie(this,sr,"f")>e)){t.next=4;break}if(!ie(this,rr,"f")){t.next=2;break}return t.next=1,ie(this,Tr,"f").call(this);case 1:i=t.sent,s=i.token,a=i.tokenTimestamp,re(this,rr,null!=s?s:ie(this,rr,"f"),"f"),re(this,sr,null!=a?a:r(),"f"),t.next=4;break;case 2:if(!this.token){t.next=4;break}return t.next=3,this.getGatewayAccessToken({corpId:ie(this,Vr,"f"),sid:ie(this,es,"f"),secret:ie(this,Kr,"f"),seatOnline:!1});case 3:o=t.sent,c=o.token,this.token=c,re(this,sr,r(),"f");case 4:case"end":return t.stop()}},t,this)}))}),yr.set(this,function(){}),wr.set(this,function(e){ie(s,lr,"f")&&ie(s,kr,"f").receive(e)}),kr.set(this,new va(function(e){var t,n,i;delete e.INVITE,null===(i=null===(n=Fi.getAliArms())||void 0===n?void 0:n.getInstance())||void 0===i||i.api({api:E(t="softphone-sdk-auto-ignore-".concat(ie(s,Vr,"f")||ie(s,Wr,"f"),"-")).call(t,ie(s,Zi,"f").authorizationUsername),msg:C({errorInfo:e,businessAttribute:A(ie(s,hs,"f")).length?ie(s,hs,"f"):void 0,appKey:ie(s,Vr,"f")||void 0,companyId:ie(s,Wr,"f")||void 0,agentId:ie(s,es,"f")||void 0,agentTag:ie(s,Yr,"f")||void 0,agentExtension:ie(s,Zi,"f").authorizationUsername||void 0,bjDate:Ci(),timestamp:r()}),traceId:e.CALLID,code:e.CODE,success:!0,time:0})})),Tr.set(this,function(){}),Rr.set(this,function(e){}),Sr.set(this,function(e){}),Ir.set(this,void 0),Er.set(this,void 0),d(this,"networkSpeed",{enumerable:!0,configurable:!0,writable:!0,value:"0.00Mb/s"}),d(this,"networkDelay",{enumerable:!0,configurable:!0,writable:!0,value:"0ms"}),d(this,"onLine",{enumerable:!0,configurable:!0,writable:!0,value:navigator.onLine}),d(this,"testspeeding",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"goodNetworkSpeed",{enumerable:!0,configurable:!0,writable:!0,value:function(){return 1e3*Number(s.networkSpeed.replace("Mb/s",""))>=30}}),d(this,"goodNetworkDelay",{enumerable:!0,configurable:!0,writable:!0,value:function(){return Number(s.networkDelay.replace("ms",""))<=500&&"0ms"!==s.networkDelay}}),d(this,"authorizedMicrophonePermissions",{enumerable:!0,configurable:!0,writable:!0,value:!1}),d(this,"authorizedNotificationPermissions",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Cr.set(this,100),Ar.set(this,3),xr.set(this,8),Dr.set(this,2),Hr.set(this,0),_r.set(this,!1),$r.set(this,void 0),qr.set(this,3),Mr.set(this,3),Pr.set(this,0),Or.set(this,0),Nr.set(this,0),jr.set(this,!1),Fr.set(this,!1),Ur.set(this,!1),Br.set(this,void 0),Lr.set(this,void 0),Gr.set(this,void 0),Vr.set(this,void 0),Wr.set(this,void 0),Kr.set(this,void 0),Yr.set(this,void 0),zr.set(this,void 0),Zr.set(this,void 0),Jr.set(this,void 0),Xr.set(this,void 0),Qr.set(this,void 0),es.set(this,void 0),ts.set(this,void 0),ns.set(this,void 0),is.set(this,void 0),rs.set(this,void 0),ss.set(this,function(e){ie(s,Ui,"m",oa).call(s)}),as.set(this,function(){}),os.set(this,void 0),cs.set(this,void 0),ls.set(this,!1),us.set(this,4e3),ds.set(this,4e3),hs.set(this,{}),gs.set(this,!1),fs.set(this,!0),d(this,"ifAutoAnswer",{enumerable:!0,configurable:!0,writable:!0,value:function(){return String(ie(s,hs,"f").autoAnswer)===Ai.YES}}),d(this,"notNeedSendStarDtmf",{enumerable:!0,configurable:!0,writable:!0,value:function(){return String(ie(s,hs,"f").afterTransferLabour)===Hi.DIRECT_ANSWER}}),vs.set(this,function(){if(ie(s,fs,"f")){var e;ie(s,ps,"f").call(s);var t=new(window.AudioContext||window.webkitAudioContext);re(s,dr,t.createScriptProcessor(2048,1,1),"f"),ie(s,dr,"f").onaudioprocess=function(e){for(var t=e.inputBuffer.getChannelData(0),n=0,i=0;i<t.length;++i)n+=t[i]*t[i];re(s,tr,Number(Math.sqrt(n/t.length).toFixed(2)),"f"),ie(s,gr,"f").call(s,ie(s,tr,"f"))},re(s,hr,new MediaStream,"f"),h(e=s.getSenders()).call(e,function(e){e.track&&ie(s,hr,"f").addTrack(e.track)}),re(s,ur,t.createMediaStreamSource(ie(s,hr,"f")),"f"),ie(s,ur,"f").connect(ie(s,dr,"f")),ie(s,dr,"f").connect(t.destination)}}),ps.set(this,function(){if(ie(s,fs,"f")){if(ie(s,ur,"f"))try{ie(s,ur,"f").disconnect()}catch(e){console.log(e)}if(ie(s,dr,"f"))try{ie(s,dr,"f").disconnect()}catch(e){console.log(e)}if(ie(s,hr,"f"))try{var e;h(e=ie(s,hr,"f").getTracks()).call(e,function(e){e.stop()})}catch(e){console.log(e)}}re(s,ur,void 0,"f"),re(s,dr,void 0,"f"),re(s,hr,void 0,"f"),re(s,tr,0,"f"),ie(s,gr,"f").call(s,ie(s,tr,"f"))}),d(this,"disposeSoftphoneEnvRequirementCheck",{enumerable:!0,configurable:!0,writable:!0,value:function(){ie(s,ms,"f").call(s),window.removeEventListener("offline",ie(s,ws,"f")),window.removeEventListener("online",ie(s,ys,"f")),window.removeEventListener("unload",s.disposeSoftphoneEnvRequirementCheck)}}),ms.set(this,function(){clearInterval(ie(s,Ir,"f")),re(s,Ir,void 0,"f"),clearTimeout(ie(s,Er,"f")),re(s,Er,void 0,"f"),s.testspeeding=!1}),d(this,"softphoneEnvCheck",{enumerable:!0,configurable:!0,writable:!0,value:function(){return ne(s,void 0,void 0,n.mark(function e(){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:this.testspeeding||(ie(this,bs,"f").call(this),this.oneRoundOfTesting());case 1:case"end":return e.stop()}},e,this)}))}}),bs.set(this,function(){window.addEventListener("offline",ie(s,ws,"f")),window.addEventListener("online",ie(s,ys,"f")),window.addEventListener("unload",s.disposeSoftphoneEnvRequirementCheck)}),d(this,"oneRoundOfTesting",{enumerable:!0,configurable:!0,writable:!0,value:function(){return ne(s,void 0,void 0,n.mark(function e(){var t=this;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:this.testspeeding=!0,this.detectNavigatorPermissions(),this.onLine?(ie(this,ks,"f").call(this,this),re(this,Er,m(function(){t.testspeeding=!1,t.disposeSoftphoneEnvRequirementCheck()},4e3),"f")):this.testspeeding=!1;case 1:case"end":return e.stop()}},e,this)}))}}),ys.set(this,function(){s.onLine=!0,s.oneRoundOfTesting()}),ws.set(this,function(){s.onLine=!1,s.networkSpeed="0.00Mb/s",s.networkDelay="0ms",ie(s,Sr,"f").call(s,{networkSpeed:s.networkSpeed,networkDelay:s.networkDelay,authorizedMicrophonePermissions:s.authorizedMicrophonePermissions,authorizedNotificationPermissions:s.authorizedNotificationPermissions}),ie(s,ms,"f").call(s)}),ks.set(this,function(e){return ne(s,void 0,void 0,n.mark(function t(){var i,r,s=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return i=e||this,clearInterval(ie(i,Ir,"f")),re(i,Ir,void 0,"f"),r=function(){return ne(s,void 0,void 0,n.mark(function e(){var t;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!i.onLine){e.next=5;break}return e.prev=1,e.next=2,ie(i,Ts,"f").call(i,"1"===ie(i,is,"f")?"https://seat.teleai.com/favicon.png":void 0);case 2:t=e.sent,i.networkSpeed=t.networkSpeed,i.networkDelay=t.networkDelay,e.next=4;break;case 3:e.prev=3,e.catch(1),i.networkSpeed="0.00Mb/s",i.networkDelay="0ms";case 4:e.next=6;break;case 5:i.networkSpeed="0.00Mb/s",i.networkDelay="0ms";case 6:ie(this,Sr,"f").call(this,{networkSpeed:this.networkSpeed,networkDelay:this.networkDelay,authorizedMicrophonePermissions:this.authorizedMicrophonePermissions,authorizedNotificationPermissions:this.authorizedNotificationPermissions}),ie(this,Er,"f")||(this.testspeeding=!1,this.disposeSoftphoneEnvRequirementCheck());case 7:case"end":return e.stop()}},e,this,[[1,3]])}))},t.next=1,r();case 1:ie(this,Er,"f")&&re(i,Ir,L(function(){return ne(this,void 0,void 0,n.mark(function e(){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,r();case 1:case"end":return e.stop()}},e)}))},1e3),"f");case 2:case"end":return t.stop()}},t,this)}))}),Ts.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,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;return ne(s,void 0,void 0,n.mark(function s(){var o,c;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:for(o=[],c=0;c<a;c++)o.push(ie(this,Rs,"f").call(this,e+"?d="+r()+c,t));return n.abrupt("return",i.all(o).then(function(e){var t=0,n=0;return h(e).call(e,function(e){t+=Number(e[0]),n+=Number(e[1])}),{networkDelay:(n/a).toFixed(2)+"ms",networkSpeed:(t/a).toFixed(2)+"Mb/s"}}));case 1:case"end":return n.stop()}},s,this)}))}),Rs.set(this,function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"https://seat.94ai.com/favicon.png?d="+r(),t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:63491;return new i(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})}),d(this,"openApiAjax",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return new i(function(t,i){return ne(s,void 0,void 0,n.mark(function s(){var a,o,c,l,u,d,h,g,f,v,p,m,b,y,w,k,T;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(n.prev=0,f=ie(this,Vr,"f")||(null===(a=e.data)||void 0===a?void 0:a.appKey),v=ie(this,Kr,"f")||(null===(o=e.data)||void 0===o?void 0:o.appSecret),p=ie(this,nr,"f")||(null===(c=e.data)||void 0===c?void 0:c.sign),m=ie(this,ir,"f")||(null===(l=e.data)||void 0===l?void 0:l.timestamp),null===(u=e.data)||void 0===u||delete u.appKey,null===(d=e.data)||void 0===d||delete d.appSecret,null===(h=e.data)||void 0===h||delete h.sign,null===(g=e.data)||void 0===g||delete g.timestamp,f){n.next=1;break}throw new Error("缺少appKey");case 1:if(!v){n.next=2;break}m=r(),p=J.enc.Base64.stringify(J.HmacSHA1(f+m,v)),n.next=5;break;case 2:if(!p||!m){n.next=4;break}return n.next=3,ie(this,mr,"f").call(this,ie(this,ar,"f"));case 3:p=ie(this,nr,"f")||p,m=ie(this,ir,"f")||m,n.next=5;break;case 4:throw new Error("缺少appSecret或sign+timestamp");case 5:return b=Ei(t,i,e),y=b.xhr,w=b.ajaxData,k=b.contentType,y.setRequestHeader("appKey",f),y.setRequestHeader("timestamp",String(m)),y.setRequestHeader("sign",p),y.setRequestHeader("Content-type",k||"application/json"),n.next=6,ie(this,vr,"f").call(this,y);case 6:y.send(w),n.next=8;break;case 7:throw n.prev=7,T=n.catch(0),i(T.message),T;case 8:case"end":return n.stop()}},s,this,[[0,7]])}))})}}),d(this,"requestGateway",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return s.gatewayApiAjax($($({},e),{url:s.getGateway()+e.url}),t)}}),d(this,"gatewayApiAjax",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return new i(function(i,r){return ne(s,void 0,void 0,n.mark(function s(){var a,o,c,l,u,d;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(n.prev=0,a=Ei(i,r,e),o=a.xhr,c=a.ajaxData,l=a.contentType,!t){n.next=2;break}return n.next=1,this.getGatewayToken();case 1:u=n.sent,o.setRequestHeader("x-token",u),o.setRequestHeader("seatsToken",u),o.setRequestHeader("x-authority-token",u);case 2:return o.setRequestHeader("x-app-code",3),o.setRequestHeader("content-type",l||"application/json"),n.next=3,ie(this,pr,"f").call(this,o);case 3:o.send(c),n.next=5;break;case 4:throw n.prev=4,d=n.catch(0),r(d.message),d;case 5:case"end":return n.stop()}},s,this,[[0,4]])}))})}}),d(this,"requestOpenApi",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return s.openApiAjax($($({},e),{url:s.getOpenApi()+e.url}))}}),d(this,"getDeviceId",{enumerable:!0,configurable:!0,writable:!0,value:function(){return ne(s,void 0,void 0,n.mark(function e(){var t,i;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!ie(this,rs,"f")){e.next=1;break}return e.abrupt("return",ie(this,rs,"f"));case 1:return e.next=2,X.load();case 2:return t=e.sent,e.next=3,t.get();case 3:return i=e.sent,re(this,rs,i.visitorId,"f"),e.abrupt("return",ie(this,rs,"f"));case 4:case"end":return e.stop()}},e,this)}))}}),Hs.set(this,function(){return ne(s,void 0,void 0,n.mark(function e(){var t,i,r,s,a,o,c=this;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!ie(this,Ui,"m",Ds).call(this)||ie(this,Zi,"f").authorizationUsername&&ie(this,Zi,"f").uri&&ie(this,Zi,"f").authorizationPassword&&ie(this,Zi,"f").transportOptions.server){e.next=3;break}return e.next=1,this.getAgentInfo();case 1:if(200!=(r=e.sent).code){e.next=2;break}o=r.data,ie(this,Zi,"f").authorizationUsername=o.agentExtension,ie(this,Zi,"f").authorizationPassword=o.extensionPwd,ie(this,Zi,"f").contactName||(ie(this,Zi,"f").contactName=o.agentExtension),ie(this,Zi,"f").uri=ui.makeURI(E(s="sip:".concat(o.agentExtension,"@")).call(s,o.wsRegisterAddress)),ie(this,Zi,"f").transportOptions.server=E(a="".concat(o.wsProtocol,"://")).call(a,o.wsRegisterAddress),re(this,es,o.agentId,"f"),re(this,Yr,o.agentTag,"f"),re(this,zr,o.agentName,"f"),re(this,Zr,o.agentAccount,"f"),re(this,Jr,o.agentActive,"f"),re(this,Xr,o.agentGroupIds,"f"),re(this,Qr,o.agentStatus,"f"),null===(i=null===(t=Fi.getAliArms())||void 0===t?void 0:t.getInstance())||void 0===i||i.setConfig({setUsername:function(){return(ie(c,Vr,"f")||ie(c,Wr,"f"))+"-"+ie(c,Zi,"f").authorizationUsername}}),e.next=3;break;case 2:throw new Error(C(r));case 3:case"end":return e.stop()}},e,this)}))}),_s.set(this,function(){return ne(s,void 0,void 0,n.mark(function e(){var t;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(ie(this,Zi,"f").viaHost){e.next=2;break}return t="",e.next=1,this.getDeviceId();case 1:ie(this,Zi,"f").viaHost=E(t).call(t,e.sent,".sip");case 2:case"end":return e.stop()}},e,this)}))}),qs.set(this,function(e){var t,n,i,r,a,o,c,l,u,d,h,g,f,v,p,m,b,w,k,T,R,S,I;ie(s,hs,"f").popWindow=null===(a=e["X-Popwindow"])||void 0===a?void 0:a[0].raw,ie(s,hs,"f").afterTransferLabour=null===(o=e["X-Aftertransferlabour"])||void 0===o?void 0:o[0].raw,ie(s,hs,"f").callId=null===(c=e["X-94callid"])||void 0===c?void 0:c[0].raw,ie(s,hs,"f").cid=null===(l=e["X-Cid"])||void 0===l?void 0:l[0].raw,ie(s,hs,"f").numberId=null===(u=e["X-Numberid"])||void 0===u?void 0:u[0].raw,ie(s,hs,"f").tag=(null===(d=e["X-Tag"])||void 0===d?void 0:d[0].raw)&&"null"!==(null===(h=e["X-Tag"])||void 0===h?void 0:h[0].raw)?y(t=e["X-Tag"][0].raw.split("-")).call(t,function(e){return String.fromCharCode(e)}).join(""):"",ie(s,hs,"f").numberTag=(null===(g=e["X-Numbertag"])||void 0===g?void 0:g[0].raw)&&"null"!==(null===(f=e["X-Numbertag"])||void 0===f?void 0:f[0].raw)?decodeURIComponent(e["X-Numbertag"][0].raw):"",ie(s,hs,"f").taskId=null===(v=e["X-Taskid"])||void 0===v?void 0:v[0].raw,ie(s,hs,"f").voiceType=null===(p=e["X-Voicetype"])||void 0===p?void 0:p[0].raw,ie(s,hs,"f").processTime=null===(m=e["X-Processtime"])||void 0===m?void 0:m[0].raw,ie(s,hs,"f").userPhone=null===(b=e["X-Userphone"])||void 0===b?void 0:b[0].raw,ie(s,hs,"f").autoAnswer=null===(w=e["X-94autoanswer"])||void 0===w?void 0:w[0].raw,ie(s,hs,"f").nodeTitle=null===(k=e["X-Nodetitle"])||void 0===k?void 0:y(n=k[0].raw.split("-")).call(n,function(e){return String.fromCharCode(e)}).join(""),ie(s,hs,"f").taskName=null===(T=e["X-Taskname"])||void 0===T?void 0:y(i=T[0].raw.split("-")).call(i,function(e){return String.fromCharCode(e)}).join(""),ie(s,hs,"f").templateTitle=null===(R=e["X-Templatetitle"])||void 0===R?void 0:y(r=R[0].raw.split("-")).call(r,function(e){return String.fromCharCode(e)}).join(""),ie(s,hs,"f").phoneNumber=(null===(S=e["X-Phonenumber"])||void 0===S?void 0:S[0].raw)||(null===(I=e.From)||void 0===I?void 0:I[0].parsed.uri.normal.user)}),Ys.set(this,function(e){switch(e){case ot.Initial:case ot.Establishing:break;case ot.Established:ie(s,Ui,"m",Ks).call(s);break;case ot.Terminating:case ot.Terminated:s.clearIceAutoDetection();var t=m(function(){clearTimeout(t),t=void 0,ie(s,er,"f").incomingStatus=!1,ie(s,er,"f").answerStatus=!1},10);ie(s,ps,"f").call(s);break;default:throw new Error("Unknown session state.")}}),Zs.set(this,function(e,t,n){ie(s,xr,"f")&&(re(s,_r,!1,"f"),ie(s,er,"f").reconnectStatus=!1,ie(s,Fr,"f")&&(re(s,Fr,!1,"f"),ie(s,Qs,"f").call(s,e,t,n)))}),Js.set(this,function(){return ne(s,void 0,void 0,n.mark(function e(){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(ie(this,xr,"f")){re(this,_r,!0,"f"),re(this,Fr,!1,"f");try{this.getUserAgent().transport.disconnect().catch(function(e){return console.error(e)})}catch(e){}console.log("sip transport disconnect");try{ie(this,Ui,"m",zs).call(this)}catch(e){}ie(this,ea,"f").call(this),ie(this,Ui,"m",oa).call(this)}case 1:case"end":return e.stop()}},e,this)}))}),Xs.set(this,function(){if(ie(s,xr,"f")){var e=ie(s,Zi,"f").uri.clone(),t=ie(s,Zi,"f").uri.clone(),n=ie(s,Zi,"f").uri.clone();n.user=void 0,ie(s,Qs,"f").call(s,n,e,t)}}),Qs.set(this,function(e,t,n){if(ie(s,xr,"f")){if(ie(s,Fr,"f"))return;re(s,Fr,!0,"f"),re(s,Lr,m(function(){ie(s,Ui,"m",sa).call(s);var i=s.getUserAgent().userAgentCore,r=i.makeOutgoingRequestMessage("OPTIONS",e,t,n,{});re(s,$r,i.request(r,{onAccept:function(){console.log("sip ping ok"),re(s,Hr,0,"f"),re(s,$r,void 0,"f"),ie(s,Zs,"f").call(s,e,t,n)},onReject:function(i){var r;if(re(s,$r,void 0,"f"),408===i.message.statusCode||503===i.message.statusCode)if(console.log("sip ping error with code "+i.message.statusCode),ie(s,Dr,"f")>0&&ie(s,Hr,"f")>=ie(s,Dr,"f"))console.log("sip maximum ping attempts reached"),ie(s,Js,"f").call(s);else{var a,o;if(ie(s,Hr,"f")>0)console.log(E(o="sip ping retry ".concat(ie(s,Hr,"f")," of ")).call(o,ie(s,Dr,"f")," fail"));re(s,Hr,(r=ie(s,Hr,"f"),++r),"f"),console.log(E(a="sip ping retry ".concat(ie(s,Hr,"f")," of ")).call(a,ie(s,Dr,"f"))),ie(s,Zs,"f").call(s,e,t,n)}else re(s,Hr,0,"f"),ie(s,Zs,"f").call(s,e,t,n)}}),"f")},1e3*ie(s,xr,"f")),"f")}}),ea.set(this,function(){if(ie(s,xr,"f")){if(re(s,Fr,!1,"f"),re(s,_r,!1,"f"),ie(s,$r,"f")){try{ie(s,$r,"f").dispose()}catch(e){}re(s,$r,void 0,"f")}ie(s,Lr,"f")&&ie(s,Ui,"m",sa).call(s)}}),aa.set(this,function(){if(ie(s,qr,"f")){if(ie(s,Ur,"f"))return;re(s,Ur,!0,"f"),ie(s,er,"f").reconnectStatus=!0,re(s,Gr,m(function(){return ne(s,void 0,void 0,n.mark(function e(){var t,i,s,a,o,c,l=this;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return s=r(),e.prev=1,ie(this,Ui,"m",ia).call(this),0===ie(this,Pr,"f")&&console.log("sip reconnect success then register start"),e.next=2,ie(this,Vi,"f").register({requestDelegate:{onAccept:function(e){var t,n;try{var i,a=r();null===(n=null===(t=Fi.getAliArms())||void 0===t?void 0:t.getInstance())||void 0===n||n.api({api:E(i="softphone-sdk-reregisterer-".concat(ie(l,Vr,"f")||ie(l,Wr,"f"),"-")).call(i,ie(l,Zi,"f").authorizationUsername),msg:C({businessAttribute:A(ie(l,hs,"f")).length?ie(l,hs,"f"):void 0,appKey:ie(l,Vr,"f")||void 0,companyId:ie(l,Wr,"f")||void 0,agentId:ie(l,es,"f")||void 0,agentTag:ie(l,Yr,"f")||void 0,agentExtension:ie(l,Zi,"f").authorizationUsername||void 0,registerInterval:ie(l,qr,"f"),registerAttempts:ie(l,Mr,"f"),registerAttempt:ie(l,Pr,"f"),bjDate:Ci(),timestamp:r()}),traceId:ie(l,hs,"f").callId||ie(l,hs,"f").cid,code:200,success:!0,time:a-s,begin:s})}catch(e){}finally{console.log("sip reconnect success and register ok"),re(l,Pr,0,"f"),re(l,Ur,!1,"f"),ie(l,er,"f").registerStatus=!0,ie(l,er,"f").reconnectStatus=!1,ie(l,Xs,"f").call(l)}},onReject:function(e){return ne(l,void 0,void 0,n.mark(function t(){var i,a,o,c,l,u,d,h,g;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:t.prev=0,h=r(),null===(a=null===(i=Fi.getAliArms())||void 0===i?void 0:i.getInstance())||void 0===a||a.api({api:E(d="softphone-sdk-reregisterer-".concat(ie(this,Vr,"f")||ie(this,Wr,"f"),"-")).call(d,ie(this,Zi,"f").authorizationUsername),msg:C({businessAttribute:A(ie(this,hs,"f")).length?ie(this,hs,"f"):void 0,appKey:ie(this,Vr,"f")||void 0,companyId:ie(this,Wr,"f")||void 0,agentId:ie(this,es,"f")||void 0,agentTag:ie(this,Yr,"f")||void 0,agentExtension:ie(this,Zi,"f").authorizationUsername||void 0,registerInterval:ie(this,qr,"f"),registerAttempts:ie(this,Mr,"f"),registerAttempt:ie(this,Pr,"f"),businessInfo:{reasonPhrase:null===(o=null==e?void 0:e.message)||void 0===o?void 0:o.reasonPhrase,code:(null===(c=null==e?void 0:e.message)||void 0===c?void 0:c.statusCode)||"error",type:"reject"},bjDate:Ci(),timestamp:r()}),traceId:ie(this,hs,"f").callId||ie(this,hs,"f").cid,code:(null===(l=null==e?void 0:e.message)||void 0===l?void 0:l.statusCode)||"error",success:!1,time:h-s,begin:s}),t.next=2;break;case 1:t.prev=1,t.catch(0);case 2:if(t.prev=2,console.log("sip reconnect success but register fail with code "+e.message.statusCode),re(this,Ur,!1,"f"),!(ie(this,Mr,"f")<=ie(this,Pr,"f"))){t.next=4;break}return console.log("sip maximum register attempts reached"),re(this,Pr,0,"f"),t.next=3,this.getUserAgent().transport.disconnect().catch(function(e){return console.error(e)});case 3:ie(this,Ui,"m",oa).call(this),t.next=5;break;case 4:re(this,Pr,(u=ie(this,Pr,"f"),++u),"f"),console.log(E(g="sip reconnect success and register retry ".concat(ie(this,Pr,"f")," of ")).call(g,ie(this,Mr,"f"))),ie(this,aa,"f").call(this);case 5:return t.finish(2);case 6:case"end":return t.stop()}},t,this,[[0,1,2,6]])}))}},requestOptions:{extraHeaders:ie(this,Li,"f")}});case 2:e.next=4;break;case 3:e.prev=3,c=e.catch(1);try{o=r(),null===(i=null===(t=Fi.getAliArms())||void 0===t?void 0:t.getInstance())||void 0===i||i.api({api:E(a="softphone-sdk-reregisterer-".concat(ie(this,Vr,"f")||ie(this,Wr,"f"),"-")).call(a,ie(this,Zi,"f").authorizationUsername),msg:C({businessAttribute:A(ie(this,hs,"f")).length?ie(this,hs,"f"):void 0,appKey:ie(this,Vr,"f")||void 0,companyId:ie(this,Wr,"f")||void 0,agentId:ie(this,es,"f")||void 0,agentTag:ie(this,Yr,"f")||void 0,agentExtension:ie(this,Zi,"f").authorizationUsername||void 0,registerInterval:ie(this,qr,"f"),registerAttempts:ie(this,Mr,"f"),registerAttempt:ie(this,Pr,"f"),businessInfo:{message:c.message,code:c.code,type:"catch"},bjDate:Ci(),timestamp:r()}),traceId:ie(this,hs,"f").callId||ie(this,hs,"f").cid,code:"error",success:!1,time:o-s,begin:s})}catch(e){}finally{console.log("sip reconnect then registerer register error",c),re(this,Pr,0,"f"),re(this,Ur,!1,"f")}case 4:case"end":return e.stop()}},e,this,[[1,3]])}))},1e3*ie(s,qr,"f")),"f")}}),"object"!==Y(a))throw new Error("userAgentOption must be plain object");ie(this,Ui,"m",Cs).call(this,a),ie(this,Ui,"m",As).call(this,a),ie(this,Ui,"m",Es).call(this,a),ie(this,Ui,"m",xs).call(this,a),ie(this,Ui,"m",Ps).call(this,a),ie(this,Ui,"m",Is).call(this,a),ie(this,Ui,"m",Ss).call(this,a),re(this,Zi,ie(this,Ui,"m",Ns).call(this,a),"f")},[{key:"armsReportFlag",get:function(){return ie(this,lr,"f")},set:function(e){re(this,lr,e,"f")}},{key:"volumeValue",get:function(){return ie(this,tr,"f")}},{key:"getToken",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return ne(this,void 0,void 0,n.mark(function t(){var i,r,s,a,o,c,l,u,d,h,g,f;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=(i=e||{}).appKey,s=i.appSecret,a=i.agentId,o=i.agentTag,c=a||ie(this,es,"f"),l=o||ie(this,Yr,"f"),u=s||ie(this,Kr,"f"),d=r||ie(this,Vr,"f"),c||!l||!u||!d){t.next=3;break}return t.next=1,this.getAgentInfo({agentTag:l,appSecret:u,appKey:d});case 1:if(200!=(h=t.sent).code){t.next=2;break}re(this,es,c=h.data.agentId,"f"),t.next=3;break;case 2:throw new Error(h.message);case 3:return t.next=4,this.getGatewayAccessToken({corpId:d,secret:u,sid:c,seatOnline:!1});case 4:return g=t.sent,f=g.token,t.abrupt("return",f);case 5:case"end":return t.stop()}},t,this)}))}},{key:"armsReport",value:function(e){var t,n,i,s,a=e.api,o=e.traceId,c=e.code,l=e.success,u=e.begin,d=e.time,h=e.businessInfo;"softphone-sdk-hangup"!==e.api&&"softphone-sdk-seats-status-change"!==e.api&&"softphone-sdk-accept"!==e.api&&"softphone-sdk-connect"!==e.api&&"softphone-sdk-send-star-dtmf"!==e.api&&"softphone-sdk-ignore"!==e.api&&"softphone-sdk-manual-call"!==e.api||(null===(n=null===(t=Fi.getAliArms())||void 0===t?void 0:t.getInstance())||void 0===n||n.api({api:E(i=E(s="".concat(a,"-")).call(s,ie(this,Vr,"f")||ie(this,Wr,"f"),"-")).call(i,ie(this,Zi,"f").authorizationUsername),msg:C({appKey:ie(this,Vr,"f")||void 0,companyId:ie(this,Wr,"f")||void 0,agentId:ie(this,es,"f")||void 0,agentTag:ie(this,Yr,"f")||void 0,agentExtension:ie(this,Zi,"f").authorizationUsername||void 0,businessAttribute:A(ie(this,hs,"f")).length?ie(this,hs,"f"):void 0,businessInfo:A(h||{}).length?h:void 0,bjDate:Ci(),timestamp:r()}),traceId:o,code:c,success:l,time:d,begin:u}))}},{key:"appKey",get:function(){return ie(this,Vr,"f")}},{key:"companyId",get:function(){return ie(this,Wr,"f")}},{key:"agentTag",get:function(){return ie(this,Yr,"f")}},{key:"agentExtension",get:function(){return ie(this,Zi,"f").authorizationUsername}},{key:"agentId",get:function(){return ie(this,es,"f")}},{key:"businessAttribute",get:function(){return ie(this,hs,"f")}},{key:"getFastOutboundCall",value:function(){return ie(this,hs,"f").voiceType===Di.LABOUR}},{key:"getSitOutboundCall",value:function(){return ie(this,hs,"f").voiceType===Di.AI}},{key:"detectNavigatorPermissions",value:function(){var e,t=this;-1===q(e=navigator.userAgent).call(e,"Firefox")?navigator.permissions.query({name:"microphone"}).then(function(e){"granted"===e.state?t.authorizedMicrophonePermissions=!0:t.authorizedMicrophonePermissions=!1}).catch(function(e){console.log("Got error :",e),t.authorizedMicrophonePermissions=!1}):navigator.mediaDevices.enumerateDevices().then(function(e){""!==f(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"===ie(this,is,"f")?"https://gateway.teleai.com":"https://gateway.94ai.com"}},{key:"getGatewayToken",value:function(){return ne(this,void 0,void 0,n.mark(function e(){var t,i;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,ie(this,br,"f").call(this,ie(this,or,"f"));case 1:if(!ie(this,rr,"f")){e.next=2;break}return e.abrupt("return",ie(this,rr,"f"));case 2:if(this.token){e.next=5;break}return e.next=3,ie(this,Hs,"f").call(this);case 3:return e.next=4,this.getGatewayAccessToken({corpId:ie(this,Vr,"f"),sid:ie(this,es,"f"),secret:ie(this,Kr,"f"),seatOnline:!1});case 4:t=e.sent,i=t.token,this.token=i,re(this,sr,r(),"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 ne(this,void 0,void 0,n.mark(function e(){var t,r,s,a=this;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t=$({},ie(this,hs,"f")),r=function(){return ne(a,void 0,void 0,n.mark(function e(){var i,r,s,a,o,c,l,u,d,h,g,f,v,p,m,b,w,k,T,R;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.numberId||!t.taskId){e.next=13;break}return i={},e.prev=1,e.next=2,this.getCallNumberDetail({id:t.numberId,taskId:t.taskId});case 2:if(200===(i=e.sent).code){e.next=3;break}return console.error(i.message),t.stop=!0,ie(this,Rr,"f").call(this,i.message),e.abrupt("return");case 3:e.next=5;break;case 4:return e.prev=4,e.catch(1),a=E(r=E(s="当前会话callid:".concat(t.callId,",根据numberId:")).call(s,t.numberId,",taskId:")).call(r,t.taskId,":查询坐席接听状态异常"),console.error(a),t.stop=!0,ie(this,Rr,"f").call(this,i.message),e.abrupt("return");case 5:if(o=i.data,c=o.callType,l=o.newIntentTag,u=o.intentTag,d=o.number,h=o.numberMd5,g=o.sid,f=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=c),t.intentTag=l||u,t.number||(t.number=d),t.numberMD5||(t.numberMD5=h),t.agentId||(t.agentId=g),t.tag||(t.tag=v),t.templateId||f&&"string"==typeof f&&(p=JSON.parse(f))&&p.templateId&&(t.templateId=p.templateId),!t.callId){e.next=12;break}return b={},e.prev=7,e.next=8,this.getCallNumberChats({callId:t.callId,taskId:t.taskId});case 8:if(200===(b=e.sent).code){e.next=9;break}return console.error(b.message),t.stop=!0,ie(this,Rr,"f").call(this,b.message),e.abrupt("return");case 9:e.next=11;break;case 10:return e.prev=10,e.catch(7),k=E(w="当前会话根据callId:".concat(t.callId,",taskId:")).call(w,t.taskId,":查询会话对话记录异常"),console.error(k),t.stop=!0,ie(this,Rr,"f").call(this,k),e.abrupt("return");case 11:t.chats=y(m=b.data).call(m,function(e){return e.matchinfo&&(e.matchinfo=JSON.parse(e.matchinfo)),e}),ie(this,cr,"f")[t.callId]=t;case 12:try{ie(this,fr,"f").call(this,ie(this,cr,"f")[t.callId])}catch(e){console.log(e)}e.next=14;break;case 13:t.stop=!0,t.taskId||(T="当前会话callid:".concat(t.callId,"的taskId不存在,无法查询通话记录"),console.error(T),ie(this,Rr,"f").call(this,T)),t.numberId||(R="当前会话callid:".concat(t.callId,"的numberId不存在,无法查询通话记录"),console.error(R),ie(this,Rr,"f").call(this,R));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,r();case 4:if(!t.stop){e.next=5;break}return e.abrupt("continue",7);case 5:return e.next=6,new i(function(e){var t=m(function(){return ne(a,void 0,void 0,n.mark(function i(){return n.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()}},i)}))},3e3)});case 6:e.next=2;break;case 7:e.next=9;break;case 8:e.prev=8,s=e.catch(1),ie(this,Rr,"f").call(this,s);case 9:case"end":return e.stop()}},e,this,[[1,8]])}))}},{key:"refreshCallChatInfo",value:function(){return ne(this,void 0,void 0,n.mark(function e(){var t,i=this;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if("string"==typeof(t=ie(this,gs,"f"))?t=t===ie(this,hs,"f").voiceType:w(t)&&(t=!!V(t).call(t,function(e){return e===ie(i,hs,"f").voiceType})),!(ie(this,hs,"f").numberId&&ie(this,hs,"f").callId&&ie(this,hs,"f").taskId&&t)){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)||("//"===g(e).call(e,0,2)?t.test(g(e).call(e,2,e.length)):"http://"===g(e).call(e,0,7)?t.test(g(e).call(e,7,e.length)):"https://"===g(e).call(e,0,8)?t.test(g(e).call(e,8,e.length)):t.test(e))}(ie(this,ts,"f"))?ie(this,ts,"f"):"1"===ie(this,is,"f")?"1"===ie(this,ns,"f")?"https://seat.teleai.com/teleaiopenapi":"https://seat.teleai.com/openapi":"1"===ie(this,ns,"f")?"https://seat.94ai.com/teleaiopenapi":"https://seat.94ai.com/openapi"}},{key:"getAgentInfo",value:function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})||{},t=e.agentTag,n=e.agentId,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["agentTag","agentId"]);return this.requestOpenApi({url:"/v1/agent/getAgent",data:$({agentTag:t||ie(this,Yr,"f"),agentId:n||ie(this,es,"f")},i)})}},{key:"updateOpenApiAgentStatus",value:function(e){return this.requestOpenApi({url:"/v1/agent/updateAgentStatus",data:{agentTag:ie(this,Yr,"f"),agentId:ie(this,es,"f"),agentStatus:e}})}},{key:"importOpenApiAgentCustomer",value:function(e){return this.requestOpenApi({url:"/v1/task/importAgentCustomer",data:{agentTag:ie(this,Yr,"f"),agentId:ie(this,es,"f"),callType:1001,customers:[{number:e}]}})}},{key:"callNumber",value:function(e){return this.importOpenApiAgentCustomer(e)}},{key:"toggleNap",value:function(e){return e?this.updateOpenApiAgentStatus(3):this.updateOpenApiAgentStatus(1)}},{key:"refreshSign",value:function(e){re(this,nr,e,"f")}},{key:"refreshTimestamp",value:function(e){re(this,ir,e,"f")}},{key:"prepareUserAgent",value:function(e,t){var i;return ne(this,void 0,void 0,n.mark(function r(){var s,a,o,c,l,u,d,h,g,f,v,p;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return a=(s=e||{}).refresh,o=s.registererOptions,c=s.registererRegisterOptions,l=s.extraHeaders,u=s.authorizationUsername,d=s.authorizationPassword,h=s.uri,g=s.contactName,f=s.transportOptions,n.next=1,this.dispose();case 1:return ie(this,Zi,"f").uri=null!=h?h:ie(this,Zi,"f").uri,ie(this,Zi,"f").authorizationUsername=null!=u?u:ie(this,Zi,"f").authorizationUsername,ie(this,Zi,"f").authorizationPassword=null!=d?d:ie(this,Zi,"f").authorizationPassword,ie(this,Zi,"f").contactName=null!==(i=null!=g?g:u)&&void 0!==i?i:ie(this,Zi,"f").contactName,f&&(ie(this,Zi,"f").transportOptions=$($({},ie(this,Zi,"f").transportOptions),f)),n.prev=2,ie(this,Ui,"m",As).call(this,e),n.next=3,ie(this,Hs,"f").call(this);case 3:return n.next=4,ie(this,_s,"f").call(this);case 4:return ie(this,Ui,"m",Ms).call(this,{refresh:a}),n.next=5,ie(this,Ui,"m",ua).call(this);case 5:return t&&ie(this,Ui,"m",la).call(this,t),n.next=6,ie(this,Ui,"m",da).call(this,{registererOptions:o,registererRegisterOptions:c,extraHeaders:l},ie(this,ls,"f"));case 6:return v=n.sent,n.abrupt("return",v);case 7:return n.prev=7,p=n.catch(2),n.next=8,this.dispose();case 8:throw p;case 9:case"end":return n.stop()}},r,this,[[2,7]])}))}},{key:"dispose",value:function(){return ne(this,void 0,void 0,n.mark(function e(){var t;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,ie(this,Ui,"m",$s).call(this),e.next=1,ie(this,Ui,"m",Fs).call(this);case 1:e.next=3;break;case 2:e.prev=2,t=e.catch(0),ie(this,Ui,"m",Bs).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 ne(this,void 0,void 0,n.mark(function t(){return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return ie(this,er,"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 ne(this,void 0,void 0,n.mark(function t(){var r,s=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=1,new i(function(t,i){ne(s,void 0,void 0,n.mark(function r(){var s,a,o;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,s=null==e?void 0:e.onAck,a=null==e?void 0:e.onAckTimeout,null==e||delete e.onAck,null==e||delete e.onAckTimeout,n.next=1,this.getCurrentInvitation().accept($({sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}},onAck:function(e){t(e),null==s||s()},onAckTimeout:function(){null==a||a(),i("接听响应超时")}},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()}},r,this,[[0,2]])}))});case 1:ie(this,er,"f").incomingStatus&&(ie(this,er,"f").incomingStatus=!1,ie(this,er,"f").answerStatus=!0),t.next=3;break;case 2:throw t.prev=2,r=t.catch(0),ie(this,er,"f").incomingStatus=!1,r;case 3:case"end":return t.stop()}},t,this,[[0,2]])}))}},{key:"hangUpInvite",value:function(e){return ne(this,void 0,void 0,n.mark(function t(){var r,s,a,o,c,l=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return s=(r=e||{}).rejectOptions,a=r.byeOptions,o=r.extraHeaders,c=r.scoutResponse,t.abrupt("return",new i(function(e,t){return ne(l,void 0,void 0,n.mark(function i(){var r,l,u,d,h,g,f,v,p,m,b;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:n.prev=0,f=null===(r=(g=a||{}).requestDelegate)||void 0===r?void 0:r.onAccept,v=null===(l=g.requestDelegate)||void 0===l?void 0:l.onReject,null===(u=g.requestDelegate)||void 0===u||delete u.onAccept,null===(d=g.requestDelegate)||void 0===d||delete d.onReject,p=ie(this,Ui,"m",Os).call(this,{onAccept:function(t){console.log("sip bye success"),e(t),null==f||f(t)},onReject:function(e){null==v||v(e),t("sip bye fail with code "+e.message.statusCode)}},g.requestDelegate),delete g.requestDelegate,m=null===(h=ie(this,Ji,"f"))||void 0===h?void 0:h.state,n.next=m===ot.Initial||m===ot.Establishing?1:m===ot.Established?3:m===ot.Terminating||m===ot.Terminated?5:6;break;case 1:return n.next=2,ie(this,Ji,"f").reject($({extraHeaders:o},s||{}));case 2:return e(!0),n.abrupt("continue",6);case 3:return n.next=4,ie(this,Ji,"f").bye($({requestDelegate:p,requestOptions:{extraHeaders:o}},g));case 4:return c||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,b=n.catch(0),t(b);case 8:return n.prev=8,ie(this,er,"f").incomingStatus=!1,ie(this,er,"f").answerStatus=!1,n.finish(8);case 9:case"end":return n.stop()}},i,this,[[0,7,8,9]])}))}));case 1:case"end":return t.stop()}},t)}))}},{key:"sendStarDtmf",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return ne(this,void 0,void 0,n.mark(function t(){var r=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new i(function(t,i){return ne(r,void 0,void 0,n.mark(function r(){var s,a,o,c,l;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,a=(s=e||{}).extraHeaders,o=s.requestDelegate,c=ie(this,Ui,"m",Os).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 s.requestDelegate,n.next=1,this.getCurrentInvitation().info($({requestOptions:{body:{contentDisposition:"render",contentType:"application/dtmf-relay",content:"Signal=*\r\nDuration=100"},extraHeaders:a},requestDelegate:c},s));case 1:ie(this,vs,"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()}},r,this,[[0,2]])}))}));case 1:case"end":return t.stop()}},t)}))}},{key:"muteRemoteAudio",value:function(){var e;h(e=ie(this,Ki,"f").getReceivers()).call(e,function(e){e.track.enabled=!1})}},{key:"unMuteRemoteAudio",value:function(){var e;h(e=ie(this,Ki,"f").getReceivers()).call(e,function(e){e.track.enabled=!0})}},{key:"muteLocalAudio",value:function(){var e;h(e=ie(this,Ki,"f").getSenders()).call(e,function(e){e.track.enabled=!1})}},{key:"unMuteLocalAudio",value:function(){var e;h(e=ie(this,Ki,"f").getSenders()).call(e,function(e){e.track.enabled=!0})}},{key:"getUserAgentStatue",value:function(){return ie(this,er,"f")}},{key:"getUserAgent",value:function(){return ie(this,Gi,"f")||re(this,Gi,new ui(ie(this,Zi,"f")),"f"),ie(this,Gi,"f")}},{key:"getSessionDescriptionHandler",value:function(){return ie(this,Wi,"f")}},{key:"getPeerConnection",value:function(){return ie(this,Ki,"f")}},{key:"getSenders",value:function(){return ie(this,zi,"f")}},{key:"getReceivers",value:function(){return ie(this,Yi,"f")}},{key:"getStream",value:function(){var e,t=this;return ie(this,Qi,"f")||re(this,Qi,new MediaStream,"f"),h(e=ie(this,Yi,"f")).call(e,function(e){e.track&&ie(t,Qi,"f").addTrack(e.track)}),ie(this,Qi,"f")}},{key:"getCurrentInviter",value:function(){if(!ie(this,Xi,"f"))throw new Error("No currentInviter...");return ie(this,Xi,"f")}},{key:"getCurrentInvitation",value:function(){return ie(this,Ji,"f")}},{key:"clearIceAutoDetection",value:function(){var e;null===(e=ie(this,Bi,"f"))||void 0===e||e.destroy(),re(this,Bi,void 0,"f")}},{key:"iceAutoDetectRecovery",value:function(e){var t,n=this;null===(t=ie(this,Bi,"f"))||void 0===t||t.destroy(),re(this,Bi,new fa(e,this,{debugIceCredentials:!0,onRecoveryStart:function(e,t){console.log("开始 ICE 恢复",e,t)},onRecovered:function(){console.log("媒体连接已恢复")},isSignalingAvailable:function(){return ie(n,Gi,"f").isConnected()},isRegistrationAvailable:function(){return ie(n,Vi,"f").state===Rt.Registered},onRecoveryFailed:function(e,t){console.error("ICE 恢复失败",e,t)}}),"f"),ie(this,Bi,"f").start()}},{key:"invite",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return ne(this,void 0,void 0,n.mark(function i(){var r,s,a;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(s=ui.makeURI(e.uri?e.uri:E(r="sip:".concat(e.extension,"@")).call(r,ie(this,Zi,"f").transportOptions.server.split("://")[1]))){n.next=1;break}throw new Error("Failed to create target URI.");case 1:return re(this,Xi,new St(this.getUserAgent(),s,{sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}}}),"f"),a=(t||{}).extraHeaders,n.next=2,this.getCurrentInviter().invite($({requestOptions:{extraHeaders:a}},t));case 2:return n.abrupt("return",ie(this,Xi,"f"));case 3:case"end":return n.stop()}},i,this)}))}}])}();Bi=new z,Li=new z,Gi=new z,Vi=new z,Wi=new z,Ki=new z,Yi=new z,zi=new z,Zi=new z,Ji=new z,Xi=new z,Qi=new z,er=new z,tr=new z,nr=new z,ir=new z,rr=new z,sr=new z,ar=new z,or=new z,cr=new z,lr=new z,ur=new z,dr=new z,hr=new z,gr=new z,fr=new z,vr=new z,pr=new z,mr=new z,br=new z,yr=new z,wr=new z,kr=new z,Tr=new z,Rr=new z,Sr=new z,Ir=new z,Er=new z,Cr=new z,Ar=new z,xr=new z,Dr=new z,Hr=new z,_r=new z,$r=new z,qr=new z,Mr=new z,Pr=new z,Or=new z,Nr=new z,jr=new z,Fr=new z,Ur=new z,Br=new z,Lr=new z,Gr=new z,Vr=new z,Wr=new z,Kr=new z,Yr=new z,zr=new z,Zr=new z,Jr=new z,Xr=new z,Qr=new z,es=new z,ts=new z,ns=new z,is=new z,rs=new z,ss=new z,as=new z,os=new z,cs=new z,ls=new z,us=new z,ds=new z,hs=new z,gs=new z,fs=new z,vs=new z,ps=new z,ms=new z,bs=new z,ys=new z,ws=new z,ks=new z,Ts=new z,Rs=new z,Hs=new z,_s=new z,qs=new z,Ys=new z,Zs=new z,Js=new z,Xs=new z,Qs=new z,ea=new z,aa=new z,Ui=new Z,Ss=function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};re(this,vr,null!==(e=n.openXhrIntercept)&&void 0!==e?e:ie(this,vr,"f"),"f"),re(this,pr,null!==(t=n.gatewayXhrIntercept)&&void 0!==t?t:ie(this,pr,"f"),"f")},Is=function(){var e,t,i,r,s,a,o=this,c=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};re(this,gs,null!==(e=c.enableChatInfoPush)&&void 0!==e?e:ie(this,gs,"f"),"f"),re(this,fs,null!==(t=c.enableVolumnTrack)&&void 0!==t?t:ie(this,fs,"f"),"f"),re(this,gr,null!==(i=c.refreshSpeekVolumn)&&void 0!==i?i:ie(this,gr,"f"),"f"),re(this,Sr,null!==(r=c.refreshRequirementCheck)&&void 0!==r?r:ie(this,Sr,"f"),"f"),re(this,fr,null!==(s=c.refreshChat)&&void 0!==s?s:ie(this,fr,"f"),"f"),re(this,Rr,null!==(a=c.refreshChatErrorCallback)&&void 0!==a?a:ie(this,Rr,"f"),"f");var l=c.errorCallback;c.errorCallback=function(e){return ne(o,void 0,void 0,n.mark(function t(){return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=1,ie(this,wr,"f").call(this,e);case 1:t.next=3;break;case 2:t.prev=2,t.catch(0);case 3:return t.prev=3,null==l||l(e),t.finish(3);case 4:case"end":return t.stop()}},t,this,[[0,2,3,4]])}))}},Es=function(){var e,t,n,i,s,a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};re(this,rr,null!==(e=a.token)&&void 0!==e?e:ie(this,rr,"f"),"f"),re(this,sr,null!==(t=a.tokenTimestamp)&&void 0!==t?t:ie(this,sr,"f"),"f"),re(this,or,null!==(n=a.tokenExpirationTime)&&void 0!==n?n:ie(this,or,"f"),"f"),ie(this,rr,"f")&&!ie(this,sr,"f")&&re(this,sr,r(),"f"),re(this,br,null!==(i=a.tokenCheck)&&void 0!==i?i:ie(this,br,"f"),"f"),re(this,Tr,null!==(s=a.tokenOverdued)&&void 0!==s?s:ie(this,Tr,"f"),"f")},Cs=function(){var e,t,n,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};re(this,ls,null!==(e=i.clusterMode)&&void 0!==e?e:ie(this,ls,"f"),"f"),re(this,us,null!==(t=i.reClusterRegisterTimeout)&&void 0!==t?t:ie(this,us,"f"),"f"),re(this,ds,null!==(n=i.reClusterConnectTimeout)&&void 0!==n?n:ie(this,ds,"f"),"f")},As=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,d=i.sign,h=i.armsReport,g=i.timestamp,f=i.companyId;re(this,es,null!=r?r:ie(this,es,"f"),"f"),re(this,Yr,null!=s?s:ie(this,Yr,"f"),"f"),re(this,Vr,null!=a?a:ie(this,Vr,"f"),"f"),re(this,Wr,null!=f?f:ie(this,Wr,"f"),"f"),re(this,Kr,null!=o?o:ie(this,Kr,"f"),"f"),re(this,ts,null!=c?c:ie(this,ts,"f"),"f"),re(this,lr,null!=h?h:ie(this,lr,"f"),"f"),re(this,is,null!=l?l:ie(this,is,"f"),"f"),re(this,ns,null!=u?u:ie(this,ns,"f"),"f"),re(this,nr,null!=d?d:ie(this,nr,"f"),"f"),re(this,ir,null!=g?g:ie(this,ir,"f"),"f"),re(this,ar,null!==(e=i.signExpirationTime)&&void 0!==e?e:ie(this,ar,"f"),"f"),re(this,mr,null!==(t=i.signCheck)&&void 0!==t?t:ie(this,mr,"f"),"f"),re(this,yr,null!==(n=i.signOverdued)&&void 0!==n?n:ie(this,yr,"f"),"f")},xs=function(e){e.sipHeaders&&(re(this,Li,e.sipHeaders,"f"),delete e.sipHeaders)},Ds=function(){return!(!ie(this,es,"f")&&!ie(this,Yr,"f")||!(ie(this,Vr,"f")&&ie(this,Kr,"f")||ie(this,nr,"f")&&ie(this,ir,"f")))},$s=function(){ie(this,Ui,"m",Us).call(this),ie(this,Ui,"m",Vs).call(this),ie(this,Ui,"m",Ws).call(this),ie(this,Ui,"m",Gs).call(this),ie(this,Ui,"m",Ls).call(this),ie(this,Ui,"m",ta).call(this),ie(this,Ui,"m",na).call(this),ie(this,Ui,"m",Bs).call(this),ie(this,ps,"f").call(this),this.clearIceAutoDetection(),re(this,hs,{},"f"),re(this,cr,{},"f")},Ms=function(e){re(this,er,W(JSON.parse(C(ji)),"function"==typeof e.refresh?e.refresh:ie(this,as,"f")),"f")},Ps=function(e){var t,n,i,r,s,a,o,c,l,u,d,h,g,f,v;re(this,Cr,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:ie(this,Cr,"f"),"f"),re(this,Ar,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:ie(this,Ar,"f"),"f"),re(this,Or,null!==(l=null===(c=e.transportOptions)||void 0===c?void 0:c.keepAliveInterval)&&void 0!==l?l:ie(this,Or,"f"),"f"),re(this,Nr,null!==(d=null===(u=e.transportOptions)||void 0===u?void 0:u.keepAliveDebounce)&&void 0!==d?d:ie(this,Nr,"f"),"f"),re(this,qr,null!==(h=e.registerInterval)&&void 0!==h?h:ie(this,qr,"f"),"f"),re(this,xr,null!==(g=e.optionsPingInterval)&&void 0!==g?g:ie(this,xr,"f"),"f"),re(this,Dr,null!==(f=e.optionsPingAttempts)&&void 0!==f?f:ie(this,Dr,"f"),"f"),re(this,Mr,null!==(v=e.registerAttempts)&&void 0!==v?v:ie(this,Mr,"f"),"f")},Os=function(e,t){var i,r=this;return t?(h(i=A(t)).call(i,function(i){if(t[i]&&"function"==typeof t[i])if(e[i]){if("function"==typeof e[i]){var s=e[i];e[i]=function(e){return ne(r,void 0,void 0,n.mark(function r(){return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=1,t[i](e);case 1:return n.next=2,s(e);case 2:case"end":return n.stop()}},r)}))}}}else e[i]=t[i]}),e):e},Ns=function(e){var t,i=this,r={delegate:{onConnect:function(){return ne(i,void 0,void 0,n.mark(function e(){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:console.log("sip connected"),ie(this,Xs,"f").call(this);case 1:case"end":return e.stop()}},e,this)}))},onInvite:function(e){ie(i,qs,"f").call(i,e.incomingInviteRequest.message.headers),i.refreshCallChatInfo(),ie(i,Ui,"m",js).call(i),re(i,Ji,e,"f"),ie(i,er,"f").incomingStatus=!0,i.iceAutoDetectRecovery(e),e.stateChange.addListener(ie(i,Ys,"f"))},onDisconnect:function(e){return ne(i,void 0,void 0,n.mark(function t(){var i;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return console.log("sip disconnected"),i=!1,ie(this,xr,"f")>0&&(i=ie(this,_r,"f"),ie(this,ea,"f").call(this)),t.prev=1,t.next=2,ie(this,Ui,"m",zs).call(this);case 2:t.next=4;break;case 3:t.prev=3,t.catch(1);case 4:(e||i)&&ie(this,Ui,"m",oa).call(this);case 5:case"end":return t.stop()}},t,this,[[1,3]])}))}}};e.delegate?h(t=A(e.delegate)).call(t,function(t){var s=t;if(e.delegate[s]&&"function"==typeof e.delegate[s]){var a=e.delegate[s];e.delegate[s]=function(e){return ne(i,void 0,void 0,n.mark(function t(){var i,o;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return null===(o=(i=r.delegate)[s])||void 0===o||o.call(i,e),t.next=1,a(e);case 1:case"end":return t.stop()}},t)}))}}}):e.delegate=r.delegate;return e.reconnectionAttempts=0,e.transportOptions=$($({},e.transportOptions||{}),{keepAliveInterval:ie(this,Or,"f"),keepAliveDebounce:ie(this,Nr,"f")}),void 0===e.sessionDescriptionHandlerFactoryOptions&&(e.sessionDescriptionHandlerFactoryOptions={iceGatheringTimeout:2e3,peerConnectionConfiguration:{iceServers:[]}}),$($({},Ni),e)},js=function(){ie(this,Ji,"f")&&(ie(this,Ji,"f").dispose(),re(this,Ji,void 0,"f"))},Fs=function(){return ne(this,void 0,void 0,n.mark(function e(){return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!ie(this,Gi,"f")){e.next=2;break}return e.next=1,ie(this,Gi,"f").stop();case 1:re(this,Gi,void 0,"f");case 2:case"end":return e.stop()}},e,this)}))},Us=function(){var e;ie(this,Qi,"f")&&(h(e=ie(this,Qi,"f").getTracks()).call(e,function(e){e.stop()}),re(this,Qi,void 0,"f"))},Bs=function(){var e,t=this;h(e=A(ji)).call(e,function(e){var n=e;ie(t,er,"f")[n]=ji[n]})},Ls=function(){ie(this,Wi,"f")&&(ie(this,Wi,"f").close(),re(this,Wi,void 0,"f"))},Gs=function(){ie(this,Ki,"f")&&(ie(this,Ki,"f").close(),re(this,Ki,void 0,"f"))},Vs=function(){re(this,zi,[],"f")},Ws=function(){re(this,Yi,[],"f")},Ks=function(){var e=this.getCurrentInvitation().sessionDescriptionHandler;ie(this,Ui,"m",Gs).call(this),ie(this,Ui,"m",Ls).call(this),ie(this,Ui,"m",Vs).call(this),ie(this,Ui,"m",Ws).call(this),re(this,Wi,e,"f"),re(this,Ki,e.peerConnection,"f"),re(this,zi,ie(this,Ki,"f").getSenders(),"f"),re(this,Yi,ie(this,Ki,"f").getReceivers(),"f"),(this.getFastOutboundCall()||!this.getSitOutboundCall()&&this.notNeedSendStarDtmf())&&ie(this,vs,"f").call(this)},zs=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return ne(this,void 0,void 0,n.mark(function t(){var r=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!ie(this,Vi,"f")){t.next=1;break}return console.log("sip due to disconnection, unregistered"),t.abrupt("return",new i(function(t,i){return ne(r,void 0,void 0,n.mark(function r(){var s,a,o;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,s=e||{},a=ie(this,Ui,"m",Os).call(this,{onAccept:function(e){console.log("sip unregister successed"),t(e)},onReject:function(e){i("sip unregister fail with code "+e.message.statusCode)}},s.requestDelegate),delete e.requestDelegate,n.next=1,ie(this,Vi,"f").unregister($({requestDelegate:a},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()}},r,this,[[0,2]])}))}));case 1:case"end":return t.stop()}},t,this)}))},ta=function(){ie(this,Ui,"m",ia).call(this),ie(this,Ui,"m",ra).call(this),ie(this,Ui,"m",sa).call(this),re(this,Ur,!1,"f"),re(this,jr,!1,"f"),re(this,Fr,!1,"f")},na=function(){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];(!(arguments.length>0&&void 0!==arguments[0])||arguments[0])&&(clearTimeout(ie(this,os,"f")),re(this,os,void 0,"f")),e&&(clearTimeout(ie(this,cs,"f")),re(this,cs,void 0,"f"))},ia=function(){clearTimeout(ie(this,Gr,"f")),re(this,Gr,void 0,"f")},ra=function(){clearTimeout(ie(this,Br,"f")),re(this,Br,void 0,"f")},sa=function(){clearTimeout(ie(this,Lr,"f")),re(this,Lr,void 0,"f")},oa=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return ne(this,void 0,void 0,n.mark(function i(){var s=this;return n.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(!ie(this,Ar,"f")){i.next=4;break}if(ie(this,er,"f").reconnectStatus=!0,!ie(this,jr,"f")){i.next=1;break}return i.abrupt("return");case 1:if(!(t>ie(this,Cr,"f"))){i.next=3;break}return console.log("sip maximum reconnection attempts reached"),i.next=2,this.dispose();case 2:return i.abrupt("return");case 3:console.log("sip reconnection attempt..."),re(this,jr,!0,"f"),re(this,Br,m(function(){ie(s,Ui,"m",ra).call(s);var i=r();s.getUserAgent().reconnect().then(function(){return ne(s,void 0,void 0,n.mark(function e(){var s,a,o,c,l;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:console.log(E(s="sip reconnection attempt ".concat(t," of ")).call(s,ie(this,Cr,"f")," - succeeded")),re(this,jr,!1,"f");try{l=r(),null===(o=null===(a=Fi.getAliArms())||void 0===a?void 0:a.getInstance())||void 0===o||o.api({api:E(c="softphone-sdk-reconnect-".concat(ie(this,Vr,"f")||ie(this,Wr,"f"),"-")).call(c,ie(this,Zi,"f").authorizationUsername),msg:C({businessAttribute:A(ie(this,hs,"f")).length?ie(this,hs,"f"):void 0,appKey:ie(this,Vr,"f")||void 0,companyId:ie(this,Wr,"f")||void 0,agentId:ie(this,es,"f")||void 0,agentTag:ie(this,Yr,"f")||void 0,agentExtension:ie(this,Zi,"f").authorizationUsername||void 0,reconnectionInterval:ie(this,Ar,"f"),reconnectionAttempts:ie(this,Cr,"f"),reconnectionAttempt:t,bjDate:Ci(),timestamp:r()}),traceId:ie(this,hs,"f").callId||ie(this,hs,"f").cid,code:200,success:!0,time:l-i,begin:i})}catch(e){}finally{ie(this,aa,"f").call(this)}case 1:case"end":return e.stop()}},e,this)}))}).catch(function(n){var a,o;try{var c,l=r();null===(o=null===(a=Fi.getAliArms())||void 0===a?void 0:a.getInstance())||void 0===o||o.api({api:E(c="softphone-sdk-reconnect-".concat(ie(s,Vr,"f")||ie(s,Wr,"f"),"-")).call(c,ie(s,Zi,"f").authorizationUsername),msg:C({businessAttribute:A(ie(s,hs,"f")).length?ie(s,hs,"f"):void 0,appKey:ie(s,Vr,"f")||void 0,companyId:ie(s,Wr,"f")||void 0,agentId:ie(s,es,"f")||void 0,agentTag:ie(s,Yr,"f")||void 0,agentExtension:ie(s,Zi,"f").authorizationUsername||void 0,reconnectionInterval:ie(s,Ar,"f"),reconnectionAttempts:ie(s,Cr,"f"),reconnectionAttempt:t,businessInfo:{message:n.message,code:n.code,type:"catch"},bjDate:Ci(),timestamp:r()}),traceId:ie(s,hs,"f").callId||ie(s,hs,"f").cid,code:"error",success:!1,time:l-i,begin:i})}catch(e){}finally{var u;console.error(n),console.log(E(u="sip reconnection attempt ".concat(t," of ")).call(u,ie(s,Cr,"f")," - failed")),re(s,jr,!1,"f"),ie(s,Ui,"m",e).call(s,++t)}})},1===t?0:1e3*ie(this,Ar,"f")),"f");case 4:case"end":return i.stop()}},i,this)}))},ca=function(e){var t,i=this;return h(t=A(e)).call(t,function(t){var r=t;if("function"==typeof(null==e?void 0:e[r])){var s=e[r];e[r]=function(e){return ne(i,void 0,void 0,n.mark(function t(){var i,a;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return null===(a=(i=ie(this,Zi,"f").delegate)[r])||void 0===a||a.call(i,e),t.next=1,s(e);case 1:case"end":return t.stop()}},t,this)}))}}}),e},la=function(e){var t=this.getUserAgent();return t.delegate=ie(this,Ui,"m",ca).call(this,e),t},ua=function(){return ne(this,void 0,void 0,n.mark(function e(){var t;return n.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 ie(this,er,"f").connectStatus=!0,e.abrupt("return",t);case 4:case"end":return e.stop()}},e,this)}))},da=function e(t){var r=this,s=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=t||{},o=a.registererOptions,c=a.registererRegisterOptions,l=a.extraHeaders;return new i(function(t,i){return ne(r,void 0,void 0,n.mark(function r(){var a,u,d,h,g,f=this;return n.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return a=this.getUserAgent(),re(this,Vi,new Dt(a,$({extraHeaders:l||ie(this,Li,"f")},o||{})),"f"),d=c||{},h=ie(this,Ui,"m",Os).call(this,{onAccept:function(e){u=e,ie(f,Ui,"m",na).call(f),ie(f,er,"f").registerStatus=!0,t(a)},onReject:function(e){ie(f,Ui,"m",na).call(f),i("sip register fail with code "+e.message.statusCode)}},d.requestDelegate),delete d.requestDelegate,s&&re(this,os,m(function(){return ne(f,void 0,void 0,n.mark(function r(){var s,g=this;return n.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(u){r.next=4;break}re(this,cs,m(function(){return ne(g,void 0,void 0,n.mark(function r(){var s,a;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(ie(this,Ui,"m",na).call(this,!1,!0),u){n.next=6;break}n.prev=1;try{ie(this,Vi,"f").dispose()}catch(e){}return ie(this,Ui,"m",$s).call(this),ie(this,ea,"f").call(this),re(this,Hr,0,"f"),re(this,Pr,0,"f"),n.next=2,ie(this,Gi,"f").transport.dispose();case 2:return re(this,Gi,new ui(ie(this,Zi,"f")),"f"),n.next=3,ie(this,Ui,"m",ua).call(this);case 3:return n.next=4,ie(this,Ui,"m",e).call(this,{registererOptions:o,registererRegisterOptions:c,extraHeaders:l});case 4:s=n.sent,t(s),n.next=6;break;case 5:n.prev=5,a=n.catch(1),i(a);case 6:case"end":return n.stop()}},r,this,[[1,5]])}))},ie(this,ds,"f")),"f");try{ie(this,Vi,"f").dispose()}catch(e){}return re(this,Vi,new Dt(a,$({extraHeaders:l||ie(this,Li,"f")},o||{})),"f"),ie(this,Ui,"m",na).call(this,!0,!1),r.prev=1,r.next=2,ie(this,Vi,"f").register($({requestDelegate:h,requestOptions:{extraHeaders:l||ie(this,Li,"f")}},d));case 2:r.next=4;break;case 3:r.prev=3,s=r.catch(1),ie(this,Ui,"m",na).call(this),i(s);case 4:case"end":return r.stop()}},r,this,[[1,3]])}))},ie(this,us,"f")),"f"),r.prev=1,r.next=2,ie(this,Vi,"f").register($({requestDelegate:h,requestOptions:{extraHeaders:l||ie(this,Li,"f")}},d));case 2:r.next=4;break;case 3:r.prev=3,g=r.catch(1),ie(this,Ui,"m",na).call(this),i(g);case 4:case"end":return r.stop()}},r,this,[[1,3]])}))})};var ma=function(){return t(function t(){e(this,t)},null,[{key:"getToken",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return ne(this,void 0,void 0,n.mark(function t(){var s,a,o,c,l,u,d,h,g,f=this;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(a=(s=e||{}).appKey,o=s.appSecret,c=s.agentId,l=s.agentTag,u=s.teleai,(d=c)||!l||!o||!a){t.next=3;break}return t.next=1,new i(function(e,t){try{var n=r(),i=J.enc.Base64.stringify(J.HmacSHA1(a+n,o)),s=Ei(e,t,{url:(u?"https://seat.teleai.com/teleaiopenapi":"https://seat.94ai.com/openapi")+"/v1/agent/getAgent",data:{agentTag:l,agentId:c}}),d=s.xhr,h=s.ajaxData,g=s.contentType;d.setRequestHeader("appKey",a),d.setRequestHeader("timestamp",String(n)),d.setRequestHeader("sign",i),d.setRequestHeader("Content-type",g||"application/json"),d.send(h)}catch(e){t(e.message)}});case 1:if(200!=(h=t.sent).code){t.next=2;break}d=h.data.agentId,t.next=3;break;case 2:throw new Error(h.message);case 3:return t.next=4,new i(function(e,t){return ne(f,void 0,void 0,n.mark(function i(){var r,s,c,l;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:try{r=Ei(e,t,{url:(u?"https://gateway.teleai.com":"https://gateway.94ai.com")+"/authority/accessToken/openApi",data:{corpId:a,secret:o,sid:d,seatOnline:!1}}),s=r.xhr,c=r.ajaxData,l=r.contentType,s.setRequestHeader("x-app-code",3),s.setRequestHeader("content-type",l||"application/json"),s.send(c)}catch(e){t(e.message)}case 1:case"end":return n.stop()}},i)}))});case 4:return g=t.sent,t.abrupt("return",g.token);case 5:case"end":return t.stop()}},t)}))}},{key:"getUserAgentManager",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return ie(this,ha,"f",ga)||re(this,ha,new pa(e),"f",ga),ie(this,ha,"f",ga)}},{key:"hasUserAgentManager",value:function(){return!!ie(this,ha,"f",ga)}},{key:"newUserAgentManager",value:function(){return new pa(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})}},{key:"dispose",value:function(){if(ie(this,ha,"f",ga))try{ie(this,ha,"f",ga).dispose()}catch(e){}finally{re(this,ha,void 0,"f",ga)}}}])}();ha=ma,ga={value:void 0};export{Hi as AfterTransferLabour,Fi as AliArms,va as CallbackAggregator,St as Inviter,xi as PopWindow,Dt as Registerer,ot as SessionState,hi as SimpleUser,Ee as URI,ui as UserAgent,ma as UserAgentFactory,pa as UserAgentManager,Di as VoiceType,Si as accumulateSec,Ii as accumulationTimer,yi as cleanupMedia,Ci as getBeijingTime,vi as getDevicePermission,gi as getMedia,Ti as getTimes,Ri as getZeorTime,bi as pauseMedia,mi as playMedia,pi as requestMicroPhonePermission,fi as stopStreamTracks,Ni as userAgentDefault,ji as userAgentStatus};
|