@voicenter-team/opensips-js 1.0.136 → 1.0.138
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/dist/opensips-js.cjs.js +27 -27
- package/dist/opensips-js.es.js +511 -512
- package/dist/opensips-js.iife.js +23 -23
- package/dist/opensips-js.umd.js +23 -23
- package/package.json +1 -1
package/dist/opensips-js.umd.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
(function(Nt,Mt){typeof exports=="object"&&typeof module<"u"?Mt(exports):typeof define=="function"&&define.amd?define(["exports"],Mt):(Nt=typeof globalThis<"u"?globalThis:Nt||self,Mt(Nt.OpensipsJS={}))})(this,function(Nt){"use strict";var Jv=Object.defineProperty;var zv=(Nt,Mt,Me)=>Mt in Nt?Jv(Nt,Mt,{enumerable:!0,configurable:!0,writable:!0,value:Me}):Nt[Mt]=Me;var ts=(Nt,Mt,Me)=>(zv(Nt,typeof Mt!="symbol"?Mt+"":Mt,Me),Me);var Mt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Me(c){return c&&c.__esModule&&Object.prototype.hasOwnProperty.call(c,"default")?c.default:c}const vl={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.10.0",homepage:"https://jssip.net",contributors:["José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)","Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.19.6","@babel/preset-env":"^7.19.4","ansi-colors":"^3.2.4",browserify:"^16.5.1",eslint:"^5.16.0","fancy-log":"^1.3.3",gulp:"^4.0.2","gulp-babel":"^8.0.0","gulp-eslint":"^5.0.0","gulp-expect-file":"^1.0.2","gulp-header":"^2.0.9","gulp-nodeunit-runner":"^0.2.2","gulp-plumber":"^1.2.1","gulp-rename":"^1.4.0","gulp-uglify-es":"^1.0.4",pegjs:"^0.7.0","vinyl-buffer":"^1.0.1","vinyl-source-stream":"^2.0.0"},scripts:{lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"}};var Ku=vl,st={USER_AGENT:"".concat(Ku.title," ").concat(Ku.version),SIP:"sip",SIPS:"sips",causes:{CONNECTION_ERROR:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{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",424:"Bad Location Information",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:"JsSIP Internal 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"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2};function El(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?El=function(n){return typeof n}:El=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},El(c)}function Sl(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function yl(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&yr(c,t)}function Al(c){var t=Yu();return function(){var a=Ar(c),o;if(t){var s=Ar(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return Fh(this,o)}}function Fh(c,t){return t&&(El(t)==="object"||typeof t=="function")?t:jh(c)}function jh(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Dn(c){var t=typeof Map=="function"?new Map:void 0;return Dn=function(a){if(a===null||!qh(a))return a;if(typeof a!="function")throw new TypeError("Super expression must either be null or a function");if(typeof t<"u"){if(t.has(a))return t.get(a);t.set(a,o)}function o(){return Cl(a,arguments,Ar(this).constructor)}return o.prototype=Object.create(a.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),yr(o,a)},Dn(c)}function Cl(c,t,n){return Yu()?Cl=Reflect.construct:Cl=function(o,s,r){var d=[null];d.push.apply(d,s);var h=Function.bind.apply(o,d),_=new h;return r&&yr(_,r.prototype),_},Cl.apply(null,arguments)}function Yu(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function qh(c){return Function.toString.call(c).indexOf("[native code]")!==-1}function yr(c,t){return yr=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},yr(c,t)}function Ar(c){return Ar=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Ar(c)}var Vh=function(c){yl(n,c);var t=Al(n);function n(a,o){var s;return Sl(this,n),s=t.call(this),s.code=1,s.name="CONFIGURATION_ERROR",s.parameter=a,s.value=o,s.message=s.value?"Invalid value ".concat(JSON.stringify(s.value),' for parameter "').concat(s.parameter,'"'):"Missing parameter: ".concat(s.parameter),s}return n}(Dn(Error)),Bh=function(c){yl(n,c);var t=Al(n);function n(a){var o;return Sl(this,n),o=t.call(this),o.code=2,o.name="INVALID_STATE_ERROR",o.status=a,o.message="Invalid status: ".concat(a),o}return n}(Dn(Error)),Gh=function(c){yl(n,c);var t=Al(n);function n(a){var o;return Sl(this,n),o=t.call(this),o.code=3,o.name="NOT_SUPPORTED_ERROR",o.message=a,o}return n}(Dn(Error)),Wh=function(c){yl(n,c);var t=Al(n);function n(a){var o;return Sl(this,n),o=t.call(this),o.code=4,o.name="NOT_READY_ERROR",o.message=a,o}return n}(Dn(Error)),Is={ConfigurationError:Vh,InvalidStateError:Bh,NotSupportedError:Gh,NotReadyError:Wh},Qe={},za,Ju;function Xa(){if(Ju)return za;Ju=1;function c(s,r){if(!(s instanceof r))throw new TypeError("Cannot call a class as a function")}function t(s,r){for(var d=0;d<r.length;d++){var h=r[d];h.enumerable=h.enumerable||!1,h.configurable=!0,"value"in h&&(h.writable=!0),Object.defineProperty(s,h.key,h)}}function n(s,r,d){return r&&t(s.prototype,r),d&&t(s,d),s}var a=bs(),o=ss();return za=function(){n(s,null,[{key:"parse",value:function(d){if(d=o.parse(d,"Name_Addr_Header"),d!==-1)return d}}]);function s(r,d,h){if(c(this,s),!r||!(r instanceof a))throw new TypeError('missing or invalid "uri" parameter');this._uri=r,this._parameters={},this.display_name=d;for(var _ in h)Object.prototype.hasOwnProperty.call(h,_)&&this.setParam(_,h[_])}return n(s,[{key:"setParam",value:function(d,h){d&&(this._parameters[d.toLowerCase()]=typeof h>"u"||h===null?null:h.toString())}},{key:"getParam",value:function(d){if(d)return this._parameters[d.toLowerCase()]}},{key:"hasParam",value:function(d){if(d)return this._parameters.hasOwnProperty(d.toLowerCase())&&!0||!1}},{key:"deleteParam",value:function(d){if(d=d.toLowerCase(),this._parameters.hasOwnProperty(d)){var h=this._parameters[d];return delete this._parameters[d],h}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"clone",value:function(){return new s(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}},{key:"_quote",value:function(d){return d.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}},{key:"toString",value:function(){var d=this._display_name?'"'.concat(this._quote(this._display_name),'" '):"";d+="<".concat(this._uri.toString(),">");for(var h in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,h)&&(d+=";".concat(h),this._parameters[h]!==null&&(d+="=".concat(this._parameters[h])));return d}},{key:"uri",get:function(){return this._uri}},{key:"display_name",get:function(){return this._display_name},set:function(d){this._display_name=d===0?"0":d}}]),s}(),za}var Qa,zu;function ss(){return zu||(zu=1,Qa=function(){function c(n){return'"'+n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var t={parse:function(a,o){var s={CRLF:g,DIGIT:T,ALPHA:E,HEXDIG:y,WSP:A,OCTET:C,DQUOTE:I,SP:H,HTAB:$,alphanum:oe,reserved:N,unreserved:j,mark:Se,escaped:ve,LWS:k,SWS:D,HCOLON:B,TEXT_UTF8_TRIM:V,TEXT_UTF8char:J,UTF8_NONASCII:F,UTF8_CONT:Z,LHEX:U,token:P,token_nodot:se,separators:it,word:ee,STAR:Y,SLASH:G,EQUAL:re,LPAREN:ge,RPAREN:be,RAQUOT:ke,LAQUOT:Re,COMMA:le,SEMI:ye,COLON:lt,LDQUOT:ot,RDQUOT:Ee,comment:Ae,ctext:Ie,quoted_string:Oe,quoted_string_clean:pe,qdtext:de,quoted_pair:_e,SIP_URI_noparams:we,SIP_URI:Ne,uri_scheme:tt,uri_scheme_sips:He,uri_scheme_sip:Vt,userinfo:Ct,user:Bn,user_unreserved:Gn,password:cn,hostport:as,host:As,hostname:fn,domainlabel:Wn,toplabel:Kn,IPv6reference:hn,IPv6address:me,h16:ae,ls32:ut,IPv4address:es,dec_octet:$s,port:ui,uri_parameters:Yn,uri_parameter:Jn,transport_param:ci,user_param:fi,method_param:hi,ttl_param:di,maddr_param:_i,lr_param:pi,other_param:mi,pname:gi,pvalue:Hs,paramchar:Fs,param_unreserved:Ti,headers:dn,header:_n,hname:vi,hvalue:js,hnv_unreserved:pn,Request_Response:wa,Request_Line:Ei,Request_URI:zn,absoluteURI:Xn,hier_part:Si,net_path:mn,abs_path:gn,opaque_part:qs,uric:Vs,uric_no_slash:yi,path_segments:Tn,segment:Bs,param:Cs,pchar:Gs,scheme:Ai,authority:Ci,srvr:Ri,reg_name:Ii,query:Qn,SIP_Version:Zn,INVITEm:bi,ACKm:wi,OPTIONSm:Oi,BYEm:Di,CANCELm:Ni,REGISTERm:Ui,SUBSCRIBEm:Pi,NOTIFYm:xi,REFERm:vn,Method:En,Status_Line:ki,Status_Code:Mi,extension_code:Li,Reason_Phrase:Oa,Allow_Events:Du,Call_ID:Nu,Contact:er,contact_param:Bt,name_addr:Gt,display_name:Ws,contact_params:tr,c_p_q:$i,c_p_expires:os,delta_seconds:us,qvalue:Je,generic_param:ze,gen_value:Da,Content_Disposition:Na,disp_type:sr,disp_param:nr,handling_param:Ua,Content_Encoding:Uu,Content_Length:Pu,Content_Type:Pa,media_type:Hi,m_type:Fi,discrete_type:ji,composite_type:Sn,extension_token:yn,x_token:qi,m_subtype:rr,m_parameter:ir,m_value:xa,CSeq:ka,CSeq_value:Ma,Expires:xu,Event:An,event_type:Cn,From:Vi,from_param:Rn,tag_param:Bi,Max_Forwards:ku,Min_Expires:Mu,Name_Addr_Header:Lu,Proxy_Authenticate:Gi,challenge:lr,other_challenge:Ks,auth_param:cs,digest_cln:In,realm:Wi,realm_value:Ki,domain:bn,URI:wn,nonce:Yi,nonce_value:Ji,opaque:zi,stale:Xi,algorithm:Qi,qop_options:On,qop_value:ar,Proxy_Require:$u,Record_Route:or,rec_route:ur,Reason:Zi,reason_param:cr,reason_cause:La,Require:Hu,Route:fr,route_param:hr,Subscription_State:$a,substate_value:dr,subexp_params:_r,event_reason_value:Ha,Subject:Fu,Supported:ju,To:el,to_param:tl,Via:pr,via_param:Ys,via_params:mr,via_ttl:sl,via_maddr:nl,via_received:rl,via_branch:il,response_port:ll,rport:al,sent_protocol:ol,protocol_name:ul,transport:cl,sent_by:fl,via_host:hl,via_port:gr,ttl:dl,WWW_Authenticate:qu,Session_Expires:Fa,s_e_expires:Tr,s_e_params:vr,s_e_refresher:ja,extension_header:qa,header_value:Va,message_body:Vu,uuid_URI:Ba,uuid:Wt,hex4:Kt,hex8:_l,hex12:Ga,Refer_To:Bu,Replaces:Wa,call_id:Er,replaces_param:Sr,to_tag:pl,from_tag:ml,early_flag:Ka};if(o!==void 0){if(s[o]===void 0)throw new Error("Invalid rule name: "+c(o)+".")}else o="CRLF";var r=0,d=0,h=[];function _(e){r<d||(r>d&&(d=r,h=[]),h.push(e))}function g(){var e;return a.substr(r,2)===`\r
|
1
|
+
(function(Nt,Mt){typeof exports=="object"&&typeof module<"u"?Mt(exports):typeof define=="function"&&define.amd?define(["exports"],Mt):(Nt=typeof globalThis<"u"?globalThis:Nt||self,Mt(Nt.OpensipsJS={}))})(this,function(Nt){"use strict";var Jv=Object.defineProperty;var zv=(Nt,Mt,Me)=>Mt in Nt?Jv(Nt,Mt,{enumerable:!0,configurable:!0,writable:!0,value:Me}):Nt[Mt]=Me;var ts=(Nt,Mt,Me)=>(zv(Nt,typeof Mt!="symbol"?Mt+"":Mt,Me),Me);var Mt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Me(c){return c&&c.__esModule&&Object.prototype.hasOwnProperty.call(c,"default")?c.default:c}const vl={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.10.0",homepage:"https://jssip.net",contributors:["José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)","Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.19.6","@babel/preset-env":"^7.19.4","ansi-colors":"^3.2.4",browserify:"^16.5.1",eslint:"^5.16.0","fancy-log":"^1.3.3",gulp:"^4.0.2","gulp-babel":"^8.0.0","gulp-eslint":"^5.0.0","gulp-expect-file":"^1.0.2","gulp-header":"^2.0.9","gulp-nodeunit-runner":"^0.2.2","gulp-plumber":"^1.2.1","gulp-rename":"^1.4.0","gulp-uglify-es":"^1.0.4",pegjs:"^0.7.0","vinyl-buffer":"^1.0.1","vinyl-source-stream":"^2.0.0"},scripts:{lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"}};var Ku=vl,st={USER_AGENT:"".concat(Ku.title," ").concat(Ku.version),SIP:"sip",SIPS:"sips",causes:{CONNECTION_ERROR:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{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",424:"Bad Location Information",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:"JsSIP Internal 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"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2};function El(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?El=function(n){return typeof n}:El=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},El(c)}function Sl(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function yl(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&yr(c,t)}function Cl(c){var t=Yu();return function(){var a=Cr(c),o;if(t){var s=Cr(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return Fh(this,o)}}function Fh(c,t){return t&&(El(t)==="object"||typeof t=="function")?t:jh(c)}function jh(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Dn(c){var t=typeof Map=="function"?new Map:void 0;return Dn=function(a){if(a===null||!qh(a))return a;if(typeof a!="function")throw new TypeError("Super expression must either be null or a function");if(typeof t<"u"){if(t.has(a))return t.get(a);t.set(a,o)}function o(){return Al(a,arguments,Cr(this).constructor)}return o.prototype=Object.create(a.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),yr(o,a)},Dn(c)}function Al(c,t,n){return Yu()?Al=Reflect.construct:Al=function(o,s,r){var d=[null];d.push.apply(d,s);var h=Function.bind.apply(o,d),_=new h;return r&&yr(_,r.prototype),_},Al.apply(null,arguments)}function Yu(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function qh(c){return Function.toString.call(c).indexOf("[native code]")!==-1}function yr(c,t){return yr=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},yr(c,t)}function Cr(c){return Cr=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Cr(c)}var Vh=function(c){yl(n,c);var t=Cl(n);function n(a,o){var s;return Sl(this,n),s=t.call(this),s.code=1,s.name="CONFIGURATION_ERROR",s.parameter=a,s.value=o,s.message=s.value?"Invalid value ".concat(JSON.stringify(s.value),' for parameter "').concat(s.parameter,'"'):"Missing parameter: ".concat(s.parameter),s}return n}(Dn(Error)),Bh=function(c){yl(n,c);var t=Cl(n);function n(a){var o;return Sl(this,n),o=t.call(this),o.code=2,o.name="INVALID_STATE_ERROR",o.status=a,o.message="Invalid status: ".concat(a),o}return n}(Dn(Error)),Gh=function(c){yl(n,c);var t=Cl(n);function n(a){var o;return Sl(this,n),o=t.call(this),o.code=3,o.name="NOT_SUPPORTED_ERROR",o.message=a,o}return n}(Dn(Error)),Wh=function(c){yl(n,c);var t=Cl(n);function n(a){var o;return Sl(this,n),o=t.call(this),o.code=4,o.name="NOT_READY_ERROR",o.message=a,o}return n}(Dn(Error)),Is={ConfigurationError:Vh,InvalidStateError:Bh,NotSupportedError:Gh,NotReadyError:Wh},Qe={},za,Ju;function Xa(){if(Ju)return za;Ju=1;function c(s,r){if(!(s instanceof r))throw new TypeError("Cannot call a class as a function")}function t(s,r){for(var d=0;d<r.length;d++){var h=r[d];h.enumerable=h.enumerable||!1,h.configurable=!0,"value"in h&&(h.writable=!0),Object.defineProperty(s,h.key,h)}}function n(s,r,d){return r&&t(s.prototype,r),d&&t(s,d),s}var a=bs(),o=ss();return za=function(){n(s,null,[{key:"parse",value:function(d){if(d=o.parse(d,"Name_Addr_Header"),d!==-1)return d}}]);function s(r,d,h){if(c(this,s),!r||!(r instanceof a))throw new TypeError('missing or invalid "uri" parameter');this._uri=r,this._parameters={},this.display_name=d;for(var _ in h)Object.prototype.hasOwnProperty.call(h,_)&&this.setParam(_,h[_])}return n(s,[{key:"setParam",value:function(d,h){d&&(this._parameters[d.toLowerCase()]=typeof h>"u"||h===null?null:h.toString())}},{key:"getParam",value:function(d){if(d)return this._parameters[d.toLowerCase()]}},{key:"hasParam",value:function(d){if(d)return this._parameters.hasOwnProperty(d.toLowerCase())&&!0||!1}},{key:"deleteParam",value:function(d){if(d=d.toLowerCase(),this._parameters.hasOwnProperty(d)){var h=this._parameters[d];return delete this._parameters[d],h}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"clone",value:function(){return new s(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}},{key:"_quote",value:function(d){return d.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}},{key:"toString",value:function(){var d=this._display_name?'"'.concat(this._quote(this._display_name),'" '):"";d+="<".concat(this._uri.toString(),">");for(var h in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,h)&&(d+=";".concat(h),this._parameters[h]!==null&&(d+="=".concat(this._parameters[h])));return d}},{key:"uri",get:function(){return this._uri}},{key:"display_name",get:function(){return this._display_name},set:function(d){this._display_name=d===0?"0":d}}]),s}(),za}var Qa,zu;function ss(){return zu||(zu=1,Qa=function(){function c(n){return'"'+n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var t={parse:function(a,o){var s={CRLF:g,DIGIT:T,ALPHA:E,HEXDIG:y,WSP:C,OCTET:A,DQUOTE:I,SP:H,HTAB:$,alphanum:oe,reserved:N,unreserved:j,mark:Se,escaped:ve,LWS:k,SWS:D,HCOLON:B,TEXT_UTF8_TRIM:V,TEXT_UTF8char:J,UTF8_NONASCII:F,UTF8_CONT:Z,LHEX:U,token:P,token_nodot:se,separators:it,word:ee,STAR:Y,SLASH:G,EQUAL:re,LPAREN:ge,RPAREN:be,RAQUOT:ke,LAQUOT:Re,COMMA:le,SEMI:ye,COLON:lt,LDQUOT:ot,RDQUOT:Ee,comment:Ce,ctext:Ie,quoted_string:Oe,quoted_string_clean:pe,qdtext:de,quoted_pair:_e,SIP_URI_noparams:we,SIP_URI:Ne,uri_scheme:tt,uri_scheme_sips:He,uri_scheme_sip:Vt,userinfo:At,user:Bn,user_unreserved:Gn,password:cn,hostport:as,host:Cs,hostname:fn,domainlabel:Wn,toplabel:Kn,IPv6reference:hn,IPv6address:me,h16:ae,ls32:ut,IPv4address:es,dec_octet:$s,port:ui,uri_parameters:Yn,uri_parameter:Jn,transport_param:ci,user_param:fi,method_param:hi,ttl_param:di,maddr_param:_i,lr_param:pi,other_param:mi,pname:gi,pvalue:Hs,paramchar:Fs,param_unreserved:Ti,headers:dn,header:_n,hname:vi,hvalue:js,hnv_unreserved:pn,Request_Response:wa,Request_Line:Ei,Request_URI:zn,absoluteURI:Xn,hier_part:Si,net_path:mn,abs_path:gn,opaque_part:qs,uric:Vs,uric_no_slash:yi,path_segments:Tn,segment:Bs,param:As,pchar:Gs,scheme:Ci,authority:Ai,srvr:Ri,reg_name:Ii,query:Qn,SIP_Version:Zn,INVITEm:bi,ACKm:wi,OPTIONSm:Oi,BYEm:Di,CANCELm:Ni,REGISTERm:Ui,SUBSCRIBEm:Pi,NOTIFYm:xi,REFERm:vn,Method:En,Status_Line:ki,Status_Code:Mi,extension_code:Li,Reason_Phrase:Oa,Allow_Events:Du,Call_ID:Nu,Contact:er,contact_param:Bt,name_addr:Gt,display_name:Ws,contact_params:tr,c_p_q:$i,c_p_expires:os,delta_seconds:us,qvalue:Je,generic_param:ze,gen_value:Da,Content_Disposition:Na,disp_type:sr,disp_param:nr,handling_param:Ua,Content_Encoding:Uu,Content_Length:Pu,Content_Type:Pa,media_type:Hi,m_type:Fi,discrete_type:ji,composite_type:Sn,extension_token:yn,x_token:qi,m_subtype:rr,m_parameter:ir,m_value:xa,CSeq:ka,CSeq_value:Ma,Expires:xu,Event:Cn,event_type:An,From:Vi,from_param:Rn,tag_param:Bi,Max_Forwards:ku,Min_Expires:Mu,Name_Addr_Header:Lu,Proxy_Authenticate:Gi,challenge:lr,other_challenge:Ks,auth_param:cs,digest_cln:In,realm:Wi,realm_value:Ki,domain:bn,URI:wn,nonce:Yi,nonce_value:Ji,opaque:zi,stale:Xi,algorithm:Qi,qop_options:On,qop_value:ar,Proxy_Require:$u,Record_Route:or,rec_route:ur,Reason:Zi,reason_param:cr,reason_cause:La,Require:Hu,Route:fr,route_param:hr,Subscription_State:$a,substate_value:dr,subexp_params:_r,event_reason_value:Ha,Subject:Fu,Supported:ju,To:el,to_param:tl,Via:pr,via_param:Ys,via_params:mr,via_ttl:sl,via_maddr:nl,via_received:rl,via_branch:il,response_port:ll,rport:al,sent_protocol:ol,protocol_name:ul,transport:cl,sent_by:fl,via_host:hl,via_port:gr,ttl:dl,WWW_Authenticate:qu,Session_Expires:Fa,s_e_expires:Tr,s_e_params:vr,s_e_refresher:ja,extension_header:qa,header_value:Va,message_body:Vu,uuid_URI:Ba,uuid:Wt,hex4:Kt,hex8:_l,hex12:Ga,Refer_To:Bu,Replaces:Wa,call_id:Er,replaces_param:Sr,to_tag:pl,from_tag:ml,early_flag:Ka};if(o!==void 0){if(s[o]===void 0)throw new Error("Invalid rule name: "+c(o)+".")}else o="CRLF";var r=0,d=0,h=[];function _(e){r<d||(r>d&&(d=r,h=[]),h.push(e))}function g(){var e;return a.substr(r,2)===`\r
|
2
2
|
`?(e=`\r
|
3
|
-
`,r+=2):(e=null,_('"\\r\\n"')),e}function T(){var e;return/^[0-9]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[0-9]")),e}function E(){var e;return/^[a-zA-Z]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[a-zA-Z]")),e}function y(){var e;return/^[0-9a-fA-F]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[0-9a-fA-F]")),e}function A(){var e;return e=H(),e===null&&(e=$()),e}function C(){var e;return/^[\0-\xFF]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\0-\\xFF]")),e}function I(){var e;return/^["]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_('["]')),e}function H(){var e;return a.charCodeAt(r)===32?(e=" ",r++):(e=null,_('" "')),e}function $(){var e;return a.charCodeAt(r)===9?(e=" ",r++):(e=null,_('"\\t"')),e}function oe(){var e;return/^[a-zA-Z0-9]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[a-zA-Z0-9]")),e}function N(){var e;return a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","'))))))))))),e}function j(){var e;return e=oe(),e===null&&(e=Se()),e}function Se(){var e;return a.charCodeAt(r)===45?(e="-",r++):(e=null,_('"-"')),e===null&&(a.charCodeAt(r)===95?(e="_",r++):(e=null,_('"_"')),e===null&&(a.charCodeAt(r)===46?(e=".",r++):(e=null,_('"."')),e===null&&(a.charCodeAt(r)===33?(e="!",r++):(e=null,_('"!"')),e===null&&(a.charCodeAt(r)===126?(e="~",r++):(e=null,_('"~"')),e===null&&(a.charCodeAt(r)===42?(e="*",r++):(e=null,_('"*"')),e===null&&(a.charCodeAt(r)===39?(e="'",r++):(e=null,_(`"'"`)),e===null&&(a.charCodeAt(r)===40?(e="(",r++):(e=null,_('"("')),e===null&&(a.charCodeAt(r)===41?(e=")",r++):(e=null,_('")"')))))))))),e}function ve(){var e,l,u,f,p;return f=r,p=r,a.charCodeAt(r)===37?(e="%",r++):(e=null,_('"%"')),e!==null?(l=y(),l!==null?(u=y(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){return v.join("")}(f,e)),e===null&&(r=f),e}function k(){var e,l,u,f,p,m;for(f=r,p=r,m=r,e=[],l=A();l!==null;)e.push(l),l=A();if(e!==null?(l=g(),l!==null?e=[e,l]:(e=null,r=m)):(e=null,r=m),e=e!==null?e:"",e!==null){if(u=A(),u!==null)for(l=[];u!==null;)l.push(u),u=A();else l=null;l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e!==null&&(e=function(v){return" "}()),e===null&&(r=f),e}function D(){var e;return e=k(),e=e!==null?e:"",e}function B(){var e,l,u,f,p;for(f=r,p=r,e=[],l=H(),l===null&&(l=$());l!==null;)e.push(l),l=H(),l===null&&(l=$());return e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return":"}()),e===null&&(r=f),e}function V(){var e,l,u,f,p,m,v;if(p=r,m=r,l=J(),l!==null)for(e=[];l!==null;)e.push(l),l=J();else e=null;if(e!==null){for(l=[],v=r,u=[],f=k();f!==null;)u.push(f),f=k();for(u!==null?(f=J(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;){for(l.push(u),v=r,u=[],f=k();f!==null;)u.push(f),f=k();u!==null?(f=J(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v)}l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){return a.substring(r,S)}(p)),e===null&&(r=p),e}function J(){var e;return/^[!-~]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[!-~]")),e===null&&(e=F()),e}function F(){var e;return/^[\x80-\uFFFF]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\x80-\\uFFFF]")),e}function Z(){var e;return/^[\x80-\xBF]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\x80-\\xBF]")),e}function U(){var e;return e=T(),e===null&&(/^[a-f]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[a-f]"))),e}function P(){var e,l,u;if(u=r,l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"'))))))))))));else e=null;return e!==null&&(e=function(f){return a.substring(r,f)}(u)),e===null&&(r=u),e}function se(){var e,l,u;if(u=r,l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"'))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')))))))))));else e=null;return e!==null&&(e=function(f){return a.substring(r,f)}(u)),e===null&&(r=u),e}function it(){var e;return a.charCodeAt(r)===40?(e="(",r++):(e=null,_('"("')),e===null&&(a.charCodeAt(r)===41?(e=")",r++):(e=null,_('")"')),e===null&&(a.charCodeAt(r)===60?(e="<",r++):(e=null,_('"<"')),e===null&&(a.charCodeAt(r)===62?(e=">",r++):(e=null,_('">"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')),e===null&&(a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===92?(e="\\",r++):(e=null,_('"\\\\"')),e===null&&(e=I(),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e===null&&(a.charCodeAt(r)===93?(e="]",r++):(e=null,_('"]"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===123?(e="{",r++):(e=null,_('"{"')),e===null&&(a.charCodeAt(r)===125?(e="}",r++):(e=null,_('"}"')),e===null&&(e=H(),e===null&&(e=$())))))))))))))))))),e}function ee(){var e,l,u;if(u=r,l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')),l===null&&(a.charCodeAt(r)===40?(l="(",r++):(l=null,_('"("')),l===null&&(a.charCodeAt(r)===41?(l=")",r++):(l=null,_('")"')),l===null&&(a.charCodeAt(r)===60?(l="<",r++):(l=null,_('"<"')),l===null&&(a.charCodeAt(r)===62?(l=">",r++):(l=null,_('">"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===92?(l="\\",r++):(l=null,_('"\\\\"')),l===null&&(l=I(),l===null&&(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l===null&&(a.charCodeAt(r)===91?(l="[",r++):(l=null,_('"["')),l===null&&(a.charCodeAt(r)===93?(l="]",r++):(l=null,_('"]"')),l===null&&(a.charCodeAt(r)===63?(l="?",r++):(l=null,_('"?"')),l===null&&(a.charCodeAt(r)===123?(l="{",r++):(l=null,_('"{"')),l===null&&(a.charCodeAt(r)===125?(l="}",r++):(l=null,_('"}"'))))))))))))))))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')),l===null&&(a.charCodeAt(r)===40?(l="(",r++):(l=null,_('"("')),l===null&&(a.charCodeAt(r)===41?(l=")",r++):(l=null,_('")"')),l===null&&(a.charCodeAt(r)===60?(l="<",r++):(l=null,_('"<"')),l===null&&(a.charCodeAt(r)===62?(l=">",r++):(l=null,_('">"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===92?(l="\\",r++):(l=null,_('"\\\\"')),l===null&&(l=I(),l===null&&(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l===null&&(a.charCodeAt(r)===91?(l="[",r++):(l=null,_('"["')),l===null&&(a.charCodeAt(r)===93?(l="]",r++):(l=null,_('"]"')),l===null&&(a.charCodeAt(r)===63?(l="?",r++):(l=null,_('"?"')),l===null&&(a.charCodeAt(r)===123?(l="{",r++):(l=null,_('"{"')),l===null&&(a.charCodeAt(r)===125?(l="}",r++):(l=null,_('"}"')))))))))))))))))))))))));else e=null;return e!==null&&(e=function(f){return a.substring(r,f)}(u)),e===null&&(r=u),e}function Y(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"*"}()),e===null&&(r=f),e}function G(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"/"}()),e===null&&(r=f),e}function re(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"="}()),e===null&&(r=f),e}function ge(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===40?(l="(",r++):(l=null,_('"("')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"("}()),e===null&&(r=f),e}function be(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===41?(l=")",r++):(l=null,_('")"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return")"}()),e===null&&(r=f),e}function ke(){var e,l,u,f;return u=r,f=r,a.charCodeAt(r)===62?(e=">",r++):(e=null,_('">"')),e!==null?(l=D(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return">"}()),e===null&&(r=u),e}function Re(){var e,l,u,f;return u=r,f=r,e=D(),e!==null?(a.charCodeAt(r)===60?(l="<",r++):(l=null,_('"<"')),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return"<"}()),e===null&&(r=u),e}function le(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return","}()),e===null&&(r=f),e}function ye(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return";"}()),e===null&&(r=f),e}function lt(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return":"}()),e===null&&(r=f),e}function ot(){var e,l,u,f;return u=r,f=r,e=D(),e!==null?(l=I(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return'"'}()),e===null&&(r=u),e}function Ee(){var e,l,u,f;return u=r,f=r,e=I(),e!==null?(l=D(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return'"'}()),e===null&&(r=u),e}function Ae(){var e,l,u,f;if(f=r,e=ge(),e!==null){for(l=[],u=Ie(),u===null&&(u=_e(),u===null&&(u=Ae()));u!==null;)l.push(u),u=Ie(),u===null&&(u=_e(),u===null&&(u=Ae()));l!==null?(u=be(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)}else e=null,r=f;return e}function Ie(){var e;return/^[!-']/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[!-']")),e===null&&(/^[*-[]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[*-[]")),e===null&&(/^[\]-~]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\]-~]")),e===null&&(e=F(),e===null&&(e=k())))),e}function Oe(){var e,l,u,f,p,m;if(p=r,m=r,e=D(),e!==null)if(l=I(),l!==null){for(u=[],f=de(),f===null&&(f=_e());f!==null;)u.push(f),f=de(),f===null&&(f=_e());u!==null?(f=I(),f!==null?e=[e,l,u,f]:(e=null,r=m)):(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e!==null&&(e=function(v){return a.substring(r,v)}(p)),e===null&&(r=p),e}function pe(){var e,l,u,f,p,m;if(p=r,m=r,e=D(),e!==null)if(l=I(),l!==null){for(u=[],f=de(),f===null&&(f=_e());f!==null;)u.push(f),f=de(),f===null&&(f=_e());u!==null?(f=I(),f!==null?e=[e,l,u,f]:(e=null,r=m)):(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e!==null&&(e=function(v){var S=a.substring(r,v).trim();return S.substring(1,S.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(p)),e===null&&(r=p),e}function de(){var e;return e=k(),e===null&&(a.charCodeAt(r)===33?(e="!",r++):(e=null,_('"!"')),e===null&&(/^[#-[]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[#-[]")),e===null&&(/^[\]-~]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\]-~]")),e===null&&(e=F())))),e}function _e(){var e,l,u;return u=r,a.charCodeAt(r)===92?(e="\\",r++):(e=null,_('"\\\\"')),e!==null?(/^[\0-\t]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[\\0-\\t]")),l===null&&(/^[\x0B-\f]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[\\x0B-\\f]")),l===null&&(/^[\x0E-]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[\\x0E-]")))),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function we(){var e,l,u,f,p,m;return p=r,m=r,e=tt(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=Ct(),u=u!==null?u:"",u!==null?(f=as(),f!==null?e=[e,l,u,f]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e!==null&&(e=function(v){try{w.uri=new Rs(w.scheme,w.user,w.host,w.port),delete w.scheme,delete w.user,delete w.host,delete w.host_type,delete w.port}catch{w=-1}}()),e===null&&(r=p),e}function Ne(){var e,l,u,f,p,m,v,S;return v=r,S=r,e=tt(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=Ct(),u=u!==null?u:"",u!==null?(f=as(),f!==null?(p=Yn(),p!==null?(m=dn(),m=m!==null?m:"",m!==null?e=[e,l,u,f,p,m]:(e=null,r=S)):(e=null,r=S)):(e=null,r=S)):(e=null,r=S)):(e=null,r=S)):(e=null,r=S),e!==null&&(e=function(O){try{w.uri=new Rs(w.scheme,w.user,w.host,w.port,w.uri_params,w.uri_headers),delete w.scheme,delete w.user,delete w.host,delete w.host_type,delete w.port,delete w.uri_params,o==="SIP_URI"&&(w=w.uri)}catch{w=-1}}()),e===null&&(r=v),e}function tt(){var e;return e=He(),e===null&&(e=Vt()),e}function He(){var e,l;return l=r,a.substr(r,4).toLowerCase()==="sips"?(e=a.substr(r,4),r+=4):(e=null,_('"sips"')),e!==null&&(e=function(u,f){w.scheme=f.toLowerCase()}(l,e)),e===null&&(r=l),e}function Vt(){var e,l;return l=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"sip"')),e!==null&&(e=function(u,f){w.scheme=f.toLowerCase()}(l,e)),e===null&&(r=l),e}function Ct(){var e,l,u,f,p,m;return f=r,p=r,e=Bn(),e!==null?(m=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=cn(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?(a.charCodeAt(r)===64?(u="@",r++):(u=null,_('"@"')),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w.user=decodeURIComponent(a.substring(r-1,v))}(f)),e===null&&(r=f),e}function Bn(){var e,l;if(l=j(),l===null&&(l=ve(),l===null&&(l=Gn())),l!==null)for(e=[];l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(l=Gn()));else e=null;return e}function Gn(){var e;return a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')),e===null&&(a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"'))))))))),e}function cn(){var e,l,u;for(u=r,e=[],l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","'))))))));l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","'))))))));return e!==null&&(e=function(f){w.password=a.substring(r,f)}(u)),e===null&&(r=u),e}function as(){var e,l,u,f,p;return f=r,e=As(),e!==null?(p=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ui(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function As(){var e,l;return l=r,e=fn(),e===null&&(e=es(),e===null&&(e=hn())),e!==null&&(e=function(u){return w.host=a.substring(r,u).toLowerCase(),w.host}(l)),e===null&&(r=l),e}function fn(){var e,l,u,f,p,m;for(f=r,p=r,e=[],m=r,l=Wn(),l!==null?(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m);l!==null;)e.push(l),m=r,l=Wn(),l!==null?(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m);return e!==null?(l=Kn(),l!==null?(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u=u!==null?u:"",u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){return w.host_type="domain",a.substring(r,v)}(f)),e===null&&(r=f),e}function Wn(){var e,l,u,f;if(f=r,e=oe(),e!==null){for(l=[],u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));u!==null;)l.push(u),u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));l!==null?e=[e,l]:(e=null,r=f)}else e=null,r=f;return e}function Kn(){var e,l,u,f;if(f=r,e=E(),e!==null){for(l=[],u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));u!==null;)l.push(u),u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));l!==null?e=[e,l]:(e=null,r=f)}else e=null,r=f;return e}function hn(){var e,l,u,f,p;return f=r,p=r,a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e!==null?(l=me(),l!==null?(a.charCodeAt(r)===93?(u="]",r++):(u=null,_('"]"')),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return w.host_type="IPv6",a.substring(r,m)}(f)),e===null&&(r=f),e}function me(){var e,l,u,f,p,m,v,S,O,ie,Ue,Dt,Js,M,R,Te;return M=r,R=r,e=ae(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?(a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?(a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?(a.charCodeAt(r)===58?(S=":",r++):(S=null,_('":"')),S!==null?(O=ae(),O!==null?(a.charCodeAt(r)===58?(ie=":",r++):(ie=null,_('":"')),ie!==null?(Ue=ae(),Ue!==null?(a.charCodeAt(r)===58?(Dt=":",r++):(Dt=null,_('":"')),Dt!==null?(Js=ut(),Js!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue,Dt,Js]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?(a.charCodeAt(r)===58?(O=":",r++):(O=null,_('":"')),O!==null?(ie=ae(),ie!==null?(a.charCodeAt(r)===58?(Ue=":",r++):(Ue=null,_('":"')),Ue!==null?(Dt=ut(),Dt!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue,Dt]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?(a.charCodeAt(r)===58?(O=":",r++):(O=null,_('":"')),O!==null?(ie=ut(),ie!==null?e=[e,l,u,f,p,m,v,S,O,ie]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ut(),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ut(),m!==null?e=[e,l,u,f,p,m]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ut(),f!==null?e=[e,l,u,f]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ut(),l!==null?e=[e,l]:(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?e=[e,l]:(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(a.substr(r,2)==="::"?(l="::",r+=2):(l=null,_('"::"')),l!==null?(u=ae(),u!==null?(a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?(a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?(a.charCodeAt(r)===58?(S=":",r++):(S=null,_('":"')),S!==null?(O=ae(),O!==null?(a.charCodeAt(r)===58?(ie=":",r++):(ie=null,_('":"')),ie!==null?(Ue=ut(),Ue!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(a.substr(r,2)==="::"?(u="::",r+=2):(u=null,_('"::"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?(a.charCodeAt(r)===58?(O=":",r++):(O=null,_('":"')),O!==null?(ie=ut(),ie!==null?e=[e,l,u,f,p,m,v,S,O,ie]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(a.substr(r,2)==="::"?(f="::",r+=2):(f=null,_('"::"')),f!==null?(p=ae(),p!==null?(a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?(a.charCodeAt(r)===58?(S=":",r++):(S=null,_('":"')),S!==null?(O=ut(),O!==null?e=[e,l,u,f,p,m,v,S,O]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(a.substr(r,2)==="::"?(p="::",r+=2):(p=null,_('"::"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ut(),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(Te=r,a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?p=[p,m]:(p=null,r=Te)):(p=null,r=Te),p=p!==null?p:"",p!==null?(a.substr(r,2)==="::"?(m="::",r+=2):(m=null,_('"::"')),m!==null?(v=ut(),v!==null?e=[e,l,u,f,p,m,v]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(Te=r,a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?p=[p,m]:(p=null,r=Te)):(p=null,r=Te),p=p!==null?p:"",p!==null?(Te=r,a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?m=[m,v]:(m=null,r=Te)):(m=null,r=Te),m=m!==null?m:"",m!==null?(a.substr(r,2)==="::"?(v="::",r+=2):(v=null,_('"::"')),v!==null?(S=ae(),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(Te=r,a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?p=[p,m]:(p=null,r=Te)):(p=null,r=Te),p=p!==null?p:"",p!==null?(Te=r,a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?m=[m,v]:(m=null,r=Te)):(m=null,r=Te),m=m!==null?m:"",m!==null?(Te=r,a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?v=[v,S]:(v=null,r=Te)):(v=null,r=Te),v=v!==null?v:"",v!==null?(a.substr(r,2)==="::"?(S="::",r+=2):(S=null,_('"::"')),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R))))))))))))))),e!==null&&(e=function(Yv){return w.host_type="IPv6",a.substring(r,Yv)}(M)),e===null&&(r=M),e}function ae(){var e,l,u,f,p;return p=r,e=y(),e!==null?(l=y(),l=l!==null?l:"",l!==null?(u=y(),u=u!==null?u:"",u!==null?(f=y(),f=f!==null?f:"",f!==null?e=[e,l,u,f]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e}function ut(){var e,l,u,f;return f=r,e=ae(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e===null&&(e=es()),e}function es(){var e,l,u,f,p,m,v,S,O;return S=r,O=r,e=$s(),e!==null?(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l!==null?(u=$s(),u!==null?(a.charCodeAt(r)===46?(f=".",r++):(f=null,_('"."')),f!==null?(p=$s(),p!==null?(a.charCodeAt(r)===46?(m=".",r++):(m=null,_('"."')),m!==null?(v=$s(),v!==null?e=[e,l,u,f,p,m,v]:(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O),e!==null&&(e=function(ie){return w.host_type="IPv4",a.substring(r,ie)}(S)),e===null&&(r=S),e}function $s(){var e,l,u,f;return f=r,a.substr(r,2)==="25"?(e="25",r+=2):(e=null,_('"25"')),e!==null?(/^[0-5]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[0-5]")),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e===null&&(f=r,a.charCodeAt(r)===50?(e="2",r++):(e=null,_('"2"')),e!==null?(/^[0-4]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[0-4]")),l!==null?(u=T(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e===null&&(f=r,a.charCodeAt(r)===49?(e="1",r++):(e=null,_('"1"')),e!==null?(l=T(),l!==null?(u=T(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e===null&&(f=r,/^[1-9]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[1-9]")),e!==null?(l=T(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e===null&&(e=T())))),e}function ui(){var e,l,u,f,p,m,v;return m=r,v=r,e=T(),e=e!==null?e:"",e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?e=[e,l,u,f,p]:(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(S,O){return O=parseInt(O.join("")),w.port=O,O}(m,e)),e===null&&(r=m),e}function Yn(){var e,l,u,f;for(e=[],f=r,a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l!==null?(u=Jn(),u!==null?l=[l,u]:(l=null,r=f)):(l=null,r=f);l!==null;)e.push(l),f=r,a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l!==null?(u=Jn(),u!==null?l=[l,u]:(l=null,r=f)):(l=null,r=f);return e}function Jn(){var e;return e=ci(),e===null&&(e=fi(),e===null&&(e=hi(),e===null&&(e=di(),e===null&&(e=_i(),e===null&&(e=pi(),e===null&&(e=mi())))))),e}function ci(){var e,l,u,f;return u=r,f=r,a.substr(r,10).toLowerCase()==="transport="?(e=a.substr(r,10),r+=10):(e=null,_('"transport="')),e!==null?(a.substr(r,3).toLowerCase()==="udp"?(l=a.substr(r,3),r+=3):(l=null,_('"udp"')),l===null&&(a.substr(r,3).toLowerCase()==="tcp"?(l=a.substr(r,3),r+=3):(l=null,_('"tcp"')),l===null&&(a.substr(r,4).toLowerCase()==="sctp"?(l=a.substr(r,4),r+=4):(l=null,_('"sctp"')),l===null&&(a.substr(r,3).toLowerCase()==="tls"?(l=a.substr(r,3),r+=3):(l=null,_('"tls"')),l===null&&(l=P())))),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.transport=m.toLowerCase()}(u,e[1])),e===null&&(r=u),e}function fi(){var e,l,u,f;return u=r,f=r,a.substr(r,5).toLowerCase()==="user="?(e=a.substr(r,5),r+=5):(e=null,_('"user="')),e!==null?(a.substr(r,5).toLowerCase()==="phone"?(l=a.substr(r,5),r+=5):(l=null,_('"phone"')),l===null&&(a.substr(r,2).toLowerCase()==="ip"?(l=a.substr(r,2),r+=2):(l=null,_('"ip"')),l===null&&(l=P())),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.user=m.toLowerCase()}(u,e[1])),e===null&&(r=u),e}function hi(){var e,l,u,f;return u=r,f=r,a.substr(r,7).toLowerCase()==="method="?(e=a.substr(r,7),r+=7):(e=null,_('"method="')),e!==null?(l=En(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.method=m}(u,e[1])),e===null&&(r=u),e}function di(){var e,l,u,f;return u=r,f=r,a.substr(r,4).toLowerCase()==="ttl="?(e=a.substr(r,4),r+=4):(e=null,_('"ttl="')),e!==null?(l=dl(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.params||(w.params={}),w.params.ttl=m}(u,e[1])),e===null&&(r=u),e}function _i(){var e,l,u,f;return u=r,f=r,a.substr(r,6).toLowerCase()==="maddr="?(e=a.substr(r,6),r+=6):(e=null,_('"maddr="')),e!==null?(l=As(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.maddr=m}(u,e[1])),e===null&&(r=u),e}function pi(){var e,l,u,f,p,m;return f=r,p=r,a.substr(r,2).toLowerCase()==="lr"?(e=a.substr(r,2),r+=2):(e=null,_('"lr"')),e!==null?(m=r,a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=P(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w.uri_params||(w.uri_params={}),w.uri_params.lr=void 0}()),e===null&&(r=f),e}function mi(){var e,l,u,f,p,m;return f=r,p=r,e=gi(),e!==null?(m=r,a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=Hs(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v,S,O){w.uri_params||(w.uri_params={}),typeof O>"u"?O=void 0:O=O[1],w.uri_params[S.toLowerCase()]=O}(f,e[0],e[1])),e===null&&(r=f),e}function gi(){var e,l,u;if(u=r,l=Fs(),l!==null)for(e=[];l!==null;)e.push(l),l=Fs();else e=null;return e!==null&&(e=function(f,p){return p.join("")}(u,e)),e===null&&(r=u),e}function Hs(){var e,l,u;if(u=r,l=Fs(),l!==null)for(e=[];l!==null;)e.push(l),l=Fs();else e=null;return e!==null&&(e=function(f,p){return p.join("")}(u,e)),e===null&&(r=u),e}function Fs(){var e;return e=Ti(),e===null&&(e=j(),e===null&&(e=ve())),e}function Ti(){var e;return a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e===null&&(a.charCodeAt(r)===93?(e="]",r++):(e=null,_('"]"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')))))))),e}function dn(){var e,l,u,f,p,m,v;if(m=r,a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e!==null)if(l=_n(),l!==null){for(u=[],v=r,a.charCodeAt(r)===38?(f="&",r++):(f=null,_('"&"')),f!==null?(p=_n(),p!==null?f=[f,p]:(f=null,r=v)):(f=null,r=v);f!==null;)u.push(f),v=r,a.charCodeAt(r)===38?(f="&",r++):(f=null,_('"&"')),f!==null?(p=_n(),p!==null?f=[f,p]:(f=null,r=v)):(f=null,r=v);u!==null?e=[e,l,u]:(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e}function _n(){var e,l,u,f,p;return f=r,p=r,e=vi(),e!==null?(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=js(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v,S){v=v.join("").toLowerCase(),S=S.join(""),w.uri_headers||(w.uri_headers={}),w.uri_headers[v]?w.uri_headers[v].push(S):w.uri_headers[v]=[S]}(f,e[0],e[2])),e===null&&(r=f),e}function vi(){var e,l;if(l=pn(),l===null&&(l=j(),l===null&&(l=ve())),l!==null)for(e=[];l!==null;)e.push(l),l=pn(),l===null&&(l=j(),l===null&&(l=ve()));else e=null;return e}function js(){var e,l;for(e=[],l=pn(),l===null&&(l=j(),l===null&&(l=ve()));l!==null;)e.push(l),l=pn(),l===null&&(l=j(),l===null&&(l=ve()));return e}function pn(){var e;return a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e===null&&(a.charCodeAt(r)===93?(e="]",r++):(e=null,_('"]"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')))))))),e}function wa(){var e;return e=ki(),e===null&&(e=Ei()),e}function Ei(){var e,l,u,f,p,m;return m=r,e=En(),e!==null?(l=H(),l!==null?(u=zn(),u!==null?(f=H(),f!==null?(p=Zn(),p!==null?e=[e,l,u,f,p]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e}function zn(){var e;return e=Ne(),e===null&&(e=Xn()),e}function Xn(){var e,l,u,f;return f=r,e=Ai(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=Si(),u===null&&(u=qs()),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Si(){var e,l,u,f,p;return f=r,e=mn(),e===null&&(e=gn()),e!==null?(p=r,a.charCodeAt(r)===63?(l="?",r++):(l=null,_('"?"')),l!==null?(u=Qn(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function mn(){var e,l,u,f;return f=r,a.substr(r,2)==="//"?(e="//",r+=2):(e=null,_('"//"')),e!==null?(l=Ci(),l!==null?(u=gn(),u=u!==null?u:"",u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function gn(){var e,l,u;return u=r,a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e!==null?(l=Tn(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function qs(){var e,l,u,f;if(f=r,e=yi(),e!==null){for(l=[],u=Vs();u!==null;)l.push(u),u=Vs();l!==null?e=[e,l]:(e=null,r=f)}else e=null,r=f;return e}function Vs(){var e;return e=N(),e===null&&(e=j(),e===null&&(e=ve())),e}function yi(){var e;return e=j(),e===null&&(e=ve(),e===null&&(a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')))))))))))),e}function Tn(){var e,l,u,f,p,m;if(p=r,e=Bs(),e!==null){for(l=[],m=r,a.charCodeAt(r)===47?(u="/",r++):(u=null,_('"/"')),u!==null?(f=Bs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,a.charCodeAt(r)===47?(u="/",r++):(u=null,_('"/"')),u!==null?(f=Bs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Bs(){var e,l,u,f,p,m;for(p=r,e=[],l=Gs();l!==null;)e.push(l),l=Gs();if(e!==null){for(l=[],m=r,a.charCodeAt(r)===59?(u=";",r++):(u=null,_('";"')),u!==null?(f=Cs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,a.charCodeAt(r)===59?(u=";",r++):(u=null,_('";"')),u!==null?(f=Cs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Cs(){var e,l;for(e=[],l=Gs();l!==null;)e.push(l),l=Gs();return e}function Gs(){var e;return e=j(),e===null&&(e=ve(),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')))))))))),e}function Ai(){var e,l,u,f,p;if(f=r,p=r,e=E(),e!==null){for(l=[],u=E(),u===null&&(u=T(),u===null&&(a.charCodeAt(r)===43?(u="+",r++):(u=null,_('"+"')),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."'))))));u!==null;)l.push(u),u=E(),u===null&&(u=T(),u===null&&(a.charCodeAt(r)===43?(u="+",r++):(u=null,_('"+"')),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."'))))));l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e!==null&&(e=function(m){w.scheme=a.substring(r,m)}(f)),e===null&&(r=f),e}function Ci(){var e;return e=Ri(),e===null&&(e=Ii()),e}function Ri(){var e,l,u,f;return u=r,f=r,e=Ct(),e!==null?(a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e=e!==null?e:"",e!==null?(l=as(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e=e!==null?e:"",e}function Ii(){var e,l;if(l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","')),l===null&&(a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"'))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","')),l===null&&(a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')))))))))));else e=null;return e}function Qn(){var e,l;for(e=[],l=Vs();l!==null;)e.push(l),l=Vs();return e}function Zn(){var e,l,u,f,p,m,v,S;if(v=r,S=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"SIP"')),e!==null)if(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l!==null){if(f=T(),f!==null)for(u=[];f!==null;)u.push(f),f=T();else u=null;if(u!==null)if(a.charCodeAt(r)===46?(f=".",r++):(f=null,_('"."')),f!==null){if(m=T(),m!==null)for(p=[];m!==null;)p.push(m),m=T();else p=null;p!==null?e=[e,l,u,f,p]:(e=null,r=S)}else e=null,r=S;else e=null,r=S}else e=null,r=S;else e=null,r=S;return e!==null&&(e=function(O){w.sip_version=a.substring(r,O)}(v)),e===null&&(r=v),e}function bi(){var e;return a.substr(r,6)==="INVITE"?(e="INVITE",r+=6):(e=null,_('"INVITE"')),e}function wi(){var e;return a.substr(r,3)==="ACK"?(e="ACK",r+=3):(e=null,_('"ACK"')),e}function Oi(){var e;return a.substr(r,7)==="OPTIONS"?(e="OPTIONS",r+=7):(e=null,_('"OPTIONS"')),e}function Di(){var e;return a.substr(r,3)==="BYE"?(e="BYE",r+=3):(e=null,_('"BYE"')),e}function Ni(){var e;return a.substr(r,6)==="CANCEL"?(e="CANCEL",r+=6):(e=null,_('"CANCEL"')),e}function Ui(){var e;return a.substr(r,8)==="REGISTER"?(e="REGISTER",r+=8):(e=null,_('"REGISTER"')),e}function Pi(){var e;return a.substr(r,9)==="SUBSCRIBE"?(e="SUBSCRIBE",r+=9):(e=null,_('"SUBSCRIBE"')),e}function xi(){var e;return a.substr(r,6)==="NOTIFY"?(e="NOTIFY",r+=6):(e=null,_('"NOTIFY"')),e}function vn(){var e;return a.substr(r,5)==="REFER"?(e="REFER",r+=5):(e=null,_('"REFER"')),e}function En(){var e,l;return l=r,e=bi(),e===null&&(e=wi(),e===null&&(e=Oi(),e===null&&(e=Di(),e===null&&(e=Ni(),e===null&&(e=Ui(),e===null&&(e=Pi(),e===null&&(e=xi(),e===null&&(e=vn(),e===null&&(e=P()))))))))),e!==null&&(e=function(u){return w.method=a.substring(r,u),w.method}(l)),e===null&&(r=l),e}function ki(){var e,l,u,f,p,m;return m=r,e=Zn(),e!==null?(l=H(),l!==null?(u=Mi(),u!==null?(f=H(),f!==null?(p=Oa(),p!==null?e=[e,l,u,f,p]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e}function Mi(){var e,l;return l=r,e=Li(),e!==null&&(e=function(u,f){w.status_code=parseInt(f.join(""))}(l,e)),e===null&&(r=l),e}function Li(){var e,l,u,f;return f=r,e=T(),e!==null?(l=T(),l!==null?(u=T(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Oa(){var e,l,u;for(u=r,e=[],l=N(),l===null&&(l=j(),l===null&&(l=ve(),l===null&&(l=F(),l===null&&(l=Z(),l===null&&(l=H(),l===null&&(l=$()))))));l!==null;)e.push(l),l=N(),l===null&&(l=j(),l===null&&(l=ve(),l===null&&(l=F(),l===null&&(l=Z(),l===null&&(l=H(),l===null&&(l=$()))))));return e!==null&&(e=function(f){w.reason_phrase=a.substring(r,f)}(u)),e===null&&(r=u),e}function Du(){var e,l,u,f,p,m;if(p=r,e=Cn(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=Cn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=Cn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Nu(){var e,l,u,f,p,m;return f=r,p=r,e=ee(),e!==null?(m=r,a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l!==null?(u=ee(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w=a.substring(r,v)}(f)),e===null&&(r=f),e}function er(){var e,l,u,f,p,m,v;if(p=r,e=Y(),e===null)if(m=r,e=Bt(),e!==null){for(l=[],v=r,u=le(),u!==null?(f=Bt(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=le(),u!==null?(f=Bt(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O,ie;for(ie=w.multi_header.length,O=0;O<ie;O++)if(w.multi_header[O].parsed===null){w=null;break}w!==null?w=w.multi_header:w=-1}()),e===null&&(r=p),e}function Bt(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Gt()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=tr(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=tr(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O;w.multi_header||(w.multi_header=[]);try{O=new b(w.uri,w.display_name,w.params),delete w.uri,delete w.display_name,delete w.params}catch{O=null}w.multi_header.push({possition:r,offset:S,parsed:O})}(p)),e===null&&(r=p),e}function Gt(){var e,l,u,f,p;return p=r,e=Ws(),e=e!==null?e:"",e!==null?(l=Re(),l!==null?(u=Ne(),u!==null?(f=ke(),f!==null?e=[e,l,u,f]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e}function Ws(){var e,l,u,f,p,m,v;if(p=r,m=r,e=P(),e!==null){for(l=[],v=r,u=k(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=k(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e===null&&(e=pe()),e!==null&&(e=function(S,O){typeof O=="string"?w.display_name=O:w.display_name=O[1].reduce(function(ie,Ue){return ie+Ue[0]+Ue[1]},O[0])}(p,e)),e===null&&(r=p),e}function tr(){var e;return e=$i(),e===null&&(e=os(),e===null&&(e=ze())),e}function $i(){var e,l,u,f,p;return f=r,p=r,a.substr(r,1).toLowerCase()==="q"?(e=a.substr(r,1),r++):(e=null,_('"q"')),e!==null?(l=re(),l!==null?(u=Je(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.params||(w.params={}),w.params.q=v}(f,e[2])),e===null&&(r=f),e}function os(){var e,l,u,f,p;return f=r,p=r,a.substr(r,7).toLowerCase()==="expires"?(e=a.substr(r,7),r+=7):(e=null,_('"expires"')),e!==null?(l=re(),l!==null?(u=us(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.params||(w.params={}),w.params.expires=v}(f,e[2])),e===null&&(r=f),e}function us(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){return parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function Je(){var e,l,u,f,p,m,v,S;return m=r,v=r,a.charCodeAt(r)===48?(e="0",r++):(e=null,_('"0"')),e!==null?(S=r,a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?l=[l,u,f,p]:(l=null,r=S)):(l=null,r=S)):(l=null,r=S)):(l=null,r=S),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(O){return parseFloat(a.substring(r,O))}(m)),e===null&&(r=m),e}function ze(){var e,l,u,f,p,m;return f=r,p=r,e=P(),e!==null?(m=r,l=re(),l!==null?(u=Da(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v,S,O){w.params||(w.params={}),typeof O>"u"?O=void 0:O=O[1],w.params[S.toLowerCase()]=O}(f,e[0],e[1])),e===null&&(r=f),e}function Da(){var e;return e=P(),e===null&&(e=As(),e===null&&(e=Oe())),e}function Na(){var e,l,u,f,p,m;if(p=r,e=sr(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=nr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=nr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function sr(){var e;return a.substr(r,6).toLowerCase()==="render"?(e=a.substr(r,6),r+=6):(e=null,_('"render"')),e===null&&(a.substr(r,7).toLowerCase()==="session"?(e=a.substr(r,7),r+=7):(e=null,_('"session"')),e===null&&(a.substr(r,4).toLowerCase()==="icon"?(e=a.substr(r,4),r+=4):(e=null,_('"icon"')),e===null&&(a.substr(r,5).toLowerCase()==="alert"?(e=a.substr(r,5),r+=5):(e=null,_('"alert"')),e===null&&(e=P())))),e}function nr(){var e;return e=Ua(),e===null&&(e=ze()),e}function Ua(){var e,l,u,f;return f=r,a.substr(r,8).toLowerCase()==="handling"?(e=a.substr(r,8),r+=8):(e=null,_('"handling"')),e!==null?(l=re(),l!==null?(a.substr(r,8).toLowerCase()==="optional"?(u=a.substr(r,8),r+=8):(u=null,_('"optional"')),u===null&&(a.substr(r,8).toLowerCase()==="required"?(u=a.substr(r,8),r+=8):(u=null,_('"required"')),u===null&&(u=P())),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Uu(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Pu(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){w=parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function Pa(){var e,l;return l=r,e=Hi(),e!==null&&(e=function(u){w=a.substring(r,u)}(l)),e===null&&(r=l),e}function Hi(){var e,l,u,f,p,m,v,S;if(v=r,e=Fi(),e!==null)if(l=G(),l!==null)if(u=rr(),u!==null){for(f=[],S=r,p=ye(),p!==null?(m=ir(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=ye(),p!==null?(m=ir(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e}function Fi(){var e;return e=ji(),e===null&&(e=Sn()),e}function ji(){var e;return a.substr(r,4).toLowerCase()==="text"?(e=a.substr(r,4),r+=4):(e=null,_('"text"')),e===null&&(a.substr(r,5).toLowerCase()==="image"?(e=a.substr(r,5),r+=5):(e=null,_('"image"')),e===null&&(a.substr(r,5).toLowerCase()==="audio"?(e=a.substr(r,5),r+=5):(e=null,_('"audio"')),e===null&&(a.substr(r,5).toLowerCase()==="video"?(e=a.substr(r,5),r+=5):(e=null,_('"video"')),e===null&&(a.substr(r,11).toLowerCase()==="application"?(e=a.substr(r,11),r+=11):(e=null,_('"application"')),e===null&&(e=yn()))))),e}function Sn(){var e;return a.substr(r,7).toLowerCase()==="message"?(e=a.substr(r,7),r+=7):(e=null,_('"message"')),e===null&&(a.substr(r,9).toLowerCase()==="multipart"?(e=a.substr(r,9),r+=9):(e=null,_('"multipart"')),e===null&&(e=yn())),e}function yn(){var e;return e=P(),e===null&&(e=qi()),e}function qi(){var e,l,u;return u=r,a.substr(r,2).toLowerCase()==="x-"?(e=a.substr(r,2),r+=2):(e=null,_('"x-"')),e!==null?(l=P(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function rr(){var e;return e=yn(),e===null&&(e=P()),e}function ir(){var e,l,u,f;return f=r,e=P(),e!==null?(l=re(),l!==null?(u=xa(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function xa(){var e;return e=P(),e===null&&(e=Oe()),e}function ka(){var e,l,u,f;return f=r,e=Ma(),e!==null?(l=k(),l!==null?(u=En(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Ma(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){w.value=parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function xu(){var e,l;return l=r,e=us(),e!==null&&(e=function(u,f){w=f}(l,e)),e===null&&(r=l),e}function An(){var e,l,u,f,p,m,v;if(p=r,m=r,e=Cn(),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=ze(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=ze(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S,O){w.event=O.join("").toLowerCase()}(p,e[0])),e===null&&(r=p),e}function Cn(){var e,l,u,f,p,m;if(p=r,e=se(),e!==null){for(l=[],m=r,a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?(f=se(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?(f=se(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Vi(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Gt()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=Rn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=Rn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O=w.tag;try{w=new b(w.uri,w.display_name,w.params),O&&w.setParam("tag",O)}catch{w=-1}}()),e===null&&(r=p),e}function Rn(){var e;return e=Bi(),e===null&&(e=ze()),e}function Bi(){var e,l,u,f,p;return f=r,p=r,a.substr(r,3).toLowerCase()==="tag"?(e=a.substr(r,3),r+=3):(e=null,_('"tag"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.tag=v}(f,e[2])),e===null&&(r=f),e}function ku(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){w=parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function Mu(){var e,l;return l=r,e=us(),e!==null&&(e=function(u,f){w=f}(l,e)),e===null&&(r=l),e}function Lu(){var e,l,u,f,p,m,v,S,O,ie;for(S=r,O=r,e=[],l=Ws();l!==null;)e.push(l),l=Ws();if(e!==null)if(l=Re(),l!==null)if(u=Ne(),u!==null)if(f=ke(),f!==null){for(p=[],ie=r,m=ye(),m!==null?(v=ze(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);m!==null;)p.push(m),ie=r,m=ye(),m!==null?(v=ze(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);p!==null?e=[e,l,u,f,p]:(e=null,r=O)}else e=null,r=O;else e=null,r=O;else e=null,r=O;else e=null,r=O;return e!==null&&(e=function(Ue){try{w=new b(w.uri,w.display_name,w.params)}catch{w=-1}}()),e===null&&(r=S),e}function Gi(){var e;return e=lr(),e}function lr(){var e,l,u,f,p,m,v,S;if(v=r,a.substr(r,6).toLowerCase()==="digest"?(e=a.substr(r,6),r+=6):(e=null,_('"Digest"')),e!==null)if(l=k(),l!==null)if(u=In(),u!==null){for(f=[],S=r,p=le(),p!==null?(m=In(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=le(),p!==null?(m=In(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e===null&&(e=Ks()),e}function Ks(){var e,l,u,f,p,m,v,S;if(v=r,e=P(),e!==null)if(l=k(),l!==null)if(u=cs(),u!==null){for(f=[],S=r,p=le(),p!==null?(m=cs(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=le(),p!==null?(m=cs(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e}function cs(){var e,l,u,f;return f=r,e=P(),e!==null?(l=re(),l!==null?(u=P(),u===null&&(u=Oe()),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function In(){var e;return e=Wi(),e===null&&(e=bn(),e===null&&(e=Yi(),e===null&&(e=zi(),e===null&&(e=Xi(),e===null&&(e=Qi(),e===null&&(e=On(),e===null&&(e=cs()))))))),e}function Wi(){var e,l,u,f;return f=r,a.substr(r,5).toLowerCase()==="realm"?(e=a.substr(r,5),r+=5):(e=null,_('"realm"')),e!==null?(l=re(),l!==null?(u=Ki(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Ki(){var e,l;return l=r,e=pe(),e!==null&&(e=function(u,f){w.realm=f}(l,e)),e===null&&(r=l),e}function bn(){var e,l,u,f,p,m,v,S,O;if(S=r,a.substr(r,6).toLowerCase()==="domain"?(e=a.substr(r,6),r+=6):(e=null,_('"domain"')),e!==null)if(l=re(),l!==null)if(u=ot(),u!==null)if(f=wn(),f!==null){if(p=[],O=r,v=H(),v!==null)for(m=[];v!==null;)m.push(v),v=H();else m=null;for(m!==null?(v=wn(),v!==null?m=[m,v]:(m=null,r=O)):(m=null,r=O);m!==null;){if(p.push(m),O=r,v=H(),v!==null)for(m=[];v!==null;)m.push(v),v=H();else m=null;m!==null?(v=wn(),v!==null?m=[m,v]:(m=null,r=O)):(m=null,r=O)}p!==null?(m=Ee(),m!==null?e=[e,l,u,f,p,m]:(e=null,r=S)):(e=null,r=S)}else e=null,r=S;else e=null,r=S;else e=null,r=S;else e=null,r=S;return e}function wn(){var e;return e=Xn(),e===null&&(e=gn()),e}function Yi(){var e,l,u,f;return f=r,a.substr(r,5).toLowerCase()==="nonce"?(e=a.substr(r,5),r+=5):(e=null,_('"nonce"')),e!==null?(l=re(),l!==null?(u=Ji(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Ji(){var e,l;return l=r,e=pe(),e!==null&&(e=function(u,f){w.nonce=f}(l,e)),e===null&&(r=l),e}function zi(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6).toLowerCase()==="opaque"?(e=a.substr(r,6),r+=6):(e=null,_('"opaque"')),e!==null?(l=re(),l!==null?(u=pe(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.opaque=v}(f,e[2])),e===null&&(r=f),e}function Xi(){var e,l,u,f,p;return f=r,a.substr(r,5).toLowerCase()==="stale"?(e=a.substr(r,5),r+=5):(e=null,_('"stale"')),e!==null?(l=re(),l!==null?(p=r,a.substr(r,4).toLowerCase()==="true"?(u=a.substr(r,4),r+=4):(u=null,_('"true"')),u!==null&&(u=function(m){w.stale=!0}()),u===null&&(r=p),u===null&&(p=r,a.substr(r,5).toLowerCase()==="false"?(u=a.substr(r,5),r+=5):(u=null,_('"false"')),u!==null&&(u=function(m){w.stale=!1}()),u===null&&(r=p)),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Qi(){var e,l,u,f,p;return f=r,p=r,a.substr(r,9).toLowerCase()==="algorithm"?(e=a.substr(r,9),r+=9):(e=null,_('"algorithm"')),e!==null?(l=re(),l!==null?(a.substr(r,3).toLowerCase()==="md5"?(u=a.substr(r,3),r+=3):(u=null,_('"MD5"')),u===null&&(a.substr(r,8).toLowerCase()==="md5-sess"?(u=a.substr(r,8),r+=8):(u=null,_('"MD5-sess"')),u===null&&(u=P())),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.algorithm=v.toUpperCase()}(f,e[2])),e===null&&(r=f),e}function On(){var e,l,u,f,p,m,v,S,O,ie;if(S=r,a.substr(r,3).toLowerCase()==="qop"?(e=a.substr(r,3),r+=3):(e=null,_('"qop"')),e!==null)if(l=re(),l!==null)if(u=ot(),u!==null){if(O=r,f=ar(),f!==null){for(p=[],ie=r,a.charCodeAt(r)===44?(m=",",r++):(m=null,_('","')),m!==null?(v=ar(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);m!==null;)p.push(m),ie=r,a.charCodeAt(r)===44?(m=",",r++):(m=null,_('","')),m!==null?(v=ar(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);p!==null?f=[f,p]:(f=null,r=O)}else f=null,r=O;f!==null?(p=Ee(),p!==null?e=[e,l,u,f,p]:(e=null,r=S)):(e=null,r=S)}else e=null,r=S;else e=null,r=S;else e=null,r=S;return e}function ar(){var e,l;return l=r,a.substr(r,8).toLowerCase()==="auth-int"?(e=a.substr(r,8),r+=8):(e=null,_('"auth-int"')),e===null&&(a.substr(r,4).toLowerCase()==="auth"?(e=a.substr(r,4),r+=4):(e=null,_('"auth"')),e===null&&(e=P())),e!==null&&(e=function(u,f){w.qop||(w.qop=[]),w.qop.push(f.toLowerCase())}(l,e)),e===null&&(r=l),e}function $u(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function or(){var e,l,u,f,p,m,v;if(p=r,m=r,e=ur(),e!==null){for(l=[],v=r,u=le(),u!==null?(f=ur(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=le(),u!==null?(f=ur(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O,ie;for(ie=w.multi_header.length,O=0;O<ie;O++)if(w.multi_header[O].parsed===null){w=null;break}w!==null?w=w.multi_header:w=-1}()),e===null&&(r=p),e}function ur(){var e,l,u,f,p,m,v;if(p=r,m=r,e=Gt(),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=ze(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=ze(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O;w.multi_header||(w.multi_header=[]);try{O=new b(w.uri,w.display_name,w.params),delete w.uri,delete w.display_name,delete w.params}catch{O=null}w.multi_header.push({possition:r,offset:S,parsed:O})}(p)),e===null&&(r=p),e}function Zi(){var e,l,u,f,p,m,v;if(p=r,m=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"SIP"')),e===null&&(e=P()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=cr(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=cr(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S,O){if(w.protocol=O.toLowerCase(),w.params||(w.params={}),w.params.text&&w.params.text[0]==='"'){var ie=w.params.text;w.text=ie.substring(1,ie.length-1),delete w.params.text}}(p,e[0])),e===null&&(r=p),e}function cr(){var e;return e=La(),e===null&&(e=ze()),e}function La(){var e,l,u,f,p,m;if(p=r,m=r,a.substr(r,5).toLowerCase()==="cause"?(e=a.substr(r,5),r+=5):(e=null,_('"cause"')),e!==null)if(l=re(),l!==null){if(f=T(),f!==null)for(u=[];f!==null;)u.push(f),f=T();else u=null;u!==null?e=[e,l,u]:(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e!==null&&(e=function(v,S){w.cause=parseInt(S.join(""))}(p,e[2])),e===null&&(r=p),e}function Hu(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function fr(){var e,l,u,f,p,m;if(p=r,e=hr(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=hr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=hr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function hr(){var e,l,u,f,p,m;if(p=r,e=Gt(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=ze(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=ze(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function $a(){var e,l,u,f,p,m;if(p=r,e=dr(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=_r(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=_r(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function dr(){var e,l;return l=r,a.substr(r,6).toLowerCase()==="active"?(e=a.substr(r,6),r+=6):(e=null,_('"active"')),e===null&&(a.substr(r,7).toLowerCase()==="pending"?(e=a.substr(r,7),r+=7):(e=null,_('"pending"')),e===null&&(a.substr(r,10).toLowerCase()==="terminated"?(e=a.substr(r,10),r+=10):(e=null,_('"terminated"')),e===null&&(e=P()))),e!==null&&(e=function(u){w.state=a.substring(r,u)}(l)),e===null&&(r=l),e}function _r(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6).toLowerCase()==="reason"?(e=a.substr(r,6),r+=6):(e=null,_('"reason"')),e!==null?(l=re(),l!==null?(u=Ha(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){typeof v<"u"&&(w.reason=v)}(f,e[2])),e===null&&(r=f),e===null&&(f=r,p=r,a.substr(r,7).toLowerCase()==="expires"?(e=a.substr(r,7),r+=7):(e=null,_('"expires"')),e!==null?(l=re(),l!==null?(u=us(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){typeof v<"u"&&(w.expires=v)}(f,e[2])),e===null&&(r=f),e===null&&(f=r,p=r,a.substr(r,11).toLowerCase()==="retry_after"?(e=a.substr(r,11),r+=11):(e=null,_('"retry_after"')),e!==null?(l=re(),l!==null?(u=us(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){typeof v<"u"&&(w.retry_after=v)}(f,e[2])),e===null&&(r=f),e===null&&(e=ze()))),e}function Ha(){var e;return a.substr(r,11).toLowerCase()==="deactivated"?(e=a.substr(r,11),r+=11):(e=null,_('"deactivated"')),e===null&&(a.substr(r,9).toLowerCase()==="probation"?(e=a.substr(r,9),r+=9):(e=null,_('"probation"')),e===null&&(a.substr(r,8).toLowerCase()==="rejected"?(e=a.substr(r,8),r+=8):(e=null,_('"rejected"')),e===null&&(a.substr(r,7).toLowerCase()==="timeout"?(e=a.substr(r,7),r+=7):(e=null,_('"timeout"')),e===null&&(a.substr(r,6).toLowerCase()==="giveup"?(e=a.substr(r,6),r+=6):(e=null,_('"giveup"')),e===null&&(a.substr(r,10).toLowerCase()==="noresource"?(e=a.substr(r,10),r+=10):(e=null,_('"noresource"')),e===null&&(a.substr(r,9).toLowerCase()==="invariant"?(e=a.substr(r,9),r+=9):(e=null,_('"invariant"')),e===null&&(e=P()))))))),e}function Fu(){var e;return e=V(),e=e!==null?e:"",e}function ju(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e=e!==null?e:"",e}function el(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Gt()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=tl(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=tl(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O=w.tag;try{w=new b(w.uri,w.display_name,w.params),O&&w.setParam("tag",O)}catch{w=-1}}()),e===null&&(r=p),e}function tl(){var e;return e=Bi(),e===null&&(e=ze()),e}function pr(){var e,l,u,f,p,m;if(p=r,e=Ys(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=Ys(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=Ys(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Ys(){var e,l,u,f,p,m,v,S;if(v=r,e=ol(),e!==null)if(l=k(),l!==null)if(u=fl(),u!==null){for(f=[],S=r,p=ye(),p!==null?(m=mr(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=ye(),p!==null?(m=mr(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e}function mr(){var e;return e=sl(),e===null&&(e=nl(),e===null&&(e=rl(),e===null&&(e=il(),e===null&&(e=ll(),e===null&&(e=ze()))))),e}function sl(){var e,l,u,f,p;return f=r,p=r,a.substr(r,3).toLowerCase()==="ttl"?(e=a.substr(r,3),r+=3):(e=null,_('"ttl"')),e!==null?(l=re(),l!==null?(u=dl(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.ttl=v}(f,e[2])),e===null&&(r=f),e}function nl(){var e,l,u,f,p;return f=r,p=r,a.substr(r,5).toLowerCase()==="maddr"?(e=a.substr(r,5),r+=5):(e=null,_('"maddr"')),e!==null?(l=re(),l!==null?(u=As(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.maddr=v}(f,e[2])),e===null&&(r=f),e}function rl(){var e,l,u,f,p;return f=r,p=r,a.substr(r,8).toLowerCase()==="received"?(e=a.substr(r,8),r+=8):(e=null,_('"received"')),e!==null?(l=re(),l!==null?(u=es(),u===null&&(u=me()),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.received=v}(f,e[2])),e===null&&(r=f),e}function il(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6).toLowerCase()==="branch"?(e=a.substr(r,6),r+=6):(e=null,_('"branch"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.branch=v}(f,e[2])),e===null&&(r=f),e}function ll(){var e,l,u,f,p;return f=r,a.substr(r,5).toLowerCase()==="rport"?(e=a.substr(r,5),r+=5):(e=null,_('"rport"')),e!==null?(p=r,l=re(),l!==null?(u=al(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function al(){var e,l,u,f,p,m,v;return m=r,v=r,e=T(),e=e!==null?e:"",e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?e=[e,l,u,f,p]:(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(S,O){w.rport=parseInt(O.join(""))}(m,e)),e===null&&(r=m),e}function ol(){var e,l,u,f,p,m;return m=r,e=ul(),e!==null?(l=G(),l!==null?(u=P(),u!==null?(f=G(),f!==null?(p=cl(),p!==null?e=[e,l,u,f,p]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e}function ul(){var e,l;return l=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"SIP"')),e===null&&(e=P()),e!==null&&(e=function(u,f){w.protocol=f}(l,e)),e===null&&(r=l),e}function cl(){var e,l;return l=r,a.substr(r,3).toLowerCase()==="udp"?(e=a.substr(r,3),r+=3):(e=null,_('"UDP"')),e===null&&(a.substr(r,3).toLowerCase()==="tcp"?(e=a.substr(r,3),r+=3):(e=null,_('"TCP"')),e===null&&(a.substr(r,3).toLowerCase()==="tls"?(e=a.substr(r,3),r+=3):(e=null,_('"TLS"')),e===null&&(a.substr(r,4).toLowerCase()==="sctp"?(e=a.substr(r,4),r+=4):(e=null,_('"SCTP"')),e===null&&(e=P())))),e!==null&&(e=function(u,f){w.transport=f}(l,e)),e===null&&(r=l),e}function fl(){var e,l,u,f,p;return f=r,e=hl(),e!==null?(p=r,l=lt(),l!==null?(u=gr(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function hl(){var e,l;return l=r,e=es(),e===null&&(e=hn(),e===null&&(e=fn())),e!==null&&(e=function(u){w.host=a.substring(r,u)}(l)),e===null&&(r=l),e}function gr(){var e,l,u,f,p,m,v;return m=r,v=r,e=T(),e=e!==null?e:"",e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?e=[e,l,u,f,p]:(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(S,O){w.port=parseInt(O.join(""))}(m,e)),e===null&&(r=m),e}function dl(){var e,l,u,f,p;return f=r,p=r,e=T(),e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){return parseInt(v.join(""))}(f,e)),e===null&&(r=f),e}function qu(){var e;return e=lr(),e}function Fa(){var e,l,u,f,p,m;if(p=r,e=Tr(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=vr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=vr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Tr(){var e,l;return l=r,e=us(),e!==null&&(e=function(u,f){w.expires=f}(l,e)),e===null&&(r=l),e}function vr(){var e;return e=ja(),e===null&&(e=ze()),e}function ja(){var e,l,u,f,p;return f=r,p=r,a.substr(r,9).toLowerCase()==="refresher"?(e=a.substr(r,9),r+=9):(e=null,_('"refresher"')),e!==null?(l=re(),l!==null?(a.substr(r,3).toLowerCase()==="uac"?(u=a.substr(r,3),r+=3):(u=null,_('"uac"')),u===null&&(a.substr(r,3).toLowerCase()==="uas"?(u=a.substr(r,3),r+=3):(u=null,_('"uas"'))),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.refresher=v.toLowerCase()}(f,e[2])),e===null&&(r=f),e}function qa(){var e,l,u,f;return f=r,e=P(),e!==null?(l=B(),l!==null?(u=Va(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Va(){var e,l;for(e=[],l=J(),l===null&&(l=Z(),l===null&&(l=k()));l!==null;)e.push(l),l=J(),l===null&&(l=Z(),l===null&&(l=k()));return e}function Vu(){var e,l;for(e=[],l=C();l!==null;)e.push(l),l=C();return e}function Ba(){var e,l,u;return u=r,a.substr(r,5)==="uuid:"?(e="uuid:",r+=5):(e=null,_('"uuid:"')),e!==null?(l=Wt(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function Wt(){var e,l,u,f,p,m,v,S,O,ie,Ue;return ie=r,Ue=r,e=_l(),e!==null?(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l!==null?(u=Kt(),u!==null?(a.charCodeAt(r)===45?(f="-",r++):(f=null,_('"-"')),f!==null?(p=Kt(),p!==null?(a.charCodeAt(r)===45?(m="-",r++):(m=null,_('"-"')),m!==null?(v=Kt(),v!==null?(a.charCodeAt(r)===45?(S="-",r++):(S=null,_('"-"')),S!==null?(O=Ga(),O!==null?e=[e,l,u,f,p,m,v,S,O]:(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue),e!==null&&(e=function(Dt,Js){w=a.substring(r+5,Dt)}(ie,e[0])),e===null&&(r=ie),e}function Kt(){var e,l,u,f,p;return p=r,e=y(),e!==null?(l=y(),l!==null?(u=y(),u!==null?(f=y(),f!==null?e=[e,l,u,f]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e}function _l(){var e,l,u;return u=r,e=Kt(),e!==null?(l=Kt(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function Ga(){var e,l,u,f;return f=r,e=Kt(),e!==null?(l=Kt(),l!==null?(u=Kt(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Bu(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Gt()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=ze(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=ze(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){try{w=new b(w.uri,w.display_name,w.params)}catch{w=-1}}()),e===null&&(r=p),e}function Wa(){var e,l,u,f,p,m;if(p=r,e=Er(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=Sr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=Sr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Er(){var e,l,u,f,p,m;return f=r,p=r,e=ee(),e!==null?(m=r,a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l!==null?(u=ee(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w.call_id=a.substring(r,v)}(f)),e===null&&(r=f),e}function Sr(){var e;return e=pl(),e===null&&(e=ml(),e===null&&(e=Ka(),e===null&&(e=ze()))),e}function pl(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6)==="to-tag"?(e="to-tag",r+=6):(e=null,_('"to-tag"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.to_tag=v}(f,e[2])),e===null&&(r=f),e}function ml(){var e,l,u,f,p;return f=r,p=r,a.substr(r,8)==="from-tag"?(e="from-tag",r+=8):(e=null,_('"from-tag"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.from_tag=v}(f,e[2])),e===null&&(r=f),e}function Ka(){var e,l;return l=r,a.substr(r,10)==="early-only"?(e="early-only",r+=10):(e=null,_('"early-only"')),e!==null&&(e=function(u){w.early_only=!0}()),e===null&&(r=l),e}function Gu(e){e.sort();for(var l=null,u=[],f=0;f<e.length;f++)e[f]!==l&&(u.push(e[f]),l=e[f]);return u}function Ya(){for(var e=1,l=1,u=!1,f=0;f<Math.max(r,d);f++){var p=a.charAt(f);p===`
|
3
|
+
`,r+=2):(e=null,_('"\\r\\n"')),e}function T(){var e;return/^[0-9]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[0-9]")),e}function E(){var e;return/^[a-zA-Z]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[a-zA-Z]")),e}function y(){var e;return/^[0-9a-fA-F]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[0-9a-fA-F]")),e}function C(){var e;return e=H(),e===null&&(e=$()),e}function A(){var e;return/^[\0-\xFF]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\0-\\xFF]")),e}function I(){var e;return/^["]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_('["]')),e}function H(){var e;return a.charCodeAt(r)===32?(e=" ",r++):(e=null,_('" "')),e}function $(){var e;return a.charCodeAt(r)===9?(e=" ",r++):(e=null,_('"\\t"')),e}function oe(){var e;return/^[a-zA-Z0-9]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[a-zA-Z0-9]")),e}function N(){var e;return a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","'))))))))))),e}function j(){var e;return e=oe(),e===null&&(e=Se()),e}function Se(){var e;return a.charCodeAt(r)===45?(e="-",r++):(e=null,_('"-"')),e===null&&(a.charCodeAt(r)===95?(e="_",r++):(e=null,_('"_"')),e===null&&(a.charCodeAt(r)===46?(e=".",r++):(e=null,_('"."')),e===null&&(a.charCodeAt(r)===33?(e="!",r++):(e=null,_('"!"')),e===null&&(a.charCodeAt(r)===126?(e="~",r++):(e=null,_('"~"')),e===null&&(a.charCodeAt(r)===42?(e="*",r++):(e=null,_('"*"')),e===null&&(a.charCodeAt(r)===39?(e="'",r++):(e=null,_(`"'"`)),e===null&&(a.charCodeAt(r)===40?(e="(",r++):(e=null,_('"("')),e===null&&(a.charCodeAt(r)===41?(e=")",r++):(e=null,_('")"')))))))))),e}function ve(){var e,l,u,f,p;return f=r,p=r,a.charCodeAt(r)===37?(e="%",r++):(e=null,_('"%"')),e!==null?(l=y(),l!==null?(u=y(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){return v.join("")}(f,e)),e===null&&(r=f),e}function k(){var e,l,u,f,p,m;for(f=r,p=r,m=r,e=[],l=C();l!==null;)e.push(l),l=C();if(e!==null?(l=g(),l!==null?e=[e,l]:(e=null,r=m)):(e=null,r=m),e=e!==null?e:"",e!==null){if(u=C(),u!==null)for(l=[];u!==null;)l.push(u),u=C();else l=null;l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e!==null&&(e=function(v){return" "}()),e===null&&(r=f),e}function D(){var e;return e=k(),e=e!==null?e:"",e}function B(){var e,l,u,f,p;for(f=r,p=r,e=[],l=H(),l===null&&(l=$());l!==null;)e.push(l),l=H(),l===null&&(l=$());return e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return":"}()),e===null&&(r=f),e}function V(){var e,l,u,f,p,m,v;if(p=r,m=r,l=J(),l!==null)for(e=[];l!==null;)e.push(l),l=J();else e=null;if(e!==null){for(l=[],v=r,u=[],f=k();f!==null;)u.push(f),f=k();for(u!==null?(f=J(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;){for(l.push(u),v=r,u=[],f=k();f!==null;)u.push(f),f=k();u!==null?(f=J(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v)}l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){return a.substring(r,S)}(p)),e===null&&(r=p),e}function J(){var e;return/^[!-~]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[!-~]")),e===null&&(e=F()),e}function F(){var e;return/^[\x80-\uFFFF]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\x80-\\uFFFF]")),e}function Z(){var e;return/^[\x80-\xBF]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\x80-\\xBF]")),e}function U(){var e;return e=T(),e===null&&(/^[a-f]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[a-f]"))),e}function P(){var e,l,u;if(u=r,l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"'))))))))))));else e=null;return e!==null&&(e=function(f){return a.substring(r,f)}(u)),e===null&&(r=u),e}function se(){var e,l,u;if(u=r,l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"'))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')))))))))));else e=null;return e!==null&&(e=function(f){return a.substring(r,f)}(u)),e===null&&(r=u),e}function it(){var e;return a.charCodeAt(r)===40?(e="(",r++):(e=null,_('"("')),e===null&&(a.charCodeAt(r)===41?(e=")",r++):(e=null,_('")"')),e===null&&(a.charCodeAt(r)===60?(e="<",r++):(e=null,_('"<"')),e===null&&(a.charCodeAt(r)===62?(e=">",r++):(e=null,_('">"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')),e===null&&(a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===92?(e="\\",r++):(e=null,_('"\\\\"')),e===null&&(e=I(),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e===null&&(a.charCodeAt(r)===93?(e="]",r++):(e=null,_('"]"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===123?(e="{",r++):(e=null,_('"{"')),e===null&&(a.charCodeAt(r)===125?(e="}",r++):(e=null,_('"}"')),e===null&&(e=H(),e===null&&(e=$())))))))))))))))))),e}function ee(){var e,l,u;if(u=r,l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')),l===null&&(a.charCodeAt(r)===40?(l="(",r++):(l=null,_('"("')),l===null&&(a.charCodeAt(r)===41?(l=")",r++):(l=null,_('")"')),l===null&&(a.charCodeAt(r)===60?(l="<",r++):(l=null,_('"<"')),l===null&&(a.charCodeAt(r)===62?(l=">",r++):(l=null,_('">"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===92?(l="\\",r++):(l=null,_('"\\\\"')),l===null&&(l=I(),l===null&&(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l===null&&(a.charCodeAt(r)===91?(l="[",r++):(l=null,_('"["')),l===null&&(a.charCodeAt(r)===93?(l="]",r++):(l=null,_('"]"')),l===null&&(a.charCodeAt(r)===63?(l="?",r++):(l=null,_('"?"')),l===null&&(a.charCodeAt(r)===123?(l="{",r++):(l=null,_('"{"')),l===null&&(a.charCodeAt(r)===125?(l="}",r++):(l=null,_('"}"'))))))))))))))))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')),l===null&&(a.charCodeAt(r)===40?(l="(",r++):(l=null,_('"("')),l===null&&(a.charCodeAt(r)===41?(l=")",r++):(l=null,_('")"')),l===null&&(a.charCodeAt(r)===60?(l="<",r++):(l=null,_('"<"')),l===null&&(a.charCodeAt(r)===62?(l=">",r++):(l=null,_('">"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===92?(l="\\",r++):(l=null,_('"\\\\"')),l===null&&(l=I(),l===null&&(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l===null&&(a.charCodeAt(r)===91?(l="[",r++):(l=null,_('"["')),l===null&&(a.charCodeAt(r)===93?(l="]",r++):(l=null,_('"]"')),l===null&&(a.charCodeAt(r)===63?(l="?",r++):(l=null,_('"?"')),l===null&&(a.charCodeAt(r)===123?(l="{",r++):(l=null,_('"{"')),l===null&&(a.charCodeAt(r)===125?(l="}",r++):(l=null,_('"}"')))))))))))))))))))))))));else e=null;return e!==null&&(e=function(f){return a.substring(r,f)}(u)),e===null&&(r=u),e}function Y(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"*"}()),e===null&&(r=f),e}function G(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"/"}()),e===null&&(r=f),e}function re(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"="}()),e===null&&(r=f),e}function ge(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===40?(l="(",r++):(l=null,_('"("')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"("}()),e===null&&(r=f),e}function be(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===41?(l=")",r++):(l=null,_('")"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return")"}()),e===null&&(r=f),e}function ke(){var e,l,u,f;return u=r,f=r,a.charCodeAt(r)===62?(e=">",r++):(e=null,_('">"')),e!==null?(l=D(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return">"}()),e===null&&(r=u),e}function Re(){var e,l,u,f;return u=r,f=r,e=D(),e!==null?(a.charCodeAt(r)===60?(l="<",r++):(l=null,_('"<"')),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return"<"}()),e===null&&(r=u),e}function le(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return","}()),e===null&&(r=f),e}function ye(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return";"}()),e===null&&(r=f),e}function lt(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return":"}()),e===null&&(r=f),e}function ot(){var e,l,u,f;return u=r,f=r,e=D(),e!==null?(l=I(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return'"'}()),e===null&&(r=u),e}function Ee(){var e,l,u,f;return u=r,f=r,e=I(),e!==null?(l=D(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return'"'}()),e===null&&(r=u),e}function Ce(){var e,l,u,f;if(f=r,e=ge(),e!==null){for(l=[],u=Ie(),u===null&&(u=_e(),u===null&&(u=Ce()));u!==null;)l.push(u),u=Ie(),u===null&&(u=_e(),u===null&&(u=Ce()));l!==null?(u=be(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)}else e=null,r=f;return e}function Ie(){var e;return/^[!-']/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[!-']")),e===null&&(/^[*-[]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[*-[]")),e===null&&(/^[\]-~]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\]-~]")),e===null&&(e=F(),e===null&&(e=k())))),e}function Oe(){var e,l,u,f,p,m;if(p=r,m=r,e=D(),e!==null)if(l=I(),l!==null){for(u=[],f=de(),f===null&&(f=_e());f!==null;)u.push(f),f=de(),f===null&&(f=_e());u!==null?(f=I(),f!==null?e=[e,l,u,f]:(e=null,r=m)):(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e!==null&&(e=function(v){return a.substring(r,v)}(p)),e===null&&(r=p),e}function pe(){var e,l,u,f,p,m;if(p=r,m=r,e=D(),e!==null)if(l=I(),l!==null){for(u=[],f=de(),f===null&&(f=_e());f!==null;)u.push(f),f=de(),f===null&&(f=_e());u!==null?(f=I(),f!==null?e=[e,l,u,f]:(e=null,r=m)):(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e!==null&&(e=function(v){var S=a.substring(r,v).trim();return S.substring(1,S.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(p)),e===null&&(r=p),e}function de(){var e;return e=k(),e===null&&(a.charCodeAt(r)===33?(e="!",r++):(e=null,_('"!"')),e===null&&(/^[#-[]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[#-[]")),e===null&&(/^[\]-~]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\]-~]")),e===null&&(e=F())))),e}function _e(){var e,l,u;return u=r,a.charCodeAt(r)===92?(e="\\",r++):(e=null,_('"\\\\"')),e!==null?(/^[\0-\t]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[\\0-\\t]")),l===null&&(/^[\x0B-\f]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[\\x0B-\\f]")),l===null&&(/^[\x0E-]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[\\x0E-]")))),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function we(){var e,l,u,f,p,m;return p=r,m=r,e=tt(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=At(),u=u!==null?u:"",u!==null?(f=as(),f!==null?e=[e,l,u,f]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e!==null&&(e=function(v){try{w.uri=new Rs(w.scheme,w.user,w.host,w.port),delete w.scheme,delete w.user,delete w.host,delete w.host_type,delete w.port}catch{w=-1}}()),e===null&&(r=p),e}function Ne(){var e,l,u,f,p,m,v,S;return v=r,S=r,e=tt(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=At(),u=u!==null?u:"",u!==null?(f=as(),f!==null?(p=Yn(),p!==null?(m=dn(),m=m!==null?m:"",m!==null?e=[e,l,u,f,p,m]:(e=null,r=S)):(e=null,r=S)):(e=null,r=S)):(e=null,r=S)):(e=null,r=S)):(e=null,r=S),e!==null&&(e=function(O){try{w.uri=new Rs(w.scheme,w.user,w.host,w.port,w.uri_params,w.uri_headers),delete w.scheme,delete w.user,delete w.host,delete w.host_type,delete w.port,delete w.uri_params,o==="SIP_URI"&&(w=w.uri)}catch{w=-1}}()),e===null&&(r=v),e}function tt(){var e;return e=He(),e===null&&(e=Vt()),e}function He(){var e,l;return l=r,a.substr(r,4).toLowerCase()==="sips"?(e=a.substr(r,4),r+=4):(e=null,_('"sips"')),e!==null&&(e=function(u,f){w.scheme=f.toLowerCase()}(l,e)),e===null&&(r=l),e}function Vt(){var e,l;return l=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"sip"')),e!==null&&(e=function(u,f){w.scheme=f.toLowerCase()}(l,e)),e===null&&(r=l),e}function At(){var e,l,u,f,p,m;return f=r,p=r,e=Bn(),e!==null?(m=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=cn(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?(a.charCodeAt(r)===64?(u="@",r++):(u=null,_('"@"')),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w.user=decodeURIComponent(a.substring(r-1,v))}(f)),e===null&&(r=f),e}function Bn(){var e,l;if(l=j(),l===null&&(l=ve(),l===null&&(l=Gn())),l!==null)for(e=[];l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(l=Gn()));else e=null;return e}function Gn(){var e;return a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')),e===null&&(a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"'))))))))),e}function cn(){var e,l,u;for(u=r,e=[],l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","'))))))));l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","'))))))));return e!==null&&(e=function(f){w.password=a.substring(r,f)}(u)),e===null&&(r=u),e}function as(){var e,l,u,f,p;return f=r,e=Cs(),e!==null?(p=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ui(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function Cs(){var e,l;return l=r,e=fn(),e===null&&(e=es(),e===null&&(e=hn())),e!==null&&(e=function(u){return w.host=a.substring(r,u).toLowerCase(),w.host}(l)),e===null&&(r=l),e}function fn(){var e,l,u,f,p,m;for(f=r,p=r,e=[],m=r,l=Wn(),l!==null?(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m);l!==null;)e.push(l),m=r,l=Wn(),l!==null?(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m);return e!==null?(l=Kn(),l!==null?(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u=u!==null?u:"",u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){return w.host_type="domain",a.substring(r,v)}(f)),e===null&&(r=f),e}function Wn(){var e,l,u,f;if(f=r,e=oe(),e!==null){for(l=[],u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));u!==null;)l.push(u),u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));l!==null?e=[e,l]:(e=null,r=f)}else e=null,r=f;return e}function Kn(){var e,l,u,f;if(f=r,e=E(),e!==null){for(l=[],u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));u!==null;)l.push(u),u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));l!==null?e=[e,l]:(e=null,r=f)}else e=null,r=f;return e}function hn(){var e,l,u,f,p;return f=r,p=r,a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e!==null?(l=me(),l!==null?(a.charCodeAt(r)===93?(u="]",r++):(u=null,_('"]"')),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return w.host_type="IPv6",a.substring(r,m)}(f)),e===null&&(r=f),e}function me(){var e,l,u,f,p,m,v,S,O,ie,Ue,Dt,Js,M,R,Te;return M=r,R=r,e=ae(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?(a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?(a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?(a.charCodeAt(r)===58?(S=":",r++):(S=null,_('":"')),S!==null?(O=ae(),O!==null?(a.charCodeAt(r)===58?(ie=":",r++):(ie=null,_('":"')),ie!==null?(Ue=ae(),Ue!==null?(a.charCodeAt(r)===58?(Dt=":",r++):(Dt=null,_('":"')),Dt!==null?(Js=ut(),Js!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue,Dt,Js]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?(a.charCodeAt(r)===58?(O=":",r++):(O=null,_('":"')),O!==null?(ie=ae(),ie!==null?(a.charCodeAt(r)===58?(Ue=":",r++):(Ue=null,_('":"')),Ue!==null?(Dt=ut(),Dt!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue,Dt]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?(a.charCodeAt(r)===58?(O=":",r++):(O=null,_('":"')),O!==null?(ie=ut(),ie!==null?e=[e,l,u,f,p,m,v,S,O,ie]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ut(),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ut(),m!==null?e=[e,l,u,f,p,m]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ut(),f!==null?e=[e,l,u,f]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ut(),l!==null?e=[e,l]:(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?e=[e,l]:(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(a.substr(r,2)==="::"?(l="::",r+=2):(l=null,_('"::"')),l!==null?(u=ae(),u!==null?(a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?(a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?(a.charCodeAt(r)===58?(S=":",r++):(S=null,_('":"')),S!==null?(O=ae(),O!==null?(a.charCodeAt(r)===58?(ie=":",r++):(ie=null,_('":"')),ie!==null?(Ue=ut(),Ue!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(a.substr(r,2)==="::"?(u="::",r+=2):(u=null,_('"::"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?(a.charCodeAt(r)===58?(O=":",r++):(O=null,_('":"')),O!==null?(ie=ut(),ie!==null?e=[e,l,u,f,p,m,v,S,O,ie]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(a.substr(r,2)==="::"?(f="::",r+=2):(f=null,_('"::"')),f!==null?(p=ae(),p!==null?(a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?(a.charCodeAt(r)===58?(S=":",r++):(S=null,_('":"')),S!==null?(O=ut(),O!==null?e=[e,l,u,f,p,m,v,S,O]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(a.substr(r,2)==="::"?(p="::",r+=2):(p=null,_('"::"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ut(),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(Te=r,a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?p=[p,m]:(p=null,r=Te)):(p=null,r=Te),p=p!==null?p:"",p!==null?(a.substr(r,2)==="::"?(m="::",r+=2):(m=null,_('"::"')),m!==null?(v=ut(),v!==null?e=[e,l,u,f,p,m,v]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(Te=r,a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?p=[p,m]:(p=null,r=Te)):(p=null,r=Te),p=p!==null?p:"",p!==null?(Te=r,a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?m=[m,v]:(m=null,r=Te)):(m=null,r=Te),m=m!==null?m:"",m!==null?(a.substr(r,2)==="::"?(v="::",r+=2):(v=null,_('"::"')),v!==null?(S=ae(),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(Te=r,a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?p=[p,m]:(p=null,r=Te)):(p=null,r=Te),p=p!==null?p:"",p!==null?(Te=r,a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?m=[m,v]:(m=null,r=Te)):(m=null,r=Te),m=m!==null?m:"",m!==null?(Te=r,a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?v=[v,S]:(v=null,r=Te)):(v=null,r=Te),v=v!==null?v:"",v!==null?(a.substr(r,2)==="::"?(S="::",r+=2):(S=null,_('"::"')),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R))))))))))))))),e!==null&&(e=function(Yv){return w.host_type="IPv6",a.substring(r,Yv)}(M)),e===null&&(r=M),e}function ae(){var e,l,u,f,p;return p=r,e=y(),e!==null?(l=y(),l=l!==null?l:"",l!==null?(u=y(),u=u!==null?u:"",u!==null?(f=y(),f=f!==null?f:"",f!==null?e=[e,l,u,f]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e}function ut(){var e,l,u,f;return f=r,e=ae(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e===null&&(e=es()),e}function es(){var e,l,u,f,p,m,v,S,O;return S=r,O=r,e=$s(),e!==null?(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l!==null?(u=$s(),u!==null?(a.charCodeAt(r)===46?(f=".",r++):(f=null,_('"."')),f!==null?(p=$s(),p!==null?(a.charCodeAt(r)===46?(m=".",r++):(m=null,_('"."')),m!==null?(v=$s(),v!==null?e=[e,l,u,f,p,m,v]:(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O),e!==null&&(e=function(ie){return w.host_type="IPv4",a.substring(r,ie)}(S)),e===null&&(r=S),e}function $s(){var e,l,u,f;return f=r,a.substr(r,2)==="25"?(e="25",r+=2):(e=null,_('"25"')),e!==null?(/^[0-5]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[0-5]")),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e===null&&(f=r,a.charCodeAt(r)===50?(e="2",r++):(e=null,_('"2"')),e!==null?(/^[0-4]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[0-4]")),l!==null?(u=T(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e===null&&(f=r,a.charCodeAt(r)===49?(e="1",r++):(e=null,_('"1"')),e!==null?(l=T(),l!==null?(u=T(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e===null&&(f=r,/^[1-9]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[1-9]")),e!==null?(l=T(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e===null&&(e=T())))),e}function ui(){var e,l,u,f,p,m,v;return m=r,v=r,e=T(),e=e!==null?e:"",e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?e=[e,l,u,f,p]:(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(S,O){return O=parseInt(O.join("")),w.port=O,O}(m,e)),e===null&&(r=m),e}function Yn(){var e,l,u,f;for(e=[],f=r,a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l!==null?(u=Jn(),u!==null?l=[l,u]:(l=null,r=f)):(l=null,r=f);l!==null;)e.push(l),f=r,a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l!==null?(u=Jn(),u!==null?l=[l,u]:(l=null,r=f)):(l=null,r=f);return e}function Jn(){var e;return e=ci(),e===null&&(e=fi(),e===null&&(e=hi(),e===null&&(e=di(),e===null&&(e=_i(),e===null&&(e=pi(),e===null&&(e=mi())))))),e}function ci(){var e,l,u,f;return u=r,f=r,a.substr(r,10).toLowerCase()==="transport="?(e=a.substr(r,10),r+=10):(e=null,_('"transport="')),e!==null?(a.substr(r,3).toLowerCase()==="udp"?(l=a.substr(r,3),r+=3):(l=null,_('"udp"')),l===null&&(a.substr(r,3).toLowerCase()==="tcp"?(l=a.substr(r,3),r+=3):(l=null,_('"tcp"')),l===null&&(a.substr(r,4).toLowerCase()==="sctp"?(l=a.substr(r,4),r+=4):(l=null,_('"sctp"')),l===null&&(a.substr(r,3).toLowerCase()==="tls"?(l=a.substr(r,3),r+=3):(l=null,_('"tls"')),l===null&&(l=P())))),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.transport=m.toLowerCase()}(u,e[1])),e===null&&(r=u),e}function fi(){var e,l,u,f;return u=r,f=r,a.substr(r,5).toLowerCase()==="user="?(e=a.substr(r,5),r+=5):(e=null,_('"user="')),e!==null?(a.substr(r,5).toLowerCase()==="phone"?(l=a.substr(r,5),r+=5):(l=null,_('"phone"')),l===null&&(a.substr(r,2).toLowerCase()==="ip"?(l=a.substr(r,2),r+=2):(l=null,_('"ip"')),l===null&&(l=P())),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.user=m.toLowerCase()}(u,e[1])),e===null&&(r=u),e}function hi(){var e,l,u,f;return u=r,f=r,a.substr(r,7).toLowerCase()==="method="?(e=a.substr(r,7),r+=7):(e=null,_('"method="')),e!==null?(l=En(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.method=m}(u,e[1])),e===null&&(r=u),e}function di(){var e,l,u,f;return u=r,f=r,a.substr(r,4).toLowerCase()==="ttl="?(e=a.substr(r,4),r+=4):(e=null,_('"ttl="')),e!==null?(l=dl(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.params||(w.params={}),w.params.ttl=m}(u,e[1])),e===null&&(r=u),e}function _i(){var e,l,u,f;return u=r,f=r,a.substr(r,6).toLowerCase()==="maddr="?(e=a.substr(r,6),r+=6):(e=null,_('"maddr="')),e!==null?(l=Cs(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.maddr=m}(u,e[1])),e===null&&(r=u),e}function pi(){var e,l,u,f,p,m;return f=r,p=r,a.substr(r,2).toLowerCase()==="lr"?(e=a.substr(r,2),r+=2):(e=null,_('"lr"')),e!==null?(m=r,a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=P(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w.uri_params||(w.uri_params={}),w.uri_params.lr=void 0}()),e===null&&(r=f),e}function mi(){var e,l,u,f,p,m;return f=r,p=r,e=gi(),e!==null?(m=r,a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=Hs(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v,S,O){w.uri_params||(w.uri_params={}),typeof O>"u"?O=void 0:O=O[1],w.uri_params[S.toLowerCase()]=O}(f,e[0],e[1])),e===null&&(r=f),e}function gi(){var e,l,u;if(u=r,l=Fs(),l!==null)for(e=[];l!==null;)e.push(l),l=Fs();else e=null;return e!==null&&(e=function(f,p){return p.join("")}(u,e)),e===null&&(r=u),e}function Hs(){var e,l,u;if(u=r,l=Fs(),l!==null)for(e=[];l!==null;)e.push(l),l=Fs();else e=null;return e!==null&&(e=function(f,p){return p.join("")}(u,e)),e===null&&(r=u),e}function Fs(){var e;return e=Ti(),e===null&&(e=j(),e===null&&(e=ve())),e}function Ti(){var e;return a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e===null&&(a.charCodeAt(r)===93?(e="]",r++):(e=null,_('"]"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')))))))),e}function dn(){var e,l,u,f,p,m,v;if(m=r,a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e!==null)if(l=_n(),l!==null){for(u=[],v=r,a.charCodeAt(r)===38?(f="&",r++):(f=null,_('"&"')),f!==null?(p=_n(),p!==null?f=[f,p]:(f=null,r=v)):(f=null,r=v);f!==null;)u.push(f),v=r,a.charCodeAt(r)===38?(f="&",r++):(f=null,_('"&"')),f!==null?(p=_n(),p!==null?f=[f,p]:(f=null,r=v)):(f=null,r=v);u!==null?e=[e,l,u]:(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e}function _n(){var e,l,u,f,p;return f=r,p=r,e=vi(),e!==null?(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=js(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v,S){v=v.join("").toLowerCase(),S=S.join(""),w.uri_headers||(w.uri_headers={}),w.uri_headers[v]?w.uri_headers[v].push(S):w.uri_headers[v]=[S]}(f,e[0],e[2])),e===null&&(r=f),e}function vi(){var e,l;if(l=pn(),l===null&&(l=j(),l===null&&(l=ve())),l!==null)for(e=[];l!==null;)e.push(l),l=pn(),l===null&&(l=j(),l===null&&(l=ve()));else e=null;return e}function js(){var e,l;for(e=[],l=pn(),l===null&&(l=j(),l===null&&(l=ve()));l!==null;)e.push(l),l=pn(),l===null&&(l=j(),l===null&&(l=ve()));return e}function pn(){var e;return a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e===null&&(a.charCodeAt(r)===93?(e="]",r++):(e=null,_('"]"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')))))))),e}function wa(){var e;return e=ki(),e===null&&(e=Ei()),e}function Ei(){var e,l,u,f,p,m;return m=r,e=En(),e!==null?(l=H(),l!==null?(u=zn(),u!==null?(f=H(),f!==null?(p=Zn(),p!==null?e=[e,l,u,f,p]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e}function zn(){var e;return e=Ne(),e===null&&(e=Xn()),e}function Xn(){var e,l,u,f;return f=r,e=Ci(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=Si(),u===null&&(u=qs()),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Si(){var e,l,u,f,p;return f=r,e=mn(),e===null&&(e=gn()),e!==null?(p=r,a.charCodeAt(r)===63?(l="?",r++):(l=null,_('"?"')),l!==null?(u=Qn(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function mn(){var e,l,u,f;return f=r,a.substr(r,2)==="//"?(e="//",r+=2):(e=null,_('"//"')),e!==null?(l=Ai(),l!==null?(u=gn(),u=u!==null?u:"",u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function gn(){var e,l,u;return u=r,a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e!==null?(l=Tn(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function qs(){var e,l,u,f;if(f=r,e=yi(),e!==null){for(l=[],u=Vs();u!==null;)l.push(u),u=Vs();l!==null?e=[e,l]:(e=null,r=f)}else e=null,r=f;return e}function Vs(){var e;return e=N(),e===null&&(e=j(),e===null&&(e=ve())),e}function yi(){var e;return e=j(),e===null&&(e=ve(),e===null&&(a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')))))))))))),e}function Tn(){var e,l,u,f,p,m;if(p=r,e=Bs(),e!==null){for(l=[],m=r,a.charCodeAt(r)===47?(u="/",r++):(u=null,_('"/"')),u!==null?(f=Bs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,a.charCodeAt(r)===47?(u="/",r++):(u=null,_('"/"')),u!==null?(f=Bs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Bs(){var e,l,u,f,p,m;for(p=r,e=[],l=Gs();l!==null;)e.push(l),l=Gs();if(e!==null){for(l=[],m=r,a.charCodeAt(r)===59?(u=";",r++):(u=null,_('";"')),u!==null?(f=As(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,a.charCodeAt(r)===59?(u=";",r++):(u=null,_('";"')),u!==null?(f=As(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function As(){var e,l;for(e=[],l=Gs();l!==null;)e.push(l),l=Gs();return e}function Gs(){var e;return e=j(),e===null&&(e=ve(),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')))))))))),e}function Ci(){var e,l,u,f,p;if(f=r,p=r,e=E(),e!==null){for(l=[],u=E(),u===null&&(u=T(),u===null&&(a.charCodeAt(r)===43?(u="+",r++):(u=null,_('"+"')),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."'))))));u!==null;)l.push(u),u=E(),u===null&&(u=T(),u===null&&(a.charCodeAt(r)===43?(u="+",r++):(u=null,_('"+"')),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."'))))));l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e!==null&&(e=function(m){w.scheme=a.substring(r,m)}(f)),e===null&&(r=f),e}function Ai(){var e;return e=Ri(),e===null&&(e=Ii()),e}function Ri(){var e,l,u,f;return u=r,f=r,e=At(),e!==null?(a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e=e!==null?e:"",e!==null?(l=as(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e=e!==null?e:"",e}function Ii(){var e,l;if(l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","')),l===null&&(a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"'))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","')),l===null&&(a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')))))))))));else e=null;return e}function Qn(){var e,l;for(e=[],l=Vs();l!==null;)e.push(l),l=Vs();return e}function Zn(){var e,l,u,f,p,m,v,S;if(v=r,S=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"SIP"')),e!==null)if(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l!==null){if(f=T(),f!==null)for(u=[];f!==null;)u.push(f),f=T();else u=null;if(u!==null)if(a.charCodeAt(r)===46?(f=".",r++):(f=null,_('"."')),f!==null){if(m=T(),m!==null)for(p=[];m!==null;)p.push(m),m=T();else p=null;p!==null?e=[e,l,u,f,p]:(e=null,r=S)}else e=null,r=S;else e=null,r=S}else e=null,r=S;else e=null,r=S;return e!==null&&(e=function(O){w.sip_version=a.substring(r,O)}(v)),e===null&&(r=v),e}function bi(){var e;return a.substr(r,6)==="INVITE"?(e="INVITE",r+=6):(e=null,_('"INVITE"')),e}function wi(){var e;return a.substr(r,3)==="ACK"?(e="ACK",r+=3):(e=null,_('"ACK"')),e}function Oi(){var e;return a.substr(r,7)==="OPTIONS"?(e="OPTIONS",r+=7):(e=null,_('"OPTIONS"')),e}function Di(){var e;return a.substr(r,3)==="BYE"?(e="BYE",r+=3):(e=null,_('"BYE"')),e}function Ni(){var e;return a.substr(r,6)==="CANCEL"?(e="CANCEL",r+=6):(e=null,_('"CANCEL"')),e}function Ui(){var e;return a.substr(r,8)==="REGISTER"?(e="REGISTER",r+=8):(e=null,_('"REGISTER"')),e}function Pi(){var e;return a.substr(r,9)==="SUBSCRIBE"?(e="SUBSCRIBE",r+=9):(e=null,_('"SUBSCRIBE"')),e}function xi(){var e;return a.substr(r,6)==="NOTIFY"?(e="NOTIFY",r+=6):(e=null,_('"NOTIFY"')),e}function vn(){var e;return a.substr(r,5)==="REFER"?(e="REFER",r+=5):(e=null,_('"REFER"')),e}function En(){var e,l;return l=r,e=bi(),e===null&&(e=wi(),e===null&&(e=Oi(),e===null&&(e=Di(),e===null&&(e=Ni(),e===null&&(e=Ui(),e===null&&(e=Pi(),e===null&&(e=xi(),e===null&&(e=vn(),e===null&&(e=P()))))))))),e!==null&&(e=function(u){return w.method=a.substring(r,u),w.method}(l)),e===null&&(r=l),e}function ki(){var e,l,u,f,p,m;return m=r,e=Zn(),e!==null?(l=H(),l!==null?(u=Mi(),u!==null?(f=H(),f!==null?(p=Oa(),p!==null?e=[e,l,u,f,p]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e}function Mi(){var e,l;return l=r,e=Li(),e!==null&&(e=function(u,f){w.status_code=parseInt(f.join(""))}(l,e)),e===null&&(r=l),e}function Li(){var e,l,u,f;return f=r,e=T(),e!==null?(l=T(),l!==null?(u=T(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Oa(){var e,l,u;for(u=r,e=[],l=N(),l===null&&(l=j(),l===null&&(l=ve(),l===null&&(l=F(),l===null&&(l=Z(),l===null&&(l=H(),l===null&&(l=$()))))));l!==null;)e.push(l),l=N(),l===null&&(l=j(),l===null&&(l=ve(),l===null&&(l=F(),l===null&&(l=Z(),l===null&&(l=H(),l===null&&(l=$()))))));return e!==null&&(e=function(f){w.reason_phrase=a.substring(r,f)}(u)),e===null&&(r=u),e}function Du(){var e,l,u,f,p,m;if(p=r,e=An(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=An(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=An(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Nu(){var e,l,u,f,p,m;return f=r,p=r,e=ee(),e!==null?(m=r,a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l!==null?(u=ee(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w=a.substring(r,v)}(f)),e===null&&(r=f),e}function er(){var e,l,u,f,p,m,v;if(p=r,e=Y(),e===null)if(m=r,e=Bt(),e!==null){for(l=[],v=r,u=le(),u!==null?(f=Bt(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=le(),u!==null?(f=Bt(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O,ie;for(ie=w.multi_header.length,O=0;O<ie;O++)if(w.multi_header[O].parsed===null){w=null;break}w!==null?w=w.multi_header:w=-1}()),e===null&&(r=p),e}function Bt(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Gt()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=tr(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=tr(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O;w.multi_header||(w.multi_header=[]);try{O=new b(w.uri,w.display_name,w.params),delete w.uri,delete w.display_name,delete w.params}catch{O=null}w.multi_header.push({possition:r,offset:S,parsed:O})}(p)),e===null&&(r=p),e}function Gt(){var e,l,u,f,p;return p=r,e=Ws(),e=e!==null?e:"",e!==null?(l=Re(),l!==null?(u=Ne(),u!==null?(f=ke(),f!==null?e=[e,l,u,f]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e}function Ws(){var e,l,u,f,p,m,v;if(p=r,m=r,e=P(),e!==null){for(l=[],v=r,u=k(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=k(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e===null&&(e=pe()),e!==null&&(e=function(S,O){typeof O=="string"?w.display_name=O:w.display_name=O[1].reduce(function(ie,Ue){return ie+Ue[0]+Ue[1]},O[0])}(p,e)),e===null&&(r=p),e}function tr(){var e;return e=$i(),e===null&&(e=os(),e===null&&(e=ze())),e}function $i(){var e,l,u,f,p;return f=r,p=r,a.substr(r,1).toLowerCase()==="q"?(e=a.substr(r,1),r++):(e=null,_('"q"')),e!==null?(l=re(),l!==null?(u=Je(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.params||(w.params={}),w.params.q=v}(f,e[2])),e===null&&(r=f),e}function os(){var e,l,u,f,p;return f=r,p=r,a.substr(r,7).toLowerCase()==="expires"?(e=a.substr(r,7),r+=7):(e=null,_('"expires"')),e!==null?(l=re(),l!==null?(u=us(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.params||(w.params={}),w.params.expires=v}(f,e[2])),e===null&&(r=f),e}function us(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){return parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function Je(){var e,l,u,f,p,m,v,S;return m=r,v=r,a.charCodeAt(r)===48?(e="0",r++):(e=null,_('"0"')),e!==null?(S=r,a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?l=[l,u,f,p]:(l=null,r=S)):(l=null,r=S)):(l=null,r=S)):(l=null,r=S),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(O){return parseFloat(a.substring(r,O))}(m)),e===null&&(r=m),e}function ze(){var e,l,u,f,p,m;return f=r,p=r,e=P(),e!==null?(m=r,l=re(),l!==null?(u=Da(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v,S,O){w.params||(w.params={}),typeof O>"u"?O=void 0:O=O[1],w.params[S.toLowerCase()]=O}(f,e[0],e[1])),e===null&&(r=f),e}function Da(){var e;return e=P(),e===null&&(e=Cs(),e===null&&(e=Oe())),e}function Na(){var e,l,u,f,p,m;if(p=r,e=sr(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=nr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=nr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function sr(){var e;return a.substr(r,6).toLowerCase()==="render"?(e=a.substr(r,6),r+=6):(e=null,_('"render"')),e===null&&(a.substr(r,7).toLowerCase()==="session"?(e=a.substr(r,7),r+=7):(e=null,_('"session"')),e===null&&(a.substr(r,4).toLowerCase()==="icon"?(e=a.substr(r,4),r+=4):(e=null,_('"icon"')),e===null&&(a.substr(r,5).toLowerCase()==="alert"?(e=a.substr(r,5),r+=5):(e=null,_('"alert"')),e===null&&(e=P())))),e}function nr(){var e;return e=Ua(),e===null&&(e=ze()),e}function Ua(){var e,l,u,f;return f=r,a.substr(r,8).toLowerCase()==="handling"?(e=a.substr(r,8),r+=8):(e=null,_('"handling"')),e!==null?(l=re(),l!==null?(a.substr(r,8).toLowerCase()==="optional"?(u=a.substr(r,8),r+=8):(u=null,_('"optional"')),u===null&&(a.substr(r,8).toLowerCase()==="required"?(u=a.substr(r,8),r+=8):(u=null,_('"required"')),u===null&&(u=P())),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Uu(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Pu(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){w=parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function Pa(){var e,l;return l=r,e=Hi(),e!==null&&(e=function(u){w=a.substring(r,u)}(l)),e===null&&(r=l),e}function Hi(){var e,l,u,f,p,m,v,S;if(v=r,e=Fi(),e!==null)if(l=G(),l!==null)if(u=rr(),u!==null){for(f=[],S=r,p=ye(),p!==null?(m=ir(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=ye(),p!==null?(m=ir(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e}function Fi(){var e;return e=ji(),e===null&&(e=Sn()),e}function ji(){var e;return a.substr(r,4).toLowerCase()==="text"?(e=a.substr(r,4),r+=4):(e=null,_('"text"')),e===null&&(a.substr(r,5).toLowerCase()==="image"?(e=a.substr(r,5),r+=5):(e=null,_('"image"')),e===null&&(a.substr(r,5).toLowerCase()==="audio"?(e=a.substr(r,5),r+=5):(e=null,_('"audio"')),e===null&&(a.substr(r,5).toLowerCase()==="video"?(e=a.substr(r,5),r+=5):(e=null,_('"video"')),e===null&&(a.substr(r,11).toLowerCase()==="application"?(e=a.substr(r,11),r+=11):(e=null,_('"application"')),e===null&&(e=yn()))))),e}function Sn(){var e;return a.substr(r,7).toLowerCase()==="message"?(e=a.substr(r,7),r+=7):(e=null,_('"message"')),e===null&&(a.substr(r,9).toLowerCase()==="multipart"?(e=a.substr(r,9),r+=9):(e=null,_('"multipart"')),e===null&&(e=yn())),e}function yn(){var e;return e=P(),e===null&&(e=qi()),e}function qi(){var e,l,u;return u=r,a.substr(r,2).toLowerCase()==="x-"?(e=a.substr(r,2),r+=2):(e=null,_('"x-"')),e!==null?(l=P(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function rr(){var e;return e=yn(),e===null&&(e=P()),e}function ir(){var e,l,u,f;return f=r,e=P(),e!==null?(l=re(),l!==null?(u=xa(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function xa(){var e;return e=P(),e===null&&(e=Oe()),e}function ka(){var e,l,u,f;return f=r,e=Ma(),e!==null?(l=k(),l!==null?(u=En(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Ma(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){w.value=parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function xu(){var e,l;return l=r,e=us(),e!==null&&(e=function(u,f){w=f}(l,e)),e===null&&(r=l),e}function Cn(){var e,l,u,f,p,m,v;if(p=r,m=r,e=An(),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=ze(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=ze(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S,O){w.event=O.join("").toLowerCase()}(p,e[0])),e===null&&(r=p),e}function An(){var e,l,u,f,p,m;if(p=r,e=se(),e!==null){for(l=[],m=r,a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?(f=se(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?(f=se(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Vi(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Gt()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=Rn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=Rn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O=w.tag;try{w=new b(w.uri,w.display_name,w.params),O&&w.setParam("tag",O)}catch{w=-1}}()),e===null&&(r=p),e}function Rn(){var e;return e=Bi(),e===null&&(e=ze()),e}function Bi(){var e,l,u,f,p;return f=r,p=r,a.substr(r,3).toLowerCase()==="tag"?(e=a.substr(r,3),r+=3):(e=null,_('"tag"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.tag=v}(f,e[2])),e===null&&(r=f),e}function ku(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){w=parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function Mu(){var e,l;return l=r,e=us(),e!==null&&(e=function(u,f){w=f}(l,e)),e===null&&(r=l),e}function Lu(){var e,l,u,f,p,m,v,S,O,ie;for(S=r,O=r,e=[],l=Ws();l!==null;)e.push(l),l=Ws();if(e!==null)if(l=Re(),l!==null)if(u=Ne(),u!==null)if(f=ke(),f!==null){for(p=[],ie=r,m=ye(),m!==null?(v=ze(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);m!==null;)p.push(m),ie=r,m=ye(),m!==null?(v=ze(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);p!==null?e=[e,l,u,f,p]:(e=null,r=O)}else e=null,r=O;else e=null,r=O;else e=null,r=O;else e=null,r=O;return e!==null&&(e=function(Ue){try{w=new b(w.uri,w.display_name,w.params)}catch{w=-1}}()),e===null&&(r=S),e}function Gi(){var e;return e=lr(),e}function lr(){var e,l,u,f,p,m,v,S;if(v=r,a.substr(r,6).toLowerCase()==="digest"?(e=a.substr(r,6),r+=6):(e=null,_('"Digest"')),e!==null)if(l=k(),l!==null)if(u=In(),u!==null){for(f=[],S=r,p=le(),p!==null?(m=In(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=le(),p!==null?(m=In(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e===null&&(e=Ks()),e}function Ks(){var e,l,u,f,p,m,v,S;if(v=r,e=P(),e!==null)if(l=k(),l!==null)if(u=cs(),u!==null){for(f=[],S=r,p=le(),p!==null?(m=cs(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=le(),p!==null?(m=cs(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e}function cs(){var e,l,u,f;return f=r,e=P(),e!==null?(l=re(),l!==null?(u=P(),u===null&&(u=Oe()),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function In(){var e;return e=Wi(),e===null&&(e=bn(),e===null&&(e=Yi(),e===null&&(e=zi(),e===null&&(e=Xi(),e===null&&(e=Qi(),e===null&&(e=On(),e===null&&(e=cs()))))))),e}function Wi(){var e,l,u,f;return f=r,a.substr(r,5).toLowerCase()==="realm"?(e=a.substr(r,5),r+=5):(e=null,_('"realm"')),e!==null?(l=re(),l!==null?(u=Ki(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Ki(){var e,l;return l=r,e=pe(),e!==null&&(e=function(u,f){w.realm=f}(l,e)),e===null&&(r=l),e}function bn(){var e,l,u,f,p,m,v,S,O;if(S=r,a.substr(r,6).toLowerCase()==="domain"?(e=a.substr(r,6),r+=6):(e=null,_('"domain"')),e!==null)if(l=re(),l!==null)if(u=ot(),u!==null)if(f=wn(),f!==null){if(p=[],O=r,v=H(),v!==null)for(m=[];v!==null;)m.push(v),v=H();else m=null;for(m!==null?(v=wn(),v!==null?m=[m,v]:(m=null,r=O)):(m=null,r=O);m!==null;){if(p.push(m),O=r,v=H(),v!==null)for(m=[];v!==null;)m.push(v),v=H();else m=null;m!==null?(v=wn(),v!==null?m=[m,v]:(m=null,r=O)):(m=null,r=O)}p!==null?(m=Ee(),m!==null?e=[e,l,u,f,p,m]:(e=null,r=S)):(e=null,r=S)}else e=null,r=S;else e=null,r=S;else e=null,r=S;else e=null,r=S;return e}function wn(){var e;return e=Xn(),e===null&&(e=gn()),e}function Yi(){var e,l,u,f;return f=r,a.substr(r,5).toLowerCase()==="nonce"?(e=a.substr(r,5),r+=5):(e=null,_('"nonce"')),e!==null?(l=re(),l!==null?(u=Ji(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Ji(){var e,l;return l=r,e=pe(),e!==null&&(e=function(u,f){w.nonce=f}(l,e)),e===null&&(r=l),e}function zi(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6).toLowerCase()==="opaque"?(e=a.substr(r,6),r+=6):(e=null,_('"opaque"')),e!==null?(l=re(),l!==null?(u=pe(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.opaque=v}(f,e[2])),e===null&&(r=f),e}function Xi(){var e,l,u,f,p;return f=r,a.substr(r,5).toLowerCase()==="stale"?(e=a.substr(r,5),r+=5):(e=null,_('"stale"')),e!==null?(l=re(),l!==null?(p=r,a.substr(r,4).toLowerCase()==="true"?(u=a.substr(r,4),r+=4):(u=null,_('"true"')),u!==null&&(u=function(m){w.stale=!0}()),u===null&&(r=p),u===null&&(p=r,a.substr(r,5).toLowerCase()==="false"?(u=a.substr(r,5),r+=5):(u=null,_('"false"')),u!==null&&(u=function(m){w.stale=!1}()),u===null&&(r=p)),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Qi(){var e,l,u,f,p;return f=r,p=r,a.substr(r,9).toLowerCase()==="algorithm"?(e=a.substr(r,9),r+=9):(e=null,_('"algorithm"')),e!==null?(l=re(),l!==null?(a.substr(r,3).toLowerCase()==="md5"?(u=a.substr(r,3),r+=3):(u=null,_('"MD5"')),u===null&&(a.substr(r,8).toLowerCase()==="md5-sess"?(u=a.substr(r,8),r+=8):(u=null,_('"MD5-sess"')),u===null&&(u=P())),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.algorithm=v.toUpperCase()}(f,e[2])),e===null&&(r=f),e}function On(){var e,l,u,f,p,m,v,S,O,ie;if(S=r,a.substr(r,3).toLowerCase()==="qop"?(e=a.substr(r,3),r+=3):(e=null,_('"qop"')),e!==null)if(l=re(),l!==null)if(u=ot(),u!==null){if(O=r,f=ar(),f!==null){for(p=[],ie=r,a.charCodeAt(r)===44?(m=",",r++):(m=null,_('","')),m!==null?(v=ar(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);m!==null;)p.push(m),ie=r,a.charCodeAt(r)===44?(m=",",r++):(m=null,_('","')),m!==null?(v=ar(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);p!==null?f=[f,p]:(f=null,r=O)}else f=null,r=O;f!==null?(p=Ee(),p!==null?e=[e,l,u,f,p]:(e=null,r=S)):(e=null,r=S)}else e=null,r=S;else e=null,r=S;else e=null,r=S;return e}function ar(){var e,l;return l=r,a.substr(r,8).toLowerCase()==="auth-int"?(e=a.substr(r,8),r+=8):(e=null,_('"auth-int"')),e===null&&(a.substr(r,4).toLowerCase()==="auth"?(e=a.substr(r,4),r+=4):(e=null,_('"auth"')),e===null&&(e=P())),e!==null&&(e=function(u,f){w.qop||(w.qop=[]),w.qop.push(f.toLowerCase())}(l,e)),e===null&&(r=l),e}function $u(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function or(){var e,l,u,f,p,m,v;if(p=r,m=r,e=ur(),e!==null){for(l=[],v=r,u=le(),u!==null?(f=ur(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=le(),u!==null?(f=ur(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O,ie;for(ie=w.multi_header.length,O=0;O<ie;O++)if(w.multi_header[O].parsed===null){w=null;break}w!==null?w=w.multi_header:w=-1}()),e===null&&(r=p),e}function ur(){var e,l,u,f,p,m,v;if(p=r,m=r,e=Gt(),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=ze(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=ze(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O;w.multi_header||(w.multi_header=[]);try{O=new b(w.uri,w.display_name,w.params),delete w.uri,delete w.display_name,delete w.params}catch{O=null}w.multi_header.push({possition:r,offset:S,parsed:O})}(p)),e===null&&(r=p),e}function Zi(){var e,l,u,f,p,m,v;if(p=r,m=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"SIP"')),e===null&&(e=P()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=cr(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=cr(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S,O){if(w.protocol=O.toLowerCase(),w.params||(w.params={}),w.params.text&&w.params.text[0]==='"'){var ie=w.params.text;w.text=ie.substring(1,ie.length-1),delete w.params.text}}(p,e[0])),e===null&&(r=p),e}function cr(){var e;return e=La(),e===null&&(e=ze()),e}function La(){var e,l,u,f,p,m;if(p=r,m=r,a.substr(r,5).toLowerCase()==="cause"?(e=a.substr(r,5),r+=5):(e=null,_('"cause"')),e!==null)if(l=re(),l!==null){if(f=T(),f!==null)for(u=[];f!==null;)u.push(f),f=T();else u=null;u!==null?e=[e,l,u]:(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e!==null&&(e=function(v,S){w.cause=parseInt(S.join(""))}(p,e[2])),e===null&&(r=p),e}function Hu(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function fr(){var e,l,u,f,p,m;if(p=r,e=hr(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=hr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=hr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function hr(){var e,l,u,f,p,m;if(p=r,e=Gt(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=ze(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=ze(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function $a(){var e,l,u,f,p,m;if(p=r,e=dr(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=_r(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=_r(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function dr(){var e,l;return l=r,a.substr(r,6).toLowerCase()==="active"?(e=a.substr(r,6),r+=6):(e=null,_('"active"')),e===null&&(a.substr(r,7).toLowerCase()==="pending"?(e=a.substr(r,7),r+=7):(e=null,_('"pending"')),e===null&&(a.substr(r,10).toLowerCase()==="terminated"?(e=a.substr(r,10),r+=10):(e=null,_('"terminated"')),e===null&&(e=P()))),e!==null&&(e=function(u){w.state=a.substring(r,u)}(l)),e===null&&(r=l),e}function _r(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6).toLowerCase()==="reason"?(e=a.substr(r,6),r+=6):(e=null,_('"reason"')),e!==null?(l=re(),l!==null?(u=Ha(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){typeof v<"u"&&(w.reason=v)}(f,e[2])),e===null&&(r=f),e===null&&(f=r,p=r,a.substr(r,7).toLowerCase()==="expires"?(e=a.substr(r,7),r+=7):(e=null,_('"expires"')),e!==null?(l=re(),l!==null?(u=us(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){typeof v<"u"&&(w.expires=v)}(f,e[2])),e===null&&(r=f),e===null&&(f=r,p=r,a.substr(r,11).toLowerCase()==="retry_after"?(e=a.substr(r,11),r+=11):(e=null,_('"retry_after"')),e!==null?(l=re(),l!==null?(u=us(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){typeof v<"u"&&(w.retry_after=v)}(f,e[2])),e===null&&(r=f),e===null&&(e=ze()))),e}function Ha(){var e;return a.substr(r,11).toLowerCase()==="deactivated"?(e=a.substr(r,11),r+=11):(e=null,_('"deactivated"')),e===null&&(a.substr(r,9).toLowerCase()==="probation"?(e=a.substr(r,9),r+=9):(e=null,_('"probation"')),e===null&&(a.substr(r,8).toLowerCase()==="rejected"?(e=a.substr(r,8),r+=8):(e=null,_('"rejected"')),e===null&&(a.substr(r,7).toLowerCase()==="timeout"?(e=a.substr(r,7),r+=7):(e=null,_('"timeout"')),e===null&&(a.substr(r,6).toLowerCase()==="giveup"?(e=a.substr(r,6),r+=6):(e=null,_('"giveup"')),e===null&&(a.substr(r,10).toLowerCase()==="noresource"?(e=a.substr(r,10),r+=10):(e=null,_('"noresource"')),e===null&&(a.substr(r,9).toLowerCase()==="invariant"?(e=a.substr(r,9),r+=9):(e=null,_('"invariant"')),e===null&&(e=P()))))))),e}function Fu(){var e;return e=V(),e=e!==null?e:"",e}function ju(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e=e!==null?e:"",e}function el(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Gt()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=tl(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=tl(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O=w.tag;try{w=new b(w.uri,w.display_name,w.params),O&&w.setParam("tag",O)}catch{w=-1}}()),e===null&&(r=p),e}function tl(){var e;return e=Bi(),e===null&&(e=ze()),e}function pr(){var e,l,u,f,p,m;if(p=r,e=Ys(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=Ys(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=Ys(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Ys(){var e,l,u,f,p,m,v,S;if(v=r,e=ol(),e!==null)if(l=k(),l!==null)if(u=fl(),u!==null){for(f=[],S=r,p=ye(),p!==null?(m=mr(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=ye(),p!==null?(m=mr(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e}function mr(){var e;return e=sl(),e===null&&(e=nl(),e===null&&(e=rl(),e===null&&(e=il(),e===null&&(e=ll(),e===null&&(e=ze()))))),e}function sl(){var e,l,u,f,p;return f=r,p=r,a.substr(r,3).toLowerCase()==="ttl"?(e=a.substr(r,3),r+=3):(e=null,_('"ttl"')),e!==null?(l=re(),l!==null?(u=dl(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.ttl=v}(f,e[2])),e===null&&(r=f),e}function nl(){var e,l,u,f,p;return f=r,p=r,a.substr(r,5).toLowerCase()==="maddr"?(e=a.substr(r,5),r+=5):(e=null,_('"maddr"')),e!==null?(l=re(),l!==null?(u=Cs(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.maddr=v}(f,e[2])),e===null&&(r=f),e}function rl(){var e,l,u,f,p;return f=r,p=r,a.substr(r,8).toLowerCase()==="received"?(e=a.substr(r,8),r+=8):(e=null,_('"received"')),e!==null?(l=re(),l!==null?(u=es(),u===null&&(u=me()),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.received=v}(f,e[2])),e===null&&(r=f),e}function il(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6).toLowerCase()==="branch"?(e=a.substr(r,6),r+=6):(e=null,_('"branch"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.branch=v}(f,e[2])),e===null&&(r=f),e}function ll(){var e,l,u,f,p;return f=r,a.substr(r,5).toLowerCase()==="rport"?(e=a.substr(r,5),r+=5):(e=null,_('"rport"')),e!==null?(p=r,l=re(),l!==null?(u=al(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function al(){var e,l,u,f,p,m,v;return m=r,v=r,e=T(),e=e!==null?e:"",e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?e=[e,l,u,f,p]:(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(S,O){w.rport=parseInt(O.join(""))}(m,e)),e===null&&(r=m),e}function ol(){var e,l,u,f,p,m;return m=r,e=ul(),e!==null?(l=G(),l!==null?(u=P(),u!==null?(f=G(),f!==null?(p=cl(),p!==null?e=[e,l,u,f,p]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e}function ul(){var e,l;return l=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"SIP"')),e===null&&(e=P()),e!==null&&(e=function(u,f){w.protocol=f}(l,e)),e===null&&(r=l),e}function cl(){var e,l;return l=r,a.substr(r,3).toLowerCase()==="udp"?(e=a.substr(r,3),r+=3):(e=null,_('"UDP"')),e===null&&(a.substr(r,3).toLowerCase()==="tcp"?(e=a.substr(r,3),r+=3):(e=null,_('"TCP"')),e===null&&(a.substr(r,3).toLowerCase()==="tls"?(e=a.substr(r,3),r+=3):(e=null,_('"TLS"')),e===null&&(a.substr(r,4).toLowerCase()==="sctp"?(e=a.substr(r,4),r+=4):(e=null,_('"SCTP"')),e===null&&(e=P())))),e!==null&&(e=function(u,f){w.transport=f}(l,e)),e===null&&(r=l),e}function fl(){var e,l,u,f,p;return f=r,e=hl(),e!==null?(p=r,l=lt(),l!==null?(u=gr(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function hl(){var e,l;return l=r,e=es(),e===null&&(e=hn(),e===null&&(e=fn())),e!==null&&(e=function(u){w.host=a.substring(r,u)}(l)),e===null&&(r=l),e}function gr(){var e,l,u,f,p,m,v;return m=r,v=r,e=T(),e=e!==null?e:"",e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?e=[e,l,u,f,p]:(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(S,O){w.port=parseInt(O.join(""))}(m,e)),e===null&&(r=m),e}function dl(){var e,l,u,f,p;return f=r,p=r,e=T(),e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){return parseInt(v.join(""))}(f,e)),e===null&&(r=f),e}function qu(){var e;return e=lr(),e}function Fa(){var e,l,u,f,p,m;if(p=r,e=Tr(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=vr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=vr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Tr(){var e,l;return l=r,e=us(),e!==null&&(e=function(u,f){w.expires=f}(l,e)),e===null&&(r=l),e}function vr(){var e;return e=ja(),e===null&&(e=ze()),e}function ja(){var e,l,u,f,p;return f=r,p=r,a.substr(r,9).toLowerCase()==="refresher"?(e=a.substr(r,9),r+=9):(e=null,_('"refresher"')),e!==null?(l=re(),l!==null?(a.substr(r,3).toLowerCase()==="uac"?(u=a.substr(r,3),r+=3):(u=null,_('"uac"')),u===null&&(a.substr(r,3).toLowerCase()==="uas"?(u=a.substr(r,3),r+=3):(u=null,_('"uas"'))),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.refresher=v.toLowerCase()}(f,e[2])),e===null&&(r=f),e}function qa(){var e,l,u,f;return f=r,e=P(),e!==null?(l=B(),l!==null?(u=Va(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Va(){var e,l;for(e=[],l=J(),l===null&&(l=Z(),l===null&&(l=k()));l!==null;)e.push(l),l=J(),l===null&&(l=Z(),l===null&&(l=k()));return e}function Vu(){var e,l;for(e=[],l=A();l!==null;)e.push(l),l=A();return e}function Ba(){var e,l,u;return u=r,a.substr(r,5)==="uuid:"?(e="uuid:",r+=5):(e=null,_('"uuid:"')),e!==null?(l=Wt(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function Wt(){var e,l,u,f,p,m,v,S,O,ie,Ue;return ie=r,Ue=r,e=_l(),e!==null?(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l!==null?(u=Kt(),u!==null?(a.charCodeAt(r)===45?(f="-",r++):(f=null,_('"-"')),f!==null?(p=Kt(),p!==null?(a.charCodeAt(r)===45?(m="-",r++):(m=null,_('"-"')),m!==null?(v=Kt(),v!==null?(a.charCodeAt(r)===45?(S="-",r++):(S=null,_('"-"')),S!==null?(O=Ga(),O!==null?e=[e,l,u,f,p,m,v,S,O]:(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue),e!==null&&(e=function(Dt,Js){w=a.substring(r+5,Dt)}(ie,e[0])),e===null&&(r=ie),e}function Kt(){var e,l,u,f,p;return p=r,e=y(),e!==null?(l=y(),l!==null?(u=y(),u!==null?(f=y(),f!==null?e=[e,l,u,f]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e}function _l(){var e,l,u;return u=r,e=Kt(),e!==null?(l=Kt(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function Ga(){var e,l,u,f;return f=r,e=Kt(),e!==null?(l=Kt(),l!==null?(u=Kt(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Bu(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Gt()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=ze(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=ze(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){try{w=new b(w.uri,w.display_name,w.params)}catch{w=-1}}()),e===null&&(r=p),e}function Wa(){var e,l,u,f,p,m;if(p=r,e=Er(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=Sr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=Sr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Er(){var e,l,u,f,p,m;return f=r,p=r,e=ee(),e!==null?(m=r,a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l!==null?(u=ee(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w.call_id=a.substring(r,v)}(f)),e===null&&(r=f),e}function Sr(){var e;return e=pl(),e===null&&(e=ml(),e===null&&(e=Ka(),e===null&&(e=ze()))),e}function pl(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6)==="to-tag"?(e="to-tag",r+=6):(e=null,_('"to-tag"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.to_tag=v}(f,e[2])),e===null&&(r=f),e}function ml(){var e,l,u,f,p;return f=r,p=r,a.substr(r,8)==="from-tag"?(e="from-tag",r+=8):(e=null,_('"from-tag"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.from_tag=v}(f,e[2])),e===null&&(r=f),e}function Ka(){var e,l;return l=r,a.substr(r,10)==="early-only"?(e="early-only",r+=10):(e=null,_('"early-only"')),e!==null&&(e=function(u){w.early_only=!0}()),e===null&&(r=l),e}function Gu(e){e.sort();for(var l=null,u=[],f=0;f<e.length;f++)e[f]!==l&&(u.push(e[f]),l=e[f]);return u}function Ya(){for(var e=1,l=1,u=!1,f=0;f<Math.max(r,d);f++){var p=a.charAt(f);p===`
|
4
4
|
`?(u||e++,l=1,u=!1):p==="\r"||p==="\u2028"||p==="\u2029"?(e++,l=1,u=!0):(l++,u=!1)}return{line:e,column:l}}var Rs=bs(),b=Xa(),w={},gl=s[o]();if(gl===null||r!==a.length){var Tl=Math.max(r,d),Ja=Tl<a.length?a.charAt(Tl):null,i=Ya();return new this.SyntaxError(Gu(h),Ja,Tl,i.line,i.column),-1}return w},toSource:function(){return this._source}};return t.SyntaxError=function(n,a,o,s,r){function d(h,_){var g,T;switch(h.length){case 0:g="end of input";break;case 1:g=h[0];break;default:g=h.slice(0,h.length-1).join(", ")+" or "+h[h.length-1]}return T=_?c(_):"end of input","Expected "+g+" but "+T+" found."}this.name="SyntaxError",this.expected=n,this.found=a,this.message=d(n,a),this.offset=o,this.line=s,this.column=r},t.SyntaxError.prototype=Error.prototype,t}()),Qa}var Za,Xu;function bs(){if(Xu)return Za;Xu=1;function c(_,g){var T;if(typeof Symbol>"u"||_[Symbol.iterator]==null){if(Array.isArray(_)||(T=t(_))||g&&_&&typeof _.length=="number"){T&&(_=T);var E=0,y=function(){};return{s:y,n:function(){return E>=_.length?{done:!0}:{done:!1,value:_[E++]}},e:function($){throw $},f:y}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
5
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var
|
6
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var C=!0,I=!1,H;return{s:function(){E=g[Symbol.iterator]()},n:function(){var oe=E.next();return C=oe.done,oe},e:function(oe){I=!0,H=oe},f:function(){try{!C&&E.return!=null&&E.return()}finally{if(I)throw H}}}}function n(g,T){if(g){if(typeof g=="string")return a(g,T);var E=Object.prototype.toString.call(g).slice(8,-1);if(E==="Object"&&g.constructor&&(E=g.constructor.name),E==="Map"||E==="Set")return Array.from(g);if(E==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(E))return a(g,T)}}function a(g,T){(T==null||T>g.length)&&(T=g.length);for(var E=0,y=new Array(T);E<T;E++)y[E]=g[E];return y}var o=st,s=bs(),r=ss();Qe.str_utf8_length=function(g){return unescape(encodeURIComponent(g)).length};var d=Qe.isFunction=function(g){return g!==void 0?Object.prototype.toString.call(g)==="[object Function]":!1};Qe.isString=function(g){return g!==void 0?Object.prototype.toString.call(g)==="[object String]":!1},Qe.isDecimal=function(g){return!isNaN(g)&&parseFloat(g)===parseInt(g,10)},Qe.isEmpty=function(g){return g===null||g===""||g===void 0||Array.isArray(g)&&g.length===0||typeof g=="number"&&isNaN(g)},Qe.hasMethods=function(g){for(var T=arguments.length,E=new Array(T>1?T-1:0),y=1;y<T;y++)E[y-1]=arguments[y];for(var A=0,C=E;A<C.length;A++){var I=C[A];if(d(g[I]))return!1}return!0};var h=Qe.createRandomToken=function(g){var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:32,E,y,A="";for(E=0;E<g;E++)y=Math.random()*T|0,A+=y.toString(T);return A};Qe.newTag=function(){return h(10)},Qe.newUUID=function(){var g="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(T){var E=Math.random()*16|0,y=T==="x"?E:E&3|8;return y.toString(16)});return g},Qe.hostType=function(g){if(g){if(g=r.parse(g,"host"),g!==-1)return g.host_type}else return};var _=Qe.escapeUser=function(g){return encodeURIComponent(decodeURIComponent(g)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/")};return Qe.normalizeTarget=function(g,T){if(g){if(g instanceof s)return g;if(typeof g=="string"){var E=g.split("@"),y,A;switch(E.length){case 1:if(!T)return;y=g,A=T;break;case 2:y=E[0],A=E[1];break;default:y=E.slice(0,E.length-1).join("@"),A=E[E.length-1]}y=y.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(y)&&(y=y.replace(/[-.()]/g,"")),g="".concat(o.SIP,":").concat(_(y),"@").concat(A);var C;return(C=s.parse(g))?C:void 0}else return}else return},Qe.headerize=function(g){var T={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},E=g.toLowerCase().replace(/_/g,"-").split("-"),y="",A=E.length,C;for(C=0;C<A;C++)C!==0&&(y+="-"),y+=E[C].charAt(0).toUpperCase()+E[C].substring(1);return T[y]&&(y=T[y]),y},Qe.sipErrorCause=function(g){for(var T in o.SIP_ERROR_CAUSES)if(o.SIP_ERROR_CAUSES[T].indexOf(g)!==-1)return o.causes[T];return o.causes.SIP_FAILURE_CODE},Qe.getRandomTestNetIP=function(){function g(T,E){return Math.floor(Math.random()*(E-T+1)+T)}return"192.0.2.".concat(g(1,254))},Qe.calculateMD5=function(g){function T(pe,de){return pe<<de|pe>>>32-de}function E(pe,de){var _e=pe&2147483648,we=de&2147483648,Ne=pe&1073741824,tt=de&1073741824,He=(pe&1073741823)+(de&1073741823);return Ne&tt?He^2147483648^_e^we:Ne|tt?He&1073741824?He^3221225472^_e^we:He^1073741824^_e^we:He^_e^we}function y(pe,de,_e){return pe&de|~pe&_e}function A(pe,de,_e){return pe&_e|de&~_e}function C(pe,de,_e){return pe^de^_e}function I(pe,de,_e){return de^(pe|~_e)}function H(pe,de,_e,we,Ne,tt,He){return pe=E(pe,E(E(y(de,_e,we),Ne),He)),E(T(pe,tt),de)}function $(pe,de,_e,we,Ne,tt,He){return pe=E(pe,E(E(A(de,_e,we),Ne),He)),E(T(pe,tt),de)}function oe(pe,de,_e,we,Ne,tt,He){return pe=E(pe,E(E(C(de,_e,we),Ne),He)),E(T(pe,tt),de)}function N(pe,de,_e,we,Ne,tt,He){return pe=E(pe,E(E(I(de,_e,we),Ne),He)),E(T(pe,tt),de)}function j(pe){for(var de,_e=pe.length,we=_e+8,Ne=(we-we%64)/64,tt=(Ne+1)*16,He=new Array(tt-1),Vt=0,Ct=0;Ct<_e;)de=(Ct-Ct%4)/4,Vt=Ct%4*8,He[de]=He[de]|pe.charCodeAt(Ct)<<Vt,Ct++;return de=(Ct-Ct%4)/4,Vt=Ct%4*8,He[de]=He[de]|128<<Vt,He[tt-2]=_e<<3,He[tt-1]=_e>>>29,He}function Se(pe){var de="",_e="",we,Ne;for(Ne=0;Ne<=3;Ne++)we=pe>>>Ne*8&255,_e="0".concat(we.toString(16)),de=de+_e.substr(_e.length-2,2);return de}function ve(pe){for(var de="",_e=0;_e<pe.length;_e++){var we=pe.charCodeAt(_e);we<128?de+=String.fromCharCode(we):we>127&&we<2048?(de+=String.fromCharCode(we>>6|192),de+=String.fromCharCode(we&63|128)):(de+=String.fromCharCode(we>>12|224),de+=String.fromCharCode(we>>6&63|128),de+=String.fromCharCode(we&63|128))}return de}var k=[],D,B,V,J,F,Z,U,P,se,it=7,ee=12,Y=17,G=22,re=5,ge=9,be=14,ke=20,Re=4,le=11,ye=16,lt=23,ot=6,Ee=10,Ae=15,Ie=21;for(g=ve(g),k=j(g),Z=1732584193,U=4023233417,P=2562383102,se=271733878,D=0;D<k.length;D+=16)B=Z,V=U,J=P,F=se,Z=H(Z,U,P,se,k[D+0],it,3614090360),se=H(se,Z,U,P,k[D+1],ee,3905402710),P=H(P,se,Z,U,k[D+2],Y,606105819),U=H(U,P,se,Z,k[D+3],G,3250441966),Z=H(Z,U,P,se,k[D+4],it,4118548399),se=H(se,Z,U,P,k[D+5],ee,1200080426),P=H(P,se,Z,U,k[D+6],Y,2821735955),U=H(U,P,se,Z,k[D+7],G,4249261313),Z=H(Z,U,P,se,k[D+8],it,1770035416),se=H(se,Z,U,P,k[D+9],ee,2336552879),P=H(P,se,Z,U,k[D+10],Y,4294925233),U=H(U,P,se,Z,k[D+11],G,2304563134),Z=H(Z,U,P,se,k[D+12],it,1804603682),se=H(se,Z,U,P,k[D+13],ee,4254626195),P=H(P,se,Z,U,k[D+14],Y,2792965006),U=H(U,P,se,Z,k[D+15],G,1236535329),Z=$(Z,U,P,se,k[D+1],re,4129170786),se=$(se,Z,U,P,k[D+6],ge,3225465664),P=$(P,se,Z,U,k[D+11],be,643717713),U=$(U,P,se,Z,k[D+0],ke,3921069994),Z=$(Z,U,P,se,k[D+5],re,3593408605),se=$(se,Z,U,P,k[D+10],ge,38016083),P=$(P,se,Z,U,k[D+15],be,3634488961),U=$(U,P,se,Z,k[D+4],ke,3889429448),Z=$(Z,U,P,se,k[D+9],re,568446438),se=$(se,Z,U,P,k[D+14],ge,3275163606),P=$(P,se,Z,U,k[D+3],be,4107603335),U=$(U,P,se,Z,k[D+8],ke,1163531501),Z=$(Z,U,P,se,k[D+13],re,2850285829),se=$(se,Z,U,P,k[D+2],ge,4243563512),P=$(P,se,Z,U,k[D+7],be,1735328473),U=$(U,P,se,Z,k[D+12],ke,2368359562),Z=oe(Z,U,P,se,k[D+5],Re,4294588738),se=oe(se,Z,U,P,k[D+8],le,2272392833),P=oe(P,se,Z,U,k[D+11],ye,1839030562),U=oe(U,P,se,Z,k[D+14],lt,4259657740),Z=oe(Z,U,P,se,k[D+1],Re,2763975236),se=oe(se,Z,U,P,k[D+4],le,1272893353),P=oe(P,se,Z,U,k[D+7],ye,4139469664),U=oe(U,P,se,Z,k[D+10],lt,3200236656),Z=oe(Z,U,P,se,k[D+13],Re,681279174),se=oe(se,Z,U,P,k[D+0],le,3936430074),P=oe(P,se,Z,U,k[D+3],ye,3572445317),U=oe(U,P,se,Z,k[D+6],lt,76029189),Z=oe(Z,U,P,se,k[D+9],Re,3654602809),se=oe(se,Z,U,P,k[D+12],le,3873151461),P=oe(P,se,Z,U,k[D+15],ye,530742520),U=oe(U,P,se,Z,k[D+2],lt,3299628645),Z=N(Z,U,P,se,k[D+0],ot,4096336452),se=N(se,Z,U,P,k[D+7],Ee,1126891415),P=N(P,se,Z,U,k[D+14],Ae,2878612391),U=N(U,P,se,Z,k[D+5],Ie,4237533241),Z=N(Z,U,P,se,k[D+12],ot,1700485571),se=N(se,Z,U,P,k[D+3],Ee,2399980690),P=N(P,se,Z,U,k[D+10],Ae,4293915773),U=N(U,P,se,Z,k[D+1],Ie,2240044497),Z=N(Z,U,P,se,k[D+8],ot,1873313359),se=N(se,Z,U,P,k[D+15],Ee,4264355552),P=N(P,se,Z,U,k[D+6],Ae,2734768916),U=N(U,P,se,Z,k[D+13],Ie,1309151649),Z=N(Z,U,P,se,k[D+4],ot,4149444226),se=N(se,Z,U,P,k[D+11],Ee,3174756917),P=N(P,se,Z,U,k[D+2],Ae,718787259),U=N(U,P,se,Z,k[D+9],Ie,3951481745),Z=E(Z,B),U=E(U,V),P=E(P,J),se=E(se,F);var Oe=Se(Z)+Se(U)+Se(P)+Se(se);return Oe.toLowerCase()},Qe.closeMediaStream=function(g){if(g)try{var T;if(g.getTracks){T=g.getTracks();var E=t(T),y;try{for(E.s();!(y=E.n()).done;){var A=y.value;A.stop()}}catch(j){E.e(j)}finally{E.f()}}else{T=g.getAudioTracks();var C=t(T),I;try{for(C.s();!(I=C.n()).done;){var H=I.value;H.stop()}}catch(j){C.e(j)}finally{C.f()}T=g.getVideoTracks();var $=t(T),oe;try{for($.s();!(oe=$.n()).done;){var N=oe.value;N.stop()}}catch(j){$.e(j)}finally{$.f()}}}catch{(typeof g.stop=="function"||c(g.stop)==="object")&&g.stop()}},Qe.cloneArray=function(g){return g&&g.slice()||[]},Qe.cloneObject=function(g){var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return g&&Object.assign({},g)||T},Qe}var eo={exports:{}},Nn=typeof Reflect=="object"?Reflect:null,Zu=Nn&&typeof Nn.apply=="function"?Nn.apply:function(t,n,a){return Function.prototype.apply.call(t,n,a)},Rl;Nn&&typeof Nn.ownKeys=="function"?Rl=Nn.ownKeys:Object.getOwnPropertySymbols?Rl=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Rl=function(t){return Object.getOwnPropertyNames(t)};function Kh(c){console&&console.warn&&console.warn(c)}var ec=Number.isNaN||function(t){return t!==t};function Le(){Le.init.call(this)}eo.exports=Le,eo.exports.once=Xh,Le.EventEmitter=Le,Le.prototype._events=void 0,Le.prototype._eventsCount=0,Le.prototype._maxListeners=void 0;var tc=10;function Il(c){if(typeof c!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof c)}Object.defineProperty(Le,"defaultMaxListeners",{enumerable:!0,get:function(){return tc},set:function(c){if(typeof c!="number"||c<0||ec(c))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+c+".");tc=c}}),Le.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},Le.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||ec(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function sc(c){return c._maxListeners===void 0?Le.defaultMaxListeners:c._maxListeners}Le.prototype.getMaxListeners=function(){return sc(this)},Le.prototype.emit=function(t){for(var n=[],a=1;a<arguments.length;a++)n.push(arguments[a]);var o=t==="error",s=this._events;if(s!==void 0)o=o&&s.error===void 0;else if(!o)return!1;if(o){var r;if(n.length>0&&(r=n[0]),r instanceof Error)throw r;var d=new Error("Unhandled error."+(r?" ("+r.message+")":""));throw d.context=r,d}var h=s[t];if(h===void 0)return!1;if(typeof h=="function")Zu(h,this,n);else for(var _=h.length,g=ac(h,_),a=0;a<_;++a)Zu(g[a],this,n);return!0};function nc(c,t,n,a){var o,s,r;if(Il(n),s=c._events,s===void 0?(s=c._events=Object.create(null),c._eventsCount=0):(s.newListener!==void 0&&(c.emit("newListener",t,n.listener?n.listener:n),s=c._events),r=s[t]),r===void 0)r=s[t]=n,++c._eventsCount;else if(typeof r=="function"?r=s[t]=a?[n,r]:[r,n]:a?r.unshift(n):r.push(n),o=sc(c),o>0&&r.length>o&&!r.warned){r.warned=!0;var d=new Error("Possible EventEmitter memory leak detected. "+r.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");d.name="MaxListenersExceededWarning",d.emitter=c,d.type=t,d.count=r.length,Kh(d)}return c}Le.prototype.addListener=function(t,n){return nc(this,t,n,!1)},Le.prototype.on=Le.prototype.addListener,Le.prototype.prependListener=function(t,n){return nc(this,t,n,!0)};function Yh(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function rc(c,t,n){var a={fired:!1,wrapFn:void 0,target:c,type:t,listener:n},o=Yh.bind(a);return o.listener=n,a.wrapFn=o,o}Le.prototype.once=function(t,n){return Il(n),this.on(t,rc(this,t,n)),this},Le.prototype.prependOnceListener=function(t,n){return Il(n),this.prependListener(t,rc(this,t,n)),this},Le.prototype.removeListener=function(t,n){var a,o,s,r,d;if(Il(n),o=this._events,o===void 0)return this;if(a=o[t],a===void 0)return this;if(a===n||a.listener===n)--this._eventsCount===0?this._events=Object.create(null):(delete o[t],o.removeListener&&this.emit("removeListener",t,a.listener||n));else if(typeof a!="function"){for(s=-1,r=a.length-1;r>=0;r--)if(a[r]===n||a[r].listener===n){d=a[r].listener,s=r;break}if(s<0)return this;s===0?a.shift():Jh(a,s),a.length===1&&(o[t]=a[0]),o.removeListener!==void 0&&this.emit("removeListener",t,d||n)}return this},Le.prototype.off=Le.prototype.removeListener,Le.prototype.removeAllListeners=function(t){var n,a,o;if(a=this._events,a===void 0)return this;if(a.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):a[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete a[t]),this;if(arguments.length===0){var s=Object.keys(a),r;for(o=0;o<s.length;++o)r=s[o],r!=="removeListener"&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(n=a[t],typeof n=="function")this.removeListener(t,n);else if(n!==void 0)for(o=n.length-1;o>=0;o--)this.removeListener(t,n[o]);return this};function ic(c,t,n){var a=c._events;if(a===void 0)return[];var o=a[t];return o===void 0?[]:typeof o=="function"?n?[o.listener||o]:[o]:n?zh(o):ac(o,o.length)}Le.prototype.listeners=function(t){return ic(this,t,!0)},Le.prototype.rawListeners=function(t){return ic(this,t,!1)},Le.listenerCount=function(c,t){return typeof c.listenerCount=="function"?c.listenerCount(t):lc.call(c,t)},Le.prototype.listenerCount=lc;function lc(c){var t=this._events;if(t!==void 0){var n=t[c];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}Le.prototype.eventNames=function(){return this._eventsCount>0?Rl(this._events):[]};function ac(c,t){for(var n=new Array(t),a=0;a<t;++a)n[a]=c[a];return n}function Jh(c,t){for(;t+1<c.length;t++)c[t]=c[t+1];c.pop()}function zh(c){for(var t=new Array(c.length),n=0;n<t.length;++n)t[n]=c[n].listener||c[n];return t}function Xh(c,t){return new Promise(function(n,a){function o(r){c.removeListener(t,s),a(r)}function s(){typeof c.removeListener=="function"&&c.removeListener("error",o),n([].slice.call(arguments))}oc(c,t,s,{once:!0}),t!=="error"&&Qh(c,o,{once:!0})})}function Qh(c,t,n){typeof c.on=="function"&&oc(c,"error",t,n)}function oc(c,t,n,a){if(typeof c.on=="function")a.once?c.once(t,n):c.on(t,n);else if(typeof c.addEventListener=="function")c.addEventListener(t,function o(s){a.once&&c.removeEventListener(t,o),n(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof c)}var ct=eo.exports,to={exports:{}},so,uc;function Zh(){if(uc)return so;uc=1;var c=1e3,t=c*60,n=t*60,a=n*24,o=a*7,s=a*365.25;so=function(g,T){T=T||{};var E=typeof g;if(E==="string"&&g.length>0)return r(g);if(E==="number"&&isFinite(g))return T.long?h(g):d(g);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(g))};function r(g){if(g=String(g),!(g.length>100)){var T=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(g);if(T){var E=parseFloat(T[1]),y=(T[2]||"ms").toLowerCase();switch(y){case"years":case"year":case"yrs":case"yr":case"y":return E*s;case"weeks":case"week":case"w":return E*o;case"days":case"day":case"d":return E*a;case"hours":case"hour":case"hrs":case"hr":case"h":return E*n;case"minutes":case"minute":case"mins":case"min":case"m":return E*t;case"seconds":case"second":case"secs":case"sec":case"s":return E*c;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return E;default:return}}}}function d(g){var T=Math.abs(g);return T>=a?Math.round(g/a)+"d":T>=n?Math.round(g/n)+"h":T>=t?Math.round(g/t)+"m":T>=c?Math.round(g/c)+"s":g+"ms"}function h(g){var T=Math.abs(g);return T>=a?_(g,T,a,"day"):T>=n?_(g,T,n,"hour"):T>=t?_(g,T,t,"minute"):T>=c?_(g,T,c,"second"):g+" ms"}function _(g,T,E,y){var A=T>=E*1.5;return Math.round(g/E)+" "+y+(A?"s":"")}return so}function ed(c){n.debug=n,n.default=n,n.coerce=h,n.disable=s,n.enable=o,n.enabled=r,n.humanize=Zh(),n.destroy=_,Object.keys(c).forEach(g=>{n[g]=c[g]}),n.names=[],n.skips=[],n.formatters={};function t(g){let T=0;for(let E=0;E<g.length;E++)T=(T<<5)-T+g.charCodeAt(E),T|=0;return n.colors[Math.abs(T)%n.colors.length]}n.selectColor=t;function n(g){let T,E=null,y,A;function C(...I){if(!C.enabled)return;const H=C,$=Number(new Date),oe=$-(T||$);H.diff=oe,H.prev=T,H.curr=$,T=$,I[0]=n.coerce(I[0]),typeof I[0]!="string"&&I.unshift("%O");let N=0;I[0]=I[0].replace(/%([a-zA-Z%])/g,(Se,ve)=>{if(Se==="%%")return"%";N++;const k=n.formatters[ve];if(typeof k=="function"){const D=I[N];Se=k.call(H,D),I.splice(N,1),N--}return Se}),n.formatArgs.call(H,I),(H.log||n.log).apply(H,I)}return C.namespace=g,C.useColors=n.useColors(),C.color=n.selectColor(g),C.extend=a,C.destroy=n.destroy,Object.defineProperty(C,"enabled",{enumerable:!0,configurable:!1,get:()=>E!==null?E:(y!==n.namespaces&&(y=n.namespaces,A=n.enabled(g)),A),set:I=>{E=I}}),typeof n.init=="function"&&n.init(C),C}function a(g,T){const E=n(this.namespace+(typeof T>"u"?":":T)+g);return E.log=this.log,E}function o(g){n.save(g),n.namespaces=g,n.names=[],n.skips=[];let T;const E=(typeof g=="string"?g:"").split(/[\s,]+/),y=E.length;for(T=0;T<y;T++)E[T]&&(g=E[T].replace(/\*/g,".*?"),g[0]==="-"?n.skips.push(new RegExp("^"+g.slice(1)+"$")):n.names.push(new RegExp("^"+g+"$")))}function s(){const g=[...n.names.map(d),...n.skips.map(d).map(T=>"-"+T)].join(",");return n.enable(""),g}function r(g){if(g[g.length-1]==="*")return!0;let T,E;for(T=0,E=n.skips.length;T<E;T++)if(n.skips[T].test(g))return!1;for(T=0,E=n.names.length;T<E;T++)if(n.names[T].test(g))return!0;return!1}function d(g){return g.toString().substring(2,g.toString().length-2).replace(/\.\*\?$/,"*")}function h(g){return g instanceof Error?g.stack||g.message:g}function _(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return n.enable(n.load()),n}var td=ed;(function(c,t){t.formatArgs=a,t.save=o,t.load=s,t.useColors=n,t.storage=r(),t.destroy=(()=>{let h=!1;return()=>{h||(h=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function n(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function a(h){if(h[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+h[0]+(this.useColors?"%c ":" ")+"+"+c.exports.humanize(this.diff),!this.useColors)return;const _="color: "+this.color;h.splice(1,0,_,"color: inherit");let g=0,T=0;h[0].replace(/%[a-zA-Z%]/g,E=>{E!=="%%"&&(g++,E==="%c"&&(T=g))}),h.splice(T,0,_)}t.log=console.debug||console.log||(()=>{});function o(h){try{h?t.storage.setItem("debug",h):t.storage.removeItem("debug")}catch{}}function s(){let h;try{h=t.storage.getItem("debug")}catch{}return!h&&typeof process<"u"&&"env"in process&&(h=process.env.DEBUG),h}function r(){try{return localStorage}catch{}}c.exports=td(t);const{formatters:d}=c.exports;d.j=function(h){try{return JSON.stringify(h)}catch(_){return"[UnexpectedJSONParseError]: "+_.message}}})(to,to.exports);var Un=to.exports;function sd(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function cc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function nd(c,t,n){return t&&cc(c.prototype,t),n&&cc(c,n),c}var Pn=Un,xn="JsSIP",ft=function(){function c(t){sd(this,c),t?(this._debug=Pn.default("".concat(xn,":").concat(t)),this._warn=Pn.default("".concat(xn,":WARN:").concat(t)),this._error=Pn.default("".concat(xn,":ERROR:").concat(t))):(this._debug=Pn.default(xn),this._warn=Pn.default("".concat(xn,":WARN")),this._error=Pn.default("".concat(xn,":ERROR"))),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}return nd(c,[{key:"debug",get:function(){return this._debug}},{key:"warn",get:function(){return this._warn}},{key:"error",get:function(){return this._error}}]),c}(),Ut={},fc={},hc={exports:{}},dc=hc.exports={v:[{name:"version",reg:/^(\d*)$/}],o:[{name:"origin",reg:/^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,names:["username","sessionId","sessionVersion","netType","ipVer","address"],format:"%s %s %d %s IP%d %s"}],s:[{name:"name"}],i:[{name:"description"}],u:[{name:"uri"}],e:[{name:"email"}],p:[{name:"phone"}],z:[{name:"timezones"}],r:[{name:"repeats"}],t:[{name:"timing",reg:/^(\d*) (\d*)/,names:["start","stop"],format:"%d %d"}],c:[{name:"connection",reg:/^IN IP(\d) (\S*)/,names:["version","ip"],format:"IN IP%d %s"}],b:[{push:"bandwidth",reg:/^(TIAS|AS|CT|RR|RS):(\d*)/,names:["type","limit"],format:"%s:%s"}],m:[{reg:/^(\w*) (\d*) ([\w/]*)(?: (.*))?/,names:["type","port","protocol","payloads"],format:"%s %d %s %s"}],a:[{push:"rtp",reg:/^rtpmap:(\d*) ([\w\-.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,names:["payload","codec","rate","encoding"],format:function(c){return c.encoding?"rtpmap:%d %s/%s/%s":c.rate?"rtpmap:%d %s/%s":"rtpmap:%d %s"}},{push:"fmtp",reg:/^fmtp:(\d*) ([\S| ]*)/,names:["payload","config"],format:"fmtp:%d %s"},{name:"control",reg:/^control:(.*)/,format:"control:%s"},{name:"rtcp",reg:/^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,names:["port","netType","ipVer","address"],format:function(c){return c.address!=null?"rtcp:%d %s IP%d %s":"rtcp:%d"}},{push:"rtcpFbTrrInt",reg:/^rtcp-fb:(\*|\d*) trr-int (\d*)/,names:["payload","value"],format:"rtcp-fb:%s trr-int %d"},{push:"rtcpFb",reg:/^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/,names:["payload","type","subtype"],format:function(c){return c.subtype!=null?"rtcp-fb:%s %s %s":"rtcp-fb:%s %s"}},{push:"ext",reg:/^extmap:(\d+)(?:\/(\w+))?(?: (urn:ietf:params:rtp-hdrext:encrypt))? (\S*)(?: (\S*))?/,names:["value","direction","encrypt-uri","uri","config"],format:function(c){return"extmap:%d"+(c.direction?"/%s":"%v")+(c["encrypt-uri"]?" %s":"%v")+" %s"+(c.config?" %s":"")}},{name:"extmapAllowMixed",reg:/^(extmap-allow-mixed)/},{push:"crypto",reg:/^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,names:["id","suite","config","sessionConfig"],format:function(c){return c.sessionConfig!=null?"crypto:%d %s %s %s":"crypto:%d %s %s"}},{name:"setup",reg:/^setup:(\w*)/,format:"setup:%s"},{name:"connectionType",reg:/^connection:(new|existing)/,format:"connection:%s"},{name:"mid",reg:/^mid:([^\s]*)/,format:"mid:%s"},{name:"msid",reg:/^msid:(.*)/,format:"msid:%s"},{name:"ptime",reg:/^ptime:(\d*(?:\.\d*)*)/,format:"ptime:%d"},{name:"maxptime",reg:/^maxptime:(\d*(?:\.\d*)*)/,format:"maxptime:%d"},{name:"direction",reg:/^(sendrecv|recvonly|sendonly|inactive)/},{name:"icelite",reg:/^(ice-lite)/},{name:"iceUfrag",reg:/^ice-ufrag:(\S*)/,format:"ice-ufrag:%s"},{name:"icePwd",reg:/^ice-pwd:(\S*)/,format:"ice-pwd:%s"},{name:"fingerprint",reg:/^fingerprint:(\S*) (\S*)/,names:["type","hash"],format:"fingerprint:%s %s"},{push:"candidates",reg:/^candidate:(\S*) (\d*) (\S*) (\d*) (\S*) (\d*) typ (\S*)(?: raddr (\S*) rport (\d*))?(?: tcptype (\S*))?(?: generation (\d*))?(?: network-id (\d*))?(?: network-cost (\d*))?/,names:["foundation","component","transport","priority","ip","port","type","raddr","rport","tcptype","generation","network-id","network-cost"],format:function(c){var t="candidate:%s %d %s %d %s %d typ %s";return t+=c.raddr!=null?" raddr %s rport %d":"%v%v",t+=c.tcptype!=null?" tcptype %s":"%v",c.generation!=null&&(t+=" generation %d"),t+=c["network-id"]!=null?" network-id %d":"%v",t+=c["network-cost"]!=null?" network-cost %d":"%v",t}},{name:"endOfCandidates",reg:/^(end-of-candidates)/},{name:"remoteCandidates",reg:/^remote-candidates:(.*)/,format:"remote-candidates:%s"},{name:"iceOptions",reg:/^ice-options:(\S*)/,format:"ice-options:%s"},{push:"ssrcs",reg:/^ssrc:(\d*) ([\w_-]*)(?::(.*))?/,names:["id","attribute","value"],format:function(c){var t="ssrc:%d";return c.attribute!=null&&(t+=" %s",c.value!=null&&(t+=":%s")),t}},{push:"ssrcGroups",reg:/^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/,names:["semantics","ssrcs"],format:"ssrc-group:%s %s"},{name:"msidSemantic",reg:/^msid-semantic:\s?(\w*) (\S*)/,names:["semantic","token"],format:"msid-semantic: %s %s"},{push:"groups",reg:/^group:(\w*) (.*)/,names:["type","mids"],format:"group:%s %s"},{name:"rtcpMux",reg:/^(rtcp-mux)/},{name:"rtcpRsize",reg:/^(rtcp-rsize)/},{name:"sctpmap",reg:/^sctpmap:([\w_/]*) (\S*)(?: (\S*))?/,names:["sctpmapNumber","app","maxMessageSize"],format:function(c){return c.maxMessageSize!=null?"sctpmap:%s %s %s":"sctpmap:%s %s"}},{name:"xGoogleFlag",reg:/^x-google-flag:([^\s]*)/,format:"x-google-flag:%s"},{push:"rids",reg:/^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/,names:["id","direction","params"],format:function(c){return c.params?"rid:%s %s %s":"rid:%s %s"}},{push:"imageattrs",reg:new RegExp("^imageattr:(\\d+|\\*)[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?"),names:["pt","dir1","attrs1","dir2","attrs2"],format:function(c){return"imageattr:%s %s %s"+(c.dir2?" %s %s":"")}},{name:"simulcast",reg:new RegExp("^simulcast:(send|recv) ([a-zA-Z0-9\\-_~;,]+)(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?$"),names:["dir1","list1","dir2","list2"],format:function(c){return"simulcast:%s %s"+(c.dir2?" %s %s":"")}},{name:"simulcast_03",reg:/^simulcast:[\s\t]+([\S+\s\t]+)$/,names:["value"],format:"simulcast: %s"},{name:"framerate",reg:/^framerate:(\d+(?:$|\.\d+))/,format:"framerate:%s"},{name:"sourceFilter",reg:/^source-filter: *(excl|incl) (\S*) (IP4|IP6|\*) (\S*) (.*)/,names:["filterMode","netType","addressTypes","destAddress","srcList"],format:"source-filter: %s %s %s %s %s"},{name:"bundleOnly",reg:/^(bundle-only)/},{name:"label",reg:/^label:(.+)/,format:"label:%s"},{name:"sctpPort",reg:/^sctp-port:(\d+)$/,format:"sctp-port:%s"},{name:"maxMessageSize",reg:/^max-message-size:(\d+)$/,format:"max-message-size:%s"},{push:"tsRefClocks",reg:/^ts-refclk:([^\s=]*)(?:=(\S*))?/,names:["clksrc","clksrcExt"],format:function(c){return"ts-refclk:%s"+(c.clksrcExt!=null?"=%s":"")}},{name:"mediaClk",reg:/^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/,names:["id","mediaClockName","mediaClockValue","rateNumerator","rateDenominator"],format:function(c){var t="mediaclk:";return t+=c.id!=null?"id=%s %s":"%v%s",t+=c.mediaClockValue!=null?"=%s":"",t+=c.rateNumerator!=null?" rate=%s":"",t+=c.rateDenominator!=null?"/%s":"",t}},{name:"keywords",reg:/^keywds:(.+)$/,format:"keywds:%s"},{name:"content",reg:/^content:(.+)/,format:"content:%s"},{name:"bfcpFloorCtrl",reg:/^floorctrl:(c-only|s-only|c-s)/,format:"floorctrl:%s"},{name:"bfcpConfId",reg:/^confid:(\d+)/,format:"confid:%s"},{name:"bfcpUserId",reg:/^userid:(\d+)/,format:"userid:%s"},{name:"bfcpFloorId",reg:/^floorid:(.+) (?:m-stream|mstrm):(.+)/,names:["id","mStream"],format:"floorid:%s mstrm:%s"},{push:"invalid",names:["value"]}]};Object.keys(dc).forEach(function(c){var t=dc[c];t.forEach(function(n){n.reg||(n.reg=/(.*)/),n.format||(n.format="%s")})});var _c=hc.exports;(function(c){var t=function(d){return String(Number(d))===d?Number(d):d},n=function(d,h,_,g){if(g&&!_)h[g]=t(d[1]);else for(var T=0;T<_.length;T+=1)d[T+1]!=null&&(h[_[T]]=t(d[T+1]))},a=function(d,h,_){var g=d.name&&d.names;d.push&&!h[d.push]?h[d.push]=[]:g&&!h[d.name]&&(h[d.name]={});var T=d.push?{}:g?h[d.name]:h;n(_.match(d.reg),T,d.names,d.name),d.push&&h[d.push].push(T)},o=_c,s=RegExp.prototype.test.bind(/^([a-z])=(.*)/);c.parse=function(d){var h={},_=[],g=h;return d.split(/(\r\n|\r|\n)/).filter(s).forEach(function(T){var E=T[0],y=T.slice(2);E==="m"&&(_.push({rtp:[],fmtp:[]}),g=_[_.length-1]);for(var A=0;A<(o[E]||[]).length;A+=1){var C=o[E][A];if(C.reg.test(y))return a(C,g,y)}}),h.media=_,h};var r=function(d,h){var _=h.split(/=(.+)/,2);return _.length===2?d[_[0]]=t(_[1]):_.length===1&&h.length>1&&(d[_[0]]=void 0),d};c.parseParams=function(d){return d.split(/;\s?/).reduce(r,{})},c.parseFmtpConfig=c.parseParams,c.parsePayloads=function(d){return d.toString().split(" ").map(Number)},c.parseRemoteCandidates=function(d){for(var h=[],_=d.split(" ").map(t),g=0;g<_.length;g+=3)h.push({component:_[g],ip:_[g+1],port:_[g+2]});return h},c.parseImageAttributes=function(d){return d.split(" ").map(function(h){return h.substring(1,h.length-1).split(",").reduce(r,{})})},c.parseSimulcastStreamList=function(d){return d.split(";").map(function(h){return h.split(",").map(function(_){var g,T=!1;return _[0]!=="~"?g=t(_):(g=t(_.substring(1,_.length)),T=!0),{scid:g,paused:T}})})}})(fc);var no=_c,rd=/%[sdv%]/g,id=function(c){var t=1,n=arguments,a=n.length;return c.replace(rd,function(o){if(t>=a)return o;var s=n[t];switch(t+=1,o){case"%%":return"%";case"%s":return String(s);case"%d":return Number(s);case"%v":return""}})},Cr=function(c,t,n){var a=t.format instanceof Function?t.format(t.push?n:n[t.name]):t.format,o=[c+"="+a];if(t.names)for(var s=0;s<t.names.length;s+=1){var r=t.names[s];t.name?o.push(n[t.name][r]):o.push(n[t.names[s]])}else o.push(n[t.name]);return id.apply(null,o)},ld=["v","o","s","i","u","e","p","c","b","t","r","z","a"],ad=["i","c","b","a"],od=function(c,t){t=t||{},c.version==null&&(c.version=0),c.name==null&&(c.name=" "),c.media.forEach(function(s){s.payloads==null&&(s.payloads="")});var n=t.outerOrder||ld,a=t.innerOrder||ad,o=[];return n.forEach(function(s){no[s].forEach(function(r){r.name in c&&c[r.name]!=null?o.push(Cr(s,r,c)):r.push in c&&c[r.push]!=null&&c[r.push].forEach(function(d){o.push(Cr(s,r,d))})})}),c.media.forEach(function(s){o.push(Cr("m",no.m[0],s)),a.forEach(function(r){no[r].forEach(function(d){d.name in s&&s[d.name]!=null?o.push(Cr(r,d,s)):d.push in s&&s[d.push]!=null&&s[d.push].forEach(function(h){o.push(Cr(r,d,h))})})})}),o.join(`\r
|
5
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var C=!0,A=!1,I;return{s:function(){T=_[Symbol.iterator]()},n:function(){var $=T.next();return C=$.done,$},e:function($){A=!0,I=$},f:function(){try{!C&&T.return!=null&&T.return()}finally{if(A)throw I}}}}function t(_,g){if(_){if(typeof _=="string")return n(_,g);var T=Object.prototype.toString.call(_).slice(8,-1);if(T==="Object"&&_.constructor&&(T=_.constructor.name),T==="Map"||T==="Set")return Array.from(_);if(T==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(T))return n(_,g)}}function n(_,g){(g==null||g>_.length)&&(g=_.length);for(var T=0,E=new Array(g);T<g;T++)E[T]=_[T];return E}function a(_,g){if(!(_ instanceof g))throw new TypeError("Cannot call a class as a function")}function o(_,g){for(var T=0;T<g.length;T++){var E=g[T];E.enumerable=E.enumerable||!1,E.configurable=!0,"value"in E&&(E.writable=!0),Object.defineProperty(_,E.key,E)}}function s(_,g,T){return g&&o(_.prototype,g),T&&o(_,T),_}var r=st,d=Rt(),h=ss();return Za=function(){s(_,null,[{key:"parse",value:function(T){if(T=h.parse(T,"SIP_URI"),T!==-1)return T}}]);function _(g,T,E,y){var C=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{},A=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{};if(a(this,_),!E)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=g||r.SIP,this._user=T,this._host=E,this._port=y;for(var I in C)Object.prototype.hasOwnProperty.call(C,I)&&this.setParam(I,C[I]);for(var H in A)Object.prototype.hasOwnProperty.call(A,H)&&this.setHeader(H,A[H])}return s(_,[{key:"setParam",value:function(T,E){T&&(this._parameters[T.toLowerCase()]=typeof E>"u"||E===null?null:E.toString())}},{key:"getParam",value:function(T){if(T)return this._parameters[T.toLowerCase()]}},{key:"hasParam",value:function(T){if(T)return this._parameters.hasOwnProperty(T.toLowerCase())&&!0||!1}},{key:"deleteParam",value:function(T){if(T=T.toLowerCase(),this._parameters.hasOwnProperty(T)){var E=this._parameters[T];return delete this._parameters[T],E}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"setHeader",value:function(T,E){this._headers[d.headerize(T)]=Array.isArray(E)?E:[E]}},{key:"getHeader",value:function(T){if(T)return this._headers[d.headerize(T)]}},{key:"hasHeader",value:function(T){if(T)return this._headers.hasOwnProperty(d.headerize(T))&&!0||!1}},{key:"deleteHeader",value:function(T){if(T=d.headerize(T),this._headers.hasOwnProperty(T)){var E=this._headers[T];return delete this._headers[T],E}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new _(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var T=[],E="".concat(this._scheme,":");this._user&&(E+="".concat(d.escapeUser(this._user),"@")),E+=this._host,(this._port||this._port===0)&&(E+=":".concat(this._port));for(var y in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,y)&&(E+=";".concat(y),this._parameters[y]!==null&&(E+="=".concat(this._parameters[y])));for(var C in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,C)){var A=c(this._headers[C]),I;try{for(A.s();!(I=A.n()).done;){var H=I.value;T.push("".concat(C,"=").concat(H))}}catch($){A.e($)}finally{A.f()}}return T.length>0&&(E+="?".concat(T.join("&"))),E}},{key:"toAor",value:function(T){var E="".concat(this._scheme,":");return this._user&&(E+="".concat(d.escapeUser(this._user),"@")),E+=this._host,T&&(this._port||this._port===0)&&(E+=":".concat(this._port)),E}},{key:"scheme",get:function(){return this._scheme},set:function(T){this._scheme=T.toLowerCase()}},{key:"user",get:function(){return this._user},set:function(T){this._user=T}},{key:"host",get:function(){return this._host},set:function(T){this._host=T.toLowerCase()}},{key:"port",get:function(){return this._port},set:function(T){this._port=T===0?T:parseInt(T,10)||null}}]),_}(),Za}var Qu;function Rt(){if(Qu)return Qe;Qu=1;function c(g){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?c=function(E){return typeof E}:c=function(E){return E&&typeof Symbol=="function"&&E.constructor===Symbol&&E!==Symbol.prototype?"symbol":typeof E},c(g)}function t(g,T){var E;if(typeof Symbol>"u"||g[Symbol.iterator]==null){if(Array.isArray(g)||(E=n(g))||T&&g&&typeof g.length=="number"){E&&(g=E);var y=0,C=function(){};return{s:C,n:function(){return y>=g.length?{done:!0}:{done:!1,value:g[y++]}},e:function(oe){throw oe},f:C}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
6
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var A=!0,I=!1,H;return{s:function(){E=g[Symbol.iterator]()},n:function(){var oe=E.next();return A=oe.done,oe},e:function(oe){I=!0,H=oe},f:function(){try{!A&&E.return!=null&&E.return()}finally{if(I)throw H}}}}function n(g,T){if(g){if(typeof g=="string")return a(g,T);var E=Object.prototype.toString.call(g).slice(8,-1);if(E==="Object"&&g.constructor&&(E=g.constructor.name),E==="Map"||E==="Set")return Array.from(g);if(E==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(E))return a(g,T)}}function a(g,T){(T==null||T>g.length)&&(T=g.length);for(var E=0,y=new Array(T);E<T;E++)y[E]=g[E];return y}var o=st,s=bs(),r=ss();Qe.str_utf8_length=function(g){return unescape(encodeURIComponent(g)).length};var d=Qe.isFunction=function(g){return g!==void 0?Object.prototype.toString.call(g)==="[object Function]":!1};Qe.isString=function(g){return g!==void 0?Object.prototype.toString.call(g)==="[object String]":!1},Qe.isDecimal=function(g){return!isNaN(g)&&parseFloat(g)===parseInt(g,10)},Qe.isEmpty=function(g){return g===null||g===""||g===void 0||Array.isArray(g)&&g.length===0||typeof g=="number"&&isNaN(g)},Qe.hasMethods=function(g){for(var T=arguments.length,E=new Array(T>1?T-1:0),y=1;y<T;y++)E[y-1]=arguments[y];for(var C=0,A=E;C<A.length;C++){var I=A[C];if(d(g[I]))return!1}return!0};var h=Qe.createRandomToken=function(g){var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:32,E,y,C="";for(E=0;E<g;E++)y=Math.random()*T|0,C+=y.toString(T);return C};Qe.newTag=function(){return h(10)},Qe.newUUID=function(){var g="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(T){var E=Math.random()*16|0,y=T==="x"?E:E&3|8;return y.toString(16)});return g},Qe.hostType=function(g){if(g){if(g=r.parse(g,"host"),g!==-1)return g.host_type}else return};var _=Qe.escapeUser=function(g){return encodeURIComponent(decodeURIComponent(g)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/")};return Qe.normalizeTarget=function(g,T){if(g){if(g instanceof s)return g;if(typeof g=="string"){var E=g.split("@"),y,C;switch(E.length){case 1:if(!T)return;y=g,C=T;break;case 2:y=E[0],C=E[1];break;default:y=E.slice(0,E.length-1).join("@"),C=E[E.length-1]}y=y.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(y)&&(y=y.replace(/[-.()]/g,"")),g="".concat(o.SIP,":").concat(_(y),"@").concat(C);var A;return(A=s.parse(g))?A:void 0}else return}else return},Qe.headerize=function(g){var T={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},E=g.toLowerCase().replace(/_/g,"-").split("-"),y="",C=E.length,A;for(A=0;A<C;A++)A!==0&&(y+="-"),y+=E[A].charAt(0).toUpperCase()+E[A].substring(1);return T[y]&&(y=T[y]),y},Qe.sipErrorCause=function(g){for(var T in o.SIP_ERROR_CAUSES)if(o.SIP_ERROR_CAUSES[T].indexOf(g)!==-1)return o.causes[T];return o.causes.SIP_FAILURE_CODE},Qe.getRandomTestNetIP=function(){function g(T,E){return Math.floor(Math.random()*(E-T+1)+T)}return"192.0.2.".concat(g(1,254))},Qe.calculateMD5=function(g){function T(pe,de){return pe<<de|pe>>>32-de}function E(pe,de){var _e=pe&2147483648,we=de&2147483648,Ne=pe&1073741824,tt=de&1073741824,He=(pe&1073741823)+(de&1073741823);return Ne&tt?He^2147483648^_e^we:Ne|tt?He&1073741824?He^3221225472^_e^we:He^1073741824^_e^we:He^_e^we}function y(pe,de,_e){return pe&de|~pe&_e}function C(pe,de,_e){return pe&_e|de&~_e}function A(pe,de,_e){return pe^de^_e}function I(pe,de,_e){return de^(pe|~_e)}function H(pe,de,_e,we,Ne,tt,He){return pe=E(pe,E(E(y(de,_e,we),Ne),He)),E(T(pe,tt),de)}function $(pe,de,_e,we,Ne,tt,He){return pe=E(pe,E(E(C(de,_e,we),Ne),He)),E(T(pe,tt),de)}function oe(pe,de,_e,we,Ne,tt,He){return pe=E(pe,E(E(A(de,_e,we),Ne),He)),E(T(pe,tt),de)}function N(pe,de,_e,we,Ne,tt,He){return pe=E(pe,E(E(I(de,_e,we),Ne),He)),E(T(pe,tt),de)}function j(pe){for(var de,_e=pe.length,we=_e+8,Ne=(we-we%64)/64,tt=(Ne+1)*16,He=new Array(tt-1),Vt=0,At=0;At<_e;)de=(At-At%4)/4,Vt=At%4*8,He[de]=He[de]|pe.charCodeAt(At)<<Vt,At++;return de=(At-At%4)/4,Vt=At%4*8,He[de]=He[de]|128<<Vt,He[tt-2]=_e<<3,He[tt-1]=_e>>>29,He}function Se(pe){var de="",_e="",we,Ne;for(Ne=0;Ne<=3;Ne++)we=pe>>>Ne*8&255,_e="0".concat(we.toString(16)),de=de+_e.substr(_e.length-2,2);return de}function ve(pe){for(var de="",_e=0;_e<pe.length;_e++){var we=pe.charCodeAt(_e);we<128?de+=String.fromCharCode(we):we>127&&we<2048?(de+=String.fromCharCode(we>>6|192),de+=String.fromCharCode(we&63|128)):(de+=String.fromCharCode(we>>12|224),de+=String.fromCharCode(we>>6&63|128),de+=String.fromCharCode(we&63|128))}return de}var k=[],D,B,V,J,F,Z,U,P,se,it=7,ee=12,Y=17,G=22,re=5,ge=9,be=14,ke=20,Re=4,le=11,ye=16,lt=23,ot=6,Ee=10,Ce=15,Ie=21;for(g=ve(g),k=j(g),Z=1732584193,U=4023233417,P=2562383102,se=271733878,D=0;D<k.length;D+=16)B=Z,V=U,J=P,F=se,Z=H(Z,U,P,se,k[D+0],it,3614090360),se=H(se,Z,U,P,k[D+1],ee,3905402710),P=H(P,se,Z,U,k[D+2],Y,606105819),U=H(U,P,se,Z,k[D+3],G,3250441966),Z=H(Z,U,P,se,k[D+4],it,4118548399),se=H(se,Z,U,P,k[D+5],ee,1200080426),P=H(P,se,Z,U,k[D+6],Y,2821735955),U=H(U,P,se,Z,k[D+7],G,4249261313),Z=H(Z,U,P,se,k[D+8],it,1770035416),se=H(se,Z,U,P,k[D+9],ee,2336552879),P=H(P,se,Z,U,k[D+10],Y,4294925233),U=H(U,P,se,Z,k[D+11],G,2304563134),Z=H(Z,U,P,se,k[D+12],it,1804603682),se=H(se,Z,U,P,k[D+13],ee,4254626195),P=H(P,se,Z,U,k[D+14],Y,2792965006),U=H(U,P,se,Z,k[D+15],G,1236535329),Z=$(Z,U,P,se,k[D+1],re,4129170786),se=$(se,Z,U,P,k[D+6],ge,3225465664),P=$(P,se,Z,U,k[D+11],be,643717713),U=$(U,P,se,Z,k[D+0],ke,3921069994),Z=$(Z,U,P,se,k[D+5],re,3593408605),se=$(se,Z,U,P,k[D+10],ge,38016083),P=$(P,se,Z,U,k[D+15],be,3634488961),U=$(U,P,se,Z,k[D+4],ke,3889429448),Z=$(Z,U,P,se,k[D+9],re,568446438),se=$(se,Z,U,P,k[D+14],ge,3275163606),P=$(P,se,Z,U,k[D+3],be,4107603335),U=$(U,P,se,Z,k[D+8],ke,1163531501),Z=$(Z,U,P,se,k[D+13],re,2850285829),se=$(se,Z,U,P,k[D+2],ge,4243563512),P=$(P,se,Z,U,k[D+7],be,1735328473),U=$(U,P,se,Z,k[D+12],ke,2368359562),Z=oe(Z,U,P,se,k[D+5],Re,4294588738),se=oe(se,Z,U,P,k[D+8],le,2272392833),P=oe(P,se,Z,U,k[D+11],ye,1839030562),U=oe(U,P,se,Z,k[D+14],lt,4259657740),Z=oe(Z,U,P,se,k[D+1],Re,2763975236),se=oe(se,Z,U,P,k[D+4],le,1272893353),P=oe(P,se,Z,U,k[D+7],ye,4139469664),U=oe(U,P,se,Z,k[D+10],lt,3200236656),Z=oe(Z,U,P,se,k[D+13],Re,681279174),se=oe(se,Z,U,P,k[D+0],le,3936430074),P=oe(P,se,Z,U,k[D+3],ye,3572445317),U=oe(U,P,se,Z,k[D+6],lt,76029189),Z=oe(Z,U,P,se,k[D+9],Re,3654602809),se=oe(se,Z,U,P,k[D+12],le,3873151461),P=oe(P,se,Z,U,k[D+15],ye,530742520),U=oe(U,P,se,Z,k[D+2],lt,3299628645),Z=N(Z,U,P,se,k[D+0],ot,4096336452),se=N(se,Z,U,P,k[D+7],Ee,1126891415),P=N(P,se,Z,U,k[D+14],Ce,2878612391),U=N(U,P,se,Z,k[D+5],Ie,4237533241),Z=N(Z,U,P,se,k[D+12],ot,1700485571),se=N(se,Z,U,P,k[D+3],Ee,2399980690),P=N(P,se,Z,U,k[D+10],Ce,4293915773),U=N(U,P,se,Z,k[D+1],Ie,2240044497),Z=N(Z,U,P,se,k[D+8],ot,1873313359),se=N(se,Z,U,P,k[D+15],Ee,4264355552),P=N(P,se,Z,U,k[D+6],Ce,2734768916),U=N(U,P,se,Z,k[D+13],Ie,1309151649),Z=N(Z,U,P,se,k[D+4],ot,4149444226),se=N(se,Z,U,P,k[D+11],Ee,3174756917),P=N(P,se,Z,U,k[D+2],Ce,718787259),U=N(U,P,se,Z,k[D+9],Ie,3951481745),Z=E(Z,B),U=E(U,V),P=E(P,J),se=E(se,F);var Oe=Se(Z)+Se(U)+Se(P)+Se(se);return Oe.toLowerCase()},Qe.closeMediaStream=function(g){if(g)try{var T;if(g.getTracks){T=g.getTracks();var E=t(T),y;try{for(E.s();!(y=E.n()).done;){var C=y.value;C.stop()}}catch(j){E.e(j)}finally{E.f()}}else{T=g.getAudioTracks();var A=t(T),I;try{for(A.s();!(I=A.n()).done;){var H=I.value;H.stop()}}catch(j){A.e(j)}finally{A.f()}T=g.getVideoTracks();var $=t(T),oe;try{for($.s();!(oe=$.n()).done;){var N=oe.value;N.stop()}}catch(j){$.e(j)}finally{$.f()}}}catch{(typeof g.stop=="function"||c(g.stop)==="object")&&g.stop()}},Qe.cloneArray=function(g){return g&&g.slice()||[]},Qe.cloneObject=function(g){var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return g&&Object.assign({},g)||T},Qe}var eo={exports:{}},Nn=typeof Reflect=="object"?Reflect:null,Zu=Nn&&typeof Nn.apply=="function"?Nn.apply:function(t,n,a){return Function.prototype.apply.call(t,n,a)},Rl;Nn&&typeof Nn.ownKeys=="function"?Rl=Nn.ownKeys:Object.getOwnPropertySymbols?Rl=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Rl=function(t){return Object.getOwnPropertyNames(t)};function Kh(c){console&&console.warn&&console.warn(c)}var ec=Number.isNaN||function(t){return t!==t};function Le(){Le.init.call(this)}eo.exports=Le,eo.exports.once=Xh,Le.EventEmitter=Le,Le.prototype._events=void 0,Le.prototype._eventsCount=0,Le.prototype._maxListeners=void 0;var tc=10;function Il(c){if(typeof c!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof c)}Object.defineProperty(Le,"defaultMaxListeners",{enumerable:!0,get:function(){return tc},set:function(c){if(typeof c!="number"||c<0||ec(c))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+c+".");tc=c}}),Le.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},Le.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||ec(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function sc(c){return c._maxListeners===void 0?Le.defaultMaxListeners:c._maxListeners}Le.prototype.getMaxListeners=function(){return sc(this)},Le.prototype.emit=function(t){for(var n=[],a=1;a<arguments.length;a++)n.push(arguments[a]);var o=t==="error",s=this._events;if(s!==void 0)o=o&&s.error===void 0;else if(!o)return!1;if(o){var r;if(n.length>0&&(r=n[0]),r instanceof Error)throw r;var d=new Error("Unhandled error."+(r?" ("+r.message+")":""));throw d.context=r,d}var h=s[t];if(h===void 0)return!1;if(typeof h=="function")Zu(h,this,n);else for(var _=h.length,g=ac(h,_),a=0;a<_;++a)Zu(g[a],this,n);return!0};function nc(c,t,n,a){var o,s,r;if(Il(n),s=c._events,s===void 0?(s=c._events=Object.create(null),c._eventsCount=0):(s.newListener!==void 0&&(c.emit("newListener",t,n.listener?n.listener:n),s=c._events),r=s[t]),r===void 0)r=s[t]=n,++c._eventsCount;else if(typeof r=="function"?r=s[t]=a?[n,r]:[r,n]:a?r.unshift(n):r.push(n),o=sc(c),o>0&&r.length>o&&!r.warned){r.warned=!0;var d=new Error("Possible EventEmitter memory leak detected. "+r.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");d.name="MaxListenersExceededWarning",d.emitter=c,d.type=t,d.count=r.length,Kh(d)}return c}Le.prototype.addListener=function(t,n){return nc(this,t,n,!1)},Le.prototype.on=Le.prototype.addListener,Le.prototype.prependListener=function(t,n){return nc(this,t,n,!0)};function Yh(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function rc(c,t,n){var a={fired:!1,wrapFn:void 0,target:c,type:t,listener:n},o=Yh.bind(a);return o.listener=n,a.wrapFn=o,o}Le.prototype.once=function(t,n){return Il(n),this.on(t,rc(this,t,n)),this},Le.prototype.prependOnceListener=function(t,n){return Il(n),this.prependListener(t,rc(this,t,n)),this},Le.prototype.removeListener=function(t,n){var a,o,s,r,d;if(Il(n),o=this._events,o===void 0)return this;if(a=o[t],a===void 0)return this;if(a===n||a.listener===n)--this._eventsCount===0?this._events=Object.create(null):(delete o[t],o.removeListener&&this.emit("removeListener",t,a.listener||n));else if(typeof a!="function"){for(s=-1,r=a.length-1;r>=0;r--)if(a[r]===n||a[r].listener===n){d=a[r].listener,s=r;break}if(s<0)return this;s===0?a.shift():Jh(a,s),a.length===1&&(o[t]=a[0]),o.removeListener!==void 0&&this.emit("removeListener",t,d||n)}return this},Le.prototype.off=Le.prototype.removeListener,Le.prototype.removeAllListeners=function(t){var n,a,o;if(a=this._events,a===void 0)return this;if(a.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):a[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete a[t]),this;if(arguments.length===0){var s=Object.keys(a),r;for(o=0;o<s.length;++o)r=s[o],r!=="removeListener"&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(n=a[t],typeof n=="function")this.removeListener(t,n);else if(n!==void 0)for(o=n.length-1;o>=0;o--)this.removeListener(t,n[o]);return this};function ic(c,t,n){var a=c._events;if(a===void 0)return[];var o=a[t];return o===void 0?[]:typeof o=="function"?n?[o.listener||o]:[o]:n?zh(o):ac(o,o.length)}Le.prototype.listeners=function(t){return ic(this,t,!0)},Le.prototype.rawListeners=function(t){return ic(this,t,!1)},Le.listenerCount=function(c,t){return typeof c.listenerCount=="function"?c.listenerCount(t):lc.call(c,t)},Le.prototype.listenerCount=lc;function lc(c){var t=this._events;if(t!==void 0){var n=t[c];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}Le.prototype.eventNames=function(){return this._eventsCount>0?Rl(this._events):[]};function ac(c,t){for(var n=new Array(t),a=0;a<t;++a)n[a]=c[a];return n}function Jh(c,t){for(;t+1<c.length;t++)c[t]=c[t+1];c.pop()}function zh(c){for(var t=new Array(c.length),n=0;n<t.length;++n)t[n]=c[n].listener||c[n];return t}function Xh(c,t){return new Promise(function(n,a){function o(r){c.removeListener(t,s),a(r)}function s(){typeof c.removeListener=="function"&&c.removeListener("error",o),n([].slice.call(arguments))}oc(c,t,s,{once:!0}),t!=="error"&&Qh(c,o,{once:!0})})}function Qh(c,t,n){typeof c.on=="function"&&oc(c,"error",t,n)}function oc(c,t,n,a){if(typeof c.on=="function")a.once?c.once(t,n):c.on(t,n);else if(typeof c.addEventListener=="function")c.addEventListener(t,function o(s){a.once&&c.removeEventListener(t,o),n(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof c)}var ct=eo.exports,to={exports:{}},so,uc;function Zh(){if(uc)return so;uc=1;var c=1e3,t=c*60,n=t*60,a=n*24,o=a*7,s=a*365.25;so=function(g,T){T=T||{};var E=typeof g;if(E==="string"&&g.length>0)return r(g);if(E==="number"&&isFinite(g))return T.long?h(g):d(g);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(g))};function r(g){if(g=String(g),!(g.length>100)){var T=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(g);if(T){var E=parseFloat(T[1]),y=(T[2]||"ms").toLowerCase();switch(y){case"years":case"year":case"yrs":case"yr":case"y":return E*s;case"weeks":case"week":case"w":return E*o;case"days":case"day":case"d":return E*a;case"hours":case"hour":case"hrs":case"hr":case"h":return E*n;case"minutes":case"minute":case"mins":case"min":case"m":return E*t;case"seconds":case"second":case"secs":case"sec":case"s":return E*c;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return E;default:return}}}}function d(g){var T=Math.abs(g);return T>=a?Math.round(g/a)+"d":T>=n?Math.round(g/n)+"h":T>=t?Math.round(g/t)+"m":T>=c?Math.round(g/c)+"s":g+"ms"}function h(g){var T=Math.abs(g);return T>=a?_(g,T,a,"day"):T>=n?_(g,T,n,"hour"):T>=t?_(g,T,t,"minute"):T>=c?_(g,T,c,"second"):g+" ms"}function _(g,T,E,y){var C=T>=E*1.5;return Math.round(g/E)+" "+y+(C?"s":"")}return so}function ed(c){n.debug=n,n.default=n,n.coerce=h,n.disable=s,n.enable=o,n.enabled=r,n.humanize=Zh(),n.destroy=_,Object.keys(c).forEach(g=>{n[g]=c[g]}),n.names=[],n.skips=[],n.formatters={};function t(g){let T=0;for(let E=0;E<g.length;E++)T=(T<<5)-T+g.charCodeAt(E),T|=0;return n.colors[Math.abs(T)%n.colors.length]}n.selectColor=t;function n(g){let T,E=null,y,C;function A(...I){if(!A.enabled)return;const H=A,$=Number(new Date),oe=$-(T||$);H.diff=oe,H.prev=T,H.curr=$,T=$,I[0]=n.coerce(I[0]),typeof I[0]!="string"&&I.unshift("%O");let N=0;I[0]=I[0].replace(/%([a-zA-Z%])/g,(Se,ve)=>{if(Se==="%%")return"%";N++;const k=n.formatters[ve];if(typeof k=="function"){const D=I[N];Se=k.call(H,D),I.splice(N,1),N--}return Se}),n.formatArgs.call(H,I),(H.log||n.log).apply(H,I)}return A.namespace=g,A.useColors=n.useColors(),A.color=n.selectColor(g),A.extend=a,A.destroy=n.destroy,Object.defineProperty(A,"enabled",{enumerable:!0,configurable:!1,get:()=>E!==null?E:(y!==n.namespaces&&(y=n.namespaces,C=n.enabled(g)),C),set:I=>{E=I}}),typeof n.init=="function"&&n.init(A),A}function a(g,T){const E=n(this.namespace+(typeof T>"u"?":":T)+g);return E.log=this.log,E}function o(g){n.save(g),n.namespaces=g,n.names=[],n.skips=[];let T;const E=(typeof g=="string"?g:"").split(/[\s,]+/),y=E.length;for(T=0;T<y;T++)E[T]&&(g=E[T].replace(/\*/g,".*?"),g[0]==="-"?n.skips.push(new RegExp("^"+g.slice(1)+"$")):n.names.push(new RegExp("^"+g+"$")))}function s(){const g=[...n.names.map(d),...n.skips.map(d).map(T=>"-"+T)].join(",");return n.enable(""),g}function r(g){if(g[g.length-1]==="*")return!0;let T,E;for(T=0,E=n.skips.length;T<E;T++)if(n.skips[T].test(g))return!1;for(T=0,E=n.names.length;T<E;T++)if(n.names[T].test(g))return!0;return!1}function d(g){return g.toString().substring(2,g.toString().length-2).replace(/\.\*\?$/,"*")}function h(g){return g instanceof Error?g.stack||g.message:g}function _(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return n.enable(n.load()),n}var td=ed;(function(c,t){t.formatArgs=a,t.save=o,t.load=s,t.useColors=n,t.storage=r(),t.destroy=(()=>{let h=!1;return()=>{h||(h=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function n(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function a(h){if(h[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+h[0]+(this.useColors?"%c ":" ")+"+"+c.exports.humanize(this.diff),!this.useColors)return;const _="color: "+this.color;h.splice(1,0,_,"color: inherit");let g=0,T=0;h[0].replace(/%[a-zA-Z%]/g,E=>{E!=="%%"&&(g++,E==="%c"&&(T=g))}),h.splice(T,0,_)}t.log=console.debug||console.log||(()=>{});function o(h){try{h?t.storage.setItem("debug",h):t.storage.removeItem("debug")}catch{}}function s(){let h;try{h=t.storage.getItem("debug")}catch{}return!h&&typeof process<"u"&&"env"in process&&(h=process.env.DEBUG),h}function r(){try{return localStorage}catch{}}c.exports=td(t);const{formatters:d}=c.exports;d.j=function(h){try{return JSON.stringify(h)}catch(_){return"[UnexpectedJSONParseError]: "+_.message}}})(to,to.exports);var Un=to.exports;function sd(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function cc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function nd(c,t,n){return t&&cc(c.prototype,t),n&&cc(c,n),c}var Pn=Un,xn="JsSIP",ft=function(){function c(t){sd(this,c),t?(this._debug=Pn.default("".concat(xn,":").concat(t)),this._warn=Pn.default("".concat(xn,":WARN:").concat(t)),this._error=Pn.default("".concat(xn,":ERROR:").concat(t))):(this._debug=Pn.default(xn),this._warn=Pn.default("".concat(xn,":WARN")),this._error=Pn.default("".concat(xn,":ERROR"))),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}return nd(c,[{key:"debug",get:function(){return this._debug}},{key:"warn",get:function(){return this._warn}},{key:"error",get:function(){return this._error}}]),c}(),Ut={},fc={},hc={exports:{}},dc=hc.exports={v:[{name:"version",reg:/^(\d*)$/}],o:[{name:"origin",reg:/^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,names:["username","sessionId","sessionVersion","netType","ipVer","address"],format:"%s %s %d %s IP%d %s"}],s:[{name:"name"}],i:[{name:"description"}],u:[{name:"uri"}],e:[{name:"email"}],p:[{name:"phone"}],z:[{name:"timezones"}],r:[{name:"repeats"}],t:[{name:"timing",reg:/^(\d*) (\d*)/,names:["start","stop"],format:"%d %d"}],c:[{name:"connection",reg:/^IN IP(\d) (\S*)/,names:["version","ip"],format:"IN IP%d %s"}],b:[{push:"bandwidth",reg:/^(TIAS|AS|CT|RR|RS):(\d*)/,names:["type","limit"],format:"%s:%s"}],m:[{reg:/^(\w*) (\d*) ([\w/]*)(?: (.*))?/,names:["type","port","protocol","payloads"],format:"%s %d %s %s"}],a:[{push:"rtp",reg:/^rtpmap:(\d*) ([\w\-.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,names:["payload","codec","rate","encoding"],format:function(c){return c.encoding?"rtpmap:%d %s/%s/%s":c.rate?"rtpmap:%d %s/%s":"rtpmap:%d %s"}},{push:"fmtp",reg:/^fmtp:(\d*) ([\S| ]*)/,names:["payload","config"],format:"fmtp:%d %s"},{name:"control",reg:/^control:(.*)/,format:"control:%s"},{name:"rtcp",reg:/^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,names:["port","netType","ipVer","address"],format:function(c){return c.address!=null?"rtcp:%d %s IP%d %s":"rtcp:%d"}},{push:"rtcpFbTrrInt",reg:/^rtcp-fb:(\*|\d*) trr-int (\d*)/,names:["payload","value"],format:"rtcp-fb:%s trr-int %d"},{push:"rtcpFb",reg:/^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/,names:["payload","type","subtype"],format:function(c){return c.subtype!=null?"rtcp-fb:%s %s %s":"rtcp-fb:%s %s"}},{push:"ext",reg:/^extmap:(\d+)(?:\/(\w+))?(?: (urn:ietf:params:rtp-hdrext:encrypt))? (\S*)(?: (\S*))?/,names:["value","direction","encrypt-uri","uri","config"],format:function(c){return"extmap:%d"+(c.direction?"/%s":"%v")+(c["encrypt-uri"]?" %s":"%v")+" %s"+(c.config?" %s":"")}},{name:"extmapAllowMixed",reg:/^(extmap-allow-mixed)/},{push:"crypto",reg:/^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,names:["id","suite","config","sessionConfig"],format:function(c){return c.sessionConfig!=null?"crypto:%d %s %s %s":"crypto:%d %s %s"}},{name:"setup",reg:/^setup:(\w*)/,format:"setup:%s"},{name:"connectionType",reg:/^connection:(new|existing)/,format:"connection:%s"},{name:"mid",reg:/^mid:([^\s]*)/,format:"mid:%s"},{name:"msid",reg:/^msid:(.*)/,format:"msid:%s"},{name:"ptime",reg:/^ptime:(\d*(?:\.\d*)*)/,format:"ptime:%d"},{name:"maxptime",reg:/^maxptime:(\d*(?:\.\d*)*)/,format:"maxptime:%d"},{name:"direction",reg:/^(sendrecv|recvonly|sendonly|inactive)/},{name:"icelite",reg:/^(ice-lite)/},{name:"iceUfrag",reg:/^ice-ufrag:(\S*)/,format:"ice-ufrag:%s"},{name:"icePwd",reg:/^ice-pwd:(\S*)/,format:"ice-pwd:%s"},{name:"fingerprint",reg:/^fingerprint:(\S*) (\S*)/,names:["type","hash"],format:"fingerprint:%s %s"},{push:"candidates",reg:/^candidate:(\S*) (\d*) (\S*) (\d*) (\S*) (\d*) typ (\S*)(?: raddr (\S*) rport (\d*))?(?: tcptype (\S*))?(?: generation (\d*))?(?: network-id (\d*))?(?: network-cost (\d*))?/,names:["foundation","component","transport","priority","ip","port","type","raddr","rport","tcptype","generation","network-id","network-cost"],format:function(c){var t="candidate:%s %d %s %d %s %d typ %s";return t+=c.raddr!=null?" raddr %s rport %d":"%v%v",t+=c.tcptype!=null?" tcptype %s":"%v",c.generation!=null&&(t+=" generation %d"),t+=c["network-id"]!=null?" network-id %d":"%v",t+=c["network-cost"]!=null?" network-cost %d":"%v",t}},{name:"endOfCandidates",reg:/^(end-of-candidates)/},{name:"remoteCandidates",reg:/^remote-candidates:(.*)/,format:"remote-candidates:%s"},{name:"iceOptions",reg:/^ice-options:(\S*)/,format:"ice-options:%s"},{push:"ssrcs",reg:/^ssrc:(\d*) ([\w_-]*)(?::(.*))?/,names:["id","attribute","value"],format:function(c){var t="ssrc:%d";return c.attribute!=null&&(t+=" %s",c.value!=null&&(t+=":%s")),t}},{push:"ssrcGroups",reg:/^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/,names:["semantics","ssrcs"],format:"ssrc-group:%s %s"},{name:"msidSemantic",reg:/^msid-semantic:\s?(\w*) (\S*)/,names:["semantic","token"],format:"msid-semantic: %s %s"},{push:"groups",reg:/^group:(\w*) (.*)/,names:["type","mids"],format:"group:%s %s"},{name:"rtcpMux",reg:/^(rtcp-mux)/},{name:"rtcpRsize",reg:/^(rtcp-rsize)/},{name:"sctpmap",reg:/^sctpmap:([\w_/]*) (\S*)(?: (\S*))?/,names:["sctpmapNumber","app","maxMessageSize"],format:function(c){return c.maxMessageSize!=null?"sctpmap:%s %s %s":"sctpmap:%s %s"}},{name:"xGoogleFlag",reg:/^x-google-flag:([^\s]*)/,format:"x-google-flag:%s"},{push:"rids",reg:/^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/,names:["id","direction","params"],format:function(c){return c.params?"rid:%s %s %s":"rid:%s %s"}},{push:"imageattrs",reg:new RegExp("^imageattr:(\\d+|\\*)[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?"),names:["pt","dir1","attrs1","dir2","attrs2"],format:function(c){return"imageattr:%s %s %s"+(c.dir2?" %s %s":"")}},{name:"simulcast",reg:new RegExp("^simulcast:(send|recv) ([a-zA-Z0-9\\-_~;,]+)(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?$"),names:["dir1","list1","dir2","list2"],format:function(c){return"simulcast:%s %s"+(c.dir2?" %s %s":"")}},{name:"simulcast_03",reg:/^simulcast:[\s\t]+([\S+\s\t]+)$/,names:["value"],format:"simulcast: %s"},{name:"framerate",reg:/^framerate:(\d+(?:$|\.\d+))/,format:"framerate:%s"},{name:"sourceFilter",reg:/^source-filter: *(excl|incl) (\S*) (IP4|IP6|\*) (\S*) (.*)/,names:["filterMode","netType","addressTypes","destAddress","srcList"],format:"source-filter: %s %s %s %s %s"},{name:"bundleOnly",reg:/^(bundle-only)/},{name:"label",reg:/^label:(.+)/,format:"label:%s"},{name:"sctpPort",reg:/^sctp-port:(\d+)$/,format:"sctp-port:%s"},{name:"maxMessageSize",reg:/^max-message-size:(\d+)$/,format:"max-message-size:%s"},{push:"tsRefClocks",reg:/^ts-refclk:([^\s=]*)(?:=(\S*))?/,names:["clksrc","clksrcExt"],format:function(c){return"ts-refclk:%s"+(c.clksrcExt!=null?"=%s":"")}},{name:"mediaClk",reg:/^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/,names:["id","mediaClockName","mediaClockValue","rateNumerator","rateDenominator"],format:function(c){var t="mediaclk:";return t+=c.id!=null?"id=%s %s":"%v%s",t+=c.mediaClockValue!=null?"=%s":"",t+=c.rateNumerator!=null?" rate=%s":"",t+=c.rateDenominator!=null?"/%s":"",t}},{name:"keywords",reg:/^keywds:(.+)$/,format:"keywds:%s"},{name:"content",reg:/^content:(.+)/,format:"content:%s"},{name:"bfcpFloorCtrl",reg:/^floorctrl:(c-only|s-only|c-s)/,format:"floorctrl:%s"},{name:"bfcpConfId",reg:/^confid:(\d+)/,format:"confid:%s"},{name:"bfcpUserId",reg:/^userid:(\d+)/,format:"userid:%s"},{name:"bfcpFloorId",reg:/^floorid:(.+) (?:m-stream|mstrm):(.+)/,names:["id","mStream"],format:"floorid:%s mstrm:%s"},{push:"invalid",names:["value"]}]};Object.keys(dc).forEach(function(c){var t=dc[c];t.forEach(function(n){n.reg||(n.reg=/(.*)/),n.format||(n.format="%s")})});var _c=hc.exports;(function(c){var t=function(d){return String(Number(d))===d?Number(d):d},n=function(d,h,_,g){if(g&&!_)h[g]=t(d[1]);else for(var T=0;T<_.length;T+=1)d[T+1]!=null&&(h[_[T]]=t(d[T+1]))},a=function(d,h,_){var g=d.name&&d.names;d.push&&!h[d.push]?h[d.push]=[]:g&&!h[d.name]&&(h[d.name]={});var T=d.push?{}:g?h[d.name]:h;n(_.match(d.reg),T,d.names,d.name),d.push&&h[d.push].push(T)},o=_c,s=RegExp.prototype.test.bind(/^([a-z])=(.*)/);c.parse=function(d){var h={},_=[],g=h;return d.split(/(\r\n|\r|\n)/).filter(s).forEach(function(T){var E=T[0],y=T.slice(2);E==="m"&&(_.push({rtp:[],fmtp:[]}),g=_[_.length-1]);for(var C=0;C<(o[E]||[]).length;C+=1){var A=o[E][C];if(A.reg.test(y))return a(A,g,y)}}),h.media=_,h};var r=function(d,h){var _=h.split(/=(.+)/,2);return _.length===2?d[_[0]]=t(_[1]):_.length===1&&h.length>1&&(d[_[0]]=void 0),d};c.parseParams=function(d){return d.split(/;\s?/).reduce(r,{})},c.parseFmtpConfig=c.parseParams,c.parsePayloads=function(d){return d.toString().split(" ").map(Number)},c.parseRemoteCandidates=function(d){for(var h=[],_=d.split(" ").map(t),g=0;g<_.length;g+=3)h.push({component:_[g],ip:_[g+1],port:_[g+2]});return h},c.parseImageAttributes=function(d){return d.split(" ").map(function(h){return h.substring(1,h.length-1).split(",").reduce(r,{})})},c.parseSimulcastStreamList=function(d){return d.split(";").map(function(h){return h.split(",").map(function(_){var g,T=!1;return _[0]!=="~"?g=t(_):(g=t(_.substring(1,_.length)),T=!0),{scid:g,paused:T}})})}})(fc);var no=_c,rd=/%[sdv%]/g,id=function(c){var t=1,n=arguments,a=n.length;return c.replace(rd,function(o){if(t>=a)return o;var s=n[t];switch(t+=1,o){case"%%":return"%";case"%s":return String(s);case"%d":return Number(s);case"%v":return""}})},Ar=function(c,t,n){var a=t.format instanceof Function?t.format(t.push?n:n[t.name]):t.format,o=[c+"="+a];if(t.names)for(var s=0;s<t.names.length;s+=1){var r=t.names[s];t.name?o.push(n[t.name][r]):o.push(n[t.names[s]])}else o.push(n[t.name]);return id.apply(null,o)},ld=["v","o","s","i","u","e","p","c","b","t","r","z","a"],ad=["i","c","b","a"],od=function(c,t){t=t||{},c.version==null&&(c.version=0),c.name==null&&(c.name=" "),c.media.forEach(function(s){s.payloads==null&&(s.payloads="")});var n=t.outerOrder||ld,a=t.innerOrder||ad,o=[];return n.forEach(function(s){no[s].forEach(function(r){r.name in c&&c[r.name]!=null?o.push(Ar(s,r,c)):r.push in c&&c[r.push]!=null&&c[r.push].forEach(function(d){o.push(Ar(s,r,d))})})}),c.media.forEach(function(s){o.push(Ar("m",no.m[0],s)),a.forEach(function(r){no[r].forEach(function(d){d.name in s&&s[d.name]!=null?o.push(Ar(r,d,s)):d.push in s&&s[d.push]!=null&&s[d.push].forEach(function(h){o.push(Ar(r,d,h))})})})}),o.join(`\r
|
7
7
|
`)+`\r
|
8
8
|
`},zs=fc,ud=od;Ut.write=ud,Ut.parse=zs.parse,Ut.parseParams=zs.parseParams,Ut.parseFmtpConfig=zs.parseFmtpConfig,Ut.parsePayloads=zs.parsePayloads,Ut.parseRemoteCandidates=zs.parseRemoteCandidates,Ut.parseImageAttributes=zs.parseImageAttributes,Ut.parseSimulcastStreamList=zs.parseSimulcastStreamList;function bl(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?bl=function(n){return typeof n}:bl=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},bl(c)}function ro(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&io(c,t)}function io(c,t){return io=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},io(c,t)}function lo(c){var t=hd();return function(){var a=wl(c),o;if(t){var s=wl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return cd(this,o)}}function cd(c,t){return t&&(bl(t)==="object"||typeof t=="function")?t:fd(c)}function fd(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function hd(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function wl(c){return wl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},wl(c)}function Ht(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=dd(c))||t&&c&&typeof c.length=="number"){n&&(c=n);var a=0,o=function(){};return{s:o,n:function(){return a>=c.length?{done:!0}:{done:!1,value:c[a++]}},e:function(_){throw _},f:o}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
9
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function dd(c,t){if(c){if(typeof c=="string")return pc(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return pc(c,t)}}function pc(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}function Rr(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function mc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Ol(c,t,n){return t&&mc(c.prototype,t),n&&mc(c,n),c}var gc=Ut,_d=ft,dt=st,nt=Rt(),Tc=Xa(),pd=ss(),ao=new _d("SIPMessage"),vc=function(){function c(t,n,a,o,s,r){if(Rr(this,c),!t||!n||!a)return null;o=o||{},this.ua=a,this.headers={},this.method=t,this.ruri=n,this.body=r,this.extraHeaders=nt.cloneArray(s),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),o.route_set?this.setHeader("route",o.route_set):a.configuration.use_preloaded_route&&this.setHeader("route","<".concat(a.transport.sip_uri,";lr>")),this.setHeader("via",""),this.setHeader("max-forwards",dt.MAX_FORWARDS);var d=o.to_uri||n,h=o.to_tag?{tag:o.to_tag}:null,_=typeof o.to_display_name<"u"?o.to_display_name:null;this.to=new Tc(d,_,h),this.setHeader("to",this.to.toString());var g=o.from_uri||a.configuration.uri,T={tag:o.from_tag||nt.newTag()},E;typeof o.from_display_name<"u"?E=o.from_display_name:a.configuration.display_name?E=a.configuration.display_name:E=null,this.from=new Tc(g,E,T),this.setHeader("from",this.from.toString());var y=o.call_id||a.configuration.jssip_id+nt.createRandomToken(15);this.call_id=y,this.setHeader("call-id",y);var
|
9
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function dd(c,t){if(c){if(typeof c=="string")return pc(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return pc(c,t)}}function pc(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}function Rr(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function mc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Ol(c,t,n){return t&&mc(c.prototype,t),n&&mc(c,n),c}var gc=Ut,_d=ft,dt=st,nt=Rt(),Tc=Xa(),pd=ss(),ao=new _d("SIPMessage"),vc=function(){function c(t,n,a,o,s,r){if(Rr(this,c),!t||!n||!a)return null;o=o||{},this.ua=a,this.headers={},this.method=t,this.ruri=n,this.body=r,this.extraHeaders=nt.cloneArray(s),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),o.route_set?this.setHeader("route",o.route_set):a.configuration.use_preloaded_route&&this.setHeader("route","<".concat(a.transport.sip_uri,";lr>")),this.setHeader("via",""),this.setHeader("max-forwards",dt.MAX_FORWARDS);var d=o.to_uri||n,h=o.to_tag?{tag:o.to_tag}:null,_=typeof o.to_display_name<"u"?o.to_display_name:null;this.to=new Tc(d,_,h),this.setHeader("to",this.to.toString());var g=o.from_uri||a.configuration.uri,T={tag:o.from_tag||nt.newTag()},E;typeof o.from_display_name<"u"?E=o.from_display_name:a.configuration.display_name?E=a.configuration.display_name:E=null,this.from=new Tc(g,E,T),this.setHeader("from",this.from.toString());var y=o.call_id||a.configuration.jssip_id+nt.createRandomToken(15);this.call_id=y,this.setHeader("call-id",y);var C=o.cseq||Math.floor(Math.random()*1e4);this.cseq=C,this.setHeader("cseq","".concat(C," ").concat(t))}return Ol(c,[{key:"setHeader",value:function(n,a){for(var o=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),s=0;s<this.extraHeaders.length;s++)o.test(this.extraHeaders[s])&&this.extraHeaders.splice(s,1);this.headers[nt.headerize(n)]=Array.isArray(a)?a:[a]}},{key:"getHeader",value:function(n){var a=this.headers[nt.headerize(n)];if(a){if(a[0])return a[0]}else{var o=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),s=Ht(this.extraHeaders),r;try{for(s.s();!(r=s.n()).done;){var d=r.value;if(o.test(d))return d.substring(d.indexOf(":")+1).trim()}}catch(h){s.e(h)}finally{s.f()}}}},{key:"getHeaders",value:function(n){var a=this.headers[nt.headerize(n)],o=[];if(a){var s=Ht(a),r;try{for(s.s();!(r=s.n()).done;){var d=r.value;o.push(d)}}catch(E){s.e(E)}finally{s.f()}return o}else{var h=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),_=Ht(this.extraHeaders),g;try{for(_.s();!(g=_.n()).done;){var T=g.value;h.test(T)&&o.push(T.substring(T.indexOf(":")+1).trim())}}catch(E){_.e(E)}finally{_.f()}return o}}},{key:"hasHeader",value:function(n){if(this.headers[nt.headerize(n)])return!0;var a=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),o=Ht(this.extraHeaders),s;try{for(o.s();!(s=o.n()).done;){var r=s.value;if(a.test(r))return!0}}catch(d){o.e(d)}finally{o.f()}return!1}},{key:"parseSDP",value:function(n){return!n&&this.sdp?this.sdp:(this.sdp=gc.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){var n="".concat(this.method," ").concat(this.ruri,` SIP/2.0\r
|
10
10
|
`);for(var a in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,a)){var o=Ht(this.headers[a]),s;try{for(o.s();!(s=o.n()).done;){var r=s.value;n+="".concat(a,": ").concat(r,`\r
|
11
11
|
`)}}catch(y){o.e(y)}finally{o.f()}}var d=Ht(this.extraHeaders),h;try{for(d.s();!(h=d.n()).done;){var _=h.value;n+="".concat(_.trim(),`\r
|
12
12
|
`)}}catch(y){d.e(y)}finally{d.f()}var g=[];switch(this.method){case dt.REGISTER:g.push("path","gruu");break;case dt.INVITE:this.ua.configuration.session_timers&&g.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&g.push("gruu"),g.push("ice","replaces");break;case dt.UPDATE:this.ua.configuration.session_timers&&g.push("timer"),g.push("ice");break}g.push("outbound");var T=this.ua.configuration.user_agent||dt.USER_AGENT;if(n+="Allow: ".concat(dt.ALLOWED_METHODS,`\r
|
@@ -17,8 +17,8 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
17
17
|
`),n+=this.body}else n+=`Content-Length: 0\r
|
18
18
|
\r
|
19
19
|
`;return n}},{key:"clone",value:function(){var n=new c(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(a){n.headers[a]=this.headers[a].slice()},this),n.body=this.body,n.extraHeaders=nt.cloneArray(this.extraHeaders),n.to=this.to,n.from=this.from,n.call_id=this.call_id,n.cseq=this.cseq,n}}]),c}(),md=function(c){ro(n,c);var t=lo(n);function n(a,o,s,r,d){var h;return Rr(this,n),h=t.call(this,dt.INVITE,a,o,s,r,d),h.transaction=null,h}return Ol(n,[{key:"cancel",value:function(o){this.transaction.cancel(o)}},{key:"clone",value:function(){var o=new n(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(s){o.headers[s]=this.headers[s].slice()},this),o.body=this.body,o.extraHeaders=nt.cloneArray(this.extraHeaders),o.to=this.to,o.from=this.from,o.call_id=this.call_id,o.cseq=this.cseq,o.transaction=this.transaction,o}}]),n}(vc),Ec=function(){function c(){Rr(this,c),this.data=null,this.headers=null,this.method=null,this.via=null,this.via_branch=null,this.call_id=null,this.cseq=null,this.from=null,this.from_tag=null,this.to=null,this.to_tag=null,this.body=null,this.sdp=null}return Ol(c,[{key:"addHeader",value:function(n,a){var o={raw:a};n=nt.headerize(n),this.headers[n]?this.headers[n].push(o):this.headers[n]=[o]}},{key:"getHeader",value:function(n){var a=this.headers[nt.headerize(n)];if(a){if(a[0])return a[0].raw}else return}},{key:"getHeaders",value:function(n){var a=this.headers[nt.headerize(n)],o=[];if(!a)return[];var s=Ht(a),r;try{for(s.s();!(r=s.n()).done;){var d=r.value;o.push(d.raw)}}catch(h){s.e(h)}finally{s.f()}return o}},{key:"hasHeader",value:function(n){return!!this.headers[nt.headerize(n)]}},{key:"parseHeader",value:function(n){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(n=nt.headerize(n),this.headers[n]){if(a>=this.headers[n].length){ao.debug('not so many "'.concat(n,'" headers present'));return}}else{ao.debug('header "'.concat(n,'" not present'));return}var o=this.headers[n][a],s=o.raw;if(o.parsed)return o.parsed;var r=pd.parse(s,n.replace(/-/g,"_"));if(r===-1){this.headers[n].splice(a,1),ao.debug('error parsing "'.concat(n,'" header field with value "').concat(s,'"'));return}else return o.parsed=r,r}},{key:"s",value:function(n,a){return this.parseHeader(n,a)}},{key:"setHeader",value:function(n,a){var o={raw:a};this.headers[nt.headerize(n)]=[o]}},{key:"parseSDP",value:function(n){return!n&&this.sdp?this.sdp:(this.sdp=gc.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}]),c}(),gd=function(c){ro(n,c);var t=lo(n);function n(a){var o;return Rr(this,n),o=t.call(this),o.ua=a,o.headers={},o.ruri=null,o.transport=null,o.server_transaction=null,o}return Ol(n,[{key:"reply",value:function(o,s,r,d,h,_){var g=[],T=this.getHeader("To");if(o=o||null,s=s||null,!o||o<100||o>699)throw new TypeError("Invalid status_code: ".concat(o));if(s&&typeof s!="string"&&!(s instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(s));s=s||dt.REASON_PHRASE[o]||"",r=nt.cloneArray(r),this.ua.configuration.extra_headers&&(r=r.concat(this.ua.configuration.extra_headers));var E="SIP/2.0 ".concat(o," ").concat(s,`\r
|
20
|
-
`);if(this.method===dt.INVITE&&o>100&&o<=200){var y=this.getHeaders("record-route"),
|
21
|
-
`)}}catch(D){
|
20
|
+
`);if(this.method===dt.INVITE&&o>100&&o<=200){var y=this.getHeaders("record-route"),C=Ht(y),A;try{for(C.s();!(A=C.n()).done;){var I=A.value;E+="Record-Route: ".concat(I,`\r
|
21
|
+
`)}}catch(D){C.e(D)}finally{C.f()}}var H=this.getHeaders("via"),$=Ht(H),oe;try{for($.s();!(oe=$.n()).done;){var N=oe.value;E+="Via: ".concat(N,`\r
|
22
22
|
`)}}catch(D){$.e(D)}finally{$.f()}!this.to_tag&&o>100?T+=";tag=".concat(nt.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(T+=";tag=".concat(this.to_tag)),E+="To: ".concat(T,`\r
|
23
23
|
`),E+="From: ".concat(this.getHeader("From"),`\r
|
24
24
|
`),E+="Call-ID: ".concat(this.call_id,`\r
|
@@ -36,18 +36,18 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
36
36
|
\r
|
37
37
|
`);this.server_transaction.receiveResponse(o,E,h,_)}},{key:"reply_sl",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:null,s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:null,r=this.getHeaders("via");if(!o||o<100||o>699)throw new TypeError("Invalid status_code: ".concat(o));if(s&&typeof s!="string"&&!(s instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(s));s=s||dt.REASON_PHRASE[o]||"";var d="SIP/2.0 ".concat(o," ").concat(s,`\r
|
38
38
|
`),h=Ht(r),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;d+="Via: ".concat(g,`\r
|
39
|
-
`)}}catch(
|
39
|
+
`)}}catch(A){h.e(A)}finally{h.f()}var T=this.getHeader("To");if(!this.to_tag&&o>100?T+=";tag=".concat(nt.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(T+=";tag=".concat(this.to_tag)),d+="To: ".concat(T,`\r
|
40
40
|
`),d+="From: ".concat(this.getHeader("From"),`\r
|
41
41
|
`),d+="Call-ID: ".concat(this.call_id,`\r
|
42
42
|
`),d+="CSeq: ".concat(this.cseq," ").concat(this.method,`\r
|
43
|
-
`),this.ua.configuration.extra_headers){var E=Ht(this.ua.configuration.extra_headers),y;try{for(E.s();!(y=E.n()).done;){var
|
44
|
-
`)}}catch(
|
43
|
+
`),this.ua.configuration.extra_headers){var E=Ht(this.ua.configuration.extra_headers),y;try{for(E.s();!(y=E.n()).done;){var C=y.value;d+="".concat(C.trim(),`\r
|
44
|
+
`)}}catch(A){E.e(A)}finally{E.f()}}d+="Content-Length: ".concat(0,`\r
|
45
45
|
\r
|
46
|
-
`),this.transport.send(d)}}]),n}(Ec),Td=function(c){ro(n,c);var t=lo(n);function n(){var a;return Rr(this,n),a=t.call(this),a.headers={},a.status_code=null,a.reason_phrase=null,a}return n}(Ec),fs={OutgoingRequest:vc,InitialOutgoingInviteRequest:md,IncomingRequest:gd,IncomingResponse:Td};function vd(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Sc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Ed(c,t,n){return t&&Sc(c.prototype,t),n&&Sc(c,n),c}var Sd=ft,hs=Rt(),Yt=new Sd("DigestAuthentication"),yd=function(){function c(t){vd(this,c),this._credentials=t,this._cnonce=null,this._nc=0,this._ncHex="00000000",this._algorithm=null,this._realm=null,this._nonce=null,this._opaque=null,this._stale=null,this._qop=null,this._method=null,this._uri=null,this._ha1=null,this._response=null}return Ed(c,[{key:"get",value:function(n){switch(n){case"realm":return this._realm;case"ha1":return this._ha1;default:Yt.warn('get() | cannot get "%s" parameter',n);return}}},{key:"authenticate",value:function(n,a){var o=n.method,s=n.ruri,r=n.body,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:null;if(this._algorithm=a.algorithm,this._realm=a.realm,this._nonce=a.nonce,this._opaque=a.opaque,this._stale=a.stale,this._algorithm){if(this._algorithm!=="MD5")return Yt.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return Yt.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return Yt.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return Yt.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return Yt.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(a.qop)if(a.qop.indexOf("auth-int")>-1)this._qop="auth-int";else if(a.qop.indexOf("auth")>-1)this._qop="auth";else return Yt.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;else this._qop=null;this._method=o,this._uri=s,this._cnonce=d||hs.createRandomToken(12),this._nc+=1;var h=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-h.length)+h,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=hs.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1;var _,g;return this._qop==="auth"?(_="".concat(this._method,":").concat(this._uri),g=hs.calculateMD5(_),Yt.debug('authenticate() | using qop=auth [a2:"%s"]',_),this._response=hs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(g))):this._qop==="auth-int"?(_="".concat(this._method,":").concat(this._uri,":").concat(hs.calculateMD5(r||"")),g=hs.calculateMD5(_),Yt.debug('authenticate() | using qop=auth-int [a2:"%s"]',_),this._response=hs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(g))):this._qop===null&&(_="".concat(this._method,":").concat(this._uri),g=hs.calculateMD5(_),Yt.debug('authenticate() | using qop=null [a2:"%s"]',_),this._response=hs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(g))),Yt.debug("authenticate() | response generated"),!0}},{key:"toString",value:function(){var n=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return n.push("algorithm=".concat(this._algorithm)),n.push('username="'.concat(this._credentials.username,'"')),n.push('realm="'.concat(this._realm,'"')),n.push('nonce="'.concat(this._nonce,'"')),n.push('uri="'.concat(this._uri,'"')),n.push('response="'.concat(this._response,'"')),this._opaque&&n.push('opaque="'.concat(this._opaque,'"')),this._qop&&(n.push("qop=".concat(this._qop)),n.push('cnonce="'.concat(this._cnonce,'"')),n.push("nc=".concat(this._ncHex))),"Digest ".concat(n.join(", "))}}]),c}(),ds=500,Ad=4e3,yc=5e3,Ac={T1:ds,T2:Ad,T4:yc,TIMER_B:64*ds,TIMER_D:0*ds,TIMER_F:64*ds,TIMER_H:64*ds,TIMER_I:0*ds,TIMER_J:0*ds,TIMER_K:0*yc,TIMER_L:64*ds,TIMER_M:64*ds,PROVISIONAL_RESPONSE_INTERVAL:6e4};function Dl(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Dl=function(n){return typeof n}:Dl=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Dl(c)}function Ir(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Cc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function br(c,t,n){return t&&Cc(c.prototype,t),n&&Cc(c,n),c}function wr(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&oo(c,t)}function oo(c,t){return oo=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},oo(c,t)}function Or(c){var t=Rd();return function(){var a=Nl(c),o;if(t){var s=Nl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return Cd(this,o)}}function Cd(c,t){return t&&(Dl(t)==="object"||typeof t=="function")?t:ws(c)}function ws(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Rd(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Nl(c){return Nl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Nl(c)}var Dr=ct.EventEmitter,Nr=ft,Ur=st,Rc=fs,ns=Ac,Ic=new Nr("NonInviteClientTransaction"),Ul=new Nr("InviteClientTransaction"),Id=new Nr("AckClientTransaction"),bc=new Nr("NonInviteServerTransaction"),Pl=new Nr("InviteServerTransaction"),ue={STATUS_TRYING:1,STATUS_PROCEEDING:2,STATUS_CALLING:3,STATUS_ACCEPTED:4,STATUS_COMPLETED:5,STATUS_TERMINATED:6,STATUS_CONFIRMED:7,NON_INVITE_CLIENT:"nict",NON_INVITE_SERVER:"nist",INVITE_CLIENT:"ict",INVITE_SERVER:"ist"},bd=function(c){wr(n,c);var t=Or(n);function n(a,o,s,r){var d;Ir(this,n),d=t.call(this),d.type=ue.NON_INVITE_CLIENT,d.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),d.ua=a,d.transport=o,d.request=s,d.eventHandlers=r;var h="SIP/2.0/".concat(o.via_transport);return h+=" ".concat(a.configuration.via_host,";branch=").concat(d.id),d.request.setHeader("via",h),d.ua.newTransaction(ws(d)),d}return br(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"send",value:function(){var o=this;this.stateChanged(ue.STATUS_TRYING),this.F=setTimeout(function(){o.timer_F()},ns.TIMER_F),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){Ic.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}},{key:"timer_F",value:function(){Ic.debug("Timer F expired for transaction ".concat(this.id)),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}},{key:"timer_K",value:function(){this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"receiveResponse",value:function(o){var s=this,r=o.status_code;if(r<200)switch(this.state){case ue.STATUS_TRYING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(o);break}else switch(this.state){case ue.STATUS_TRYING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_COMPLETED),clearTimeout(this.F),r===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(o),this.K=setTimeout(function(){s.timer_K()},ns.TIMER_K);break;case ue.STATUS_COMPLETED:break}}},{key:"C",get:function(){return ue}}]),n}(Dr),wd=function(c){wr(n,c);var t=Or(n);function n(a,o,s,r){var d;Ir(this,n),d=t.call(this),d.type=ue.INVITE_CLIENT,d.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),d.ua=a,d.transport=o,d.request=s,d.eventHandlers=r,s.transaction=ws(d);var h="SIP/2.0/".concat(o.via_transport);return h+=" ".concat(a.configuration.via_host,";branch=").concat(d.id),d.request.setHeader("via",h),d.ua.newTransaction(ws(d)),d}return br(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"send",value:function(){var o=this;this.stateChanged(ue.STATUS_CALLING),this.B=setTimeout(function(){o.timer_B()},ns.TIMER_B),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==ue.STATUS_ACCEPTED&&(Ul.debug("transport error occurred, deleting transaction ".concat(this.id)),this.eventHandlers.onTransportError()),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_M",value:function(){Ul.debug("Timer M expired for transaction ".concat(this.id)),this.state===ue.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"timer_B",value:function(){Ul.debug("Timer B expired for transaction ".concat(this.id)),this.state===ue.STATUS_CALLING&&(this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}},{key:"timer_D",value:function(){Ul.debug("Timer D expired for transaction ".concat(this.id)),clearTimeout(this.B),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"sendACK",value:function(o){var s=this,r=new Rc.OutgoingRequest(Ur.ACK,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});r.setHeader("from",this.request.getHeader("from")),r.setHeader("via",this.request.getHeader("via")),r.setHeader("to",o.getHeader("to")),this.D=setTimeout(function(){s.timer_D()},ns.TIMER_D),this.transport.send(r)}},{key:"cancel",value:function(o){if(this.state===ue.STATUS_PROCEEDING){var s=new Rc.OutgoingRequest(Ur.CANCEL,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});s.setHeader("from",this.request.getHeader("from")),s.setHeader("via",this.request.getHeader("via")),s.setHeader("to",this.request.getHeader("to")),o&&s.setHeader("reason",o),this.transport.send(s)}}},{key:"receiveResponse",value:function(o){var s=this,r=o.status_code;if(r>=100&&r<=199)switch(this.state){case ue.STATUS_CALLING:this.stateChanged(ue.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(o);break;case ue.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(o);break}else if(r>=200&&r<=299)switch(this.state){case ue.STATUS_CALLING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_ACCEPTED),this.M=setTimeout(function(){s.timer_M()},ns.TIMER_M),this.eventHandlers.onReceiveResponse(o);break;case ue.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(o);break}else if(r>=300&&r<=699)switch(this.state){case ue.STATUS_CALLING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_COMPLETED),this.sendACK(o),this.eventHandlers.onReceiveResponse(o);break;case ue.STATUS_COMPLETED:this.sendACK(o);break}}},{key:"C",get:function(){return ue}}]),n}(Dr),Od=function(c){wr(n,c);var t=Or(n);function n(a,o,s,r){var d;Ir(this,n),d=t.call(this),d.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),d.transport=o,d.request=s,d.eventHandlers=r;var h="SIP/2.0/".concat(o.via_transport);return h+=" ".concat(a.configuration.via_host,";branch=").concat(d.id),d.request.setHeader("via",h),d}return br(n,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){Id.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return ue}}]),n}(Dr),Dd=function(c){wr(n,c);var t=Or(n);function n(a,o,s){var r;return Ir(this,n),r=t.call(this),r.type=ue.NON_INVITE_SERVER,r.id=s.via_branch,r.ua=a,r.transport=o,r.request=s,r.last_response="",s.server_transaction=ws(r),r.state=ue.STATUS_TRYING,a.newTransaction(ws(r)),r}return br(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"timer_J",value:function(){bc.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,bc.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(o,s,r,d){var h=this;if(o===100)switch(this.state){case ue.STATUS_TRYING:this.stateChanged(ue.STATUS_PROCEEDING),this.transport.send(s)||this.onTransportError();break;case ue.STATUS_PROCEEDING:this.last_response=s,this.transport.send(s)?r&&r():(this.onTransportError(),d&&d());break}else if(o>=200&&o<=699)switch(this.state){case ue.STATUS_TRYING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_COMPLETED),this.last_response=s,this.J=setTimeout(function(){h.timer_J()},ns.TIMER_J),this.transport.send(s)?r&&r():(this.onTransportError(),d&&d());break;case ue.STATUS_COMPLETED:break}}},{key:"C",get:function(){return ue}}]),n}(Dr),Nd=function(c){wr(n,c);var t=Or(n);function n(a,o,s){var r;return Ir(this,n),r=t.call(this),r.type=ue.INVITE_SERVER,r.id=s.via_branch,r.ua=a,r.transport=o,r.request=s,r.last_response="",s.server_transaction=ws(r),r.state=ue.STATUS_PROCEEDING,a.newTransaction(ws(r)),r.resendProvisionalTimer=null,s.reply(100),r}return br(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"timer_H",value:function(){Pl.debug("Timer H expired for transaction ".concat(this.id)),this.state===ue.STATUS_COMPLETED&&Pl.debug("ACK not received, dialog will be terminated"),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){Pl.debug("Timer L expired for transaction ".concat(this.id)),this.state===ue.STATUS_ACCEPTED&&(this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,Pl.debug("transport error occurred, deleting transaction ".concat(this.id)),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"resend_provisional",value:function(){this.transport.send(this.last_response)||this.onTransportError()}},{key:"receiveResponse",value:function(o,s,r,d){var h=this;if(o>=100&&o<=199)switch(this.state){case ue.STATUS_PROCEEDING:this.transport.send(s)||this.onTransportError(),this.last_response=s;break}if(o>100&&o<=199&&this.state===ue.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(function(){h.resend_provisional()},ns.PROVISIONAL_RESPONSE_INTERVAL));else if(o>=200&&o<=299)switch(this.state){case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_ACCEPTED),this.last_response=s,this.L=setTimeout(function(){h.timer_L()},ns.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case ue.STATUS_ACCEPTED:this.transport.send(s)?r&&r():(this.onTransportError(),d&&d());break}else if(o>=300&&o<=699)switch(this.state){case ue.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(s)?(this.stateChanged(ue.STATUS_COMPLETED),this.H=setTimeout(function(){h.timer_H()},ns.TIMER_H),r&&r()):(this.onTransportError(),d&&d());break}}},{key:"C",get:function(){return ue}}]),n}(Dr);function Ud(c,t){var n=c._transactions,a;switch(t.method){case Ur.INVITE:if(a=n.ist[t.via_branch],a){switch(a.state){case ue.STATUS_PROCEEDING:a.transport.send(a.last_response);break;case ue.STATUS_ACCEPTED:break}return!0}break;case Ur.ACK:if(a=n.ist[t.via_branch],a){if(a.state===ue.STATUS_ACCEPTED)return!1;if(a.state===ue.STATUS_COMPLETED)return a.state=ue.STATUS_CONFIRMED,a.I=setTimeout(function(){a.timer_I()},ns.TIMER_I),!0}else return!1;break;case Ur.CANCEL:return a=n.ist[t.via_branch],a?(t.reply_sl(200),a.state!==ue.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(a=n.nist[t.via_branch],a){switch(a.state){case ue.STATUS_TRYING:break;case ue.STATUS_PROCEEDING:case ue.STATUS_COMPLETED:a.transport.send(a.last_response);break}return!0}break}}var Pr={C:ue,NonInviteClientTransaction:bd,InviteClientTransaction:wd,AckClientTransaction:Od,NonInviteServerTransaction:Dd,InviteServerTransaction:Nd,checkTransaction:Ud};function Pd(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function wc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function xd(c,t,n){return t&&wc(c.prototype,t),n&&wc(c,n),c}var kd=ft,Oc=st,Md=yd,uo=Pr,Ld=new kd("RequestSender"),co={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}},xr=function(){function c(t,n,a){Pd(this,c),this._ua=t,this._eventHandlers=a,this._method=n.method,this._request=n,this._auth=null,this._challenged=!1,this._staled=!1;for(var o in co)Object.prototype.hasOwnProperty.call(co,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=co[o]));t.status===t.C.STATUS_USER_CLOSED&&(this._method!==Oc.BYE||this._method!==Oc.ACK)&&this._eventHandlers.onTransportError()}return xd(c,[{key:"send",value:function(){var n=this,a={onRequestTimeout:function(){n._eventHandlers.onRequestTimeout()},onTransportError:function(){n._eventHandlers.onTransportError()},onReceiveResponse:function(s){n._receiveResponse(s)}};switch(this._method){case"INVITE":this.clientTransaction=new uo.InviteClientTransaction(this._ua,this._ua.transport,this._request,a);break;case"ACK":this.clientTransaction=new uo.AckClientTransaction(this._ua,this._ua.transport,this._request,a);break;default:this.clientTransaction=new uo.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,a)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}},{key:"_receiveResponse",value:function(n){var a,o,s=n.status_code;if((s===401||s===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(n.status_code===401?(a=n.parseHeader("www-authenticate"),o="authorization"):(a=n.parseHeader("proxy-authenticate"),o="proxy-authorization"),!a){Ld.debug("".concat(n.status_code," with wrong or missing challenge, cannot authenticate")),this._eventHandlers.onReceiveResponse(n);return}if(!this._challenged||!this._staled&&a.stale===!0){if(this._auth||(this._auth=new Md({username:this._ua.configuration.authorization_user,password:this._ua.configuration.password,realm:this._ua.configuration.realm,ha1:this._ua.configuration.ha1})),!this._auth.authenticate(this._request,a)){this._eventHandlers.onReceiveResponse(n);return}this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),a.stale&&(this._staled=!0),this._request=this._request.clone(),this._request.cseq+=1,this._request.setHeader("cseq","".concat(this._request.cseq," ").concat(this._method)),this._request.setHeader(o,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(n)}else this._eventHandlers.onReceiveResponse(n)}}]),c}();function $d(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Dc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Hd(c,t,n){return t&&Dc(c.prototype,t),n&&Dc(c,n),c}var Fd=ft,fo=Rt(),Xs=st,Nc=fs,Uc=xr,kr=new Fd("Registrator"),xl=10,jd=function(){function c(t,n){$d(this,c),this._reg_id=1,this._ua=t,this._transport=n,this._registrar=t.configuration.registrar_server,this._expires=t.configuration.register_expires,this._call_id=fo.createRandomToken(22),this._cseq=0,this._to_uri=t.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString(),this._contact+=";+sip.ice",this._extraHeaders=[],this._extraContactParams="",this._sipInstance='"<urn:uuid:'.concat(this._ua.configuration.instance_id,'>"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}return Hd(c,[{key:"setExtraHeaders",value:function(n){Array.isArray(n)||(n=[]),this._extraHeaders=n.slice()}},{key:"setExtraContactParams",value:function(n){n instanceof Object||(n={}),this._extraContactParams="";for(var a in n)if(Object.prototype.hasOwnProperty.call(n,a)){var o=n[a];this._extraContactParams+=";".concat(a),o&&(this._extraContactParams+="=".concat(o))}}},{key:"register",value:function(){var n=this;if(this._registering){kr.debug("Register request in progress...");return}var a=this._extraHeaders.slice();a.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),a.push("Expires: ".concat(this._expires));var o=new Nc.OutgoingRequest(Xs.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},a),s=new Uc(this._ua,o,{onRequestTimeout:function(){n._registrationFailure(null,Xs.causes.REQUEST_TIMEOUT)},onTransportError:function(){n._registrationFailure(null,Xs.causes.CONNECTION_ERROR)},onAuthenticated:function(){n._cseq+=1},onReceiveResponse:function(d){if(d.cseq===n._cseq)switch(n._registrationTimer!==null&&(clearTimeout(n._registrationTimer),n._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(d.status_code):break;case/^2[0-9]{2}$/.test(d.status_code):{if(n._registering=!1,!d.hasHeader("Contact")){kr.debug("no Contact header in response to REGISTER, response ignored");break}var h=d.headers.Contact.reduce(function(y,A){return y.concat(A.parsed)},[]),_=h.find(function(y){return n._sipInstance===y.getParam("+sip.instance")&&n._reg_id===parseInt(y.getParam("reg-id"))});if(_||(_=h.find(function(y){return y.uri.user===n._ua.contact.uri.user})),!_){kr.debug("no Contact header pointing to us, response ignored");break}var g=_.getParam("expires");!g&&d.hasHeader("expires")&&(g=d.getHeader("expires")),g||(g=n._expires),g=Number(g),g<xl&&(g=xl);var T=g>64?g*1e3/2+Math.floor((g/2-32)*1e3*Math.random()):g*1e3-5e3;n._registrationTimer=setTimeout(function(){n._registrationTimer=null,n._ua.listeners("registrationExpiring").length===0?n.register():n._ua.emit("registrationExpiring")},T),_.hasParam("temp-gruu")&&(n._ua.contact.temp_gruu=_.getParam("temp-gruu").replace(/"/g,"")),_.hasParam("pub-gruu")&&(n._ua.contact.pub_gruu=_.getParam("pub-gruu").replace(/"/g,"")),n._registered||(n._registered=!0,n._ua.registered({response:d}));break}case/^423$/.test(d.status_code):{d.hasHeader("min-expires")?(n._expires=Number(d.getHeader("min-expires")),n._expires<xl&&(n._expires=xl),n.register()):(kr.debug("423 response received for REGISTER without Min-Expires"),n._registrationFailure(d,Xs.causes.SIP_FAILURE_CODE));break}default:{var E=fo.sipErrorCause(d.status_code);n._registrationFailure(d,E)}}}});this._registering=!0,s.send()}},{key:"unregister",value:function(){var n=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!this._registered){kr.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);var o=this._extraHeaders.slice();a.all?o.push("Contact: *".concat(this._extraContactParams)):o.push("Contact: ".concat(this._contact,";expires=0").concat(this._extraContactParams)),o.push("Expires: 0");var s=new Nc.OutgoingRequest(Xs.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},o),r=new Uc(this._ua,s,{onRequestTimeout:function(){n._unregistered(null,Xs.causes.REQUEST_TIMEOUT)},onTransportError:function(){n._unregistered(null,Xs.causes.CONNECTION_ERROR)},onAuthenticated:function(){n._cseq+=1},onReceiveResponse:function(h){switch(!0){case/^1[0-9]{2}$/.test(h.status_code):break;case/^2[0-9]{2}$/.test(h.status_code):n._unregistered(h);break;default:{var _=fo.sipErrorCause(h.status_code);n._unregistered(h,_)}}}});r.send()}},{key:"close",value:function(){this._registered&&this.unregister()}},{key:"onTransportClosed",value:function(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}},{key:"_registrationFailure",value:function(n,a){this._registering=!1,this._ua.registrationFailed({response:n||null,cause:a}),this._registered&&(this._registered=!1,this._ua.unregistered({response:n||null,cause:a}))}},{key:"_unregistered",value:function(n,a){this._registering=!1,this._registered=!1,this._ua.unregistered({response:n||null,cause:a||null})}},{key:"registered",get:function(){return this._registered}}]),c}();function qd(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Pc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Vd(c,t,n){return t&&Pc(c.prototype,t),n&&Pc(c,n),c}var ho=st,kl=Pr,Bd=xr,_o={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}},Gd=function(){function c(t,n,a){qd(this,c),this._dialog=t,this._ua=t._ua,this._request=n,this._eventHandlers=a,this._reattempt=!1,this._reattemptTimer=null;for(var o in _o)Object.prototype.hasOwnProperty.call(_o,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=_o[o]))}return Vd(c,[{key:"send",value:function(){var n=this,a=new Bd(this._ua,this._request,{onRequestTimeout:function(){n._eventHandlers.onRequestTimeout()},onTransportError:function(){n._eventHandlers.onTransportError()},onAuthenticated:function(r){n._eventHandlers.onAuthenticated(r)},onReceiveResponse:function(r){n._receiveResponse(r)}});if(a.send(),(this._request.method===ho.INVITE||this._request.method===ho.UPDATE&&this._request.body)&&a.clientTransaction.state!==kl.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;var o=function s(){(a.clientTransaction.state===kl.C.STATUS_ACCEPTED||a.clientTransaction.state===kl.C.STATUS_COMPLETED||a.clientTransaction.state===kl.C.STATUS_TERMINATED)&&(a.clientTransaction.removeListener("stateChanged",s),n._dialog.uac_pending_reply=!1)};a.clientTransaction.on("stateChanged",o)}}},{key:"_receiveResponse",value:function(n){var a=this;n.status_code===408||n.status_code===481?this._eventHandlers.onDialogError(n):n.method===ho.INVITE&&n.status_code===491?this._reattempt?n.status_code>=200&&n.status_code<300?this._eventHandlers.onSuccessResponse(n):n.status_code>=300&&this._eventHandlers.onErrorResponse(n):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(function(){a._dialog.isTerminated()||(a._reattempt=!0,a.send())},1e3)):n.status_code>=200&&n.status_code<300?this._eventHandlers.onSuccessResponse(n):n.status_code>=300&&this._eventHandlers.onErrorResponse(n)}},{key:"request",get:function(){return this._request}}]),c}();function Wd(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function xc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function kc(c,t,n){return t&&xc(c.prototype,t),n&&xc(c,n),c}var Kd=ft,Mc=fs,Os=st,Mr=Pr,Yd=Gd,po=Rt(),mo=new Kd("Dialog"),Ds={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3},Jd=function(){kc(c,null,[{key:"C",get:function(){return Ds}}]);function c(t,n,a){var o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:Ds.STATUS_CONFIRMED;if(Wd(this,c),this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!n.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};n instanceof Mc.IncomingResponse&&(o=n.status_code<200?Ds.STATUS_EARLY:Ds.STATUS_CONFIRMED);var s=n.parseHeader("contact");a==="UAS"?(this._id={call_id:n.call_id,local_tag:n.to_tag,remote_tag:n.from_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri,this._remote_target=s.uri,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):a==="UAC"&&(this._id={call_id:n.call_id,local_tag:n.from_tag,remote_tag:n.to_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=s.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),mo.debug("new ".concat(a," dialog created with status ").concat(this._state===Ds.STATUS_EARLY?"EARLY":"CONFIRMED"))}return kc(c,[{key:"isTerminated",value:function(){return this._status===Ds.STATUS_TERMINATED}},{key:"update",value:function(n,a){this._state=Ds.STATUS_CONFIRMED,mo.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),a==="UAC"&&(this._route_set=n.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){mo.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this),this._state=Ds.STATUS_TERMINATED}},{key:"sendRequest",value:function(n){var a=this,o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},s=po.cloneArray(o.extraHeaders),r=po.cloneObject(o.eventHandlers),d=o.body||null,h=this._createRequest(n,s,d);r.onAuthenticated=function(){a._local_seqnum+=1};var _=new Yd(this,h,r);return _.send(),h}},{key:"receiveRequest",value:function(n){this._checkInDialogRequest(n)&&(n.method===Os.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:n.method===Os.INVITE&&(this._ack_seqnum=n.cseq),this._owner.receiveRequest(n))}},{key:"_createRequest",value:function(n,a,o){a=po.cloneArray(a),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));var s=n===Os.CANCEL||n===Os.ACK?this._local_seqnum:this._local_seqnum+=1,r=new Mc.OutgoingRequest(n,this._remote_target,this._ua,{cseq:s,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},a,o);return r}},{key:"_checkInDialogRequest",value:function(n){var a=this;if(!this._remote_seqnum)this._remote_seqnum=n.cseq;else if(n.cseq<this._remote_seqnum)if(n.method===Os.ACK){if(this._ack_seqnum===null||n.cseq!==this._ack_seqnum)return!1}else return n.reply(500),!1;else n.cseq>this._remote_seqnum&&(this._remote_seqnum=n.cseq);if(n.method===Os.INVITE||n.method===Os.UPDATE&&n.body){if(this._uac_pending_reply===!0)n.reply(491);else if(this._uas_pending_reply===!0){var o=(Math.random()*10|0)+1;return n.reply(500,null,["Retry-After:".concat(o)]),!1}else{this._uas_pending_reply=!0;var s=function r(){(n.server_transaction.state===Mr.C.STATUS_ACCEPTED||n.server_transaction.state===Mr.C.STATUS_COMPLETED||n.server_transaction.state===Mr.C.STATUS_TERMINATED)&&(n.server_transaction.removeListener("stateChanged",r),a._uas_pending_reply=!1)};n.server_transaction.on("stateChanged",s)}n.hasHeader("contact")&&n.server_transaction.on("stateChanged",function(){n.server_transaction.state===Mr.C.STATUS_ACCEPTED&&(a._remote_target=n.parseHeader("contact").uri)})}else n.method===Os.NOTIFY&&n.hasHeader("contact")&&n.server_transaction.on("stateChanged",function(){n.server_transaction.state===Mr.C.STATUS_COMPLETED&&(a._remote_target=n.parseHeader("contact").uri)});return!0}},{key:"id",get:function(){return this._id}},{key:"local_seqnum",get:function(){return this._local_seqnum},set:function(n){this._local_seqnum=n}},{key:"owner",get:function(){return this._owner}},{key:"uac_pending_reply",get:function(){return this._uac_pending_reply},set:function(n){this._uac_pending_reply=n}},{key:"uas_pending_reply",get:function(){return this._uas_pending_reply}}]),c}(),go={exports:{}};function Ml(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ml=function(n){return typeof n}:Ml=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Ml(c)}function zd(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Lc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Xd(c,t,n){return t&&Lc(c.prototype,t),n&&Lc(c,n),c}function Qd(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&To(c,t)}function To(c,t){return To=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},To(c,t)}function Zd(c){var t=s_();return function(){var a=Ll(c),o;if(t){var s=Ll(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return e_(this,o)}}function e_(c,t){return t&&(Ml(t)==="object"||typeof t=="function")?t:t_(c)}function t_(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function s_(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Ll(c){return Ll=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Ll(c)}var n_=ct.EventEmitter,r_=ft,i_=st,l_=Is,$c=Rt(),a_=new r_("RTCSession:DTMF"),Hc={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};go.exports=function(c){Qd(n,c);var t=Zd(n);function n(a){var o;return zd(this,n),o=t.call(this),o._session=a,o._direction=null,o._tone=null,o._duration=null,o._request=null,o}return Xd(n,[{key:"send",value:function(o){var s=this,r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(o===void 0)throw new TypeError("Not enough arguments");if(this._direction="outgoing",this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new l_.InvalidStateError(this._session.status);var d=$c.cloneArray(r.extraHeaders);if(this.eventHandlers=$c.cloneObject(r.eventHandlers),typeof o=="string")o=o.toUpperCase();else if(typeof o=="number")o=o.toString();else throw new TypeError("Invalid tone: ".concat(o));if(o.match(/^[0-9A-DR#*]$/))this._tone=o;else throw new TypeError("Invalid tone: ".concat(o));this._duration=r.duration,d.push("Content-Type: application/dtmf-relay");var h="Signal=".concat(this._tone,`\r
|
46
|
+
`),this.transport.send(d)}}]),n}(Ec),Td=function(c){ro(n,c);var t=lo(n);function n(){var a;return Rr(this,n),a=t.call(this),a.headers={},a.status_code=null,a.reason_phrase=null,a}return n}(Ec),fs={OutgoingRequest:vc,InitialOutgoingInviteRequest:md,IncomingRequest:gd,IncomingResponse:Td};function vd(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Sc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Ed(c,t,n){return t&&Sc(c.prototype,t),n&&Sc(c,n),c}var Sd=ft,hs=Rt(),Yt=new Sd("DigestAuthentication"),yd=function(){function c(t){vd(this,c),this._credentials=t,this._cnonce=null,this._nc=0,this._ncHex="00000000",this._algorithm=null,this._realm=null,this._nonce=null,this._opaque=null,this._stale=null,this._qop=null,this._method=null,this._uri=null,this._ha1=null,this._response=null}return Ed(c,[{key:"get",value:function(n){switch(n){case"realm":return this._realm;case"ha1":return this._ha1;default:Yt.warn('get() | cannot get "%s" parameter',n);return}}},{key:"authenticate",value:function(n,a){var o=n.method,s=n.ruri,r=n.body,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:null;if(this._algorithm=a.algorithm,this._realm=a.realm,this._nonce=a.nonce,this._opaque=a.opaque,this._stale=a.stale,this._algorithm){if(this._algorithm!=="MD5")return Yt.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return Yt.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return Yt.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return Yt.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return Yt.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(a.qop)if(a.qop.indexOf("auth-int")>-1)this._qop="auth-int";else if(a.qop.indexOf("auth")>-1)this._qop="auth";else return Yt.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;else this._qop=null;this._method=o,this._uri=s,this._cnonce=d||hs.createRandomToken(12),this._nc+=1;var h=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-h.length)+h,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=hs.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1;var _,g;return this._qop==="auth"?(_="".concat(this._method,":").concat(this._uri),g=hs.calculateMD5(_),Yt.debug('authenticate() | using qop=auth [a2:"%s"]',_),this._response=hs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(g))):this._qop==="auth-int"?(_="".concat(this._method,":").concat(this._uri,":").concat(hs.calculateMD5(r||"")),g=hs.calculateMD5(_),Yt.debug('authenticate() | using qop=auth-int [a2:"%s"]',_),this._response=hs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(g))):this._qop===null&&(_="".concat(this._method,":").concat(this._uri),g=hs.calculateMD5(_),Yt.debug('authenticate() | using qop=null [a2:"%s"]',_),this._response=hs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(g))),Yt.debug("authenticate() | response generated"),!0}},{key:"toString",value:function(){var n=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return n.push("algorithm=".concat(this._algorithm)),n.push('username="'.concat(this._credentials.username,'"')),n.push('realm="'.concat(this._realm,'"')),n.push('nonce="'.concat(this._nonce,'"')),n.push('uri="'.concat(this._uri,'"')),n.push('response="'.concat(this._response,'"')),this._opaque&&n.push('opaque="'.concat(this._opaque,'"')),this._qop&&(n.push("qop=".concat(this._qop)),n.push('cnonce="'.concat(this._cnonce,'"')),n.push("nc=".concat(this._ncHex))),"Digest ".concat(n.join(", "))}}]),c}(),ds=500,Cd=4e3,yc=5e3,Cc={T1:ds,T2:Cd,T4:yc,TIMER_B:64*ds,TIMER_D:0*ds,TIMER_F:64*ds,TIMER_H:64*ds,TIMER_I:0*ds,TIMER_J:0*ds,TIMER_K:0*yc,TIMER_L:64*ds,TIMER_M:64*ds,PROVISIONAL_RESPONSE_INTERVAL:6e4};function Dl(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Dl=function(n){return typeof n}:Dl=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Dl(c)}function Ir(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Ac(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function br(c,t,n){return t&&Ac(c.prototype,t),n&&Ac(c,n),c}function wr(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&oo(c,t)}function oo(c,t){return oo=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},oo(c,t)}function Or(c){var t=Rd();return function(){var a=Nl(c),o;if(t){var s=Nl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return Ad(this,o)}}function Ad(c,t){return t&&(Dl(t)==="object"||typeof t=="function")?t:ws(c)}function ws(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Rd(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Nl(c){return Nl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Nl(c)}var Dr=ct.EventEmitter,Nr=ft,Ur=st,Rc=fs,ns=Cc,Ic=new Nr("NonInviteClientTransaction"),Ul=new Nr("InviteClientTransaction"),Id=new Nr("AckClientTransaction"),bc=new Nr("NonInviteServerTransaction"),Pl=new Nr("InviteServerTransaction"),ue={STATUS_TRYING:1,STATUS_PROCEEDING:2,STATUS_CALLING:3,STATUS_ACCEPTED:4,STATUS_COMPLETED:5,STATUS_TERMINATED:6,STATUS_CONFIRMED:7,NON_INVITE_CLIENT:"nict",NON_INVITE_SERVER:"nist",INVITE_CLIENT:"ict",INVITE_SERVER:"ist"},bd=function(c){wr(n,c);var t=Or(n);function n(a,o,s,r){var d;Ir(this,n),d=t.call(this),d.type=ue.NON_INVITE_CLIENT,d.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),d.ua=a,d.transport=o,d.request=s,d.eventHandlers=r;var h="SIP/2.0/".concat(o.via_transport);return h+=" ".concat(a.configuration.via_host,";branch=").concat(d.id),d.request.setHeader("via",h),d.ua.newTransaction(ws(d)),d}return br(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"send",value:function(){var o=this;this.stateChanged(ue.STATUS_TRYING),this.F=setTimeout(function(){o.timer_F()},ns.TIMER_F),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){Ic.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}},{key:"timer_F",value:function(){Ic.debug("Timer F expired for transaction ".concat(this.id)),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}},{key:"timer_K",value:function(){this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"receiveResponse",value:function(o){var s=this,r=o.status_code;if(r<200)switch(this.state){case ue.STATUS_TRYING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(o);break}else switch(this.state){case ue.STATUS_TRYING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_COMPLETED),clearTimeout(this.F),r===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(o),this.K=setTimeout(function(){s.timer_K()},ns.TIMER_K);break;case ue.STATUS_COMPLETED:break}}},{key:"C",get:function(){return ue}}]),n}(Dr),wd=function(c){wr(n,c);var t=Or(n);function n(a,o,s,r){var d;Ir(this,n),d=t.call(this),d.type=ue.INVITE_CLIENT,d.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),d.ua=a,d.transport=o,d.request=s,d.eventHandlers=r,s.transaction=ws(d);var h="SIP/2.0/".concat(o.via_transport);return h+=" ".concat(a.configuration.via_host,";branch=").concat(d.id),d.request.setHeader("via",h),d.ua.newTransaction(ws(d)),d}return br(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"send",value:function(){var o=this;this.stateChanged(ue.STATUS_CALLING),this.B=setTimeout(function(){o.timer_B()},ns.TIMER_B),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==ue.STATUS_ACCEPTED&&(Ul.debug("transport error occurred, deleting transaction ".concat(this.id)),this.eventHandlers.onTransportError()),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_M",value:function(){Ul.debug("Timer M expired for transaction ".concat(this.id)),this.state===ue.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"timer_B",value:function(){Ul.debug("Timer B expired for transaction ".concat(this.id)),this.state===ue.STATUS_CALLING&&(this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}},{key:"timer_D",value:function(){Ul.debug("Timer D expired for transaction ".concat(this.id)),clearTimeout(this.B),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"sendACK",value:function(o){var s=this,r=new Rc.OutgoingRequest(Ur.ACK,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});r.setHeader("from",this.request.getHeader("from")),r.setHeader("via",this.request.getHeader("via")),r.setHeader("to",o.getHeader("to")),this.D=setTimeout(function(){s.timer_D()},ns.TIMER_D),this.transport.send(r)}},{key:"cancel",value:function(o){if(this.state===ue.STATUS_PROCEEDING){var s=new Rc.OutgoingRequest(Ur.CANCEL,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});s.setHeader("from",this.request.getHeader("from")),s.setHeader("via",this.request.getHeader("via")),s.setHeader("to",this.request.getHeader("to")),o&&s.setHeader("reason",o),this.transport.send(s)}}},{key:"receiveResponse",value:function(o){var s=this,r=o.status_code;if(r>=100&&r<=199)switch(this.state){case ue.STATUS_CALLING:this.stateChanged(ue.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(o);break;case ue.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(o);break}else if(r>=200&&r<=299)switch(this.state){case ue.STATUS_CALLING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_ACCEPTED),this.M=setTimeout(function(){s.timer_M()},ns.TIMER_M),this.eventHandlers.onReceiveResponse(o);break;case ue.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(o);break}else if(r>=300&&r<=699)switch(this.state){case ue.STATUS_CALLING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_COMPLETED),this.sendACK(o),this.eventHandlers.onReceiveResponse(o);break;case ue.STATUS_COMPLETED:this.sendACK(o);break}}},{key:"C",get:function(){return ue}}]),n}(Dr),Od=function(c){wr(n,c);var t=Or(n);function n(a,o,s,r){var d;Ir(this,n),d=t.call(this),d.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),d.transport=o,d.request=s,d.eventHandlers=r;var h="SIP/2.0/".concat(o.via_transport);return h+=" ".concat(a.configuration.via_host,";branch=").concat(d.id),d.request.setHeader("via",h),d}return br(n,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){Id.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return ue}}]),n}(Dr),Dd=function(c){wr(n,c);var t=Or(n);function n(a,o,s){var r;return Ir(this,n),r=t.call(this),r.type=ue.NON_INVITE_SERVER,r.id=s.via_branch,r.ua=a,r.transport=o,r.request=s,r.last_response="",s.server_transaction=ws(r),r.state=ue.STATUS_TRYING,a.newTransaction(ws(r)),r}return br(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"timer_J",value:function(){bc.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,bc.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(o,s,r,d){var h=this;if(o===100)switch(this.state){case ue.STATUS_TRYING:this.stateChanged(ue.STATUS_PROCEEDING),this.transport.send(s)||this.onTransportError();break;case ue.STATUS_PROCEEDING:this.last_response=s,this.transport.send(s)?r&&r():(this.onTransportError(),d&&d());break}else if(o>=200&&o<=699)switch(this.state){case ue.STATUS_TRYING:case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_COMPLETED),this.last_response=s,this.J=setTimeout(function(){h.timer_J()},ns.TIMER_J),this.transport.send(s)?r&&r():(this.onTransportError(),d&&d());break;case ue.STATUS_COMPLETED:break}}},{key:"C",get:function(){return ue}}]),n}(Dr),Nd=function(c){wr(n,c);var t=Or(n);function n(a,o,s){var r;return Ir(this,n),r=t.call(this),r.type=ue.INVITE_SERVER,r.id=s.via_branch,r.ua=a,r.transport=o,r.request=s,r.last_response="",s.server_transaction=ws(r),r.state=ue.STATUS_PROCEEDING,a.newTransaction(ws(r)),r.resendProvisionalTimer=null,s.reply(100),r}return br(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"timer_H",value:function(){Pl.debug("Timer H expired for transaction ".concat(this.id)),this.state===ue.STATUS_COMPLETED&&Pl.debug("ACK not received, dialog will be terminated"),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){Pl.debug("Timer L expired for transaction ".concat(this.id)),this.state===ue.STATUS_ACCEPTED&&(this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,Pl.debug("transport error occurred, deleting transaction ".concat(this.id)),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(ue.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"resend_provisional",value:function(){this.transport.send(this.last_response)||this.onTransportError()}},{key:"receiveResponse",value:function(o,s,r,d){var h=this;if(o>=100&&o<=199)switch(this.state){case ue.STATUS_PROCEEDING:this.transport.send(s)||this.onTransportError(),this.last_response=s;break}if(o>100&&o<=199&&this.state===ue.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(function(){h.resend_provisional()},ns.PROVISIONAL_RESPONSE_INTERVAL));else if(o>=200&&o<=299)switch(this.state){case ue.STATUS_PROCEEDING:this.stateChanged(ue.STATUS_ACCEPTED),this.last_response=s,this.L=setTimeout(function(){h.timer_L()},ns.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case ue.STATUS_ACCEPTED:this.transport.send(s)?r&&r():(this.onTransportError(),d&&d());break}else if(o>=300&&o<=699)switch(this.state){case ue.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(s)?(this.stateChanged(ue.STATUS_COMPLETED),this.H=setTimeout(function(){h.timer_H()},ns.TIMER_H),r&&r()):(this.onTransportError(),d&&d());break}}},{key:"C",get:function(){return ue}}]),n}(Dr);function Ud(c,t){var n=c._transactions,a;switch(t.method){case Ur.INVITE:if(a=n.ist[t.via_branch],a){switch(a.state){case ue.STATUS_PROCEEDING:a.transport.send(a.last_response);break;case ue.STATUS_ACCEPTED:break}return!0}break;case Ur.ACK:if(a=n.ist[t.via_branch],a){if(a.state===ue.STATUS_ACCEPTED)return!1;if(a.state===ue.STATUS_COMPLETED)return a.state=ue.STATUS_CONFIRMED,a.I=setTimeout(function(){a.timer_I()},ns.TIMER_I),!0}else return!1;break;case Ur.CANCEL:return a=n.ist[t.via_branch],a?(t.reply_sl(200),a.state!==ue.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(a=n.nist[t.via_branch],a){switch(a.state){case ue.STATUS_TRYING:break;case ue.STATUS_PROCEEDING:case ue.STATUS_COMPLETED:a.transport.send(a.last_response);break}return!0}break}}var Pr={C:ue,NonInviteClientTransaction:bd,InviteClientTransaction:wd,AckClientTransaction:Od,NonInviteServerTransaction:Dd,InviteServerTransaction:Nd,checkTransaction:Ud};function Pd(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function wc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function xd(c,t,n){return t&&wc(c.prototype,t),n&&wc(c,n),c}var kd=ft,Oc=st,Md=yd,uo=Pr,Ld=new kd("RequestSender"),co={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}},xr=function(){function c(t,n,a){Pd(this,c),this._ua=t,this._eventHandlers=a,this._method=n.method,this._request=n,this._auth=null,this._challenged=!1,this._staled=!1;for(var o in co)Object.prototype.hasOwnProperty.call(co,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=co[o]));t.status===t.C.STATUS_USER_CLOSED&&(this._method!==Oc.BYE||this._method!==Oc.ACK)&&this._eventHandlers.onTransportError()}return xd(c,[{key:"send",value:function(){var n=this,a={onRequestTimeout:function(){n._eventHandlers.onRequestTimeout()},onTransportError:function(){n._eventHandlers.onTransportError()},onReceiveResponse:function(s){n._receiveResponse(s)}};switch(this._method){case"INVITE":this.clientTransaction=new uo.InviteClientTransaction(this._ua,this._ua.transport,this._request,a);break;case"ACK":this.clientTransaction=new uo.AckClientTransaction(this._ua,this._ua.transport,this._request,a);break;default:this.clientTransaction=new uo.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,a)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}},{key:"_receiveResponse",value:function(n){var a,o,s=n.status_code;if((s===401||s===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(n.status_code===401?(a=n.parseHeader("www-authenticate"),o="authorization"):(a=n.parseHeader("proxy-authenticate"),o="proxy-authorization"),!a){Ld.debug("".concat(n.status_code," with wrong or missing challenge, cannot authenticate")),this._eventHandlers.onReceiveResponse(n);return}if(!this._challenged||!this._staled&&a.stale===!0){if(this._auth||(this._auth=new Md({username:this._ua.configuration.authorization_user,password:this._ua.configuration.password,realm:this._ua.configuration.realm,ha1:this._ua.configuration.ha1})),!this._auth.authenticate(this._request,a)){this._eventHandlers.onReceiveResponse(n);return}this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),a.stale&&(this._staled=!0),this._request=this._request.clone(),this._request.cseq+=1,this._request.setHeader("cseq","".concat(this._request.cseq," ").concat(this._method)),this._request.setHeader(o,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(n)}else this._eventHandlers.onReceiveResponse(n)}}]),c}();function $d(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Dc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Hd(c,t,n){return t&&Dc(c.prototype,t),n&&Dc(c,n),c}var Fd=ft,fo=Rt(),Xs=st,Nc=fs,Uc=xr,kr=new Fd("Registrator"),xl=10,jd=function(){function c(t,n){$d(this,c),this._reg_id=1,this._ua=t,this._transport=n,this._registrar=t.configuration.registrar_server,this._expires=t.configuration.register_expires,this._call_id=fo.createRandomToken(22),this._cseq=0,this._to_uri=t.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString(),this._contact+=";+sip.ice",this._extraHeaders=[],this._extraContactParams="",this._sipInstance='"<urn:uuid:'.concat(this._ua.configuration.instance_id,'>"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}return Hd(c,[{key:"setExtraHeaders",value:function(n){Array.isArray(n)||(n=[]),this._extraHeaders=n.slice()}},{key:"setExtraContactParams",value:function(n){n instanceof Object||(n={}),this._extraContactParams="";for(var a in n)if(Object.prototype.hasOwnProperty.call(n,a)){var o=n[a];this._extraContactParams+=";".concat(a),o&&(this._extraContactParams+="=".concat(o))}}},{key:"register",value:function(){var n=this;if(this._registering){kr.debug("Register request in progress...");return}var a=this._extraHeaders.slice();a.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),a.push("Expires: ".concat(this._expires));var o=new Nc.OutgoingRequest(Xs.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},a),s=new Uc(this._ua,o,{onRequestTimeout:function(){n._registrationFailure(null,Xs.causes.REQUEST_TIMEOUT)},onTransportError:function(){n._registrationFailure(null,Xs.causes.CONNECTION_ERROR)},onAuthenticated:function(){n._cseq+=1},onReceiveResponse:function(d){if(d.cseq===n._cseq)switch(n._registrationTimer!==null&&(clearTimeout(n._registrationTimer),n._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(d.status_code):break;case/^2[0-9]{2}$/.test(d.status_code):{if(n._registering=!1,!d.hasHeader("Contact")){kr.debug("no Contact header in response to REGISTER, response ignored");break}var h=d.headers.Contact.reduce(function(y,C){return y.concat(C.parsed)},[]),_=h.find(function(y){return n._sipInstance===y.getParam("+sip.instance")&&n._reg_id===parseInt(y.getParam("reg-id"))});if(_||(_=h.find(function(y){return y.uri.user===n._ua.contact.uri.user})),!_){kr.debug("no Contact header pointing to us, response ignored");break}var g=_.getParam("expires");!g&&d.hasHeader("expires")&&(g=d.getHeader("expires")),g||(g=n._expires),g=Number(g),g<xl&&(g=xl);var T=g>64?g*1e3/2+Math.floor((g/2-32)*1e3*Math.random()):g*1e3-5e3;n._registrationTimer=setTimeout(function(){n._registrationTimer=null,n._ua.listeners("registrationExpiring").length===0?n.register():n._ua.emit("registrationExpiring")},T),_.hasParam("temp-gruu")&&(n._ua.contact.temp_gruu=_.getParam("temp-gruu").replace(/"/g,"")),_.hasParam("pub-gruu")&&(n._ua.contact.pub_gruu=_.getParam("pub-gruu").replace(/"/g,"")),n._registered||(n._registered=!0,n._ua.registered({response:d}));break}case/^423$/.test(d.status_code):{d.hasHeader("min-expires")?(n._expires=Number(d.getHeader("min-expires")),n._expires<xl&&(n._expires=xl),n.register()):(kr.debug("423 response received for REGISTER without Min-Expires"),n._registrationFailure(d,Xs.causes.SIP_FAILURE_CODE));break}default:{var E=fo.sipErrorCause(d.status_code);n._registrationFailure(d,E)}}}});this._registering=!0,s.send()}},{key:"unregister",value:function(){var n=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!this._registered){kr.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);var o=this._extraHeaders.slice();a.all?o.push("Contact: *".concat(this._extraContactParams)):o.push("Contact: ".concat(this._contact,";expires=0").concat(this._extraContactParams)),o.push("Expires: 0");var s=new Nc.OutgoingRequest(Xs.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},o),r=new Uc(this._ua,s,{onRequestTimeout:function(){n._unregistered(null,Xs.causes.REQUEST_TIMEOUT)},onTransportError:function(){n._unregistered(null,Xs.causes.CONNECTION_ERROR)},onAuthenticated:function(){n._cseq+=1},onReceiveResponse:function(h){switch(!0){case/^1[0-9]{2}$/.test(h.status_code):break;case/^2[0-9]{2}$/.test(h.status_code):n._unregistered(h);break;default:{var _=fo.sipErrorCause(h.status_code);n._unregistered(h,_)}}}});r.send()}},{key:"close",value:function(){this._registered&&this.unregister()}},{key:"onTransportClosed",value:function(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}},{key:"_registrationFailure",value:function(n,a){this._registering=!1,this._ua.registrationFailed({response:n||null,cause:a}),this._registered&&(this._registered=!1,this._ua.unregistered({response:n||null,cause:a}))}},{key:"_unregistered",value:function(n,a){this._registering=!1,this._registered=!1,this._ua.unregistered({response:n||null,cause:a||null})}},{key:"registered",get:function(){return this._registered}}]),c}();function qd(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Pc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Vd(c,t,n){return t&&Pc(c.prototype,t),n&&Pc(c,n),c}var ho=st,kl=Pr,Bd=xr,_o={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}},Gd=function(){function c(t,n,a){qd(this,c),this._dialog=t,this._ua=t._ua,this._request=n,this._eventHandlers=a,this._reattempt=!1,this._reattemptTimer=null;for(var o in _o)Object.prototype.hasOwnProperty.call(_o,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=_o[o]))}return Vd(c,[{key:"send",value:function(){var n=this,a=new Bd(this._ua,this._request,{onRequestTimeout:function(){n._eventHandlers.onRequestTimeout()},onTransportError:function(){n._eventHandlers.onTransportError()},onAuthenticated:function(r){n._eventHandlers.onAuthenticated(r)},onReceiveResponse:function(r){n._receiveResponse(r)}});if(a.send(),(this._request.method===ho.INVITE||this._request.method===ho.UPDATE&&this._request.body)&&a.clientTransaction.state!==kl.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;var o=function s(){(a.clientTransaction.state===kl.C.STATUS_ACCEPTED||a.clientTransaction.state===kl.C.STATUS_COMPLETED||a.clientTransaction.state===kl.C.STATUS_TERMINATED)&&(a.clientTransaction.removeListener("stateChanged",s),n._dialog.uac_pending_reply=!1)};a.clientTransaction.on("stateChanged",o)}}},{key:"_receiveResponse",value:function(n){var a=this;n.status_code===408||n.status_code===481?this._eventHandlers.onDialogError(n):n.method===ho.INVITE&&n.status_code===491?this._reattempt?n.status_code>=200&&n.status_code<300?this._eventHandlers.onSuccessResponse(n):n.status_code>=300&&this._eventHandlers.onErrorResponse(n):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(function(){a._dialog.isTerminated()||(a._reattempt=!0,a.send())},1e3)):n.status_code>=200&&n.status_code<300?this._eventHandlers.onSuccessResponse(n):n.status_code>=300&&this._eventHandlers.onErrorResponse(n)}},{key:"request",get:function(){return this._request}}]),c}();function Wd(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function xc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function kc(c,t,n){return t&&xc(c.prototype,t),n&&xc(c,n),c}var Kd=ft,Mc=fs,Os=st,Mr=Pr,Yd=Gd,po=Rt(),mo=new Kd("Dialog"),Ds={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3},Jd=function(){kc(c,null,[{key:"C",get:function(){return Ds}}]);function c(t,n,a){var o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:Ds.STATUS_CONFIRMED;if(Wd(this,c),this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!n.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};n instanceof Mc.IncomingResponse&&(o=n.status_code<200?Ds.STATUS_EARLY:Ds.STATUS_CONFIRMED);var s=n.parseHeader("contact");a==="UAS"?(this._id={call_id:n.call_id,local_tag:n.to_tag,remote_tag:n.from_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri,this._remote_target=s.uri,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):a==="UAC"&&(this._id={call_id:n.call_id,local_tag:n.from_tag,remote_tag:n.to_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=s.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),mo.debug("new ".concat(a," dialog created with status ").concat(this._state===Ds.STATUS_EARLY?"EARLY":"CONFIRMED"))}return kc(c,[{key:"isTerminated",value:function(){return this._status===Ds.STATUS_TERMINATED}},{key:"update",value:function(n,a){this._state=Ds.STATUS_CONFIRMED,mo.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),a==="UAC"&&(this._route_set=n.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){mo.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this),this._state=Ds.STATUS_TERMINATED}},{key:"sendRequest",value:function(n){var a=this,o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},s=po.cloneArray(o.extraHeaders),r=po.cloneObject(o.eventHandlers),d=o.body||null,h=this._createRequest(n,s,d);r.onAuthenticated=function(){a._local_seqnum+=1};var _=new Yd(this,h,r);return _.send(),h}},{key:"receiveRequest",value:function(n){this._checkInDialogRequest(n)&&(n.method===Os.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:n.method===Os.INVITE&&(this._ack_seqnum=n.cseq),this._owner.receiveRequest(n))}},{key:"_createRequest",value:function(n,a,o){a=po.cloneArray(a),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));var s=n===Os.CANCEL||n===Os.ACK?this._local_seqnum:this._local_seqnum+=1,r=new Mc.OutgoingRequest(n,this._remote_target,this._ua,{cseq:s,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},a,o);return r}},{key:"_checkInDialogRequest",value:function(n){var a=this;if(!this._remote_seqnum)this._remote_seqnum=n.cseq;else if(n.cseq<this._remote_seqnum)if(n.method===Os.ACK){if(this._ack_seqnum===null||n.cseq!==this._ack_seqnum)return!1}else return n.reply(500),!1;else n.cseq>this._remote_seqnum&&(this._remote_seqnum=n.cseq);if(n.method===Os.INVITE||n.method===Os.UPDATE&&n.body){if(this._uac_pending_reply===!0)n.reply(491);else if(this._uas_pending_reply===!0){var o=(Math.random()*10|0)+1;return n.reply(500,null,["Retry-After:".concat(o)]),!1}else{this._uas_pending_reply=!0;var s=function r(){(n.server_transaction.state===Mr.C.STATUS_ACCEPTED||n.server_transaction.state===Mr.C.STATUS_COMPLETED||n.server_transaction.state===Mr.C.STATUS_TERMINATED)&&(n.server_transaction.removeListener("stateChanged",r),a._uas_pending_reply=!1)};n.server_transaction.on("stateChanged",s)}n.hasHeader("contact")&&n.server_transaction.on("stateChanged",function(){n.server_transaction.state===Mr.C.STATUS_ACCEPTED&&(a._remote_target=n.parseHeader("contact").uri)})}else n.method===Os.NOTIFY&&n.hasHeader("contact")&&n.server_transaction.on("stateChanged",function(){n.server_transaction.state===Mr.C.STATUS_COMPLETED&&(a._remote_target=n.parseHeader("contact").uri)});return!0}},{key:"id",get:function(){return this._id}},{key:"local_seqnum",get:function(){return this._local_seqnum},set:function(n){this._local_seqnum=n}},{key:"owner",get:function(){return this._owner}},{key:"uac_pending_reply",get:function(){return this._uac_pending_reply},set:function(n){this._uac_pending_reply=n}},{key:"uas_pending_reply",get:function(){return this._uas_pending_reply}}]),c}(),go={exports:{}};function Ml(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ml=function(n){return typeof n}:Ml=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Ml(c)}function zd(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Lc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Xd(c,t,n){return t&&Lc(c.prototype,t),n&&Lc(c,n),c}function Qd(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&To(c,t)}function To(c,t){return To=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},To(c,t)}function Zd(c){var t=s_();return function(){var a=Ll(c),o;if(t){var s=Ll(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return e_(this,o)}}function e_(c,t){return t&&(Ml(t)==="object"||typeof t=="function")?t:t_(c)}function t_(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function s_(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Ll(c){return Ll=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Ll(c)}var n_=ct.EventEmitter,r_=ft,i_=st,l_=Is,$c=Rt(),a_=new r_("RTCSession:DTMF"),Hc={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};go.exports=function(c){Qd(n,c);var t=Zd(n);function n(a){var o;return zd(this,n),o=t.call(this),o._session=a,o._direction=null,o._tone=null,o._duration=null,o._request=null,o}return Xd(n,[{key:"send",value:function(o){var s=this,r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(o===void 0)throw new TypeError("Not enough arguments");if(this._direction="outgoing",this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new l_.InvalidStateError(this._session.status);var d=$c.cloneArray(r.extraHeaders);if(this.eventHandlers=$c.cloneObject(r.eventHandlers),typeof o=="string")o=o.toUpperCase();else if(typeof o=="number")o=o.toString();else throw new TypeError("Invalid tone: ".concat(o));if(o.match(/^[0-9A-DR#*]$/))this._tone=o;else throw new TypeError("Invalid tone: ".concat(o));this._duration=r.duration,d.push("Content-Type: application/dtmf-relay");var h="Signal=".concat(this._tone,`\r
|
47
47
|
`);h+="Duration=".concat(this._duration),this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(i_.INFO,{extraHeaders:d,eventHandlers:{onSuccessResponse:function(g){s.emit("succeeded",{originator:"remote",response:g})},onErrorResponse:function(g){s.eventHandlers.onFailed&&s.eventHandlers.onFailed(),s.emit("failed",{originator:"remote",response:g})},onRequestTimeout:function(){s._session.onRequestTimeout()},onTransportError:function(){s._session.onTransportError()},onDialogError:function(){s._session.onDialogError()}},body:h})}},{key:"init_incoming",value:function(o){var s=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,r=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=o,o.reply(200),o.body){var d=o.body.split(`
|
48
|
-
`);d.length>=1&&s.test(d[0])&&(this._tone=d[0].replace(s,"$2")),d.length>=2&&r.test(d[1])&&(this._duration=parseInt(d[1].replace(r,"$2"),10))}this._duration||(this._duration=Hc.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:o}):a_.debug("invalid INFO DTMF received, discarded")}},{key:"tone",get:function(){return this._tone}},{key:"duration",get:function(){return this._duration}}]),n}(n_),go.exports.C=Hc;var o_=go.exports;function $l(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?$l=function(n){return typeof n}:$l=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},$l(c)}function u_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Fc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function c_(c,t,n){return t&&Fc(c.prototype,t),n&&Fc(c,n),c}function f_(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&vo(c,t)}function vo(c,t){return vo=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},vo(c,t)}function h_(c){var t=p_();return function(){var a=Hl(c),o;if(t){var s=Hl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return d_(this,o)}}function d_(c,t){return t&&($l(t)==="object"||typeof t=="function")?t:__(c)}function __(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function p_(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Hl(c){return Hl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Hl(c)}var m_=ct.EventEmitter,g_=st,T_=Is,v_=Rt(),E_=function(c){f_(n,c);var t=h_(n);function n(a){var o;return u_(this,n),o=t.call(this),o._session=a,o._direction=null,o._contentType=null,o._body=null,o}return c_(n,[{key:"send",value:function(o,s){var r=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(this._direction="outgoing",o===void 0)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new T_.InvalidStateError(this._session.status);this._contentType=o,this._body=s;var h=v_.cloneArray(d.extraHeaders);h.push("Content-Type: ".concat(o)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(g_.INFO,{extraHeaders:h,eventHandlers:{onSuccessResponse:function(g){r.emit("succeeded",{originator:"remote",response:g})},onErrorResponse:function(g){r.emit("failed",{originator:"remote",response:g})},onTransportError:function(){r._session.onTransportError()},onRequestTimeout:function(){r._session.onRequestTimeout()},onDialogError:function(){r._session.onDialogError()}},body:s})}},{key:"init_incoming",value:function(o){this._direction="incoming",this.request=o,o.reply(200),this._contentType=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0,this._body=o.body,this._session.newInfo({originator:"remote",info:this,request:o})}},{key:"contentType",get:function(){return this._contentType}},{key:"body",get:function(){return this._body}}]),n}(m_);function S_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function jc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function y_(c,t,n){return t&&jc(c.prototype,t),n&&jc(c,n),c}var
|
48
|
+
`);d.length>=1&&s.test(d[0])&&(this._tone=d[0].replace(s,"$2")),d.length>=2&&r.test(d[1])&&(this._duration=parseInt(d[1].replace(r,"$2"),10))}this._duration||(this._duration=Hc.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:o}):a_.debug("invalid INFO DTMF received, discarded")}},{key:"tone",get:function(){return this._tone}},{key:"duration",get:function(){return this._duration}}]),n}(n_),go.exports.C=Hc;var o_=go.exports;function $l(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?$l=function(n){return typeof n}:$l=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},$l(c)}function u_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Fc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function c_(c,t,n){return t&&Fc(c.prototype,t),n&&Fc(c,n),c}function f_(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&vo(c,t)}function vo(c,t){return vo=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},vo(c,t)}function h_(c){var t=p_();return function(){var a=Hl(c),o;if(t){var s=Hl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return d_(this,o)}}function d_(c,t){return t&&($l(t)==="object"||typeof t=="function")?t:__(c)}function __(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function p_(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Hl(c){return Hl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Hl(c)}var m_=ct.EventEmitter,g_=st,T_=Is,v_=Rt(),E_=function(c){f_(n,c);var t=h_(n);function n(a){var o;return u_(this,n),o=t.call(this),o._session=a,o._direction=null,o._contentType=null,o._body=null,o}return c_(n,[{key:"send",value:function(o,s){var r=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(this._direction="outgoing",o===void 0)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new T_.InvalidStateError(this._session.status);this._contentType=o,this._body=s;var h=v_.cloneArray(d.extraHeaders);h.push("Content-Type: ".concat(o)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(g_.INFO,{extraHeaders:h,eventHandlers:{onSuccessResponse:function(g){r.emit("succeeded",{originator:"remote",response:g})},onErrorResponse:function(g){r.emit("failed",{originator:"remote",response:g})},onTransportError:function(){r._session.onTransportError()},onRequestTimeout:function(){r._session.onRequestTimeout()},onDialogError:function(){r._session.onDialogError()}},body:s})}},{key:"init_incoming",value:function(o){this._direction="incoming",this.request=o,o.reply(200),this._contentType=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0,this._body=o.body,this._session.newInfo({originator:"remote",info:this,request:o})}},{key:"contentType",get:function(){return this._contentType}},{key:"body",get:function(){return this._body}}]),n}(m_);function S_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function jc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function y_(c,t,n){return t&&jc(c.prototype,t),n&&jc(c,n),c}var C_=ft,qc=st,A_=new C_("RTCSession:ReferNotifier"),Eo={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300},R_=function(){function c(t,n,a){S_(this,c),this._session=t,this._id=n,this._expires=a||Eo.expires,this._active=!0,this.notify(100)}return y_(c,[{key:"notify",value:function(n,a){if(A_.debug("notify()"),this._active!==!1){a=a||qc.REASON_PHRASE[n]||"";var o;n>=200?o="terminated;reason=noresource":o="active;expires=".concat(this._expires),this._session.sendRequest(qc.NOTIFY,{extraHeaders:["Event: ".concat(Eo.event_type,";id=").concat(this._id),"Subscription-State: ".concat(o),"Content-Type: ".concat(Eo.body_type)],body:"SIP/2.0 ".concat(n," ").concat(a),eventHandlers:{onErrorResponse:function(){this._active=!1}}})}}}]),c}();function Fl(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Fl=function(n){return typeof n}:Fl=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Fl(c)}function I_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Vc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function b_(c,t,n){return t&&Vc(c.prototype,t),n&&Vc(c,n),c}function w_(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&So(c,t)}function So(c,t){return So=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},So(c,t)}function O_(c){var t=U_();return function(){var a=jl(c),o;if(t){var s=jl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return D_(this,o)}}function D_(c,t){return t&&(Fl(t)==="object"||typeof t=="function")?t:N_(c)}function N_(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function U_(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function jl(c){return jl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},jl(c)}var P_=ct.EventEmitter,x_=ft,Lr=st,k_=ss(),Bc=Rt(),Qs=new x_("RTCSession:ReferSubscriber"),M_=function(c){w_(n,c);var t=O_(n);function n(a){var o;return I_(this,n),o=t.call(this),o._id=null,o._session=a,o}return b_(n,[{key:"sendRefer",value:function(o){var s=this,r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Qs.debug("sendRefer()");var d=Bc.cloneArray(r.extraHeaders),h=Bc.cloneObject(r.eventHandlers);for(var _ in h)Object.prototype.hasOwnProperty.call(h,_)&&this.on(_,h[_]);var g=null;r.replaces&&(g=r.replaces._request.call_id,g+=";to-tag=".concat(r.replaces._to_tag),g+=";from-tag=".concat(r.replaces._from_tag),g=encodeURIComponent(g));var T="Refer-To: <".concat(o).concat(g?"?Replaces=".concat(g):"",">");if(d.push(T),!d.some(function(C){return C.toLowerCase().startsWith("referred-by:")})){var E="Referred-By: <".concat(this._session._ua._configuration.uri._scheme,":").concat(this._session._ua._configuration.uri._user,"@").concat(this._session._ua._configuration.uri._host,">");d.push(E)}d.push("Contact: ".concat(this._session.contact));var y=this._session.sendRequest(Lr.REFER,{extraHeaders:d,eventHandlers:{onSuccessResponse:function(A){s._requestSucceeded(A)},onErrorResponse:function(A){s._requestFailed(A,Lr.causes.REJECTED)},onTransportError:function(){s._requestFailed(null,Lr.causes.CONNECTION_ERROR)},onRequestTimeout:function(){s._requestFailed(null,Lr.causes.REQUEST_TIMEOUT)},onDialogError:function(){s._requestFailed(null,Lr.causes.DIALOG_ERROR)}}});this._id=y.cseq}},{key:"receiveNotify",value:function(o){if(Qs.debug("receiveNotify()"),!!o.body){var s=k_.parse(o.body.trim().split(`\r
|
49
49
|
`,1)[0],"Status_Line");if(s===-1){Qs.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(o.body,'"'));return}switch(!0){case/^100$/.test(s.status_code):this.emit("trying",{request:o,status_line:s});break;case/^1[0-9]{2}$/.test(s.status_code):this.emit("progress",{request:o,status_line:s});break;case/^2[0-9]{2}$/.test(s.status_code):this.emit("accepted",{request:o,status_line:s});break;default:this.emit("failed",{request:o,status_line:s});break}}}},{key:"_requestSucceeded",value:function(o){Qs.debug("REFER succeeded"),Qs.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:o})}},{key:"_requestFailed",value:function(o,s){Qs.debug("REFER failed"),Qs.debug('emit "requestFailed"'),this.emit("requestFailed",{response:o||null,cause:s})}},{key:"id",get:function(){return this._id}}]),n}(P_);function ql(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?ql=function(n){return typeof n}:ql=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},ql(c)}function _s(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=L_(c))||t&&c&&typeof c.length=="number"){n&&(c=n);var a=0,o=function(){};return{s:o,n:function(){return a>=c.length?{done:!0}:{done:!1,value:c[a++]}},e:function(_){throw _},f:o}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
50
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function L_(c,t){if(c){if(typeof c=="string")return Gc(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Gc(c,t)}}function Gc(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}function $_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Wc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Kc(c,t,n){return t&&Wc(c.prototype,t),n&&Wc(c,n),c}function H_(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&yo(c,t)}function yo(c,t){return yo=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},yo(c,t)}function F_(c){var t=V_();return function(){var a=Vl(c),o;if(t){var s=Vl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return j_(this,o)}}function j_(c,t){return t&&(ql(t)==="object"||typeof t=="function")?t:q_(c)}function q_(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function V_(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Vl(c){return Vl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Vl(c)}var B_=ct.EventEmitter,Yc=Ut,G_=ft,ce=st,Zs=Is,Jc=Pr,Be=Rt(),$r=Ac,W_=fs,Bl=Jd,K_=xr,Lt=o_,zc=E_,Y_=R_,J_=M_,Xc=bs(),W=new G_("RTCSession"),X={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9},Gl=["audio","video"],z_=function(c){H_(n,c);var t=F_(n);Kc(n,null,[{key:"C",get:function(){return X}}]);function n(a){var o;return $_(this,n),W.debug("new"),o=t.call(this),o._id=null,o._ua=a,o._status=X.STATUS_NULL,o._dialog=null,o._earlyDialogs={},o._contact=null,o._from_tag=null,o._to_tag=null,o._connection=null,o._connectionPromiseQueue=Promise.resolve(),o._request=null,o._is_canceled=!1,o._cancel_reason="",o._is_confirmed=!1,o._late_sdp=!1,o._rtcOfferConstraints=null,o._rtcAnswerConstraints=null,o._localMediaStream=null,o._localMediaStreamLocallyGenerated=!1,o._rtcReady=!0,o._iceReady=!1,o._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},o._direction=null,o._local_identity=null,o._remote_identity=null,o._start_time=null,o._end_time=null,o._tones=null,o._audioMuted=!1,o._videoMuted=!1,o._localHold=!1,o._remoteHold=!1,o._sessionTimers={enabled:o._ua.configuration.session_timers,refreshMethod:o._ua.configuration.session_timers_refresh_method,defaultExpires:ce.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},o._referSubscribers={},o._data={},o}return Kc(n,[{key:"isInProgress",value:function(){switch(this._status){case X.STATUS_NULL:case X.STATUS_INVITE_SENT:case X.STATUS_1XX_RECEIVED:case X.STATUS_INVITE_RECEIVED:case X.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}},{key:"isEstablished",value:function(){switch(this._status){case X.STATUS_ANSWERED:case X.STATUS_WAITING_FOR_ACK:case X.STATUS_CONFIRMED:return!0;default:return!1}}},{key:"isEnded",value:function(){switch(this._status){case X.STATUS_CANCELED:case X.STATUS_TERMINATED:return!0;default:return!1}}},{key:"isMuted",value:function(){return{audio:this._audioMuted,video:this._videoMuted}}},{key:"isOnHold",value:function(){return{local:this._localHold,remote:this._remoteHold}}},{key:"connect",value:function(o){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;W.debug("connect()");var d=o,h=Be.cloneObject(s.eventHandlers),_=Be.cloneArray(s.extraHeaders),g=Be.cloneObject(s.mediaConstraints,{audio:!0,video:!0}),T=s.mediaStream||null,E=Be.cloneObject(s.pcConfig,{iceServers:[]}),y=s.rtcConstraints||null,A=s.rtcOfferConstraints||null;if(this._rtcOfferConstraints=A,this._rtcAnswerConstraints=s.rtcAnswerConstraints||null,this._data=s.data||this._data,o===void 0)throw new TypeError("Not enough arguments");if(this._status!==X.STATUS_NULL)throw new Zs.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new Zs.NotSupportedError("WebRTC not supported");if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(d));this._sessionTimers.enabled&&Be.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES);for(var C in h)Object.prototype.hasOwnProperty.call(h,C)&&this.on(C,h[C]);this._from_tag=Be.newTag();var I=s.anonymous||!1,H={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:I,outbound:!0}),I?(H.from_display_name="Anonymous",H.from_uri=new Xc("sip","anonymous","anonymous.invalid"),_.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),_.push("Privacy: id")):s.fromUserName&&(H.from_uri=new Xc("sip",s.fromUserName,this._ua.configuration.uri.host),_.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),s.fromDisplayName&&(H.from_display_name=s.fromDisplayName),_.push("Contact: ".concat(this._contact)),_.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&_.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher?";refresher=uac":"")),this._request=new W_.InitialOutgoingInviteRequest(o,this._ua,H,_),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(E,y),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,r&&r(this),this._newRTCSession("local",this._request),this._sendInitialRequest(g,A,T)}},{key:"init_incoming",value:function(o,s){var r=this;W.debug("init_incoming()");var d,h=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0;if(o.body&&h!=="application/sdp"){o.reply(415);return}if(this._status=X.STATUS_INVITE_RECEIVED,this._from_tag=o.from_tag,this._id=o.call_id+this._from_tag,this._request=o,this._contact=this._ua.contact.toString(),o.hasHeader("expires")&&(d=o.getHeader("expires")*1e3),o.to_tag=Be.newTag(),!this._createDialog(o,"UAS",!0)){o.reply(500,"Missing Contact header field");return}o.body?this._late_sdp=!1:this._late_sdp=!0,this._status=X.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){o.reply(408),r._failed("local",null,ce.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),d&&(this._timers.expiresTimer=setTimeout(function(){r._status===X.STATUS_WAITING_FOR_ANSWER&&(o.reply(487),r._failed("system",null,ce.causes.EXPIRES))},d)),this._direction="incoming",this._local_identity=o.to,this._remote_identity=o.from,s&&s(this),this._newRTCSession("remote",o),this._status!==X.STATUS_TERMINATED&&(o.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))}},{key:"answer",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};W.debug("answer()");var r=this._request,d=Be.cloneArray(s.extraHeaders),h=Be.cloneObject(s.mediaConstraints),_=s.mediaStream||null,g=Be.cloneObject(s.pcConfig,{iceServers:[]}),T=s.rtcConstraints||null,E=s.rtcAnswerConstraints||null,y=Be.cloneObject(s.rtcOfferConstraints),A,C=!1,I=!1,H=!1,$=!1;if(this._rtcAnswerConstraints=E,this._rtcOfferConstraints=s.rtcOfferConstraints||null,this._data=s.data||this._data,this._direction!=="incoming")throw new Zs.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==X.STATUS_WAITING_FOR_ANSWER)throw new Zs.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Be.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES),this._status=X.STATUS_ANSWERED,!this._createDialog(r,"UAS")){r.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),d.unshift("Contact: ".concat(this._contact));var oe=r.parseSDP();Array.isArray(oe.media)||(oe.media=[oe.media]);var N=_s(oe.media),j;try{for(N.s();!(j=N.n()).done;){var Se=j.value;Se.type==="audio"&&(C=!0,(!Se.direction||Se.direction==="sendrecv")&&(H=!0)),Se.type==="video"&&(I=!0,(!Se.direction||Se.direction==="sendrecv")&&($=!0))}}catch(F){N.e(F)}finally{N.f()}if(_&&h.audio===!1){A=_.getAudioTracks();var ve=_s(A),k;try{for(ve.s();!(k=ve.n()).done;){var D=k.value;_.removeTrack(D)}}catch(F){ve.e(F)}finally{ve.f()}}if(_&&h.video===!1){A=_.getVideoTracks();var B=_s(A),V;try{for(B.s();!(V=B.n()).done;){var J=V.value;_.removeTrack(J)}}catch(F){B.e(F)}finally{B.f()}}!_&&h.audio===void 0&&(h.audio=H),!_&&h.video===void 0&&(h.video=$),!_&&!C&&!y.offerToReceiveAudio&&(h.audio=!1),!_&&!I&&!y.offerToReceiveVideo&&(h.video=!1),this._createRTCConnection(g,T),Promise.resolve().then(function(){if(_)return _;if(h.audio||h.video)return o._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(h).catch(function(F){throw o._status===X.STATUS_TERMINATED?new Error("terminated"):(r.reply(480),o._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),W.warn('emit "getusermediafailed" [error:%o]',F),o.emit("getusermediafailed",F),new Error("getUserMedia() failed"))})}).then(function(F){if(o._status===X.STATUS_TERMINATED)throw new Error("terminated");o._localMediaStream=F,F&&F.getTracks().forEach(function(Z){o._connection.addTrack(Z,F)})}).then(function(){if(!o._late_sdp){var F={originator:"remote",type:"offer",sdp:r.body};W.debug('emit "sdp"'),o.emit("sdp",F);var Z=new RTCSessionDescription({type:"offer",sdp:F.sdp});return o._connectionPromiseQueue=o._connectionPromiseQueue.then(function(){return o._connection.setRemoteDescription(Z)}).catch(function(U){throw r.reply(488),o._failed("system",null,ce.causes.WEBRTC_ERROR),W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',U),o.emit("peerconnection:setremotedescriptionfailed",U),new Error("peerconnection.setRemoteDescription() failed")}),o._connectionPromiseQueue}}).then(function(){if(o._status===X.STATUS_TERMINATED)throw new Error("terminated");return o._connecting(r),o._late_sdp?o._createLocalDescription("offer",o._rtcOfferConstraints).catch(function(){throw r.reply(500),new Error("_createLocalDescription() failed")}):o._createLocalDescription("answer",E).catch(function(){throw r.reply(500),new Error("_createLocalDescription() failed")})}).then(function(F){if(o._status===X.STATUS_TERMINATED)throw new Error("terminated");o._handleSessionTimersInIncomingRequest(r,d),r.reply(200,null,d,F,function(){o._status=X.STATUS_WAITING_FOR_ACK,o._setInvite2xxTimer(r,F),o._setACKTimer(),o._accepted("local")},function(){o._failed("system",null,ce.causes.CONNECTION_ERROR)})}).catch(function(F){o._status!==X.STATUS_TERMINATED&&W.warn(F)})}},{key:"terminate",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};W.debug("terminate()");var r=s.cause||ce.causes.BYE,d=Be.cloneArray(s.extraHeaders),h=s.body,_,g=s.status_code,T=s.reason_phrase;if(this._status===X.STATUS_TERMINATED)throw new Zs.InvalidStateError(this._status);switch(this._status){case X.STATUS_NULL:case X.STATUS_INVITE_SENT:case X.STATUS_1XX_RECEIVED:if(W.debug("canceling session"),g&&(g<200||g>=700))throw new TypeError("Invalid status_code: ".concat(g));g&&(T=T||ce.REASON_PHRASE[g]||"",_="SIP ;cause=".concat(g,' ;text="').concat(T,'"')),this._status===X.STATUS_NULL||this._status===X.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=_):this._status===X.STATUS_1XX_RECEIVED&&this._request.cancel(_),this._status=X.STATUS_CANCELED,this._failed("local",null,ce.causes.CANCELED);break;case X.STATUS_WAITING_FOR_ANSWER:case X.STATUS_ANSWERED:if(W.debug("rejecting session"),g=g||480,g<300||g>=700)throw new TypeError("Invalid status_code: ".concat(g));this._request.reply(g,T,d,h),this._failed("local",null,ce.causes.REJECTED);break;case X.STATUS_WAITING_FOR_ACK:case X.STATUS_CONFIRMED:if(W.debug("terminating session"),T=s.reason_phrase||ce.REASON_PHRASE[g]||"",g&&(g<200||g>=700))throw new TypeError("Invalid status_code: ".concat(g));if(g&&d.push("Reason: SIP ;cause=".concat(g,'; text="').concat(T,'"')),this._status===X.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Jc.C.STATUS_TERMINATED){var E=this._dialog;this.receiveRequest=function(y){var A=y.method;A===ce.ACK&&(o.sendRequest(ce.BYE,{extraHeaders:d,body:h}),E.terminate())},this._request.server_transaction.on("stateChanged",function(){o._request.server_transaction.state===Jc.C.STATUS_TERMINATED&&(o.sendRequest(ce.BYE,{extraHeaders:d,body:h}),E.terminate())}),this._ended("local",null,r),this._dialog=E,this._ua.newDialog(E)}else this.sendRequest(ce.BYE,{extraHeaders:d,body:h}),this._ended("local",null,r)}}},{key:"sendDTMF",value:function(o){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};W.debug("sendDTMF() | tones: %s",o);var r=0,d=s.duration||null,h=s.interToneGap||null,_=s.transportType||ce.DTMF_TRANSPORT.INFO;if(o===void 0)throw new TypeError("Not enough arguments");if(this._status!==X.STATUS_CONFIRMED&&this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_1XX_RECEIVED)throw new Zs.InvalidStateError(this._status);if(_!==ce.DTMF_TRANSPORT.INFO&&_!==ce.DTMF_TRANSPORT.RFC2833)throw new TypeError("invalid transportType: ".concat(_));if(typeof o=="number"&&(o=o.toString()),!o||typeof o!="string"||!o.match(/^[0-9A-DR#*,]+$/i))throw new TypeError("Invalid tones: ".concat(o));if(d&&!Be.isDecimal(d))throw new TypeError("Invalid tone duration: ".concat(d));if(d?d<Lt.C.MIN_DURATION?(W.debug('"duration" value is lower than the minimum allowed, setting it to '.concat(Lt.C.MIN_DURATION," milliseconds")),d=Lt.C.MIN_DURATION):d>Lt.C.MAX_DURATION?(W.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(Lt.C.MAX_DURATION," milliseconds")),d=Lt.C.MAX_DURATION):d=Math.abs(d):d=Lt.C.DEFAULT_DURATION,s.duration=d,h&&!Be.isDecimal(h))throw new TypeError("Invalid interToneGap: ".concat(h));if(h?h<Lt.C.MIN_INTER_TONE_GAP?(W.debug('"interToneGap" value is lower than the minimum allowed, setting it to '.concat(Lt.C.MIN_INTER_TONE_GAP," milliseconds")),h=Lt.C.MIN_INTER_TONE_GAP):h=Math.abs(h):h=Lt.C.DEFAULT_INTER_TONE_GAP,_===ce.DTMF_TRANSPORT.RFC2833){var g=this._getDTMFRTPSender();g&&(o=g.toneBuffer+o,g.insertDTMF(o,d,h));return}if(this._tones){this._tones+=o;return}this._tones=o,T.call(this);function T(){var E=this,y;if(this._status===X.STATUS_TERMINATED||!this._tones||r>=this._tones.length){this._tones=null;return}var A=this._tones[r];if(r+=1,A===",")y=2e3;else{var C=new Lt(this);s.eventHandlers={onFailed:function(){E._tones=null}},C.send(A,s),y=d+h}setTimeout(T.bind(this),y)}}},{key:"sendInfo",value:function(o,s){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(W.debug("sendInfo()"),this._status!==X.STATUS_CONFIRMED&&this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_1XX_RECEIVED)throw new Zs.InvalidStateError(this._status);var d=new zc(this);d.send(o,s,r)}},{key:"mute",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!1};W.debug("mute()");var s=!1,r=!1;this._audioMuted===!1&&o.audio&&(s=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&o.video&&(r=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(s===!0||r===!0)&&this._onmute({audio:s,video:r})}},{key:"unmute",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!0};W.debug("unmute()");var s=!1,r=!1;this._audioMuted===!0&&o.audio&&(s=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&o.video&&(r=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(s===!0||r===!0)&&this._onunmute({audio:s,video:r})}},{key:"hold",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;if(W.debug("hold()"),this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var d={succeeded:function(){r&&r()},failed:function(){o.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:d,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:d,extraHeaders:s.extraHeaders}),!0}},{key:"unhold",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;if(W.debug("unhold()"),this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var d={succeeded:function(){r&&r()},failed:function(){o.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:d,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:d,extraHeaders:s.extraHeaders}),!0}},{key:"renegotiate",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;W.debug("renegotiate()");var d=s.rtcOfferConstraints||null;if(this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;var h={succeeded:function(){r&&r()},failed:function(){o.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:h,rtcOfferConstraints:d,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:h,rtcOfferConstraints:d,extraHeaders:s.extraHeaders}),!0}},{key:"refer",value:function(o,s){var r=this;W.debug("refer()");var d=o;if(this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED)return!1;if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(d));var h=new J_(this);h.sendRefer(o,s);var _=h.id;return this._referSubscribers[_]=h,h.on("requestFailed",function(){delete r._referSubscribers[_]}),h.on("accepted",function(){delete r._referSubscribers[_]}),h.on("failed",function(){delete r._referSubscribers[_]}),h}},{key:"sendRequest",value:function(o,s){return W.debug("sendRequest()"),this._dialog.sendRequest(o,s)}},{key:"receiveRequest",value:function(o){var s=this;if(W.debug("receiveRequest()"),o.method===ce.CANCEL)(this._status===X.STATUS_WAITING_FOR_ANSWER||this._status===X.STATUS_ANSWERED)&&(this._status=X.STATUS_CANCELED,this._request.reply(487),this._failed("remote",o,ce.causes.CANCELED));else switch(o.method){case ce.ACK:if(this._status!==X.STATUS_WAITING_FOR_ACK)return;if(this._status=X.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!o.body){this.terminate({cause:ce.causes.MISSING_SDP,status_code:400});break}var r={originator:"remote",type:"answer",sdp:o.body};W.debug('emit "sdp"'),this.emit("sdp",r);var d=new RTCSessionDescription({type:"answer",sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._connection.setRemoteDescription(d)}).then(function(){s._is_confirmed||s._confirmed("remote",o)}).catch(function(_){s.terminate({cause:ce.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',_),s.emit("peerconnection:setremotedescriptionfailed",_)})}else this._is_confirmed||this._confirmed("remote",o);break;case ce.BYE:this._status===X.STATUS_CONFIRMED||this._status===X.STATUS_WAITING_FOR_ACK?(o.reply(200),this._ended("remote",o,ce.causes.BYE)):this._status===X.STATUS_INVITE_RECEIVED||this._status===X.STATUS_WAITING_FOR_ANSWER?(o.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",o,ce.causes.BYE)):o.reply(403,"Wrong Status");break;case ce.INVITE:this._status===X.STATUS_CONFIRMED?o.hasHeader("replaces")?this._receiveReplaces(o):this._receiveReinvite(o):o.reply(403,"Wrong Status");break;case ce.INFO:if(this._status===X.STATUS_1XX_RECEIVED||this._status===X.STATUS_WAITING_FOR_ANSWER||this._status===X.STATUS_ANSWERED||this._status===X.STATUS_WAITING_FOR_ACK||this._status===X.STATUS_CONFIRMED){var h=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0;h&&h.match(/^application\/dtmf-relay/i)?new Lt(this).init_incoming(o):h!==void 0?new zc(this).init_incoming(o):o.reply(415)}else o.reply(403,"Wrong Status");break;case ce.UPDATE:this._status===X.STATUS_CONFIRMED?this._receiveUpdate(o):o.reply(403,"Wrong Status");break;case ce.REFER:this._status===X.STATUS_CONFIRMED?this._receiveRefer(o):o.reply(403,"Wrong Status");break;case ce.NOTIFY:this._status===X.STATUS_CONFIRMED?this._receiveNotify(o):o.reply(403,"Wrong Status");break;default:o.reply(501)}}},{key:"onTransportError",value:function(){W.warn("onTransportError()"),this._status!==X.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ce.causes.CONNECTION_ERROR,cause:ce.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){W.warn("onRequestTimeout()"),this._status!==X.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:ce.causes.REQUEST_TIMEOUT,cause:ce.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){W.warn("onDialogError()"),this._status!==X.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ce.causes.DIALOG_ERROR,cause:ce.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(o){W.debug("newDTMF()"),this.emit("newDTMF",o)}},{key:"newInfo",value:function(o){W.debug("newInfo()"),this.emit("newInfo",o)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(W.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(W.debug("_isReadyToReOffer() | session not established yet"),!1):(W.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(W.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(W.debug("close() | closing local MediaStream"),Be.closeMediaStream(this._localMediaStream)),this._status!==X.STATUS_TERMINATED){if(this._status=X.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(d){W.warn("close() | error closing the RTCPeerConnection: %o",d)}for(var o in this._timers)Object.prototype.hasOwnProperty.call(this._timers,o)&&clearTimeout(this._timers[o]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(var s in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,s)&&(this._earlyDialogs[s].terminate(),delete this._earlyDialogs[s]);for(var r in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,r)&&delete this._referSubscribers[r];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(o,s){var r=$r.T1;function d(){this._status===X.STATUS_WAITING_FOR_ACK&&(o.reply(200,null,["Contact: ".concat(this._contact)],s),r<$r.T2&&(r=r*2,r>$r.T2&&(r=$r.T2)),this._timers.invite2xxTimer=setTimeout(d.bind(this),r))}this._timers.invite2xxTimer=setTimeout(d.bind(this),r)}},{key:"_setACKTimer",value:function(){var o=this;this._timers.ackTimer=setTimeout(function(){o._status===X.STATUS_WAITING_FOR_ACK&&(W.debug("no ACK received, terminating the session"),clearTimeout(o._timers.invite2xxTimer),o.sendRequest(ce.BYE),o._ended("remote",null,ce.causes.NO_ACK))},$r.TIMER_H)}},{key:"_createRTCConnection",value:function(o,s){var r=this;this._connection=new RTCPeerConnection(o,s),this._connection.addEventListener("iceconnectionstatechange",function(){var d=r._connection.iceConnectionState;d==="failed"&&r.terminate({cause:ce.causes.RTP_TIMEOUT,status_code:408,reason_phrase:ce.causes.RTP_TIMEOUT})}),W.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(o,s){var r=this;if(W.debug("createLocalDescription()"),o!=="offer"&&o!=="answer")throw new Error('createLocalDescription() | invalid type "'.concat(o,'"'));var d=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return o==="offer"?d.createOffer(s).catch(function(h){return W.warn('emit "peerconnection:createofferfailed" [error:%o]',h),r.emit("peerconnection:createofferfailed",h),Promise.reject(h)}):d.createAnswer(s).catch(function(h){return W.warn('emit "peerconnection:createanswerfailed" [error:%o]',h),r.emit("peerconnection:createanswerfailed",h),Promise.reject(h)})}).then(function(h){return d.setLocalDescription(h).catch(function(_){return r._rtcReady=!0,W.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',_),r.emit("peerconnection:setlocaldescriptionfailed",_),Promise.reject(_)})}).then(function(){var h=s&&s.iceRestart;if(d.iceGatheringState==="complete"&&!h||d.iceGatheringState==="gathering"&&r._iceReady){r._rtcReady=!0;var _={originator:"local",type:o,sdp:d.localDescription.sdp};return W.debug('emit "sdp"'),r.emit("sdp",_),Promise.resolve(_.sdp)}return new Promise(function(g){var T=!1,E,y;r._iceReady=!1;var A=function(){d.removeEventListener("icecandidate",E),d.removeEventListener("icegatheringstatechange",y),T=!0,r._rtcReady=!0,r._iceReady=!0;var I={originator:"local",type:o,sdp:d.localDescription.sdp};W.debug('emit "sdp"'),r.emit("sdp",I),g(I.sdp)};d.addEventListener("icecandidate",E=function(I){var H=I.candidate;H?r.emit("icecandidate",{candidate:H,ready:A}):T||A()}),d.addEventListener("icegatheringstatechange",y=function(){d.iceGatheringState==="complete"&&!T&&A()})})})}},{key:"_createDialog",value:function(o,s,r){var d=s==="UAS"?o.to_tag:o.from_tag,h=s==="UAS"?o.from_tag:o.to_tag,_=o.call_id+d+h,g=this._earlyDialogs[_];if(r)return g?!0:(g=new Bl(this,o,s,Bl.C.STATUS_EARLY),g.error?(W.debug(g.error),this._failed("remote",o,ce.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[_]=g,!0));if(this._from_tag=o.from_tag,this._to_tag=o.to_tag,g)return g.update(o,s),this._dialog=g,delete this._earlyDialogs[_],!0;var T=new Bl(this,o,s);return T.error?(W.debug(T.error),this._failed("remote",o,ce.causes.INTERNAL_ERROR),!1):(this._dialog=T,!0)}},{key:"_receiveReinvite",value:function(o){var s=this;W.debug("receiveReinvite()");var r=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0,d={request:o,callback:void 0,reject:_.bind(this)},h=!1;function _(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};h=!0;var E=T.status_code||403,y=T.reason_phrase||"",A=Be.cloneArray(T.extraHeaders);if(this._status!==X.STATUS_CONFIRMED)return!1;if(E<300||E>=700)throw new TypeError("Invalid status_code: ".concat(E));o.reply(E,y,A)}if(this.emit("reinvite",d),h)return;if(this._late_sdp=!1,!o.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._createLocalDescription("offer",s._rtcOfferConstraints)}).then(function(T){g.call(s,T)}).catch(function(){o.reply(500)});return}if(r!=="application/sdp"){W.debug("invalid Content-Type"),o.reply(415);return}this._processInDialogSdpOffer(o).then(function(T){s._status!==X.STATUS_TERMINATED&&g.call(s,T)}).catch(function(T){W.warn(T)});function g(T){var E=this,y=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(o,y),this._late_sdp&&(T=this._mangleOffer(T)),o.reply(200,null,y,T,function(){E._status=X.STATUS_WAITING_FOR_ACK,E._setInvite2xxTimer(o,T),E._setACKTimer()}),typeof d.callback=="function"&&d.callback()}}},{key:"_receiveUpdate",value:function(o){var s=this;W.debug("receiveUpdate()");var r=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0,d={request:o,callback:void 0,reject:_.bind(this)},h=!1;function _(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};h=!0;var E=T.status_code||403,y=T.reason_phrase||"",A=Be.cloneArray(T.extraHeaders);if(this._status!==X.STATUS_CONFIRMED)return!1;if(E<300||E>=700)throw new TypeError("Invalid status_code: ".concat(E));o.reply(E,y,A)}if(this.emit("update",d),h)return;if(!o.body){g.call(this,null);return}if(r!=="application/sdp"){W.debug("invalid Content-Type"),o.reply(415);return}this._processInDialogSdpOffer(o).then(function(T){s._status!==X.STATUS_TERMINATED&&g.call(s,T)}).catch(function(T){W.warn(T)});function g(T){var E=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(o,E),o.reply(200,null,E,T),typeof d.callback=="function"&&d.callback()}}},{key:"_processInDialogSdpOffer",value:function(o){var s=this;W.debug("_processInDialogSdpOffer()");var r=o.parseSDP(),d=!1,h=_s(r.media),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;if(Gl.indexOf(g.type)!==-1){var T=g.direction||r.direction||"sendrecv";if(T==="sendonly"||T==="inactive")d=!0;else{d=!1;break}}}}catch(A){h.e(A)}finally{h.f()}var E={originator:"remote",type:"offer",sdp:o.body};W.debug('emit "sdp"'),this.emit("sdp",E);var y=new RTCSessionDescription({type:"offer",sdp:E.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(s._status===X.STATUS_TERMINATED)throw new Error("terminated");return s._connection.setRemoteDescription(y).catch(function(A){throw o.reply(488),W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',A),s.emit("peerconnection:setremotedescriptionfailed",A),A})}).then(function(){if(s._status===X.STATUS_TERMINATED)throw new Error("terminated");s._remoteHold===!0&&d===!1?(s._remoteHold=!1,s._onunhold("remote")):s._remoteHold===!1&&d===!0&&(s._remoteHold=!0,s._onhold("remote"))}).then(function(){if(s._status===X.STATUS_TERMINATED)throw new Error("terminated");return s._createLocalDescription("answer",s._rtcAnswerConstraints).catch(function(A){throw o.reply(500),W.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',A),A})}).catch(function(A){W.warn("_processInDialogSdpOffer() failed [error: %o]",A)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(o){var s=this;if(W.debug("receiveRefer()"),!o.refer_to){W.debug("no Refer-To header field present in REFER"),o.reply(400);return}if(o.refer_to.uri.scheme!==ce.SIP){W.debug("Refer-To header field points to a non-SIP URI scheme"),o.reply(416);return}o.reply(202);var r=new Y_(this,o.cseq);W.debug('emit "refer"'),this.emit("refer",{request:o,accept:function(g,T){d.call(s,g,T)},reject:function(){h.call(s)}});function d(_){var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(_=typeof _=="function"?_:null,this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED)return!1;var T=new n(this._ua);if(T.on("progress",function(y){var A=y.response;r.notify(A.status_code,A.reason_phrase)}),T.on("accepted",function(y){var A=y.response;r.notify(A.status_code,A.reason_phrase)}),T.on("_failed",function(y){var A=y.message,C=y.cause;A?r.notify(A.status_code,A.reason_phrase):r.notify(487,C)}),o.refer_to.uri.hasHeader("replaces")){var E=decodeURIComponent(o.refer_to.uri.getHeader("replaces"));g.extraHeaders=Be.cloneArray(g.extraHeaders),g.extraHeaders.push("Replaces: ".concat(E))}T.connect(o.refer_to.uri.toAor(),g,_)}function h(){r.notify(603)}}},{key:"_receiveNotify",value:function(o){switch(W.debug("receiveNotify()"),o.event||o.reply(400),o.event.event){case"refer":{var s,r;if(o.event.params&&o.event.params.id)s=o.event.params.id,r=this._referSubscribers[s];else if(Object.keys(this._referSubscribers).length===1)r=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{o.reply(400,"Missing event id parameter");return}if(!r){o.reply(481,"Subscription does not exist");return}r.receiveNotify(o),o.reply(200);break}default:o.reply(489)}}},{key:"_receiveReplaces",value:function(o){var s=this;W.debug("receiveReplaces()");function r(h){var _=this;if(this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED)return!1;var g=new n(this._ua);g.on("confirmed",function(){_.terminate()}),g.init_incoming(o,h)}function d(){W.debug("Replaced INVITE rejected by the user"),o.reply(486)}this.emit("replaces",{request:o,accept:function(_){r.call(s,_)},reject:function(){d.call(s)}})}},{key:"_sendInitialRequest",value:function(o,s,r){var d=this,h=new K_(this._ua,this._request,{onRequestTimeout:function(){d.onRequestTimeout()},onTransportError:function(){d.onTransportError()},onAuthenticated:function(g){d._request=g},onReceiveResponse:function(g){d._receiveInviteResponse(g)}});Promise.resolve().then(function(){if(r)return r;if(o.audio||o.video)return d._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(o).catch(function(_){throw d._status===X.STATUS_TERMINATED?new Error("terminated"):(d._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),W.warn('emit "getusermediafailed" [error:%o]',_),d.emit("getusermediafailed",_),_)})}).then(function(_){if(d._status===X.STATUS_TERMINATED)throw new Error("terminated");return d._localMediaStream=_,_&&_.getTracks().forEach(function(g){d._connection.addTrack(g,_)}),d._connecting(d._request),d._createLocalDescription("offer",s).catch(function(g){throw d._failed("local",null,ce.causes.WEBRTC_ERROR),g})}).then(function(_){if(d._is_canceled||d._status===X.STATUS_TERMINATED)throw new Error("terminated");d._request.body=_,d._status=X.STATUS_INVITE_SENT,W.debug('emit "sending" [request:%o]',d._request),d.emit("sending",{request:d._request}),h.send()}).catch(function(_){d._status!==X.STATUS_TERMINATED&&W.warn(_)})}},{key:"_getDTMFRTPSender",value:function(){var o=this._connection.getSenders().find(function(s){return s.track&&s.track.kind==="audio"});if(!(o&&o.dtmf)){W.warn("sendDTMF() | no local audio track to send DTMF with");return}return o.dtmf}},{key:"_receiveInviteResponse",value:function(o){var s=this;if(W.debug("receiveInviteResponse()"),this._dialog&&o.status_code>=200&&o.status_code<=299)if(this._dialog.id.call_id===o.call_id&&this._dialog.id.local_tag===o.from_tag&&this._dialog.id.remote_tag===o.to_tag){this.sendRequest(ce.ACK);return}else{var r=new Bl(this,o,"UAC");if(r.error!==void 0){W.debug(r.error);return}this.sendRequest(ce.ACK),this.sendRequest(ce.BYE);return}if(this._is_canceled){o.status_code>=100&&o.status_code<200?this._request.cancel(this._cancel_reason):o.status_code>=200&&o.status_code<299&&this._acceptAndTerminate(o);return}if(!(this._status!==X.STATUS_INVITE_SENT&&this._status!==X.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(o.status_code):this._status=X.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(o.status_code):{if(!o.to_tag){W.debug("1xx response received without to tag");break}if(o.hasHeader("contact")&&!this._createDialog(o,"UAC",!0))break;if(this._status=X.STATUS_1XX_RECEIVED,!o.body){this._progress("remote",o);break}var d={originator:"remote",type:"answer",sdp:o.body};W.debug('emit "sdp"'),this.emit("sdp",d);var h=new RTCSessionDescription({type:"answer",sdp:d.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._connection.setRemoteDescription(h)}).then(function(){return s._progress("remote",o)}).catch(function(E){W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),s.emit("peerconnection:setremotedescriptionfailed",E)});break}case/^2[0-9]{2}$/.test(o.status_code):{if(this._status=X.STATUS_CONFIRMED,!o.body){this._acceptAndTerminate(o,400,ce.causes.MISSING_SDP),this._failed("remote",o,ce.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(o,"UAC"))break;var _={originator:"remote",type:"answer",sdp:o.body};W.debug('emit "sdp"'),this.emit("sdp",_);var g=new RTCSessionDescription({type:"answer",sdp:_.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(s._connection.signalingState==="stable")return s._connection.createOffer(s._rtcOfferConstraints).then(function(E){return s._connection.setLocalDescription(E)}).catch(function(E){s._acceptAndTerminate(o,500,E.toString()),s._failed("local",o,ce.causes.WEBRTC_ERROR)})}).then(function(){s._connection.setRemoteDescription(g).then(function(){s._handleSessionTimersInIncomingResponse(o),s._accepted("remote",o),s.sendRequest(ce.ACK),s._confirmed("local",null)}).catch(function(E){s._acceptAndTerminate(o,488,"Not Acceptable Here"),s._failed("remote",o,ce.causes.BAD_MEDIA_DESCRIPTION),W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),s.emit("peerconnection:setremotedescriptionfailed",E)})});break}default:{var T=Be.sipErrorCause(o.status_code);this._failed("remote",o,T)}}}},{key:"_sendReinvite",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};W.debug("sendReinvite()");var r=Be.cloneArray(s.extraHeaders),d=Be.cloneObject(s.eventHandlers),h=s.rtcOfferConstraints||this._rtcOfferConstraints||null,_=!1;r.push("Contact: ".concat(this._contact)),r.push("Content-Type: application/sdp"),this._sessionTimers.running&&r.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return o._createLocalDescription("offer",h)}).then(function(E){E=o._mangleOffer(E);var y={originator:"local",type:"offer",sdp:E};W.debug('emit "sdp"'),o.emit("sdp",y),o.sendRequest(ce.INVITE,{extraHeaders:r,body:E,eventHandlers:{onSuccessResponse:function(C){g.call(o,C),_=!0},onErrorResponse:function(C){T.call(o,C)},onTransportError:function(){o.onTransportError()},onRequestTimeout:function(){o.onRequestTimeout()},onDialogError:function(){o.onDialogError()}}})}).catch(function(){T()});function g(E){var y=this;if(this._status!==X.STATUS_TERMINATED&&(this.sendRequest(ce.ACK),!_)){if(this._handleSessionTimersInIncomingResponse(E),E.body){if(!E.hasHeader("Content-Type")||E.getHeader("Content-Type").toLowerCase()!=="application/sdp"){T.call(this);return}}else{T.call(this);return}var A={originator:"remote",type:"answer",sdp:E.body};W.debug('emit "sdp"'),this.emit("sdp",A);var C=new RTCSessionDescription({type:"answer",sdp:A.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return y._connection.setRemoteDescription(C)}).then(function(){d.succeeded&&d.succeeded(E)}).catch(function(I){T.call(y),W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',I),y.emit("peerconnection:setremotedescriptionfailed",I)})}}function T(E){d.failed&&d.failed(E)}}},{key:"_sendUpdate",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};W.debug("sendUpdate()");var r=Be.cloneArray(s.extraHeaders),d=Be.cloneObject(s.eventHandlers),h=s.rtcOfferConstraints||this._rtcOfferConstraints||null,_=s.sdpOffer||!1,g=!1;r.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&r.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),_?(r.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return o._createLocalDescription("offer",h)}).then(function(y){y=o._mangleOffer(y);var A={originator:"local",type:"offer",sdp:y};W.debug('emit "sdp"'),o.emit("sdp",A),o.sendRequest(ce.UPDATE,{extraHeaders:r,body:y,eventHandlers:{onSuccessResponse:function(I){T.call(o,I),g=!0},onErrorResponse:function(I){E.call(o,I)},onTransportError:function(){o.onTransportError()},onRequestTimeout:function(){o.onRequestTimeout()},onDialogError:function(){o.onDialogError()}}})}).catch(function(){E.call(o)})):this.sendRequest(ce.UPDATE,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(A){T.call(o,A)},onErrorResponse:function(A){E.call(o,A)},onTransportError:function(){o.onTransportError()},onRequestTimeout:function(){o.onRequestTimeout()},onDialogError:function(){o.onDialogError()}}});function T(y){var A=this;if(this._status!==X.STATUS_TERMINATED&&!g)if(this._handleSessionTimersInIncomingResponse(y),_){if(y.body){if(!y.hasHeader("Content-Type")||y.getHeader("Content-Type").toLowerCase()!=="application/sdp"){E.call(this);return}}else{E.call(this);return}var C={originator:"remote",type:"answer",sdp:y.body};W.debug('emit "sdp"'),this.emit("sdp",C);var I=new RTCSessionDescription({type:"answer",sdp:C.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return A._connection.setRemoteDescription(I)}).then(function(){d.succeeded&&d.succeeded(y)}).catch(function(H){E.call(A),W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',H),A.emit("peerconnection:setremotedescriptionfailed",H)})}else d.succeeded&&d.succeeded(y)}function E(y){d.failed&&d.failed(y)}}},{key:"_acceptAndTerminate",value:function(o,s,r){W.debug("acceptAndTerminate()");var d=[];s&&(r=r||ce.REASON_PHRASE[s]||"",d.push("Reason: SIP ;cause=".concat(s,'; text="').concat(r,'"'))),(this._dialog||this._createDialog(o,"UAC"))&&(this.sendRequest(ce.ACK),this.sendRequest(ce.BYE,{extraHeaders:d})),this._status=X.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(o){if(!this._localHold&&!this._remoteHold)return o;if(o=Yc.parse(o),this._localHold&&!this._remoteHold){W.debug("mangleOffer() | me on hold, mangling offer");var s=_s(o.media),r;try{for(s.s();!(r=s.n()).done;){var d=r.value;Gl.indexOf(d.type)!==-1&&(d.direction?d.direction==="sendrecv"?d.direction="sendonly":d.direction==="recvonly"&&(d.direction="inactive"):d.direction="sendonly")}}catch(A){s.e(A)}finally{s.f()}}else if(this._localHold&&this._remoteHold){W.debug("mangleOffer() | both on hold, mangling offer");var h=_s(o.media),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;Gl.indexOf(g.type)!==-1&&(g.direction="inactive")}}catch(A){h.e(A)}finally{h.f()}}else if(this._remoteHold){W.debug("mangleOffer() | remote on hold, mangling offer");var T=_s(o.media),E;try{for(T.s();!(E=T.n()).done;){var y=E.value;Gl.indexOf(y.type)!==-1&&(y.direction?y.direction==="sendrecv"?y.direction="recvonly":y.direction==="recvonly"&&(y.direction="inactive"):y.direction="recvonly")}}catch(A){T.e(A)}finally{T.f()}}return Yc.write(o)}},{key:"_setLocalMediaStatus",value:function(){var o=!0,s=!0;(this._localHold||this._remoteHold)&&(o=!1,s=!1),this._audioMuted&&(o=!1),this._videoMuted&&(s=!1),this._toggleMuteAudio(!o),this._toggleMuteVideo(!s)}},{key:"_handleSessionTimersInIncomingRequest",value:function(o,s){if(this._sessionTimers.enabled){var r;o.session_expires&&o.session_expires>=ce.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=o.session_expires,r=o.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,r="uas"),s.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(r)),this._sessionTimers.refresher=r==="uas",this._runSessionTimer()}}},{key:"_handleSessionTimersInIncomingResponse",value:function(o){if(this._sessionTimers.enabled){var s;o.session_expires&&o.session_expires>=ce.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=o.session_expires,s=o.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,s="uac"),this._sessionTimers.refresher=s==="uac",this._runSessionTimer()}}},{key:"_runSessionTimer",value:function(){var o=this,s=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){o._status!==X.STATUS_TERMINATED&&o._isReadyToReOffer()&&(W.debug("runSessionTimer() | sending session refresh request"),o._sessionTimers.refreshMethod===ce.UPDATE?o._sendUpdate():o._sendReinvite())},s*500):this._sessionTimers.timer=setTimeout(function(){o._status!==X.STATUS_TERMINATED&&(W.warn("runSessionTimer() | timer expired, terminating the session"),o.terminate({cause:ce.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},s*1100)}},{key:"_toggleMuteAudio",value:function(o){var s=this._connection.getSenders().filter(function(_){return _.track&&_.track.kind==="audio"}),r=_s(s),d;try{for(r.s();!(d=r.n()).done;){var h=d.value;h.track.enabled=!o}}catch(_){r.e(_)}finally{r.f()}}},{key:"_toggleMuteVideo",value:function(o){var s=this._connection.getSenders().filter(function(_){return _.track&&_.track.kind==="video"}),r=_s(s),d;try{for(r.s();!(d=r.n()).done;){var h=d.value;h.track.enabled=!o}}catch(_){r.e(_)}finally{r.f()}}},{key:"_newRTCSession",value:function(o,s){W.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:o,session:this,request:s})}},{key:"_connecting",value:function(o){W.debug("session connecting"),W.debug('emit "connecting"'),this.emit("connecting",{request:o})}},{key:"_progress",value:function(o,s){W.debug("session progress"),W.debug('emit "progress"'),this.emit("progress",{originator:o,response:s||null})}},{key:"_accepted",value:function(o,s){W.debug("session accepted"),this._start_time=new Date,W.debug('emit "accepted"'),this.emit("accepted",{originator:o,response:s||null})}},{key:"_confirmed",value:function(o,s){W.debug("session confirmed"),this._is_confirmed=!0,W.debug('emit "confirmed"'),this.emit("confirmed",{originator:o,ack:s||null})}},{key:"_ended",value:function(o,s,r){W.debug("session ended"),this._end_time=new Date,this._close(),W.debug('emit "ended"'),this.emit("ended",{originator:o,message:s||null,cause:r})}},{key:"_failed",value:function(o,s,r){W.debug("session failed"),W.debug('emit "_failed"'),this.emit("_failed",{originator:o,message:s||null,cause:r}),this._close(),W.debug('emit "failed"'),this.emit("failed",{originator:o,message:s||null,cause:r})}},{key:"_onhold",value:function(o){W.debug("session onhold"),this._setLocalMediaStatus(),W.debug('emit "hold"'),this.emit("hold",{originator:o})}},{key:"_onunhold",value:function(o){W.debug("session onunhold"),this._setLocalMediaStatus(),W.debug('emit "unhold"'),this.emit("unhold",{originator:o})}},{key:"_onmute",value:function(o){var s=o.audio,r=o.video;W.debug("session onmute"),this._setLocalMediaStatus(),W.debug('emit "muted"'),this.emit("muted",{audio:s,video:r})}},{key:"_onunmute",value:function(o){var s=o.audio,r=o.video;W.debug("session onunmute"),this._setLocalMediaStatus(),W.debug('emit "unmuted"'),this.emit("unmuted",{audio:s,video:r})}},{key:"C",get:function(){return X}},{key:"causes",get:function(){return ce.causes}},{key:"id",get:function(){return this._id}},{key:"connection",get:function(){return this._connection}},{key:"contact",get:function(){return this._contact}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}},{key:"start_time",get:function(){return this._start_time}},{key:"end_time",get:function(){return this._end_time}},{key:"data",get:function(){return this._data},set:function(o){this._data=o}},{key:"status",get:function(){return this._status}}]),n}(B_);function Wl(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Wl=function(n){return typeof n}:Wl=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Wl(c)}function X_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Qc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Q_(c,t,n){return t&&Qc(c.prototype,t),n&&Qc(c,n),c}function Z_(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&Ao(c,t)}function Ao(c,t){return Ao=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},Ao(c,t)}function ep(c){var t=np();return function(){var a=Kl(c),o;if(t){var s=Kl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return tp(this,o)}}function tp(c,t){return t&&(Wl(t)==="object"||typeof t=="function")?t:sp(c)}function sp(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function np(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Kl(c){return Kl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Kl(c)}var rp=ct.EventEmitter,ip=ft,Co=st,lp=fs,Hr=Rt(),ap=xr,Zc=Is,op=bs(),Yl=new ip("Message"),up=function(c){Z_(n,c);var t=ep(n);function n(a){var o;return X_(this,n),o=t.call(this),o._ua=a,o._request=null,o._closed=!1,o._direction=null,o._local_identity=null,o._remote_identity=null,o._is_replied=!1,o._data={},o}return Q_(n,[{key:"send",value:function(o,s){var r=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},h=o;if(o===void 0||s===void 0)throw new TypeError("Not enough arguments");if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(h));var _=Hr.cloneArray(d.extraHeaders),g=Hr.cloneObject(d.eventHandlers),T=d.contentType||"text/plain",E={};d.fromUserName&&(E.from_uri=new op("sip",d.fromUserName,this._ua.configuration.uri.host),_.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),d.fromDisplayName&&(E.from_display_name=d.fromDisplayName);for(var y in g)Object.prototype.hasOwnProperty.call(g,y)&&this.on(y,g[y]);_.push("Content-Type: ".concat(T)),this._request=new lp.OutgoingRequest(Co.MESSAGE,o,this._ua,E,_),s&&(this._request.body=s);var A=new ap(this._ua,this._request,{onRequestTimeout:function(){r._onRequestTimeout()},onTransportError:function(){r._onTransportError()},onReceiveResponse:function(I){r._receiveResponse(I)}});this._newMessage("local",this._request),A.send()}},{key:"init_incoming",value:function(o){this._request=o,this._newMessage("remote",o),this._is_replied||(this._is_replied=!0,o.reply(200)),this._close()}},{key:"accept",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=Hr.cloneArray(o.extraHeaders),r=o.body;if(this._direction!=="incoming")throw new Zc.NotSupportedError('"accept" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");this._is_replied=!0,this._request.reply(200,null,s,r)}},{key:"reject",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=o.status_code||480,r=o.reason_phrase,d=Hr.cloneArray(o.extraHeaders),h=o.body;if(this._direction!=="incoming")throw new Zc.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(s<300||s>=700)throw new TypeError("Invalid status_code: ".concat(s));this._is_replied=!0,this._request.reply(s,r,d,h)}},{key:"_receiveResponse",value:function(o){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):this._succeeded("remote",o);break;default:{var s=Hr.sipErrorCause(o.status_code);this._failed("remote",o,s);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,Co.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,Co.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newMessage",value:function(o,s){o==="remote"?(this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from):o==="local"&&(this._direction="outgoing",this._local_identity=s.from,this._remote_identity=s.to),this._ua.newMessage(this,{originator:o,message:this,request:s})}},{key:"_failed",value:function(o,s,r){Yl.debug("MESSAGE failed"),this._close(),Yl.debug('emit "failed"'),this.emit("failed",{originator:o,response:s||null,cause:r})}},{key:"_succeeded",value:function(o,s){Yl.debug("MESSAGE succeeded"),this._close(),Yl.debug('emit "succeeded"'),this.emit("succeeded",{originator:o,response:s})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}]),n}(rp);function Jl(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Jl=function(n){return typeof n}:Jl=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Jl(c)}function cp(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function ef(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function fp(c,t,n){return t&&ef(c.prototype,t),n&&ef(c,n),c}function hp(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&Ro(c,t)}function Ro(c,t){return Ro=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},Ro(c,t)}function dp(c){var t=mp();return function(){var a=zl(c),o;if(t){var s=zl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return _p(this,o)}}function _p(c,t){return t&&(Jl(t)==="object"||typeof t=="function")?t:pp(c)}function pp(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function mp(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function zl(c){return zl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},zl(c)}var gp=ct.EventEmitter,Tp=ft,Io=st,vp=fs,Fr=Rt(),Ep=xr,tf=Is,Xl=new Tp("Options"),Sp=function(c){hp(n,c);var t=dp(n);function n(a){var o;return cp(this,n),o=t.call(this),o._ua=a,o._request=null,o._closed=!1,o._direction=null,o._local_identity=null,o._remote_identity=null,o._is_replied=!1,o._data={},o}return fp(n,[{key:"send",value:function(o,s){var r=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},h=o;if(o===void 0)throw new TypeError("A target is required for OPTIONS");if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(h));var _=Fr.cloneArray(d.extraHeaders),g=Fr.cloneObject(d.eventHandlers),T=d.contentType||"application/sdp";for(var E in g)Object.prototype.hasOwnProperty.call(g,E)&&this.on(E,g[E]);_.push("Content-Type: ".concat(T)),this._request=new vp.OutgoingRequest(Io.OPTIONS,o,this._ua,null,_),s&&(this._request.body=s);var y=new Ep(this._ua,this._request,{onRequestTimeout:function(){r._onRequestTimeout()},onTransportError:function(){r._onTransportError()},onReceiveResponse:function(C){r._receiveResponse(C)}});this._newOptions("local",this._request),y.send()}},{key:"init_incoming",value:function(o){this._request=o,this._newOptions("remote",o),this._is_replied||(this._is_replied=!0,o.reply(200)),this._close()}},{key:"accept",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=Fr.cloneArray(o.extraHeaders),r=o.body;if(this._direction!=="incoming")throw new tf.NotSupportedError('"accept" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");this._is_replied=!0,this._request.reply(200,null,s,r)}},{key:"reject",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=o.status_code||480,r=o.reason_phrase,d=Fr.cloneArray(o.extraHeaders),h=o.body;if(this._direction!=="incoming")throw new tf.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(s<300||s>=700)throw new TypeError("Invalid status_code: ".concat(s));this._is_replied=!0,this._request.reply(s,r,d,h)}},{key:"_receiveResponse",value:function(o){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):this._succeeded("remote",o);break;default:{var s=Fr.sipErrorCause(o.status_code);this._failed("remote",o,s);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,Io.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,Io.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newOptions",value:function(o,s){o==="remote"?(this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from):o==="local"&&(this._direction="outgoing",this._local_identity=s.from,this._remote_identity=s.to),this._ua.newOptions(this,{originator:o,message:this,request:s})}},{key:"_failed",value:function(o,s,r){Xl.debug("OPTIONS failed"),this._close(),Xl.debug('emit "failed"'),this.emit("failed",{originator:o,response:s||null,cause:r})}},{key:"_succeeded",value:function(o,s){Xl.debug("OPTIONS succeeded"),this._close(),Xl.debug('emit "succeeded"'),this.emit("succeeded",{originator:o,response:s})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}]),n}(gp),bo={},yp=ft,wo=Rt(),Ap=ss(),jr=new yp("Socket");bo.isSocket=function(c){if(Array.isArray(c))return!1;if(typeof c>"u")return jr.warn("undefined JsSIP.Socket instance"),!1;try{if(!wo.isString(c.url))throw jr.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!wo.isString(c.via_transport))throw jr.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(Ap.parse(c.sip_uri,"SIP_URI")===-1)throw jr.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch{return!1}try{["connect","disconnect","send"].forEach(function(t){if(!wo.isFunction(c[t]))throw jr.warn("missing or invalid JsSIP.Socket method: ".concat(t)),new Error("Missing or invalid JsSIP.Socket method: ".concat(t))})}catch{return!1}return!0};function Cp(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function sf(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Rp(c,t,n){return t&&sf(c.prototype,t),n&&sf(c,n),c}var Ip=ft,bp=bo,nf=st,Pt=new Ip("Transport"),Ft={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:nf.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:nf.CONNECTION_RECOVERY_MAX_INTERVAL}},wp=function(){function c(t){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ft.recovery_options;Cp(this,c),Pt.debug("new()"),this.status=Ft.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(a){Pt.warn("cannot use TextDecoder: ".concat(a))}if(typeof t>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(a){if(!bp.isSocket(a.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(a.weight&&!Number(a.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:a.socket,weight:a.weight||0,status:Ft.SOCKET_STATUS_READY})},this),this._getSocket()}return Rp(c,[{key:"connect",value:function(){if(Pt.debug("connect()"),this.isConnected()){Pt.debug("Transport is already connected");return}else if(this.isConnecting()){Pt.debug("Transport is connecting");return}this.close_requested=!1,this.status=Ft.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect())}},{key:"disconnect",value:function(){Pt.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=Ft.STATUS_DISCONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(n){if(Pt.debug("send()"),!this.isConnected())return Pt.warn("unable to send message, transport is not connected"),!1;var a=n.toString();return Pt.debug(`sending message:
|
50
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function L_(c,t){if(c){if(typeof c=="string")return Gc(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Gc(c,t)}}function Gc(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}function $_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Wc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Kc(c,t,n){return t&&Wc(c.prototype,t),n&&Wc(c,n),c}function H_(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&yo(c,t)}function yo(c,t){return yo=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},yo(c,t)}function F_(c){var t=V_();return function(){var a=Vl(c),o;if(t){var s=Vl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return j_(this,o)}}function j_(c,t){return t&&(ql(t)==="object"||typeof t=="function")?t:q_(c)}function q_(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function V_(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Vl(c){return Vl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Vl(c)}var B_=ct.EventEmitter,Yc=Ut,G_=ft,ce=st,Zs=Is,Jc=Pr,Be=Rt(),$r=Cc,W_=fs,Bl=Jd,K_=xr,Lt=o_,zc=E_,Y_=R_,J_=M_,Xc=bs(),W=new G_("RTCSession"),X={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9},Gl=["audio","video"],z_=function(c){H_(n,c);var t=F_(n);Kc(n,null,[{key:"C",get:function(){return X}}]);function n(a){var o;return $_(this,n),W.debug("new"),o=t.call(this),o._id=null,o._ua=a,o._status=X.STATUS_NULL,o._dialog=null,o._earlyDialogs={},o._contact=null,o._from_tag=null,o._to_tag=null,o._connection=null,o._connectionPromiseQueue=Promise.resolve(),o._request=null,o._is_canceled=!1,o._cancel_reason="",o._is_confirmed=!1,o._late_sdp=!1,o._rtcOfferConstraints=null,o._rtcAnswerConstraints=null,o._localMediaStream=null,o._localMediaStreamLocallyGenerated=!1,o._rtcReady=!0,o._iceReady=!1,o._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},o._direction=null,o._local_identity=null,o._remote_identity=null,o._start_time=null,o._end_time=null,o._tones=null,o._audioMuted=!1,o._videoMuted=!1,o._localHold=!1,o._remoteHold=!1,o._sessionTimers={enabled:o._ua.configuration.session_timers,refreshMethod:o._ua.configuration.session_timers_refresh_method,defaultExpires:ce.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},o._referSubscribers={},o._data={},o}return Kc(n,[{key:"isInProgress",value:function(){switch(this._status){case X.STATUS_NULL:case X.STATUS_INVITE_SENT:case X.STATUS_1XX_RECEIVED:case X.STATUS_INVITE_RECEIVED:case X.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}},{key:"isEstablished",value:function(){switch(this._status){case X.STATUS_ANSWERED:case X.STATUS_WAITING_FOR_ACK:case X.STATUS_CONFIRMED:return!0;default:return!1}}},{key:"isEnded",value:function(){switch(this._status){case X.STATUS_CANCELED:case X.STATUS_TERMINATED:return!0;default:return!1}}},{key:"isMuted",value:function(){return{audio:this._audioMuted,video:this._videoMuted}}},{key:"isOnHold",value:function(){return{local:this._localHold,remote:this._remoteHold}}},{key:"connect",value:function(o){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;W.debug("connect()");var d=o,h=Be.cloneObject(s.eventHandlers),_=Be.cloneArray(s.extraHeaders),g=Be.cloneObject(s.mediaConstraints,{audio:!0,video:!0}),T=s.mediaStream||null,E=Be.cloneObject(s.pcConfig,{iceServers:[]}),y=s.rtcConstraints||null,C=s.rtcOfferConstraints||null;if(this._rtcOfferConstraints=C,this._rtcAnswerConstraints=s.rtcAnswerConstraints||null,this._data=s.data||this._data,o===void 0)throw new TypeError("Not enough arguments");if(this._status!==X.STATUS_NULL)throw new Zs.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new Zs.NotSupportedError("WebRTC not supported");if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(d));this._sessionTimers.enabled&&Be.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES);for(var A in h)Object.prototype.hasOwnProperty.call(h,A)&&this.on(A,h[A]);this._from_tag=Be.newTag();var I=s.anonymous||!1,H={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:I,outbound:!0}),I?(H.from_display_name="Anonymous",H.from_uri=new Xc("sip","anonymous","anonymous.invalid"),_.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),_.push("Privacy: id")):s.fromUserName&&(H.from_uri=new Xc("sip",s.fromUserName,this._ua.configuration.uri.host),_.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),s.fromDisplayName&&(H.from_display_name=s.fromDisplayName),_.push("Contact: ".concat(this._contact)),_.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&_.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher?";refresher=uac":"")),this._request=new W_.InitialOutgoingInviteRequest(o,this._ua,H,_),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(E,y),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,r&&r(this),this._newRTCSession("local",this._request),this._sendInitialRequest(g,C,T)}},{key:"init_incoming",value:function(o,s){var r=this;W.debug("init_incoming()");var d,h=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0;if(o.body&&h!=="application/sdp"){o.reply(415);return}if(this._status=X.STATUS_INVITE_RECEIVED,this._from_tag=o.from_tag,this._id=o.call_id+this._from_tag,this._request=o,this._contact=this._ua.contact.toString(),o.hasHeader("expires")&&(d=o.getHeader("expires")*1e3),o.to_tag=Be.newTag(),!this._createDialog(o,"UAS",!0)){o.reply(500,"Missing Contact header field");return}o.body?this._late_sdp=!1:this._late_sdp=!0,this._status=X.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){o.reply(408),r._failed("local",null,ce.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),d&&(this._timers.expiresTimer=setTimeout(function(){r._status===X.STATUS_WAITING_FOR_ANSWER&&(o.reply(487),r._failed("system",null,ce.causes.EXPIRES))},d)),this._direction="incoming",this._local_identity=o.to,this._remote_identity=o.from,s&&s(this),this._newRTCSession("remote",o),this._status!==X.STATUS_TERMINATED&&(o.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))}},{key:"answer",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};W.debug("answer()");var r=this._request,d=Be.cloneArray(s.extraHeaders),h=Be.cloneObject(s.mediaConstraints),_=s.mediaStream||null,g=Be.cloneObject(s.pcConfig,{iceServers:[]}),T=s.rtcConstraints||null,E=s.rtcAnswerConstraints||null,y=Be.cloneObject(s.rtcOfferConstraints),C,A=!1,I=!1,H=!1,$=!1;if(this._rtcAnswerConstraints=E,this._rtcOfferConstraints=s.rtcOfferConstraints||null,this._data=s.data||this._data,this._direction!=="incoming")throw new Zs.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==X.STATUS_WAITING_FOR_ANSWER)throw new Zs.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Be.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES),this._status=X.STATUS_ANSWERED,!this._createDialog(r,"UAS")){r.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),d.unshift("Contact: ".concat(this._contact));var oe=r.parseSDP();Array.isArray(oe.media)||(oe.media=[oe.media]);var N=_s(oe.media),j;try{for(N.s();!(j=N.n()).done;){var Se=j.value;Se.type==="audio"&&(A=!0,(!Se.direction||Se.direction==="sendrecv")&&(H=!0)),Se.type==="video"&&(I=!0,(!Se.direction||Se.direction==="sendrecv")&&($=!0))}}catch(F){N.e(F)}finally{N.f()}if(_&&h.audio===!1){C=_.getAudioTracks();var ve=_s(C),k;try{for(ve.s();!(k=ve.n()).done;){var D=k.value;_.removeTrack(D)}}catch(F){ve.e(F)}finally{ve.f()}}if(_&&h.video===!1){C=_.getVideoTracks();var B=_s(C),V;try{for(B.s();!(V=B.n()).done;){var J=V.value;_.removeTrack(J)}}catch(F){B.e(F)}finally{B.f()}}!_&&h.audio===void 0&&(h.audio=H),!_&&h.video===void 0&&(h.video=$),!_&&!A&&!y.offerToReceiveAudio&&(h.audio=!1),!_&&!I&&!y.offerToReceiveVideo&&(h.video=!1),this._createRTCConnection(g,T),Promise.resolve().then(function(){if(_)return _;if(h.audio||h.video)return o._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(h).catch(function(F){throw o._status===X.STATUS_TERMINATED?new Error("terminated"):(r.reply(480),o._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),W.warn('emit "getusermediafailed" [error:%o]',F),o.emit("getusermediafailed",F),new Error("getUserMedia() failed"))})}).then(function(F){if(o._status===X.STATUS_TERMINATED)throw new Error("terminated");o._localMediaStream=F,F&&F.getTracks().forEach(function(Z){o._connection.addTrack(Z,F)})}).then(function(){if(!o._late_sdp){var F={originator:"remote",type:"offer",sdp:r.body};W.debug('emit "sdp"'),o.emit("sdp",F);var Z=new RTCSessionDescription({type:"offer",sdp:F.sdp});return o._connectionPromiseQueue=o._connectionPromiseQueue.then(function(){return o._connection.setRemoteDescription(Z)}).catch(function(U){throw r.reply(488),o._failed("system",null,ce.causes.WEBRTC_ERROR),W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',U),o.emit("peerconnection:setremotedescriptionfailed",U),new Error("peerconnection.setRemoteDescription() failed")}),o._connectionPromiseQueue}}).then(function(){if(o._status===X.STATUS_TERMINATED)throw new Error("terminated");return o._connecting(r),o._late_sdp?o._createLocalDescription("offer",o._rtcOfferConstraints).catch(function(){throw r.reply(500),new Error("_createLocalDescription() failed")}):o._createLocalDescription("answer",E).catch(function(){throw r.reply(500),new Error("_createLocalDescription() failed")})}).then(function(F){if(o._status===X.STATUS_TERMINATED)throw new Error("terminated");o._handleSessionTimersInIncomingRequest(r,d),r.reply(200,null,d,F,function(){o._status=X.STATUS_WAITING_FOR_ACK,o._setInvite2xxTimer(r,F),o._setACKTimer(),o._accepted("local")},function(){o._failed("system",null,ce.causes.CONNECTION_ERROR)})}).catch(function(F){o._status!==X.STATUS_TERMINATED&&W.warn(F)})}},{key:"terminate",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};W.debug("terminate()");var r=s.cause||ce.causes.BYE,d=Be.cloneArray(s.extraHeaders),h=s.body,_,g=s.status_code,T=s.reason_phrase;if(this._status===X.STATUS_TERMINATED)throw new Zs.InvalidStateError(this._status);switch(this._status){case X.STATUS_NULL:case X.STATUS_INVITE_SENT:case X.STATUS_1XX_RECEIVED:if(W.debug("canceling session"),g&&(g<200||g>=700))throw new TypeError("Invalid status_code: ".concat(g));g&&(T=T||ce.REASON_PHRASE[g]||"",_="SIP ;cause=".concat(g,' ;text="').concat(T,'"')),this._status===X.STATUS_NULL||this._status===X.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=_):this._status===X.STATUS_1XX_RECEIVED&&this._request.cancel(_),this._status=X.STATUS_CANCELED,this._failed("local",null,ce.causes.CANCELED);break;case X.STATUS_WAITING_FOR_ANSWER:case X.STATUS_ANSWERED:if(W.debug("rejecting session"),g=g||480,g<300||g>=700)throw new TypeError("Invalid status_code: ".concat(g));this._request.reply(g,T,d,h),this._failed("local",null,ce.causes.REJECTED);break;case X.STATUS_WAITING_FOR_ACK:case X.STATUS_CONFIRMED:if(W.debug("terminating session"),T=s.reason_phrase||ce.REASON_PHRASE[g]||"",g&&(g<200||g>=700))throw new TypeError("Invalid status_code: ".concat(g));if(g&&d.push("Reason: SIP ;cause=".concat(g,'; text="').concat(T,'"')),this._status===X.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Jc.C.STATUS_TERMINATED){var E=this._dialog;this.receiveRequest=function(y){var C=y.method;C===ce.ACK&&(o.sendRequest(ce.BYE,{extraHeaders:d,body:h}),E.terminate())},this._request.server_transaction.on("stateChanged",function(){o._request.server_transaction.state===Jc.C.STATUS_TERMINATED&&(o.sendRequest(ce.BYE,{extraHeaders:d,body:h}),E.terminate())}),this._ended("local",null,r),this._dialog=E,this._ua.newDialog(E)}else this.sendRequest(ce.BYE,{extraHeaders:d,body:h}),this._ended("local",null,r)}}},{key:"sendDTMF",value:function(o){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};W.debug("sendDTMF() | tones: %s",o);var r=0,d=s.duration||null,h=s.interToneGap||null,_=s.transportType||ce.DTMF_TRANSPORT.INFO;if(o===void 0)throw new TypeError("Not enough arguments");if(this._status!==X.STATUS_CONFIRMED&&this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_1XX_RECEIVED)throw new Zs.InvalidStateError(this._status);if(_!==ce.DTMF_TRANSPORT.INFO&&_!==ce.DTMF_TRANSPORT.RFC2833)throw new TypeError("invalid transportType: ".concat(_));if(typeof o=="number"&&(o=o.toString()),!o||typeof o!="string"||!o.match(/^[0-9A-DR#*,]+$/i))throw new TypeError("Invalid tones: ".concat(o));if(d&&!Be.isDecimal(d))throw new TypeError("Invalid tone duration: ".concat(d));if(d?d<Lt.C.MIN_DURATION?(W.debug('"duration" value is lower than the minimum allowed, setting it to '.concat(Lt.C.MIN_DURATION," milliseconds")),d=Lt.C.MIN_DURATION):d>Lt.C.MAX_DURATION?(W.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(Lt.C.MAX_DURATION," milliseconds")),d=Lt.C.MAX_DURATION):d=Math.abs(d):d=Lt.C.DEFAULT_DURATION,s.duration=d,h&&!Be.isDecimal(h))throw new TypeError("Invalid interToneGap: ".concat(h));if(h?h<Lt.C.MIN_INTER_TONE_GAP?(W.debug('"interToneGap" value is lower than the minimum allowed, setting it to '.concat(Lt.C.MIN_INTER_TONE_GAP," milliseconds")),h=Lt.C.MIN_INTER_TONE_GAP):h=Math.abs(h):h=Lt.C.DEFAULT_INTER_TONE_GAP,_===ce.DTMF_TRANSPORT.RFC2833){var g=this._getDTMFRTPSender();g&&(o=g.toneBuffer+o,g.insertDTMF(o,d,h));return}if(this._tones){this._tones+=o;return}this._tones=o,T.call(this);function T(){var E=this,y;if(this._status===X.STATUS_TERMINATED||!this._tones||r>=this._tones.length){this._tones=null;return}var C=this._tones[r];if(r+=1,C===",")y=2e3;else{var A=new Lt(this);s.eventHandlers={onFailed:function(){E._tones=null}},A.send(C,s),y=d+h}setTimeout(T.bind(this),y)}}},{key:"sendInfo",value:function(o,s){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(W.debug("sendInfo()"),this._status!==X.STATUS_CONFIRMED&&this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_1XX_RECEIVED)throw new Zs.InvalidStateError(this._status);var d=new zc(this);d.send(o,s,r)}},{key:"mute",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!1};W.debug("mute()");var s=!1,r=!1;this._audioMuted===!1&&o.audio&&(s=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&o.video&&(r=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(s===!0||r===!0)&&this._onmute({audio:s,video:r})}},{key:"unmute",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!0};W.debug("unmute()");var s=!1,r=!1;this._audioMuted===!0&&o.audio&&(s=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&o.video&&(r=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(s===!0||r===!0)&&this._onunmute({audio:s,video:r})}},{key:"hold",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;if(W.debug("hold()"),this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var d={succeeded:function(){r&&r()},failed:function(){o.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:d,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:d,extraHeaders:s.extraHeaders}),!0}},{key:"unhold",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;if(W.debug("unhold()"),this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var d={succeeded:function(){r&&r()},failed:function(){o.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:d,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:d,extraHeaders:s.extraHeaders}),!0}},{key:"renegotiate",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;W.debug("renegotiate()");var d=s.rtcOfferConstraints||null;if(this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;var h={succeeded:function(){r&&r()},failed:function(){o.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:h,rtcOfferConstraints:d,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:h,rtcOfferConstraints:d,extraHeaders:s.extraHeaders}),!0}},{key:"refer",value:function(o,s){var r=this;W.debug("refer()");var d=o;if(this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED)return!1;if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(d));var h=new J_(this);h.sendRefer(o,s);var _=h.id;return this._referSubscribers[_]=h,h.on("requestFailed",function(){delete r._referSubscribers[_]}),h.on("accepted",function(){delete r._referSubscribers[_]}),h.on("failed",function(){delete r._referSubscribers[_]}),h}},{key:"sendRequest",value:function(o,s){return W.debug("sendRequest()"),this._dialog.sendRequest(o,s)}},{key:"receiveRequest",value:function(o){var s=this;if(W.debug("receiveRequest()"),o.method===ce.CANCEL)(this._status===X.STATUS_WAITING_FOR_ANSWER||this._status===X.STATUS_ANSWERED)&&(this._status=X.STATUS_CANCELED,this._request.reply(487),this._failed("remote",o,ce.causes.CANCELED));else switch(o.method){case ce.ACK:if(this._status!==X.STATUS_WAITING_FOR_ACK)return;if(this._status=X.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!o.body){this.terminate({cause:ce.causes.MISSING_SDP,status_code:400});break}var r={originator:"remote",type:"answer",sdp:o.body};W.debug('emit "sdp"'),this.emit("sdp",r);var d=new RTCSessionDescription({type:"answer",sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._connection.setRemoteDescription(d)}).then(function(){s._is_confirmed||s._confirmed("remote",o)}).catch(function(_){s.terminate({cause:ce.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',_),s.emit("peerconnection:setremotedescriptionfailed",_)})}else this._is_confirmed||this._confirmed("remote",o);break;case ce.BYE:this._status===X.STATUS_CONFIRMED||this._status===X.STATUS_WAITING_FOR_ACK?(o.reply(200),this._ended("remote",o,ce.causes.BYE)):this._status===X.STATUS_INVITE_RECEIVED||this._status===X.STATUS_WAITING_FOR_ANSWER?(o.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",o,ce.causes.BYE)):o.reply(403,"Wrong Status");break;case ce.INVITE:this._status===X.STATUS_CONFIRMED?o.hasHeader("replaces")?this._receiveReplaces(o):this._receiveReinvite(o):o.reply(403,"Wrong Status");break;case ce.INFO:if(this._status===X.STATUS_1XX_RECEIVED||this._status===X.STATUS_WAITING_FOR_ANSWER||this._status===X.STATUS_ANSWERED||this._status===X.STATUS_WAITING_FOR_ACK||this._status===X.STATUS_CONFIRMED){var h=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0;h&&h.match(/^application\/dtmf-relay/i)?new Lt(this).init_incoming(o):h!==void 0?new zc(this).init_incoming(o):o.reply(415)}else o.reply(403,"Wrong Status");break;case ce.UPDATE:this._status===X.STATUS_CONFIRMED?this._receiveUpdate(o):o.reply(403,"Wrong Status");break;case ce.REFER:this._status===X.STATUS_CONFIRMED?this._receiveRefer(o):o.reply(403,"Wrong Status");break;case ce.NOTIFY:this._status===X.STATUS_CONFIRMED?this._receiveNotify(o):o.reply(403,"Wrong Status");break;default:o.reply(501)}}},{key:"onTransportError",value:function(){W.warn("onTransportError()"),this._status!==X.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ce.causes.CONNECTION_ERROR,cause:ce.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){W.warn("onRequestTimeout()"),this._status!==X.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:ce.causes.REQUEST_TIMEOUT,cause:ce.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){W.warn("onDialogError()"),this._status!==X.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ce.causes.DIALOG_ERROR,cause:ce.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(o){W.debug("newDTMF()"),this.emit("newDTMF",o)}},{key:"newInfo",value:function(o){W.debug("newInfo()"),this.emit("newInfo",o)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(W.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(W.debug("_isReadyToReOffer() | session not established yet"),!1):(W.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(W.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(W.debug("close() | closing local MediaStream"),Be.closeMediaStream(this._localMediaStream)),this._status!==X.STATUS_TERMINATED){if(this._status=X.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(d){W.warn("close() | error closing the RTCPeerConnection: %o",d)}for(var o in this._timers)Object.prototype.hasOwnProperty.call(this._timers,o)&&clearTimeout(this._timers[o]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(var s in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,s)&&(this._earlyDialogs[s].terminate(),delete this._earlyDialogs[s]);for(var r in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,r)&&delete this._referSubscribers[r];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(o,s){var r=$r.T1;function d(){this._status===X.STATUS_WAITING_FOR_ACK&&(o.reply(200,null,["Contact: ".concat(this._contact)],s),r<$r.T2&&(r=r*2,r>$r.T2&&(r=$r.T2)),this._timers.invite2xxTimer=setTimeout(d.bind(this),r))}this._timers.invite2xxTimer=setTimeout(d.bind(this),r)}},{key:"_setACKTimer",value:function(){var o=this;this._timers.ackTimer=setTimeout(function(){o._status===X.STATUS_WAITING_FOR_ACK&&(W.debug("no ACK received, terminating the session"),clearTimeout(o._timers.invite2xxTimer),o.sendRequest(ce.BYE),o._ended("remote",null,ce.causes.NO_ACK))},$r.TIMER_H)}},{key:"_createRTCConnection",value:function(o,s){var r=this;this._connection=new RTCPeerConnection(o,s),this._connection.addEventListener("iceconnectionstatechange",function(){var d=r._connection.iceConnectionState;d==="failed"&&r.terminate({cause:ce.causes.RTP_TIMEOUT,status_code:408,reason_phrase:ce.causes.RTP_TIMEOUT})}),W.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(o,s){var r=this;if(W.debug("createLocalDescription()"),o!=="offer"&&o!=="answer")throw new Error('createLocalDescription() | invalid type "'.concat(o,'"'));var d=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return o==="offer"?d.createOffer(s).catch(function(h){return W.warn('emit "peerconnection:createofferfailed" [error:%o]',h),r.emit("peerconnection:createofferfailed",h),Promise.reject(h)}):d.createAnswer(s).catch(function(h){return W.warn('emit "peerconnection:createanswerfailed" [error:%o]',h),r.emit("peerconnection:createanswerfailed",h),Promise.reject(h)})}).then(function(h){return d.setLocalDescription(h).catch(function(_){return r._rtcReady=!0,W.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',_),r.emit("peerconnection:setlocaldescriptionfailed",_),Promise.reject(_)})}).then(function(){var h=s&&s.iceRestart;if(d.iceGatheringState==="complete"&&!h||d.iceGatheringState==="gathering"&&r._iceReady){r._rtcReady=!0;var _={originator:"local",type:o,sdp:d.localDescription.sdp};return W.debug('emit "sdp"'),r.emit("sdp",_),Promise.resolve(_.sdp)}return new Promise(function(g){var T=!1,E,y;r._iceReady=!1;var C=function(){d.removeEventListener("icecandidate",E),d.removeEventListener("icegatheringstatechange",y),T=!0,r._rtcReady=!0,r._iceReady=!0;var I={originator:"local",type:o,sdp:d.localDescription.sdp};W.debug('emit "sdp"'),r.emit("sdp",I),g(I.sdp)};d.addEventListener("icecandidate",E=function(I){var H=I.candidate;H?r.emit("icecandidate",{candidate:H,ready:C}):T||C()}),d.addEventListener("icegatheringstatechange",y=function(){d.iceGatheringState==="complete"&&!T&&C()})})})}},{key:"_createDialog",value:function(o,s,r){var d=s==="UAS"?o.to_tag:o.from_tag,h=s==="UAS"?o.from_tag:o.to_tag,_=o.call_id+d+h,g=this._earlyDialogs[_];if(r)return g?!0:(g=new Bl(this,o,s,Bl.C.STATUS_EARLY),g.error?(W.debug(g.error),this._failed("remote",o,ce.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[_]=g,!0));if(this._from_tag=o.from_tag,this._to_tag=o.to_tag,g)return g.update(o,s),this._dialog=g,delete this._earlyDialogs[_],!0;var T=new Bl(this,o,s);return T.error?(W.debug(T.error),this._failed("remote",o,ce.causes.INTERNAL_ERROR),!1):(this._dialog=T,!0)}},{key:"_receiveReinvite",value:function(o){var s=this;W.debug("receiveReinvite()");var r=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0,d={request:o,callback:void 0,reject:_.bind(this)},h=!1;function _(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};h=!0;var E=T.status_code||403,y=T.reason_phrase||"",C=Be.cloneArray(T.extraHeaders);if(this._status!==X.STATUS_CONFIRMED)return!1;if(E<300||E>=700)throw new TypeError("Invalid status_code: ".concat(E));o.reply(E,y,C)}if(this.emit("reinvite",d),h)return;if(this._late_sdp=!1,!o.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._createLocalDescription("offer",s._rtcOfferConstraints)}).then(function(T){g.call(s,T)}).catch(function(){o.reply(500)});return}if(r!=="application/sdp"){W.debug("invalid Content-Type"),o.reply(415);return}this._processInDialogSdpOffer(o).then(function(T){s._status!==X.STATUS_TERMINATED&&g.call(s,T)}).catch(function(T){W.warn(T)});function g(T){var E=this,y=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(o,y),this._late_sdp&&(T=this._mangleOffer(T)),o.reply(200,null,y,T,function(){E._status=X.STATUS_WAITING_FOR_ACK,E._setInvite2xxTimer(o,T),E._setACKTimer()}),typeof d.callback=="function"&&d.callback()}}},{key:"_receiveUpdate",value:function(o){var s=this;W.debug("receiveUpdate()");var r=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0,d={request:o,callback:void 0,reject:_.bind(this)},h=!1;function _(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};h=!0;var E=T.status_code||403,y=T.reason_phrase||"",C=Be.cloneArray(T.extraHeaders);if(this._status!==X.STATUS_CONFIRMED)return!1;if(E<300||E>=700)throw new TypeError("Invalid status_code: ".concat(E));o.reply(E,y,C)}if(this.emit("update",d),h)return;if(!o.body){g.call(this,null);return}if(r!=="application/sdp"){W.debug("invalid Content-Type"),o.reply(415);return}this._processInDialogSdpOffer(o).then(function(T){s._status!==X.STATUS_TERMINATED&&g.call(s,T)}).catch(function(T){W.warn(T)});function g(T){var E=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(o,E),o.reply(200,null,E,T),typeof d.callback=="function"&&d.callback()}}},{key:"_processInDialogSdpOffer",value:function(o){var s=this;W.debug("_processInDialogSdpOffer()");var r=o.parseSDP(),d=!1,h=_s(r.media),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;if(Gl.indexOf(g.type)!==-1){var T=g.direction||r.direction||"sendrecv";if(T==="sendonly"||T==="inactive")d=!0;else{d=!1;break}}}}catch(C){h.e(C)}finally{h.f()}var E={originator:"remote",type:"offer",sdp:o.body};W.debug('emit "sdp"'),this.emit("sdp",E);var y=new RTCSessionDescription({type:"offer",sdp:E.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(s._status===X.STATUS_TERMINATED)throw new Error("terminated");return s._connection.setRemoteDescription(y).catch(function(C){throw o.reply(488),W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',C),s.emit("peerconnection:setremotedescriptionfailed",C),C})}).then(function(){if(s._status===X.STATUS_TERMINATED)throw new Error("terminated");s._remoteHold===!0&&d===!1?(s._remoteHold=!1,s._onunhold("remote")):s._remoteHold===!1&&d===!0&&(s._remoteHold=!0,s._onhold("remote"))}).then(function(){if(s._status===X.STATUS_TERMINATED)throw new Error("terminated");return s._createLocalDescription("answer",s._rtcAnswerConstraints).catch(function(C){throw o.reply(500),W.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',C),C})}).catch(function(C){W.warn("_processInDialogSdpOffer() failed [error: %o]",C)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(o){var s=this;if(W.debug("receiveRefer()"),!o.refer_to){W.debug("no Refer-To header field present in REFER"),o.reply(400);return}if(o.refer_to.uri.scheme!==ce.SIP){W.debug("Refer-To header field points to a non-SIP URI scheme"),o.reply(416);return}o.reply(202);var r=new Y_(this,o.cseq);W.debug('emit "refer"'),this.emit("refer",{request:o,accept:function(g,T){d.call(s,g,T)},reject:function(){h.call(s)}});function d(_){var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(_=typeof _=="function"?_:null,this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED)return!1;var T=new n(this._ua);if(T.on("progress",function(y){var C=y.response;r.notify(C.status_code,C.reason_phrase)}),T.on("accepted",function(y){var C=y.response;r.notify(C.status_code,C.reason_phrase)}),T.on("_failed",function(y){var C=y.message,A=y.cause;C?r.notify(C.status_code,C.reason_phrase):r.notify(487,A)}),o.refer_to.uri.hasHeader("replaces")){var E=decodeURIComponent(o.refer_to.uri.getHeader("replaces"));g.extraHeaders=Be.cloneArray(g.extraHeaders),g.extraHeaders.push("Replaces: ".concat(E))}T.connect(o.refer_to.uri.toAor(),g,_)}function h(){r.notify(603)}}},{key:"_receiveNotify",value:function(o){switch(W.debug("receiveNotify()"),o.event||o.reply(400),o.event.event){case"refer":{var s,r;if(o.event.params&&o.event.params.id)s=o.event.params.id,r=this._referSubscribers[s];else if(Object.keys(this._referSubscribers).length===1)r=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{o.reply(400,"Missing event id parameter");return}if(!r){o.reply(481,"Subscription does not exist");return}r.receiveNotify(o),o.reply(200);break}default:o.reply(489)}}},{key:"_receiveReplaces",value:function(o){var s=this;W.debug("receiveReplaces()");function r(h){var _=this;if(this._status!==X.STATUS_WAITING_FOR_ACK&&this._status!==X.STATUS_CONFIRMED)return!1;var g=new n(this._ua);g.on("confirmed",function(){_.terminate()}),g.init_incoming(o,h)}function d(){W.debug("Replaced INVITE rejected by the user"),o.reply(486)}this.emit("replaces",{request:o,accept:function(_){r.call(s,_)},reject:function(){d.call(s)}})}},{key:"_sendInitialRequest",value:function(o,s,r){var d=this,h=new K_(this._ua,this._request,{onRequestTimeout:function(){d.onRequestTimeout()},onTransportError:function(){d.onTransportError()},onAuthenticated:function(g){d._request=g},onReceiveResponse:function(g){d._receiveInviteResponse(g)}});Promise.resolve().then(function(){if(r)return r;if(o.audio||o.video)return d._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(o).catch(function(_){throw d._status===X.STATUS_TERMINATED?new Error("terminated"):(d._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),W.warn('emit "getusermediafailed" [error:%o]',_),d.emit("getusermediafailed",_),_)})}).then(function(_){if(d._status===X.STATUS_TERMINATED)throw new Error("terminated");return d._localMediaStream=_,_&&_.getTracks().forEach(function(g){d._connection.addTrack(g,_)}),d._connecting(d._request),d._createLocalDescription("offer",s).catch(function(g){throw d._failed("local",null,ce.causes.WEBRTC_ERROR),g})}).then(function(_){if(d._is_canceled||d._status===X.STATUS_TERMINATED)throw new Error("terminated");d._request.body=_,d._status=X.STATUS_INVITE_SENT,W.debug('emit "sending" [request:%o]',d._request),d.emit("sending",{request:d._request}),h.send()}).catch(function(_){d._status!==X.STATUS_TERMINATED&&W.warn(_)})}},{key:"_getDTMFRTPSender",value:function(){var o=this._connection.getSenders().find(function(s){return s.track&&s.track.kind==="audio"});if(!(o&&o.dtmf)){W.warn("sendDTMF() | no local audio track to send DTMF with");return}return o.dtmf}},{key:"_receiveInviteResponse",value:function(o){var s=this;if(W.debug("receiveInviteResponse()"),this._dialog&&o.status_code>=200&&o.status_code<=299)if(this._dialog.id.call_id===o.call_id&&this._dialog.id.local_tag===o.from_tag&&this._dialog.id.remote_tag===o.to_tag){this.sendRequest(ce.ACK);return}else{var r=new Bl(this,o,"UAC");if(r.error!==void 0){W.debug(r.error);return}this.sendRequest(ce.ACK),this.sendRequest(ce.BYE);return}if(this._is_canceled){o.status_code>=100&&o.status_code<200?this._request.cancel(this._cancel_reason):o.status_code>=200&&o.status_code<299&&this._acceptAndTerminate(o);return}if(!(this._status!==X.STATUS_INVITE_SENT&&this._status!==X.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(o.status_code):this._status=X.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(o.status_code):{if(!o.to_tag){W.debug("1xx response received without to tag");break}if(o.hasHeader("contact")&&!this._createDialog(o,"UAC",!0))break;if(this._status=X.STATUS_1XX_RECEIVED,!o.body){this._progress("remote",o);break}var d={originator:"remote",type:"answer",sdp:o.body};W.debug('emit "sdp"'),this.emit("sdp",d);var h=new RTCSessionDescription({type:"answer",sdp:d.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._connection.setRemoteDescription(h)}).then(function(){return s._progress("remote",o)}).catch(function(E){W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),s.emit("peerconnection:setremotedescriptionfailed",E)});break}case/^2[0-9]{2}$/.test(o.status_code):{if(this._status=X.STATUS_CONFIRMED,!o.body){this._acceptAndTerminate(o,400,ce.causes.MISSING_SDP),this._failed("remote",o,ce.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(o,"UAC"))break;var _={originator:"remote",type:"answer",sdp:o.body};W.debug('emit "sdp"'),this.emit("sdp",_);var g=new RTCSessionDescription({type:"answer",sdp:_.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(s._connection.signalingState==="stable")return s._connection.createOffer(s._rtcOfferConstraints).then(function(E){return s._connection.setLocalDescription(E)}).catch(function(E){s._acceptAndTerminate(o,500,E.toString()),s._failed("local",o,ce.causes.WEBRTC_ERROR)})}).then(function(){s._connection.setRemoteDescription(g).then(function(){s._handleSessionTimersInIncomingResponse(o),s._accepted("remote",o),s.sendRequest(ce.ACK),s._confirmed("local",null)}).catch(function(E){s._acceptAndTerminate(o,488,"Not Acceptable Here"),s._failed("remote",o,ce.causes.BAD_MEDIA_DESCRIPTION),W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),s.emit("peerconnection:setremotedescriptionfailed",E)})});break}default:{var T=Be.sipErrorCause(o.status_code);this._failed("remote",o,T)}}}},{key:"_sendReinvite",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};W.debug("sendReinvite()");var r=Be.cloneArray(s.extraHeaders),d=Be.cloneObject(s.eventHandlers),h=s.rtcOfferConstraints||this._rtcOfferConstraints||null,_=!1;r.push("Contact: ".concat(this._contact)),r.push("Content-Type: application/sdp"),this._sessionTimers.running&&r.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return o._createLocalDescription("offer",h)}).then(function(E){E=o._mangleOffer(E);var y={originator:"local",type:"offer",sdp:E};W.debug('emit "sdp"'),o.emit("sdp",y),o.sendRequest(ce.INVITE,{extraHeaders:r,body:E,eventHandlers:{onSuccessResponse:function(A){g.call(o,A),_=!0},onErrorResponse:function(A){T.call(o,A)},onTransportError:function(){o.onTransportError()},onRequestTimeout:function(){o.onRequestTimeout()},onDialogError:function(){o.onDialogError()}}})}).catch(function(){T()});function g(E){var y=this;if(this._status!==X.STATUS_TERMINATED&&(this.sendRequest(ce.ACK),!_)){if(this._handleSessionTimersInIncomingResponse(E),E.body){if(!E.hasHeader("Content-Type")||E.getHeader("Content-Type").toLowerCase()!=="application/sdp"){T.call(this);return}}else{T.call(this);return}var C={originator:"remote",type:"answer",sdp:E.body};W.debug('emit "sdp"'),this.emit("sdp",C);var A=new RTCSessionDescription({type:"answer",sdp:C.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return y._connection.setRemoteDescription(A)}).then(function(){d.succeeded&&d.succeeded(E)}).catch(function(I){T.call(y),W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',I),y.emit("peerconnection:setremotedescriptionfailed",I)})}}function T(E){d.failed&&d.failed(E)}}},{key:"_sendUpdate",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};W.debug("sendUpdate()");var r=Be.cloneArray(s.extraHeaders),d=Be.cloneObject(s.eventHandlers),h=s.rtcOfferConstraints||this._rtcOfferConstraints||null,_=s.sdpOffer||!1,g=!1;r.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&r.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),_?(r.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return o._createLocalDescription("offer",h)}).then(function(y){y=o._mangleOffer(y);var C={originator:"local",type:"offer",sdp:y};W.debug('emit "sdp"'),o.emit("sdp",C),o.sendRequest(ce.UPDATE,{extraHeaders:r,body:y,eventHandlers:{onSuccessResponse:function(I){T.call(o,I),g=!0},onErrorResponse:function(I){E.call(o,I)},onTransportError:function(){o.onTransportError()},onRequestTimeout:function(){o.onRequestTimeout()},onDialogError:function(){o.onDialogError()}}})}).catch(function(){E.call(o)})):this.sendRequest(ce.UPDATE,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(C){T.call(o,C)},onErrorResponse:function(C){E.call(o,C)},onTransportError:function(){o.onTransportError()},onRequestTimeout:function(){o.onRequestTimeout()},onDialogError:function(){o.onDialogError()}}});function T(y){var C=this;if(this._status!==X.STATUS_TERMINATED&&!g)if(this._handleSessionTimersInIncomingResponse(y),_){if(y.body){if(!y.hasHeader("Content-Type")||y.getHeader("Content-Type").toLowerCase()!=="application/sdp"){E.call(this);return}}else{E.call(this);return}var A={originator:"remote",type:"answer",sdp:y.body};W.debug('emit "sdp"'),this.emit("sdp",A);var I=new RTCSessionDescription({type:"answer",sdp:A.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return C._connection.setRemoteDescription(I)}).then(function(){d.succeeded&&d.succeeded(y)}).catch(function(H){E.call(C),W.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',H),C.emit("peerconnection:setremotedescriptionfailed",H)})}else d.succeeded&&d.succeeded(y)}function E(y){d.failed&&d.failed(y)}}},{key:"_acceptAndTerminate",value:function(o,s,r){W.debug("acceptAndTerminate()");var d=[];s&&(r=r||ce.REASON_PHRASE[s]||"",d.push("Reason: SIP ;cause=".concat(s,'; text="').concat(r,'"'))),(this._dialog||this._createDialog(o,"UAC"))&&(this.sendRequest(ce.ACK),this.sendRequest(ce.BYE,{extraHeaders:d})),this._status=X.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(o){if(!this._localHold&&!this._remoteHold)return o;if(o=Yc.parse(o),this._localHold&&!this._remoteHold){W.debug("mangleOffer() | me on hold, mangling offer");var s=_s(o.media),r;try{for(s.s();!(r=s.n()).done;){var d=r.value;Gl.indexOf(d.type)!==-1&&(d.direction?d.direction==="sendrecv"?d.direction="sendonly":d.direction==="recvonly"&&(d.direction="inactive"):d.direction="sendonly")}}catch(C){s.e(C)}finally{s.f()}}else if(this._localHold&&this._remoteHold){W.debug("mangleOffer() | both on hold, mangling offer");var h=_s(o.media),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;Gl.indexOf(g.type)!==-1&&(g.direction="inactive")}}catch(C){h.e(C)}finally{h.f()}}else if(this._remoteHold){W.debug("mangleOffer() | remote on hold, mangling offer");var T=_s(o.media),E;try{for(T.s();!(E=T.n()).done;){var y=E.value;Gl.indexOf(y.type)!==-1&&(y.direction?y.direction==="sendrecv"?y.direction="recvonly":y.direction==="recvonly"&&(y.direction="inactive"):y.direction="recvonly")}}catch(C){T.e(C)}finally{T.f()}}return Yc.write(o)}},{key:"_setLocalMediaStatus",value:function(){var o=!0,s=!0;(this._localHold||this._remoteHold)&&(o=!1,s=!1),this._audioMuted&&(o=!1),this._videoMuted&&(s=!1),this._toggleMuteAudio(!o),this._toggleMuteVideo(!s)}},{key:"_handleSessionTimersInIncomingRequest",value:function(o,s){if(this._sessionTimers.enabled){var r;o.session_expires&&o.session_expires>=ce.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=o.session_expires,r=o.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,r="uas"),s.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(r)),this._sessionTimers.refresher=r==="uas",this._runSessionTimer()}}},{key:"_handleSessionTimersInIncomingResponse",value:function(o){if(this._sessionTimers.enabled){var s;o.session_expires&&o.session_expires>=ce.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=o.session_expires,s=o.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,s="uac"),this._sessionTimers.refresher=s==="uac",this._runSessionTimer()}}},{key:"_runSessionTimer",value:function(){var o=this,s=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){o._status!==X.STATUS_TERMINATED&&o._isReadyToReOffer()&&(W.debug("runSessionTimer() | sending session refresh request"),o._sessionTimers.refreshMethod===ce.UPDATE?o._sendUpdate():o._sendReinvite())},s*500):this._sessionTimers.timer=setTimeout(function(){o._status!==X.STATUS_TERMINATED&&(W.warn("runSessionTimer() | timer expired, terminating the session"),o.terminate({cause:ce.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},s*1100)}},{key:"_toggleMuteAudio",value:function(o){var s=this._connection.getSenders().filter(function(_){return _.track&&_.track.kind==="audio"}),r=_s(s),d;try{for(r.s();!(d=r.n()).done;){var h=d.value;h.track.enabled=!o}}catch(_){r.e(_)}finally{r.f()}}},{key:"_toggleMuteVideo",value:function(o){var s=this._connection.getSenders().filter(function(_){return _.track&&_.track.kind==="video"}),r=_s(s),d;try{for(r.s();!(d=r.n()).done;){var h=d.value;h.track.enabled=!o}}catch(_){r.e(_)}finally{r.f()}}},{key:"_newRTCSession",value:function(o,s){W.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:o,session:this,request:s})}},{key:"_connecting",value:function(o){W.debug("session connecting"),W.debug('emit "connecting"'),this.emit("connecting",{request:o})}},{key:"_progress",value:function(o,s){W.debug("session progress"),W.debug('emit "progress"'),this.emit("progress",{originator:o,response:s||null})}},{key:"_accepted",value:function(o,s){W.debug("session accepted"),this._start_time=new Date,W.debug('emit "accepted"'),this.emit("accepted",{originator:o,response:s||null})}},{key:"_confirmed",value:function(o,s){W.debug("session confirmed"),this._is_confirmed=!0,W.debug('emit "confirmed"'),this.emit("confirmed",{originator:o,ack:s||null})}},{key:"_ended",value:function(o,s,r){W.debug("session ended"),this._end_time=new Date,this._close(),W.debug('emit "ended"'),this.emit("ended",{originator:o,message:s||null,cause:r})}},{key:"_failed",value:function(o,s,r){W.debug("session failed"),W.debug('emit "_failed"'),this.emit("_failed",{originator:o,message:s||null,cause:r}),this._close(),W.debug('emit "failed"'),this.emit("failed",{originator:o,message:s||null,cause:r})}},{key:"_onhold",value:function(o){W.debug("session onhold"),this._setLocalMediaStatus(),W.debug('emit "hold"'),this.emit("hold",{originator:o})}},{key:"_onunhold",value:function(o){W.debug("session onunhold"),this._setLocalMediaStatus(),W.debug('emit "unhold"'),this.emit("unhold",{originator:o})}},{key:"_onmute",value:function(o){var s=o.audio,r=o.video;W.debug("session onmute"),this._setLocalMediaStatus(),W.debug('emit "muted"'),this.emit("muted",{audio:s,video:r})}},{key:"_onunmute",value:function(o){var s=o.audio,r=o.video;W.debug("session onunmute"),this._setLocalMediaStatus(),W.debug('emit "unmuted"'),this.emit("unmuted",{audio:s,video:r})}},{key:"C",get:function(){return X}},{key:"causes",get:function(){return ce.causes}},{key:"id",get:function(){return this._id}},{key:"connection",get:function(){return this._connection}},{key:"contact",get:function(){return this._contact}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}},{key:"start_time",get:function(){return this._start_time}},{key:"end_time",get:function(){return this._end_time}},{key:"data",get:function(){return this._data},set:function(o){this._data=o}},{key:"status",get:function(){return this._status}}]),n}(B_);function Wl(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Wl=function(n){return typeof n}:Wl=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Wl(c)}function X_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Qc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Q_(c,t,n){return t&&Qc(c.prototype,t),n&&Qc(c,n),c}function Z_(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&Co(c,t)}function Co(c,t){return Co=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},Co(c,t)}function ep(c){var t=np();return function(){var a=Kl(c),o;if(t){var s=Kl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return tp(this,o)}}function tp(c,t){return t&&(Wl(t)==="object"||typeof t=="function")?t:sp(c)}function sp(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function np(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Kl(c){return Kl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Kl(c)}var rp=ct.EventEmitter,ip=ft,Ao=st,lp=fs,Hr=Rt(),ap=xr,Zc=Is,op=bs(),Yl=new ip("Message"),up=function(c){Z_(n,c);var t=ep(n);function n(a){var o;return X_(this,n),o=t.call(this),o._ua=a,o._request=null,o._closed=!1,o._direction=null,o._local_identity=null,o._remote_identity=null,o._is_replied=!1,o._data={},o}return Q_(n,[{key:"send",value:function(o,s){var r=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},h=o;if(o===void 0||s===void 0)throw new TypeError("Not enough arguments");if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(h));var _=Hr.cloneArray(d.extraHeaders),g=Hr.cloneObject(d.eventHandlers),T=d.contentType||"text/plain",E={};d.fromUserName&&(E.from_uri=new op("sip",d.fromUserName,this._ua.configuration.uri.host),_.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),d.fromDisplayName&&(E.from_display_name=d.fromDisplayName);for(var y in g)Object.prototype.hasOwnProperty.call(g,y)&&this.on(y,g[y]);_.push("Content-Type: ".concat(T)),this._request=new lp.OutgoingRequest(Ao.MESSAGE,o,this._ua,E,_),s&&(this._request.body=s);var C=new ap(this._ua,this._request,{onRequestTimeout:function(){r._onRequestTimeout()},onTransportError:function(){r._onTransportError()},onReceiveResponse:function(I){r._receiveResponse(I)}});this._newMessage("local",this._request),C.send()}},{key:"init_incoming",value:function(o){this._request=o,this._newMessage("remote",o),this._is_replied||(this._is_replied=!0,o.reply(200)),this._close()}},{key:"accept",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=Hr.cloneArray(o.extraHeaders),r=o.body;if(this._direction!=="incoming")throw new Zc.NotSupportedError('"accept" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");this._is_replied=!0,this._request.reply(200,null,s,r)}},{key:"reject",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=o.status_code||480,r=o.reason_phrase,d=Hr.cloneArray(o.extraHeaders),h=o.body;if(this._direction!=="incoming")throw new Zc.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(s<300||s>=700)throw new TypeError("Invalid status_code: ".concat(s));this._is_replied=!0,this._request.reply(s,r,d,h)}},{key:"_receiveResponse",value:function(o){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):this._succeeded("remote",o);break;default:{var s=Hr.sipErrorCause(o.status_code);this._failed("remote",o,s);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,Ao.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,Ao.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newMessage",value:function(o,s){o==="remote"?(this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from):o==="local"&&(this._direction="outgoing",this._local_identity=s.from,this._remote_identity=s.to),this._ua.newMessage(this,{originator:o,message:this,request:s})}},{key:"_failed",value:function(o,s,r){Yl.debug("MESSAGE failed"),this._close(),Yl.debug('emit "failed"'),this.emit("failed",{originator:o,response:s||null,cause:r})}},{key:"_succeeded",value:function(o,s){Yl.debug("MESSAGE succeeded"),this._close(),Yl.debug('emit "succeeded"'),this.emit("succeeded",{originator:o,response:s})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}]),n}(rp);function Jl(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Jl=function(n){return typeof n}:Jl=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Jl(c)}function cp(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function ef(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function fp(c,t,n){return t&&ef(c.prototype,t),n&&ef(c,n),c}function hp(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&Ro(c,t)}function Ro(c,t){return Ro=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},Ro(c,t)}function dp(c){var t=mp();return function(){var a=zl(c),o;if(t){var s=zl(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return _p(this,o)}}function _p(c,t){return t&&(Jl(t)==="object"||typeof t=="function")?t:pp(c)}function pp(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function mp(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function zl(c){return zl=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},zl(c)}var gp=ct.EventEmitter,Tp=ft,Io=st,vp=fs,Fr=Rt(),Ep=xr,tf=Is,Xl=new Tp("Options"),Sp=function(c){hp(n,c);var t=dp(n);function n(a){var o;return cp(this,n),o=t.call(this),o._ua=a,o._request=null,o._closed=!1,o._direction=null,o._local_identity=null,o._remote_identity=null,o._is_replied=!1,o._data={},o}return fp(n,[{key:"send",value:function(o,s){var r=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},h=o;if(o===void 0)throw new TypeError("A target is required for OPTIONS");if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(h));var _=Fr.cloneArray(d.extraHeaders),g=Fr.cloneObject(d.eventHandlers),T=d.contentType||"application/sdp";for(var E in g)Object.prototype.hasOwnProperty.call(g,E)&&this.on(E,g[E]);_.push("Content-Type: ".concat(T)),this._request=new vp.OutgoingRequest(Io.OPTIONS,o,this._ua,null,_),s&&(this._request.body=s);var y=new Ep(this._ua,this._request,{onRequestTimeout:function(){r._onRequestTimeout()},onTransportError:function(){r._onTransportError()},onReceiveResponse:function(A){r._receiveResponse(A)}});this._newOptions("local",this._request),y.send()}},{key:"init_incoming",value:function(o){this._request=o,this._newOptions("remote",o),this._is_replied||(this._is_replied=!0,o.reply(200)),this._close()}},{key:"accept",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=Fr.cloneArray(o.extraHeaders),r=o.body;if(this._direction!=="incoming")throw new tf.NotSupportedError('"accept" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");this._is_replied=!0,this._request.reply(200,null,s,r)}},{key:"reject",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=o.status_code||480,r=o.reason_phrase,d=Fr.cloneArray(o.extraHeaders),h=o.body;if(this._direction!=="incoming")throw new tf.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(s<300||s>=700)throw new TypeError("Invalid status_code: ".concat(s));this._is_replied=!0,this._request.reply(s,r,d,h)}},{key:"_receiveResponse",value:function(o){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):this._succeeded("remote",o);break;default:{var s=Fr.sipErrorCause(o.status_code);this._failed("remote",o,s);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,Io.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,Io.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newOptions",value:function(o,s){o==="remote"?(this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from):o==="local"&&(this._direction="outgoing",this._local_identity=s.from,this._remote_identity=s.to),this._ua.newOptions(this,{originator:o,message:this,request:s})}},{key:"_failed",value:function(o,s,r){Xl.debug("OPTIONS failed"),this._close(),Xl.debug('emit "failed"'),this.emit("failed",{originator:o,response:s||null,cause:r})}},{key:"_succeeded",value:function(o,s){Xl.debug("OPTIONS succeeded"),this._close(),Xl.debug('emit "succeeded"'),this.emit("succeeded",{originator:o,response:s})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}]),n}(gp),bo={},yp=ft,wo=Rt(),Cp=ss(),jr=new yp("Socket");bo.isSocket=function(c){if(Array.isArray(c))return!1;if(typeof c>"u")return jr.warn("undefined JsSIP.Socket instance"),!1;try{if(!wo.isString(c.url))throw jr.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!wo.isString(c.via_transport))throw jr.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(Cp.parse(c.sip_uri,"SIP_URI")===-1)throw jr.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch{return!1}try{["connect","disconnect","send"].forEach(function(t){if(!wo.isFunction(c[t]))throw jr.warn("missing or invalid JsSIP.Socket method: ".concat(t)),new Error("Missing or invalid JsSIP.Socket method: ".concat(t))})}catch{return!1}return!0};function Ap(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function sf(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Rp(c,t,n){return t&&sf(c.prototype,t),n&&sf(c,n),c}var Ip=ft,bp=bo,nf=st,Pt=new Ip("Transport"),Ft={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:nf.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:nf.CONNECTION_RECOVERY_MAX_INTERVAL}},wp=function(){function c(t){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ft.recovery_options;Ap(this,c),Pt.debug("new()"),this.status=Ft.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(a){Pt.warn("cannot use TextDecoder: ".concat(a))}if(typeof t>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(a){if(!bp.isSocket(a.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(a.weight&&!Number(a.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:a.socket,weight:a.weight||0,status:Ft.SOCKET_STATUS_READY})},this),this._getSocket()}return Rp(c,[{key:"connect",value:function(){if(Pt.debug("connect()"),this.isConnected()){Pt.debug("Transport is already connected");return}else if(this.isConnecting()){Pt.debug("Transport is connecting");return}this.close_requested=!1,this.status=Ft.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect())}},{key:"disconnect",value:function(){Pt.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=Ft.STATUS_DISCONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(n){if(Pt.debug("send()"),!this.isConnected())return Pt.warn("unable to send message, transport is not connected"),!1;var a=n.toString();return Pt.debug(`sending message:
|
51
51
|
|
52
52
|
`.concat(a,`
|
53
53
|
`)),this.socket.send(a)}},{key:"isConnected",value:function(){return this.status===Ft.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===Ft.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var n=this;this.recover_attempts+=1;var a=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);a<this.recovery_options.min_interval?a=this.recovery_options.min_interval:a>this.recovery_options.max_interval&&(a=this.recovery_options.max_interval),Pt.debug("reconnection attempt: ".concat(this.recover_attempts,". next connection attempt in ").concat(a," seconds")),this.recovery_timer=setTimeout(function(){!n.close_requested&&!(n.isConnected()||n.isConnecting())&&(n._getSocket(),n.connect())},a*1e3)}},{key:"_getSocket",value:function(){var n=[];if(this.sockets.forEach(function(o){o.status!==Ft.SOCKET_STATUS_ERROR&&(n.length===0?n.push(o):o.weight>n[0].weight?n=[o]:o.weight===n[0].weight&&n.push(o))}),n.length===0){this.sockets.forEach(function(o){o.status=Ft.SOCKET_STATUS_READY}),this._getSocket();return}var a=Math.floor(Math.random()*n.length);this.socket=n[a].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=Ft.STATUS_CONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(n,a,o){this.status=Ft.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:n,code:a,reason:o}),!this.close_requested&&(this.sockets.forEach(function(s){this.socket===s.socket&&(s.status=Ft.SOCKET_STATUS_ERROR)},this),this._reconnect(n))}},{key:"_onData",value:function(n){if(n===`\r
|
@@ -60,7 +60,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
60
60
|
`));this.ondata({transport:this,message:n})}},{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}}]),c}(),rf={};function lf(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=Op(c))||t&&c&&typeof c.length=="number"){n&&(c=n);var a=0,o=function(){};return{s:o,n:function(){return a>=c.length?{done:!0}:{done:!1,value:c[a++]}},e:function(_){throw _},f:o}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
61
61
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function Op(c,t){if(c){if(typeof c=="string")return af(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return af(c,t)}}function af(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}var Dp=ft,Oo=ss(),Do=fs,Ql=new Dp("Parser");rf.parseMessage=function(c,t){var n,a,o=c.indexOf(`\r
|
62
62
|
`);if(o===-1){Ql.warn("parseMessage() | no CRLF found, not a SIP message");return}var s=c.substring(0,o),r=Oo.parse(s,"Request_Response");if(r===-1){Ql.warn('parseMessage() | error parsing first line of SIP message: "'.concat(s,'"'));return}else r.status_code?(n=new Do.IncomingResponse,n.status_code=r.status_code,n.reason_phrase=r.reason_phrase):(n=new Do.IncomingRequest(t),n.method=r.method,n.ruri=r.uri);n.data=c;for(var d=o+2;;){if(o=Np(c,d),o===-2){a=d+2;break}else if(o===-1){Ql.warn("parseMessage() | malformed message");return}if(r=Up(n,c,d,o),r!==!0){Ql.warn("parseMessage() |",r.error);return}d=o+2}if(n.hasHeader("content-length")){var h=n.getHeader("content-length");n.body=c.substr(a,h)}else n.body=c.substring(a);return n};function Np(c,t){var n=t,a=0,o=0;if(c.substring(n,n+2).match(/(^\r\n)/))return-2;for(;a===0;){if(o=c.indexOf(`\r
|
63
|
-
`,n),o===-1)return o;!c.substring(o+2,o+4).match(/(^\r\n)/)&&c.charAt(o+2).match(/(^\s+)/)?n=o+2:a=o}return a}function Up(c,t,n,a){var o,s=t.indexOf(":",n),r=t.substring(n,s).trim(),d=t.substring(s+1,a).trim();switch(r.toLowerCase()){case"via":case"v":c.addHeader("via",d),c.getHeaders("via").length===1?(o=c.parseHeader("Via"),o&&(c.via=o,c.via_branch=o.branch)):o=0;break;case"from":case"f":c.setHeader("from",d),o=c.parseHeader("from"),o&&(c.from=o,c.from_tag=o.getParam("tag"));break;case"to":case"t":c.setHeader("to",d),o=c.parseHeader("to"),o&&(c.to=o,c.to_tag=o.getParam("tag"));break;case"record-route":if(o=Oo.parse(d,"Record_Route"),o===-1)o=void 0;else{var h=lf(o),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;c.addHeader("record-route",d.substring(g.possition,g.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=g.parsed}}catch(
|
63
|
+
`,n),o===-1)return o;!c.substring(o+2,o+4).match(/(^\r\n)/)&&c.charAt(o+2).match(/(^\s+)/)?n=o+2:a=o}return a}function Up(c,t,n,a){var o,s=t.indexOf(":",n),r=t.substring(n,s).trim(),d=t.substring(s+1,a).trim();switch(r.toLowerCase()){case"via":case"v":c.addHeader("via",d),c.getHeaders("via").length===1?(o=c.parseHeader("Via"),o&&(c.via=o,c.via_branch=o.branch)):o=0;break;case"from":case"f":c.setHeader("from",d),o=c.parseHeader("from"),o&&(c.from=o,c.from_tag=o.getParam("tag"));break;case"to":case"t":c.setHeader("to",d),o=c.parseHeader("to"),o&&(c.to=o,c.to_tag=o.getParam("tag"));break;case"record-route":if(o=Oo.parse(d,"Record_Route"),o===-1)o=void 0;else{var h=lf(o),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;c.addHeader("record-route",d.substring(g.possition,g.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=g.parsed}}catch(C){h.e(C)}finally{h.f()}}break;case"call-id":case"i":c.setHeader("call-id",d),o=c.parseHeader("call-id"),o&&(c.call_id=d);break;case"contact":case"m":if(o=Oo.parse(d,"Contact"),o===-1)o=void 0;else{var T=lf(o),E;try{for(T.s();!(E=T.n()).done;){var y=E.value;c.addHeader("contact",d.substring(y.possition,y.offset)),c.headers.Contact[c.getHeaders("contact").length-1].parsed=y.parsed}}catch(C){T.e(C)}finally{T.f()}}break;case"content-length":case"l":c.setHeader("content-length",d),o=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",d),o=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",d),o=c.parseHeader("cseq"),o&&(c.cseq=o.value),c instanceof Do.IncomingResponse&&(c.method=o.method);break;case"max-forwards":c.setHeader("max-forwards",d),o=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",d),o=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",d),o=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",d),o=c.parseHeader("session-expires"),o&&(c.session_expires=o.expires,c.session_expires_refresher=o.refresher);break;case"refer-to":case"r":c.setHeader("refer-to",d),o=c.parseHeader("refer-to"),o&&(c.refer_to=o);break;case"replaces":c.setHeader("replaces",d),o=c.parseHeader("replaces"),o&&(c.replaces=o);break;case"event":case"o":c.setHeader("event",d),o=c.parseHeader("event"),o&&(c.event=o);break;default:c.addHeader(r,d),o=0}return o===void 0?{error:'error parsing header "'.concat(r,'"')}:!0}function Zl(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=Pp(c))||t&&c&&typeof c.length=="number"){n&&(c=n);var a=0,o=function(){};return{s:o,n:function(){return a>=c.length?{done:!0}:{done:!1,value:c[a++]}},e:function(_){throw _},f:o}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
64
64
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function Pp(c,t){if(c){if(typeof c=="string")return of(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return of(c,t)}}function of(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}var xp=ft,uf=st,cf=fs,No=Rt(),Uo=new xp("sanityCheck"),kp=[Gp],Mp=[Hp,Fp,jp,qp],Lp=[Vp,Bp],Fe,rs,ff,$p=function(c,t,n){Fe=c,rs=t,ff=n;var a=Zl(kp),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;if(s()===!1)return!1}}catch(E){a.e(E)}finally{a.f()}if(Fe instanceof cf.IncomingRequest){var r=Zl(Mp),d;try{for(r.s();!(d=r.n()).done;){var h=d.value;if(h()===!1)return!1}}catch(E){r.e(E)}finally{r.f()}}else if(Fe instanceof cf.IncomingResponse){var _=Zl(Lp),g;try{for(_.s();!(g=_.n()).done;){var T=g.value;if(T()===!1)return!1}}catch(E){_.e(E)}finally{_.f()}}return!0};function Hp(){if(Fe.s("to").uri.scheme!=="sip")return qr(416),!1}function Fp(){if(!Fe.to_tag&&Fe.call_id.substr(0,5)===rs.configuration.jssip_id)return qr(482),!1}function jp(){var c=No.str_utf8_length(Fe.body),t=Fe.getHeader("content-length");if(c<t)return qr(400),!1}function qp(){var c=Fe.from_tag,t=Fe.call_id,n=Fe.cseq,a;if(!Fe.to_tag)if(Fe.method===uf.INVITE){if(rs._transactions.ist[Fe.via_branch])return!1;for(var o in rs._transactions.ist)if(Object.prototype.hasOwnProperty.call(rs._transactions.ist,o)&&(a=rs._transactions.ist[o],a.request.from_tag===c&&a.request.call_id===t&&a.request.cseq===n))return qr(482),!1}else{if(rs._transactions.nist[Fe.via_branch])return!1;for(var s in rs._transactions.nist)if(Object.prototype.hasOwnProperty.call(rs._transactions.nist,s)&&(a=rs._transactions.nist[s],a.request.from_tag===c&&a.request.call_id===t&&a.request.cseq===n))return qr(482),!1}}function Vp(){if(Fe.getHeaders("via").length>1)return Uo.debug("more than one Via header field present in the response, dropping the response"),!1}function Bp(){var c=No.str_utf8_length(Fe.body),t=Fe.getHeader("content-length");if(c<t)return Uo.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}function Gp(){for(var c=["from","to","call_id","cseq","via"],t=0,n=c;t<n.length;t++){var a=n[t];if(!Fe.hasHeader(a))return Uo.debug("missing mandatory header field : ".concat(a,", dropping the response")),!1}}function qr(c){var t=Fe.getHeaders("via"),n,a="SIP/2.0 ".concat(c," ").concat(uf.REASON_PHRASE[c],`\r
|
65
65
|
`),o=Zl(t),s;try{for(o.s();!(s=o.n()).done;){var r=s.value;a+="Via: ".concat(r,`\r
|
66
66
|
`)}}catch(d){o.e(d)}finally{o.f()}n=Fe.getHeader("To"),Fe.to_tag||(n+=";tag=".concat(No.newTag())),a+="To: ".concat(n,`\r
|
@@ -69,10 +69,10 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
69
69
|
`),a+="CSeq: ".concat(Fe.cseq," ").concat(Fe.method,`\r
|
70
70
|
`),a+=`\r
|
71
71
|
`,ff.send(a)}var Po={};function hf(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=Wp(c))||t&&c&&typeof c.length=="number"){n&&(c=n);var a=0,o=function(){};return{s:o,n:function(){return a>=c.length?{done:!0}:{done:!1,value:c[a++]}},e:function(_){throw _},f:o}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
72
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function Wp(c,t){if(c){if(typeof c=="string")return df(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return df(c,t)}}function df(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}var kn=Rt(),en=st,xo=ss(),_f=bs(),ko=bo,Mo=Is;Po.settings={authorization_user:null,password:null,realm:null,ha1:null,authorization_jwt:null,display_name:null,uri:null,contact_uri:null,instance_id:null,use_preloaded_route:!1,session_timers:!0,session_timers_refresh_method:en.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:en.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:en.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:"".concat(kn.createRandomToken(12),".invalid")};var ea={mandatory:{sockets:function(t){var n=[];if(ko.isSocket(t))n.push({socket:t});else if(Array.isArray(t)&&t.length){var a=hf(t),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;Object.prototype.hasOwnProperty.call(s,"socket")&&ko.isSocket(s.socket)?n.push(s):ko.isSocket(s)&&n.push({socket:s})}}catch(r){a.e(r)}finally{a.f()}}else return;return n},uri:function(t){/^sip:/i.test(t)||(t="".concat(en.SIP,":").concat(t));var n=_f.parse(t);if(n)return n.user?n:void 0}},optional:{authorization_user:function(t){if(xo.parse('"'.concat(t,'"'),"quoted_string")!==-1)return t},authorization_jwt:function(t){if(typeof t=="string")return t},user_agent:function(t){if(typeof t=="string")return t},connection_recovery_max_interval:function(t){if(kn.isDecimal(t)){var n=Number(t);if(n>0)return n}},connection_recovery_min_interval:function(t){if(kn.isDecimal(t)){var n=Number(t);if(n>0)return n}},contact_uri:function(t){if(typeof t=="string"){var n=xo.parse(t,"SIP_URI");if(n!==-1)return n}},display_name:function(t){return t},instance_id:function(t){if(/^uuid:/i.test(t)&&(t=t.substr(5)),xo.parse(t,"uuid")!==-1)return t},no_answer_timeout:function(t){if(kn.isDecimal(t)){var n=Number(t);if(n>0)return n}},session_timers:function(t){if(typeof t=="boolean")return t},session_timers_refresh_method:function(t){if(typeof t=="string"&&(t=t.toUpperCase(),t===en.INVITE||t===en.UPDATE))return t},session_timers_force_refresher:function(t){if(typeof t=="boolean")return t},password:function(t){return String(t)},realm:function(t){return String(t)},ha1:function(t){return String(t)},register:function(t){if(typeof t=="boolean")return t},register_expires:function(t){if(kn.isDecimal(t)){var n=Number(t);if(n>0)return n}},registrar_server:function(t){/^sip:/i.test(t)||(t="".concat(en.SIP,":").concat(t));var n=_f.parse(t);if(n)return n.user?void 0:n},use_preloaded_route:function(t){if(typeof t=="boolean")return t},extra_headers:function(t){var n=[];if(Array.isArray(t)&&t.length){var a=hf(t),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;typeof s=="string"&&n.push(s)}}catch(r){a.e(r)}finally{a.f()}}else return;return n}}};Po.load=function(c,t){for(var n in ea.mandatory)if(t.hasOwnProperty(n)){var a=t[n],o=ea.mandatory[n](a);if(o!==void 0)c[n]=o;else throw new Mo.ConfigurationError(n,a)}else throw new Mo.ConfigurationError(n);for(var s in ea.optional)if(t.hasOwnProperty(s)){var r=t[s];if(kn.isEmpty(r))continue;var d=ea.optional[s](r);if(d!==void 0)c[s]=d;else throw new Mo.ConfigurationError(s,r)}};function ta(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?ta=function(n){return typeof n}:ta=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},ta(c)}function Kp(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function pf(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function mf(c,t,n){return t&&pf(c.prototype,t),n&&pf(c,n),c}function Yp(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&Lo(c,t)}function Lo(c,t){return Lo=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},Lo(c,t)}function Jp(c){var t=Xp();return function(){var a=sa(c),o;if(t){var s=sa(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return zp(this,o)}}function zp(c,t){return t&&(ta(t)==="object"||typeof t=="function")?t:gf(c)}function gf(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Xp(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function sa(c){return sa=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},sa(c)}var Qp=ct.EventEmitter,Zp=ft,_t=st,em=jd,Tf=z_,vf=up,Ef=Sp,$o=Pr,tm=wp,na=Rt(),sm=Is,nm=bs(),rm=rf,Ho=fs,im=$p,Fo=Po,Ve=new Zp("UA"),pt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},lm=function(c){Yp(n,c);var t=Jp(n);mf(n,null,[{key:"C",get:function(){return pt}}]);function n(a){var o;if(Kp(this,n),console.log("constructor es5"),Ve.debug("new() [configuration:%o]",a),o=t.call(this),o._cache={credentials:{}},o._configuration=Object.assign({},Fo.settings),o._dynConfiguration={},o._dialogs={},o._applicants={},o._sessions={},o._transport=null,o._contact=null,o._status=pt.STATUS_INIT,o._error=null,o._transactions={nist:{},nict:{},ist:{},ict:{}},o._data={},o._closeTimer=null,a===void 0)throw new TypeError("Not enough arguments");try{o._loadConfig(a)}catch(s){throw o._status=pt.STATUS_NOT_READY,o._error=pt.CONFIGURATION_ERROR,s}return o._registrator=new em(gf(o)),o}return mf(n,[{key:"start",value:function(){Ve.debug("start()"),this._status===pt.STATUS_INIT?this._transport.connect():this._status===pt.STATUS_USER_CLOSED?(Ve.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=pt.STATUS_INIT,this._transport.connect()):this._status===pt.STATUS_READY?Ve.debug("UA is in READY status, not restarted"):Ve.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}},{key:"register",value:function(){Ve.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}},{key:"unregister",value:function(o){Ve.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(o)}},{key:"registrator",value:function(){return this._registrator}},{key:"isRegistered",value:function(){return this._registrator.registered}},{key:"isConnected",value:function(){return this._transport.isConnected()}},{key:"call",value:function(o,s){Ve.debug("call()");var r=new Tf(this);return r.connect(o,s),r}},{key:"sendMessage",value:function(o,s,r){Ve.debug("sendMessage()");var d=new vf(this);return d.send(o,s,r),d}},{key:"sendOptions",value:function(o,s,r){Ve.debug("sendOptions()");var d=new Ef(this);return d.send(o,s,r),d}},{key:"terminateSessions",value:function(o){Ve.debug("terminateSessions()");for(var s in this._sessions)this._sessions[s].isEnded()||this._sessions[s].terminate(o)}},{key:"stop",value:function(){var o=this;if(Ve.debug("stop()"),this._dynConfiguration={},this._status===pt.STATUS_USER_CLOSED){Ve.debug("UA already closed");return}this._registrator.close();var s=Object.keys(this._sessions).length;for(var r in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,r)){Ve.debug("closing session ".concat(r));try{this._sessions[r].terminate()}catch{}}for(var d in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,d))try{this._applicants[d].close()}catch{}this._status=pt.STATUS_USER_CLOSED;var h=Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length;h===0&&s===0?this._transport.disconnect():this._closeTimer=setTimeout(function(){o._closeTimer=null,o._transport.disconnect()},2e3)}},{key:"normalizeTarget",value:function(o){return na.normalizeTarget(o,this._configuration.hostport_params)}},{key:"get",value:function(o){switch(o){case"authorization_user":return this._configuration.authorization_user;case"realm":return this._configuration.realm;case"ha1":return this._configuration.ha1;case"authorization_jwt":return this._configuration.authorization_jwt;default:Ve.warn('get() | cannot get "%s" parameter in runtime',o);return}}},{key:"set",value:function(o,s){switch(o){case"authorization_user":{this._configuration.authorization_user=String(s);break}case"password":{this._configuration.password=String(s);break}case"realm":{this._configuration.realm=String(s);break}case"ha1":{this._configuration.ha1=String(s),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(s);break}case"display_name":{this._configuration.display_name=s;break}default:return Ve.warn('set() | cannot set "%s" parameter in runtime',o),!1}return!0}},{key:"newTransaction",value:function(o){this._transactions[o.type][o.id]=o,this.emit("newTransaction",{transaction:o})}},{key:"destroyTransaction",value:function(o){delete this._transactions[o.type][o.id],this.emit("transactionDestroyed",{transaction:o})}},{key:"newDialog",value:function(o){this._dialogs[o.id]=o}},{key:"destroyDialog",value:function(o){delete this._dialogs[o.id]}},{key:"newMessage",value:function(o,s){this._applicants[o]=o,this.emit("newMessage",s)}},{key:"newOptions",value:function(o,s){this._applicants[o]=o,this.emit("newOptions",s)}},{key:"destroyMessage",value:function(o){delete this._applicants[o]}},{key:"newRTCSession",value:function(o,s){this._sessions[o.id]=o,this.emit("newRTCSession",s)}},{key:"destroyRTCSession",value:function(o){delete this._sessions[o.id]}},{key:"registered",value:function(o){this.emit("registered",o)}},{key:"unregistered",value:function(o){this.emit("unregistered",o)}},{key:"registrationFailed",value:function(o){this.emit("registrationFailed",o)}},{key:"receiveRequest",value:function(o){console.log("receiveRequest");var s=o.method;if(o.ruri.user!==this._configuration.uri.user&&o.ruri.user!==this._contact.uri.user){Ve.debug("Request-URI does not point to us"),o.method!==_t.ACK&&o.reply_sl(404);return}if(o.ruri.scheme===_t.SIPS){o.reply_sl(416);return}if(!$o.checkTransaction(this,o)){if(s===_t.INVITE?new $o.InviteServerTransaction(this,this._transport,o):s!==_t.ACK&&s!==_t.CANCEL&&new $o.NonInviteServerTransaction(this,this._transport,o),s===_t.OPTIONS){if(console.log("OPPP in option"),this.listeners("newOptions").length===0){o.reply(200);return}var r=new Ef(this);r.init_incoming(o)}else if(s===_t.MESSAGE){if(this.listeners("newMessage").length===0){o.reply(405);return}var d=new vf(this);d.init_incoming(o)}else if(s===_t.INVITE&&!o.to_tag&&this.listeners("newRTCSession").length===0){o.reply(405);return}var h,_;if(o.to_tag)h=this._findDialog(o.call_id,o.from_tag,o.to_tag),h?h.receiveRequest(o):s===_t.NOTIFY?(_=this._findSession(o),_?_.receiveRequest(o):(Ve.debug("received NOTIFY request for a non existent subscription"),o.reply(481,"Subscription does not exist"))):s!==_t.ACK&&o.reply(481);else switch(s){case _t.INVITE:if(window.RTCPeerConnection)if(o.hasHeader("replaces")){var g=o.replaces;h=this._findDialog(g.call_id,g.from_tag,g.to_tag),h?(_=h.owner,_.isEnded()?o.reply(603):_.receiveRequest(o)):o.reply(481)}else _=new Tf(this),_.init_incoming(o);else Ve.warn("INVITE received but WebRTC is not supported"),o.reply(488);break;case _t.BYE:o.reply(481);break;case _t.CANCEL:_=this._findSession(o),_?_.receiveRequest(o):Ve.debug("received CANCEL request for a non existent session");break;case _t.ACK:break;case _t.NOTIFY:this.emit("sipEvent",{event:o.event,request:o}),o.reply(200);break;default:o.reply(405);break}}}},{key:"_findSession",value:function(o){var s=o.call_id,r=o.from_tag,d=o.to_tag,h=s+r,_=this._sessions[h],g=s+d,T=this._sessions[g];return _||T||null}},{key:"_findDialog",value:function(o,s,r){var d=o+s+r,h=this._dialogs[d];return h||(d=o+r+s,h=this._dialogs[d],h||null)}},{key:"_loadConfig",value:function(o){try{Fo.load(this._configuration,o)}catch(g){throw g}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=na.newUUID()),this._configuration.jssip_id=na.createRandomToken(5);var s=this._configuration.uri.clone();s.user=null,this._configuration.hostport_params=s.toString().replace(/^sip:/i,"");try{this._transport=new tm(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=am.bind(this),this._transport.onconnect=om.bind(this),this._transport.ondisconnect=um.bind(this),this._transport.ondata=cm.bind(this)}catch(g){throw Ve.warn(g),new sm.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){var r=this._configuration.uri.clone();r.user=null,r.clearParams(),r.clearHeaders(),this._configuration.registrar_server=r}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new nm("sip",na.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString:function(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},E=T.anonymous||null,y=T.outbound||null,A="<";return E?A+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":A+=this.pub_gruu||this.uri.toString(),y&&(E?!this.temp_gruu:!this.pub_gruu)&&(A+=";ob"),A+=">",A}};var d=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(var h in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,h)&&(d.indexOf(h)!==-1?Object.defineProperty(this._configuration,h,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,h,{writable:!1,configurable:!1}));Ve.debug("configuration parameters after validation:");for(var _ in this._configuration)if(Object.prototype.hasOwnProperty.call(Fo.settings,_))switch(_){case"uri":case"registrar_server":Ve.debug("- ".concat(_,": ").concat(this._configuration[_]));break;case"password":case"ha1":case"authorization_jwt":Ve.debug("- ".concat(_,": NOT SHOWN"));break;default:Ve.debug("- ".concat(_,": ").concat(JSON.stringify(this._configuration[_])))}}},{key:"C",get:function(){return pt}},{key:"status",get:function(){return this._status}},{key:"contact",get:function(){return this._contact}},{key:"configuration",get:function(){return this._configuration}},{key:"transport",get:function(){return this._transport}}]),n}(Qp);function am(c){this.emit("connecting",c)}function om(c){this._status!==pt.STATUS_USER_CLOSED&&(this._status=pt.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function um(c){for(var t=["nict","ict","nist","ist"],n=0,a=t;n<a.length;n++){var o=a[n];for(var s in this._transactions[o])Object.prototype.hasOwnProperty.call(this._transactions[o],s)&&this._transactions[o][s].onTransportError()}this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==pt.STATUS_USER_CLOSED&&(this._status=pt.STATUS_NOT_READY,this._error=pt.NETWORK_ERROR)}function cm(c){console.log("onTransportData");var t=c.transport,n=c.message;if(n=rm.parseMessage(n,this),!!n&&!(this._status===pt.STATUS_USER_CLOSED&&n instanceof Ho.IncomingRequest)&&im(n,this,t)){if(n instanceof Ho.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof Ho.IncomingResponse){var a;switch(n.method){case _t.INVITE:a=this._transactions.ict[n.via_branch],a&&a.receiveResponse(n);break;case _t.ACK:break;default:a=this._transactions.nict[n.via_branch],a&&a.receiveResponse(n);break}}}}function fm(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Sf(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function hm(c,t,n){return t&&Sf(c.prototype,t),n&&Sf(c,n),c}var dm=ft,_m=ss(),wt=new dm("WebSocketInterface"),pm=function(){function c(t){fm(this,c),wt.debug('new() [url:"%s"]',t),this._url=t,this._sip_uri=null,this._via_transport=null,this._ws=null;var n=_m.parse(t,"absoluteURI");if(n===-1)throw wt.warn("invalid WebSocket URI: ".concat(t)),new TypeError("Invalid argument: ".concat(t));if(n.scheme!=="wss"&&n.scheme!=="ws")throw wt.warn("invalid WebSocket URI scheme: ".concat(n.scheme)),new TypeError("Invalid argument: ".concat(t));this._sip_uri="sip:".concat(n.host).concat(n.port?":".concat(n.port):"",";transport=ws"),this._via_transport=n.scheme.toUpperCase()}return hm(c,[{key:"connect",value:function(){if(wt.debug("connect()"),this.isConnected()){wt.debug("WebSocket ".concat(this._url," is already connected"));return}else if(this.isConnecting()){wt.debug("WebSocket ".concat(this._url," is connecting"));return}this._ws&&this.disconnect(),wt.debug("connecting to WebSocket ".concat(this._url));try{this._ws=new WebSocket(this._url,"sip"),this._ws.binaryType="arraybuffer",this._ws.onopen=this._onOpen.bind(this),this._ws.onclose=this._onClose.bind(this),this._ws.onmessage=this._onMessage.bind(this),this._ws.onerror=this._onError.bind(this)}catch(n){this._onError(n)}}},{key:"disconnect",value:function(){wt.debug("disconnect()"),this._ws&&(this._ws.onopen=function(){},this._ws.onclose=function(){},this._ws.onmessage=function(){},this._ws.onerror=function(){},this._ws.close(),this._ws=null)}},{key:"send",value:function(n){return wt.debug("send()"),this.isConnected()?(this._ws.send(n),!0):(wt.warn("unable to send message, WebSocket is not open"),!1)}},{key:"isConnected",value:function(){return this._ws&&this._ws.readyState===this._ws.OPEN}},{key:"isConnecting",value:function(){return this._ws&&this._ws.readyState===this._ws.CONNECTING}},{key:"_onOpen",value:function(){wt.debug("WebSocket ".concat(this._url," connected")),this.onconnect()}},{key:"_onClose",value:function(n){var a=n.wasClean,o=n.code,s=n.reason;wt.debug("WebSocket ".concat(this._url," closed")),a===!1&&wt.debug("WebSocket abrupt disconnection"),this.ondisconnect(!a,o,s)}},{key:"_onMessage",value:function(n){var a=n.data;wt.debug("received WebSocket message"),this.ondata(a)}},{key:"_onError",value:function(n){wt.warn("WebSocket ".concat(this._url," error: "),n)}},{key:"via_transport",get:function(){return this._via_transport},set:function(n){this._via_transport=n.toUpperCase()}},{key:"sip_uri",get:function(){return this._sip_uri}},{key:"url",get:function(){return this._url}}]),c}(),jo=vl,mm=st,gm=Is,Tm=Rt(),vm=lm,Em=bs(),Sm=Xa(),ym=ss(),Am=pm,Cm=Un("JsSIP");Cm("version %s",jo.version);var yf={C:mm,Exceptions:gm,Utils:Tm,UA:vm,URI:Em,NameAddrHeader:Sm,WebSocketInterface:Am,Grammar:ym,debug:Un,get name(){return jo.title},get version(){return jo.version}};const Mn=Un,Ln="JsSIP";var at=class{constructor(t){t?(this._debug=Mn.default(`${Ln}:${t}`),this._warn=Mn.default(`${Ln}:WARN:${t}`),this._error=Mn.default(`${Ln}:ERROR:${t}`)):(this._debug=Mn.default(Ln),this._warn=Mn.default(`${Ln}:WARN`),this._error=Mn.default(`${Ln}:ERROR`)),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}get debug(){return this._debug}get warn(){return this._warn}get error(){return this._error}};const ra=Me(at),Af=vl;var De={USER_AGENT:`${Af.title} ${Af.version}`,SIP:"sip",SIPS:"sips",causes:{CONNECTION_ERROR:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{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",424:"Bad Location Information",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:"JsSIP Internal 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"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2};const L=Me(De);var Ze={},qo,Cf;function Vo(){if(Cf)return qo;Cf=1;const c=ps(),t=Jt();return qo=class $h{static parse(a){if(a=t.parse(a,"Name_Addr_Header"),a!==-1)return a}constructor(a,o,s){if(!a||!(a instanceof c))throw new TypeError('missing or invalid "uri" parameter');this._uri=a,this._parameters={},this.display_name=o;for(const r in s)Object.prototype.hasOwnProperty.call(s,r)&&this.setParam(r,s[r])}get uri(){return this._uri}get display_name(){return this._display_name}set display_name(a){this._display_name=a===0?"0":a}setParam(a,o){a&&(this._parameters[a.toLowerCase()]=typeof o>"u"||o===null?null:o.toString())}getParam(a){if(a)return this._parameters[a.toLowerCase()]}hasParam(a){if(a)return this._parameters.hasOwnProperty(a.toLowerCase())&&!0||!1}deleteParam(a){if(a=a.toLowerCase(),this._parameters.hasOwnProperty(a)){const o=this._parameters[a];return delete this._parameters[a],o}}clearParams(){this._parameters={}}clone(){return new $h(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}_quote(a){return a.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}toString(){let a=this._display_name?`"${this._quote(this._display_name)}" `:"";a+=`<${this._uri.toString()}>`;for(const o in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,o)&&(a+=`;${o}`,this._parameters[o]!==null&&(a+=`=${this._parameters[o]}`));return a}},qo}var Bo,Rf;function Jt(){return Rf||(Rf=1,Bo=function(){function c(n){return'"'+n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var t={parse:function(n,a){var o={CRLF:_,DIGIT:g,ALPHA:T,HEXDIG:E,WSP:y,OCTET:A,DQUOTE:C,SP:I,HTAB:H,alphanum:$,reserved:oe,unreserved:N,mark:j,escaped:Se,LWS:ve,SWS:k,HCOLON:D,TEXT_UTF8_TRIM:B,TEXT_UTF8char:V,UTF8_NONASCII:J,UTF8_CONT:F,LHEX:Z,token:U,token_nodot:P,separators:se,word:it,STAR:ee,SLASH:Y,EQUAL:G,LPAREN:re,RPAREN:ge,RAQUOT:be,LAQUOT:ke,COMMA:Re,SEMI:le,COLON:ye,LDQUOT:lt,RDQUOT:ot,comment:Ee,ctext:Ae,quoted_string:Ie,quoted_string_clean:Oe,qdtext:pe,quoted_pair:de,SIP_URI_noparams:_e,SIP_URI:we,uri_scheme:Ne,uri_scheme_sips:tt,uri_scheme_sip:He,userinfo:Vt,user:Ct,user_unreserved:Bn,password:Gn,hostport:cn,host:as,hostname:As,domainlabel:fn,toplabel:Wn,IPv6reference:Kn,IPv6address:hn,h16:me,ls32:ae,IPv4address:ut,dec_octet:es,port:$s,uri_parameters:ui,uri_parameter:Yn,transport_param:Jn,user_param:ci,method_param:fi,ttl_param:hi,maddr_param:di,lr_param:_i,other_param:pi,pname:mi,pvalue:gi,paramchar:Hs,param_unreserved:Fs,headers:Ti,header:dn,hname:_n,hvalue:vi,hnv_unreserved:js,Request_Response:pn,Request_Line:wa,Request_URI:Ei,absoluteURI:zn,hier_part:Xn,net_path:Si,abs_path:mn,opaque_part:gn,uric:qs,uric_no_slash:Vs,path_segments:yi,segment:Tn,param:Bs,pchar:Cs,scheme:Gs,authority:Ai,srvr:Ci,reg_name:Ri,query:Ii,SIP_Version:Qn,INVITEm:Zn,ACKm:bi,OPTIONSm:wi,BYEm:Oi,CANCELm:Di,REGISTERm:Ni,SUBSCRIBEm:Ui,NOTIFYm:Pi,REFERm:xi,Method:vn,Status_Line:En,Status_Code:ki,extension_code:Mi,Reason_Phrase:Li,Allow_Events:Oa,Call_ID:Du,Contact:Nu,contact_param:er,name_addr:Bt,display_name:Gt,contact_params:Ws,c_p_q:tr,c_p_expires:$i,delta_seconds:os,qvalue:us,generic_param:Je,gen_value:ze,Content_Disposition:Da,disp_type:Na,disp_param:sr,handling_param:nr,Content_Encoding:Ua,Content_Length:Uu,Content_Type:Pu,media_type:Pa,m_type:Hi,discrete_type:Fi,composite_type:ji,extension_token:Sn,x_token:yn,m_subtype:qi,m_parameter:rr,m_value:ir,CSeq:xa,CSeq_value:ka,Expires:Ma,Event:xu,event_type:An,From:Cn,from_param:Vi,tag_param:Rn,Max_Forwards:Bi,Min_Expires:ku,Name_Addr_Header:Mu,Proxy_Authenticate:Lu,challenge:Gi,other_challenge:lr,auth_param:Ks,digest_cln:cs,realm:In,realm_value:Wi,domain:Ki,URI:bn,nonce:wn,nonce_value:Yi,opaque:Ji,stale:zi,algorithm:Xi,qop_options:Qi,qop_value:On,Proxy_Require:ar,Record_Route:$u,rec_route:or,Reason:ur,reason_param:Zi,reason_cause:cr,Require:La,Route:Hu,route_param:fr,Subscription_State:hr,substate_value:$a,subexp_params:dr,event_reason_value:_r,Subject:Ha,Supported:Fu,To:ju,to_param:el,Via:tl,via_param:pr,via_params:Ys,via_ttl:mr,via_maddr:sl,via_received:nl,via_branch:rl,response_port:il,rport:ll,sent_protocol:al,protocol_name:ol,transport:ul,sent_by:cl,via_host:fl,via_port:hl,ttl:gr,WWW_Authenticate:dl,Session_Expires:qu,s_e_expires:Fa,s_e_params:Tr,s_e_refresher:vr,extension_header:ja,header_value:qa,message_body:Va,uuid_URI:Vu,uuid:Ba,hex4:Wt,hex8:Kt,hex12:_l,Refer_To:Ga,Replaces:Bu,call_id:Wa,replaces_param:Er,to_tag:Sr,from_tag:pl,early_flag:ml};if(a!==void 0){if(o[a]===void 0)throw new Error("Invalid rule name: "+c(a)+".")}else a="CRLF";var s=0,r=0,d=[];function h(i){s<r||(s>r&&(r=s,d=[]),d.push(i))}function _(){var i;return n.substr(s,2)===`\r
|
72
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function Wp(c,t){if(c){if(typeof c=="string")return df(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return df(c,t)}}function df(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}var kn=Rt(),en=st,xo=ss(),_f=bs(),ko=bo,Mo=Is;Po.settings={authorization_user:null,password:null,realm:null,ha1:null,authorization_jwt:null,display_name:null,uri:null,contact_uri:null,instance_id:null,use_preloaded_route:!1,session_timers:!0,session_timers_refresh_method:en.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:en.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:en.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:"".concat(kn.createRandomToken(12),".invalid")};var ea={mandatory:{sockets:function(t){var n=[];if(ko.isSocket(t))n.push({socket:t});else if(Array.isArray(t)&&t.length){var a=hf(t),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;Object.prototype.hasOwnProperty.call(s,"socket")&&ko.isSocket(s.socket)?n.push(s):ko.isSocket(s)&&n.push({socket:s})}}catch(r){a.e(r)}finally{a.f()}}else return;return n},uri:function(t){/^sip:/i.test(t)||(t="".concat(en.SIP,":").concat(t));var n=_f.parse(t);if(n)return n.user?n:void 0}},optional:{authorization_user:function(t){if(xo.parse('"'.concat(t,'"'),"quoted_string")!==-1)return t},authorization_jwt:function(t){if(typeof t=="string")return t},user_agent:function(t){if(typeof t=="string")return t},connection_recovery_max_interval:function(t){if(kn.isDecimal(t)){var n=Number(t);if(n>0)return n}},connection_recovery_min_interval:function(t){if(kn.isDecimal(t)){var n=Number(t);if(n>0)return n}},contact_uri:function(t){if(typeof t=="string"){var n=xo.parse(t,"SIP_URI");if(n!==-1)return n}},display_name:function(t){return t},instance_id:function(t){if(/^uuid:/i.test(t)&&(t=t.substr(5)),xo.parse(t,"uuid")!==-1)return t},no_answer_timeout:function(t){if(kn.isDecimal(t)){var n=Number(t);if(n>0)return n}},session_timers:function(t){if(typeof t=="boolean")return t},session_timers_refresh_method:function(t){if(typeof t=="string"&&(t=t.toUpperCase(),t===en.INVITE||t===en.UPDATE))return t},session_timers_force_refresher:function(t){if(typeof t=="boolean")return t},password:function(t){return String(t)},realm:function(t){return String(t)},ha1:function(t){return String(t)},register:function(t){if(typeof t=="boolean")return t},register_expires:function(t){if(kn.isDecimal(t)){var n=Number(t);if(n>0)return n}},registrar_server:function(t){/^sip:/i.test(t)||(t="".concat(en.SIP,":").concat(t));var n=_f.parse(t);if(n)return n.user?void 0:n},use_preloaded_route:function(t){if(typeof t=="boolean")return t},extra_headers:function(t){var n=[];if(Array.isArray(t)&&t.length){var a=hf(t),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;typeof s=="string"&&n.push(s)}}catch(r){a.e(r)}finally{a.f()}}else return;return n}}};Po.load=function(c,t){for(var n in ea.mandatory)if(t.hasOwnProperty(n)){var a=t[n],o=ea.mandatory[n](a);if(o!==void 0)c[n]=o;else throw new Mo.ConfigurationError(n,a)}else throw new Mo.ConfigurationError(n);for(var s in ea.optional)if(t.hasOwnProperty(s)){var r=t[s];if(kn.isEmpty(r))continue;var d=ea.optional[s](r);if(d!==void 0)c[s]=d;else throw new Mo.ConfigurationError(s,r)}};function ta(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?ta=function(n){return typeof n}:ta=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},ta(c)}function Kp(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function pf(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function mf(c,t,n){return t&&pf(c.prototype,t),n&&pf(c,n),c}function Yp(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&Lo(c,t)}function Lo(c,t){return Lo=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},Lo(c,t)}function Jp(c){var t=Xp();return function(){var a=sa(c),o;if(t){var s=sa(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return zp(this,o)}}function zp(c,t){return t&&(ta(t)==="object"||typeof t=="function")?t:gf(c)}function gf(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Xp(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function sa(c){return sa=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},sa(c)}var Qp=ct.EventEmitter,Zp=ft,_t=st,em=jd,Tf=z_,vf=up,Ef=Sp,$o=Pr,tm=wp,na=Rt(),sm=Is,nm=bs(),rm=rf,Ho=fs,im=$p,Fo=Po,Ve=new Zp("UA"),pt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},lm=function(c){Yp(n,c);var t=Jp(n);mf(n,null,[{key:"C",get:function(){return pt}}]);function n(a){var o;if(Kp(this,n),console.log("constructor es5"),Ve.debug("new() [configuration:%o]",a),o=t.call(this),o._cache={credentials:{}},o._configuration=Object.assign({},Fo.settings),o._dynConfiguration={},o._dialogs={},o._applicants={},o._sessions={},o._transport=null,o._contact=null,o._status=pt.STATUS_INIT,o._error=null,o._transactions={nist:{},nict:{},ist:{},ict:{}},o._data={},o._closeTimer=null,a===void 0)throw new TypeError("Not enough arguments");try{o._loadConfig(a)}catch(s){throw o._status=pt.STATUS_NOT_READY,o._error=pt.CONFIGURATION_ERROR,s}return o._registrator=new em(gf(o)),o}return mf(n,[{key:"start",value:function(){Ve.debug("start()"),this._status===pt.STATUS_INIT?this._transport.connect():this._status===pt.STATUS_USER_CLOSED?(Ve.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=pt.STATUS_INIT,this._transport.connect()):this._status===pt.STATUS_READY?Ve.debug("UA is in READY status, not restarted"):Ve.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}},{key:"register",value:function(){Ve.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}},{key:"unregister",value:function(o){Ve.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(o)}},{key:"registrator",value:function(){return this._registrator}},{key:"isRegistered",value:function(){return this._registrator.registered}},{key:"isConnected",value:function(){return this._transport.isConnected()}},{key:"call",value:function(o,s){Ve.debug("call()");var r=new Tf(this);return r.connect(o,s),r}},{key:"sendMessage",value:function(o,s,r){Ve.debug("sendMessage()");var d=new vf(this);return d.send(o,s,r),d}},{key:"sendOptions",value:function(o,s,r){Ve.debug("sendOptions()");var d=new Ef(this);return d.send(o,s,r),d}},{key:"terminateSessions",value:function(o){Ve.debug("terminateSessions()");for(var s in this._sessions)this._sessions[s].isEnded()||this._sessions[s].terminate(o)}},{key:"stop",value:function(){var o=this;if(Ve.debug("stop()"),this._dynConfiguration={},this._status===pt.STATUS_USER_CLOSED){Ve.debug("UA already closed");return}this._registrator.close();var s=Object.keys(this._sessions).length;for(var r in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,r)){Ve.debug("closing session ".concat(r));try{this._sessions[r].terminate()}catch{}}for(var d in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,d))try{this._applicants[d].close()}catch{}this._status=pt.STATUS_USER_CLOSED;var h=Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length;h===0&&s===0?this._transport.disconnect():this._closeTimer=setTimeout(function(){o._closeTimer=null,o._transport.disconnect()},2e3)}},{key:"normalizeTarget",value:function(o){return na.normalizeTarget(o,this._configuration.hostport_params)}},{key:"get",value:function(o){switch(o){case"authorization_user":return this._configuration.authorization_user;case"realm":return this._configuration.realm;case"ha1":return this._configuration.ha1;case"authorization_jwt":return this._configuration.authorization_jwt;default:Ve.warn('get() | cannot get "%s" parameter in runtime',o);return}}},{key:"set",value:function(o,s){switch(o){case"authorization_user":{this._configuration.authorization_user=String(s);break}case"password":{this._configuration.password=String(s);break}case"realm":{this._configuration.realm=String(s);break}case"ha1":{this._configuration.ha1=String(s),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(s);break}case"display_name":{this._configuration.display_name=s;break}default:return Ve.warn('set() | cannot set "%s" parameter in runtime',o),!1}return!0}},{key:"newTransaction",value:function(o){this._transactions[o.type][o.id]=o,this.emit("newTransaction",{transaction:o})}},{key:"destroyTransaction",value:function(o){delete this._transactions[o.type][o.id],this.emit("transactionDestroyed",{transaction:o})}},{key:"newDialog",value:function(o){this._dialogs[o.id]=o}},{key:"destroyDialog",value:function(o){delete this._dialogs[o.id]}},{key:"newMessage",value:function(o,s){this._applicants[o]=o,this.emit("newMessage",s)}},{key:"newOptions",value:function(o,s){this._applicants[o]=o,this.emit("newOptions",s)}},{key:"destroyMessage",value:function(o){delete this._applicants[o]}},{key:"newRTCSession",value:function(o,s){this._sessions[o.id]=o,this.emit("newRTCSession",s)}},{key:"destroyRTCSession",value:function(o){delete this._sessions[o.id]}},{key:"registered",value:function(o){this.emit("registered",o)}},{key:"unregistered",value:function(o){this.emit("unregistered",o)}},{key:"registrationFailed",value:function(o){this.emit("registrationFailed",o)}},{key:"receiveRequest",value:function(o){console.log("receiveRequest");var s=o.method;if(o.ruri.user!==this._configuration.uri.user&&o.ruri.user!==this._contact.uri.user){Ve.debug("Request-URI does not point to us"),o.method!==_t.ACK&&o.reply_sl(404);return}if(o.ruri.scheme===_t.SIPS){o.reply_sl(416);return}if(!$o.checkTransaction(this,o)){if(s===_t.INVITE?new $o.InviteServerTransaction(this,this._transport,o):s!==_t.ACK&&s!==_t.CANCEL&&new $o.NonInviteServerTransaction(this,this._transport,o),s===_t.OPTIONS){if(console.log("OPPP in option"),this.listeners("newOptions").length===0){o.reply(200);return}var r=new Ef(this);r.init_incoming(o)}else if(s===_t.MESSAGE){if(this.listeners("newMessage").length===0){o.reply(405);return}var d=new vf(this);d.init_incoming(o)}else if(s===_t.INVITE&&!o.to_tag&&this.listeners("newRTCSession").length===0){o.reply(405);return}var h,_;if(o.to_tag)h=this._findDialog(o.call_id,o.from_tag,o.to_tag),h?h.receiveRequest(o):s===_t.NOTIFY?(_=this._findSession(o),_?_.receiveRequest(o):(Ve.debug("received NOTIFY request for a non existent subscription"),o.reply(481,"Subscription does not exist"))):s!==_t.ACK&&o.reply(481);else switch(s){case _t.INVITE:if(window.RTCPeerConnection)if(o.hasHeader("replaces")){var g=o.replaces;h=this._findDialog(g.call_id,g.from_tag,g.to_tag),h?(_=h.owner,_.isEnded()?o.reply(603):_.receiveRequest(o)):o.reply(481)}else _=new Tf(this),_.init_incoming(o);else Ve.warn("INVITE received but WebRTC is not supported"),o.reply(488);break;case _t.BYE:o.reply(481);break;case _t.CANCEL:_=this._findSession(o),_?_.receiveRequest(o):Ve.debug("received CANCEL request for a non existent session");break;case _t.ACK:break;case _t.NOTIFY:this.emit("sipEvent",{event:o.event,request:o}),o.reply(200);break;default:o.reply(405);break}}}},{key:"_findSession",value:function(o){var s=o.call_id,r=o.from_tag,d=o.to_tag,h=s+r,_=this._sessions[h],g=s+d,T=this._sessions[g];return _||T||null}},{key:"_findDialog",value:function(o,s,r){var d=o+s+r,h=this._dialogs[d];return h||(d=o+r+s,h=this._dialogs[d],h||null)}},{key:"_loadConfig",value:function(o){try{Fo.load(this._configuration,o)}catch(g){throw g}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=na.newUUID()),this._configuration.jssip_id=na.createRandomToken(5);var s=this._configuration.uri.clone();s.user=null,this._configuration.hostport_params=s.toString().replace(/^sip:/i,"");try{this._transport=new tm(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=am.bind(this),this._transport.onconnect=om.bind(this),this._transport.ondisconnect=um.bind(this),this._transport.ondata=cm.bind(this)}catch(g){throw Ve.warn(g),new sm.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){var r=this._configuration.uri.clone();r.user=null,r.clearParams(),r.clearHeaders(),this._configuration.registrar_server=r}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new nm("sip",na.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString:function(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},E=T.anonymous||null,y=T.outbound||null,C="<";return E?C+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":C+=this.pub_gruu||this.uri.toString(),y&&(E?!this.temp_gruu:!this.pub_gruu)&&(C+=";ob"),C+=">",C}};var d=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(var h in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,h)&&(d.indexOf(h)!==-1?Object.defineProperty(this._configuration,h,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,h,{writable:!1,configurable:!1}));Ve.debug("configuration parameters after validation:");for(var _ in this._configuration)if(Object.prototype.hasOwnProperty.call(Fo.settings,_))switch(_){case"uri":case"registrar_server":Ve.debug("- ".concat(_,": ").concat(this._configuration[_]));break;case"password":case"ha1":case"authorization_jwt":Ve.debug("- ".concat(_,": NOT SHOWN"));break;default:Ve.debug("- ".concat(_,": ").concat(JSON.stringify(this._configuration[_])))}}},{key:"C",get:function(){return pt}},{key:"status",get:function(){return this._status}},{key:"contact",get:function(){return this._contact}},{key:"configuration",get:function(){return this._configuration}},{key:"transport",get:function(){return this._transport}}]),n}(Qp);function am(c){this.emit("connecting",c)}function om(c){this._status!==pt.STATUS_USER_CLOSED&&(this._status=pt.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function um(c){for(var t=["nict","ict","nist","ist"],n=0,a=t;n<a.length;n++){var o=a[n];for(var s in this._transactions[o])Object.prototype.hasOwnProperty.call(this._transactions[o],s)&&this._transactions[o][s].onTransportError()}this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==pt.STATUS_USER_CLOSED&&(this._status=pt.STATUS_NOT_READY,this._error=pt.NETWORK_ERROR)}function cm(c){console.log("onTransportData");var t=c.transport,n=c.message;if(n=rm.parseMessage(n,this),!!n&&!(this._status===pt.STATUS_USER_CLOSED&&n instanceof Ho.IncomingRequest)&&im(n,this,t)){if(n instanceof Ho.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof Ho.IncomingResponse){var a;switch(n.method){case _t.INVITE:a=this._transactions.ict[n.via_branch],a&&a.receiveResponse(n);break;case _t.ACK:break;default:a=this._transactions.nict[n.via_branch],a&&a.receiveResponse(n);break}}}}function fm(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Sf(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function hm(c,t,n){return t&&Sf(c.prototype,t),n&&Sf(c,n),c}var dm=ft,_m=ss(),wt=new dm("WebSocketInterface"),pm=function(){function c(t){fm(this,c),wt.debug('new() [url:"%s"]',t),this._url=t,this._sip_uri=null,this._via_transport=null,this._ws=null;var n=_m.parse(t,"absoluteURI");if(n===-1)throw wt.warn("invalid WebSocket URI: ".concat(t)),new TypeError("Invalid argument: ".concat(t));if(n.scheme!=="wss"&&n.scheme!=="ws")throw wt.warn("invalid WebSocket URI scheme: ".concat(n.scheme)),new TypeError("Invalid argument: ".concat(t));this._sip_uri="sip:".concat(n.host).concat(n.port?":".concat(n.port):"",";transport=ws"),this._via_transport=n.scheme.toUpperCase()}return hm(c,[{key:"connect",value:function(){if(wt.debug("connect()"),this.isConnected()){wt.debug("WebSocket ".concat(this._url," is already connected"));return}else if(this.isConnecting()){wt.debug("WebSocket ".concat(this._url," is connecting"));return}this._ws&&this.disconnect(),wt.debug("connecting to WebSocket ".concat(this._url));try{this._ws=new WebSocket(this._url,"sip"),this._ws.binaryType="arraybuffer",this._ws.onopen=this._onOpen.bind(this),this._ws.onclose=this._onClose.bind(this),this._ws.onmessage=this._onMessage.bind(this),this._ws.onerror=this._onError.bind(this)}catch(n){this._onError(n)}}},{key:"disconnect",value:function(){wt.debug("disconnect()"),this._ws&&(this._ws.onopen=function(){},this._ws.onclose=function(){},this._ws.onmessage=function(){},this._ws.onerror=function(){},this._ws.close(),this._ws=null)}},{key:"send",value:function(n){return wt.debug("send()"),this.isConnected()?(this._ws.send(n),!0):(wt.warn("unable to send message, WebSocket is not open"),!1)}},{key:"isConnected",value:function(){return this._ws&&this._ws.readyState===this._ws.OPEN}},{key:"isConnecting",value:function(){return this._ws&&this._ws.readyState===this._ws.CONNECTING}},{key:"_onOpen",value:function(){wt.debug("WebSocket ".concat(this._url," connected")),this.onconnect()}},{key:"_onClose",value:function(n){var a=n.wasClean,o=n.code,s=n.reason;wt.debug("WebSocket ".concat(this._url," closed")),a===!1&&wt.debug("WebSocket abrupt disconnection"),this.ondisconnect(!a,o,s)}},{key:"_onMessage",value:function(n){var a=n.data;wt.debug("received WebSocket message"),this.ondata(a)}},{key:"_onError",value:function(n){wt.warn("WebSocket ".concat(this._url," error: "),n)}},{key:"via_transport",get:function(){return this._via_transport},set:function(n){this._via_transport=n.toUpperCase()}},{key:"sip_uri",get:function(){return this._sip_uri}},{key:"url",get:function(){return this._url}}]),c}(),jo=vl,mm=st,gm=Is,Tm=Rt(),vm=lm,Em=bs(),Sm=Xa(),ym=ss(),Cm=pm,Am=Un("JsSIP");Am("version %s",jo.version);var yf={C:mm,Exceptions:gm,Utils:Tm,UA:vm,URI:Em,NameAddrHeader:Sm,WebSocketInterface:Cm,Grammar:ym,debug:Un,get name(){return jo.title},get version(){return jo.version}};const Mn=Un,Ln="JsSIP";var at=class{constructor(t){t?(this._debug=Mn.default(`${Ln}:${t}`),this._warn=Mn.default(`${Ln}:WARN:${t}`),this._error=Mn.default(`${Ln}:ERROR:${t}`)):(this._debug=Mn.default(Ln),this._warn=Mn.default(`${Ln}:WARN`),this._error=Mn.default(`${Ln}:ERROR`)),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}get debug(){return this._debug}get warn(){return this._warn}get error(){return this._error}};const ra=Me(at),Cf=vl;var De={USER_AGENT:`${Cf.title} ${Cf.version}`,SIP:"sip",SIPS:"sips",causes:{CONNECTION_ERROR:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{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",424:"Bad Location Information",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:"JsSIP Internal 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"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2};const L=Me(De);var Ze={},qo,Af;function Vo(){if(Af)return qo;Af=1;const c=ps(),t=Jt();return qo=class $h{static parse(a){if(a=t.parse(a,"Name_Addr_Header"),a!==-1)return a}constructor(a,o,s){if(!a||!(a instanceof c))throw new TypeError('missing or invalid "uri" parameter');this._uri=a,this._parameters={},this.display_name=o;for(const r in s)Object.prototype.hasOwnProperty.call(s,r)&&this.setParam(r,s[r])}get uri(){return this._uri}get display_name(){return this._display_name}set display_name(a){this._display_name=a===0?"0":a}setParam(a,o){a&&(this._parameters[a.toLowerCase()]=typeof o>"u"||o===null?null:o.toString())}getParam(a){if(a)return this._parameters[a.toLowerCase()]}hasParam(a){if(a)return this._parameters.hasOwnProperty(a.toLowerCase())&&!0||!1}deleteParam(a){if(a=a.toLowerCase(),this._parameters.hasOwnProperty(a)){const o=this._parameters[a];return delete this._parameters[a],o}}clearParams(){this._parameters={}}clone(){return new $h(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}_quote(a){return a.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}toString(){let a=this._display_name?`"${this._quote(this._display_name)}" `:"";a+=`<${this._uri.toString()}>`;for(const o in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,o)&&(a+=`;${o}`,this._parameters[o]!==null&&(a+=`=${this._parameters[o]}`));return a}},qo}var Bo,Rf;function Jt(){return Rf||(Rf=1,Bo=function(){function c(n){return'"'+n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var t={parse:function(n,a){var o={CRLF:_,DIGIT:g,ALPHA:T,HEXDIG:E,WSP:y,OCTET:C,DQUOTE:A,SP:I,HTAB:H,alphanum:$,reserved:oe,unreserved:N,mark:j,escaped:Se,LWS:ve,SWS:k,HCOLON:D,TEXT_UTF8_TRIM:B,TEXT_UTF8char:V,UTF8_NONASCII:J,UTF8_CONT:F,LHEX:Z,token:U,token_nodot:P,separators:se,word:it,STAR:ee,SLASH:Y,EQUAL:G,LPAREN:re,RPAREN:ge,RAQUOT:be,LAQUOT:ke,COMMA:Re,SEMI:le,COLON:ye,LDQUOT:lt,RDQUOT:ot,comment:Ee,ctext:Ce,quoted_string:Ie,quoted_string_clean:Oe,qdtext:pe,quoted_pair:de,SIP_URI_noparams:_e,SIP_URI:we,uri_scheme:Ne,uri_scheme_sips:tt,uri_scheme_sip:He,userinfo:Vt,user:At,user_unreserved:Bn,password:Gn,hostport:cn,host:as,hostname:Cs,domainlabel:fn,toplabel:Wn,IPv6reference:Kn,IPv6address:hn,h16:me,ls32:ae,IPv4address:ut,dec_octet:es,port:$s,uri_parameters:ui,uri_parameter:Yn,transport_param:Jn,user_param:ci,method_param:fi,ttl_param:hi,maddr_param:di,lr_param:_i,other_param:pi,pname:mi,pvalue:gi,paramchar:Hs,param_unreserved:Fs,headers:Ti,header:dn,hname:_n,hvalue:vi,hnv_unreserved:js,Request_Response:pn,Request_Line:wa,Request_URI:Ei,absoluteURI:zn,hier_part:Xn,net_path:Si,abs_path:mn,opaque_part:gn,uric:qs,uric_no_slash:Vs,path_segments:yi,segment:Tn,param:Bs,pchar:As,scheme:Gs,authority:Ci,srvr:Ai,reg_name:Ri,query:Ii,SIP_Version:Qn,INVITEm:Zn,ACKm:bi,OPTIONSm:wi,BYEm:Oi,CANCELm:Di,REGISTERm:Ni,SUBSCRIBEm:Ui,NOTIFYm:Pi,REFERm:xi,Method:vn,Status_Line:En,Status_Code:ki,extension_code:Mi,Reason_Phrase:Li,Allow_Events:Oa,Call_ID:Du,Contact:Nu,contact_param:er,name_addr:Bt,display_name:Gt,contact_params:Ws,c_p_q:tr,c_p_expires:$i,delta_seconds:os,qvalue:us,generic_param:Je,gen_value:ze,Content_Disposition:Da,disp_type:Na,disp_param:sr,handling_param:nr,Content_Encoding:Ua,Content_Length:Uu,Content_Type:Pu,media_type:Pa,m_type:Hi,discrete_type:Fi,composite_type:ji,extension_token:Sn,x_token:yn,m_subtype:qi,m_parameter:rr,m_value:ir,CSeq:xa,CSeq_value:ka,Expires:Ma,Event:xu,event_type:Cn,From:An,from_param:Vi,tag_param:Rn,Max_Forwards:Bi,Min_Expires:ku,Name_Addr_Header:Mu,Proxy_Authenticate:Lu,challenge:Gi,other_challenge:lr,auth_param:Ks,digest_cln:cs,realm:In,realm_value:Wi,domain:Ki,URI:bn,nonce:wn,nonce_value:Yi,opaque:Ji,stale:zi,algorithm:Xi,qop_options:Qi,qop_value:On,Proxy_Require:ar,Record_Route:$u,rec_route:or,Reason:ur,reason_param:Zi,reason_cause:cr,Require:La,Route:Hu,route_param:fr,Subscription_State:hr,substate_value:$a,subexp_params:dr,event_reason_value:_r,Subject:Ha,Supported:Fu,To:ju,to_param:el,Via:tl,via_param:pr,via_params:Ys,via_ttl:mr,via_maddr:sl,via_received:nl,via_branch:rl,response_port:il,rport:ll,sent_protocol:al,protocol_name:ol,transport:ul,sent_by:cl,via_host:fl,via_port:hl,ttl:gr,WWW_Authenticate:dl,Session_Expires:qu,s_e_expires:Fa,s_e_params:Tr,s_e_refresher:vr,extension_header:ja,header_value:qa,message_body:Va,uuid_URI:Vu,uuid:Ba,hex4:Wt,hex8:Kt,hex12:_l,Refer_To:Ga,Replaces:Bu,call_id:Wa,replaces_param:Er,to_tag:Sr,from_tag:pl,early_flag:ml};if(a!==void 0){if(o[a]===void 0)throw new Error("Invalid rule name: "+c(a)+".")}else a="CRLF";var s=0,r=0,d=[];function h(i){s<r||(s>r&&(r=s,d=[]),d.push(i))}function _(){var i;return n.substr(s,2)===`\r
|
73
73
|
`?(i=`\r
|
74
|
-
`,s+=2):(i=null,h('"\\r\\n"')),i}function g(){var i;return/^[0-9]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[0-9]")),i}function T(){var i;return/^[a-zA-Z]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[a-zA-Z]")),i}function E(){var i;return/^[0-9a-fA-F]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[0-9a-fA-F]")),i}function y(){var i;return i=I(),i===null&&(i=H()),i}function A(){var i;return/^[\0-\xFF]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\0-\\xFF]")),i}function C(){var i;return/^["]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h('["]')),i}function I(){var i;return n.charCodeAt(s)===32?(i=" ",s++):(i=null,h('" "')),i}function H(){var i;return n.charCodeAt(s)===9?(i=" ",s++):(i=null,h('"\\t"')),i}function $(){var i;return/^[a-zA-Z0-9]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[a-zA-Z0-9]")),i}function oe(){var i;return n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","'))))))))))),i}function N(){var i;return i=$(),i===null&&(i=j()),i}function j(){var i;return n.charCodeAt(s)===45?(i="-",s++):(i=null,h('"-"')),i===null&&(n.charCodeAt(s)===95?(i="_",s++):(i=null,h('"_"')),i===null&&(n.charCodeAt(s)===46?(i=".",s++):(i=null,h('"."')),i===null&&(n.charCodeAt(s)===33?(i="!",s++):(i=null,h('"!"')),i===null&&(n.charCodeAt(s)===126?(i="~",s++):(i=null,h('"~"')),i===null&&(n.charCodeAt(s)===42?(i="*",s++):(i=null,h('"*"')),i===null&&(n.charCodeAt(s)===39?(i="'",s++):(i=null,h(`"'"`)),i===null&&(n.charCodeAt(s)===40?(i="(",s++):(i=null,h('"("')),i===null&&(n.charCodeAt(s)===41?(i=")",s++):(i=null,h('")"')))))))))),i}function Se(){var i,e,l,u,f;return u=s,f=s,n.charCodeAt(s)===37?(i="%",s++):(i=null,h('"%"')),i!==null?(e=E(),e!==null?(l=E(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){return m.join("")}(u,i)),i===null&&(s=u),i}function ve(){var i,e,l,u,f,p;for(u=s,f=s,p=s,i=[],e=y();e!==null;)i.push(e),e=y();if(i!==null?(e=_(),e!==null?i=[i,e]:(i=null,s=p)):(i=null,s=p),i=i!==null?i:"",i!==null){if(l=y(),l!==null)for(e=[];l!==null;)e.push(l),l=y();else e=null;e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i!==null&&(i=function(m){return" "}()),i===null&&(s=u),i}function k(){var i;return i=ve(),i=i!==null?i:"",i}function D(){var i,e,l,u,f;for(u=s,f=s,i=[],e=I(),e===null&&(e=H());e!==null;)i.push(e),e=I(),e===null&&(e=H());return i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return":"}()),i===null&&(s=u),i}function B(){var i,e,l,u,f,p,m;if(f=s,p=s,e=V(),e!==null)for(i=[];e!==null;)i.push(e),e=V();else i=null;if(i!==null){for(e=[],m=s,l=[],u=ve();u!==null;)l.push(u),u=ve();for(l!==null?(u=V(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;){for(e.push(l),m=s,l=[],u=ve();u!==null;)l.push(u),u=ve();l!==null?(u=V(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m)}e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){return n.substring(s,v)}(f)),i===null&&(s=f),i}function V(){var i;return/^[!-~]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[!-~]")),i===null&&(i=J()),i}function J(){var i;return/^[\x80-\uFFFF]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\x80-\\uFFFF]")),i}function F(){var i;return/^[\x80-\xBF]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\x80-\\xBF]")),i}function Z(){var i;return i=g(),i===null&&(/^[a-f]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[a-f]"))),i}function U(){var i,e,l;if(l=s,e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"'))))))))))));else i=null;return i!==null&&(i=function(u){return n.substring(s,u)}(l)),i===null&&(s=l),i}function P(){var i,e,l;if(l=s,e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"'))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')))))))))));else i=null;return i!==null&&(i=function(u){return n.substring(s,u)}(l)),i===null&&(s=l),i}function se(){var i;return n.charCodeAt(s)===40?(i="(",s++):(i=null,h('"("')),i===null&&(n.charCodeAt(s)===41?(i=")",s++):(i=null,h('")"')),i===null&&(n.charCodeAt(s)===60?(i="<",s++):(i=null,h('"<"')),i===null&&(n.charCodeAt(s)===62?(i=">",s++):(i=null,h('">"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===92?(i="\\",s++):(i=null,h('"\\\\"')),i===null&&(i=C(),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i===null&&(n.charCodeAt(s)===93?(i="]",s++):(i=null,h('"]"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===123?(i="{",s++):(i=null,h('"{"')),i===null&&(n.charCodeAt(s)===125?(i="}",s++):(i=null,h('"}"')),i===null&&(i=I(),i===null&&(i=H())))))))))))))))))),i}function it(){var i,e,l;if(l=s,e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')),e===null&&(n.charCodeAt(s)===40?(e="(",s++):(e=null,h('"("')),e===null&&(n.charCodeAt(s)===41?(e=")",s++):(e=null,h('")"')),e===null&&(n.charCodeAt(s)===60?(e="<",s++):(e=null,h('"<"')),e===null&&(n.charCodeAt(s)===62?(e=">",s++):(e=null,h('">"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===92?(e="\\",s++):(e=null,h('"\\\\"')),e===null&&(e=C(),e===null&&(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e===null&&(n.charCodeAt(s)===91?(e="[",s++):(e=null,h('"["')),e===null&&(n.charCodeAt(s)===93?(e="]",s++):(e=null,h('"]"')),e===null&&(n.charCodeAt(s)===63?(e="?",s++):(e=null,h('"?"')),e===null&&(n.charCodeAt(s)===123?(e="{",s++):(e=null,h('"{"')),e===null&&(n.charCodeAt(s)===125?(e="}",s++):(e=null,h('"}"'))))))))))))))))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')),e===null&&(n.charCodeAt(s)===40?(e="(",s++):(e=null,h('"("')),e===null&&(n.charCodeAt(s)===41?(e=")",s++):(e=null,h('")"')),e===null&&(n.charCodeAt(s)===60?(e="<",s++):(e=null,h('"<"')),e===null&&(n.charCodeAt(s)===62?(e=">",s++):(e=null,h('">"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===92?(e="\\",s++):(e=null,h('"\\\\"')),e===null&&(e=C(),e===null&&(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e===null&&(n.charCodeAt(s)===91?(e="[",s++):(e=null,h('"["')),e===null&&(n.charCodeAt(s)===93?(e="]",s++):(e=null,h('"]"')),e===null&&(n.charCodeAt(s)===63?(e="?",s++):(e=null,h('"?"')),e===null&&(n.charCodeAt(s)===123?(e="{",s++):(e=null,h('"{"')),e===null&&(n.charCodeAt(s)===125?(e="}",s++):(e=null,h('"}"')))))))))))))))))))))))));else i=null;return i!==null&&(i=function(u){return n.substring(s,u)}(l)),i===null&&(s=l),i}function ee(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"*"}()),i===null&&(s=u),i}function Y(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"/"}()),i===null&&(s=u),i}function G(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"="}()),i===null&&(s=u),i}function re(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===40?(e="(",s++):(e=null,h('"("')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"("}()),i===null&&(s=u),i}function ge(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===41?(e=")",s++):(e=null,h('")"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return")"}()),i===null&&(s=u),i}function be(){var i,e,l,u;return l=s,u=s,n.charCodeAt(s)===62?(i=">",s++):(i=null,h('">"')),i!==null?(e=k(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return">"}()),i===null&&(s=l),i}function ke(){var i,e,l,u;return l=s,u=s,i=k(),i!==null?(n.charCodeAt(s)===60?(e="<",s++):(e=null,h('"<"')),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return"<"}()),i===null&&(s=l),i}function Re(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return","}()),i===null&&(s=u),i}function le(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return";"}()),i===null&&(s=u),i}function ye(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return":"}()),i===null&&(s=u),i}function lt(){var i,e,l,u;return l=s,u=s,i=k(),i!==null?(e=C(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return'"'}()),i===null&&(s=l),i}function ot(){var i,e,l,u;return l=s,u=s,i=C(),i!==null?(e=k(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return'"'}()),i===null&&(s=l),i}function Ee(){var i,e,l,u;if(u=s,i=re(),i!==null){for(e=[],l=Ae(),l===null&&(l=de(),l===null&&(l=Ee()));l!==null;)e.push(l),l=Ae(),l===null&&(l=de(),l===null&&(l=Ee()));e!==null?(l=ge(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)}else i=null,s=u;return i}function Ae(){var i;return/^[!-']/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[!-']")),i===null&&(/^[*-[]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[*-[]")),i===null&&(/^[\]-~]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\]-~]")),i===null&&(i=J(),i===null&&(i=ve())))),i}function Ie(){var i,e,l,u,f,p;if(f=s,p=s,i=k(),i!==null)if(e=C(),e!==null){for(l=[],u=pe(),u===null&&(u=de());u!==null;)l.push(u),u=pe(),u===null&&(u=de());l!==null?(u=C(),u!==null?i=[i,e,l,u]:(i=null,s=p)):(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i!==null&&(i=function(m){return n.substring(s,m)}(f)),i===null&&(s=f),i}function Oe(){var i,e,l,u,f,p;if(f=s,p=s,i=k(),i!==null)if(e=C(),e!==null){for(l=[],u=pe(),u===null&&(u=de());u!==null;)l.push(u),u=pe(),u===null&&(u=de());l!==null?(u=C(),u!==null?i=[i,e,l,u]:(i=null,s=p)):(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i!==null&&(i=function(m){var v=n.substring(s,m).trim();return v.substring(1,v.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(f)),i===null&&(s=f),i}function pe(){var i;return i=ve(),i===null&&(n.charCodeAt(s)===33?(i="!",s++):(i=null,h('"!"')),i===null&&(/^[#-[]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[#-[]")),i===null&&(/^[\]-~]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\]-~]")),i===null&&(i=J())))),i}function de(){var i,e,l;return l=s,n.charCodeAt(s)===92?(i="\\",s++):(i=null,h('"\\\\"')),i!==null?(/^[\0-\t]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[\\0-\\t]")),e===null&&(/^[\x0B-\f]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[\\x0B-\\f]")),e===null&&(/^[\x0E-]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[\\x0E-]")))),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function _e(){var i,e,l,u,f,p;return f=s,p=s,i=Ne(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=Vt(),l=l!==null?l:"",l!==null?(u=cn(),u!==null?i=[i,e,l,u]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i!==null&&(i=function(m){try{b.uri=new Ya(b.scheme,b.user,b.host,b.port),delete b.scheme,delete b.user,delete b.host,delete b.host_type,delete b.port}catch{b=-1}}()),i===null&&(s=f),i}function we(){var i,e,l,u,f,p,m,v;return m=s,v=s,i=Ne(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=Vt(),l=l!==null?l:"",l!==null?(u=cn(),u!==null?(f=ui(),f!==null?(p=Ti(),p=p!==null?p:"",p!==null?i=[i,e,l,u,f,p]:(i=null,s=v)):(i=null,s=v)):(i=null,s=v)):(i=null,s=v)):(i=null,s=v)):(i=null,s=v),i!==null&&(i=function(S){try{b.uri=new Ya(b.scheme,b.user,b.host,b.port,b.uri_params,b.uri_headers),delete b.scheme,delete b.user,delete b.host,delete b.host_type,delete b.port,delete b.uri_params,a==="SIP_URI"&&(b=b.uri)}catch{b=-1}}()),i===null&&(s=m),i}function Ne(){var i;return i=tt(),i===null&&(i=He()),i}function tt(){var i,e;return e=s,n.substr(s,4).toLowerCase()==="sips"?(i=n.substr(s,4),s+=4):(i=null,h('"sips"')),i!==null&&(i=function(l,u){b.scheme=u.toLowerCase()}(e,i)),i===null&&(s=e),i}function He(){var i,e;return e=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"sip"')),i!==null&&(i=function(l,u){b.scheme=u.toLowerCase()}(e,i)),i===null&&(s=e),i}function Vt(){var i,e,l,u,f,p;return u=s,f=s,i=Ct(),i!==null?(p=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=Gn(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?(n.charCodeAt(s)===64?(l="@",s++):(l=null,h('"@"')),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b.user=decodeURIComponent(n.substring(s-1,m))}(u)),i===null&&(s=u),i}function Ct(){var i,e;if(e=N(),e===null&&(e=Se(),e===null&&(e=Bn())),e!==null)for(i=[];e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(e=Bn()));else i=null;return i}function Bn(){var i;return n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"'))))))))),i}function Gn(){var i,e,l;for(l=s,i=[],e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","'))))))));e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","'))))))));return i!==null&&(i=function(u){b.password=n.substring(s,u)}(l)),i===null&&(s=l),i}function cn(){var i,e,l,u,f;return u=s,i=as(),i!==null?(f=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=$s(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function as(){var i,e;return e=s,i=As(),i===null&&(i=ut(),i===null&&(i=Kn())),i!==null&&(i=function(l){return b.host=n.substring(s,l).toLowerCase(),b.host}(e)),i===null&&(s=e),i}function As(){var i,e,l,u,f,p;for(u=s,f=s,i=[],p=s,e=fn(),e!==null?(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p);e!==null;)i.push(e),p=s,e=fn(),e!==null?(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p);return i!==null?(e=Wn(),e!==null?(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l=l!==null?l:"",l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){return b.host_type="domain",n.substring(s,m)}(u)),i===null&&(s=u),i}function fn(){var i,e,l,u;if(u=s,i=$(),i!==null){for(e=[],l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));l!==null;)e.push(l),l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));e!==null?i=[i,e]:(i=null,s=u)}else i=null,s=u;return i}function Wn(){var i,e,l,u;if(u=s,i=T(),i!==null){for(e=[],l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));l!==null;)e.push(l),l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));e!==null?i=[i,e]:(i=null,s=u)}else i=null,s=u;return i}function Kn(){var i,e,l,u,f;return u=s,f=s,n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i!==null?(e=hn(),e!==null?(n.charCodeAt(s)===93?(l="]",s++):(l=null,h('"]"')),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return b.host_type="IPv6",n.substring(s,p)}(u)),i===null&&(s=u),i}function hn(){var i,e,l,u,f,p,m,v,S,O,ie,Ue,Dt,Js,M,R;return Js=s,M=s,i=me(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?(n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?(n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?(n.charCodeAt(s)===58?(v=":",s++):(v=null,h('":"')),v!==null?(S=me(),S!==null?(n.charCodeAt(s)===58?(O=":",s++):(O=null,h('":"')),O!==null?(ie=me(),ie!==null?(n.charCodeAt(s)===58?(Ue=":",s++):(Ue=null,h('":"')),Ue!==null?(Dt=ae(),Dt!==null?i=[i,e,l,u,f,p,m,v,S,O,ie,Ue,Dt]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?(n.charCodeAt(s)===58?(S=":",s++):(S=null,h('":"')),S!==null?(O=me(),O!==null?(n.charCodeAt(s)===58?(ie=":",s++):(ie=null,h('":"')),ie!==null?(Ue=ae(),Ue!==null?i=[i,e,l,u,f,p,m,v,S,O,ie,Ue]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?(n.charCodeAt(s)===58?(S=":",s++):(S=null,h('":"')),S!==null?(O=ae(),O!==null?i=[i,e,l,u,f,p,m,v,S,O]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=ae(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=ae(),p!==null?i=[i,e,l,u,f,p]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=ae(),u!==null?i=[i,e,l,u]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=ae(),e!==null?i=[i,e]:(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?i=[i,e]:(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(n.substr(s,2)==="::"?(e="::",s+=2):(e=null,h('"::"')),e!==null?(l=me(),l!==null?(n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?(n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?(n.charCodeAt(s)===58?(v=":",s++):(v=null,h('":"')),v!==null?(S=me(),S!==null?(n.charCodeAt(s)===58?(O=":",s++):(O=null,h('":"')),O!==null?(ie=ae(),ie!==null?i=[i,e,l,u,f,p,m,v,S,O,ie]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(n.substr(s,2)==="::"?(l="::",s+=2):(l=null,h('"::"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?(n.charCodeAt(s)===58?(S=":",s++):(S=null,h('":"')),S!==null?(O=ae(),O!==null?i=[i,e,l,u,f,p,m,v,S,O]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(n.substr(s,2)==="::"?(u="::",s+=2):(u=null,h('"::"')),u!==null?(f=me(),f!==null?(n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?(n.charCodeAt(s)===58?(v=":",s++):(v=null,h('":"')),v!==null?(S=ae(),S!==null?i=[i,e,l,u,f,p,m,v,S]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(n.substr(s,2)==="::"?(f="::",s+=2):(f=null,h('"::"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=ae(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(R=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,s=R)):(f=null,s=R),f=f!==null?f:"",f!==null?(n.substr(s,2)==="::"?(p="::",s+=2):(p=null,h('"::"')),p!==null?(m=ae(),m!==null?i=[i,e,l,u,f,p,m]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(R=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,s=R)):(f=null,s=R),f=f!==null?f:"",f!==null?(R=s,n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?p=[p,m]:(p=null,s=R)):(p=null,s=R),p=p!==null?p:"",p!==null?(n.substr(s,2)==="::"?(m="::",s+=2):(m=null,h('"::"')),m!==null?(v=me(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(R=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,s=R)):(f=null,s=R),f=f!==null?f:"",f!==null?(R=s,n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?p=[p,m]:(p=null,s=R)):(p=null,s=R),p=p!==null?p:"",p!==null?(R=s,n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?m=[m,v]:(m=null,s=R)):(m=null,s=R),m=m!==null?m:"",m!==null?(n.substr(s,2)==="::"?(v="::",s+=2):(v=null,h('"::"')),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M))))))))))))))),i!==null&&(i=function(Te){return b.host_type="IPv6",n.substring(s,Te)}(Js)),i===null&&(s=Js),i}function me(){var i,e,l,u,f;return f=s,i=E(),i!==null?(e=E(),e=e!==null?e:"",e!==null?(l=E(),l=l!==null?l:"",l!==null?(u=E(),u=u!==null?u:"",u!==null?i=[i,e,l,u]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i}function ae(){var i,e,l,u;return u=s,i=me(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i===null&&(i=ut()),i}function ut(){var i,e,l,u,f,p,m,v,S;return v=s,S=s,i=es(),i!==null?(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e!==null?(l=es(),l!==null?(n.charCodeAt(s)===46?(u=".",s++):(u=null,h('"."')),u!==null?(f=es(),f!==null?(n.charCodeAt(s)===46?(p=".",s++):(p=null,h('"."')),p!==null?(m=es(),m!==null?i=[i,e,l,u,f,p,m]:(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S),i!==null&&(i=function(O){return b.host_type="IPv4",n.substring(s,O)}(v)),i===null&&(s=v),i}function es(){var i,e,l,u;return u=s,n.substr(s,2)==="25"?(i="25",s+=2):(i=null,h('"25"')),i!==null?(/^[0-5]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[0-5]")),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i===null&&(u=s,n.charCodeAt(s)===50?(i="2",s++):(i=null,h('"2"')),i!==null?(/^[0-4]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[0-4]")),e!==null?(l=g(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i===null&&(u=s,n.charCodeAt(s)===49?(i="1",s++):(i=null,h('"1"')),i!==null?(e=g(),e!==null?(l=g(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i===null&&(u=s,/^[1-9]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[1-9]")),i!==null?(e=g(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i===null&&(i=g())))),i}function $s(){var i,e,l,u,f,p,m;return p=s,m=s,i=g(),i=i!==null?i:"",i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?i=[i,e,l,u,f]:(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(v,S){return S=parseInt(S.join("")),b.port=S,S}(p,i)),i===null&&(s=p),i}function ui(){var i,e,l,u;for(i=[],u=s,n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e!==null?(l=Yn(),l!==null?e=[e,l]:(e=null,s=u)):(e=null,s=u);e!==null;)i.push(e),u=s,n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e!==null?(l=Yn(),l!==null?e=[e,l]:(e=null,s=u)):(e=null,s=u);return i}function Yn(){var i;return i=Jn(),i===null&&(i=ci(),i===null&&(i=fi(),i===null&&(i=hi(),i===null&&(i=di(),i===null&&(i=_i(),i===null&&(i=pi())))))),i}function Jn(){var i,e,l,u;return l=s,u=s,n.substr(s,10).toLowerCase()==="transport="?(i=n.substr(s,10),s+=10):(i=null,h('"transport="')),i!==null?(n.substr(s,3).toLowerCase()==="udp"?(e=n.substr(s,3),s+=3):(e=null,h('"udp"')),e===null&&(n.substr(s,3).toLowerCase()==="tcp"?(e=n.substr(s,3),s+=3):(e=null,h('"tcp"')),e===null&&(n.substr(s,4).toLowerCase()==="sctp"?(e=n.substr(s,4),s+=4):(e=null,h('"sctp"')),e===null&&(n.substr(s,3).toLowerCase()==="tls"?(e=n.substr(s,3),s+=3):(e=null,h('"tls"')),e===null&&(e=U())))),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.transport=p.toLowerCase()}(l,i[1])),i===null&&(s=l),i}function ci(){var i,e,l,u;return l=s,u=s,n.substr(s,5).toLowerCase()==="user="?(i=n.substr(s,5),s+=5):(i=null,h('"user="')),i!==null?(n.substr(s,5).toLowerCase()==="phone"?(e=n.substr(s,5),s+=5):(e=null,h('"phone"')),e===null&&(n.substr(s,2).toLowerCase()==="ip"?(e=n.substr(s,2),s+=2):(e=null,h('"ip"')),e===null&&(e=U())),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.user=p.toLowerCase()}(l,i[1])),i===null&&(s=l),i}function fi(){var i,e,l,u;return l=s,u=s,n.substr(s,7).toLowerCase()==="method="?(i=n.substr(s,7),s+=7):(i=null,h('"method="')),i!==null?(e=vn(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.method=p}(l,i[1])),i===null&&(s=l),i}function hi(){var i,e,l,u;return l=s,u=s,n.substr(s,4).toLowerCase()==="ttl="?(i=n.substr(s,4),s+=4):(i=null,h('"ttl="')),i!==null?(e=gr(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.params||(b.params={}),b.params.ttl=p}(l,i[1])),i===null&&(s=l),i}function di(){var i,e,l,u;return l=s,u=s,n.substr(s,6).toLowerCase()==="maddr="?(i=n.substr(s,6),s+=6):(i=null,h('"maddr="')),i!==null?(e=as(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.maddr=p}(l,i[1])),i===null&&(s=l),i}function _i(){var i,e,l,u,f,p;return u=s,f=s,n.substr(s,2).toLowerCase()==="lr"?(i=n.substr(s,2),s+=2):(i=null,h('"lr"')),i!==null?(p=s,n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=U(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b.uri_params||(b.uri_params={}),b.uri_params.lr=void 0}()),i===null&&(s=u),i}function pi(){var i,e,l,u,f,p;return u=s,f=s,i=mi(),i!==null?(p=s,n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=gi(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m,v,S){b.uri_params||(b.uri_params={}),typeof S>"u"?S=void 0:S=S[1],b.uri_params[v.toLowerCase()]=S}(u,i[0],i[1])),i===null&&(s=u),i}function mi(){var i,e,l;if(l=s,e=Hs(),e!==null)for(i=[];e!==null;)i.push(e),e=Hs();else i=null;return i!==null&&(i=function(u,f){return f.join("")}(l,i)),i===null&&(s=l),i}function gi(){var i,e,l;if(l=s,e=Hs(),e!==null)for(i=[];e!==null;)i.push(e),e=Hs();else i=null;return i!==null&&(i=function(u,f){return f.join("")}(l,i)),i===null&&(s=l),i}function Hs(){var i;return i=Fs(),i===null&&(i=N(),i===null&&(i=Se())),i}function Fs(){var i;return n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i===null&&(n.charCodeAt(s)===93?(i="]",s++):(i=null,h('"]"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')))))))),i}function Ti(){var i,e,l,u,f,p,m;if(p=s,n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i!==null)if(e=dn(),e!==null){for(l=[],m=s,n.charCodeAt(s)===38?(u="&",s++):(u=null,h('"&"')),u!==null?(f=dn(),f!==null?u=[u,f]:(u=null,s=m)):(u=null,s=m);u!==null;)l.push(u),m=s,n.charCodeAt(s)===38?(u="&",s++):(u=null,h('"&"')),u!==null?(f=dn(),f!==null?u=[u,f]:(u=null,s=m)):(u=null,s=m);l!==null?i=[i,e,l]:(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i}function dn(){var i,e,l,u,f;return u=s,f=s,i=_n(),i!==null?(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=vi(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m,v){m=m.join("").toLowerCase(),v=v.join(""),b.uri_headers||(b.uri_headers={}),b.uri_headers[m]?b.uri_headers[m].push(v):b.uri_headers[m]=[v]}(u,i[0],i[2])),i===null&&(s=u),i}function _n(){var i,e;if(e=js(),e===null&&(e=N(),e===null&&(e=Se())),e!==null)for(i=[];e!==null;)i.push(e),e=js(),e===null&&(e=N(),e===null&&(e=Se()));else i=null;return i}function vi(){var i,e;for(i=[],e=js(),e===null&&(e=N(),e===null&&(e=Se()));e!==null;)i.push(e),e=js(),e===null&&(e=N(),e===null&&(e=Se()));return i}function js(){var i;return n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i===null&&(n.charCodeAt(s)===93?(i="]",s++):(i=null,h('"]"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')))))))),i}function pn(){var i;return i=En(),i===null&&(i=wa()),i}function wa(){var i,e,l,u,f,p;return p=s,i=vn(),i!==null?(e=I(),e!==null?(l=Ei(),l!==null?(u=I(),u!==null?(f=Qn(),f!==null?i=[i,e,l,u,f]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i}function Ei(){var i;return i=we(),i===null&&(i=zn()),i}function zn(){var i,e,l,u;return u=s,i=Gs(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=Xn(),l===null&&(l=gn()),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Xn(){var i,e,l,u,f;return u=s,i=Si(),i===null&&(i=mn()),i!==null?(f=s,n.charCodeAt(s)===63?(e="?",s++):(e=null,h('"?"')),e!==null?(l=Ii(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function Si(){var i,e,l,u;return u=s,n.substr(s,2)==="//"?(i="//",s+=2):(i=null,h('"//"')),i!==null?(e=Ai(),e!==null?(l=mn(),l=l!==null?l:"",l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function mn(){var i,e,l;return l=s,n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i!==null?(e=yi(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function gn(){var i,e,l,u;if(u=s,i=Vs(),i!==null){for(e=[],l=qs();l!==null;)e.push(l),l=qs();e!==null?i=[i,e]:(i=null,s=u)}else i=null,s=u;return i}function qs(){var i;return i=oe(),i===null&&(i=N(),i===null&&(i=Se())),i}function Vs(){var i;return i=N(),i===null&&(i=Se(),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')))))))))))),i}function yi(){var i,e,l,u,f,p;if(f=s,i=Tn(),i!==null){for(e=[],p=s,n.charCodeAt(s)===47?(l="/",s++):(l=null,h('"/"')),l!==null?(u=Tn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,n.charCodeAt(s)===47?(l="/",s++):(l=null,h('"/"')),l!==null?(u=Tn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Tn(){var i,e,l,u,f,p;for(f=s,i=[],e=Cs();e!==null;)i.push(e),e=Cs();if(i!==null){for(e=[],p=s,n.charCodeAt(s)===59?(l=";",s++):(l=null,h('";"')),l!==null?(u=Bs(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,n.charCodeAt(s)===59?(l=";",s++):(l=null,h('";"')),l!==null?(u=Bs(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Bs(){var i,e;for(i=[],e=Cs();e!==null;)i.push(e),e=Cs();return i}function Cs(){var i;return i=N(),i===null&&(i=Se(),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')))))))))),i}function Gs(){var i,e,l,u,f;if(u=s,f=s,i=T(),i!==null){for(e=[],l=T(),l===null&&(l=g(),l===null&&(n.charCodeAt(s)===43?(l="+",s++):(l=null,h('"+"')),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."'))))));l!==null;)e.push(l),l=T(),l===null&&(l=g(),l===null&&(n.charCodeAt(s)===43?(l="+",s++):(l=null,h('"+"')),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."'))))));e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i!==null&&(i=function(p){b.scheme=n.substring(s,p)}(u)),i===null&&(s=u),i}function Ai(){var i;return i=Ci(),i===null&&(i=Ri()),i}function Ci(){var i,e,l,u;return l=s,u=s,i=Vt(),i!==null?(n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i=i!==null?i:"",i!==null?(e=cn(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i=i!==null?i:"",i}function Ri(){var i,e;if(e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","')),e===null&&(n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"'))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","')),e===null&&(n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')))))))))));else i=null;return i}function Ii(){var i,e;for(i=[],e=qs();e!==null;)i.push(e),e=qs();return i}function Qn(){var i,e,l,u,f,p,m,v;if(m=s,v=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"SIP"')),i!==null)if(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e!==null){if(u=g(),u!==null)for(l=[];u!==null;)l.push(u),u=g();else l=null;if(l!==null)if(n.charCodeAt(s)===46?(u=".",s++):(u=null,h('"."')),u!==null){if(p=g(),p!==null)for(f=[];p!==null;)f.push(p),p=g();else f=null;f!==null?i=[i,e,l,u,f]:(i=null,s=v)}else i=null,s=v;else i=null,s=v}else i=null,s=v;else i=null,s=v;return i!==null&&(i=function(S){b.sip_version=n.substring(s,S)}(m)),i===null&&(s=m),i}function Zn(){var i;return n.substr(s,6)==="INVITE"?(i="INVITE",s+=6):(i=null,h('"INVITE"')),i}function bi(){var i;return n.substr(s,3)==="ACK"?(i="ACK",s+=3):(i=null,h('"ACK"')),i}function wi(){var i;return n.substr(s,7)==="OPTIONS"?(i="OPTIONS",s+=7):(i=null,h('"OPTIONS"')),i}function Oi(){var i;return n.substr(s,3)==="BYE"?(i="BYE",s+=3):(i=null,h('"BYE"')),i}function Di(){var i;return n.substr(s,6)==="CANCEL"?(i="CANCEL",s+=6):(i=null,h('"CANCEL"')),i}function Ni(){var i;return n.substr(s,8)==="REGISTER"?(i="REGISTER",s+=8):(i=null,h('"REGISTER"')),i}function Ui(){var i;return n.substr(s,9)==="SUBSCRIBE"?(i="SUBSCRIBE",s+=9):(i=null,h('"SUBSCRIBE"')),i}function Pi(){var i;return n.substr(s,6)==="NOTIFY"?(i="NOTIFY",s+=6):(i=null,h('"NOTIFY"')),i}function xi(){var i;return n.substr(s,5)==="REFER"?(i="REFER",s+=5):(i=null,h('"REFER"')),i}function vn(){var i,e;return e=s,i=Zn(),i===null&&(i=bi(),i===null&&(i=wi(),i===null&&(i=Oi(),i===null&&(i=Di(),i===null&&(i=Ni(),i===null&&(i=Ui(),i===null&&(i=Pi(),i===null&&(i=xi(),i===null&&(i=U()))))))))),i!==null&&(i=function(l){return b.method=n.substring(s,l),b.method}(e)),i===null&&(s=e),i}function En(){var i,e,l,u,f,p;return p=s,i=Qn(),i!==null?(e=I(),e!==null?(l=ki(),l!==null?(u=I(),u!==null?(f=Li(),f!==null?i=[i,e,l,u,f]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i}function ki(){var i,e;return e=s,i=Mi(),i!==null&&(i=function(l,u){b.status_code=parseInt(u.join(""))}(e,i)),i===null&&(s=e),i}function Mi(){var i,e,l,u;return u=s,i=g(),i!==null?(e=g(),e!==null?(l=g(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Li(){var i,e,l;for(l=s,i=[],e=oe(),e===null&&(e=N(),e===null&&(e=Se(),e===null&&(e=J(),e===null&&(e=F(),e===null&&(e=I(),e===null&&(e=H()))))));e!==null;)i.push(e),e=oe(),e===null&&(e=N(),e===null&&(e=Se(),e===null&&(e=J(),e===null&&(e=F(),e===null&&(e=I(),e===null&&(e=H()))))));return i!==null&&(i=function(u){b.reason_phrase=n.substring(s,u)}(l)),i===null&&(s=l),i}function Oa(){var i,e,l,u,f,p;if(f=s,i=An(),i!==null){for(e=[],p=s,l=Re(),l!==null?(u=An(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Re(),l!==null?(u=An(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Du(){var i,e,l,u,f,p;return u=s,f=s,i=it(),i!==null?(p=s,n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e!==null?(l=it(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b=n.substring(s,m)}(u)),i===null&&(s=u),i}function Nu(){var i,e,l,u,f,p,m;if(f=s,i=ee(),i===null)if(p=s,i=er(),i!==null){for(e=[],m=s,l=Re(),l!==null?(u=er(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=Re(),l!==null?(u=er(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S,O;for(O=b.multi_header.length,S=0;S<O;S++)if(b.multi_header[S].parsed===null){b=null;break}b!==null?b=b.multi_header:b=-1}()),i===null&&(s=f),i}function er(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=Bt()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Ws(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Ws(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S;b.multi_header||(b.multi_header=[]);try{S=new Rs(b.uri,b.display_name,b.params),delete b.uri,delete b.display_name,delete b.params}catch{S=null}b.multi_header.push({possition:s,offset:v,parsed:S})}(f)),i===null&&(s=f),i}function Bt(){var i,e,l,u,f;return f=s,i=Gt(),i=i!==null?i:"",i!==null?(e=ke(),e!==null?(l=we(),l!==null?(u=be(),u!==null?i=[i,e,l,u]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i}function Gt(){var i,e,l,u,f,p,m;if(f=s,p=s,i=U(),i!==null){for(e=[],m=s,l=ve(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=ve(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i===null&&(i=Oe()),i!==null&&(i=function(v,S){typeof S=="string"?b.display_name=S:b.display_name=S[1].reduce(function(O,ie){return O+ie[0]+ie[1]},S[0])}(f,i)),i===null&&(s=f),i}function Ws(){var i;return i=tr(),i===null&&(i=$i(),i===null&&(i=Je())),i}function tr(){var i,e,l,u,f;return u=s,f=s,n.substr(s,1).toLowerCase()==="q"?(i=n.substr(s,1),s++):(i=null,h('"q"')),i!==null?(e=G(),e!==null?(l=us(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.params||(b.params={}),b.params.q=m}(u,i[2])),i===null&&(s=u),i}function $i(){var i,e,l,u,f;return u=s,f=s,n.substr(s,7).toLowerCase()==="expires"?(i=n.substr(s,7),s+=7):(i=null,h('"expires"')),i!==null?(e=G(),e!==null?(l=os(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.params||(b.params={}),b.params.expires=m}(u,i[2])),i===null&&(s=u),i}function os(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){return parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function us(){var i,e,l,u,f,p,m,v;return p=s,m=s,n.charCodeAt(s)===48?(i="0",s++):(i=null,h('"0"')),i!==null?(v=s,n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?e=[e,l,u,f]:(e=null,s=v)):(e=null,s=v)):(e=null,s=v)):(e=null,s=v),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(S){return parseFloat(n.substring(s,S))}(p)),i===null&&(s=p),i}function Je(){var i,e,l,u,f,p;return u=s,f=s,i=U(),i!==null?(p=s,e=G(),e!==null?(l=ze(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m,v,S){b.params||(b.params={}),typeof S>"u"?S=void 0:S=S[1],b.params[v.toLowerCase()]=S}(u,i[0],i[1])),i===null&&(s=u),i}function ze(){var i;return i=U(),i===null&&(i=as(),i===null&&(i=Ie())),i}function Da(){var i,e,l,u,f,p;if(f=s,i=Na(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=sr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=sr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Na(){var i;return n.substr(s,6).toLowerCase()==="render"?(i=n.substr(s,6),s+=6):(i=null,h('"render"')),i===null&&(n.substr(s,7).toLowerCase()==="session"?(i=n.substr(s,7),s+=7):(i=null,h('"session"')),i===null&&(n.substr(s,4).toLowerCase()==="icon"?(i=n.substr(s,4),s+=4):(i=null,h('"icon"')),i===null&&(n.substr(s,5).toLowerCase()==="alert"?(i=n.substr(s,5),s+=5):(i=null,h('"alert"')),i===null&&(i=U())))),i}function sr(){var i;return i=nr(),i===null&&(i=Je()),i}function nr(){var i,e,l,u;return u=s,n.substr(s,8).toLowerCase()==="handling"?(i=n.substr(s,8),s+=8):(i=null,h('"handling"')),i!==null?(e=G(),e!==null?(n.substr(s,8).toLowerCase()==="optional"?(l=n.substr(s,8),s+=8):(l=null,h('"optional"')),l===null&&(n.substr(s,8).toLowerCase()==="required"?(l=n.substr(s,8),s+=8):(l=null,h('"required"')),l===null&&(l=U())),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Ua(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Re(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Re(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Uu(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){b=parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function Pu(){var i,e;return e=s,i=Pa(),i!==null&&(i=function(l){b=n.substring(s,l)}(e)),i===null&&(s=e),i}function Pa(){var i,e,l,u,f,p,m,v;if(m=s,i=Hi(),i!==null)if(e=Y(),e!==null)if(l=qi(),l!==null){for(u=[],v=s,f=le(),f!==null?(p=rr(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=le(),f!==null?(p=rr(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i}function Hi(){var i;return i=Fi(),i===null&&(i=ji()),i}function Fi(){var i;return n.substr(s,4).toLowerCase()==="text"?(i=n.substr(s,4),s+=4):(i=null,h('"text"')),i===null&&(n.substr(s,5).toLowerCase()==="image"?(i=n.substr(s,5),s+=5):(i=null,h('"image"')),i===null&&(n.substr(s,5).toLowerCase()==="audio"?(i=n.substr(s,5),s+=5):(i=null,h('"audio"')),i===null&&(n.substr(s,5).toLowerCase()==="video"?(i=n.substr(s,5),s+=5):(i=null,h('"video"')),i===null&&(n.substr(s,11).toLowerCase()==="application"?(i=n.substr(s,11),s+=11):(i=null,h('"application"')),i===null&&(i=Sn()))))),i}function ji(){var i;return n.substr(s,7).toLowerCase()==="message"?(i=n.substr(s,7),s+=7):(i=null,h('"message"')),i===null&&(n.substr(s,9).toLowerCase()==="multipart"?(i=n.substr(s,9),s+=9):(i=null,h('"multipart"')),i===null&&(i=Sn())),i}function Sn(){var i;return i=U(),i===null&&(i=yn()),i}function yn(){var i,e,l;return l=s,n.substr(s,2).toLowerCase()==="x-"?(i=n.substr(s,2),s+=2):(i=null,h('"x-"')),i!==null?(e=U(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function qi(){var i;return i=Sn(),i===null&&(i=U()),i}function rr(){var i,e,l,u;return u=s,i=U(),i!==null?(e=G(),e!==null?(l=ir(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function ir(){var i;return i=U(),i===null&&(i=Ie()),i}function xa(){var i,e,l,u;return u=s,i=ka(),i!==null?(e=ve(),e!==null?(l=vn(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function ka(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){b.value=parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function Ma(){var i,e;return e=s,i=os(),i!==null&&(i=function(l,u){b=u}(e,i)),i===null&&(s=e),i}function xu(){var i,e,l,u,f,p,m;if(f=s,p=s,i=An(),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Je(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Je(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v,S){b.event=S.join("").toLowerCase()}(f,i[0])),i===null&&(s=f),i}function An(){var i,e,l,u,f,p;if(f=s,i=P(),i!==null){for(e=[],p=s,n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?(u=P(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?(u=P(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Cn(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=Bt()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Vi(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Vi(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S=b.tag;try{b=new Rs(b.uri,b.display_name,b.params),S&&b.setParam("tag",S)}catch{b=-1}}()),i===null&&(s=f),i}function Vi(){var i;return i=Rn(),i===null&&(i=Je()),i}function Rn(){var i,e,l,u,f;return u=s,f=s,n.substr(s,3).toLowerCase()==="tag"?(i=n.substr(s,3),s+=3):(i=null,h('"tag"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.tag=m}(u,i[2])),i===null&&(s=u),i}function Bi(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){b=parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function ku(){var i,e;return e=s,i=os(),i!==null&&(i=function(l,u){b=u}(e,i)),i===null&&(s=e),i}function Mu(){var i,e,l,u,f,p,m,v,S,O;for(v=s,S=s,i=[],e=Gt();e!==null;)i.push(e),e=Gt();if(i!==null)if(e=ke(),e!==null)if(l=we(),l!==null)if(u=be(),u!==null){for(f=[],O=s,p=le(),p!==null?(m=Je(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);p!==null;)f.push(p),O=s,p=le(),p!==null?(m=Je(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);f!==null?i=[i,e,l,u,f]:(i=null,s=S)}else i=null,s=S;else i=null,s=S;else i=null,s=S;else i=null,s=S;return i!==null&&(i=function(ie){try{b=new Rs(b.uri,b.display_name,b.params)}catch{b=-1}}()),i===null&&(s=v),i}function Lu(){var i;return i=Gi(),i}function Gi(){var i,e,l,u,f,p,m,v;if(m=s,n.substr(s,6).toLowerCase()==="digest"?(i=n.substr(s,6),s+=6):(i=null,h('"Digest"')),i!==null)if(e=ve(),e!==null)if(l=cs(),l!==null){for(u=[],v=s,f=Re(),f!==null?(p=cs(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=Re(),f!==null?(p=cs(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i===null&&(i=lr()),i}function lr(){var i,e,l,u,f,p,m,v;if(m=s,i=U(),i!==null)if(e=ve(),e!==null)if(l=Ks(),l!==null){for(u=[],v=s,f=Re(),f!==null?(p=Ks(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=Re(),f!==null?(p=Ks(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i}function Ks(){var i,e,l,u;return u=s,i=U(),i!==null?(e=G(),e!==null?(l=U(),l===null&&(l=Ie()),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function cs(){var i;return i=In(),i===null&&(i=Ki(),i===null&&(i=wn(),i===null&&(i=Ji(),i===null&&(i=zi(),i===null&&(i=Xi(),i===null&&(i=Qi(),i===null&&(i=Ks()))))))),i}function In(){var i,e,l,u;return u=s,n.substr(s,5).toLowerCase()==="realm"?(i=n.substr(s,5),s+=5):(i=null,h('"realm"')),i!==null?(e=G(),e!==null?(l=Wi(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Wi(){var i,e;return e=s,i=Oe(),i!==null&&(i=function(l,u){b.realm=u}(e,i)),i===null&&(s=e),i}function Ki(){var i,e,l,u,f,p,m,v,S;if(v=s,n.substr(s,6).toLowerCase()==="domain"?(i=n.substr(s,6),s+=6):(i=null,h('"domain"')),i!==null)if(e=G(),e!==null)if(l=lt(),l!==null)if(u=bn(),u!==null){if(f=[],S=s,m=I(),m!==null)for(p=[];m!==null;)p.push(m),m=I();else p=null;for(p!==null?(m=bn(),m!==null?p=[p,m]:(p=null,s=S)):(p=null,s=S);p!==null;){if(f.push(p),S=s,m=I(),m!==null)for(p=[];m!==null;)p.push(m),m=I();else p=null;p!==null?(m=bn(),m!==null?p=[p,m]:(p=null,s=S)):(p=null,s=S)}f!==null?(p=ot(),p!==null?i=[i,e,l,u,f,p]:(i=null,s=v)):(i=null,s=v)}else i=null,s=v;else i=null,s=v;else i=null,s=v;else i=null,s=v;return i}function bn(){var i;return i=zn(),i===null&&(i=mn()),i}function wn(){var i,e,l,u;return u=s,n.substr(s,5).toLowerCase()==="nonce"?(i=n.substr(s,5),s+=5):(i=null,h('"nonce"')),i!==null?(e=G(),e!==null?(l=Yi(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Yi(){var i,e;return e=s,i=Oe(),i!==null&&(i=function(l,u){b.nonce=u}(e,i)),i===null&&(s=e),i}function Ji(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6).toLowerCase()==="opaque"?(i=n.substr(s,6),s+=6):(i=null,h('"opaque"')),i!==null?(e=G(),e!==null?(l=Oe(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.opaque=m}(u,i[2])),i===null&&(s=u),i}function zi(){var i,e,l,u,f;return u=s,n.substr(s,5).toLowerCase()==="stale"?(i=n.substr(s,5),s+=5):(i=null,h('"stale"')),i!==null?(e=G(),e!==null?(f=s,n.substr(s,4).toLowerCase()==="true"?(l=n.substr(s,4),s+=4):(l=null,h('"true"')),l!==null&&(l=function(p){b.stale=!0}()),l===null&&(s=f),l===null&&(f=s,n.substr(s,5).toLowerCase()==="false"?(l=n.substr(s,5),s+=5):(l=null,h('"false"')),l!==null&&(l=function(p){b.stale=!1}()),l===null&&(s=f)),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Xi(){var i,e,l,u,f;return u=s,f=s,n.substr(s,9).toLowerCase()==="algorithm"?(i=n.substr(s,9),s+=9):(i=null,h('"algorithm"')),i!==null?(e=G(),e!==null?(n.substr(s,3).toLowerCase()==="md5"?(l=n.substr(s,3),s+=3):(l=null,h('"MD5"')),l===null&&(n.substr(s,8).toLowerCase()==="md5-sess"?(l=n.substr(s,8),s+=8):(l=null,h('"MD5-sess"')),l===null&&(l=U())),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.algorithm=m.toUpperCase()}(u,i[2])),i===null&&(s=u),i}function Qi(){var i,e,l,u,f,p,m,v,S,O;if(v=s,n.substr(s,3).toLowerCase()==="qop"?(i=n.substr(s,3),s+=3):(i=null,h('"qop"')),i!==null)if(e=G(),e!==null)if(l=lt(),l!==null){if(S=s,u=On(),u!==null){for(f=[],O=s,n.charCodeAt(s)===44?(p=",",s++):(p=null,h('","')),p!==null?(m=On(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);p!==null;)f.push(p),O=s,n.charCodeAt(s)===44?(p=",",s++):(p=null,h('","')),p!==null?(m=On(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);f!==null?u=[u,f]:(u=null,s=S)}else u=null,s=S;u!==null?(f=ot(),f!==null?i=[i,e,l,u,f]:(i=null,s=v)):(i=null,s=v)}else i=null,s=v;else i=null,s=v;else i=null,s=v;return i}function On(){var i,e;return e=s,n.substr(s,8).toLowerCase()==="auth-int"?(i=n.substr(s,8),s+=8):(i=null,h('"auth-int"')),i===null&&(n.substr(s,4).toLowerCase()==="auth"?(i=n.substr(s,4),s+=4):(i=null,h('"auth"')),i===null&&(i=U())),i!==null&&(i=function(l,u){b.qop||(b.qop=[]),b.qop.push(u.toLowerCase())}(e,i)),i===null&&(s=e),i}function ar(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Re(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Re(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function $u(){var i,e,l,u,f,p,m;if(f=s,p=s,i=or(),i!==null){for(e=[],m=s,l=Re(),l!==null?(u=or(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=Re(),l!==null?(u=or(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S,O;for(O=b.multi_header.length,S=0;S<O;S++)if(b.multi_header[S].parsed===null){b=null;break}b!==null?b=b.multi_header:b=-1}()),i===null&&(s=f),i}function or(){var i,e,l,u,f,p,m;if(f=s,p=s,i=Bt(),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Je(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Je(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S;b.multi_header||(b.multi_header=[]);try{S=new Rs(b.uri,b.display_name,b.params),delete b.uri,delete b.display_name,delete b.params}catch{S=null}b.multi_header.push({possition:s,offset:v,parsed:S})}(f)),i===null&&(s=f),i}function ur(){var i,e,l,u,f,p,m;if(f=s,p=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"SIP"')),i===null&&(i=U()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Zi(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Zi(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v,S){if(b.protocol=S.toLowerCase(),b.params||(b.params={}),b.params.text&&b.params.text[0]==='"'){var O=b.params.text;b.text=O.substring(1,O.length-1),delete b.params.text}}(f,i[0])),i===null&&(s=f),i}function Zi(){var i;return i=cr(),i===null&&(i=Je()),i}function cr(){var i,e,l,u,f,p;if(f=s,p=s,n.substr(s,5).toLowerCase()==="cause"?(i=n.substr(s,5),s+=5):(i=null,h('"cause"')),i!==null)if(e=G(),e!==null){if(u=g(),u!==null)for(l=[];u!==null;)l.push(u),u=g();else l=null;l!==null?i=[i,e,l]:(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i!==null&&(i=function(m,v){b.cause=parseInt(v.join(""))}(f,i[2])),i===null&&(s=f),i}function La(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Re(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Re(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Hu(){var i,e,l,u,f,p;if(f=s,i=fr(),i!==null){for(e=[],p=s,l=Re(),l!==null?(u=fr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Re(),l!==null?(u=fr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function fr(){var i,e,l,u,f,p;if(f=s,i=Bt(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=Je(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=Je(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function hr(){var i,e,l,u,f,p;if(f=s,i=$a(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=dr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=dr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function $a(){var i,e;return e=s,n.substr(s,6).toLowerCase()==="active"?(i=n.substr(s,6),s+=6):(i=null,h('"active"')),i===null&&(n.substr(s,7).toLowerCase()==="pending"?(i=n.substr(s,7),s+=7):(i=null,h('"pending"')),i===null&&(n.substr(s,10).toLowerCase()==="terminated"?(i=n.substr(s,10),s+=10):(i=null,h('"terminated"')),i===null&&(i=U()))),i!==null&&(i=function(l){b.state=n.substring(s,l)}(e)),i===null&&(s=e),i}function dr(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6).toLowerCase()==="reason"?(i=n.substr(s,6),s+=6):(i=null,h('"reason"')),i!==null?(e=G(),e!==null?(l=_r(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){typeof m<"u"&&(b.reason=m)}(u,i[2])),i===null&&(s=u),i===null&&(u=s,f=s,n.substr(s,7).toLowerCase()==="expires"?(i=n.substr(s,7),s+=7):(i=null,h('"expires"')),i!==null?(e=G(),e!==null?(l=os(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){typeof m<"u"&&(b.expires=m)}(u,i[2])),i===null&&(s=u),i===null&&(u=s,f=s,n.substr(s,11).toLowerCase()==="retry_after"?(i=n.substr(s,11),s+=11):(i=null,h('"retry_after"')),i!==null?(e=G(),e!==null?(l=os(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){typeof m<"u"&&(b.retry_after=m)}(u,i[2])),i===null&&(s=u),i===null&&(i=Je()))),i}function _r(){var i;return n.substr(s,11).toLowerCase()==="deactivated"?(i=n.substr(s,11),s+=11):(i=null,h('"deactivated"')),i===null&&(n.substr(s,9).toLowerCase()==="probation"?(i=n.substr(s,9),s+=9):(i=null,h('"probation"')),i===null&&(n.substr(s,8).toLowerCase()==="rejected"?(i=n.substr(s,8),s+=8):(i=null,h('"rejected"')),i===null&&(n.substr(s,7).toLowerCase()==="timeout"?(i=n.substr(s,7),s+=7):(i=null,h('"timeout"')),i===null&&(n.substr(s,6).toLowerCase()==="giveup"?(i=n.substr(s,6),s+=6):(i=null,h('"giveup"')),i===null&&(n.substr(s,10).toLowerCase()==="noresource"?(i=n.substr(s,10),s+=10):(i=null,h('"noresource"')),i===null&&(n.substr(s,9).toLowerCase()==="invariant"?(i=n.substr(s,9),s+=9):(i=null,h('"invariant"')),i===null&&(i=U()))))))),i}function Ha(){var i;return i=B(),i=i!==null?i:"",i}function Fu(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Re(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Re(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i=i!==null?i:"",i}function ju(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=Bt()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=el(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=el(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S=b.tag;try{b=new Rs(b.uri,b.display_name,b.params),S&&b.setParam("tag",S)}catch{b=-1}}()),i===null&&(s=f),i}function el(){var i;return i=Rn(),i===null&&(i=Je()),i}function tl(){var i,e,l,u,f,p;if(f=s,i=pr(),i!==null){for(e=[],p=s,l=Re(),l!==null?(u=pr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Re(),l!==null?(u=pr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function pr(){var i,e,l,u,f,p,m,v;if(m=s,i=al(),i!==null)if(e=ve(),e!==null)if(l=cl(),l!==null){for(u=[],v=s,f=le(),f!==null?(p=Ys(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=le(),f!==null?(p=Ys(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i}function Ys(){var i;return i=mr(),i===null&&(i=sl(),i===null&&(i=nl(),i===null&&(i=rl(),i===null&&(i=il(),i===null&&(i=Je()))))),i}function mr(){var i,e,l,u,f;return u=s,f=s,n.substr(s,3).toLowerCase()==="ttl"?(i=n.substr(s,3),s+=3):(i=null,h('"ttl"')),i!==null?(e=G(),e!==null?(l=gr(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.ttl=m}(u,i[2])),i===null&&(s=u),i}function sl(){var i,e,l,u,f;return u=s,f=s,n.substr(s,5).toLowerCase()==="maddr"?(i=n.substr(s,5),s+=5):(i=null,h('"maddr"')),i!==null?(e=G(),e!==null?(l=as(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.maddr=m}(u,i[2])),i===null&&(s=u),i}function nl(){var i,e,l,u,f;return u=s,f=s,n.substr(s,8).toLowerCase()==="received"?(i=n.substr(s,8),s+=8):(i=null,h('"received"')),i!==null?(e=G(),e!==null?(l=ut(),l===null&&(l=hn()),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.received=m}(u,i[2])),i===null&&(s=u),i}function rl(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6).toLowerCase()==="branch"?(i=n.substr(s,6),s+=6):(i=null,h('"branch"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.branch=m}(u,i[2])),i===null&&(s=u),i}function il(){var i,e,l,u,f;return u=s,n.substr(s,5).toLowerCase()==="rport"?(i=n.substr(s,5),s+=5):(i=null,h('"rport"')),i!==null?(f=s,e=G(),e!==null?(l=ll(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function ll(){var i,e,l,u,f,p,m;return p=s,m=s,i=g(),i=i!==null?i:"",i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?i=[i,e,l,u,f]:(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(v,S){b.rport=parseInt(S.join(""))}(p,i)),i===null&&(s=p),i}function al(){var i,e,l,u,f,p;return p=s,i=ol(),i!==null?(e=Y(),e!==null?(l=U(),l!==null?(u=Y(),u!==null?(f=ul(),f!==null?i=[i,e,l,u,f]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i}function ol(){var i,e;return e=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"SIP"')),i===null&&(i=U()),i!==null&&(i=function(l,u){b.protocol=u}(e,i)),i===null&&(s=e),i}function ul(){var i,e;return e=s,n.substr(s,3).toLowerCase()==="udp"?(i=n.substr(s,3),s+=3):(i=null,h('"UDP"')),i===null&&(n.substr(s,3).toLowerCase()==="tcp"?(i=n.substr(s,3),s+=3):(i=null,h('"TCP"')),i===null&&(n.substr(s,3).toLowerCase()==="tls"?(i=n.substr(s,3),s+=3):(i=null,h('"TLS"')),i===null&&(n.substr(s,4).toLowerCase()==="sctp"?(i=n.substr(s,4),s+=4):(i=null,h('"SCTP"')),i===null&&(i=U())))),i!==null&&(i=function(l,u){b.transport=u}(e,i)),i===null&&(s=e),i}function cl(){var i,e,l,u,f;return u=s,i=fl(),i!==null?(f=s,e=ye(),e!==null?(l=hl(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function fl(){var i,e;return e=s,i=ut(),i===null&&(i=Kn(),i===null&&(i=As())),i!==null&&(i=function(l){b.host=n.substring(s,l)}(e)),i===null&&(s=e),i}function hl(){var i,e,l,u,f,p,m;return p=s,m=s,i=g(),i=i!==null?i:"",i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?i=[i,e,l,u,f]:(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(v,S){b.port=parseInt(S.join(""))}(p,i)),i===null&&(s=p),i}function gr(){var i,e,l,u,f;return u=s,f=s,i=g(),i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){return parseInt(m.join(""))}(u,i)),i===null&&(s=u),i}function dl(){var i;return i=Gi(),i}function qu(){var i,e,l,u,f,p;if(f=s,i=Fa(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=Tr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=Tr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Fa(){var i,e;return e=s,i=os(),i!==null&&(i=function(l,u){b.expires=u}(e,i)),i===null&&(s=e),i}function Tr(){var i;return i=vr(),i===null&&(i=Je()),i}function vr(){var i,e,l,u,f;return u=s,f=s,n.substr(s,9).toLowerCase()==="refresher"?(i=n.substr(s,9),s+=9):(i=null,h('"refresher"')),i!==null?(e=G(),e!==null?(n.substr(s,3).toLowerCase()==="uac"?(l=n.substr(s,3),s+=3):(l=null,h('"uac"')),l===null&&(n.substr(s,3).toLowerCase()==="uas"?(l=n.substr(s,3),s+=3):(l=null,h('"uas"'))),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.refresher=m.toLowerCase()}(u,i[2])),i===null&&(s=u),i}function ja(){var i,e,l,u;return u=s,i=U(),i!==null?(e=D(),e!==null?(l=qa(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function qa(){var i,e;for(i=[],e=V(),e===null&&(e=F(),e===null&&(e=ve()));e!==null;)i.push(e),e=V(),e===null&&(e=F(),e===null&&(e=ve()));return i}function Va(){var i,e;for(i=[],e=A();e!==null;)i.push(e),e=A();return i}function Vu(){var i,e,l;return l=s,n.substr(s,5)==="uuid:"?(i="uuid:",s+=5):(i=null,h('"uuid:"')),i!==null?(e=Ba(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function Ba(){var i,e,l,u,f,p,m,v,S,O,ie;return O=s,ie=s,i=Kt(),i!==null?(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e!==null?(l=Wt(),l!==null?(n.charCodeAt(s)===45?(u="-",s++):(u=null,h('"-"')),u!==null?(f=Wt(),f!==null?(n.charCodeAt(s)===45?(p="-",s++):(p=null,h('"-"')),p!==null?(m=Wt(),m!==null?(n.charCodeAt(s)===45?(v="-",s++):(v=null,h('"-"')),v!==null?(S=_l(),S!==null?i=[i,e,l,u,f,p,m,v,S]:(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie),i!==null&&(i=function(Ue,Dt){b=n.substring(s+5,Ue)}(O,i[0])),i===null&&(s=O),i}function Wt(){var i,e,l,u,f;return f=s,i=E(),i!==null?(e=E(),e!==null?(l=E(),l!==null?(u=E(),u!==null?i=[i,e,l,u]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i}function Kt(){var i,e,l;return l=s,i=Wt(),i!==null?(e=Wt(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function _l(){var i,e,l,u;return u=s,i=Wt(),i!==null?(e=Wt(),e!==null?(l=Wt(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Ga(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=Bt()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Je(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Je(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){try{b=new Rs(b.uri,b.display_name,b.params)}catch{b=-1}}()),i===null&&(s=f),i}function Bu(){var i,e,l,u,f,p;if(f=s,i=Wa(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=Er(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=Er(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Wa(){var i,e,l,u,f,p;return u=s,f=s,i=it(),i!==null?(p=s,n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e!==null?(l=it(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b.call_id=n.substring(s,m)}(u)),i===null&&(s=u),i}function Er(){var i;return i=Sr(),i===null&&(i=pl(),i===null&&(i=ml(),i===null&&(i=Je()))),i}function Sr(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6)==="to-tag"?(i="to-tag",s+=6):(i=null,h('"to-tag"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.to_tag=m}(u,i[2])),i===null&&(s=u),i}function pl(){var i,e,l,u,f;return u=s,f=s,n.substr(s,8)==="from-tag"?(i="from-tag",s+=8):(i=null,h('"from-tag"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.from_tag=m}(u,i[2])),i===null&&(s=u),i}function ml(){var i,e;return e=s,n.substr(s,10)==="early-only"?(i="early-only",s+=10):(i=null,h('"early-only"')),i!==null&&(i=function(l){b.early_only=!0}()),i===null&&(s=e),i}function Ka(i){i.sort();for(var e=null,l=[],u=0;u<i.length;u++)i[u]!==e&&(l.push(i[u]),e=i[u]);return l}function Gu(){for(var i=1,e=1,l=!1,u=0;u<Math.max(s,r);u++){var f=n.charAt(u);f===`
|
75
|
-
`?(l||i++,e=1,l=!1):f==="\r"||f==="\u2028"||f==="\u2029"?(i++,e=1,l=!0):(e++,l=!1)}return{line:i,column:e}}var Ya=ps(),Rs=Vo(),b={},w=o[a]();if(w===null||s!==n.length){var gl=Math.max(s,r),Tl=gl<n.length?n.charAt(gl):null,Ja=Gu();return new this.SyntaxError(Ka(d),Tl,gl,Ja.line,Ja.column),-1}return b},toSource:function(){return this._source}};return t.SyntaxError=function(n,a,o,s,r){function d(h,_){var g,T;switch(h.length){case 0:g="end of input";break;case 1:g=h[0];break;default:g=h.slice(0,h.length-1).join(", ")+" or "+h[h.length-1]}return T=_?c(_):"end of input","Expected "+g+" but "+T+" found."}this.name="SyntaxError",this.expected=n,this.found=a,this.message=d(n,a),this.offset=o,this.line=s,this.column=r},t.SyntaxError.prototype=Error.prototype,t}()),Bo}var Go,If;function ps(){if(If)return Go;If=1;const c=De,t=mt(),n=Jt();return Go=class Hh{static parse(o){if(o=n.parse(o,"SIP_URI"),o!==-1)return o}constructor(o,s,r,d,h={},_={}){if(!r)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=o||c.SIP,this._user=s,this._host=r,this._port=d;for(const g in h)Object.prototype.hasOwnProperty.call(h,g)&&this.setParam(g,h[g]);for(const g in _)Object.prototype.hasOwnProperty.call(_,g)&&this.setHeader(g,_[g])}get scheme(){return this._scheme}set scheme(o){this._scheme=o.toLowerCase()}get user(){return this._user}set user(o){this._user=o}get host(){return this._host}set host(o){this._host=o.toLowerCase()}get port(){return this._port}set port(o){this._port=o===0?o:parseInt(o,10)||null}setParam(o,s){o&&(this._parameters[o.toLowerCase()]=typeof s>"u"||s===null?null:s.toString())}getParam(o){if(o)return this._parameters[o.toLowerCase()]}hasParam(o){if(o)return this._parameters.hasOwnProperty(o.toLowerCase())&&!0||!1}deleteParam(o){if(o=o.toLowerCase(),this._parameters.hasOwnProperty(o)){const s=this._parameters[o];return delete this._parameters[o],s}}clearParams(){this._parameters={}}setHeader(o,s){this._headers[t.headerize(o)]=Array.isArray(s)?s:[s]}getHeader(o){if(o)return this._headers[t.headerize(o)]}hasHeader(o){if(o)return this._headers.hasOwnProperty(t.headerize(o))&&!0||!1}deleteHeader(o){if(o=t.headerize(o),this._headers.hasOwnProperty(o)){const s=this._headers[o];return delete this._headers[o],s}}clearHeaders(){this._headers={}}clone(){return new Hh(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}toString(){const o=[];let s=`${this._scheme}:`;this._user&&(s+=`${t.escapeUser(this._user)}@`),s+=this._host,(this._port||this._port===0)&&(s+=`:${this._port}`);for(const r in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,r)&&(s+=`;${r}`,this._parameters[r]!==null&&(s+=`=${this._parameters[r]}`));for(const r in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,r))for(const d of this._headers[r])o.push(`${r}=${d}`);return o.length>0&&(s+=`?${o.join("&")}`),s}toAor(o){let s=`${this._scheme}:`;return this._user&&(s+=`${t.escapeUser(this._user)}@`),s+=this._host,o&&(this._port||this._port===0)&&(s+=`:${this._port}`),s}},Go}var bf;function mt(){if(bf)return Ze;bf=1;const c=De,t=ps(),n=Jt();Ze.str_utf8_length=r=>unescape(encodeURIComponent(r)).length;const a=Ze.isFunction=r=>r!==void 0?Object.prototype.toString.call(r)==="[object Function]":!1;Ze.isString=r=>r!==void 0?Object.prototype.toString.call(r)==="[object String]":!1,Ze.isDecimal=r=>!isNaN(r)&&parseFloat(r)===parseInt(r,10),Ze.isEmpty=r=>r===null||r===""||r===void 0||Array.isArray(r)&&r.length===0||typeof r=="number"&&isNaN(r),Ze.hasMethods=function(r,...d){for(const h of d)if(a(r[h]))return!1;return!0};const o=Ze.createRandomToken=(r,d=32)=>{let h,_,g="";for(h=0;h<r;h++)_=Math.random()*d|0,g+=_.toString(d);return g};Ze.newTag=()=>o(10),Ze.newUUID=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,d=>{const h=Math.random()*16|0;return(d==="x"?h:h&3|8).toString(16)}),Ze.hostType=r=>{if(r){if(r=n.parse(r,"host"),r!==-1)return r.host_type}else return};const s=Ze.escapeUser=r=>encodeURIComponent(decodeURIComponent(r)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/");return Ze.normalizeTarget=(r,d)=>{if(r){if(r instanceof t)return r;if(typeof r=="string"){const h=r.split("@");let _,g;switch(h.length){case 1:if(!d)return;_=r,g=d;break;case 2:_=h[0],g=h[1];break;default:_=h.slice(0,h.length-1).join("@"),g=h[h.length-1]}_=_.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(_)&&(_=_.replace(/[-.()]/g,"")),r=`${c.SIP}:${s(_)}@${g}`;let T;return(T=t.parse(r))?T:void 0}else return}else return},Ze.headerize=r=>{const d={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},h=r.toLowerCase().replace(/_/g,"-").split("-");let _="";const g=h.length;let T;for(T=0;T<g;T++)T!==0&&(_+="-"),_+=h[T].charAt(0).toUpperCase()+h[T].substring(1);return d[_]&&(_=d[_]),_},Ze.sipErrorCause=r=>{for(const d in c.SIP_ERROR_CAUSES)if(c.SIP_ERROR_CAUSES[d].indexOf(r)!==-1)return c.causes[d];return c.causes.SIP_FAILURE_CODE},Ze.getRandomTestNetIP=()=>{function r(d,h){return Math.floor(Math.random()*(h-d+1)+d)}return`192.0.2.${r(1,254)}`},Ze.calculateMD5=r=>{function d(Ee,Ae){return Ee<<Ae|Ee>>>32-Ae}function h(Ee,Ae){const Ie=Ee&2147483648,Oe=Ae&2147483648,pe=Ee&1073741824,de=Ae&1073741824,_e=(Ee&1073741823)+(Ae&1073741823);return pe&de?_e^2147483648^Ie^Oe:pe|de?_e&1073741824?_e^3221225472^Ie^Oe:_e^1073741824^Ie^Oe:_e^Ie^Oe}function _(Ee,Ae,Ie){return Ee&Ae|~Ee&Ie}function g(Ee,Ae,Ie){return Ee&Ie|Ae&~Ie}function T(Ee,Ae,Ie){return Ee^Ae^Ie}function E(Ee,Ae,Ie){return Ae^(Ee|~Ie)}function y(Ee,Ae,Ie,Oe,pe,de,_e){return Ee=h(Ee,h(h(_(Ae,Ie,Oe),pe),_e)),h(d(Ee,de),Ae)}function A(Ee,Ae,Ie,Oe,pe,de,_e){return Ee=h(Ee,h(h(g(Ae,Ie,Oe),pe),_e)),h(d(Ee,de),Ae)}function C(Ee,Ae,Ie,Oe,pe,de,_e){return Ee=h(Ee,h(h(T(Ae,Ie,Oe),pe),_e)),h(d(Ee,de),Ae)}function I(Ee,Ae,Ie,Oe,pe,de,_e){return Ee=h(Ee,h(h(E(Ae,Ie,Oe),pe),_e)),h(d(Ee,de),Ae)}function H(Ee){let Ae;const Ie=Ee.length,Oe=Ie+8,de=((Oe-Oe%64)/64+1)*16,_e=new Array(de-1);let we=0,Ne=0;for(;Ne<Ie;)Ae=(Ne-Ne%4)/4,we=Ne%4*8,_e[Ae]=_e[Ae]|Ee.charCodeAt(Ne)<<we,Ne++;return Ae=(Ne-Ne%4)/4,we=Ne%4*8,_e[Ae]=_e[Ae]|128<<we,_e[de-2]=Ie<<3,_e[de-1]=Ie>>>29,_e}function $(Ee){let Ae="",Ie="",Oe,pe;for(pe=0;pe<=3;pe++)Oe=Ee>>>pe*8&255,Ie=`0${Oe.toString(16)}`,Ae=Ae+Ie.substr(Ie.length-2,2);return Ae}function oe(Ee){let Ae="";for(let Ie=0;Ie<Ee.length;Ie++){const Oe=Ee.charCodeAt(Ie);Oe<128?Ae+=String.fromCharCode(Oe):Oe>127&&Oe<2048?(Ae+=String.fromCharCode(Oe>>6|192),Ae+=String.fromCharCode(Oe&63|128)):(Ae+=String.fromCharCode(Oe>>12|224),Ae+=String.fromCharCode(Oe>>6&63|128),Ae+=String.fromCharCode(Oe&63|128))}return Ae}let N=[],j,Se,ve,k,D,B,V,J,F;const Z=7,U=12,P=17,se=22,it=5,ee=9,Y=14,G=20,re=4,ge=11,be=16,ke=23,Re=6,le=10,ye=15,lt=21;for(r=oe(r),N=H(r),B=1732584193,V=4023233417,J=2562383102,F=271733878,j=0;j<N.length;j+=16)Se=B,ve=V,k=J,D=F,B=y(B,V,J,F,N[j+0],Z,3614090360),F=y(F,B,V,J,N[j+1],U,3905402710),J=y(J,F,B,V,N[j+2],P,606105819),V=y(V,J,F,B,N[j+3],se,3250441966),B=y(B,V,J,F,N[j+4],Z,4118548399),F=y(F,B,V,J,N[j+5],U,1200080426),J=y(J,F,B,V,N[j+6],P,2821735955),V=y(V,J,F,B,N[j+7],se,4249261313),B=y(B,V,J,F,N[j+8],Z,1770035416),F=y(F,B,V,J,N[j+9],U,2336552879),J=y(J,F,B,V,N[j+10],P,4294925233),V=y(V,J,F,B,N[j+11],se,2304563134),B=y(B,V,J,F,N[j+12],Z,1804603682),F=y(F,B,V,J,N[j+13],U,4254626195),J=y(J,F,B,V,N[j+14],P,2792965006),V=y(V,J,F,B,N[j+15],se,1236535329),B=A(B,V,J,F,N[j+1],it,4129170786),F=A(F,B,V,J,N[j+6],ee,3225465664),J=A(J,F,B,V,N[j+11],Y,643717713),V=A(V,J,F,B,N[j+0],G,3921069994),B=A(B,V,J,F,N[j+5],it,3593408605),F=A(F,B,V,J,N[j+10],ee,38016083),J=A(J,F,B,V,N[j+15],Y,3634488961),V=A(V,J,F,B,N[j+4],G,3889429448),B=A(B,V,J,F,N[j+9],it,568446438),F=A(F,B,V,J,N[j+14],ee,3275163606),J=A(J,F,B,V,N[j+3],Y,4107603335),V=A(V,J,F,B,N[j+8],G,1163531501),B=A(B,V,J,F,N[j+13],it,2850285829),F=A(F,B,V,J,N[j+2],ee,4243563512),J=A(J,F,B,V,N[j+7],Y,1735328473),V=A(V,J,F,B,N[j+12],G,2368359562),B=C(B,V,J,F,N[j+5],re,4294588738),F=C(F,B,V,J,N[j+8],ge,2272392833),J=C(J,F,B,V,N[j+11],be,1839030562),V=C(V,J,F,B,N[j+14],ke,4259657740),B=C(B,V,J,F,N[j+1],re,2763975236),F=C(F,B,V,J,N[j+4],ge,1272893353),J=C(J,F,B,V,N[j+7],be,4139469664),V=C(V,J,F,B,N[j+10],ke,3200236656),B=C(B,V,J,F,N[j+13],re,681279174),F=C(F,B,V,J,N[j+0],ge,3936430074),J=C(J,F,B,V,N[j+3],be,3572445317),V=C(V,J,F,B,N[j+6],ke,76029189),B=C(B,V,J,F,N[j+9],re,3654602809),F=C(F,B,V,J,N[j+12],ge,3873151461),J=C(J,F,B,V,N[j+15],be,530742520),V=C(V,J,F,B,N[j+2],ke,3299628645),B=I(B,V,J,F,N[j+0],Re,4096336452),F=I(F,B,V,J,N[j+7],le,1126891415),J=I(J,F,B,V,N[j+14],ye,2878612391),V=I(V,J,F,B,N[j+5],lt,4237533241),B=I(B,V,J,F,N[j+12],Re,1700485571),F=I(F,B,V,J,N[j+3],le,2399980690),J=I(J,F,B,V,N[j+10],ye,4293915773),V=I(V,J,F,B,N[j+1],lt,2240044497),B=I(B,V,J,F,N[j+8],Re,1873313359),F=I(F,B,V,J,N[j+15],le,4264355552),J=I(J,F,B,V,N[j+6],ye,2734768916),V=I(V,J,F,B,N[j+13],lt,1309151649),B=I(B,V,J,F,N[j+4],Re,4149444226),F=I(F,B,V,J,N[j+11],le,3174756917),J=I(J,F,B,V,N[j+2],ye,718787259),V=I(V,J,F,B,N[j+9],lt,3951481745),B=h(B,Se),V=h(V,ve),J=h(J,k),F=h(F,D);return($(B)+$(V)+$(J)+$(F)).toLowerCase()},Ze.closeMediaStream=r=>{if(r)try{let d;if(r.getTracks){d=r.getTracks();for(const h of d)h.stop()}else{d=r.getAudioTracks();for(const h of d)h.stop();d=r.getVideoTracks();for(const h of d)h.stop()}}catch{(typeof r.stop=="function"||typeof r.stop=="object")&&r.stop()}},Ze.cloneArray=r=>r&&r.slice()||[],Ze.cloneObject=(r,d={})=>r&&Object.assign({},r)||d,Ze}const wf=Ut,Rm=at,gt=De,rt=mt(),Of=Vo(),Im=Jt(),Wo=new Rm("SIPMessage");class ia{constructor(t,n,a,o,s,r){if(!t||!n||!a)return null;o=o||{},this.ua=a,this.headers={},this.method=t,this.ruri=n,this.body=r,this.extraHeaders=rt.cloneArray(s),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),o.route_set?this.setHeader("route",o.route_set):a.configuration.use_preloaded_route&&this.setHeader("route",`<${a.transport.sip_uri};lr>`),this.setHeader("via",""),this.setHeader("max-forwards",gt.MAX_FORWARDS);const d=o.to_uri||n,h=o.to_tag?{tag:o.to_tag}:null,_=typeof o.to_display_name<"u"?o.to_display_name:null;this.to=new Of(d,_,h),this.setHeader("to",this.to.toString());const g=o.from_uri||a.configuration.uri,T={tag:o.from_tag||rt.newTag()};let E;typeof o.from_display_name<"u"?E=o.from_display_name:a.configuration.display_name?E=a.configuration.display_name:E=null,this.from=new Of(g,E,T),this.setHeader("from",this.from.toString());const y=o.call_id||a.configuration.jssip_id+rt.createRandomToken(15);this.call_id=y,this.setHeader("call-id",y);const A=o.cseq||Math.floor(Math.random()*1e4);this.cseq=A,this.setHeader("cseq",`${A} ${t}`)}setHeader(t,n){const a=new RegExp(`^\\s*${t}\\s*:`,"i");for(let o=0;o<this.extraHeaders.length;o++)a.test(this.extraHeaders[o])&&this.extraHeaders.splice(o,1);this.headers[rt.headerize(t)]=Array.isArray(n)?n:[n]}getHeader(t){const n=this.headers[rt.headerize(t)];if(n){if(n[0])return n[0]}else{const a=new RegExp(`^\\s*${t}\\s*:`,"i");for(const o of this.extraHeaders)if(a.test(o))return o.substring(o.indexOf(":")+1).trim()}}getHeaders(t){const n=this.headers[rt.headerize(t)],a=[];if(n){for(const o of n)a.push(o);return a}else{const o=new RegExp(`^\\s*${t}\\s*:`,"i");for(const s of this.extraHeaders)o.test(s)&&a.push(s.substring(s.indexOf(":")+1).trim());return a}}hasHeader(t){if(this.headers[rt.headerize(t)])return!0;{const n=new RegExp(`^\\s*${t}\\s*:`,"i");for(const a of this.extraHeaders)if(n.test(a))return!0}return!1}parseSDP(t){return!t&&this.sdp?this.sdp:(this.sdp=wf.parse(this.body||""),this.sdp)}toString(){let t=`${this.method} ${this.ruri} SIP/2.0\r
|
74
|
+
`,s+=2):(i=null,h('"\\r\\n"')),i}function g(){var i;return/^[0-9]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[0-9]")),i}function T(){var i;return/^[a-zA-Z]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[a-zA-Z]")),i}function E(){var i;return/^[0-9a-fA-F]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[0-9a-fA-F]")),i}function y(){var i;return i=I(),i===null&&(i=H()),i}function C(){var i;return/^[\0-\xFF]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\0-\\xFF]")),i}function A(){var i;return/^["]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h('["]')),i}function I(){var i;return n.charCodeAt(s)===32?(i=" ",s++):(i=null,h('" "')),i}function H(){var i;return n.charCodeAt(s)===9?(i=" ",s++):(i=null,h('"\\t"')),i}function $(){var i;return/^[a-zA-Z0-9]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[a-zA-Z0-9]")),i}function oe(){var i;return n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","'))))))))))),i}function N(){var i;return i=$(),i===null&&(i=j()),i}function j(){var i;return n.charCodeAt(s)===45?(i="-",s++):(i=null,h('"-"')),i===null&&(n.charCodeAt(s)===95?(i="_",s++):(i=null,h('"_"')),i===null&&(n.charCodeAt(s)===46?(i=".",s++):(i=null,h('"."')),i===null&&(n.charCodeAt(s)===33?(i="!",s++):(i=null,h('"!"')),i===null&&(n.charCodeAt(s)===126?(i="~",s++):(i=null,h('"~"')),i===null&&(n.charCodeAt(s)===42?(i="*",s++):(i=null,h('"*"')),i===null&&(n.charCodeAt(s)===39?(i="'",s++):(i=null,h(`"'"`)),i===null&&(n.charCodeAt(s)===40?(i="(",s++):(i=null,h('"("')),i===null&&(n.charCodeAt(s)===41?(i=")",s++):(i=null,h('")"')))))))))),i}function Se(){var i,e,l,u,f;return u=s,f=s,n.charCodeAt(s)===37?(i="%",s++):(i=null,h('"%"')),i!==null?(e=E(),e!==null?(l=E(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){return m.join("")}(u,i)),i===null&&(s=u),i}function ve(){var i,e,l,u,f,p;for(u=s,f=s,p=s,i=[],e=y();e!==null;)i.push(e),e=y();if(i!==null?(e=_(),e!==null?i=[i,e]:(i=null,s=p)):(i=null,s=p),i=i!==null?i:"",i!==null){if(l=y(),l!==null)for(e=[];l!==null;)e.push(l),l=y();else e=null;e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i!==null&&(i=function(m){return" "}()),i===null&&(s=u),i}function k(){var i;return i=ve(),i=i!==null?i:"",i}function D(){var i,e,l,u,f;for(u=s,f=s,i=[],e=I(),e===null&&(e=H());e!==null;)i.push(e),e=I(),e===null&&(e=H());return i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return":"}()),i===null&&(s=u),i}function B(){var i,e,l,u,f,p,m;if(f=s,p=s,e=V(),e!==null)for(i=[];e!==null;)i.push(e),e=V();else i=null;if(i!==null){for(e=[],m=s,l=[],u=ve();u!==null;)l.push(u),u=ve();for(l!==null?(u=V(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;){for(e.push(l),m=s,l=[],u=ve();u!==null;)l.push(u),u=ve();l!==null?(u=V(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m)}e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){return n.substring(s,v)}(f)),i===null&&(s=f),i}function V(){var i;return/^[!-~]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[!-~]")),i===null&&(i=J()),i}function J(){var i;return/^[\x80-\uFFFF]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\x80-\\uFFFF]")),i}function F(){var i;return/^[\x80-\xBF]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\x80-\\xBF]")),i}function Z(){var i;return i=g(),i===null&&(/^[a-f]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[a-f]"))),i}function U(){var i,e,l;if(l=s,e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"'))))))))))));else i=null;return i!==null&&(i=function(u){return n.substring(s,u)}(l)),i===null&&(s=l),i}function P(){var i,e,l;if(l=s,e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"'))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')))))))))));else i=null;return i!==null&&(i=function(u){return n.substring(s,u)}(l)),i===null&&(s=l),i}function se(){var i;return n.charCodeAt(s)===40?(i="(",s++):(i=null,h('"("')),i===null&&(n.charCodeAt(s)===41?(i=")",s++):(i=null,h('")"')),i===null&&(n.charCodeAt(s)===60?(i="<",s++):(i=null,h('"<"')),i===null&&(n.charCodeAt(s)===62?(i=">",s++):(i=null,h('">"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===92?(i="\\",s++):(i=null,h('"\\\\"')),i===null&&(i=A(),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i===null&&(n.charCodeAt(s)===93?(i="]",s++):(i=null,h('"]"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===123?(i="{",s++):(i=null,h('"{"')),i===null&&(n.charCodeAt(s)===125?(i="}",s++):(i=null,h('"}"')),i===null&&(i=I(),i===null&&(i=H())))))))))))))))))),i}function it(){var i,e,l;if(l=s,e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')),e===null&&(n.charCodeAt(s)===40?(e="(",s++):(e=null,h('"("')),e===null&&(n.charCodeAt(s)===41?(e=")",s++):(e=null,h('")"')),e===null&&(n.charCodeAt(s)===60?(e="<",s++):(e=null,h('"<"')),e===null&&(n.charCodeAt(s)===62?(e=">",s++):(e=null,h('">"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===92?(e="\\",s++):(e=null,h('"\\\\"')),e===null&&(e=A(),e===null&&(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e===null&&(n.charCodeAt(s)===91?(e="[",s++):(e=null,h('"["')),e===null&&(n.charCodeAt(s)===93?(e="]",s++):(e=null,h('"]"')),e===null&&(n.charCodeAt(s)===63?(e="?",s++):(e=null,h('"?"')),e===null&&(n.charCodeAt(s)===123?(e="{",s++):(e=null,h('"{"')),e===null&&(n.charCodeAt(s)===125?(e="}",s++):(e=null,h('"}"'))))))))))))))))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')),e===null&&(n.charCodeAt(s)===40?(e="(",s++):(e=null,h('"("')),e===null&&(n.charCodeAt(s)===41?(e=")",s++):(e=null,h('")"')),e===null&&(n.charCodeAt(s)===60?(e="<",s++):(e=null,h('"<"')),e===null&&(n.charCodeAt(s)===62?(e=">",s++):(e=null,h('">"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===92?(e="\\",s++):(e=null,h('"\\\\"')),e===null&&(e=A(),e===null&&(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e===null&&(n.charCodeAt(s)===91?(e="[",s++):(e=null,h('"["')),e===null&&(n.charCodeAt(s)===93?(e="]",s++):(e=null,h('"]"')),e===null&&(n.charCodeAt(s)===63?(e="?",s++):(e=null,h('"?"')),e===null&&(n.charCodeAt(s)===123?(e="{",s++):(e=null,h('"{"')),e===null&&(n.charCodeAt(s)===125?(e="}",s++):(e=null,h('"}"')))))))))))))))))))))))));else i=null;return i!==null&&(i=function(u){return n.substring(s,u)}(l)),i===null&&(s=l),i}function ee(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"*"}()),i===null&&(s=u),i}function Y(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"/"}()),i===null&&(s=u),i}function G(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"="}()),i===null&&(s=u),i}function re(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===40?(e="(",s++):(e=null,h('"("')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"("}()),i===null&&(s=u),i}function ge(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===41?(e=")",s++):(e=null,h('")"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return")"}()),i===null&&(s=u),i}function be(){var i,e,l,u;return l=s,u=s,n.charCodeAt(s)===62?(i=">",s++):(i=null,h('">"')),i!==null?(e=k(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return">"}()),i===null&&(s=l),i}function ke(){var i,e,l,u;return l=s,u=s,i=k(),i!==null?(n.charCodeAt(s)===60?(e="<",s++):(e=null,h('"<"')),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return"<"}()),i===null&&(s=l),i}function Re(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return","}()),i===null&&(s=u),i}function le(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return";"}()),i===null&&(s=u),i}function ye(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return":"}()),i===null&&(s=u),i}function lt(){var i,e,l,u;return l=s,u=s,i=k(),i!==null?(e=A(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return'"'}()),i===null&&(s=l),i}function ot(){var i,e,l,u;return l=s,u=s,i=A(),i!==null?(e=k(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return'"'}()),i===null&&(s=l),i}function Ee(){var i,e,l,u;if(u=s,i=re(),i!==null){for(e=[],l=Ce(),l===null&&(l=de(),l===null&&(l=Ee()));l!==null;)e.push(l),l=Ce(),l===null&&(l=de(),l===null&&(l=Ee()));e!==null?(l=ge(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)}else i=null,s=u;return i}function Ce(){var i;return/^[!-']/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[!-']")),i===null&&(/^[*-[]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[*-[]")),i===null&&(/^[\]-~]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\]-~]")),i===null&&(i=J(),i===null&&(i=ve())))),i}function Ie(){var i,e,l,u,f,p;if(f=s,p=s,i=k(),i!==null)if(e=A(),e!==null){for(l=[],u=pe(),u===null&&(u=de());u!==null;)l.push(u),u=pe(),u===null&&(u=de());l!==null?(u=A(),u!==null?i=[i,e,l,u]:(i=null,s=p)):(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i!==null&&(i=function(m){return n.substring(s,m)}(f)),i===null&&(s=f),i}function Oe(){var i,e,l,u,f,p;if(f=s,p=s,i=k(),i!==null)if(e=A(),e!==null){for(l=[],u=pe(),u===null&&(u=de());u!==null;)l.push(u),u=pe(),u===null&&(u=de());l!==null?(u=A(),u!==null?i=[i,e,l,u]:(i=null,s=p)):(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i!==null&&(i=function(m){var v=n.substring(s,m).trim();return v.substring(1,v.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(f)),i===null&&(s=f),i}function pe(){var i;return i=ve(),i===null&&(n.charCodeAt(s)===33?(i="!",s++):(i=null,h('"!"')),i===null&&(/^[#-[]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[#-[]")),i===null&&(/^[\]-~]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\]-~]")),i===null&&(i=J())))),i}function de(){var i,e,l;return l=s,n.charCodeAt(s)===92?(i="\\",s++):(i=null,h('"\\\\"')),i!==null?(/^[\0-\t]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[\\0-\\t]")),e===null&&(/^[\x0B-\f]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[\\x0B-\\f]")),e===null&&(/^[\x0E-]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[\\x0E-]")))),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function _e(){var i,e,l,u,f,p;return f=s,p=s,i=Ne(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=Vt(),l=l!==null?l:"",l!==null?(u=cn(),u!==null?i=[i,e,l,u]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i!==null&&(i=function(m){try{b.uri=new Ya(b.scheme,b.user,b.host,b.port),delete b.scheme,delete b.user,delete b.host,delete b.host_type,delete b.port}catch{b=-1}}()),i===null&&(s=f),i}function we(){var i,e,l,u,f,p,m,v;return m=s,v=s,i=Ne(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=Vt(),l=l!==null?l:"",l!==null?(u=cn(),u!==null?(f=ui(),f!==null?(p=Ti(),p=p!==null?p:"",p!==null?i=[i,e,l,u,f,p]:(i=null,s=v)):(i=null,s=v)):(i=null,s=v)):(i=null,s=v)):(i=null,s=v)):(i=null,s=v),i!==null&&(i=function(S){try{b.uri=new Ya(b.scheme,b.user,b.host,b.port,b.uri_params,b.uri_headers),delete b.scheme,delete b.user,delete b.host,delete b.host_type,delete b.port,delete b.uri_params,a==="SIP_URI"&&(b=b.uri)}catch{b=-1}}()),i===null&&(s=m),i}function Ne(){var i;return i=tt(),i===null&&(i=He()),i}function tt(){var i,e;return e=s,n.substr(s,4).toLowerCase()==="sips"?(i=n.substr(s,4),s+=4):(i=null,h('"sips"')),i!==null&&(i=function(l,u){b.scheme=u.toLowerCase()}(e,i)),i===null&&(s=e),i}function He(){var i,e;return e=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"sip"')),i!==null&&(i=function(l,u){b.scheme=u.toLowerCase()}(e,i)),i===null&&(s=e),i}function Vt(){var i,e,l,u,f,p;return u=s,f=s,i=At(),i!==null?(p=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=Gn(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?(n.charCodeAt(s)===64?(l="@",s++):(l=null,h('"@"')),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b.user=decodeURIComponent(n.substring(s-1,m))}(u)),i===null&&(s=u),i}function At(){var i,e;if(e=N(),e===null&&(e=Se(),e===null&&(e=Bn())),e!==null)for(i=[];e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(e=Bn()));else i=null;return i}function Bn(){var i;return n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"'))))))))),i}function Gn(){var i,e,l;for(l=s,i=[],e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","'))))))));e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","'))))))));return i!==null&&(i=function(u){b.password=n.substring(s,u)}(l)),i===null&&(s=l),i}function cn(){var i,e,l,u,f;return u=s,i=as(),i!==null?(f=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=$s(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function as(){var i,e;return e=s,i=Cs(),i===null&&(i=ut(),i===null&&(i=Kn())),i!==null&&(i=function(l){return b.host=n.substring(s,l).toLowerCase(),b.host}(e)),i===null&&(s=e),i}function Cs(){var i,e,l,u,f,p;for(u=s,f=s,i=[],p=s,e=fn(),e!==null?(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p);e!==null;)i.push(e),p=s,e=fn(),e!==null?(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p);return i!==null?(e=Wn(),e!==null?(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l=l!==null?l:"",l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){return b.host_type="domain",n.substring(s,m)}(u)),i===null&&(s=u),i}function fn(){var i,e,l,u;if(u=s,i=$(),i!==null){for(e=[],l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));l!==null;)e.push(l),l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));e!==null?i=[i,e]:(i=null,s=u)}else i=null,s=u;return i}function Wn(){var i,e,l,u;if(u=s,i=T(),i!==null){for(e=[],l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));l!==null;)e.push(l),l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));e!==null?i=[i,e]:(i=null,s=u)}else i=null,s=u;return i}function Kn(){var i,e,l,u,f;return u=s,f=s,n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i!==null?(e=hn(),e!==null?(n.charCodeAt(s)===93?(l="]",s++):(l=null,h('"]"')),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return b.host_type="IPv6",n.substring(s,p)}(u)),i===null&&(s=u),i}function hn(){var i,e,l,u,f,p,m,v,S,O,ie,Ue,Dt,Js,M,R;return Js=s,M=s,i=me(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?(n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?(n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?(n.charCodeAt(s)===58?(v=":",s++):(v=null,h('":"')),v!==null?(S=me(),S!==null?(n.charCodeAt(s)===58?(O=":",s++):(O=null,h('":"')),O!==null?(ie=me(),ie!==null?(n.charCodeAt(s)===58?(Ue=":",s++):(Ue=null,h('":"')),Ue!==null?(Dt=ae(),Dt!==null?i=[i,e,l,u,f,p,m,v,S,O,ie,Ue,Dt]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?(n.charCodeAt(s)===58?(S=":",s++):(S=null,h('":"')),S!==null?(O=me(),O!==null?(n.charCodeAt(s)===58?(ie=":",s++):(ie=null,h('":"')),ie!==null?(Ue=ae(),Ue!==null?i=[i,e,l,u,f,p,m,v,S,O,ie,Ue]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?(n.charCodeAt(s)===58?(S=":",s++):(S=null,h('":"')),S!==null?(O=ae(),O!==null?i=[i,e,l,u,f,p,m,v,S,O]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=ae(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=ae(),p!==null?i=[i,e,l,u,f,p]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=ae(),u!==null?i=[i,e,l,u]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=ae(),e!==null?i=[i,e]:(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?i=[i,e]:(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(n.substr(s,2)==="::"?(e="::",s+=2):(e=null,h('"::"')),e!==null?(l=me(),l!==null?(n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?(n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?(n.charCodeAt(s)===58?(v=":",s++):(v=null,h('":"')),v!==null?(S=me(),S!==null?(n.charCodeAt(s)===58?(O=":",s++):(O=null,h('":"')),O!==null?(ie=ae(),ie!==null?i=[i,e,l,u,f,p,m,v,S,O,ie]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(n.substr(s,2)==="::"?(l="::",s+=2):(l=null,h('"::"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?(n.charCodeAt(s)===58?(S=":",s++):(S=null,h('":"')),S!==null?(O=ae(),O!==null?i=[i,e,l,u,f,p,m,v,S,O]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(n.substr(s,2)==="::"?(u="::",s+=2):(u=null,h('"::"')),u!==null?(f=me(),f!==null?(n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?(n.charCodeAt(s)===58?(v=":",s++):(v=null,h('":"')),v!==null?(S=ae(),S!==null?i=[i,e,l,u,f,p,m,v,S]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(n.substr(s,2)==="::"?(f="::",s+=2):(f=null,h('"::"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=ae(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(R=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,s=R)):(f=null,s=R),f=f!==null?f:"",f!==null?(n.substr(s,2)==="::"?(p="::",s+=2):(p=null,h('"::"')),p!==null?(m=ae(),m!==null?i=[i,e,l,u,f,p,m]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(R=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,s=R)):(f=null,s=R),f=f!==null?f:"",f!==null?(R=s,n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?p=[p,m]:(p=null,s=R)):(p=null,s=R),p=p!==null?p:"",p!==null?(n.substr(s,2)==="::"?(m="::",s+=2):(m=null,h('"::"')),m!==null?(v=me(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(R=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,s=R)):(f=null,s=R),f=f!==null?f:"",f!==null?(R=s,n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?p=[p,m]:(p=null,s=R)):(p=null,s=R),p=p!==null?p:"",p!==null?(R=s,n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?m=[m,v]:(m=null,s=R)):(m=null,s=R),m=m!==null?m:"",m!==null?(n.substr(s,2)==="::"?(v="::",s+=2):(v=null,h('"::"')),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M))))))))))))))),i!==null&&(i=function(Te){return b.host_type="IPv6",n.substring(s,Te)}(Js)),i===null&&(s=Js),i}function me(){var i,e,l,u,f;return f=s,i=E(),i!==null?(e=E(),e=e!==null?e:"",e!==null?(l=E(),l=l!==null?l:"",l!==null?(u=E(),u=u!==null?u:"",u!==null?i=[i,e,l,u]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i}function ae(){var i,e,l,u;return u=s,i=me(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i===null&&(i=ut()),i}function ut(){var i,e,l,u,f,p,m,v,S;return v=s,S=s,i=es(),i!==null?(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e!==null?(l=es(),l!==null?(n.charCodeAt(s)===46?(u=".",s++):(u=null,h('"."')),u!==null?(f=es(),f!==null?(n.charCodeAt(s)===46?(p=".",s++):(p=null,h('"."')),p!==null?(m=es(),m!==null?i=[i,e,l,u,f,p,m]:(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S),i!==null&&(i=function(O){return b.host_type="IPv4",n.substring(s,O)}(v)),i===null&&(s=v),i}function es(){var i,e,l,u;return u=s,n.substr(s,2)==="25"?(i="25",s+=2):(i=null,h('"25"')),i!==null?(/^[0-5]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[0-5]")),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i===null&&(u=s,n.charCodeAt(s)===50?(i="2",s++):(i=null,h('"2"')),i!==null?(/^[0-4]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[0-4]")),e!==null?(l=g(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i===null&&(u=s,n.charCodeAt(s)===49?(i="1",s++):(i=null,h('"1"')),i!==null?(e=g(),e!==null?(l=g(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i===null&&(u=s,/^[1-9]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[1-9]")),i!==null?(e=g(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i===null&&(i=g())))),i}function $s(){var i,e,l,u,f,p,m;return p=s,m=s,i=g(),i=i!==null?i:"",i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?i=[i,e,l,u,f]:(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(v,S){return S=parseInt(S.join("")),b.port=S,S}(p,i)),i===null&&(s=p),i}function ui(){var i,e,l,u;for(i=[],u=s,n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e!==null?(l=Yn(),l!==null?e=[e,l]:(e=null,s=u)):(e=null,s=u);e!==null;)i.push(e),u=s,n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e!==null?(l=Yn(),l!==null?e=[e,l]:(e=null,s=u)):(e=null,s=u);return i}function Yn(){var i;return i=Jn(),i===null&&(i=ci(),i===null&&(i=fi(),i===null&&(i=hi(),i===null&&(i=di(),i===null&&(i=_i(),i===null&&(i=pi())))))),i}function Jn(){var i,e,l,u;return l=s,u=s,n.substr(s,10).toLowerCase()==="transport="?(i=n.substr(s,10),s+=10):(i=null,h('"transport="')),i!==null?(n.substr(s,3).toLowerCase()==="udp"?(e=n.substr(s,3),s+=3):(e=null,h('"udp"')),e===null&&(n.substr(s,3).toLowerCase()==="tcp"?(e=n.substr(s,3),s+=3):(e=null,h('"tcp"')),e===null&&(n.substr(s,4).toLowerCase()==="sctp"?(e=n.substr(s,4),s+=4):(e=null,h('"sctp"')),e===null&&(n.substr(s,3).toLowerCase()==="tls"?(e=n.substr(s,3),s+=3):(e=null,h('"tls"')),e===null&&(e=U())))),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.transport=p.toLowerCase()}(l,i[1])),i===null&&(s=l),i}function ci(){var i,e,l,u;return l=s,u=s,n.substr(s,5).toLowerCase()==="user="?(i=n.substr(s,5),s+=5):(i=null,h('"user="')),i!==null?(n.substr(s,5).toLowerCase()==="phone"?(e=n.substr(s,5),s+=5):(e=null,h('"phone"')),e===null&&(n.substr(s,2).toLowerCase()==="ip"?(e=n.substr(s,2),s+=2):(e=null,h('"ip"')),e===null&&(e=U())),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.user=p.toLowerCase()}(l,i[1])),i===null&&(s=l),i}function fi(){var i,e,l,u;return l=s,u=s,n.substr(s,7).toLowerCase()==="method="?(i=n.substr(s,7),s+=7):(i=null,h('"method="')),i!==null?(e=vn(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.method=p}(l,i[1])),i===null&&(s=l),i}function hi(){var i,e,l,u;return l=s,u=s,n.substr(s,4).toLowerCase()==="ttl="?(i=n.substr(s,4),s+=4):(i=null,h('"ttl="')),i!==null?(e=gr(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.params||(b.params={}),b.params.ttl=p}(l,i[1])),i===null&&(s=l),i}function di(){var i,e,l,u;return l=s,u=s,n.substr(s,6).toLowerCase()==="maddr="?(i=n.substr(s,6),s+=6):(i=null,h('"maddr="')),i!==null?(e=as(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.maddr=p}(l,i[1])),i===null&&(s=l),i}function _i(){var i,e,l,u,f,p;return u=s,f=s,n.substr(s,2).toLowerCase()==="lr"?(i=n.substr(s,2),s+=2):(i=null,h('"lr"')),i!==null?(p=s,n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=U(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b.uri_params||(b.uri_params={}),b.uri_params.lr=void 0}()),i===null&&(s=u),i}function pi(){var i,e,l,u,f,p;return u=s,f=s,i=mi(),i!==null?(p=s,n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=gi(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m,v,S){b.uri_params||(b.uri_params={}),typeof S>"u"?S=void 0:S=S[1],b.uri_params[v.toLowerCase()]=S}(u,i[0],i[1])),i===null&&(s=u),i}function mi(){var i,e,l;if(l=s,e=Hs(),e!==null)for(i=[];e!==null;)i.push(e),e=Hs();else i=null;return i!==null&&(i=function(u,f){return f.join("")}(l,i)),i===null&&(s=l),i}function gi(){var i,e,l;if(l=s,e=Hs(),e!==null)for(i=[];e!==null;)i.push(e),e=Hs();else i=null;return i!==null&&(i=function(u,f){return f.join("")}(l,i)),i===null&&(s=l),i}function Hs(){var i;return i=Fs(),i===null&&(i=N(),i===null&&(i=Se())),i}function Fs(){var i;return n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i===null&&(n.charCodeAt(s)===93?(i="]",s++):(i=null,h('"]"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')))))))),i}function Ti(){var i,e,l,u,f,p,m;if(p=s,n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i!==null)if(e=dn(),e!==null){for(l=[],m=s,n.charCodeAt(s)===38?(u="&",s++):(u=null,h('"&"')),u!==null?(f=dn(),f!==null?u=[u,f]:(u=null,s=m)):(u=null,s=m);u!==null;)l.push(u),m=s,n.charCodeAt(s)===38?(u="&",s++):(u=null,h('"&"')),u!==null?(f=dn(),f!==null?u=[u,f]:(u=null,s=m)):(u=null,s=m);l!==null?i=[i,e,l]:(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i}function dn(){var i,e,l,u,f;return u=s,f=s,i=_n(),i!==null?(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=vi(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m,v){m=m.join("").toLowerCase(),v=v.join(""),b.uri_headers||(b.uri_headers={}),b.uri_headers[m]?b.uri_headers[m].push(v):b.uri_headers[m]=[v]}(u,i[0],i[2])),i===null&&(s=u),i}function _n(){var i,e;if(e=js(),e===null&&(e=N(),e===null&&(e=Se())),e!==null)for(i=[];e!==null;)i.push(e),e=js(),e===null&&(e=N(),e===null&&(e=Se()));else i=null;return i}function vi(){var i,e;for(i=[],e=js(),e===null&&(e=N(),e===null&&(e=Se()));e!==null;)i.push(e),e=js(),e===null&&(e=N(),e===null&&(e=Se()));return i}function js(){var i;return n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i===null&&(n.charCodeAt(s)===93?(i="]",s++):(i=null,h('"]"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')))))))),i}function pn(){var i;return i=En(),i===null&&(i=wa()),i}function wa(){var i,e,l,u,f,p;return p=s,i=vn(),i!==null?(e=I(),e!==null?(l=Ei(),l!==null?(u=I(),u!==null?(f=Qn(),f!==null?i=[i,e,l,u,f]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i}function Ei(){var i;return i=we(),i===null&&(i=zn()),i}function zn(){var i,e,l,u;return u=s,i=Gs(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=Xn(),l===null&&(l=gn()),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Xn(){var i,e,l,u,f;return u=s,i=Si(),i===null&&(i=mn()),i!==null?(f=s,n.charCodeAt(s)===63?(e="?",s++):(e=null,h('"?"')),e!==null?(l=Ii(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function Si(){var i,e,l,u;return u=s,n.substr(s,2)==="//"?(i="//",s+=2):(i=null,h('"//"')),i!==null?(e=Ci(),e!==null?(l=mn(),l=l!==null?l:"",l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function mn(){var i,e,l;return l=s,n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i!==null?(e=yi(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function gn(){var i,e,l,u;if(u=s,i=Vs(),i!==null){for(e=[],l=qs();l!==null;)e.push(l),l=qs();e!==null?i=[i,e]:(i=null,s=u)}else i=null,s=u;return i}function qs(){var i;return i=oe(),i===null&&(i=N(),i===null&&(i=Se())),i}function Vs(){var i;return i=N(),i===null&&(i=Se(),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')))))))))))),i}function yi(){var i,e,l,u,f,p;if(f=s,i=Tn(),i!==null){for(e=[],p=s,n.charCodeAt(s)===47?(l="/",s++):(l=null,h('"/"')),l!==null?(u=Tn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,n.charCodeAt(s)===47?(l="/",s++):(l=null,h('"/"')),l!==null?(u=Tn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Tn(){var i,e,l,u,f,p;for(f=s,i=[],e=As();e!==null;)i.push(e),e=As();if(i!==null){for(e=[],p=s,n.charCodeAt(s)===59?(l=";",s++):(l=null,h('";"')),l!==null?(u=Bs(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,n.charCodeAt(s)===59?(l=";",s++):(l=null,h('";"')),l!==null?(u=Bs(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Bs(){var i,e;for(i=[],e=As();e!==null;)i.push(e),e=As();return i}function As(){var i;return i=N(),i===null&&(i=Se(),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')))))))))),i}function Gs(){var i,e,l,u,f;if(u=s,f=s,i=T(),i!==null){for(e=[],l=T(),l===null&&(l=g(),l===null&&(n.charCodeAt(s)===43?(l="+",s++):(l=null,h('"+"')),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."'))))));l!==null;)e.push(l),l=T(),l===null&&(l=g(),l===null&&(n.charCodeAt(s)===43?(l="+",s++):(l=null,h('"+"')),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."'))))));e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i!==null&&(i=function(p){b.scheme=n.substring(s,p)}(u)),i===null&&(s=u),i}function Ci(){var i;return i=Ai(),i===null&&(i=Ri()),i}function Ai(){var i,e,l,u;return l=s,u=s,i=Vt(),i!==null?(n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i=i!==null?i:"",i!==null?(e=cn(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i=i!==null?i:"",i}function Ri(){var i,e;if(e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","')),e===null&&(n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"'))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","')),e===null&&(n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')))))))))));else i=null;return i}function Ii(){var i,e;for(i=[],e=qs();e!==null;)i.push(e),e=qs();return i}function Qn(){var i,e,l,u,f,p,m,v;if(m=s,v=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"SIP"')),i!==null)if(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e!==null){if(u=g(),u!==null)for(l=[];u!==null;)l.push(u),u=g();else l=null;if(l!==null)if(n.charCodeAt(s)===46?(u=".",s++):(u=null,h('"."')),u!==null){if(p=g(),p!==null)for(f=[];p!==null;)f.push(p),p=g();else f=null;f!==null?i=[i,e,l,u,f]:(i=null,s=v)}else i=null,s=v;else i=null,s=v}else i=null,s=v;else i=null,s=v;return i!==null&&(i=function(S){b.sip_version=n.substring(s,S)}(m)),i===null&&(s=m),i}function Zn(){var i;return n.substr(s,6)==="INVITE"?(i="INVITE",s+=6):(i=null,h('"INVITE"')),i}function bi(){var i;return n.substr(s,3)==="ACK"?(i="ACK",s+=3):(i=null,h('"ACK"')),i}function wi(){var i;return n.substr(s,7)==="OPTIONS"?(i="OPTIONS",s+=7):(i=null,h('"OPTIONS"')),i}function Oi(){var i;return n.substr(s,3)==="BYE"?(i="BYE",s+=3):(i=null,h('"BYE"')),i}function Di(){var i;return n.substr(s,6)==="CANCEL"?(i="CANCEL",s+=6):(i=null,h('"CANCEL"')),i}function Ni(){var i;return n.substr(s,8)==="REGISTER"?(i="REGISTER",s+=8):(i=null,h('"REGISTER"')),i}function Ui(){var i;return n.substr(s,9)==="SUBSCRIBE"?(i="SUBSCRIBE",s+=9):(i=null,h('"SUBSCRIBE"')),i}function Pi(){var i;return n.substr(s,6)==="NOTIFY"?(i="NOTIFY",s+=6):(i=null,h('"NOTIFY"')),i}function xi(){var i;return n.substr(s,5)==="REFER"?(i="REFER",s+=5):(i=null,h('"REFER"')),i}function vn(){var i,e;return e=s,i=Zn(),i===null&&(i=bi(),i===null&&(i=wi(),i===null&&(i=Oi(),i===null&&(i=Di(),i===null&&(i=Ni(),i===null&&(i=Ui(),i===null&&(i=Pi(),i===null&&(i=xi(),i===null&&(i=U()))))))))),i!==null&&(i=function(l){return b.method=n.substring(s,l),b.method}(e)),i===null&&(s=e),i}function En(){var i,e,l,u,f,p;return p=s,i=Qn(),i!==null?(e=I(),e!==null?(l=ki(),l!==null?(u=I(),u!==null?(f=Li(),f!==null?i=[i,e,l,u,f]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i}function ki(){var i,e;return e=s,i=Mi(),i!==null&&(i=function(l,u){b.status_code=parseInt(u.join(""))}(e,i)),i===null&&(s=e),i}function Mi(){var i,e,l,u;return u=s,i=g(),i!==null?(e=g(),e!==null?(l=g(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Li(){var i,e,l;for(l=s,i=[],e=oe(),e===null&&(e=N(),e===null&&(e=Se(),e===null&&(e=J(),e===null&&(e=F(),e===null&&(e=I(),e===null&&(e=H()))))));e!==null;)i.push(e),e=oe(),e===null&&(e=N(),e===null&&(e=Se(),e===null&&(e=J(),e===null&&(e=F(),e===null&&(e=I(),e===null&&(e=H()))))));return i!==null&&(i=function(u){b.reason_phrase=n.substring(s,u)}(l)),i===null&&(s=l),i}function Oa(){var i,e,l,u,f,p;if(f=s,i=Cn(),i!==null){for(e=[],p=s,l=Re(),l!==null?(u=Cn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Re(),l!==null?(u=Cn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Du(){var i,e,l,u,f,p;return u=s,f=s,i=it(),i!==null?(p=s,n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e!==null?(l=it(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b=n.substring(s,m)}(u)),i===null&&(s=u),i}function Nu(){var i,e,l,u,f,p,m;if(f=s,i=ee(),i===null)if(p=s,i=er(),i!==null){for(e=[],m=s,l=Re(),l!==null?(u=er(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=Re(),l!==null?(u=er(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S,O;for(O=b.multi_header.length,S=0;S<O;S++)if(b.multi_header[S].parsed===null){b=null;break}b!==null?b=b.multi_header:b=-1}()),i===null&&(s=f),i}function er(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=Bt()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Ws(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Ws(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S;b.multi_header||(b.multi_header=[]);try{S=new Rs(b.uri,b.display_name,b.params),delete b.uri,delete b.display_name,delete b.params}catch{S=null}b.multi_header.push({possition:s,offset:v,parsed:S})}(f)),i===null&&(s=f),i}function Bt(){var i,e,l,u,f;return f=s,i=Gt(),i=i!==null?i:"",i!==null?(e=ke(),e!==null?(l=we(),l!==null?(u=be(),u!==null?i=[i,e,l,u]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i}function Gt(){var i,e,l,u,f,p,m;if(f=s,p=s,i=U(),i!==null){for(e=[],m=s,l=ve(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=ve(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i===null&&(i=Oe()),i!==null&&(i=function(v,S){typeof S=="string"?b.display_name=S:b.display_name=S[1].reduce(function(O,ie){return O+ie[0]+ie[1]},S[0])}(f,i)),i===null&&(s=f),i}function Ws(){var i;return i=tr(),i===null&&(i=$i(),i===null&&(i=Je())),i}function tr(){var i,e,l,u,f;return u=s,f=s,n.substr(s,1).toLowerCase()==="q"?(i=n.substr(s,1),s++):(i=null,h('"q"')),i!==null?(e=G(),e!==null?(l=us(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.params||(b.params={}),b.params.q=m}(u,i[2])),i===null&&(s=u),i}function $i(){var i,e,l,u,f;return u=s,f=s,n.substr(s,7).toLowerCase()==="expires"?(i=n.substr(s,7),s+=7):(i=null,h('"expires"')),i!==null?(e=G(),e!==null?(l=os(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.params||(b.params={}),b.params.expires=m}(u,i[2])),i===null&&(s=u),i}function os(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){return parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function us(){var i,e,l,u,f,p,m,v;return p=s,m=s,n.charCodeAt(s)===48?(i="0",s++):(i=null,h('"0"')),i!==null?(v=s,n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?e=[e,l,u,f]:(e=null,s=v)):(e=null,s=v)):(e=null,s=v)):(e=null,s=v),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(S){return parseFloat(n.substring(s,S))}(p)),i===null&&(s=p),i}function Je(){var i,e,l,u,f,p;return u=s,f=s,i=U(),i!==null?(p=s,e=G(),e!==null?(l=ze(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m,v,S){b.params||(b.params={}),typeof S>"u"?S=void 0:S=S[1],b.params[v.toLowerCase()]=S}(u,i[0],i[1])),i===null&&(s=u),i}function ze(){var i;return i=U(),i===null&&(i=as(),i===null&&(i=Ie())),i}function Da(){var i,e,l,u,f,p;if(f=s,i=Na(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=sr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=sr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Na(){var i;return n.substr(s,6).toLowerCase()==="render"?(i=n.substr(s,6),s+=6):(i=null,h('"render"')),i===null&&(n.substr(s,7).toLowerCase()==="session"?(i=n.substr(s,7),s+=7):(i=null,h('"session"')),i===null&&(n.substr(s,4).toLowerCase()==="icon"?(i=n.substr(s,4),s+=4):(i=null,h('"icon"')),i===null&&(n.substr(s,5).toLowerCase()==="alert"?(i=n.substr(s,5),s+=5):(i=null,h('"alert"')),i===null&&(i=U())))),i}function sr(){var i;return i=nr(),i===null&&(i=Je()),i}function nr(){var i,e,l,u;return u=s,n.substr(s,8).toLowerCase()==="handling"?(i=n.substr(s,8),s+=8):(i=null,h('"handling"')),i!==null?(e=G(),e!==null?(n.substr(s,8).toLowerCase()==="optional"?(l=n.substr(s,8),s+=8):(l=null,h('"optional"')),l===null&&(n.substr(s,8).toLowerCase()==="required"?(l=n.substr(s,8),s+=8):(l=null,h('"required"')),l===null&&(l=U())),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Ua(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Re(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Re(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Uu(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){b=parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function Pu(){var i,e;return e=s,i=Pa(),i!==null&&(i=function(l){b=n.substring(s,l)}(e)),i===null&&(s=e),i}function Pa(){var i,e,l,u,f,p,m,v;if(m=s,i=Hi(),i!==null)if(e=Y(),e!==null)if(l=qi(),l!==null){for(u=[],v=s,f=le(),f!==null?(p=rr(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=le(),f!==null?(p=rr(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i}function Hi(){var i;return i=Fi(),i===null&&(i=ji()),i}function Fi(){var i;return n.substr(s,4).toLowerCase()==="text"?(i=n.substr(s,4),s+=4):(i=null,h('"text"')),i===null&&(n.substr(s,5).toLowerCase()==="image"?(i=n.substr(s,5),s+=5):(i=null,h('"image"')),i===null&&(n.substr(s,5).toLowerCase()==="audio"?(i=n.substr(s,5),s+=5):(i=null,h('"audio"')),i===null&&(n.substr(s,5).toLowerCase()==="video"?(i=n.substr(s,5),s+=5):(i=null,h('"video"')),i===null&&(n.substr(s,11).toLowerCase()==="application"?(i=n.substr(s,11),s+=11):(i=null,h('"application"')),i===null&&(i=Sn()))))),i}function ji(){var i;return n.substr(s,7).toLowerCase()==="message"?(i=n.substr(s,7),s+=7):(i=null,h('"message"')),i===null&&(n.substr(s,9).toLowerCase()==="multipart"?(i=n.substr(s,9),s+=9):(i=null,h('"multipart"')),i===null&&(i=Sn())),i}function Sn(){var i;return i=U(),i===null&&(i=yn()),i}function yn(){var i,e,l;return l=s,n.substr(s,2).toLowerCase()==="x-"?(i=n.substr(s,2),s+=2):(i=null,h('"x-"')),i!==null?(e=U(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function qi(){var i;return i=Sn(),i===null&&(i=U()),i}function rr(){var i,e,l,u;return u=s,i=U(),i!==null?(e=G(),e!==null?(l=ir(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function ir(){var i;return i=U(),i===null&&(i=Ie()),i}function xa(){var i,e,l,u;return u=s,i=ka(),i!==null?(e=ve(),e!==null?(l=vn(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function ka(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){b.value=parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function Ma(){var i,e;return e=s,i=os(),i!==null&&(i=function(l,u){b=u}(e,i)),i===null&&(s=e),i}function xu(){var i,e,l,u,f,p,m;if(f=s,p=s,i=Cn(),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Je(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Je(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v,S){b.event=S.join("").toLowerCase()}(f,i[0])),i===null&&(s=f),i}function Cn(){var i,e,l,u,f,p;if(f=s,i=P(),i!==null){for(e=[],p=s,n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?(u=P(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?(u=P(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function An(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=Bt()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Vi(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Vi(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S=b.tag;try{b=new Rs(b.uri,b.display_name,b.params),S&&b.setParam("tag",S)}catch{b=-1}}()),i===null&&(s=f),i}function Vi(){var i;return i=Rn(),i===null&&(i=Je()),i}function Rn(){var i,e,l,u,f;return u=s,f=s,n.substr(s,3).toLowerCase()==="tag"?(i=n.substr(s,3),s+=3):(i=null,h('"tag"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.tag=m}(u,i[2])),i===null&&(s=u),i}function Bi(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){b=parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function ku(){var i,e;return e=s,i=os(),i!==null&&(i=function(l,u){b=u}(e,i)),i===null&&(s=e),i}function Mu(){var i,e,l,u,f,p,m,v,S,O;for(v=s,S=s,i=[],e=Gt();e!==null;)i.push(e),e=Gt();if(i!==null)if(e=ke(),e!==null)if(l=we(),l!==null)if(u=be(),u!==null){for(f=[],O=s,p=le(),p!==null?(m=Je(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);p!==null;)f.push(p),O=s,p=le(),p!==null?(m=Je(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);f!==null?i=[i,e,l,u,f]:(i=null,s=S)}else i=null,s=S;else i=null,s=S;else i=null,s=S;else i=null,s=S;return i!==null&&(i=function(ie){try{b=new Rs(b.uri,b.display_name,b.params)}catch{b=-1}}()),i===null&&(s=v),i}function Lu(){var i;return i=Gi(),i}function Gi(){var i,e,l,u,f,p,m,v;if(m=s,n.substr(s,6).toLowerCase()==="digest"?(i=n.substr(s,6),s+=6):(i=null,h('"Digest"')),i!==null)if(e=ve(),e!==null)if(l=cs(),l!==null){for(u=[],v=s,f=Re(),f!==null?(p=cs(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=Re(),f!==null?(p=cs(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i===null&&(i=lr()),i}function lr(){var i,e,l,u,f,p,m,v;if(m=s,i=U(),i!==null)if(e=ve(),e!==null)if(l=Ks(),l!==null){for(u=[],v=s,f=Re(),f!==null?(p=Ks(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=Re(),f!==null?(p=Ks(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i}function Ks(){var i,e,l,u;return u=s,i=U(),i!==null?(e=G(),e!==null?(l=U(),l===null&&(l=Ie()),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function cs(){var i;return i=In(),i===null&&(i=Ki(),i===null&&(i=wn(),i===null&&(i=Ji(),i===null&&(i=zi(),i===null&&(i=Xi(),i===null&&(i=Qi(),i===null&&(i=Ks()))))))),i}function In(){var i,e,l,u;return u=s,n.substr(s,5).toLowerCase()==="realm"?(i=n.substr(s,5),s+=5):(i=null,h('"realm"')),i!==null?(e=G(),e!==null?(l=Wi(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Wi(){var i,e;return e=s,i=Oe(),i!==null&&(i=function(l,u){b.realm=u}(e,i)),i===null&&(s=e),i}function Ki(){var i,e,l,u,f,p,m,v,S;if(v=s,n.substr(s,6).toLowerCase()==="domain"?(i=n.substr(s,6),s+=6):(i=null,h('"domain"')),i!==null)if(e=G(),e!==null)if(l=lt(),l!==null)if(u=bn(),u!==null){if(f=[],S=s,m=I(),m!==null)for(p=[];m!==null;)p.push(m),m=I();else p=null;for(p!==null?(m=bn(),m!==null?p=[p,m]:(p=null,s=S)):(p=null,s=S);p!==null;){if(f.push(p),S=s,m=I(),m!==null)for(p=[];m!==null;)p.push(m),m=I();else p=null;p!==null?(m=bn(),m!==null?p=[p,m]:(p=null,s=S)):(p=null,s=S)}f!==null?(p=ot(),p!==null?i=[i,e,l,u,f,p]:(i=null,s=v)):(i=null,s=v)}else i=null,s=v;else i=null,s=v;else i=null,s=v;else i=null,s=v;return i}function bn(){var i;return i=zn(),i===null&&(i=mn()),i}function wn(){var i,e,l,u;return u=s,n.substr(s,5).toLowerCase()==="nonce"?(i=n.substr(s,5),s+=5):(i=null,h('"nonce"')),i!==null?(e=G(),e!==null?(l=Yi(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Yi(){var i,e;return e=s,i=Oe(),i!==null&&(i=function(l,u){b.nonce=u}(e,i)),i===null&&(s=e),i}function Ji(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6).toLowerCase()==="opaque"?(i=n.substr(s,6),s+=6):(i=null,h('"opaque"')),i!==null?(e=G(),e!==null?(l=Oe(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.opaque=m}(u,i[2])),i===null&&(s=u),i}function zi(){var i,e,l,u,f;return u=s,n.substr(s,5).toLowerCase()==="stale"?(i=n.substr(s,5),s+=5):(i=null,h('"stale"')),i!==null?(e=G(),e!==null?(f=s,n.substr(s,4).toLowerCase()==="true"?(l=n.substr(s,4),s+=4):(l=null,h('"true"')),l!==null&&(l=function(p){b.stale=!0}()),l===null&&(s=f),l===null&&(f=s,n.substr(s,5).toLowerCase()==="false"?(l=n.substr(s,5),s+=5):(l=null,h('"false"')),l!==null&&(l=function(p){b.stale=!1}()),l===null&&(s=f)),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Xi(){var i,e,l,u,f;return u=s,f=s,n.substr(s,9).toLowerCase()==="algorithm"?(i=n.substr(s,9),s+=9):(i=null,h('"algorithm"')),i!==null?(e=G(),e!==null?(n.substr(s,3).toLowerCase()==="md5"?(l=n.substr(s,3),s+=3):(l=null,h('"MD5"')),l===null&&(n.substr(s,8).toLowerCase()==="md5-sess"?(l=n.substr(s,8),s+=8):(l=null,h('"MD5-sess"')),l===null&&(l=U())),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.algorithm=m.toUpperCase()}(u,i[2])),i===null&&(s=u),i}function Qi(){var i,e,l,u,f,p,m,v,S,O;if(v=s,n.substr(s,3).toLowerCase()==="qop"?(i=n.substr(s,3),s+=3):(i=null,h('"qop"')),i!==null)if(e=G(),e!==null)if(l=lt(),l!==null){if(S=s,u=On(),u!==null){for(f=[],O=s,n.charCodeAt(s)===44?(p=",",s++):(p=null,h('","')),p!==null?(m=On(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);p!==null;)f.push(p),O=s,n.charCodeAt(s)===44?(p=",",s++):(p=null,h('","')),p!==null?(m=On(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);f!==null?u=[u,f]:(u=null,s=S)}else u=null,s=S;u!==null?(f=ot(),f!==null?i=[i,e,l,u,f]:(i=null,s=v)):(i=null,s=v)}else i=null,s=v;else i=null,s=v;else i=null,s=v;return i}function On(){var i,e;return e=s,n.substr(s,8).toLowerCase()==="auth-int"?(i=n.substr(s,8),s+=8):(i=null,h('"auth-int"')),i===null&&(n.substr(s,4).toLowerCase()==="auth"?(i=n.substr(s,4),s+=4):(i=null,h('"auth"')),i===null&&(i=U())),i!==null&&(i=function(l,u){b.qop||(b.qop=[]),b.qop.push(u.toLowerCase())}(e,i)),i===null&&(s=e),i}function ar(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Re(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Re(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function $u(){var i,e,l,u,f,p,m;if(f=s,p=s,i=or(),i!==null){for(e=[],m=s,l=Re(),l!==null?(u=or(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=Re(),l!==null?(u=or(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S,O;for(O=b.multi_header.length,S=0;S<O;S++)if(b.multi_header[S].parsed===null){b=null;break}b!==null?b=b.multi_header:b=-1}()),i===null&&(s=f),i}function or(){var i,e,l,u,f,p,m;if(f=s,p=s,i=Bt(),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Je(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Je(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S;b.multi_header||(b.multi_header=[]);try{S=new Rs(b.uri,b.display_name,b.params),delete b.uri,delete b.display_name,delete b.params}catch{S=null}b.multi_header.push({possition:s,offset:v,parsed:S})}(f)),i===null&&(s=f),i}function ur(){var i,e,l,u,f,p,m;if(f=s,p=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"SIP"')),i===null&&(i=U()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Zi(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Zi(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v,S){if(b.protocol=S.toLowerCase(),b.params||(b.params={}),b.params.text&&b.params.text[0]==='"'){var O=b.params.text;b.text=O.substring(1,O.length-1),delete b.params.text}}(f,i[0])),i===null&&(s=f),i}function Zi(){var i;return i=cr(),i===null&&(i=Je()),i}function cr(){var i,e,l,u,f,p;if(f=s,p=s,n.substr(s,5).toLowerCase()==="cause"?(i=n.substr(s,5),s+=5):(i=null,h('"cause"')),i!==null)if(e=G(),e!==null){if(u=g(),u!==null)for(l=[];u!==null;)l.push(u),u=g();else l=null;l!==null?i=[i,e,l]:(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i!==null&&(i=function(m,v){b.cause=parseInt(v.join(""))}(f,i[2])),i===null&&(s=f),i}function La(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Re(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Re(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Hu(){var i,e,l,u,f,p;if(f=s,i=fr(),i!==null){for(e=[],p=s,l=Re(),l!==null?(u=fr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Re(),l!==null?(u=fr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function fr(){var i,e,l,u,f,p;if(f=s,i=Bt(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=Je(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=Je(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function hr(){var i,e,l,u,f,p;if(f=s,i=$a(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=dr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=dr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function $a(){var i,e;return e=s,n.substr(s,6).toLowerCase()==="active"?(i=n.substr(s,6),s+=6):(i=null,h('"active"')),i===null&&(n.substr(s,7).toLowerCase()==="pending"?(i=n.substr(s,7),s+=7):(i=null,h('"pending"')),i===null&&(n.substr(s,10).toLowerCase()==="terminated"?(i=n.substr(s,10),s+=10):(i=null,h('"terminated"')),i===null&&(i=U()))),i!==null&&(i=function(l){b.state=n.substring(s,l)}(e)),i===null&&(s=e),i}function dr(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6).toLowerCase()==="reason"?(i=n.substr(s,6),s+=6):(i=null,h('"reason"')),i!==null?(e=G(),e!==null?(l=_r(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){typeof m<"u"&&(b.reason=m)}(u,i[2])),i===null&&(s=u),i===null&&(u=s,f=s,n.substr(s,7).toLowerCase()==="expires"?(i=n.substr(s,7),s+=7):(i=null,h('"expires"')),i!==null?(e=G(),e!==null?(l=os(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){typeof m<"u"&&(b.expires=m)}(u,i[2])),i===null&&(s=u),i===null&&(u=s,f=s,n.substr(s,11).toLowerCase()==="retry_after"?(i=n.substr(s,11),s+=11):(i=null,h('"retry_after"')),i!==null?(e=G(),e!==null?(l=os(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){typeof m<"u"&&(b.retry_after=m)}(u,i[2])),i===null&&(s=u),i===null&&(i=Je()))),i}function _r(){var i;return n.substr(s,11).toLowerCase()==="deactivated"?(i=n.substr(s,11),s+=11):(i=null,h('"deactivated"')),i===null&&(n.substr(s,9).toLowerCase()==="probation"?(i=n.substr(s,9),s+=9):(i=null,h('"probation"')),i===null&&(n.substr(s,8).toLowerCase()==="rejected"?(i=n.substr(s,8),s+=8):(i=null,h('"rejected"')),i===null&&(n.substr(s,7).toLowerCase()==="timeout"?(i=n.substr(s,7),s+=7):(i=null,h('"timeout"')),i===null&&(n.substr(s,6).toLowerCase()==="giveup"?(i=n.substr(s,6),s+=6):(i=null,h('"giveup"')),i===null&&(n.substr(s,10).toLowerCase()==="noresource"?(i=n.substr(s,10),s+=10):(i=null,h('"noresource"')),i===null&&(n.substr(s,9).toLowerCase()==="invariant"?(i=n.substr(s,9),s+=9):(i=null,h('"invariant"')),i===null&&(i=U()))))))),i}function Ha(){var i;return i=B(),i=i!==null?i:"",i}function Fu(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Re(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Re(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i=i!==null?i:"",i}function ju(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=Bt()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=el(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=el(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S=b.tag;try{b=new Rs(b.uri,b.display_name,b.params),S&&b.setParam("tag",S)}catch{b=-1}}()),i===null&&(s=f),i}function el(){var i;return i=Rn(),i===null&&(i=Je()),i}function tl(){var i,e,l,u,f,p;if(f=s,i=pr(),i!==null){for(e=[],p=s,l=Re(),l!==null?(u=pr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Re(),l!==null?(u=pr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function pr(){var i,e,l,u,f,p,m,v;if(m=s,i=al(),i!==null)if(e=ve(),e!==null)if(l=cl(),l!==null){for(u=[],v=s,f=le(),f!==null?(p=Ys(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=le(),f!==null?(p=Ys(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i}function Ys(){var i;return i=mr(),i===null&&(i=sl(),i===null&&(i=nl(),i===null&&(i=rl(),i===null&&(i=il(),i===null&&(i=Je()))))),i}function mr(){var i,e,l,u,f;return u=s,f=s,n.substr(s,3).toLowerCase()==="ttl"?(i=n.substr(s,3),s+=3):(i=null,h('"ttl"')),i!==null?(e=G(),e!==null?(l=gr(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.ttl=m}(u,i[2])),i===null&&(s=u),i}function sl(){var i,e,l,u,f;return u=s,f=s,n.substr(s,5).toLowerCase()==="maddr"?(i=n.substr(s,5),s+=5):(i=null,h('"maddr"')),i!==null?(e=G(),e!==null?(l=as(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.maddr=m}(u,i[2])),i===null&&(s=u),i}function nl(){var i,e,l,u,f;return u=s,f=s,n.substr(s,8).toLowerCase()==="received"?(i=n.substr(s,8),s+=8):(i=null,h('"received"')),i!==null?(e=G(),e!==null?(l=ut(),l===null&&(l=hn()),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.received=m}(u,i[2])),i===null&&(s=u),i}function rl(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6).toLowerCase()==="branch"?(i=n.substr(s,6),s+=6):(i=null,h('"branch"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.branch=m}(u,i[2])),i===null&&(s=u),i}function il(){var i,e,l,u,f;return u=s,n.substr(s,5).toLowerCase()==="rport"?(i=n.substr(s,5),s+=5):(i=null,h('"rport"')),i!==null?(f=s,e=G(),e!==null?(l=ll(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function ll(){var i,e,l,u,f,p,m;return p=s,m=s,i=g(),i=i!==null?i:"",i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?i=[i,e,l,u,f]:(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(v,S){b.rport=parseInt(S.join(""))}(p,i)),i===null&&(s=p),i}function al(){var i,e,l,u,f,p;return p=s,i=ol(),i!==null?(e=Y(),e!==null?(l=U(),l!==null?(u=Y(),u!==null?(f=ul(),f!==null?i=[i,e,l,u,f]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i}function ol(){var i,e;return e=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"SIP"')),i===null&&(i=U()),i!==null&&(i=function(l,u){b.protocol=u}(e,i)),i===null&&(s=e),i}function ul(){var i,e;return e=s,n.substr(s,3).toLowerCase()==="udp"?(i=n.substr(s,3),s+=3):(i=null,h('"UDP"')),i===null&&(n.substr(s,3).toLowerCase()==="tcp"?(i=n.substr(s,3),s+=3):(i=null,h('"TCP"')),i===null&&(n.substr(s,3).toLowerCase()==="tls"?(i=n.substr(s,3),s+=3):(i=null,h('"TLS"')),i===null&&(n.substr(s,4).toLowerCase()==="sctp"?(i=n.substr(s,4),s+=4):(i=null,h('"SCTP"')),i===null&&(i=U())))),i!==null&&(i=function(l,u){b.transport=u}(e,i)),i===null&&(s=e),i}function cl(){var i,e,l,u,f;return u=s,i=fl(),i!==null?(f=s,e=ye(),e!==null?(l=hl(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function fl(){var i,e;return e=s,i=ut(),i===null&&(i=Kn(),i===null&&(i=Cs())),i!==null&&(i=function(l){b.host=n.substring(s,l)}(e)),i===null&&(s=e),i}function hl(){var i,e,l,u,f,p,m;return p=s,m=s,i=g(),i=i!==null?i:"",i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?i=[i,e,l,u,f]:(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(v,S){b.port=parseInt(S.join(""))}(p,i)),i===null&&(s=p),i}function gr(){var i,e,l,u,f;return u=s,f=s,i=g(),i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){return parseInt(m.join(""))}(u,i)),i===null&&(s=u),i}function dl(){var i;return i=Gi(),i}function qu(){var i,e,l,u,f,p;if(f=s,i=Fa(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=Tr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=Tr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Fa(){var i,e;return e=s,i=os(),i!==null&&(i=function(l,u){b.expires=u}(e,i)),i===null&&(s=e),i}function Tr(){var i;return i=vr(),i===null&&(i=Je()),i}function vr(){var i,e,l,u,f;return u=s,f=s,n.substr(s,9).toLowerCase()==="refresher"?(i=n.substr(s,9),s+=9):(i=null,h('"refresher"')),i!==null?(e=G(),e!==null?(n.substr(s,3).toLowerCase()==="uac"?(l=n.substr(s,3),s+=3):(l=null,h('"uac"')),l===null&&(n.substr(s,3).toLowerCase()==="uas"?(l=n.substr(s,3),s+=3):(l=null,h('"uas"'))),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.refresher=m.toLowerCase()}(u,i[2])),i===null&&(s=u),i}function ja(){var i,e,l,u;return u=s,i=U(),i!==null?(e=D(),e!==null?(l=qa(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function qa(){var i,e;for(i=[],e=V(),e===null&&(e=F(),e===null&&(e=ve()));e!==null;)i.push(e),e=V(),e===null&&(e=F(),e===null&&(e=ve()));return i}function Va(){var i,e;for(i=[],e=C();e!==null;)i.push(e),e=C();return i}function Vu(){var i,e,l;return l=s,n.substr(s,5)==="uuid:"?(i="uuid:",s+=5):(i=null,h('"uuid:"')),i!==null?(e=Ba(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function Ba(){var i,e,l,u,f,p,m,v,S,O,ie;return O=s,ie=s,i=Kt(),i!==null?(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e!==null?(l=Wt(),l!==null?(n.charCodeAt(s)===45?(u="-",s++):(u=null,h('"-"')),u!==null?(f=Wt(),f!==null?(n.charCodeAt(s)===45?(p="-",s++):(p=null,h('"-"')),p!==null?(m=Wt(),m!==null?(n.charCodeAt(s)===45?(v="-",s++):(v=null,h('"-"')),v!==null?(S=_l(),S!==null?i=[i,e,l,u,f,p,m,v,S]:(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie),i!==null&&(i=function(Ue,Dt){b=n.substring(s+5,Ue)}(O,i[0])),i===null&&(s=O),i}function Wt(){var i,e,l,u,f;return f=s,i=E(),i!==null?(e=E(),e!==null?(l=E(),l!==null?(u=E(),u!==null?i=[i,e,l,u]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i}function Kt(){var i,e,l;return l=s,i=Wt(),i!==null?(e=Wt(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function _l(){var i,e,l,u;return u=s,i=Wt(),i!==null?(e=Wt(),e!==null?(l=Wt(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Ga(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=Bt()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Je(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Je(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){try{b=new Rs(b.uri,b.display_name,b.params)}catch{b=-1}}()),i===null&&(s=f),i}function Bu(){var i,e,l,u,f,p;if(f=s,i=Wa(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=Er(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=Er(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Wa(){var i,e,l,u,f,p;return u=s,f=s,i=it(),i!==null?(p=s,n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e!==null?(l=it(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b.call_id=n.substring(s,m)}(u)),i===null&&(s=u),i}function Er(){var i;return i=Sr(),i===null&&(i=pl(),i===null&&(i=ml(),i===null&&(i=Je()))),i}function Sr(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6)==="to-tag"?(i="to-tag",s+=6):(i=null,h('"to-tag"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.to_tag=m}(u,i[2])),i===null&&(s=u),i}function pl(){var i,e,l,u,f;return u=s,f=s,n.substr(s,8)==="from-tag"?(i="from-tag",s+=8):(i=null,h('"from-tag"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.from_tag=m}(u,i[2])),i===null&&(s=u),i}function ml(){var i,e;return e=s,n.substr(s,10)==="early-only"?(i="early-only",s+=10):(i=null,h('"early-only"')),i!==null&&(i=function(l){b.early_only=!0}()),i===null&&(s=e),i}function Ka(i){i.sort();for(var e=null,l=[],u=0;u<i.length;u++)i[u]!==e&&(l.push(i[u]),e=i[u]);return l}function Gu(){for(var i=1,e=1,l=!1,u=0;u<Math.max(s,r);u++){var f=n.charAt(u);f===`
|
75
|
+
`?(l||i++,e=1,l=!1):f==="\r"||f==="\u2028"||f==="\u2029"?(i++,e=1,l=!0):(e++,l=!1)}return{line:i,column:e}}var Ya=ps(),Rs=Vo(),b={},w=o[a]();if(w===null||s!==n.length){var gl=Math.max(s,r),Tl=gl<n.length?n.charAt(gl):null,Ja=Gu();return new this.SyntaxError(Ka(d),Tl,gl,Ja.line,Ja.column),-1}return b},toSource:function(){return this._source}};return t.SyntaxError=function(n,a,o,s,r){function d(h,_){var g,T;switch(h.length){case 0:g="end of input";break;case 1:g=h[0];break;default:g=h.slice(0,h.length-1).join(", ")+" or "+h[h.length-1]}return T=_?c(_):"end of input","Expected "+g+" but "+T+" found."}this.name="SyntaxError",this.expected=n,this.found=a,this.message=d(n,a),this.offset=o,this.line=s,this.column=r},t.SyntaxError.prototype=Error.prototype,t}()),Bo}var Go,If;function ps(){if(If)return Go;If=1;const c=De,t=mt(),n=Jt();return Go=class Hh{static parse(o){if(o=n.parse(o,"SIP_URI"),o!==-1)return o}constructor(o,s,r,d,h={},_={}){if(!r)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=o||c.SIP,this._user=s,this._host=r,this._port=d;for(const g in h)Object.prototype.hasOwnProperty.call(h,g)&&this.setParam(g,h[g]);for(const g in _)Object.prototype.hasOwnProperty.call(_,g)&&this.setHeader(g,_[g])}get scheme(){return this._scheme}set scheme(o){this._scheme=o.toLowerCase()}get user(){return this._user}set user(o){this._user=o}get host(){return this._host}set host(o){this._host=o.toLowerCase()}get port(){return this._port}set port(o){this._port=o===0?o:parseInt(o,10)||null}setParam(o,s){o&&(this._parameters[o.toLowerCase()]=typeof s>"u"||s===null?null:s.toString())}getParam(o){if(o)return this._parameters[o.toLowerCase()]}hasParam(o){if(o)return this._parameters.hasOwnProperty(o.toLowerCase())&&!0||!1}deleteParam(o){if(o=o.toLowerCase(),this._parameters.hasOwnProperty(o)){const s=this._parameters[o];return delete this._parameters[o],s}}clearParams(){this._parameters={}}setHeader(o,s){this._headers[t.headerize(o)]=Array.isArray(s)?s:[s]}getHeader(o){if(o)return this._headers[t.headerize(o)]}hasHeader(o){if(o)return this._headers.hasOwnProperty(t.headerize(o))&&!0||!1}deleteHeader(o){if(o=t.headerize(o),this._headers.hasOwnProperty(o)){const s=this._headers[o];return delete this._headers[o],s}}clearHeaders(){this._headers={}}clone(){return new Hh(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}toString(){const o=[];let s=`${this._scheme}:`;this._user&&(s+=`${t.escapeUser(this._user)}@`),s+=this._host,(this._port||this._port===0)&&(s+=`:${this._port}`);for(const r in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,r)&&(s+=`;${r}`,this._parameters[r]!==null&&(s+=`=${this._parameters[r]}`));for(const r in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,r))for(const d of this._headers[r])o.push(`${r}=${d}`);return o.length>0&&(s+=`?${o.join("&")}`),s}toAor(o){let s=`${this._scheme}:`;return this._user&&(s+=`${t.escapeUser(this._user)}@`),s+=this._host,o&&(this._port||this._port===0)&&(s+=`:${this._port}`),s}},Go}var bf;function mt(){if(bf)return Ze;bf=1;const c=De,t=ps(),n=Jt();Ze.str_utf8_length=r=>unescape(encodeURIComponent(r)).length;const a=Ze.isFunction=r=>r!==void 0?Object.prototype.toString.call(r)==="[object Function]":!1;Ze.isString=r=>r!==void 0?Object.prototype.toString.call(r)==="[object String]":!1,Ze.isDecimal=r=>!isNaN(r)&&parseFloat(r)===parseInt(r,10),Ze.isEmpty=r=>r===null||r===""||r===void 0||Array.isArray(r)&&r.length===0||typeof r=="number"&&isNaN(r),Ze.hasMethods=function(r,...d){for(const h of d)if(a(r[h]))return!1;return!0};const o=Ze.createRandomToken=(r,d=32)=>{let h,_,g="";for(h=0;h<r;h++)_=Math.random()*d|0,g+=_.toString(d);return g};Ze.newTag=()=>o(10),Ze.newUUID=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,d=>{const h=Math.random()*16|0;return(d==="x"?h:h&3|8).toString(16)}),Ze.hostType=r=>{if(r){if(r=n.parse(r,"host"),r!==-1)return r.host_type}else return};const s=Ze.escapeUser=r=>encodeURIComponent(decodeURIComponent(r)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/");return Ze.normalizeTarget=(r,d)=>{if(r){if(r instanceof t)return r;if(typeof r=="string"){const h=r.split("@");let _,g;switch(h.length){case 1:if(!d)return;_=r,g=d;break;case 2:_=h[0],g=h[1];break;default:_=h.slice(0,h.length-1).join("@"),g=h[h.length-1]}_=_.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(_)&&(_=_.replace(/[-.()]/g,"")),r=`${c.SIP}:${s(_)}@${g}`;let T;return(T=t.parse(r))?T:void 0}else return}else return},Ze.headerize=r=>{const d={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},h=r.toLowerCase().replace(/_/g,"-").split("-");let _="";const g=h.length;let T;for(T=0;T<g;T++)T!==0&&(_+="-"),_+=h[T].charAt(0).toUpperCase()+h[T].substring(1);return d[_]&&(_=d[_]),_},Ze.sipErrorCause=r=>{for(const d in c.SIP_ERROR_CAUSES)if(c.SIP_ERROR_CAUSES[d].indexOf(r)!==-1)return c.causes[d];return c.causes.SIP_FAILURE_CODE},Ze.getRandomTestNetIP=()=>{function r(d,h){return Math.floor(Math.random()*(h-d+1)+d)}return`192.0.2.${r(1,254)}`},Ze.calculateMD5=r=>{function d(Ee,Ce){return Ee<<Ce|Ee>>>32-Ce}function h(Ee,Ce){const Ie=Ee&2147483648,Oe=Ce&2147483648,pe=Ee&1073741824,de=Ce&1073741824,_e=(Ee&1073741823)+(Ce&1073741823);return pe&de?_e^2147483648^Ie^Oe:pe|de?_e&1073741824?_e^3221225472^Ie^Oe:_e^1073741824^Ie^Oe:_e^Ie^Oe}function _(Ee,Ce,Ie){return Ee&Ce|~Ee&Ie}function g(Ee,Ce,Ie){return Ee&Ie|Ce&~Ie}function T(Ee,Ce,Ie){return Ee^Ce^Ie}function E(Ee,Ce,Ie){return Ce^(Ee|~Ie)}function y(Ee,Ce,Ie,Oe,pe,de,_e){return Ee=h(Ee,h(h(_(Ce,Ie,Oe),pe),_e)),h(d(Ee,de),Ce)}function C(Ee,Ce,Ie,Oe,pe,de,_e){return Ee=h(Ee,h(h(g(Ce,Ie,Oe),pe),_e)),h(d(Ee,de),Ce)}function A(Ee,Ce,Ie,Oe,pe,de,_e){return Ee=h(Ee,h(h(T(Ce,Ie,Oe),pe),_e)),h(d(Ee,de),Ce)}function I(Ee,Ce,Ie,Oe,pe,de,_e){return Ee=h(Ee,h(h(E(Ce,Ie,Oe),pe),_e)),h(d(Ee,de),Ce)}function H(Ee){let Ce;const Ie=Ee.length,Oe=Ie+8,de=((Oe-Oe%64)/64+1)*16,_e=new Array(de-1);let we=0,Ne=0;for(;Ne<Ie;)Ce=(Ne-Ne%4)/4,we=Ne%4*8,_e[Ce]=_e[Ce]|Ee.charCodeAt(Ne)<<we,Ne++;return Ce=(Ne-Ne%4)/4,we=Ne%4*8,_e[Ce]=_e[Ce]|128<<we,_e[de-2]=Ie<<3,_e[de-1]=Ie>>>29,_e}function $(Ee){let Ce="",Ie="",Oe,pe;for(pe=0;pe<=3;pe++)Oe=Ee>>>pe*8&255,Ie=`0${Oe.toString(16)}`,Ce=Ce+Ie.substr(Ie.length-2,2);return Ce}function oe(Ee){let Ce="";for(let Ie=0;Ie<Ee.length;Ie++){const Oe=Ee.charCodeAt(Ie);Oe<128?Ce+=String.fromCharCode(Oe):Oe>127&&Oe<2048?(Ce+=String.fromCharCode(Oe>>6|192),Ce+=String.fromCharCode(Oe&63|128)):(Ce+=String.fromCharCode(Oe>>12|224),Ce+=String.fromCharCode(Oe>>6&63|128),Ce+=String.fromCharCode(Oe&63|128))}return Ce}let N=[],j,Se,ve,k,D,B,V,J,F;const Z=7,U=12,P=17,se=22,it=5,ee=9,Y=14,G=20,re=4,ge=11,be=16,ke=23,Re=6,le=10,ye=15,lt=21;for(r=oe(r),N=H(r),B=1732584193,V=4023233417,J=2562383102,F=271733878,j=0;j<N.length;j+=16)Se=B,ve=V,k=J,D=F,B=y(B,V,J,F,N[j+0],Z,3614090360),F=y(F,B,V,J,N[j+1],U,3905402710),J=y(J,F,B,V,N[j+2],P,606105819),V=y(V,J,F,B,N[j+3],se,3250441966),B=y(B,V,J,F,N[j+4],Z,4118548399),F=y(F,B,V,J,N[j+5],U,1200080426),J=y(J,F,B,V,N[j+6],P,2821735955),V=y(V,J,F,B,N[j+7],se,4249261313),B=y(B,V,J,F,N[j+8],Z,1770035416),F=y(F,B,V,J,N[j+9],U,2336552879),J=y(J,F,B,V,N[j+10],P,4294925233),V=y(V,J,F,B,N[j+11],se,2304563134),B=y(B,V,J,F,N[j+12],Z,1804603682),F=y(F,B,V,J,N[j+13],U,4254626195),J=y(J,F,B,V,N[j+14],P,2792965006),V=y(V,J,F,B,N[j+15],se,1236535329),B=C(B,V,J,F,N[j+1],it,4129170786),F=C(F,B,V,J,N[j+6],ee,3225465664),J=C(J,F,B,V,N[j+11],Y,643717713),V=C(V,J,F,B,N[j+0],G,3921069994),B=C(B,V,J,F,N[j+5],it,3593408605),F=C(F,B,V,J,N[j+10],ee,38016083),J=C(J,F,B,V,N[j+15],Y,3634488961),V=C(V,J,F,B,N[j+4],G,3889429448),B=C(B,V,J,F,N[j+9],it,568446438),F=C(F,B,V,J,N[j+14],ee,3275163606),J=C(J,F,B,V,N[j+3],Y,4107603335),V=C(V,J,F,B,N[j+8],G,1163531501),B=C(B,V,J,F,N[j+13],it,2850285829),F=C(F,B,V,J,N[j+2],ee,4243563512),J=C(J,F,B,V,N[j+7],Y,1735328473),V=C(V,J,F,B,N[j+12],G,2368359562),B=A(B,V,J,F,N[j+5],re,4294588738),F=A(F,B,V,J,N[j+8],ge,2272392833),J=A(J,F,B,V,N[j+11],be,1839030562),V=A(V,J,F,B,N[j+14],ke,4259657740),B=A(B,V,J,F,N[j+1],re,2763975236),F=A(F,B,V,J,N[j+4],ge,1272893353),J=A(J,F,B,V,N[j+7],be,4139469664),V=A(V,J,F,B,N[j+10],ke,3200236656),B=A(B,V,J,F,N[j+13],re,681279174),F=A(F,B,V,J,N[j+0],ge,3936430074),J=A(J,F,B,V,N[j+3],be,3572445317),V=A(V,J,F,B,N[j+6],ke,76029189),B=A(B,V,J,F,N[j+9],re,3654602809),F=A(F,B,V,J,N[j+12],ge,3873151461),J=A(J,F,B,V,N[j+15],be,530742520),V=A(V,J,F,B,N[j+2],ke,3299628645),B=I(B,V,J,F,N[j+0],Re,4096336452),F=I(F,B,V,J,N[j+7],le,1126891415),J=I(J,F,B,V,N[j+14],ye,2878612391),V=I(V,J,F,B,N[j+5],lt,4237533241),B=I(B,V,J,F,N[j+12],Re,1700485571),F=I(F,B,V,J,N[j+3],le,2399980690),J=I(J,F,B,V,N[j+10],ye,4293915773),V=I(V,J,F,B,N[j+1],lt,2240044497),B=I(B,V,J,F,N[j+8],Re,1873313359),F=I(F,B,V,J,N[j+15],le,4264355552),J=I(J,F,B,V,N[j+6],ye,2734768916),V=I(V,J,F,B,N[j+13],lt,1309151649),B=I(B,V,J,F,N[j+4],Re,4149444226),F=I(F,B,V,J,N[j+11],le,3174756917),J=I(J,F,B,V,N[j+2],ye,718787259),V=I(V,J,F,B,N[j+9],lt,3951481745),B=h(B,Se),V=h(V,ve),J=h(J,k),F=h(F,D);return($(B)+$(V)+$(J)+$(F)).toLowerCase()},Ze.closeMediaStream=r=>{if(r)try{let d;if(r.getTracks){d=r.getTracks();for(const h of d)h.stop()}else{d=r.getAudioTracks();for(const h of d)h.stop();d=r.getVideoTracks();for(const h of d)h.stop()}}catch{(typeof r.stop=="function"||typeof r.stop=="object")&&r.stop()}},Ze.cloneArray=r=>r&&r.slice()||[],Ze.cloneObject=(r,d={})=>r&&Object.assign({},r)||d,Ze}const wf=Ut,Rm=at,gt=De,rt=mt(),Of=Vo(),Im=Jt(),Wo=new Rm("SIPMessage");class ia{constructor(t,n,a,o,s,r){if(!t||!n||!a)return null;o=o||{},this.ua=a,this.headers={},this.method=t,this.ruri=n,this.body=r,this.extraHeaders=rt.cloneArray(s),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),o.route_set?this.setHeader("route",o.route_set):a.configuration.use_preloaded_route&&this.setHeader("route",`<${a.transport.sip_uri};lr>`),this.setHeader("via",""),this.setHeader("max-forwards",gt.MAX_FORWARDS);const d=o.to_uri||n,h=o.to_tag?{tag:o.to_tag}:null,_=typeof o.to_display_name<"u"?o.to_display_name:null;this.to=new Of(d,_,h),this.setHeader("to",this.to.toString());const g=o.from_uri||a.configuration.uri,T={tag:o.from_tag||rt.newTag()};let E;typeof o.from_display_name<"u"?E=o.from_display_name:a.configuration.display_name?E=a.configuration.display_name:E=null,this.from=new Of(g,E,T),this.setHeader("from",this.from.toString());const y=o.call_id||a.configuration.jssip_id+rt.createRandomToken(15);this.call_id=y,this.setHeader("call-id",y);const C=o.cseq||Math.floor(Math.random()*1e4);this.cseq=C,this.setHeader("cseq",`${C} ${t}`)}setHeader(t,n){const a=new RegExp(`^\\s*${t}\\s*:`,"i");for(let o=0;o<this.extraHeaders.length;o++)a.test(this.extraHeaders[o])&&this.extraHeaders.splice(o,1);this.headers[rt.headerize(t)]=Array.isArray(n)?n:[n]}getHeader(t){const n=this.headers[rt.headerize(t)];if(n){if(n[0])return n[0]}else{const a=new RegExp(`^\\s*${t}\\s*:`,"i");for(const o of this.extraHeaders)if(a.test(o))return o.substring(o.indexOf(":")+1).trim()}}getHeaders(t){const n=this.headers[rt.headerize(t)],a=[];if(n){for(const o of n)a.push(o);return a}else{const o=new RegExp(`^\\s*${t}\\s*:`,"i");for(const s of this.extraHeaders)o.test(s)&&a.push(s.substring(s.indexOf(":")+1).trim());return a}}hasHeader(t){if(this.headers[rt.headerize(t)])return!0;{const n=new RegExp(`^\\s*${t}\\s*:`,"i");for(const a of this.extraHeaders)if(n.test(a))return!0}return!1}parseSDP(t){return!t&&this.sdp?this.sdp:(this.sdp=wf.parse(this.body||""),this.sdp)}toString(){let t=`${this.method} ${this.ruri} SIP/2.0\r
|
76
76
|
`;for(const o in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,o))for(const s of this.headers[o])t+=`${o}: ${s}\r
|
77
77
|
`;for(const o of this.extraHeaders)t+=`${o.trim()}\r
|
78
78
|
`;const n=[];switch(this.method){case gt.REGISTER:n.push("path","gruu");break;case gt.INVITE:this.ua.configuration.session_timers&&n.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&n.push("gruu"),n.push("ice","replaces");break;case gt.UPDATE:this.ua.configuration.session_timers&&n.push("timer"),n.push("ice");break}n.push("outbound");const a=this.ua.configuration.user_agent||gt.USER_AGENT;if(t+=`Allow: ${gt.ALLOWED_METHODS}\r
|
@@ -112,7 +112,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
112
112
|
`,this.transport.send(o)}}class wm extends Df{constructor(){super(),this.headers={},this.status_code=null,this.reason_phrase=null}}var Tt={OutgoingRequest:ia,InitialOutgoingInviteRequest:Ko,IncomingRequest:bm,IncomingResponse:wm};const $n=Me(Tt),Om=at,ms=mt(),zt=new Om("DigestAuthentication");var Nf=class{constructor(t){this._credentials=t,this._cnonce=null,this._nc=0,this._ncHex="00000000",this._algorithm=null,this._realm=null,this._nonce=null,this._opaque=null,this._stale=null,this._qop=null,this._method=null,this._uri=null,this._ha1=null,this._response=null}get(t){switch(t){case"realm":return this._realm;case"ha1":return this._ha1;default:zt.warn('get() | cannot get "%s" parameter',t);return}}authenticate({method:t,ruri:n,body:a},o,s=null){if(this._algorithm=o.algorithm,this._realm=o.realm,this._nonce=o.nonce,this._opaque=o.opaque,this._stale=o.stale,this._algorithm){if(this._algorithm!=="MD5")return zt.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return zt.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return zt.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return zt.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return zt.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(o.qop)if(o.qop.indexOf("auth-int")>-1)this._qop="auth-int";else if(o.qop.indexOf("auth")>-1)this._qop="auth";else return zt.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;else this._qop=null;this._method=t,this._uri=n,this._cnonce=s||ms.createRandomToken(12),this._nc+=1;const r=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-r.length)+r,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=ms.calculateMD5(`${this._credentials.username}:${this._realm}:${this._credentials.password}`):this._ha1=this._credentials.ha1;let d,h;return this._qop==="auth"?(d=`${this._method}:${this._uri}`,h=ms.calculateMD5(d),zt.debug('authenticate() | using qop=auth [a2:"%s"]',d),this._response=ms.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${h}`)):this._qop==="auth-int"?(d=`${this._method}:${this._uri}:${ms.calculateMD5(a||"")}`,h=ms.calculateMD5(d),zt.debug('authenticate() | using qop=auth-int [a2:"%s"]',d),this._response=ms.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${h}`)):this._qop===null&&(d=`${this._method}:${this._uri}`,h=ms.calculateMD5(d),zt.debug('authenticate() | using qop=null [a2:"%s"]',d),this._response=ms.calculateMD5(`${this._ha1}:${this._nonce}:${h}`)),zt.debug("authenticate() | response generated"),!0}toString(){const t=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return t.push(`algorithm=${this._algorithm}`),t.push(`username="${this._credentials.username}"`),t.push(`realm="${this._realm}"`),t.push(`nonce="${this._nonce}"`),t.push(`uri="${this._uri}"`),t.push(`response="${this._response}"`),this._opaque&&t.push(`opaque="${this._opaque}"`),this._qop&&(t.push(`qop=${this._qop}`),t.push(`cnonce="${this._cnonce}"`),t.push(`nc=${this._ncHex}`)),`Digest ${t.join(", ")}`}};const Dm=Me(Nf),gs=500,Nm=4e3,Uf=5e3;var Yo={T1:gs,T2:Nm,T4:Uf,TIMER_B:64*gs,TIMER_D:0*gs,TIMER_F:64*gs,TIMER_H:64*gs,TIMER_I:0*gs,TIMER_J:0*gs,TIMER_K:0*Uf,TIMER_L:64*gs,TIMER_M:64*gs,PROVISIONAL_RESPONSE_INTERVAL:6e4};const Vr=Me(Yo),Br=ct.EventEmitter,Gr=at,Wr=De,Pf=Tt,is=Yo,xf=new Gr("NonInviteClientTransaction"),la=new Gr("InviteClientTransaction"),Um=new Gr("AckClientTransaction"),kf=new Gr("NonInviteServerTransaction"),aa=new Gr("InviteServerTransaction"),fe={STATUS_TRYING:1,STATUS_PROCEEDING:2,STATUS_CALLING:3,STATUS_ACCEPTED:4,STATUS_COMPLETED:5,STATUS_TERMINATED:6,STATUS_CONFIRMED:7,NON_INVITE_CLIENT:"nict",NON_INVITE_SERVER:"nist",INVITE_CLIENT:"ict",INVITE_SERVER:"ist"};class Pm extends Br{constructor(t,n,a,o){super(),this.type=fe.NON_INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=t,this.transport=n,this.request=a,this.eventHandlers=o;let s=`SIP/2.0/${n.via_transport}`;s+=` ${t.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",s),this.ua.newTransaction(this)}get C(){return fe}stateChanged(t){this.state=t,this.emit("stateChanged")}send(){this.stateChanged(fe.STATUS_TRYING),this.F=setTimeout(()=>{this.timer_F()},is.TIMER_F),this.transport.send(this.request)||this.onTransportError()}onTransportError(){xf.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}timer_F(){xf.debug(`Timer F expired for transaction ${this.id}`),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}timer_K(){this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}receiveResponse(t){const n=t.status_code;if(n<200)switch(this.state){case fe.STATUS_TRYING:case fe.STATUS_PROCEEDING:this.stateChanged(fe.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(t);break}else switch(this.state){case fe.STATUS_TRYING:case fe.STATUS_PROCEEDING:this.stateChanged(fe.STATUS_COMPLETED),clearTimeout(this.F),n===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(t),this.K=setTimeout(()=>{this.timer_K()},is.TIMER_K);break;case fe.STATUS_COMPLETED:break}}}class xm extends Br{constructor(t,n,a,o){super(),this.type=fe.INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=t,this.transport=n,this.request=a,this.eventHandlers=o,a.transaction=this;let s=`SIP/2.0/${n.via_transport}`;s+=` ${t.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",s),this.ua.newTransaction(this)}get C(){return fe}stateChanged(t){this.state=t,this.emit("stateChanged")}send(){this.stateChanged(fe.STATUS_CALLING),this.B=setTimeout(()=>{this.timer_B()},is.TIMER_B),this.transport.send(this.request)||this.onTransportError()}onTransportError(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==fe.STATUS_ACCEPTED&&(la.debug(`transport error occurred, deleting transaction ${this.id}`),this.eventHandlers.onTransportError()),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_M(){la.debug(`Timer M expired for transaction ${this.id}`),this.state===fe.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this))}timer_B(){la.debug(`Timer B expired for transaction ${this.id}`),this.state===fe.STATUS_CALLING&&(this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}timer_D(){la.debug(`Timer D expired for transaction ${this.id}`),clearTimeout(this.B),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}sendACK(t){const n=new Pf.OutgoingRequest(Wr.ACK,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});n.setHeader("from",this.request.getHeader("from")),n.setHeader("via",this.request.getHeader("via")),n.setHeader("to",t.getHeader("to")),this.D=setTimeout(()=>{this.timer_D()},is.TIMER_D),this.transport.send(n)}cancel(t){if(this.state!==fe.STATUS_PROCEEDING)return;const n=new Pf.OutgoingRequest(Wr.CANCEL,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});n.setHeader("from",this.request.getHeader("from")),n.setHeader("via",this.request.getHeader("via")),n.setHeader("to",this.request.getHeader("to")),t&&n.setHeader("reason",t),this.transport.send(n)}receiveResponse(t){const n=t.status_code;if(n>=100&&n<=199)switch(this.state){case fe.STATUS_CALLING:this.stateChanged(fe.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(t);break;case fe.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(t);break}else if(n>=200&&n<=299)switch(this.state){case fe.STATUS_CALLING:case fe.STATUS_PROCEEDING:this.stateChanged(fe.STATUS_ACCEPTED),this.M=setTimeout(()=>{this.timer_M()},is.TIMER_M),this.eventHandlers.onReceiveResponse(t);break;case fe.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(t);break}else if(n>=300&&n<=699)switch(this.state){case fe.STATUS_CALLING:case fe.STATUS_PROCEEDING:this.stateChanged(fe.STATUS_COMPLETED),this.sendACK(t),this.eventHandlers.onReceiveResponse(t);break;case fe.STATUS_COMPLETED:this.sendACK(t);break}}}class km extends Br{constructor(t,n,a,o){super(),this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.transport=n,this.request=a,this.eventHandlers=o;let s=`SIP/2.0/${n.via_transport}`;s+=` ${t.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",s)}get C(){return fe}send(){this.transport.send(this.request)||this.onTransportError()}onTransportError(){Um.debug(`transport error occurred for transaction ${this.id}`),this.eventHandlers.onTransportError()}}class Mm extends Br{constructor(t,n,a){super(),this.type=fe.NON_INVITE_SERVER,this.id=a.via_branch,this.ua=t,this.transport=n,this.request=a,this.last_response="",a.server_transaction=this,this.state=fe.STATUS_TRYING,t.newTransaction(this)}get C(){return fe}stateChanged(t){this.state=t,this.emit("stateChanged")}timer_J(){kf.debug(`Timer J expired for transaction ${this.id}`),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}onTransportError(){this.transportError||(this.transportError=!0,kf.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.J),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this))}receiveResponse(t,n,a,o){if(t===100)switch(this.state){case fe.STATUS_TRYING:this.stateChanged(fe.STATUS_PROCEEDING),this.transport.send(n)||this.onTransportError();break;case fe.STATUS_PROCEEDING:this.last_response=n,this.transport.send(n)?a&&a():(this.onTransportError(),o&&o());break}else if(t>=200&&t<=699)switch(this.state){case fe.STATUS_TRYING:case fe.STATUS_PROCEEDING:this.stateChanged(fe.STATUS_COMPLETED),this.last_response=n,this.J=setTimeout(()=>{this.timer_J()},is.TIMER_J),this.transport.send(n)?a&&a():(this.onTransportError(),o&&o());break;case fe.STATUS_COMPLETED:break}}}class Lm extends Br{constructor(t,n,a){super(),this.type=fe.INVITE_SERVER,this.id=a.via_branch,this.ua=t,this.transport=n,this.request=a,this.last_response="",a.server_transaction=this,this.state=fe.STATUS_PROCEEDING,t.newTransaction(this),this.resendProvisionalTimer=null,a.reply(100)}get C(){return fe}stateChanged(t){this.state=t,this.emit("stateChanged")}timer_H(){aa.debug(`Timer H expired for transaction ${this.id}`),this.state===fe.STATUS_COMPLETED&&aa.debug("ACK not received, dialog will be terminated"),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_I(){this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_L(){aa.debug(`Timer L expired for transaction ${this.id}`),this.state===fe.STATUS_ACCEPTED&&(this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this))}onTransportError(){this.transportError||(this.transportError=!0,aa.debug(`transport error occurred, deleting transaction ${this.id}`),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this))}resend_provisional(){this.transport.send(this.last_response)||this.onTransportError()}receiveResponse(t,n,a,o){if(t>=100&&t<=199)switch(this.state){case fe.STATUS_PROCEEDING:this.transport.send(n)||this.onTransportError(),this.last_response=n;break}if(t>100&&t<=199&&this.state===fe.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(()=>{this.resend_provisional()},is.PROVISIONAL_RESPONSE_INTERVAL));else if(t>=200&&t<=299)switch(this.state){case fe.STATUS_PROCEEDING:this.stateChanged(fe.STATUS_ACCEPTED),this.last_response=n,this.L=setTimeout(()=>{this.timer_L()},is.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case fe.STATUS_ACCEPTED:this.transport.send(n)?a&&a():(this.onTransportError(),o&&o());break}else if(t>=300&&t<=699)switch(this.state){case fe.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(n)?(this.stateChanged(fe.STATUS_COMPLETED),this.H=setTimeout(()=>{this.timer_H()},is.TIMER_H),a&&a()):(this.onTransportError(),o&&o());break}}}function $m({_transactions:c},t){let n;switch(t.method){case Wr.INVITE:if(n=c.ist[t.via_branch],n){switch(n.state){case fe.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case fe.STATUS_ACCEPTED:break}return!0}break;case Wr.ACK:if(n=c.ist[t.via_branch],n){if(n.state===fe.STATUS_ACCEPTED)return!1;if(n.state===fe.STATUS_COMPLETED)return n.state=fe.STATUS_CONFIRMED,n.I=setTimeout(()=>{n.timer_I()},is.TIMER_I),!0}else return!1;break;case Wr.CANCEL:return n=c.ist[t.via_branch],n?(t.reply_sl(200),n.state!==fe.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=c.nist[t.via_branch],n){switch(n.state){case fe.STATUS_TRYING:break;case fe.STATUS_PROCEEDING:case fe.STATUS_COMPLETED:n.transport.send(n.last_response);break}return!0}break}}var Hn={C:fe,NonInviteClientTransaction:Pm,InviteClientTransaction:xm,AckClientTransaction:km,NonInviteServerTransaction:Mm,InviteServerTransaction:Lm,checkTransaction:$m};const jt=Me(Hn),Hm=at,Mf=De,Fm=Nf,Jo=Hn,jm=new Hm("RequestSender"),zo={onRequestTimeout:()=>{},onTransportError:()=>{},onReceiveResponse:()=>{},onAuthenticated:()=>{}};var Fn=class{constructor(t,n,a){this._ua=t,this._eventHandlers=a,this._method=n.method,this._request=n,this._auth=null,this._challenged=!1,this._staled=!1;for(const o in zo)Object.prototype.hasOwnProperty.call(zo,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=zo[o]));t.status===t.C.STATUS_USER_CLOSED&&(this._method!==Mf.BYE||this._method!==Mf.ACK)&&this._eventHandlers.onTransportError()}send(){const t={onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onReceiveResponse:n=>{this._receiveResponse(n)}};switch(this._method){case"INVITE":this.clientTransaction=new Jo.InviteClientTransaction(this._ua,this._ua.transport,this._request,t);break;case"ACK":this.clientTransaction=new Jo.AckClientTransaction(this._ua,this._ua.transport,this._request,t);break;default:this.clientTransaction=new Jo.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,t)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}_receiveResponse(t){let n,a;const o=t.status_code;if((o===401||o===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(t.status_code===401?(n=t.parseHeader("www-authenticate"),a="authorization"):(n=t.parseHeader("proxy-authenticate"),a="proxy-authorization"),!n){jm.debug(`${t.status_code} with wrong or missing challenge, cannot authenticate`),this._eventHandlers.onReceiveResponse(t);return}if(!this._challenged||!this._staled&&n.stale===!0){if(this._auth||(this._auth=new Fm({username:this._ua.configuration.authorization_user,password:this._ua.configuration.password,realm:this._ua.configuration.realm,ha1:this._ua.configuration.ha1})),!this._auth.authenticate(this._request,n)){this._eventHandlers.onReceiveResponse(t);return}this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),n.stale&&(this._staled=!0),this._request=this._request.clone(),this._request.cseq+=1,this._request.setHeader("cseq",`${this._request.cseq} ${this._method}`),this._request.setHeader(a,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(t)}else this._eventHandlers.onReceiveResponse(t)}};const Kr=Me(Fn),qm=at,Xo=mt(),tn=De,Lf=Tt,$f=Fn,Yr=new qm("Registrator"),oa=10;var Vm=class{constructor(t,n){this._reg_id=1,this._ua=t,this._transport=n,this._registrar=t.configuration.registrar_server,this._expires=t.configuration.register_expires,this._call_id=Xo.createRandomToken(22),this._cseq=0,this._to_uri=t.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString(),this._contact+=";+sip.ice",this._extraHeaders=[],this._extraContactParams="",this._sipInstance=`"<urn:uuid:${this._ua.configuration.instance_id}>"`,this._contact+=`;reg-id=${this._reg_id}`,this._contact+=`;+sip.instance=${this._sipInstance}`}get registered(){return this._registered}setExtraHeaders(t){Array.isArray(t)||(t=[]),this._extraHeaders=t.slice()}setExtraContactParams(t){t instanceof Object||(t={}),this._extraContactParams="";for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)){const a=t[n];this._extraContactParams+=`;${n}`,a&&(this._extraContactParams+=`=${a}`)}}register(){if(this._registering){Yr.debug("Register request in progress...");return}const t=this._extraHeaders.slice();t.push(`Contact: ${this._contact};expires=${this._expires}${this._extraContactParams}`),t.push(`Expires: ${this._expires}`);const n=new Lf.OutgoingRequest(tn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),a=new $f(this._ua,n,{onRequestTimeout:()=>{this._registrationFailure(null,tn.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,tn.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:o=>{if(o.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):{if(this._registering=!1,!o.hasHeader("Contact")){Yr.debug("no Contact header in response to REGISTER, response ignored");break}const s=o.headers.Contact.reduce((_,g)=>_.concat(g.parsed),[]);let r=s.find(_=>this._sipInstance===_.getParam("+sip.instance")&&this._reg_id===parseInt(_.getParam("reg-id")));if(r||(r=s.find(_=>_.uri.user===this._ua.contact.uri.user)),!r){Yr.debug("no Contact header pointing to us, response ignored");break}let d=r.getParam("expires");!d&&o.hasHeader("expires")&&(d=o.getHeader("expires")),d||(d=this._expires),d=Number(d),d<oa&&(d=oa);const h=d>64?d*1e3/2+Math.floor((d/2-32)*1e3*Math.random()):d*1e3-5e3;this._registrationTimer=setTimeout(()=>{this._registrationTimer=null,this._ua.listeners("registrationExpiring").length===0?this.register():this._ua.emit("registrationExpiring")},h),r.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),this._registered||(this._registered=!0,this._ua.registered({response:o}));break}case/^423$/.test(o.status_code):{o.hasHeader("min-expires")?(this._expires=Number(o.getHeader("min-expires")),this._expires<oa&&(this._expires=oa),this.register()):(Yr.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(o,tn.causes.SIP_FAILURE_CODE));break}default:{const s=Xo.sipErrorCause(o.status_code);this._registrationFailure(o,s)}}}});this._registering=!0,a.send()}unregister(t={}){if(!this._registered){Yr.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const n=this._extraHeaders.slice();t.all?n.push(`Contact: *${this._extraContactParams}`):n.push(`Contact: ${this._contact};expires=0${this._extraContactParams}`),n.push("Expires: 0");const a=new Lf.OutgoingRequest(tn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new $f(this._ua,a,{onRequestTimeout:()=>{this._unregistered(null,tn.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,tn.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:s=>{switch(!0){case/^1[0-9]{2}$/.test(s.status_code):break;case/^2[0-9]{2}$/.test(s.status_code):this._unregistered(s);break;default:{const r=Xo.sipErrorCause(s.status_code);this._unregistered(s,r)}}}}).send()}close(){this._registered&&this.unregister()}onTransportClosed(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}_registrationFailure(t,n){this._registering=!1,this._ua.registrationFailed({response:t||null,cause:n}),this._registered&&(this._registered=!1,this._ua.unregistered({response:t||null,cause:n}))}_unregistered(t,n){this._registering=!1,this._registered=!1,this._ua.unregistered({response:t||null,cause:n||null})}};class Bm extends Error{constructor(t,n){super(),this.code=1,this.name="CONFIGURATION_ERROR",this.parameter=t,this.value=n,this.message=this.value?`Invalid value ${JSON.stringify(this.value)} for parameter "${this.parameter}"`:`Missing parameter: ${this.parameter}`}}class Gm extends Error{constructor(t){super(),this.code=2,this.name="INVALID_STATE_ERROR",this.status=t,this.message=`Invalid status: ${t}`}}class Wm extends Error{constructor(t){super(),this.code=3,this.name="NOT_SUPPORTED_ERROR",this.message=t}}class Km extends Error{constructor(t){super(),this.code=4,this.name="NOT_READY_ERROR",this.message=t}}var Ts={ConfigurationError:Bm,InvalidStateError:Gm,NotSupportedError:Wm,NotReadyError:Km};const Ns=Me(Ts),Qo=De,ua=Hn,Ym=Fn,Zo={onRequestTimeout:()=>{},onTransportError:()=>{},onSuccessResponse:()=>{},onErrorResponse:()=>{},onAuthenticated:()=>{},onDialogError:()=>{}};var Hf=class{constructor(t,n,a){this._dialog=t,this._ua=t._ua,this._request=n,this._eventHandlers=a,this._reattempt=!1,this._reattemptTimer=null;for(const o in Zo)Object.prototype.hasOwnProperty.call(Zo,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=Zo[o]))}get request(){return this._request}send(){const t=new Ym(this._ua,this._request,{onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onAuthenticated:n=>{this._eventHandlers.onAuthenticated(n)},onReceiveResponse:n=>{this._receiveResponse(n)}});if(t.send(),(this._request.method===Qo.INVITE||this._request.method===Qo.UPDATE&&this._request.body)&&t.clientTransaction.state!==ua.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;const n=()=>{(t.clientTransaction.state===ua.C.STATUS_ACCEPTED||t.clientTransaction.state===ua.C.STATUS_COMPLETED||t.clientTransaction.state===ua.C.STATUS_TERMINATED)&&(t.clientTransaction.removeListener("stateChanged",n),this._dialog.uac_pending_reply=!1)};t.clientTransaction.on("stateChanged",n)}}_receiveResponse(t){t.status_code===408||t.status_code===481?this._eventHandlers.onDialogError(t):t.method===Qo.INVITE&&t.status_code===491?this._reattempt?t.status_code>=200&&t.status_code<300?this._eventHandlers.onSuccessResponse(t):t.status_code>=300&&this._eventHandlers.onErrorResponse(t):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(()=>{this._dialog.isTerminated()||(this._reattempt=!0,this.send())},1e3)):t.status_code>=200&&t.status_code<300?this._eventHandlers.onSuccessResponse(t):t.status_code>=300&&this._eventHandlers.onErrorResponse(t)}};const Jm=Me(Hf),zm=at,Ff=Tt,Us=De,Jr=Hn,Xm=Hf,eu=mt(),tu=new zm("Dialog"),Ps={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};var jf=class{static get C(){return Ps}constructor(t,n,a,o=Ps.STATUS_CONFIRMED){if(this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!n.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};n instanceof Ff.IncomingResponse&&(o=n.status_code<200?Ps.STATUS_EARLY:Ps.STATUS_CONFIRMED);const s=n.parseHeader("contact");a==="UAS"?(this._id={call_id:n.call_id,local_tag:n.to_tag,remote_tag:n.from_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri,this._remote_target=s.uri,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):a==="UAC"&&(this._id={call_id:n.call_id,local_tag:n.from_tag,remote_tag:n.to_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=s.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),tu.debug(`new ${a} dialog created with status ${this._state===Ps.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(t){this._local_seqnum=t}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(t){this._uac_pending_reply=t}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===Ps.STATUS_TERMINATED}update(t,n){this._state=Ps.STATUS_CONFIRMED,tu.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),n==="UAC"&&(this._route_set=t.getHeaders("record-route").reverse())}terminate(){tu.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Ps.STATUS_TERMINATED}sendRequest(t,n={}){const a=eu.cloneArray(n.extraHeaders),o=eu.cloneObject(n.eventHandlers),s=n.body||null,r=this._createRequest(t,a,s);return o.onAuthenticated=()=>{this._local_seqnum+=1},new Xm(this,r,o).send(),r}receiveRequest(t){this._checkInDialogRequest(t)&&(t.method===Us.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:t.method===Us.INVITE&&(this._ack_seqnum=t.cseq),this._owner.receiveRequest(t))}_createRequest(t,n,a){n=eu.cloneArray(n),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const o=t===Us.CANCEL||t===Us.ACK?this._local_seqnum:this._local_seqnum+=1;return new Ff.OutgoingRequest(t,this._remote_target,this._ua,{cseq:o,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},n,a)}_checkInDialogRequest(t){if(!this._remote_seqnum)this._remote_seqnum=t.cseq;else if(t.cseq<this._remote_seqnum)if(t.method===Us.ACK){if(this._ack_seqnum===null||t.cseq!==this._ack_seqnum)return!1}else return t.reply(500),!1;else t.cseq>this._remote_seqnum&&(this._remote_seqnum=t.cseq);if(t.method===Us.INVITE||t.method===Us.UPDATE&&t.body){if(this._uac_pending_reply===!0)t.reply(491);else if(this._uas_pending_reply===!0){const n=(Math.random()*10|0)+1;return t.reply(500,null,[`Retry-After:${n}`]),!1}else{this._uas_pending_reply=!0;const n=()=>{(t.server_transaction.state===Jr.C.STATUS_ACCEPTED||t.server_transaction.state===Jr.C.STATUS_COMPLETED||t.server_transaction.state===Jr.C.STATUS_TERMINATED)&&(t.server_transaction.removeListener("stateChanged",n),this._uas_pending_reply=!1)};t.server_transaction.on("stateChanged",n)}t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===Jr.C.STATUS_ACCEPTED&&(this._remote_target=t.parseHeader("contact").uri)})}else t.method===Us.NOTIFY&&t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===Jr.C.STATUS_COMPLETED&&(this._remote_target=t.parseHeader("contact").uri)});return!0}};const ca=Me(jf);var su={exports:{}};const Qm=ct.EventEmitter,Zm=at,eg=De,tg=Ts,qf=mt(),sg=new Zm("RTCSession:DTMF"),Vf={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};su.exports=class extends Qm{constructor(t){super(),this._session=t,this._direction=null,this._tone=null,this._duration=null,this._request=null}get tone(){return this._tone}get duration(){return this._duration}send(t,n={}){if(t===void 0)throw new TypeError("Not enough arguments");if(this._direction="outgoing",this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new tg.InvalidStateError(this._session.status);const a=qf.cloneArray(n.extraHeaders);if(this.eventHandlers=qf.cloneObject(n.eventHandlers),typeof t=="string")t=t.toUpperCase();else if(typeof t=="number")t=t.toString();else throw new TypeError(`Invalid tone: ${t}`);if(t.match(/^[0-9A-DR#*]$/))this._tone=t;else throw new TypeError(`Invalid tone: ${t}`);this._duration=n.duration,a.push("Content-Type: application/dtmf-relay");let o=`Signal=${this._tone}\r
|
113
113
|
`;o+=`Duration=${this._duration}`,this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(eg.INFO,{extraHeaders:a,eventHandlers:{onSuccessResponse:s=>{this.emit("succeeded",{originator:"remote",response:s})},onErrorResponse:s=>{this.eventHandlers.onFailed&&this.eventHandlers.onFailed(),this.emit("failed",{originator:"remote",response:s})},onRequestTimeout:()=>{this._session.onRequestTimeout()},onTransportError:()=>{this._session.onTransportError()},onDialogError:()=>{this._session.onDialogError()}},body:o})}init_incoming(t){const n=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,a=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=t,t.reply(200),t.body){const o=t.body.split(`
|
114
114
|
`);o.length>=1&&n.test(o[0])&&(this._tone=o[0].replace(n,"$2")),o.length>=2&&a.test(o[1])&&(this._duration=parseInt(o[1].replace(a,"$2"),10))}this._duration||(this._duration=Vf.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:t}):sg.debug("invalid INFO DTMF received, discarded")}},su.exports.C=Vf;var Bf=su.exports;const ng=Me(Bf),rg=ct.EventEmitter,ig=De,lg=Ts,ag=mt();var Gf=class extends rg{constructor(t){super(),this._session=t,this._direction=null,this._contentType=null,this._body=null}get contentType(){return this._contentType}get body(){return this._body}send(t,n,a={}){if(this._direction="outgoing",t===void 0)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new lg.InvalidStateError(this._session.status);this._contentType=t,this._body=n;const o=ag.cloneArray(a.extraHeaders);o.push(`Content-Type: ${t}`),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(ig.INFO,{extraHeaders:o,eventHandlers:{onSuccessResponse:s=>{this.emit("succeeded",{originator:"remote",response:s})},onErrorResponse:s=>{this.emit("failed",{originator:"remote",response:s})},onTransportError:()=>{this._session.onTransportError()},onRequestTimeout:()=>{this._session.onRequestTimeout()},onDialogError:()=>{this._session.onDialogError()}},body:n})}init_incoming(t){this._direction="incoming",this.request=t,t.reply(200),this._contentType=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,this._body=t.body,this._session.newInfo({originator:"remote",info:this,request:t})}};const nu=Me(Gf),og=at,Wf=De,ug=new og("RTCSession:ReferNotifier"),ru={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300};var Kf=class{constructor(t,n,a){this._session=t,this._id=n,this._expires=a||ru.expires,this._active=!0,this.notify(100)}notify(t,n){if(ug.debug("notify()"),this._active===!1)return;n=n||Wf.REASON_PHRASE[t]||"";let a;t>=200?a="terminated;reason=noresource":a=`active;expires=${this._expires}`,this._session.sendRequest(Wf.NOTIFY,{extraHeaders:[`Event: ${ru.event_type};id=${this._id}`,`Subscription-State: ${a}`,`Content-Type: ${ru.body_type}`],body:`SIP/2.0 ${t} ${n}`,eventHandlers:{onErrorResponse(){this._active=!1}}})}};const cg=Me(Kf),fg=ct.EventEmitter,hg=at,zr=De,dg=Jt(),Yf=mt(),sn=new hg("RTCSession:ReferSubscriber");var Jf=class extends fg{constructor(t){super(),this._id=null,this._session=t}get id(){return this._id}sendRefer(t,n={}){sn.debug("sendRefer()");const a=Yf.cloneArray(n.extraHeaders),o=Yf.cloneObject(n.eventHandlers);for(const h in o)Object.prototype.hasOwnProperty.call(o,h)&&this.on(h,o[h]);let s=null;n.replaces&&(s=n.replaces._request.call_id,s+=`;to-tag=${n.replaces._to_tag}`,s+=`;from-tag=${n.replaces._from_tag}`,s=encodeURIComponent(s));const r=`Refer-To: <${t}${s?`?Replaces=${s}`:""}>`;if(a.push(r),!a.some(h=>h.toLowerCase().startsWith("referred-by:"))){const h=`Referred-By: <${this._session._ua._configuration.uri._scheme}:${this._session._ua._configuration.uri._user}@${this._session._ua._configuration.uri._host}>`;a.push(h)}a.push(`Contact: ${this._session.contact}`);const d=this._session.sendRequest(zr.REFER,{extraHeaders:a,eventHandlers:{onSuccessResponse:h=>{this._requestSucceeded(h)},onErrorResponse:h=>{this._requestFailed(h,zr.causes.REJECTED)},onTransportError:()=>{this._requestFailed(null,zr.causes.CONNECTION_ERROR)},onRequestTimeout:()=>{this._requestFailed(null,zr.causes.REQUEST_TIMEOUT)},onDialogError:()=>{this._requestFailed(null,zr.causes.DIALOG_ERROR)}}});this._id=d.cseq}receiveNotify(t){if(sn.debug("receiveNotify()"),!t.body)return;const n=dg.parse(t.body.trim().split(`\r
|
115
|
-
`,1)[0],"Status_Line");if(n===-1){sn.debug(`receiveNotify() | error parsing NOTIFY body: "${t.body}"`);return}switch(!0){case/^100$/.test(n.status_code):this.emit("trying",{request:t,status_line:n});break;case/^1[0-9]{2}$/.test(n.status_code):this.emit("progress",{request:t,status_line:n});break;case/^2[0-9]{2}$/.test(n.status_code):this.emit("accepted",{request:t,status_line:n});break;default:this.emit("failed",{request:t,status_line:n});break}}_requestSucceeded(t){sn.debug("REFER succeeded"),sn.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:t})}_requestFailed(t,n){sn.debug("REFER failed"),sn.debug('emit "requestFailed"'),this.emit("requestFailed",{response:t||null,cause:n})}};const _g=Me(Jf),pg=ct.EventEmitter,zf=Ut,mg=at,he=De,nn=Ts,Xf=Hn,Ge=mt(),Xr=Yo,gg=Tt,fa=jf,Tg=Fn,$t=Bf,Qf=Gf,vg=Kf,Eg=Jf,Zf=ps(),K=new mg("RTCSession"),Q={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9},ha=["audio","video"];var eh=class Wu extends pg{static get C(){return Q}constructor(t){K.debug("new"),super(),this._id=null,this._ua=t,this._status=Q.STATUS_NULL,this._dialog=null,this._earlyDialogs={},this._contact=null,this._from_tag=null,this._to_tag=null,this._connection=null,this._connectionPromiseQueue=Promise.resolve(),this._request=null,this._is_canceled=!1,this._cancel_reason="",this._is_confirmed=!1,this._late_sdp=!1,this._rtcOfferConstraints=null,this._rtcAnswerConstraints=null,this._localMediaStream=null,this._localMediaStreamLocallyGenerated=!1,this._rtcReady=!0,this._iceReady=!1,this._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},this._direction=null,this._local_identity=null,this._remote_identity=null,this._start_time=null,this._end_time=null,this._tones=null,this._audioMuted=!1,this._videoMuted=!1,this._localHold=!1,this._remoteHold=!1,this._sessionTimers={enabled:this._ua.configuration.session_timers,refreshMethod:this._ua.configuration.session_timers_refresh_method,defaultExpires:he.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._referSubscribers={},this._data={}}get C(){return Q}get causes(){return he.causes}get id(){return this._id}get connection(){return this._connection}get contact(){return this._contact}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}get start_time(){return this._start_time}get end_time(){return this._end_time}get data(){return this._data}set data(t){this._data=t}get status(){return this._status}isInProgress(){switch(this._status){case Q.STATUS_NULL:case Q.STATUS_INVITE_SENT:case Q.STATUS_1XX_RECEIVED:case Q.STATUS_INVITE_RECEIVED:case Q.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case Q.STATUS_ANSWERED:case Q.STATUS_WAITING_FOR_ACK:case Q.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case Q.STATUS_CANCELED:case Q.STATUS_TERMINATED:return!0;default:return!1}}isMuted(){return{audio:this._audioMuted,video:this._videoMuted}}isOnHold(){return{local:this._localHold,remote:this._remoteHold}}connect(t,n={},a){K.debug("connect()");const o=t,s=Ge.cloneObject(n.eventHandlers),r=Ge.cloneArray(n.extraHeaders),d=Ge.cloneObject(n.mediaConstraints,{audio:!0,video:!0}),h=n.mediaStream||null,_=Ge.cloneObject(n.pcConfig,{iceServers:[]}),g=n.rtcConstraints||null,T=n.rtcOfferConstraints||null;if(this._rtcOfferConstraints=T,this._rtcAnswerConstraints=n.rtcAnswerConstraints||null,this._data=n.data||this._data,t===void 0)throw new TypeError("Not enough arguments");if(this._status!==Q.STATUS_NULL)throw new nn.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new nn.NotSupportedError("WebRTC not supported");if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${o}`);this._sessionTimers.enabled&&Ge.isDecimal(n.sessionTimersExpires)&&(n.sessionTimersExpires>=he.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=n.sessionTimersExpires:this._sessionTimers.defaultExpires=he.SESSION_EXPIRES);for(const A in s)Object.prototype.hasOwnProperty.call(s,A)&&this.on(A,s[A]);this._from_tag=Ge.newTag();const E=n.anonymous||!1,y={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:E,outbound:!0}),E?(y.from_display_name="Anonymous",y.from_uri=new Zf("sip","anonymous","anonymous.invalid"),r.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),r.push("Privacy: id")):n.fromUserName&&(y.from_uri=new Zf("sip",n.fromUserName,this._ua.configuration.uri.host),r.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),n.fromDisplayName&&(y.from_display_name=n.fromDisplayName),r.push(`Contact: ${this._contact}`),r.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&r.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new gg.InitialOutgoingInviteRequest(t,this._ua,y,r),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(_,g),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,a&&a(this),this._newRTCSession("local",this._request),this._sendInitialRequest(d,T,h)}init_incoming(t,n){K.debug("init_incoming()");let a;const o=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;if(t.body&&o!=="application/sdp"){t.reply(415);return}if(this._status=Q.STATUS_INVITE_RECEIVED,this._from_tag=t.from_tag,this._id=t.call_id+this._from_tag,this._request=t,this._contact=this._ua.contact.toString(),t.hasHeader("expires")&&(a=t.getHeader("expires")*1e3),t.to_tag=Ge.newTag(),!this._createDialog(t,"UAS",!0)){t.reply(500,"Missing Contact header field");return}t.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Q.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{t.reply(408),this._failed("local",null,he.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),a&&(this._timers.expiresTimer=setTimeout(()=>{this._status===Q.STATUS_WAITING_FOR_ANSWER&&(t.reply(487),this._failed("system",null,he.causes.EXPIRES))},a)),this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from,n&&n(this),this._newRTCSession("remote",t),this._status!==Q.STATUS_TERMINATED&&(t.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(t={}){K.debug("answer()");const n=this._request,a=Ge.cloneArray(t.extraHeaders),o=Ge.cloneObject(t.mediaConstraints),s=t.mediaStream||null,r=Ge.cloneObject(t.pcConfig,{iceServers:[]}),d=t.rtcConstraints||null,h=t.rtcAnswerConstraints||null,_=Ge.cloneObject(t.rtcOfferConstraints);let g,T=!1,E=!1,y=!1,A=!1;if(this._rtcAnswerConstraints=h,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,this._direction!=="incoming")throw new nn.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==Q.STATUS_WAITING_FOR_ANSWER)throw new nn.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Ge.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=he.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=he.SESSION_EXPIRES),this._status=Q.STATUS_ANSWERED,!this._createDialog(n,"UAS")){n.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),a.unshift(`Contact: ${this._contact}`);const C=n.parseSDP();Array.isArray(C.media)||(C.media=[C.media]);for(const I of C.media)I.type==="audio"&&(T=!0,(!I.direction||I.direction==="sendrecv")&&(y=!0)),I.type==="video"&&(E=!0,(!I.direction||I.direction==="sendrecv")&&(A=!0));if(s&&o.audio===!1){g=s.getAudioTracks();for(const I of g)s.removeTrack(I)}if(s&&o.video===!1){g=s.getVideoTracks();for(const I of g)s.removeTrack(I)}!s&&o.audio===void 0&&(o.audio=y),!s&&o.video===void 0&&(o.video=A),!s&&!T&&!_.offerToReceiveAudio&&(o.audio=!1),!s&&!E&&!_.offerToReceiveVideo&&(o.video=!1),this._createRTCConnection(r,d),Promise.resolve().then(()=>{if(s)return s;if(o.audio||o.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(o).catch(I=>{throw this._status===Q.STATUS_TERMINATED?new Error("terminated"):(n.reply(480),this._failed("local",null,he.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',I),this.emit("getusermediafailed",I),new Error("getUserMedia() failed"))})}).then(I=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=I,I&&I.getTracks().forEach(H=>{this._connection.addTrack(H,I)})}).then(()=>{if(this._late_sdp)return;const I={originator:"remote",type:"offer",sdp:n.body};K.debug('emit "sdp"'),this.emit("sdp",I);const H=new RTCSessionDescription({type:"offer",sdp:I.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(H)).catch($=>{throw n.reply(488),this._failed("system",null,he.causes.WEBRTC_ERROR),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',$),this.emit("peerconnection:setremotedescriptionfailed",$),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(n),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",h).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(I=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,a),n.reply(200,null,a,I,()=>{this._status=Q.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,I),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,he.causes.CONNECTION_ERROR)})}).catch(I=>{this._status!==Q.STATUS_TERMINATED&&K.warn(I)})}terminate(t={}){K.debug("terminate()");const n=t.cause||he.causes.BYE,a=Ge.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,d=t.reason_phrase;if(this._status===Q.STATUS_TERMINATED)throw new nn.InvalidStateError(this._status);switch(this._status){case Q.STATUS_NULL:case Q.STATUS_INVITE_SENT:case Q.STATUS_1XX_RECEIVED:if(K.debug("canceling session"),r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);r&&(d=d||he.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${d}"`),this._status===Q.STATUS_NULL||this._status===Q.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===Q.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=Q.STATUS_CANCELED,this._failed("local",null,he.causes.CANCELED);break;case Q.STATUS_WAITING_FOR_ANSWER:case Q.STATUS_ANSWERED:if(K.debug("rejecting session"),r=r||480,r<300||r>=700)throw new TypeError(`Invalid status_code: ${r}`);this._request.reply(r,d,a,o),this._failed("local",null,he.causes.REJECTED);break;case Q.STATUS_WAITING_FOR_ACK:case Q.STATUS_CONFIRMED:if(K.debug("terminating session"),d=t.reason_phrase||he.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);if(r&&a.push(`Reason: SIP ;cause=${r}; text="${d}"`),this._status===Q.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Xf.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:_})=>{_===he.ACK&&(this.sendRequest(he.BYE,{extraHeaders:a,body:o}),h.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Xf.C.STATUS_TERMINATED&&(this.sendRequest(he.BYE,{extraHeaders:a,body:o}),h.terminate())}),this._ended("local",null,n),this._dialog=h,this._ua.newDialog(h)}else this.sendRequest(he.BYE,{extraHeaders:a,body:o}),this._ended("local",null,n)}}sendDTMF(t,n={}){K.debug("sendDTMF() | tones: %s",t);let a=0,o=n.duration||null,s=n.interToneGap||null;const r=n.transportType||he.DTMF_TRANSPORT.INFO;if(t===void 0)throw new TypeError("Not enough arguments");if(this._status!==Q.STATUS_CONFIRMED&&this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_1XX_RECEIVED)throw new nn.InvalidStateError(this._status);if(r!==he.DTMF_TRANSPORT.INFO&&r!==he.DTMF_TRANSPORT.RFC2833)throw new TypeError(`invalid transportType: ${r}`);if(typeof t=="number"&&(t=t.toString()),!t||typeof t!="string"||!t.match(/^[0-9A-DR#*,]+$/i))throw new TypeError(`Invalid tones: ${t}`);if(o&&!Ge.isDecimal(o))throw new TypeError(`Invalid tone duration: ${o}`);if(o?o<$t.C.MIN_DURATION?(K.debug(`"duration" value is lower than the minimum allowed, setting it to ${$t.C.MIN_DURATION} milliseconds`),o=$t.C.MIN_DURATION):o>$t.C.MAX_DURATION?(K.debug(`"duration" value is greater than the maximum allowed, setting it to ${$t.C.MAX_DURATION} milliseconds`),o=$t.C.MAX_DURATION):o=Math.abs(o):o=$t.C.DEFAULT_DURATION,n.duration=o,s&&!Ge.isDecimal(s))throw new TypeError(`Invalid interToneGap: ${s}`);if(s?s<$t.C.MIN_INTER_TONE_GAP?(K.debug(`"interToneGap" value is lower than the minimum allowed, setting it to ${$t.C.MIN_INTER_TONE_GAP} milliseconds`),s=$t.C.MIN_INTER_TONE_GAP):s=Math.abs(s):s=$t.C.DEFAULT_INTER_TONE_GAP,r===he.DTMF_TRANSPORT.RFC2833){const h=this._getDTMFRTPSender();h&&(t=h.toneBuffer+t,h.insertDTMF(t,o,s));return}if(this._tones){this._tones+=t;return}this._tones=t,d.call(this);function d(){let h;if(this._status===Q.STATUS_TERMINATED||!this._tones||a>=this._tones.length){this._tones=null;return}const _=this._tones[a];if(a+=1,_===",")h=2e3;else{const g=new $t(this);n.eventHandlers={onFailed:()=>{this._tones=null}},g.send(_,n),h=o+s}setTimeout(d.bind(this),h)}}sendInfo(t,n,a={}){if(K.debug("sendInfo()"),this._status!==Q.STATUS_CONFIRMED&&this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_1XX_RECEIVED)throw new nn.InvalidStateError(this._status);new Qf(this).send(t,n,a)}mute(t={audio:!0,video:!1}){K.debug("mute()");let n=!1,a=!1;this._audioMuted===!1&&t.audio&&(n=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&t.video&&(a=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(n===!0||a===!0)&&this._onmute({audio:n,video:a})}unmute(t={audio:!0,video:!0}){K.debug("unmute()");let n=!1,a=!1;this._audioMuted===!0&&t.audio&&(n=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&t.video&&(a=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(n===!0||a===!0)&&this._onunmute({audio:n,video:a})}hold(t={},n){if(K.debug("hold()"),this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:he.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}unhold(t={},n){if(K.debug("unhold()"),this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:he.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}renegotiate(t={},n){K.debug("renegotiate()");const a=t.rtcOfferConstraints||null;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const o={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:he.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}),!0}refer(t,n){K.debug("refer()");const a=t;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${a}`);const o=new Eg(this);o.sendRefer(t,n);const s=o.id;return this._referSubscribers[s]=o,o.on("requestFailed",()=>{delete this._referSubscribers[s]}),o.on("accepted",()=>{delete this._referSubscribers[s]}),o.on("failed",()=>{delete this._referSubscribers[s]}),o}sendRequest(t,n){return K.debug("sendRequest()"),this._dialog.sendRequest(t,n)}receiveRequest(t){if(K.debug("receiveRequest()"),t.method===he.CANCEL)(this._status===Q.STATUS_WAITING_FOR_ANSWER||this._status===Q.STATUS_ANSWERED)&&(this._status=Q.STATUS_CANCELED,this._request.reply(487),this._failed("remote",t,he.causes.CANCELED));else switch(t.method){case he.ACK:if(this._status!==Q.STATUS_WAITING_FOR_ACK)return;if(this._status=Q.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!t.body){this.terminate({cause:he.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:t.body};K.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>{this._is_confirmed||this._confirmed("remote",t)}).catch(o=>{this.terminate({cause:he.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})}else this._is_confirmed||this._confirmed("remote",t);break;case he.BYE:this._status===Q.STATUS_CONFIRMED||this._status===Q.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,he.causes.BYE)):this._status===Q.STATUS_INVITE_RECEIVED||this._status===Q.STATUS_WAITING_FOR_ANSWER?(t.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",t,he.causes.BYE)):t.reply(403,"Wrong Status");break;case he.INVITE:this._status===Q.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case he.INFO:if(this._status===Q.STATUS_1XX_RECEIVED||this._status===Q.STATUS_WAITING_FOR_ANSWER||this._status===Q.STATUS_ANSWERED||this._status===Q.STATUS_WAITING_FOR_ACK||this._status===Q.STATUS_CONFIRMED){const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;n&&n.match(/^application\/dtmf-relay/i)?new $t(this).init_incoming(t):n!==void 0?new Qf(this).init_incoming(t):t.reply(415)}else t.reply(403,"Wrong Status");break;case he.UPDATE:this._status===Q.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case he.REFER:this._status===Q.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case he.NOTIFY:this._status===Q.STATUS_CONFIRMED?this._receiveNotify(t):t.reply(403,"Wrong Status");break;default:t.reply(501)}}onTransportError(){K.warn("onTransportError()"),this._status!==Q.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:he.causes.CONNECTION_ERROR,cause:he.causes.CONNECTION_ERROR})}onRequestTimeout(){K.warn("onRequestTimeout()"),this._status!==Q.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:he.causes.REQUEST_TIMEOUT,cause:he.causes.REQUEST_TIMEOUT})}onDialogError(){K.warn("onDialogError()"),this._status!==Q.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:he.causes.DIALOG_ERROR,cause:he.causes.DIALOG_ERROR})}newDTMF(t){K.debug("newDTMF()"),this.emit("newDTMF",t)}newInfo(t){K.debug("newInfo()"),this.emit("newInfo",t)}_isReadyToReOffer(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(K.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(K.debug("_isReadyToReOffer() | session not established yet"),!1):(K.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}_close(){if(K.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(K.debug("close() | closing local MediaStream"),Ge.closeMediaStream(this._localMediaStream)),this._status!==Q.STATUS_TERMINATED){if(this._status=Q.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(t){K.warn("close() | error closing the RTCPeerConnection: %o",t)}for(const t in this._timers)Object.prototype.hasOwnProperty.call(this._timers,t)&&clearTimeout(this._timers[t]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const t in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(const t in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,t)&&delete this._referSubscribers[t];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(t,n){let a=Xr.T1;function o(){this._status===Q.STATUS_WAITING_FOR_ACK&&(t.reply(200,null,[`Contact: ${this._contact}`],n),a<Xr.T2&&(a=a*2,a>Xr.T2&&(a=Xr.T2)),this._timers.invite2xxTimer=setTimeout(o.bind(this),a))}this._timers.invite2xxTimer=setTimeout(o.bind(this),a)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===Q.STATUS_WAITING_FOR_ACK&&(K.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(he.BYE),this._ended("remote",null,he.causes.NO_ACK))},Xr.TIMER_H)}_createRTCConnection(t,n){this._connection=new RTCPeerConnection(t,n),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:he.causes.RTP_TIMEOUT,status_code:408,reason_phrase:he.causes.RTP_TIMEOUT})}),K.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(t,n){if(K.debug("createLocalDescription()"),t!=="offer"&&t!=="answer")throw new Error(`createLocalDescription() | invalid type "${t}"`);const a=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>t==="offer"?a.createOffer(n).catch(o=>(K.warn('emit "peerconnection:createofferfailed" [error:%o]',o),this.emit("peerconnection:createofferfailed",o),Promise.reject(o))):a.createAnswer(n).catch(o=>(K.warn('emit "peerconnection:createanswerfailed" [error:%o]',o),this.emit("peerconnection:createanswerfailed",o),Promise.reject(o)))).then(o=>a.setLocalDescription(o).catch(s=>(this._rtcReady=!0,K.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',s),this.emit("peerconnection:setlocaldescriptionfailed",s),Promise.reject(s)))).then(()=>{const o=n&&n.iceRestart;if(a.iceGatheringState==="complete"&&!o||a.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const s={originator:"local",type:t,sdp:a.localDescription.sdp};return K.debug('emit "sdp"'),this.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(s=>{let r=!1,d,h;this._iceReady=!1;const _=()=>{a.removeEventListener("icecandidate",d),a.removeEventListener("icegatheringstatechange",h),r=!0,this._rtcReady=!0,this._iceReady=!0;const g={originator:"local",type:t,sdp:a.localDescription.sdp};K.debug('emit "sdp"'),this.emit("sdp",g),s(g.sdp)};a.addEventListener("icecandidate",d=g=>{const T=g.candidate;T?this.emit("icecandidate",{candidate:T,ready:_}):r||_()}),a.addEventListener("icegatheringstatechange",h=()=>{a.iceGatheringState==="complete"&&!r&&_()})})})}_createDialog(t,n,a){const o=n==="UAS"?t.to_tag:t.from_tag,s=n==="UAS"?t.from_tag:t.to_tag,r=t.call_id+o+s;let d=this._earlyDialogs[r];if(a)return d?!0:(d=new fa(this,t,n,fa.C.STATUS_EARLY),d.error?(K.debug(d.error),this._failed("remote",t,he.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=d,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,d)return d.update(t,n),this._dialog=d,delete this._earlyDialogs[r],!0;const h=new fa(this,t,n);return h.error?(K.debug(h.error),this._failed("remote",t,he.causes.INTERNAL_ERROR),!1):(this._dialog=h,!0)}}_receiveReinvite(t){K.debug("receiveReinvite()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=Ge.cloneArray(d.extraHeaders);if(this._status!==Q.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("reinvite",a),o)return;if(this._late_sdp=!1,!t.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(d=>{r.call(this,d)}).catch(()=>{t.reply(500)});return}if(n!=="application/sdp"){K.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==Q.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{K.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),this._late_sdp&&(d=this._mangleOffer(d)),t.reply(200,null,h,d,()=>{this._status=Q.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(t,d),this._setACKTimer()}),typeof a.callback=="function"&&a.callback()}}_receiveUpdate(t){K.debug("receiveUpdate()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=Ge.cloneArray(d.extraHeaders);if(this._status!==Q.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("update",a),o)return;if(!t.body){r.call(this,null);return}if(n!=="application/sdp"){K.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==Q.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{K.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),t.reply(200,null,h,d),typeof a.callback=="function"&&a.callback()}}_processInDialogSdpOffer(t){K.debug("_processInDialogSdpOffer()");const n=t.parseSDP();let a=!1;for(const r of n.media){if(ha.indexOf(r.type)===-1)continue;const d=r.direction||n.direction||"sendrecv";if(d==="sendonly"||d==="inactive")a=!0;else{a=!1;break}}const o={originator:"remote",type:"offer",sdp:t.body};K.debug('emit "sdp"'),this.emit("sdp",o);const s=new RTCSessionDescription({type:"offer",sdp:o.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(s).catch(r=>{throw t.reply(488),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',r),this.emit("peerconnection:setremotedescriptionfailed",r),r})}).then(()=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&a===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&a===!0&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(r=>{throw t.reply(500),K.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',r),r})}).catch(r=>{K.warn("_processInDialogSdpOffer() failed [error: %o]",r)}),this._connectionPromiseQueue}_receiveRefer(t){if(K.debug("receiveRefer()"),!t.refer_to){K.debug("no Refer-To header field present in REFER"),t.reply(400);return}if(t.refer_to.uri.scheme!==he.SIP){K.debug("Refer-To header field points to a non-SIP URI scheme"),t.reply(416);return}t.reply(202);const n=new vg(this,t.cseq);K.debug('emit "refer"'),this.emit("refer",{request:t,accept:(s,r)=>{a.call(this,s,r)},reject:()=>{o.call(this)}});function a(s,r={}){if(s=typeof s=="function"?s:null,this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;const d=new Wu(this._ua);if(d.on("progress",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("accepted",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("_failed",({message:h,cause:_})=>{h?n.notify(h.status_code,h.reason_phrase):n.notify(487,_)}),t.refer_to.uri.hasHeader("replaces")){const h=decodeURIComponent(t.refer_to.uri.getHeader("replaces"));r.extraHeaders=Ge.cloneArray(r.extraHeaders),r.extraHeaders.push(`Replaces: ${h}`)}d.connect(t.refer_to.uri.toAor(),r,s)}function o(){n.notify(603)}}_receiveNotify(t){switch(K.debug("receiveNotify()"),t.event||t.reply(400),t.event.event){case"refer":{let n,a;if(t.event.params&&t.event.params.id)n=t.event.params.id,a=this._referSubscribers[n];else if(Object.keys(this._referSubscribers).length===1)a=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{t.reply(400,"Missing event id parameter");return}if(!a){t.reply(481,"Subscription does not exist");return}a.receiveNotify(t),t.reply(200);break}default:t.reply(489)}}_receiveReplaces(t){K.debug("receiveReplaces()");function n(o){if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;const s=new Wu(this._ua);s.on("confirmed",()=>{this.terminate()}),s.init_incoming(t,o)}function a(){K.debug("Replaced INVITE rejected by the user"),t.reply(486)}this.emit("replaces",{request:t,accept:o=>{n.call(this,o)},reject:()=>{a.call(this)}})}_sendInitialRequest(t,n,a){const o=new Tg(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});Promise.resolve().then(()=>{if(a)return a;if(t.audio||t.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(t).catch(s=>{throw this._status===Q.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,he.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',s),this.emit("getusermediafailed",s),s)})}).then(s=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=s,s&&s.getTracks().forEach(r=>{this._connection.addTrack(r,s)}),this._connecting(this._request),this._createLocalDescription("offer",n).catch(r=>{throw this._failed("local",null,he.causes.WEBRTC_ERROR),r})}).then(s=>{if(this._is_canceled||this._status===Q.STATUS_TERMINATED)throw new Error("terminated");this._request.body=s,this._status=Q.STATUS_INVITE_SENT,K.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),o.send()}).catch(s=>{this._status!==Q.STATUS_TERMINATED&&K.warn(s)})}_getDTMFRTPSender(){const t=this._connection.getSenders().find(n=>n.track&&n.track.kind==="audio");if(!(t&&t.dtmf)){K.warn("sendDTMF() | no local audio track to send DTMF with");return}return t.dtmf}_receiveInviteResponse(t){if(K.debug("receiveInviteResponse()"),this._dialog&&t.status_code>=200&&t.status_code<=299)if(this._dialog.id.call_id===t.call_id&&this._dialog.id.local_tag===t.from_tag&&this._dialog.id.remote_tag===t.to_tag){this.sendRequest(he.ACK);return}else{const n=new fa(this,t,"UAC");if(n.error!==void 0){K.debug(n.error);return}this.sendRequest(he.ACK),this.sendRequest(he.BYE);return}if(this._is_canceled){t.status_code>=100&&t.status_code<200?this._request.cancel(this._cancel_reason):t.status_code>=200&&t.status_code<299&&this._acceptAndTerminate(t);return}if(!(this._status!==Q.STATUS_INVITE_SENT&&this._status!==Q.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(t.status_code):this._status=Q.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(t.status_code):{if(!t.to_tag){K.debug("1xx response received without to tag");break}if(t.hasHeader("contact")&&!this._createDialog(t,"UAC",!0))break;if(this._status=Q.STATUS_1XX_RECEIVED,!t.body){this._progress("remote",t);break}const n={originator:"remote",type:"answer",sdp:t.body};K.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>this._progress("remote",t)).catch(o=>{K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)});break}case/^2[0-9]{2}$/.test(t.status_code):{if(this._status=Q.STATUS_CONFIRMED,!t.body){this._acceptAndTerminate(t,400,he.causes.MISSING_SDP),this._failed("remote",t,he.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(t,"UAC"))break;const n={originator:"remote",type:"answer",sdp:t.body};K.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._connection.signalingState==="stable")return this._connection.createOffer(this._rtcOfferConstraints).then(o=>this._connection.setLocalDescription(o)).catch(o=>{this._acceptAndTerminate(t,500,o.toString()),this._failed("local",t,he.causes.WEBRTC_ERROR)})}).then(()=>{this._connection.setRemoteDescription(a).then(()=>{this._handleSessionTimersInIncomingResponse(t),this._accepted("remote",t),this.sendRequest(he.ACK),this._confirmed("local",null)}).catch(o=>{this._acceptAndTerminate(t,488,"Not Acceptable Here"),this._failed("remote",t,he.causes.BAD_MEDIA_DESCRIPTION),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})});break}default:{const n=Ge.sipErrorCause(t.status_code);this._failed("remote",t,n)}}}_sendReinvite(t={}){K.debug("sendReinvite()");const n=Ge.cloneArray(t.extraHeaders),a=Ge.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null;let s=!1;n.push(`Contact: ${this._contact}`),n.push("Content-Type: application/sdp"),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(h=>{h=this._mangleOffer(h);const _={originator:"local",type:"offer",sdp:h};K.debug('emit "sdp"'),this.emit("sdp",_),this.sendRequest(he.INVITE,{extraHeaders:n,body:h,eventHandlers:{onSuccessResponse:g=>{r.call(this,g),s=!0},onErrorResponse:g=>{d.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{d()});function r(h){if(this._status===Q.STATUS_TERMINATED||(this.sendRequest(he.ACK),s))return;if(this._handleSessionTimersInIncomingResponse(h),h.body){if(!h.hasHeader("Content-Type")||h.getHeader("Content-Type").toLowerCase()!=="application/sdp"){d.call(this);return}}else{d.call(this);return}const _={originator:"remote",type:"answer",sdp:h.body};K.debug('emit "sdp"'),this.emit("sdp",_);const g=new RTCSessionDescription({type:"answer",sdp:_.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(g)).then(()=>{a.succeeded&&a.succeeded(h)}).catch(T=>{d.call(this),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function d(h){a.failed&&a.failed(h)}}_sendUpdate(t={}){K.debug("sendUpdate()");const n=Ge.cloneArray(t.extraHeaders),a=Ge.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null,s=t.sdpOffer||!1;let r=!1;n.push(`Contact: ${this._contact}`),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),s?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(_=>{_=this._mangleOffer(_);const g={originator:"local",type:"offer",sdp:_};K.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(he.UPDATE,{extraHeaders:n,body:_,eventHandlers:{onSuccessResponse:T=>{d.call(this,T),r=!0},onErrorResponse:T=>{h.call(this,T)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{h.call(this)})):this.sendRequest(he.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:_=>{d.call(this,_)},onErrorResponse:_=>{h.call(this,_)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function d(_){if(this._status!==Q.STATUS_TERMINATED&&!r)if(this._handleSessionTimersInIncomingResponse(_),s){if(_.body){if(!_.hasHeader("Content-Type")||_.getHeader("Content-Type").toLowerCase()!=="application/sdp"){h.call(this);return}}else{h.call(this);return}const g={originator:"remote",type:"answer",sdp:_.body};K.debug('emit "sdp"'),this.emit("sdp",g);const T=new RTCSessionDescription({type:"answer",sdp:g.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(T)).then(()=>{a.succeeded&&a.succeeded(_)}).catch(E=>{h.call(this),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),this.emit("peerconnection:setremotedescriptionfailed",E)})}else a.succeeded&&a.succeeded(_)}function h(_){a.failed&&a.failed(_)}}_acceptAndTerminate(t,n,a){K.debug("acceptAndTerminate()");const o=[];n&&(a=a||he.REASON_PHRASE[n]||"",o.push(`Reason: SIP ;cause=${n}; text="${a}"`)),(this._dialog||this._createDialog(t,"UAC"))&&(this.sendRequest(he.ACK),this.sendRequest(he.BYE,{extraHeaders:o})),this._status=Q.STATUS_TERMINATED}_mangleOffer(t){if(!this._localHold&&!this._remoteHold)return t;if(t=zf.parse(t),this._localHold&&!this._remoteHold){K.debug("mangleOffer() | me on hold, mangling offer");for(const n of t.media)ha.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="sendonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="sendonly")}else if(this._localHold&&this._remoteHold){K.debug("mangleOffer() | both on hold, mangling offer");for(const n of t.media)ha.indexOf(n.type)!==-1&&(n.direction="inactive")}else if(this._remoteHold){K.debug("mangleOffer() | remote on hold, mangling offer");for(const n of t.media)ha.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="recvonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="recvonly")}return zf.write(t)}_setLocalMediaStatus(){let t=!0,n=!0;(this._localHold||this._remoteHold)&&(t=!1,n=!1),this._audioMuted&&(t=!1),this._videoMuted&&(n=!1),this._toggleMuteAudio(!t),this._toggleMuteVideo(!n)}_handleSessionTimersInIncomingRequest(t,n){if(!this._sessionTimers.enabled)return;let a;t.session_expires&&t.session_expires>=he.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,a=t.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,a="uas"),n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${a}`),this._sessionTimers.refresher=a==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(t){if(!this._sessionTimers.enabled)return;let n;t.session_expires&&t.session_expires>=he.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,n=t.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uac"),this._sessionTimers.refresher=n==="uac",this._runSessionTimer()}_runSessionTimer(){const t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(()=>{this._status!==Q.STATUS_TERMINATED&&this._isReadyToReOffer()&&(K.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===he.UPDATE?this._sendUpdate():this._sendReinvite())},t*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==Q.STATUS_TERMINATED&&(K.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:he.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},t*1100)}_toggleMuteAudio(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="audio");for(const a of n)a.track.enabled=!t}_toggleMuteVideo(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="video");for(const a of n)a.track.enabled=!t}_newRTCSession(t,n){K.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:t,session:this,request:n})}_connecting(t){K.debug("session connecting"),K.debug('emit "connecting"'),this.emit("connecting",{request:t})}_progress(t,n){K.debug("session progress"),K.debug('emit "progress"'),this.emit("progress",{originator:t,response:n||null})}_accepted(t,n){K.debug("session accepted"),this._start_time=new Date,K.debug('emit "accepted"'),this.emit("accepted",{originator:t,response:n||null})}_confirmed(t,n){K.debug("session confirmed"),this._is_confirmed=!0,K.debug('emit "confirmed"'),this.emit("confirmed",{originator:t,ack:n||null})}_ended(t,n,a){K.debug("session ended"),this._end_time=new Date,this._close(),K.debug('emit "ended"'),this.emit("ended",{originator:t,message:n||null,cause:a})}_failed(t,n,a){K.debug("session failed"),K.debug('emit "_failed"'),this.emit("_failed",{originator:t,message:n||null,cause:a}),this._close(),K.debug('emit "failed"'),this.emit("failed",{originator:t,message:n||null,cause:a})}_onhold(t){K.debug("session onhold"),this._setLocalMediaStatus(),K.debug('emit "hold"'),this.emit("hold",{originator:t})}_onunhold(t){K.debug("session onunhold"),this._setLocalMediaStatus(),K.debug('emit "unhold"'),this.emit("unhold",{originator:t})}_onmute({audio:t,video:n}){K.debug("session onmute"),this._setLocalMediaStatus(),K.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}_onunmute({audio:t,video:n}){K.debug("session onunmute"),this._setLocalMediaStatus(),K.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}};const Sg=Me(eh),yg=ct.EventEmitter,Ag=at,iu=De,Cg=Tt,Qr=mt(),Rg=Fn,th=Ts,Ig=ps(),da=new Ag("Message");var bg=class extends yg{constructor(t){super(),this._ua=t,this._request=null,this._closed=!1,this._direction=null,this._local_identity=null,this._remote_identity=null,this._is_replied=!1,this._data={}}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}send(t,n,a={}){const o=t;if(t===void 0||n===void 0)throw new TypeError("Not enough arguments");if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${o}`);const s=Qr.cloneArray(a.extraHeaders),r=Qr.cloneObject(a.eventHandlers),d=a.contentType||"text/plain",h={};a.fromUserName&&(h.from_uri=new Ig("sip",a.fromUserName,this._ua.configuration.uri.host),s.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),a.fromDisplayName&&(h.from_display_name=a.fromDisplayName);for(const g in r)Object.prototype.hasOwnProperty.call(r,g)&&this.on(g,r[g]);s.push(`Content-Type: ${d}`),this._request=new Cg.OutgoingRequest(iu.MESSAGE,t,this._ua,h,s),n&&(this._request.body=n);const _=new Rg(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:g=>{this._receiveResponse(g)}});this._newMessage("local",this._request),_.send()}init_incoming(t){this._request=t,this._newMessage("remote",t),this._is_replied||(this._is_replied=!0,t.reply(200)),this._close()}accept(t={}){const n=Qr.cloneArray(t.extraHeaders),a=t.body;if(this._direction!=="incoming")throw new th.NotSupportedError('"accept" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");this._is_replied=!0,this._request.reply(200,null,n,a)}reject(t={}){const n=t.status_code||480,a=t.reason_phrase,o=Qr.cloneArray(t.extraHeaders),s=t.body;if(this._direction!=="incoming")throw new th.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(n<300||n>=700)throw new TypeError(`Invalid status_code: ${n}`);this._is_replied=!0,this._request.reply(n,a,o,s)}_receiveResponse(t){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):this._succeeded("remote",t);break;default:{const n=Qr.sipErrorCause(t.status_code);this._failed("remote",t,n);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,iu.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,iu.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newMessage(t,n){t==="remote"?(this._direction="incoming",this._local_identity=n.to,this._remote_identity=n.from):t==="local"&&(this._direction="outgoing",this._local_identity=n.from,this._remote_identity=n.to),this._ua.newMessage(this,{originator:t,message:this,request:n})}_failed(t,n,a){da.debug("MESSAGE failed"),this._close(),da.debug('emit "failed"'),this.emit("failed",{originator:t,response:n||null,cause:a})}_succeeded(t,n){da.debug("MESSAGE succeeded"),this._close(),da.debug('emit "succeeded"'),this.emit("succeeded",{originator:t,response:n})}};const wg=ct.EventEmitter,Og=at,lu=De,Dg=Tt,Zr=mt(),Ng=Fn,sh=Ts,_a=new Og("Options");var Ug=class extends wg{constructor(t){super(),this._ua=t,this._request=null,this._closed=!1,this._direction=null,this._local_identity=null,this._remote_identity=null,this._is_replied=!1,this._data={}}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}send(t,n,a={}){const o=t;if(t===void 0)throw new TypeError("A target is required for OPTIONS");if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${o}`);const s=Zr.cloneArray(a.extraHeaders),r=Zr.cloneObject(a.eventHandlers),d=a.contentType||"application/sdp";for(const _ in r)Object.prototype.hasOwnProperty.call(r,_)&&this.on(_,r[_]);s.push(`Content-Type: ${d}`),this._request=new Dg.OutgoingRequest(lu.OPTIONS,t,this._ua,null,s),n&&(this._request.body=n);const h=new Ng(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:_=>{this._receiveResponse(_)}});this._newOptions("local",this._request),h.send()}init_incoming(t){this._request=t,this._newOptions("remote",t),this._is_replied||(this._is_replied=!0,t.reply(200)),this._close()}accept(t={}){const n=Zr.cloneArray(t.extraHeaders),a=t.body;if(this._direction!=="incoming")throw new sh.NotSupportedError('"accept" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");this._is_replied=!0,this._request.reply(200,null,n,a)}reject(t={}){const n=t.status_code||480,a=t.reason_phrase,o=Zr.cloneArray(t.extraHeaders),s=t.body;if(this._direction!=="incoming")throw new sh.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(n<300||n>=700)throw new TypeError(`Invalid status_code: ${n}`);this._is_replied=!0,this._request.reply(n,a,o,s)}_receiveResponse(t){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):this._succeeded("remote",t);break;default:{const n=Zr.sipErrorCause(t.status_code);this._failed("remote",t,n);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,lu.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,lu.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newOptions(t,n){t==="remote"?(this._direction="incoming",this._local_identity=n.to,this._remote_identity=n.from):t==="local"&&(this._direction="outgoing",this._local_identity=n.from,this._remote_identity=n.to),this._ua.newOptions(this,{originator:t,message:this,request:n})}_failed(t,n,a){_a.debug("OPTIONS failed"),this._close(),_a.debug('emit "failed"'),this.emit("failed",{originator:t,response:n||null,cause:a})}_succeeded(t,n){_a.debug("OPTIONS succeeded"),this._close(),_a.debug('emit "succeeded"'),this.emit("succeeded",{originator:t,response:n})}},au={};const Pg=at,ou=mt(),xg=Jt(),ei=new Pg("Socket");au.isSocket=c=>{if(Array.isArray(c))return!1;if(typeof c>"u")return ei.warn("undefined JsSIP.Socket instance"),!1;try{if(!ou.isString(c.url))throw ei.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!ou.isString(c.via_transport))throw ei.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(xg.parse(c.sip_uri,"SIP_URI")===-1)throw ei.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch{return!1}try{["connect","disconnect","send"].forEach(t=>{if(!ou.isFunction(c[t]))throw ei.warn(`missing or invalid JsSIP.Socket method: ${t}`),new Error(`Missing or invalid JsSIP.Socket method: ${t}`)})}catch{return!1}return!0};const kg=at,Mg=au,nh=De,xt=new kg("Transport"),qt={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:nh.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:nh.CONNECTION_RECOVERY_MAX_INTERVAL}};var rh=class{constructor(t,n=qt.recovery_options){xt.debug("new()"),this.status=qt.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(a){xt.warn(`cannot use TextDecoder: ${a}`)}if(typeof t>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(a){if(!Mg.isSocket(a.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(a.weight&&!Number(a.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:a.socket,weight:a.weight||0,status:qt.SOCKET_STATUS_READY})},this),this._getSocket()}get via_transport(){return this.socket.via_transport}get url(){return this.socket.url}get sip_uri(){return this.socket.sip_uri}connect(){if(xt.debug("connect()"),this.isConnected()){xt.debug("Transport is already connected");return}else if(this.isConnecting()){xt.debug("Transport is connecting");return}this.close_requested=!1,this.status=qt.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect())}disconnect(){xt.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=qt.STATUS_DISCONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=()=>{},this.socket.ondisconnect=()=>{},this.socket.ondata=()=>{},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}send(t){if(xt.debug("send()"),!this.isConnected())return xt.warn("unable to send message, transport is not connected"),!1;const n=t.toString();return xt.debug(`sending message:
|
115
|
+
`,1)[0],"Status_Line");if(n===-1){sn.debug(`receiveNotify() | error parsing NOTIFY body: "${t.body}"`);return}switch(!0){case/^100$/.test(n.status_code):this.emit("trying",{request:t,status_line:n});break;case/^1[0-9]{2}$/.test(n.status_code):this.emit("progress",{request:t,status_line:n});break;case/^2[0-9]{2}$/.test(n.status_code):this.emit("accepted",{request:t,status_line:n});break;default:this.emit("failed",{request:t,status_line:n});break}}_requestSucceeded(t){sn.debug("REFER succeeded"),sn.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:t})}_requestFailed(t,n){sn.debug("REFER failed"),sn.debug('emit "requestFailed"'),this.emit("requestFailed",{response:t||null,cause:n})}};const _g=Me(Jf),pg=ct.EventEmitter,zf=Ut,mg=at,he=De,nn=Ts,Xf=Hn,Ge=mt(),Xr=Yo,gg=Tt,fa=jf,Tg=Fn,$t=Bf,Qf=Gf,vg=Kf,Eg=Jf,Zf=ps(),K=new mg("RTCSession"),Q={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9},ha=["audio","video"];var eh=class Wu extends pg{static get C(){return Q}constructor(t){K.debug("new"),super(),this._id=null,this._ua=t,this._status=Q.STATUS_NULL,this._dialog=null,this._earlyDialogs={},this._contact=null,this._from_tag=null,this._to_tag=null,this._connection=null,this._connectionPromiseQueue=Promise.resolve(),this._request=null,this._is_canceled=!1,this._cancel_reason="",this._is_confirmed=!1,this._late_sdp=!1,this._rtcOfferConstraints=null,this._rtcAnswerConstraints=null,this._localMediaStream=null,this._localMediaStreamLocallyGenerated=!1,this._rtcReady=!0,this._iceReady=!1,this._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},this._direction=null,this._local_identity=null,this._remote_identity=null,this._start_time=null,this._end_time=null,this._tones=null,this._audioMuted=!1,this._videoMuted=!1,this._localHold=!1,this._remoteHold=!1,this._sessionTimers={enabled:this._ua.configuration.session_timers,refreshMethod:this._ua.configuration.session_timers_refresh_method,defaultExpires:he.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._referSubscribers={},this._data={}}get C(){return Q}get causes(){return he.causes}get id(){return this._id}get connection(){return this._connection}get contact(){return this._contact}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}get start_time(){return this._start_time}get end_time(){return this._end_time}get data(){return this._data}set data(t){this._data=t}get status(){return this._status}isInProgress(){switch(this._status){case Q.STATUS_NULL:case Q.STATUS_INVITE_SENT:case Q.STATUS_1XX_RECEIVED:case Q.STATUS_INVITE_RECEIVED:case Q.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case Q.STATUS_ANSWERED:case Q.STATUS_WAITING_FOR_ACK:case Q.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case Q.STATUS_CANCELED:case Q.STATUS_TERMINATED:return!0;default:return!1}}isMuted(){return{audio:this._audioMuted,video:this._videoMuted}}isOnHold(){return{local:this._localHold,remote:this._remoteHold}}connect(t,n={},a){K.debug("connect()");const o=t,s=Ge.cloneObject(n.eventHandlers),r=Ge.cloneArray(n.extraHeaders),d=Ge.cloneObject(n.mediaConstraints,{audio:!0,video:!0}),h=n.mediaStream||null,_=Ge.cloneObject(n.pcConfig,{iceServers:[]}),g=n.rtcConstraints||null,T=n.rtcOfferConstraints||null;if(this._rtcOfferConstraints=T,this._rtcAnswerConstraints=n.rtcAnswerConstraints||null,this._data=n.data||this._data,t===void 0)throw new TypeError("Not enough arguments");if(this._status!==Q.STATUS_NULL)throw new nn.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new nn.NotSupportedError("WebRTC not supported");if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${o}`);this._sessionTimers.enabled&&Ge.isDecimal(n.sessionTimersExpires)&&(n.sessionTimersExpires>=he.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=n.sessionTimersExpires:this._sessionTimers.defaultExpires=he.SESSION_EXPIRES);for(const C in s)Object.prototype.hasOwnProperty.call(s,C)&&this.on(C,s[C]);this._from_tag=Ge.newTag();const E=n.anonymous||!1,y={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:E,outbound:!0}),E?(y.from_display_name="Anonymous",y.from_uri=new Zf("sip","anonymous","anonymous.invalid"),r.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),r.push("Privacy: id")):n.fromUserName&&(y.from_uri=new Zf("sip",n.fromUserName,this._ua.configuration.uri.host),r.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),n.fromDisplayName&&(y.from_display_name=n.fromDisplayName),r.push(`Contact: ${this._contact}`),r.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&r.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new gg.InitialOutgoingInviteRequest(t,this._ua,y,r),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(_,g),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,a&&a(this),this._newRTCSession("local",this._request),this._sendInitialRequest(d,T,h)}init_incoming(t,n){K.debug("init_incoming()");let a;const o=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;if(t.body&&o!=="application/sdp"){t.reply(415);return}if(this._status=Q.STATUS_INVITE_RECEIVED,this._from_tag=t.from_tag,this._id=t.call_id+this._from_tag,this._request=t,this._contact=this._ua.contact.toString(),t.hasHeader("expires")&&(a=t.getHeader("expires")*1e3),t.to_tag=Ge.newTag(),!this._createDialog(t,"UAS",!0)){t.reply(500,"Missing Contact header field");return}t.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Q.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{t.reply(408),this._failed("local",null,he.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),a&&(this._timers.expiresTimer=setTimeout(()=>{this._status===Q.STATUS_WAITING_FOR_ANSWER&&(t.reply(487),this._failed("system",null,he.causes.EXPIRES))},a)),this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from,n&&n(this),this._newRTCSession("remote",t),this._status!==Q.STATUS_TERMINATED&&(t.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(t={}){K.debug("answer()");const n=this._request,a=Ge.cloneArray(t.extraHeaders),o=Ge.cloneObject(t.mediaConstraints),s=t.mediaStream||null,r=Ge.cloneObject(t.pcConfig,{iceServers:[]}),d=t.rtcConstraints||null,h=t.rtcAnswerConstraints||null,_=Ge.cloneObject(t.rtcOfferConstraints);let g,T=!1,E=!1,y=!1,C=!1;if(this._rtcAnswerConstraints=h,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,this._direction!=="incoming")throw new nn.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==Q.STATUS_WAITING_FOR_ANSWER)throw new nn.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Ge.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=he.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=he.SESSION_EXPIRES),this._status=Q.STATUS_ANSWERED,!this._createDialog(n,"UAS")){n.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),a.unshift(`Contact: ${this._contact}`);const A=n.parseSDP();Array.isArray(A.media)||(A.media=[A.media]);for(const I of A.media)I.type==="audio"&&(T=!0,(!I.direction||I.direction==="sendrecv")&&(y=!0)),I.type==="video"&&(E=!0,(!I.direction||I.direction==="sendrecv")&&(C=!0));if(s&&o.audio===!1){g=s.getAudioTracks();for(const I of g)s.removeTrack(I)}if(s&&o.video===!1){g=s.getVideoTracks();for(const I of g)s.removeTrack(I)}!s&&o.audio===void 0&&(o.audio=y),!s&&o.video===void 0&&(o.video=C),!s&&!T&&!_.offerToReceiveAudio&&(o.audio=!1),!s&&!E&&!_.offerToReceiveVideo&&(o.video=!1),this._createRTCConnection(r,d),Promise.resolve().then(()=>{if(s)return s;if(o.audio||o.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(o).catch(I=>{throw this._status===Q.STATUS_TERMINATED?new Error("terminated"):(n.reply(480),this._failed("local",null,he.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',I),this.emit("getusermediafailed",I),new Error("getUserMedia() failed"))})}).then(I=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=I,I&&I.getTracks().forEach(H=>{this._connection.addTrack(H,I)})}).then(()=>{if(this._late_sdp)return;const I={originator:"remote",type:"offer",sdp:n.body};K.debug('emit "sdp"'),this.emit("sdp",I);const H=new RTCSessionDescription({type:"offer",sdp:I.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(H)).catch($=>{throw n.reply(488),this._failed("system",null,he.causes.WEBRTC_ERROR),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',$),this.emit("peerconnection:setremotedescriptionfailed",$),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(n),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",h).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(I=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,a),n.reply(200,null,a,I,()=>{this._status=Q.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,I),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,he.causes.CONNECTION_ERROR)})}).catch(I=>{this._status!==Q.STATUS_TERMINATED&&K.warn(I)})}terminate(t={}){K.debug("terminate()");const n=t.cause||he.causes.BYE,a=Ge.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,d=t.reason_phrase;if(this._status===Q.STATUS_TERMINATED)throw new nn.InvalidStateError(this._status);switch(this._status){case Q.STATUS_NULL:case Q.STATUS_INVITE_SENT:case Q.STATUS_1XX_RECEIVED:if(K.debug("canceling session"),r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);r&&(d=d||he.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${d}"`),this._status===Q.STATUS_NULL||this._status===Q.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===Q.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=Q.STATUS_CANCELED,this._failed("local",null,he.causes.CANCELED);break;case Q.STATUS_WAITING_FOR_ANSWER:case Q.STATUS_ANSWERED:if(K.debug("rejecting session"),r=r||480,r<300||r>=700)throw new TypeError(`Invalid status_code: ${r}`);this._request.reply(r,d,a,o),this._failed("local",null,he.causes.REJECTED);break;case Q.STATUS_WAITING_FOR_ACK:case Q.STATUS_CONFIRMED:if(K.debug("terminating session"),d=t.reason_phrase||he.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);if(r&&a.push(`Reason: SIP ;cause=${r}; text="${d}"`),this._status===Q.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Xf.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:_})=>{_===he.ACK&&(this.sendRequest(he.BYE,{extraHeaders:a,body:o}),h.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Xf.C.STATUS_TERMINATED&&(this.sendRequest(he.BYE,{extraHeaders:a,body:o}),h.terminate())}),this._ended("local",null,n),this._dialog=h,this._ua.newDialog(h)}else this.sendRequest(he.BYE,{extraHeaders:a,body:o}),this._ended("local",null,n)}}sendDTMF(t,n={}){K.debug("sendDTMF() | tones: %s",t);let a=0,o=n.duration||null,s=n.interToneGap||null;const r=n.transportType||he.DTMF_TRANSPORT.INFO;if(t===void 0)throw new TypeError("Not enough arguments");if(this._status!==Q.STATUS_CONFIRMED&&this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_1XX_RECEIVED)throw new nn.InvalidStateError(this._status);if(r!==he.DTMF_TRANSPORT.INFO&&r!==he.DTMF_TRANSPORT.RFC2833)throw new TypeError(`invalid transportType: ${r}`);if(typeof t=="number"&&(t=t.toString()),!t||typeof t!="string"||!t.match(/^[0-9A-DR#*,]+$/i))throw new TypeError(`Invalid tones: ${t}`);if(o&&!Ge.isDecimal(o))throw new TypeError(`Invalid tone duration: ${o}`);if(o?o<$t.C.MIN_DURATION?(K.debug(`"duration" value is lower than the minimum allowed, setting it to ${$t.C.MIN_DURATION} milliseconds`),o=$t.C.MIN_DURATION):o>$t.C.MAX_DURATION?(K.debug(`"duration" value is greater than the maximum allowed, setting it to ${$t.C.MAX_DURATION} milliseconds`),o=$t.C.MAX_DURATION):o=Math.abs(o):o=$t.C.DEFAULT_DURATION,n.duration=o,s&&!Ge.isDecimal(s))throw new TypeError(`Invalid interToneGap: ${s}`);if(s?s<$t.C.MIN_INTER_TONE_GAP?(K.debug(`"interToneGap" value is lower than the minimum allowed, setting it to ${$t.C.MIN_INTER_TONE_GAP} milliseconds`),s=$t.C.MIN_INTER_TONE_GAP):s=Math.abs(s):s=$t.C.DEFAULT_INTER_TONE_GAP,r===he.DTMF_TRANSPORT.RFC2833){const h=this._getDTMFRTPSender();h&&(t=h.toneBuffer+t,h.insertDTMF(t,o,s));return}if(this._tones){this._tones+=t;return}this._tones=t,d.call(this);function d(){let h;if(this._status===Q.STATUS_TERMINATED||!this._tones||a>=this._tones.length){this._tones=null;return}const _=this._tones[a];if(a+=1,_===",")h=2e3;else{const g=new $t(this);n.eventHandlers={onFailed:()=>{this._tones=null}},g.send(_,n),h=o+s}setTimeout(d.bind(this),h)}}sendInfo(t,n,a={}){if(K.debug("sendInfo()"),this._status!==Q.STATUS_CONFIRMED&&this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_1XX_RECEIVED)throw new nn.InvalidStateError(this._status);new Qf(this).send(t,n,a)}mute(t={audio:!0,video:!1}){K.debug("mute()");let n=!1,a=!1;this._audioMuted===!1&&t.audio&&(n=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&t.video&&(a=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(n===!0||a===!0)&&this._onmute({audio:n,video:a})}unmute(t={audio:!0,video:!0}){K.debug("unmute()");let n=!1,a=!1;this._audioMuted===!0&&t.audio&&(n=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&t.video&&(a=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(n===!0||a===!0)&&this._onunmute({audio:n,video:a})}hold(t={},n){if(K.debug("hold()"),this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:he.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}unhold(t={},n){if(K.debug("unhold()"),this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:he.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}renegotiate(t={},n){K.debug("renegotiate()");const a=t.rtcOfferConstraints||null;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const o={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:he.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}),!0}refer(t,n){K.debug("refer()");const a=t;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${a}`);const o=new Eg(this);o.sendRefer(t,n);const s=o.id;return this._referSubscribers[s]=o,o.on("requestFailed",()=>{delete this._referSubscribers[s]}),o.on("accepted",()=>{delete this._referSubscribers[s]}),o.on("failed",()=>{delete this._referSubscribers[s]}),o}sendRequest(t,n){return K.debug("sendRequest()"),this._dialog.sendRequest(t,n)}receiveRequest(t){if(K.debug("receiveRequest()"),t.method===he.CANCEL)(this._status===Q.STATUS_WAITING_FOR_ANSWER||this._status===Q.STATUS_ANSWERED)&&(this._status=Q.STATUS_CANCELED,this._request.reply(487),this._failed("remote",t,he.causes.CANCELED));else switch(t.method){case he.ACK:if(this._status!==Q.STATUS_WAITING_FOR_ACK)return;if(this._status=Q.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!t.body){this.terminate({cause:he.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:t.body};K.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>{this._is_confirmed||this._confirmed("remote",t)}).catch(o=>{this.terminate({cause:he.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})}else this._is_confirmed||this._confirmed("remote",t);break;case he.BYE:this._status===Q.STATUS_CONFIRMED||this._status===Q.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,he.causes.BYE)):this._status===Q.STATUS_INVITE_RECEIVED||this._status===Q.STATUS_WAITING_FOR_ANSWER?(t.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",t,he.causes.BYE)):t.reply(403,"Wrong Status");break;case he.INVITE:this._status===Q.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case he.INFO:if(this._status===Q.STATUS_1XX_RECEIVED||this._status===Q.STATUS_WAITING_FOR_ANSWER||this._status===Q.STATUS_ANSWERED||this._status===Q.STATUS_WAITING_FOR_ACK||this._status===Q.STATUS_CONFIRMED){const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;n&&n.match(/^application\/dtmf-relay/i)?new $t(this).init_incoming(t):n!==void 0?new Qf(this).init_incoming(t):t.reply(415)}else t.reply(403,"Wrong Status");break;case he.UPDATE:this._status===Q.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case he.REFER:this._status===Q.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case he.NOTIFY:this._status===Q.STATUS_CONFIRMED?this._receiveNotify(t):t.reply(403,"Wrong Status");break;default:t.reply(501)}}onTransportError(){K.warn("onTransportError()"),this._status!==Q.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:he.causes.CONNECTION_ERROR,cause:he.causes.CONNECTION_ERROR})}onRequestTimeout(){K.warn("onRequestTimeout()"),this._status!==Q.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:he.causes.REQUEST_TIMEOUT,cause:he.causes.REQUEST_TIMEOUT})}onDialogError(){K.warn("onDialogError()"),this._status!==Q.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:he.causes.DIALOG_ERROR,cause:he.causes.DIALOG_ERROR})}newDTMF(t){K.debug("newDTMF()"),this.emit("newDTMF",t)}newInfo(t){K.debug("newInfo()"),this.emit("newInfo",t)}_isReadyToReOffer(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(K.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(K.debug("_isReadyToReOffer() | session not established yet"),!1):(K.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}_close(){if(K.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(K.debug("close() | closing local MediaStream"),Ge.closeMediaStream(this._localMediaStream)),this._status!==Q.STATUS_TERMINATED){if(this._status=Q.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(t){K.warn("close() | error closing the RTCPeerConnection: %o",t)}for(const t in this._timers)Object.prototype.hasOwnProperty.call(this._timers,t)&&clearTimeout(this._timers[t]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const t in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(const t in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,t)&&delete this._referSubscribers[t];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(t,n){let a=Xr.T1;function o(){this._status===Q.STATUS_WAITING_FOR_ACK&&(t.reply(200,null,[`Contact: ${this._contact}`],n),a<Xr.T2&&(a=a*2,a>Xr.T2&&(a=Xr.T2)),this._timers.invite2xxTimer=setTimeout(o.bind(this),a))}this._timers.invite2xxTimer=setTimeout(o.bind(this),a)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===Q.STATUS_WAITING_FOR_ACK&&(K.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(he.BYE),this._ended("remote",null,he.causes.NO_ACK))},Xr.TIMER_H)}_createRTCConnection(t,n){this._connection=new RTCPeerConnection(t,n),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:he.causes.RTP_TIMEOUT,status_code:408,reason_phrase:he.causes.RTP_TIMEOUT})}),K.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(t,n){if(K.debug("createLocalDescription()"),t!=="offer"&&t!=="answer")throw new Error(`createLocalDescription() | invalid type "${t}"`);const a=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>t==="offer"?a.createOffer(n).catch(o=>(K.warn('emit "peerconnection:createofferfailed" [error:%o]',o),this.emit("peerconnection:createofferfailed",o),Promise.reject(o))):a.createAnswer(n).catch(o=>(K.warn('emit "peerconnection:createanswerfailed" [error:%o]',o),this.emit("peerconnection:createanswerfailed",o),Promise.reject(o)))).then(o=>a.setLocalDescription(o).catch(s=>(this._rtcReady=!0,K.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',s),this.emit("peerconnection:setlocaldescriptionfailed",s),Promise.reject(s)))).then(()=>{const o=n&&n.iceRestart;if(a.iceGatheringState==="complete"&&!o||a.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const s={originator:"local",type:t,sdp:a.localDescription.sdp};return K.debug('emit "sdp"'),this.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(s=>{let r=!1,d,h;this._iceReady=!1;const _=()=>{a.removeEventListener("icecandidate",d),a.removeEventListener("icegatheringstatechange",h),r=!0,this._rtcReady=!0,this._iceReady=!0;const g={originator:"local",type:t,sdp:a.localDescription.sdp};K.debug('emit "sdp"'),this.emit("sdp",g),s(g.sdp)};a.addEventListener("icecandidate",d=g=>{const T=g.candidate;T?this.emit("icecandidate",{candidate:T,ready:_}):r||_()}),a.addEventListener("icegatheringstatechange",h=()=>{a.iceGatheringState==="complete"&&!r&&_()})})})}_createDialog(t,n,a){const o=n==="UAS"?t.to_tag:t.from_tag,s=n==="UAS"?t.from_tag:t.to_tag,r=t.call_id+o+s;let d=this._earlyDialogs[r];if(a)return d?!0:(d=new fa(this,t,n,fa.C.STATUS_EARLY),d.error?(K.debug(d.error),this._failed("remote",t,he.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=d,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,d)return d.update(t,n),this._dialog=d,delete this._earlyDialogs[r],!0;const h=new fa(this,t,n);return h.error?(K.debug(h.error),this._failed("remote",t,he.causes.INTERNAL_ERROR),!1):(this._dialog=h,!0)}}_receiveReinvite(t){K.debug("receiveReinvite()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=Ge.cloneArray(d.extraHeaders);if(this._status!==Q.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("reinvite",a),o)return;if(this._late_sdp=!1,!t.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(d=>{r.call(this,d)}).catch(()=>{t.reply(500)});return}if(n!=="application/sdp"){K.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==Q.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{K.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),this._late_sdp&&(d=this._mangleOffer(d)),t.reply(200,null,h,d,()=>{this._status=Q.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(t,d),this._setACKTimer()}),typeof a.callback=="function"&&a.callback()}}_receiveUpdate(t){K.debug("receiveUpdate()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=Ge.cloneArray(d.extraHeaders);if(this._status!==Q.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("update",a),o)return;if(!t.body){r.call(this,null);return}if(n!=="application/sdp"){K.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==Q.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{K.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),t.reply(200,null,h,d),typeof a.callback=="function"&&a.callback()}}_processInDialogSdpOffer(t){K.debug("_processInDialogSdpOffer()");const n=t.parseSDP();let a=!1;for(const r of n.media){if(ha.indexOf(r.type)===-1)continue;const d=r.direction||n.direction||"sendrecv";if(d==="sendonly"||d==="inactive")a=!0;else{a=!1;break}}const o={originator:"remote",type:"offer",sdp:t.body};K.debug('emit "sdp"'),this.emit("sdp",o);const s=new RTCSessionDescription({type:"offer",sdp:o.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(s).catch(r=>{throw t.reply(488),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',r),this.emit("peerconnection:setremotedescriptionfailed",r),r})}).then(()=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&a===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&a===!0&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(r=>{throw t.reply(500),K.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',r),r})}).catch(r=>{K.warn("_processInDialogSdpOffer() failed [error: %o]",r)}),this._connectionPromiseQueue}_receiveRefer(t){if(K.debug("receiveRefer()"),!t.refer_to){K.debug("no Refer-To header field present in REFER"),t.reply(400);return}if(t.refer_to.uri.scheme!==he.SIP){K.debug("Refer-To header field points to a non-SIP URI scheme"),t.reply(416);return}t.reply(202);const n=new vg(this,t.cseq);K.debug('emit "refer"'),this.emit("refer",{request:t,accept:(s,r)=>{a.call(this,s,r)},reject:()=>{o.call(this)}});function a(s,r={}){if(s=typeof s=="function"?s:null,this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;const d=new Wu(this._ua);if(d.on("progress",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("accepted",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("_failed",({message:h,cause:_})=>{h?n.notify(h.status_code,h.reason_phrase):n.notify(487,_)}),t.refer_to.uri.hasHeader("replaces")){const h=decodeURIComponent(t.refer_to.uri.getHeader("replaces"));r.extraHeaders=Ge.cloneArray(r.extraHeaders),r.extraHeaders.push(`Replaces: ${h}`)}d.connect(t.refer_to.uri.toAor(),r,s)}function o(){n.notify(603)}}_receiveNotify(t){switch(K.debug("receiveNotify()"),t.event||t.reply(400),t.event.event){case"refer":{let n,a;if(t.event.params&&t.event.params.id)n=t.event.params.id,a=this._referSubscribers[n];else if(Object.keys(this._referSubscribers).length===1)a=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{t.reply(400,"Missing event id parameter");return}if(!a){t.reply(481,"Subscription does not exist");return}a.receiveNotify(t),t.reply(200);break}default:t.reply(489)}}_receiveReplaces(t){K.debug("receiveReplaces()");function n(o){if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;const s=new Wu(this._ua);s.on("confirmed",()=>{this.terminate()}),s.init_incoming(t,o)}function a(){K.debug("Replaced INVITE rejected by the user"),t.reply(486)}this.emit("replaces",{request:t,accept:o=>{n.call(this,o)},reject:()=>{a.call(this)}})}_sendInitialRequest(t,n,a){const o=new Tg(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});Promise.resolve().then(()=>{if(a)return a;if(t.audio||t.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(t).catch(s=>{throw this._status===Q.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,he.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',s),this.emit("getusermediafailed",s),s)})}).then(s=>{if(this._status===Q.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=s,s&&s.getTracks().forEach(r=>{this._connection.addTrack(r,s)}),this._connecting(this._request),this._createLocalDescription("offer",n).catch(r=>{throw this._failed("local",null,he.causes.WEBRTC_ERROR),r})}).then(s=>{if(this._is_canceled||this._status===Q.STATUS_TERMINATED)throw new Error("terminated");this._request.body=s,this._status=Q.STATUS_INVITE_SENT,K.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),o.send()}).catch(s=>{this._status!==Q.STATUS_TERMINATED&&K.warn(s)})}_getDTMFRTPSender(){const t=this._connection.getSenders().find(n=>n.track&&n.track.kind==="audio");if(!(t&&t.dtmf)){K.warn("sendDTMF() | no local audio track to send DTMF with");return}return t.dtmf}_receiveInviteResponse(t){if(K.debug("receiveInviteResponse()"),this._dialog&&t.status_code>=200&&t.status_code<=299)if(this._dialog.id.call_id===t.call_id&&this._dialog.id.local_tag===t.from_tag&&this._dialog.id.remote_tag===t.to_tag){this.sendRequest(he.ACK);return}else{const n=new fa(this,t,"UAC");if(n.error!==void 0){K.debug(n.error);return}this.sendRequest(he.ACK),this.sendRequest(he.BYE);return}if(this._is_canceled){t.status_code>=100&&t.status_code<200?this._request.cancel(this._cancel_reason):t.status_code>=200&&t.status_code<299&&this._acceptAndTerminate(t);return}if(!(this._status!==Q.STATUS_INVITE_SENT&&this._status!==Q.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(t.status_code):this._status=Q.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(t.status_code):{if(!t.to_tag){K.debug("1xx response received without to tag");break}if(t.hasHeader("contact")&&!this._createDialog(t,"UAC",!0))break;if(this._status=Q.STATUS_1XX_RECEIVED,!t.body){this._progress("remote",t);break}const n={originator:"remote",type:"answer",sdp:t.body};K.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>this._progress("remote",t)).catch(o=>{K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)});break}case/^2[0-9]{2}$/.test(t.status_code):{if(this._status=Q.STATUS_CONFIRMED,!t.body){this._acceptAndTerminate(t,400,he.causes.MISSING_SDP),this._failed("remote",t,he.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(t,"UAC"))break;const n={originator:"remote",type:"answer",sdp:t.body};K.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._connection.signalingState==="stable")return this._connection.createOffer(this._rtcOfferConstraints).then(o=>this._connection.setLocalDescription(o)).catch(o=>{this._acceptAndTerminate(t,500,o.toString()),this._failed("local",t,he.causes.WEBRTC_ERROR)})}).then(()=>{this._connection.setRemoteDescription(a).then(()=>{this._handleSessionTimersInIncomingResponse(t),this._accepted("remote",t),this.sendRequest(he.ACK),this._confirmed("local",null)}).catch(o=>{this._acceptAndTerminate(t,488,"Not Acceptable Here"),this._failed("remote",t,he.causes.BAD_MEDIA_DESCRIPTION),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})});break}default:{const n=Ge.sipErrorCause(t.status_code);this._failed("remote",t,n)}}}_sendReinvite(t={}){K.debug("sendReinvite()");const n=Ge.cloneArray(t.extraHeaders),a=Ge.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null;let s=!1;n.push(`Contact: ${this._contact}`),n.push("Content-Type: application/sdp"),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(h=>{h=this._mangleOffer(h);const _={originator:"local",type:"offer",sdp:h};K.debug('emit "sdp"'),this.emit("sdp",_),this.sendRequest(he.INVITE,{extraHeaders:n,body:h,eventHandlers:{onSuccessResponse:g=>{r.call(this,g),s=!0},onErrorResponse:g=>{d.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{d()});function r(h){if(this._status===Q.STATUS_TERMINATED||(this.sendRequest(he.ACK),s))return;if(this._handleSessionTimersInIncomingResponse(h),h.body){if(!h.hasHeader("Content-Type")||h.getHeader("Content-Type").toLowerCase()!=="application/sdp"){d.call(this);return}}else{d.call(this);return}const _={originator:"remote",type:"answer",sdp:h.body};K.debug('emit "sdp"'),this.emit("sdp",_);const g=new RTCSessionDescription({type:"answer",sdp:_.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(g)).then(()=>{a.succeeded&&a.succeeded(h)}).catch(T=>{d.call(this),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function d(h){a.failed&&a.failed(h)}}_sendUpdate(t={}){K.debug("sendUpdate()");const n=Ge.cloneArray(t.extraHeaders),a=Ge.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null,s=t.sdpOffer||!1;let r=!1;n.push(`Contact: ${this._contact}`),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),s?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(_=>{_=this._mangleOffer(_);const g={originator:"local",type:"offer",sdp:_};K.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(he.UPDATE,{extraHeaders:n,body:_,eventHandlers:{onSuccessResponse:T=>{d.call(this,T),r=!0},onErrorResponse:T=>{h.call(this,T)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{h.call(this)})):this.sendRequest(he.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:_=>{d.call(this,_)},onErrorResponse:_=>{h.call(this,_)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function d(_){if(this._status!==Q.STATUS_TERMINATED&&!r)if(this._handleSessionTimersInIncomingResponse(_),s){if(_.body){if(!_.hasHeader("Content-Type")||_.getHeader("Content-Type").toLowerCase()!=="application/sdp"){h.call(this);return}}else{h.call(this);return}const g={originator:"remote",type:"answer",sdp:_.body};K.debug('emit "sdp"'),this.emit("sdp",g);const T=new RTCSessionDescription({type:"answer",sdp:g.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(T)).then(()=>{a.succeeded&&a.succeeded(_)}).catch(E=>{h.call(this),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),this.emit("peerconnection:setremotedescriptionfailed",E)})}else a.succeeded&&a.succeeded(_)}function h(_){a.failed&&a.failed(_)}}_acceptAndTerminate(t,n,a){K.debug("acceptAndTerminate()");const o=[];n&&(a=a||he.REASON_PHRASE[n]||"",o.push(`Reason: SIP ;cause=${n}; text="${a}"`)),(this._dialog||this._createDialog(t,"UAC"))&&(this.sendRequest(he.ACK),this.sendRequest(he.BYE,{extraHeaders:o})),this._status=Q.STATUS_TERMINATED}_mangleOffer(t){if(!this._localHold&&!this._remoteHold)return t;if(t=zf.parse(t),this._localHold&&!this._remoteHold){K.debug("mangleOffer() | me on hold, mangling offer");for(const n of t.media)ha.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="sendonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="sendonly")}else if(this._localHold&&this._remoteHold){K.debug("mangleOffer() | both on hold, mangling offer");for(const n of t.media)ha.indexOf(n.type)!==-1&&(n.direction="inactive")}else if(this._remoteHold){K.debug("mangleOffer() | remote on hold, mangling offer");for(const n of t.media)ha.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="recvonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="recvonly")}return zf.write(t)}_setLocalMediaStatus(){let t=!0,n=!0;(this._localHold||this._remoteHold)&&(t=!1,n=!1),this._audioMuted&&(t=!1),this._videoMuted&&(n=!1),this._toggleMuteAudio(!t),this._toggleMuteVideo(!n)}_handleSessionTimersInIncomingRequest(t,n){if(!this._sessionTimers.enabled)return;let a;t.session_expires&&t.session_expires>=he.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,a=t.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,a="uas"),n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${a}`),this._sessionTimers.refresher=a==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(t){if(!this._sessionTimers.enabled)return;let n;t.session_expires&&t.session_expires>=he.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,n=t.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uac"),this._sessionTimers.refresher=n==="uac",this._runSessionTimer()}_runSessionTimer(){const t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(()=>{this._status!==Q.STATUS_TERMINATED&&this._isReadyToReOffer()&&(K.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===he.UPDATE?this._sendUpdate():this._sendReinvite())},t*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==Q.STATUS_TERMINATED&&(K.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:he.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},t*1100)}_toggleMuteAudio(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="audio");for(const a of n)a.track.enabled=!t}_toggleMuteVideo(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="video");for(const a of n)a.track.enabled=!t}_newRTCSession(t,n){K.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:t,session:this,request:n})}_connecting(t){K.debug("session connecting"),K.debug('emit "connecting"'),this.emit("connecting",{request:t})}_progress(t,n){K.debug("session progress"),K.debug('emit "progress"'),this.emit("progress",{originator:t,response:n||null})}_accepted(t,n){K.debug("session accepted"),this._start_time=new Date,K.debug('emit "accepted"'),this.emit("accepted",{originator:t,response:n||null})}_confirmed(t,n){K.debug("session confirmed"),this._is_confirmed=!0,K.debug('emit "confirmed"'),this.emit("confirmed",{originator:t,ack:n||null})}_ended(t,n,a){K.debug("session ended"),this._end_time=new Date,this._close(),K.debug('emit "ended"'),this.emit("ended",{originator:t,message:n||null,cause:a})}_failed(t,n,a){K.debug("session failed"),K.debug('emit "_failed"'),this.emit("_failed",{originator:t,message:n||null,cause:a}),this._close(),K.debug('emit "failed"'),this.emit("failed",{originator:t,message:n||null,cause:a})}_onhold(t){K.debug("session onhold"),this._setLocalMediaStatus(),K.debug('emit "hold"'),this.emit("hold",{originator:t})}_onunhold(t){K.debug("session onunhold"),this._setLocalMediaStatus(),K.debug('emit "unhold"'),this.emit("unhold",{originator:t})}_onmute({audio:t,video:n}){K.debug("session onmute"),this._setLocalMediaStatus(),K.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}_onunmute({audio:t,video:n}){K.debug("session onunmute"),this._setLocalMediaStatus(),K.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}};const Sg=Me(eh),yg=ct.EventEmitter,Cg=at,iu=De,Ag=Tt,Qr=mt(),Rg=Fn,th=Ts,Ig=ps(),da=new Cg("Message");var bg=class extends yg{constructor(t){super(),this._ua=t,this._request=null,this._closed=!1,this._direction=null,this._local_identity=null,this._remote_identity=null,this._is_replied=!1,this._data={}}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}send(t,n,a={}){const o=t;if(t===void 0||n===void 0)throw new TypeError("Not enough arguments");if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${o}`);const s=Qr.cloneArray(a.extraHeaders),r=Qr.cloneObject(a.eventHandlers),d=a.contentType||"text/plain",h={};a.fromUserName&&(h.from_uri=new Ig("sip",a.fromUserName,this._ua.configuration.uri.host),s.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),a.fromDisplayName&&(h.from_display_name=a.fromDisplayName);for(const g in r)Object.prototype.hasOwnProperty.call(r,g)&&this.on(g,r[g]);s.push(`Content-Type: ${d}`),this._request=new Ag.OutgoingRequest(iu.MESSAGE,t,this._ua,h,s),n&&(this._request.body=n);const _=new Rg(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:g=>{this._receiveResponse(g)}});this._newMessage("local",this._request),_.send()}init_incoming(t){this._request=t,this._newMessage("remote",t),this._is_replied||(this._is_replied=!0,t.reply(200)),this._close()}accept(t={}){const n=Qr.cloneArray(t.extraHeaders),a=t.body;if(this._direction!=="incoming")throw new th.NotSupportedError('"accept" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");this._is_replied=!0,this._request.reply(200,null,n,a)}reject(t={}){const n=t.status_code||480,a=t.reason_phrase,o=Qr.cloneArray(t.extraHeaders),s=t.body;if(this._direction!=="incoming")throw new th.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(n<300||n>=700)throw new TypeError(`Invalid status_code: ${n}`);this._is_replied=!0,this._request.reply(n,a,o,s)}_receiveResponse(t){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):this._succeeded("remote",t);break;default:{const n=Qr.sipErrorCause(t.status_code);this._failed("remote",t,n);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,iu.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,iu.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newMessage(t,n){t==="remote"?(this._direction="incoming",this._local_identity=n.to,this._remote_identity=n.from):t==="local"&&(this._direction="outgoing",this._local_identity=n.from,this._remote_identity=n.to),this._ua.newMessage(this,{originator:t,message:this,request:n})}_failed(t,n,a){da.debug("MESSAGE failed"),this._close(),da.debug('emit "failed"'),this.emit("failed",{originator:t,response:n||null,cause:a})}_succeeded(t,n){da.debug("MESSAGE succeeded"),this._close(),da.debug('emit "succeeded"'),this.emit("succeeded",{originator:t,response:n})}};const wg=ct.EventEmitter,Og=at,lu=De,Dg=Tt,Zr=mt(),Ng=Fn,sh=Ts,_a=new Og("Options");var Ug=class extends wg{constructor(t){super(),this._ua=t,this._request=null,this._closed=!1,this._direction=null,this._local_identity=null,this._remote_identity=null,this._is_replied=!1,this._data={}}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}send(t,n,a={}){const o=t;if(t===void 0)throw new TypeError("A target is required for OPTIONS");if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${o}`);const s=Zr.cloneArray(a.extraHeaders),r=Zr.cloneObject(a.eventHandlers),d=a.contentType||"application/sdp";for(const _ in r)Object.prototype.hasOwnProperty.call(r,_)&&this.on(_,r[_]);s.push(`Content-Type: ${d}`),this._request=new Dg.OutgoingRequest(lu.OPTIONS,t,this._ua,null,s),n&&(this._request.body=n);const h=new Ng(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:_=>{this._receiveResponse(_)}});this._newOptions("local",this._request),h.send()}init_incoming(t){this._request=t,this._newOptions("remote",t),this._is_replied||(this._is_replied=!0,t.reply(200)),this._close()}accept(t={}){const n=Zr.cloneArray(t.extraHeaders),a=t.body;if(this._direction!=="incoming")throw new sh.NotSupportedError('"accept" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");this._is_replied=!0,this._request.reply(200,null,n,a)}reject(t={}){const n=t.status_code||480,a=t.reason_phrase,o=Zr.cloneArray(t.extraHeaders),s=t.body;if(this._direction!=="incoming")throw new sh.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(n<300||n>=700)throw new TypeError(`Invalid status_code: ${n}`);this._is_replied=!0,this._request.reply(n,a,o,s)}_receiveResponse(t){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):this._succeeded("remote",t);break;default:{const n=Zr.sipErrorCause(t.status_code);this._failed("remote",t,n);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,lu.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,lu.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newOptions(t,n){t==="remote"?(this._direction="incoming",this._local_identity=n.to,this._remote_identity=n.from):t==="local"&&(this._direction="outgoing",this._local_identity=n.from,this._remote_identity=n.to),this._ua.newOptions(this,{originator:t,message:this,request:n})}_failed(t,n,a){_a.debug("OPTIONS failed"),this._close(),_a.debug('emit "failed"'),this.emit("failed",{originator:t,response:n||null,cause:a})}_succeeded(t,n){_a.debug("OPTIONS succeeded"),this._close(),_a.debug('emit "succeeded"'),this.emit("succeeded",{originator:t,response:n})}},au={};const Pg=at,ou=mt(),xg=Jt(),ei=new Pg("Socket");au.isSocket=c=>{if(Array.isArray(c))return!1;if(typeof c>"u")return ei.warn("undefined JsSIP.Socket instance"),!1;try{if(!ou.isString(c.url))throw ei.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!ou.isString(c.via_transport))throw ei.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(xg.parse(c.sip_uri,"SIP_URI")===-1)throw ei.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch{return!1}try{["connect","disconnect","send"].forEach(t=>{if(!ou.isFunction(c[t]))throw ei.warn(`missing or invalid JsSIP.Socket method: ${t}`),new Error(`Missing or invalid JsSIP.Socket method: ${t}`)})}catch{return!1}return!0};const kg=at,Mg=au,nh=De,xt=new kg("Transport"),qt={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:nh.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:nh.CONNECTION_RECOVERY_MAX_INTERVAL}};var rh=class{constructor(t,n=qt.recovery_options){xt.debug("new()"),this.status=qt.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(a){xt.warn(`cannot use TextDecoder: ${a}`)}if(typeof t>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(a){if(!Mg.isSocket(a.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(a.weight&&!Number(a.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:a.socket,weight:a.weight||0,status:qt.SOCKET_STATUS_READY})},this),this._getSocket()}get via_transport(){return this.socket.via_transport}get url(){return this.socket.url}get sip_uri(){return this.socket.sip_uri}connect(){if(xt.debug("connect()"),this.isConnected()){xt.debug("Transport is already connected");return}else if(this.isConnecting()){xt.debug("Transport is connecting");return}this.close_requested=!1,this.status=qt.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect())}disconnect(){xt.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=qt.STATUS_DISCONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=()=>{},this.socket.ondisconnect=()=>{},this.socket.ondata=()=>{},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}send(t){if(xt.debug("send()"),!this.isConnected())return xt.warn("unable to send message, transport is not connected"),!1;const n=t.toString();return xt.debug(`sending message:
|
116
116
|
|
117
117
|
${n}
|
118
118
|
`),this.socket.send(n)}isConnected(){return this.status===qt.STATUS_CONNECTED}isConnecting(){return this.status===qt.STATUS_CONNECTING}_reconnect(){this.recover_attempts+=1;let t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);t<this.recovery_options.min_interval?t=this.recovery_options.min_interval:t>this.recovery_options.max_interval&&(t=this.recovery_options.max_interval),xt.debug(`reconnection attempt: ${this.recover_attempts}. next connection attempt in ${t} seconds`),this.recovery_timer=setTimeout(()=>{!this.close_requested&&!(this.isConnected()||this.isConnecting())&&(this._getSocket(),this.connect())},t*1e3)}_getSocket(){let t=[];if(this.sockets.forEach(a=>{a.status!==qt.SOCKET_STATUS_ERROR&&(t.length===0?t.push(a):a.weight>t[0].weight?t=[a]:a.weight===t[0].weight&&t.push(a))}),t.length===0){this.sockets.forEach(a=>{a.status=qt.SOCKET_STATUS_READY}),this._getSocket();return}const n=Math.floor(Math.random()*t.length);this.socket=t[n].socket}_onConnect(){this.recover_attempts=0,this.status=qt.STATUS_CONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}_onDisconnect(t,n,a){this.status=qt.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:t,code:n,reason:a}),!this.close_requested&&(this.sockets.forEach(function(o){this.socket===o.socket&&(o.status=qt.SOCKET_STATUS_ERROR)},this),this._reconnect(t))}_onData(t){if(t===`\r
|
@@ -131,15 +131,15 @@ ${t}
|
|
131
131
|
`,a+=`Call-ID: ${je.call_id}\r
|
132
132
|
`,a+=`CSeq: ${je.cseq} ${je.method}\r
|
133
133
|
`,a+=`\r
|
134
|
-
`,oh.send(a)}const Qg=Me(uh);var si={};const jn=mt(),rn=De,du=Jt(),ch=ps(),_u=au,pu=Ts;si.settings={authorization_user:null,password:null,realm:null,ha1:null,authorization_jwt:null,display_name:null,uri:null,contact_uri:null,instance_id:null,use_preloaded_route:!1,session_timers:!0,session_timers_refresh_method:rn.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:rn.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:rn.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:`${jn.createRandomToken(12)}.invalid`};const ma={mandatory:{sockets(c){const t=[];if(_u.isSocket(c))t.push({socket:c});else if(Array.isArray(c)&&c.length)for(const n of c)Object.prototype.hasOwnProperty.call(n,"socket")&&_u.isSocket(n.socket)?t.push(n):_u.isSocket(n)&&t.push({socket:n});else return;return t},uri(c){/^sip:/i.test(c)||(c=`${rn.SIP}:${c}`);const t=ch.parse(c);if(t)return t.user?t:void 0}},optional:{authorization_user(c){if(du.parse(`"${c}"`,"quoted_string")!==-1)return c},authorization_jwt(c){if(typeof c=="string")return c},user_agent(c){if(typeof c=="string")return c},connection_recovery_max_interval(c){if(jn.isDecimal(c)){const t=Number(c);if(t>0)return t}},connection_recovery_min_interval(c){if(jn.isDecimal(c)){const t=Number(c);if(t>0)return t}},contact_uri(c){if(typeof c=="string"){const t=du.parse(c,"SIP_URI");if(t!==-1)return t}},display_name(c){return c},instance_id(c){if(/^uuid:/i.test(c)&&(c=c.substr(5)),du.parse(c,"uuid")!==-1)return c},no_answer_timeout(c){if(jn.isDecimal(c)){const t=Number(c);if(t>0)return t}},session_timers(c){if(typeof c=="boolean")return c},session_timers_refresh_method(c){if(typeof c=="string"&&(c=c.toUpperCase(),c===rn.INVITE||c===rn.UPDATE))return c},session_timers_force_refresher(c){if(typeof c=="boolean")return c},password(c){return String(c)},realm(c){return String(c)},ha1(c){return String(c)},register(c){if(typeof c=="boolean")return c},register_expires(c){if(jn.isDecimal(c)){const t=Number(c);if(t>0)return t}},registrar_server(c){/^sip:/i.test(c)||(c=`${rn.SIP}:${c}`);const t=ch.parse(c);if(t)return t.user?void 0:t},use_preloaded_route(c){if(typeof c=="boolean")return c},extra_headers(c){const t=[];if(Array.isArray(c)&&c.length)for(const n of c)typeof n=="string"&&t.push(n);else return;return t}}};si.load=(c,t)=>{for(const n in ma.mandatory)if(t.hasOwnProperty(n)){const a=t[n],o=ma.mandatory[n](a);if(o!==void 0)c[n]=o;else throw new pu.ConfigurationError(n,a)}else throw new pu.ConfigurationError(n);for(const n in ma.optional)if(t.hasOwnProperty(n)){const a=t[n];if(jn.isEmpty(a))continue;const o=ma.optional[n](a);if(o!==void 0)c[n]=o;else throw new pu.ConfigurationError(n,a)}};const Zg=ct.EventEmitter,eT=at,vt=De,tT=Vm,fh=eh,hh=bg,dh=Ug,mu=Hn,sT=rh,ga=mt(),nT=Ts,rT=ps(),iT=ih,gu=Tt,lT=uh,Tu=si,qe=new eT("UA"),Et={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};var _h=class extends Zg{static get C(){return Et}constructor(t){if(qe.debug("new() [configuration:%o]",t),super(),this._cache={credentials:{}},this._configuration=Object.assign({},Tu.settings),this._dynConfiguration={},this._dialogs={},this._applicants={},this._sessions={},this._transport=null,this._contact=null,this._status=Et.STATUS_INIT,this._error=null,this._transactions={nist:{},nict:{},ist:{},ict:{}},this._data={},this._closeTimer=null,t===void 0)throw new TypeError("Not enough arguments");try{this._loadConfig(t)}catch(n){throw this._status=Et.STATUS_NOT_READY,this._error=Et.CONFIGURATION_ERROR,n}this._registrator=new tT(this)}get C(){return Et}get status(){return this._status}get contact(){return this._contact}get configuration(){return this._configuration}get transport(){return this._transport}start(){qe.debug("start()"),this._status===Et.STATUS_INIT?this._transport.connect():this._status===Et.STATUS_USER_CLOSED?(qe.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=Et.STATUS_INIT,this._transport.connect()):this._status===Et.STATUS_READY?qe.debug("UA is in READY status, not restarted"):qe.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}register(){qe.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}unregister(t){qe.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(t)}registrator(){return this._registrator}isRegistered(){return this._registrator.registered}isConnected(){return this._transport.isConnected()}call(t,n){qe.debug("call()");const a=new fh(this);return a.connect(t,n),a}sendMessage(t,n,a){qe.debug("sendMessage()");const o=new hh(this);return o.send(t,n,a),o}sendOptions(t,n,a){qe.debug("sendOptions()");const o=new dh(this);return o.send(t,n,a),o}terminateSessions(t){qe.debug("terminateSessions()");for(const n in this._sessions)this._sessions[n].isEnded()||this._sessions[n].terminate(t)}stop(){if(qe.debug("stop()"),this._dynConfiguration={},this._status===Et.STATUS_USER_CLOSED){qe.debug("UA already closed");return}this._registrator.close();const t=Object.keys(this._sessions).length;for(const a in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,a)){qe.debug(`closing session ${a}`);try{this._sessions[a].terminate()}catch{}}for(const a in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,a))try{this._applicants[a].close()}catch{}this._status=Et.STATUS_USER_CLOSED,Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length===0&&t===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}normalizeTarget(t){return ga.normalizeTarget(t,this._configuration.hostport_params)}get(t){switch(t){case"authorization_user":return this._configuration.authorization_user;case"realm":return this._configuration.realm;case"ha1":return this._configuration.ha1;case"authorization_jwt":return this._configuration.authorization_jwt;default:qe.warn('get() | cannot get "%s" parameter in runtime',t);return}}set(t,n){switch(t){case"authorization_user":{this._configuration.authorization_user=String(n);break}case"password":{this._configuration.password=String(n);break}case"realm":{this._configuration.realm=String(n);break}case"ha1":{this._configuration.ha1=String(n),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(n);break}case"display_name":{this._configuration.display_name=n;break}default:return qe.warn('set() | cannot set "%s" parameter in runtime',t),!1}return!0}newTransaction(t){this._transactions[t.type][t.id]=t,this.emit("newTransaction",{transaction:t})}destroyTransaction(t){delete this._transactions[t.type][t.id],this.emit("transactionDestroyed",{transaction:t})}newDialog(t){this._dialogs[t.id]=t}destroyDialog(t){delete this._dialogs[t.id]}newMessage(t,n){this._applicants[t]=t,this.emit("newMessage",n)}newOptions(t,n){this._applicants[t]=t,this.emit("newOptions",n)}destroyMessage(t){delete this._applicants[t]}newRTCSession(t,n){this._sessions[t.id]=t,this.emit("newRTCSession",n)}destroyRTCSession(t){delete this._sessions[t.id]}registered(t){this.emit("registered",t)}unregistered(t){this.emit("unregistered",t)}registrationFailed(t){this.emit("registrationFailed",t)}receiveRequest(t){console.log("receiveRequest");const n=t.method;if(t.ruri.user!==this._configuration.uri.user&&t.ruri.user!==this._contact.uri.user){qe.debug("Request-URI does not point to us"),t.method!==vt.ACK&&t.reply_sl(404);return}if(t.ruri.scheme===vt.SIPS){t.reply_sl(416);return}if(mu.checkTransaction(this,t))return;if(n===vt.INVITE?new mu.InviteServerTransaction(this,this._transport,t):n!==vt.ACK&&n!==vt.CANCEL&&new mu.NonInviteServerTransaction(this,this._transport,t),n===vt.OPTIONS){if(console.log("OPPP in option"),this.listeners("newOptions").length===0){t.reply(200);return}new dh(this).init_incoming(t)}else if(n===vt.MESSAGE){if(this.listeners("newMessage").length===0){t.reply(405);return}new hh(this).init_incoming(t)}else if(n===vt.INVITE&&!t.to_tag&&this.listeners("newRTCSession").length===0){t.reply(405);return}let a,o;if(t.to_tag)a=this._findDialog(t.call_id,t.from_tag,t.to_tag),a?a.receiveRequest(t):n===vt.NOTIFY?(o=this._findSession(t),o?o.receiveRequest(t):(qe.debug("received NOTIFY request for a non existent subscription"),t.reply(481,"Subscription does not exist"))):n!==vt.ACK&&t.reply(481);else switch(n){case vt.INVITE:if(window.RTCPeerConnection)if(t.hasHeader("replaces")){const s=t.replaces;a=this._findDialog(s.call_id,s.from_tag,s.to_tag),a?(o=a.owner,o.isEnded()?t.reply(603):o.receiveRequest(t)):t.reply(481)}else o=new fh(this),o.init_incoming(t);else qe.warn("INVITE received but WebRTC is not supported"),t.reply(488);break;case vt.BYE:t.reply(481);break;case vt.CANCEL:o=this._findSession(t),o?o.receiveRequest(t):qe.debug("received CANCEL request for a non existent session");break;case vt.ACK:break;case vt.NOTIFY:this.emit("sipEvent",{event:t.event,request:t}),t.reply(200);break;default:t.reply(405);break}}_findSession({call_id:t,from_tag:n,to_tag:a}){const o=t+n,s=this._sessions[o],r=t+a,d=this._sessions[r];return s||d||null}_findDialog(t,n,a){let o=t+n+a,s=this._dialogs[o];return s||(o=t+a+n,s=this._dialogs[o],s||null)}_loadConfig(t){console.log("in _loadConfig");try{console.log("config.load"),Tu.load(this._configuration,t)}catch(o){throw console.log("throw in _loadConfig",o),o}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=ga.newUUID()),this._configuration.jssip_id=ga.createRandomToken(5);const n=this._configuration.uri.clone();n.user=null,this._configuration.hostport_params=n.toString().replace(/^sip:/i,"");try{console.log("new transport"),this._transport=new sT(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=aT.bind(this),this._transport.onconnect=oT.bind(this),this._transport.ondisconnect=uT.bind(this),this._transport.ondata=cT.bind(this)}catch(o){throw qe.warn(o),new nT.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){const o=this._configuration.uri.clone();o.user=null,o.clearParams(),o.clearHeaders(),this._configuration.registrar_server=o}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:(console.log("this._configuration.contact_uri 1"),this._configuration.contact_uri=new rT("sip",ga.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),console.log("this._configuration.contact_uri 2",this._configuration.contact_uri)),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(o={}){const s=o.anonymous||null,r=o.outbound||null;let d="<";return s?d+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":d+=this.pub_gruu||this.uri.toString(),r&&(s?!this.temp_gruu:!this.pub_gruu)&&(d+=";ob"),d+=">",console.log("contact",d),d}};const a=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const o in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,o)&&(a.indexOf(o)!==-1?Object.defineProperty(this._configuration,o,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,o,{writable:!1,configurable:!1}));qe.debug("configuration parameters after validation:"),qe.debug("this._contact.toString:",this._contact.toString());for(const o in this._configuration)if(Object.prototype.hasOwnProperty.call(Tu.settings,o))switch(o){case"uri":case"registrar_server":qe.debug(`- ${o}: ${this._configuration[o]}`);break;case"password":case"ha1":case"authorization_jwt":qe.debug(`- ${o}: NOT SHOWN`);break;default:qe.debug(`- ${o}: ${JSON.stringify(this._configuration[o])}`)}console.log("_loadConfig retun")}};function aT(c){this.emit("connecting",c)}function oT(c){this._status!==Et.STATUS_USER_CLOSED&&(this._status=Et.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function uT(c){const t=["nict","ict","nist","ist"];for(const n of t)for(const a in this._transactions[n])Object.prototype.hasOwnProperty.call(this._transactions[n],a)&&this._transactions[n][a].onTransportError();this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==Et.STATUS_USER_CLOSED&&(this._status=Et.STATUS_NOT_READY,this._error=Et.NETWORK_ERROR)}function cT(c){console.log("onTransportData",c);const t=c.transport;let n=c.message;if(n=iT.parseMessage(n,this),!!n&&!(this._status===Et.STATUS_USER_CLOSED&&n instanceof gu.IncomingRequest)&&lT(n,this,t)){if(n instanceof gu.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof gu.IncomingResponse){let a;switch(n.method){case vt.INVITE:a=this._transactions.ict[n.via_branch],a&&a.receiveResponse(n);break;case vt.ACK:break;default:a=this._transactions.nict[n.via_branch],a&&a.receiveResponse(n);break}}}}const fT=Me(_h);for(var St=[],vu=0;vu<256;++vu)St.push((vu+256).toString(16).slice(1));function hT(c,t=0){return(St[c[t+0]]+St[c[t+1]]+St[c[t+2]]+St[c[t+3]]+"-"+St[c[t+4]]+St[c[t+5]]+"-"+St[c[t+6]]+St[c[t+7]]+"-"+St[c[t+8]]+St[c[t+9]]+"-"+St[c[t+10]]+St[c[t+11]]+St[c[t+12]]+St[c[t+13]]+St[c[t+14]]+St[c[t+15]]).toLowerCase()}var Ta,dT=new Uint8Array(16);function _T(){if(!Ta&&(Ta=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Ta))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ta(dT)}var pT=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const ph={randomUUID:pT};function mh(c,t,n){if(ph.randomUUID&&!t&&!c)return ph.randomUUID();c=c||{};var a=c.random||(c.rng||_T)();if(a[6]=a[6]&15|64,a[8]=a[8]&63|128,t){n=n||0;for(var o=0;o<16;++o)t[n+o]=a[o];return t}return hT(a)}var xe=mt();const vs=Me(xe),Eu=new ra("Dialog"),xs={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};class va{static get C(){return xs}constructor(t,n,a,o=xs.STATUS_CONFIRMED){if(this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,n instanceof Tt.IncomingResponse&&(o=n.status_code<200?xs.STATUS_EARLY:xs.STATUS_CONFIRMED),a==="UAS"){this._id={call_id:n.call_id,local_tag:n.to_tag,remote_tag:n.from_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri;let s=n.getHeaders("to")[0].split(";")[0];s=s.match(/<([^>]*)>/)[1],this._remote_target=s,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum}else if(a==="UAC"){this._id={call_id:n.call_id,local_tag:n.from_tag,remote_tag:n.to_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri;let s=n.getHeaders("to")[0].split(";")[0];s=s.match(/<([^>]*)>/)[1],this._remote_target=s,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null}this._ua.newDialog(this),Eu.debug(`new ${a} dialog created with status ${this._state===xs.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(t){this._local_seqnum=t}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(t){this._uac_pending_reply=t}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===xs.STATUS_TERMINATED}update(t,n){this._state=xs.STATUS_CONFIRMED,Eu.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),n==="UAC"&&(this._route_set=t.getHeaders("record-route").reverse())}terminate(){Eu.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=xs.STATUS_TERMINATED}sendRequest(t,n={}){const a=vs.cloneArray(n.extraHeaders),o=vs.cloneObject(n.eventHandlers),s=n.body||null,r=this._createRequest(t,a,s);return o.onAuthenticated=()=>{this._local_seqnum+=1},new Jm(this,r,o).send(),r}receiveRequest(t){this._checkInDialogRequest(t)&&(t.method===L.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:t.method===L.INVITE&&(this._ack_seqnum=t.cseq),this._owner.receiveRequest(t))}_createRequest(t,n,a){n=vs.cloneArray(n),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const o=t===L.CANCEL||t===L.ACK?this._local_seqnum:this._local_seqnum+=1;return new Tt.OutgoingRequest(t,this._remote_target,this._ua,{cseq:o,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},n,a)}_checkInDialogRequest(t){if(!this._remote_seqnum)this._remote_seqnum=t.cseq;else if(t.cseq<this._remote_seqnum)if(t.method===L.ACK){if(this._ack_seqnum===null||t.cseq!==this._ack_seqnum)return!1}else return t.reply(500),!1;else t.cseq>this._remote_seqnum&&(this._remote_seqnum=t.cseq);if(t.method===L.INVITE||t.method===L.UPDATE&&t.body){if(this._uac_pending_reply===!0)t.reply(491);else if(this._uas_pending_reply===!0){const n=(Math.random()*10|0)+1;return t.reply(500,null,[`Retry-After:${n}`]),!1}else{this._uas_pending_reply=!0;const n=()=>{(t.server_transaction.state===jt.C.STATUS_ACCEPTED||t.server_transaction.state===jt.C.STATUS_COMPLETED||t.server_transaction.state===jt.C.STATUS_TERMINATED)&&(t.server_transaction.removeListener("stateChanged",n),this._uas_pending_reply=!1)};t.server_transaction.on("stateChanged",n)}t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===jt.C.STATUS_ACCEPTED&&(this._remote_target=t.parseHeader("contact").uri)})}else t.method===L.NOTIFY&&t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===jt.C.STATUS_COMPLETED&&(this._remote_target=t.parseHeader("contact").uri)});return!0}}class mT{constructor(t,n){ts(this,"plugin",null);ts(this,"rtcpPeer",null);ts(this,"handleId",0);ts(this,"info",null);ts(this,"joinResult",null);ts(this,"state",{});ts(this,"stream",null);ts(this,"loaded",!1);ts(this,"aTracks",[]);ts(this,"vTracks",[]);this.info=t,this.plugin=n,this.rtcpPeer=new RTCPeerConnection({iceServers:[]})}get memberInfo(){return{stream:this.stream,joinResult:this.joinResult,sender:this.handleId,type:"subscriber",name:this.info.display,state:this.state,id:this.handleId}}updateMemberState(t){var n;this.state={...this.state,...t||{}},(n=this.plugin)==null||n.session.emit("member:update",this.memberInfo)}updateMemberStateFromMessage(t){var s,r,d,h;const n=(r=(s=t==null?void 0:t.plugindata)==null?void 0:s.data)==null?void 0:r.newStatePublisher,o=((h=(d=t==null?void 0:t.plugindata)==null?void 0:d.data)==null?void 0:h.publisher_state).find(_=>_.id===n);this.updateMemberState(o==null?void 0:o.state)}hangup(){this.rtcpPeer&&(this.rtcpPeer.close(),this.rtcpPeer=null),this.stream&&this.stream.getTracks().forEach(t=>{t.stop()})}}class Xt{static canGetMediaDevices(){return!(!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices)}static async getDevices(t){return Xt.canGetMediaDevices()?(await navigator.mediaDevices.enumerateDevices()).filter(a=>a.kind===t):[]}static async getMicrophoneList(){return(await Xt.getDevices("audioinput")).map((n,a)=>({...n,deviceId:n.deviceId,label:n.label||`microphone ${a+1}`,kind:n.kind,groupId:n.groupId}))}static async getSpeakerList(){return(await Xt.getDevices("audiooutput")).map((n,a)=>({...n,deviceId:n.deviceId,label:n.label||`speaker ${a+1}`,kind:n.kind,groupId:n.groupId}))}static async getCameraList(){return(await Xt.getDevices("videoinput")).map((n,a)=>({...n,deviceId:n.deviceId,label:n.label||`camera ${a+1}`,kind:n.kind,groupId:n.groupId}))}static stopStreamTracks(t){t&&t.getTracks().forEach(n=>{n.stop()})}static async getMediaFromInputs({videoInput:t,audioInput:n}){let a,o;t==="default"?a=!0:t&&t!=="default"&&(a={deviceId:{exact:t}}),n==="default"?o=!0:n&&n!=="default"&&(o={deviceId:{exact:n}});const s={audio:o,video:a};return Xt.getUserMedia(s)}static async getUserMedia(t){return await navigator.mediaDevices.getUserMedia(t)}static async changeAudioOutput(t,n){if(!(!t||!n))if(typeof t.sinkId<"u")try{await t.setSinkId(n)}catch(a){let o=a;a.name==="SecurityError"&&(o=`You need to use HTTPS for selecting audio output device: ${a}`),console.error(o)}else console.warn("Browser does not support output device selection.")}static toggleAudioMute(t){const n=t.getAudioTracks();if(n.length!==0)return n.forEach(a=>{a.enabled=!a.enabled}),n[0].enabled}static toggleVideoMute(t){const n=t.getVideoTracks();if(n.length!==0)return n.forEach(a=>{a.enabled=!a.enabled}),n[0].enabled}static async getStream(t={video:!0,audio:!0}){try{const n=await navigator.mediaDevices.getUserMedia(t);let a=n.getTracks();return t.video?a=n.getVideoTracks():t.audio&&(a=n.getAudioTracks()),a.length===0?{stream:n,track:null}:{stream:n,track:a[0]}}catch(n){return console.warn(n),{stream:null,track:null}}}}var gT=ps();const ln=Me(gT),kt={LEAVE:"Leave",DETACH:"Detach",AUDIO_CHANGE:"AudioChange",VIDEO_CHANGE:"VideoChange",STATE:"State",ICE:"Ice",CONFIGURE:"Configure",TRICKLE:"Trickle",SUBSCRIBER:"Subscriber",PUBLISHER:"Publisher"},z=new ra("JanusSession"),TT="/opt/recordings/",te={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9},Ea=["audio","video"];class Sa extends ct.EventEmitter{static get C(){return te}constructor(t){z.debug("new"),super(),this._id=null,this._ua=t,this._status=te.STATUS_NULL,this._dialog=null,this._earlyDialogs={},this._contact=null,this._from_tag=null,this._to_tag=null,this.lastTransaction=0,this._connection=null,this._connectionPromiseQueue=Promise.resolve(),this._request=null,this._is_canceled=!1,this._cancel_reason="",this._is_confirmed=!1,this._late_sdp=!1,this._rtcOfferConstraints=null,this._rtcAnswerConstraints=null,this._localMediaStream=null,this._localMediaStreamLocallyGenerated=!1,this._rtcReady=!0,this._iceReady=!1,this._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},this._direction=null,this._local_identity=null,this._remote_identity=null,this._start_time=null,this._end_time=null,this._audioMuted=!1,this._videoMuted=!1,this._localHold=!1,this._remoteHold=!1,this._sessionTimers={enabled:this._ua.configuration.session_timers,refreshMethod:this._ua.configuration.session_timers_refresh_method,defaultExpires:L.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._referSubscribers={},this._candidates=[],this.publishers=[],this.private_id=null,this.memberList={},this.myFeedList=[],this.display_name="",this.stunServers=[{urls:"stun:turn.voicenter.co",credential:"kxsjahnsdjns3eds23esd",username:"turn2es21e"}],this.opaque_id=this.generateOpaqueId(),this.screen_share_opaque_id=this.generateOpaqueId(),this._data={},this.isAudioOn=!0,this.isVideoOn=!0,this.mediaConstraints={}}get C(){return te}get causes(){return L.causes}get id(){return this._id}get connection(){return this._connection}get contact(){return this._contact}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}get start_time(){return this._start_time}get end_time(){return this._end_time}get data(){return this._data}set data(t){this._data=t}get status(){return this._status}isInProgress(){switch(this._status){case te.STATUS_NULL:case te.STATUS_INVITE_SENT:case te.STATUS_1XX_RECEIVED:case te.STATUS_INVITE_RECEIVED:case te.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case te.STATUS_ANSWERED:case te.STATUS_WAITING_FOR_ACK:case te.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case te.STATUS_CANCELED:case te.STATUS_TERMINATED:return!0;default:return!1}}isMuted(){return{audio:this._audioMuted,video:this._videoMuted}}isOnHold(){return{local:this._localHold,remote:this._remoteHold}}getPTypeHeader(t){return`PTYPE: ${t}`}generateOpaqueId(){return`videoroomtest-${mh().replace(/-/g,"").slice(0,12)}`}connect(t,n,a={},o){z.debug("connect()"),this.display_name=n;const s=t,r=xe.cloneObject(a.eventHandlers),d=xe.cloneArray(a.extraHeaders),h=xe.cloneObject(a.mediaConstraints,{audio:!0,video:!0});this.mediaConstraints={...h};const _=a.mediaStream||null,g=xe.cloneObject(a.pcConfig,{iceServers:[]}),T=a.rtcConstraints||null,E=a.rtcOfferConstraints||null;if(this._rtcOfferConstraints=E,this._rtcAnswerConstraints=a.rtcAnswerConstraints||null,this._data=a.data||this._data,t===void 0)throw new TypeError("Not enough arguments");if(this._status!==te.STATUS_NULL)throw new Ns.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new Ns.NotSupportedError("WebRTC not supported");if(t=this._ua.normalizeTarget(t),this.room_id=t.user,this.target=t,!t)throw new TypeError(`Invalid target: ${s}`);this._sessionTimers.enabled&&xe.isDecimal(a.sessionTimersExpires)&&(a.sessionTimersExpires>=L.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=a.sessionTimersExpires:this._sessionTimers.defaultExpires=L.SESSION_EXPIRES);for(const C in r)Object.prototype.hasOwnProperty.call(r,C)&&this.on(C,r[C]);this._from_tag=xe.newTag();const y=a.anonymous||!1,A={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:y,outbound:!0}),y?(A.from_display_name="Anonymous",A.from_uri=new ln("sip","anonymous","anonymous.invalid"),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),d.push("Privacy: id")):a.fromUserName&&(A.from_uri=new ln("sip",a.fromUserName,this._ua.configuration.uri.host),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),a.fromDisplayName&&(A.from_display_name=a.fromDisplayName),d.push(`Contact: ${this._contact}`),d.push("Content-Type: application/json"),this._sessionTimers.enabled&&d.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new Tt.InitialOutgoingInviteRequest(t,this._ua,A,d),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(g,T),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,o&&o(this),this._newJanusSession("local",this._request),this._sendInitialRequest(h,E,_)}_overrideSenderTracks(t,n){t.getTracks().forEach(a=>{n.getSenders().forEach(async s=>{s.track.kind===a.kind&&(a.kind==="audio"&&!this.isAudioOn&&(a.enabled=!1),a.kind==="video"&&!this.isVideoOn&&(a.enabled=!1),await s.replaceTrack(a))})})}init_incoming(t,n){z.debug("init_incoming()");let a;const o=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;if(t.body&&o!=="application/sdp"){t.reply(415);return}if(this._status=te.STATUS_INVITE_RECEIVED,this._from_tag=t.from_tag,this._id=t.call_id+this._from_tag,this._request=t,this._contact=this._ua.contact.toString(),t.hasHeader("expires")&&(a=t.getHeader("expires")*1e3),t.to_tag=xe.newTag(),!this._createDialog(t,"UAS",!0)){t.reply(500,"Missing Contact header field");return}t.body?this._late_sdp=!1:this._late_sdp=!0,this._status=te.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{t.reply(408),this._failed("local",null,L.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),a&&(this._timers.expiresTimer=setTimeout(()=>{this._status===te.STATUS_WAITING_FOR_ANSWER&&(t.reply(487),this._failed("system",null,L.causes.EXPIRES))},a)),this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from,n&&n(this),this._newJanusSession("remote",t),this._status!==te.STATUS_TERMINATED&&(t.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(t={}){z.debug("answer()");const n=this._request,a=xe.cloneArray(t.extraHeaders),o=xe.cloneObject(t.mediaConstraints),s=t.mediaStream||null,r=xe.cloneObject(t.pcConfig,{iceServers:[]}),d=t.rtcConstraints||null,h=t.rtcAnswerConstraints||null,_=xe.cloneObject(t.rtcOfferConstraints);let g,T=!1,E=!1,y=!1,A=!1;if(this._rtcAnswerConstraints=h,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,this._direction!=="incoming")throw new Ns.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==te.STATUS_WAITING_FOR_ANSWER)throw new Ns.InvalidStateError(this._status);if(this._sessionTimers.enabled&&xe.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=L.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=L.SESSION_EXPIRES),this._status=te.STATUS_ANSWERED,!this._createDialog(n,"UAS")){n.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),a.unshift(`Contact: ${this._contact}`);const C=n.parseSDP();Array.isArray(C.media)||(C.media=[C.media]);for(const I of C.media)I.type==="audio"&&(T=!0,(!I.direction||I.direction==="sendrecv")&&(y=!0)),I.type==="video"&&(E=!0,(!I.direction||I.direction==="sendrecv")&&(A=!0));if(s&&o.audio===!1){g=s.getAudioTracks();for(const I of g)s.removeTrack(I)}if(s&&o.video===!1){g=s.getVideoTracks();for(const I of g)s.removeTrack(I)}!s&&o.audio===void 0&&(o.audio=y),!s&&o.video===void 0&&(o.video=A),!s&&!T&&!_.offerToReceiveAudio&&(o.audio=!1),!s&&!E&&!_.offerToReceiveVideo&&(o.video=!1),this._createRTCConnection(r,d),Promise.resolve().then(()=>{if(s)return s;if(o.audio||o.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(I=>{throw this._status===te.STATUS_TERMINATED?new Error("terminated"):(n.reply(480),this._failed("local",null,L.causes.USER_DENIED_MEDIA_ACCESS),z.warn('emit "getusermediafailed" [error:%o]',I),this.emit("getusermediafailed",I),new Error("getUserMedia() failed"))})}).then(I=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=I,I&&I.getTracks().forEach(H=>{this._connection.addTrack(H,I)})}).then(()=>{if(this._late_sdp)return;const I={originator:"remote",type:"offer",sdp:n.body};z.debug('emit "sdp"'),this.emit("sdp",I);const H=new RTCSessionDescription({type:"offer",sdp:I.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(H)).catch($=>{throw n.reply(488),this._failed("system",null,L.causes.WEBRTC_ERROR),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',$),this.emit("peerconnection:setremotedescriptionfailed",$),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(n),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",h).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(I=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,a),n.reply(200,null,a,I,()=>{this._status=te.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,I),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,L.causes.CONNECTION_ERROR)})}).catch(I=>{this._status!==te.STATUS_TERMINATED&&z.warn(I)})}terminate(t={}){z.debug("terminate()");const n=t.cause||L.causes.BYE,a=xe.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,d=t.reason_phrase;if(this._status===te.STATUS_TERMINATED)throw new Ns.InvalidStateError(this._status);switch(this._status){case te.STATUS_NULL:case te.STATUS_INVITE_SENT:case te.STATUS_1XX_RECEIVED:if(z.debug("canceling session"),r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);r&&(d=d||L.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${d}"`),this._status===te.STATUS_NULL||this._status===te.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===te.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=te.STATUS_CANCELED,this._failed("local",null,L.causes.CANCELED);break;case te.STATUS_WAITING_FOR_ANSWER:case te.STATUS_ANSWERED:if(z.debug("rejecting session"),r=r||480,r<300||r>=700)throw new TypeError(`Invalid status_code: ${r}`);this._request.reply(r,d,a,o),this._failed("local",null,L.causes.REJECTED);break;case te.STATUS_WAITING_FOR_ACK:case te.STATUS_CONFIRMED:if(z.debug("terminating session"),d=t.reason_phrase||L.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);if(r&&a.push(`Reason: SIP ;cause=${r}; text="${d}"`),this._status===te.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==jt.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:_})=>{_===L.ACK&&(this.sendRequest(L.BYE,{extraHeaders:a,body:o}),h.terminate(),this.closeSession())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===jt.C.STATUS_TERMINATED&&(this.sendRequest(L.BYE,{extraHeaders:a,body:o}),h.terminate(),this.closeSession())}),this._ended("local",null,n),this._dialog=h,this._ua.newDialog(h)}else{const h={janus:"leave"},_=["Content-Type: application/json",this.getPTypeHeader(kt.LEAVE)];this.sendRequest(L.BYE,{extraHeaders:_,body:JSON.stringify(h)}),this.closeSession(),this._ended("local",null,n)}}}configureMedia(t){this.isAudioOn=t.audio,this.isVideoOn=t.video}enableAudio(t){const n={janus:"message",body:{audio:t},handle_id:this.handle_id,session_id:this.session_id},a=["Content-Type: application/json",this.getPTypeHeader(kt.AUDIO_CHANGE)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{o.status_code===200&&(this._ua.emit("changeAudioState",t),this.sendStateMessage({audio:t}))}}})}startAudio(){Xt.toggleAudioMute(this.stream),this._toggleMuteAudio(!1),this.enableAudio(!0),this.isAudioOn=!0}stopAudio(){Xt.toggleAudioMute(this.stream),this._toggleMuteAudio(!0),this.enableAudio(!1),this.isAudioOn=!1}enableVideo(t){const n={janus:"message",body:{video:t},handle_id:this.handle_id,session_id:this.session_id},a=["Content-Type: application/json",this.getPTypeHeader(kt.VIDEO_CHANGE)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{o.status_code===200&&(this._ua.emit("changeVideoState",t),this.sendStateMessage({video:t}))}}})}startVideo(){Xt.toggleVideoMute(this.stream),this._toggleMuteVideo(!1),this.enableVideo(!0),this.isVideoOn=!0}stopVideo(){Xt.toggleVideoMute(this.stream),this._toggleMuteVideo(!0),this.enableVideo(!1),this.isVideoOn=!1}sendStateMessage(t){const n={janus:"message",body:{request:"state",data:t},handle_id:this.handle_id,session_id:this.session_id},a=["Content-Type: application/json",this.getPTypeHeader(kt.STATE)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n)})}sendInfo(t,n,a={}){if(z.debug("sendInfo()"),this._status!==te.STATUS_CONFIRMED&&this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_1XX_RECEIVED)throw new Ns.InvalidStateError(this._status);new nu(this).send(t,n,a)}mute(t={audio:!0,video:!1}){z.debug("mute()");let n=!1,a=!1;this._audioMuted===!1&&t.audio&&(n=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&t.video&&(a=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(n===!0||a===!0)&&this._onmute({audio:n,video:a})}unmute(t={audio:!0,video:!0}){z.debug("unmute()");let n=!1,a=!1;this._audioMuted===!0&&t.audio&&(n=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&t.video&&(a=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(n===!0||a===!0)&&this._onunmute({audio:n,video:a})}hold(t={},n){if(z.debug("hold()"),this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:L.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}unhold(t={},n){if(z.debug("unhold()"),this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:L.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}renegotiate(t={},n){z.debug("renegotiate()");const a=t.rtcOfferConstraints||null;if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const o={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:L.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}),!0}refer(t,n){z.debug("refer()");const a=t;if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${a}`);const o=new _g(this);o.sendRefer(t,n);const s=o.id;return this._referSubscribers[s]=o,o.on("requestFailed",()=>{delete this._referSubscribers[s]}),o.on("accepted",()=>{delete this._referSubscribers[s]}),o.on("failed",()=>{delete this._referSubscribers[s]}),o}sendRequest(t,n){return z.debug("sendRequest()"),this._dialog.sendRequest(t,n)}receiveNotify(t){z.debug("receiveRequest()")}receiveRequest(t){if(z.debug("receiveRequest()"),t.method===L.CANCEL)(this._status===te.STATUS_WAITING_FOR_ANSWER||this._status===te.STATUS_ANSWERED)&&(this._status=te.STATUS_CANCELED,this._request.reply(487),this._failed("remote",t,L.causes.CANCELED));else switch(t.method){case L.ACK:if(this._status!==te.STATUS_WAITING_FOR_ACK)return;if(this._status=te.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!t.body){this.terminate({cause:L.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:t.body};z.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>{this._is_confirmed||this._confirmed("remote",t)}).catch(o=>{this.terminate({cause:L.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})}else this._is_confirmed||this._confirmed("remote",t);break;case L.BYE:this._status===te.STATUS_CONFIRMED||this._status===te.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,L.causes.BYE)):this._status===te.STATUS_INVITE_RECEIVED||this._status===te.STATUS_WAITING_FOR_ANSWER?(t.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",t,L.causes.BYE)):t.reply(403,"Wrong Status");break;case L.INVITE:this._status===te.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case L.INFO:if(this._status===te.STATUS_1XX_RECEIVED||this._status===te.STATUS_WAITING_FOR_ANSWER||this._status===te.STATUS_ANSWERED||this._status===te.STATUS_WAITING_FOR_ACK||this._status===te.STATUS_CONFIRMED){const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;n&&n.match(/^application\/dtmf-relay/i)?new ng(this).init_incoming(t):n!==void 0?new nu(this).init_incoming(t):t.reply(415)}else t.reply(403,"Wrong Status");break;case L.UPDATE:this._status===te.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case L.REFER:this._status===te.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case L.NOTIFY:this._status===te.STATUS_CONFIRMED?this._receiveNotify(t):t.reply(403,"Wrong Status");break;default:t.reply(501)}}onTransportError(){z.warn("onTransportError()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.CONNECTION_ERROR,cause:L.causes.CONNECTION_ERROR})}onRequestTimeout(){z.warn("onRequestTimeout()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:L.causes.REQUEST_TIMEOUT,cause:L.causes.REQUEST_TIMEOUT})}onDialogError(){z.warn("onDialogError()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.DIALOG_ERROR,cause:L.causes.DIALOG_ERROR})}newDTMF(t){z.debug("newDTMF()"),this.emit("newDTMF",t)}newInfo(t){z.debug("newInfo()"),this.emit("newInfo",t)}_isReadyToReOffer(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(z.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(z.debug("_isReadyToReOffer() | session not established yet"),!1):(z.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}_close(){if(z.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(z.debug("close() | closing local MediaStream"),xe.closeMediaStream(this._localMediaStream)),this._status!==te.STATUS_TERMINATED){if(this._status=te.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(t){z.warn("close() | error closing the RTCPeerConnection: %o",t)}for(const t in this._timers)Object.prototype.hasOwnProperty.call(this._timers,t)&&clearTimeout(this._timers[t]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const t in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(const t in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,t)&&delete this._referSubscribers[t];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(t,n){let a=Vr.T1;function o(){this._status===te.STATUS_WAITING_FOR_ACK&&(t.reply(200,null,[`Contact: ${this._contact}`],n),a<Vr.T2&&(a=a*2,a>Vr.T2&&(a=Vr.T2)),this._timers.invite2xxTimer=setTimeout(o.bind(this),a))}this._timers.invite2xxTimer=setTimeout(o.bind(this),a)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===te.STATUS_WAITING_FOR_ACK&&(z.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(L.BYE),this._ended("remote",null,L.causes.NO_ACK))},Vr.TIMER_H)}_createRTCConnection(t,n){this.stunServers,this._connection=new RTCPeerConnection(t,n),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:L.causes.RTP_TIMEOUT,status_code:408,reason_phrase:L.causes.RTP_TIMEOUT})});let a;const o=s=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||s.candidate&&(this._candidates.push(s.candidate),clearTimeout(a),a=setTimeout(()=>{this.lastTrickleReceived=!0,this.subscribeSent&&!this.isConfigureSent&&(this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream}),this._sendConfigureMessage({audio:!0,video:!0}).then(()=>{}))},500))};this._connection.onicecandidate=o,z.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(t,n){if(z.debug("createLocalDescription()"),t!=="offer"&&t!=="answer")throw new Error(`createLocalDescription() | invalid type "${t}"`);const a=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>t==="offer"?a.createOffer(n).catch(o=>(z.warn('emit "peerconnection:createofferfailed" [error:%o]',o),this.emit("peerconnection:createofferfailed",o),Promise.reject(o))):a.createAnswer(n).catch(o=>(z.warn('emit "peerconnection:createanswerfailed" [error:%o]',o),this.emit("peerconnection:createanswerfailed",o),Promise.reject(o)))).then(o=>(this.jsepOffer=o,a.setLocalDescription(o).catch(s=>(this._rtcReady=!0,z.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',s),this.emit("peerconnection:setlocaldescriptionfailed",s),Promise.reject(s))))).then(()=>{const o=n&&n.iceRestart;if(a.iceGatheringState==="complete"&&!o||a.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const s={originator:"local",type:t,sdp:a.localDescription.sdp};return z.debug('emit "sdp"'),this.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(s=>{let r=!1,d,h;this._iceReady=!1;const _=()=>{a.removeEventListener("icecandidate",d),a.removeEventListener("icegatheringstatechange",h),r=!0,this._rtcReady=!0,this._iceReady=!0;const g={originator:"local",type:t,sdp:a.localDescription.sdp};z.debug('emit "sdp"'),this.emit("sdp",g),s(g.sdp)};a.addEventListener("icecandidate",d=g=>{const T=g.candidate;T?this.emit("icecandidate",{candidate:T,ready:_}):r||_()}),a.addEventListener("icegatheringstatechange",h=()=>{a.iceGatheringState==="complete"&&!r&&_()})})})}_createDialog(t,n,a){const o=n==="UAS"?t.to_tag:t.from_tag,s=n==="UAS"?t.from_tag:t.to_tag,r=t.call_id+o+s;let d=this._earlyDialogs[r];if(a)return d?!0:(d=new va(this,t,n,va.C.STATUS_EARLY),d.error?(z.debug(d.error),this._failed("remote",t,L.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=d,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,d)return d.update(t,n),this._dialog=d,delete this._earlyDialogs[r],!0;const h=new va(this,t,n);return h.error?(z.debug(h.error),this._failed("remote",t,L.causes.INTERNAL_ERROR),!1):(this._dialog=h,!0)}}_receiveReinvite(t){z.debug("receiveReinvite()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=xe.cloneArray(d.extraHeaders);if(this._status!==te.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("reinvite",a),o)return;if(this._late_sdp=!1,!t.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(d=>{r.call(this,d)}).catch(()=>{t.reply(500)});return}if(n!=="application/sdp"){z.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==te.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{z.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),this._late_sdp&&(d=this._mangleOffer(d)),t.reply(200,null,h,d,()=>{this._status=te.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(t,d),this._setACKTimer()}),typeof a.callback=="function"&&a.callback()}}_receiveUpdate(t){z.debug("receiveUpdate()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=xe.cloneArray(d.extraHeaders);if(this._status!==te.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("update",a),o)return;if(!t.body){r.call(this,null);return}if(n!=="application/sdp"){z.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==te.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{z.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),t.reply(200,null,h,d),typeof a.callback=="function"&&a.callback()}}_processInDialogSdpOffer(t){z.debug("_processInDialogSdpOffer()");const n=t.parseSDP();let a=!1;for(const r of n.media){if(Ea.indexOf(r.type)===-1)continue;const d=r.direction||n.direction||"sendrecv";if(d==="sendonly"||d==="inactive")a=!0;else{a=!1;break}}const o={originator:"remote",type:"offer",sdp:t.body};z.debug('emit "sdp"'),this.emit("sdp",o);const s=new RTCSessionDescription({type:"offer",sdp:o.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(s).catch(r=>{throw t.reply(488),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',r),this.emit("peerconnection:setremotedescriptionfailed",r),r})}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&a===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&a===!0&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(r=>{throw t.reply(500),z.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',r),r})}).catch(r=>{z.warn("_processInDialogSdpOffer() failed [error: %o]",r)}),this._connectionPromiseQueue}_receiveRefer(t){if(z.debug("receiveRefer()"),!t.refer_to){z.debug("no Refer-To header field present in REFER"),t.reply(400);return}if(t.refer_to.uri.scheme!==L.SIP){z.debug("Refer-To header field points to a non-SIP URI scheme"),t.reply(416);return}t.reply(202);const n=new cg(this,t.cseq);z.debug('emit "refer"'),this.emit("refer",{request:t,accept:(s,r)=>{a.call(this,s,r)},reject:()=>{o.call(this)}});function a(s,r={}){if(s=typeof s=="function"?s:null,this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;const d=new Sa(this._ua);if(d.on("progress",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("accepted",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("_failed",({message:h,cause:_})=>{h?n.notify(h.status_code,h.reason_phrase):n.notify(487,_)}),t.refer_to.uri.hasHeader("replaces")){const h=decodeURIComponent(t.refer_to.uri.getHeader("replaces"));r.extraHeaders=xe.cloneArray(r.extraHeaders),r.extraHeaders.push(`Replaces: ${h}`)}d.connect(t.refer_to.uri.toAor(),r,s)}function o(){n.notify(603)}}_receiveNotify(t){switch(z.debug("receiveNotify()"),t.event||t.reply(400),t.event.event){case"refer":{let n,a;if(t.event.params&&t.event.params.id)n=t.event.params.id,a=this._referSubscribers[n];else if(Object.keys(this._referSubscribers).length===1)a=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{t.reply(400,"Missing event id parameter");return}if(!a){t.reply(481,"Subscription does not exist");return}a.receiveNotify(t),t.reply(200);break}default:t.reply(489)}}_receiveReplaces(t){z.debug("receiveReplaces()");function n(o){if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;const s=new Sa(this._ua);s.on("confirmed",()=>{this.terminate()}),s.init_incoming(t,o)}function a(){z.debug("Replaced INVITE rejected by the user"),t.reply(486)}this.emit("replaces",{request:t,accept:o=>{n.call(this,o)},reject:()=>{a.call(this)}})}_getNextTransactionId(){return(this.lastTransaction+1).toString()}_sendInitialRequest(t,n,a){this.ackSent=!1,this.publisherSubscribeSent=!1;const o=new Kr(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});Promise.resolve().then(()=>{if(a)return a;if(t.audio||t.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(s=>{throw this._status===te.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,L.causes.USER_DENIED_MEDIA_ACCESS),z.warn('emit "getusermediafailed" [error:%o]',s),this.emit("getusermediafailed",s),s)})}).then(s=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=s,s&&s.getTracks().forEach(r=>{this._connection.addTrack(r,s)}),this._connecting(this._request),this._createLocalDescription("offer",n).catch(r=>{throw this._failed("local",null,L.causes.WEBRTC_ERROR),r})}).then(s=>{if(this._is_canceled||this._status===te.STATUS_TERMINATED)throw new Error("terminated");const r={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaque_id},d=JSON.stringify(r);this._request.body=d,this._status=te.STATUS_INVITE_SENT,z.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),o.send()}).catch(s=>{this._status!==te.STATUS_TERMINATED&&z.warn(s)})}async requestAudioAndVideoPermissions(){this.stream=await this.loadStream()}async setupMediaStream(){await this.requestAudioAndVideoPermissions(),await this.processPlugins()}async changeMediaConstraints(t){this.mediaConstraints={...t},await this.processPlugins(),this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream})}async loadStream(){const t={};this.isAudioOn?this.mediaConstraints.audio?t.audio=this.mediaConstraints.audio:t.audio=!0:t.audio=!1,this.isVideoOn?this.mediaConstraints.video?t.video=this.mediaConstraints.video:t.video=!0:t.video=!1;let n=null;try{n=await navigator.mediaDevices.getUserMedia(t)}catch{try{t.video=!1,n=await navigator.mediaDevices.getUserMedia(t)}catch{t.audio=!1,t.video=!1,n=await navigator.mediaDevices.getUserMedia(t)}}return n}addTracks(t){this._connection.getSenders().forEach(n=>{this._connection.removeTrack(n)}),t.forEach(n=>{this._connection.addTrack(n)})}getRecordFileName(){return TT+this.room_id+btoa(unescape(encodeURIComponent(this.displayName)))+Date.now()}async processIceCandidates(){for(let t=0;t<this.iceCandidates.length;t++)await this._connection.addIceCandidate(this.iceCandidates[t]);this.iceCandidates=[]}async _sendConfigureMessage(t){const n=this._candidates.map(r=>({janus:"trickle",candidate:r,handle_id:this.handle_id,session_id:this.session_id})),o={configure:{janus:"message",body:{request:"configure",record:!0,filename:this.getRecordFileName(),...t},jsep:this.jsepOffer,handle_id:this.handle_id,session_id:this.session_id},trickles:[...n]},s=["Content-Type: application/json",this.getPTypeHeader(kt.ICE)];this.sendRequest(L.INFO,{extraHeaders:s,body:JSON.stringify(o),eventHandlers:{onSuccessResponse:async r=>{this.isConfigureSent=!0;const h=r.data.split(`\r
|
135
|
-
`),_=h[h.length-1],g=JSON.parse(_);await this._connection.setRemoteDescription(g.jsep),this._candidates=[]}}})}_sendMemberStartMessage(t,n){const a={janus:"message",body:{request:"start",room:this.room_id},handle_id:t.handleId,session_id:this.session_id,jsep:n},o=["Content-Type: application/json",this.getPTypeHeader(kt.CONFIGURE)];this.sendRequest(L.INFO,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{s.status_code===200&&await t.rtcpPeer.setLocalDescription(n)}}})}_sendTrickleMessage(t){const a={trickles:[...t.map(s=>({janus:"trickle",candidate:s,handle_id:this.handle_id,session_id:this.session_id}))]},o=[this.getPTypeHeader(kt.TRICKLE)];this.sendRequest(L.INFO,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{}}})}async _answerAttachedStream(t,n){let a=null;const o=async h=>{if(!t.rtcpPeer||t.loaded)return;{t.loaded=!0;const y={audio:!0,video:!0};await new Promise(A=>{setTimeout(A,100)}),a=await t.rtcpPeer.createAnswer(y),this._sendMemberStartMessage(t,a)}const _=h.streams[0].getAudioTracks(),g=h.streams[0].getVideoTracks(),T=[];_[0]&&T.push(_[0]),g[0]&&T.push(g[0]);const E=new MediaStream(T);t.stream=E,this._ua.emit("memberJoin",t.memberInfo)};let s,r=[];const d=h=>{t.rtcpPeer.signalingState!=="stable"&&t.rtcpPeer.signalingState!=="have-local-offer"||(r.push(h.candidate||null),clearTimeout(s),s=setTimeout(()=>{this._sendTrickleMessage(r)},500))};t.rtcpPeer=new RTCPeerConnection,t.rtcpPeer.ontrack=o,t.rtcpPeer.onicecandidate=d,t.rtcpPeer.sender=n.sender,await t.rtcpPeer.setRemoteDescription(n.jsep)}_sendJoinMemberRequest(t){const n={janus:"message",body:{request:"join",room:this.room_id,feed:t.info.id,ptype:"subscriber"},handle_id:t.handleId,session_id:this.session_id},a=[this.getPTypeHeader(kt.SUBSCRIBER)];this.sendRequest(L.SUBSCRIBE,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{var s,r;if(o.status_code===200){const d=JSON.parse(o.body);(r=(s=d==null?void 0:d.plugindata)==null?void 0:s.data)!=null&&r.id&&await this._answerAttachedStream(t,d)}}}})}_attachMember(t){const n={janus:"attach",opaque_id:this.opaque_id,plugin:"janus.plugin.videoroom",session_id:this.session_id},a=[this.getPTypeHeader(kt.SUBSCRIBER)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{if(o.status_code===200){const r=JSON.parse(o.body).data.id;t.handleId=r,this._sendJoinMemberRequest(t)}}}})}_detachMember(t){const n={janus:"detach",handle_id:t.handleId,session_id:this.session_id},a=[this.getPTypeHeader(kt.SUBSCRIBER)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n)}),Xt.stopStreamTracks(t.memberInfo.stream),this._ua.emit("memberHangup",t.memberInfo)}receivePublishers(t){var a,o,s,r,d,h,_,g;const n={...this.memberList};(o=(a=t==null?void 0:t.plugindata)==null?void 0:a.data)==null||o.publishers.forEach(T=>{delete n[T.id],!this.memberList[T.id]&&!this.myFeedList.includes(T.id)&&T.clientID!==this.client_id&&(this.memberList[T.id]=new mT(T,this),this._attachMember(this.memberList[T.id]))}),((r=(s=t==null?void 0:t.plugindata)==null?void 0:s.data)==null?void 0:r.videoroom)==="synced"&&Object.keys(n).forEach(T=>{n[T].hangup(),delete this.memberList[T]}),this.publishers=(h=(d=t==null?void 0:t.plugindata)==null?void 0:d.data)==null?void 0:h.publishers,this.private_id=(g=(_=t==null?void 0:t.plugindata)==null?void 0:_.data)==null?void 0:g.private_id}receiveUnpublished(t){const n=this.memberList[t];n&&(n.hangup(),this._detachMember(n),delete this.memberList[t])}closeSession(){this.stream&&this.stream.getTracks().forEach(n=>{n.stop()}),Object.values(this.memberList).forEach(n=>{n.hangup(),this._detachMember(n)}),this._ua.emit("conferenceEnd",this.id)}async processPlugins(){const t=this._ua.processStreamPlugins;let n=await this.loadStream();for(const a of t)n=await a.process(n);this.stream.getTracks().forEach(a=>{this.stream.removeTrack(a),a.stop()}),n.getTracks().forEach(a=>{this.stream.addTrack(a)})}async resyncPlugins(t){const n=this._ua.processStreamPlugins.filter(a=>a.type===t);for(const a of n)a.running&&a.terminate();if(t==="video"){let a=await this.loadStream();for(const o of n)o.running&&(a=await o.start(a));this.stream.getTracks().forEach(o=>{this.stream.removeTrack(o),o.stop()}),a.getTracks().forEach(o=>{this.stream.addTrack(o)}),this._overrideSenderTracks(this.stream,this._connection),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream})}else{const a=this._ua.newStreamPlugins.find(d=>d.type===t);let s=a.getStream().clone();for(const d of n)d.running&&(s=await d.start(s));const r=a.getConnection();this._overrideSenderTracks(s,r),this._ua.emit("changePluginStream",{type:t,stream:s})}}stopProcessPlugins(t){const n=this._ua.processStreamPlugins.filter(a=>a.type===t);for(const a of n)a.running&&a.kill()}_receiveInviteResponse(t){if(z.debug("receiveInviteResponse()"),this._dialog&&t.status_code>=200&&t.status_code<=299&&!this.ackSent)if(this._dialog.id.call_id===t.call_id&&this._dialog.id.local_tag===t.from_tag&&this._dialog.id.remote_tag===t.to_tag){this.ackSent=!0,this.sendRequest(L.ACK);return}else{const n=new va(this,t,"UAC");if(n.error!==void 0){z.debug(n.error);return}this.sendRequest(L.ACK),this.sendRequest(L.BYE);return}if(this.ackSent&&!this.publisherSubscribeSent){const n=JSON.parse(t.body);this.setupMediaStream().then(()=>{this.session_id=n.session_id,this.handle_id=n.data.id,this.client_id=mh();const a={janus:"message",body:{request:"join",room:this.room_id,ptype:"publisher",display:this.display_name,clientID:this.client_id,opaque_id:this.opaque_id},handle_id:this.handle_id},o=[this.getPTypeHeader(kt.PUBLISHER)];this.sendRequest(L.SUBSCRIBE,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{var r,d,h,_;if(s.status_code===200){if(this.subscribeSent=!0,s.body)try{const g=JSON.parse(s.body)||{};((d=(r=g.plugindata)==null?void 0:r.data)==null?void 0:d.videoroom)==="joined"&&this.myFeedList.push(g.plugindata.data.id),(_=(h=g.plugindata)==null?void 0:h.data)!=null&&_.publishers&&this.receivePublishers(g)}catch(g){console.error(g)}this.lastTrickleReceived&&!this.isConfigureSent&&(this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream}),this._sendConfigureMessage({audio:!0,video:!0}).then(()=>{})),this._ua.emit("conferenceStart")}}}}),this.publisherSubscribeSent=!0})}if(this._is_canceled){t.status_code>=100&&t.status_code<200?this._request.cancel(this._cancel_reason):t.status_code>=200&&t.status_code<299&&this._acceptAndTerminate(t);return}if(!(this._status!==te.STATUS_INVITE_SENT&&this._status!==te.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(t.status_code):this._status=te.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(t.status_code):{if(!t.to_tag){z.debug("1xx response received without to tag");break}if(t.hasHeader("contact")&&!this._createDialog(t,"UAC",!0))break;if(this._status=te.STATUS_1XX_RECEIVED,!t.body){this._progress("remote",t);break}const n={originator:"remote",type:"answer",sdp:t.body};z.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>this._progress("remote",t)).catch(o=>{z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)});break}case/^2[0-9]{2}$/.test(t.status_code):{if(this._status=te.STATUS_CONFIRMED,!t.body){this._acceptAndTerminate(t,400,L.causes.MISSING_SDP),this._failed("remote",t,L.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(t,"UAC"))break;break}default:{const n=xe.sipErrorCause(t.status_code);this._failed("remote",t,n)}}}_sendReinvite(t={}){z.debug("sendReinvite()");const n=xe.cloneArray(t.extraHeaders),a=xe.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null;let s=!1;n.push(`Contact: ${this._contact}`),n.push("Content-Type: application/sdp"),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(h=>{h=this._mangleOffer(h);const _={originator:"local",type:"offer",sdp:h};z.debug('emit "sdp"'),this.emit("sdp",_),this.sendRequest(L.INVITE,{extraHeaders:n,body:h,eventHandlers:{onSuccessResponse:g=>{r.call(this,g),s=!0},onErrorResponse:g=>{d.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{d()});function r(h){if(this._status===te.STATUS_TERMINATED||(this.sendRequest(L.ACK),s))return;if(this._handleSessionTimersInIncomingResponse(h),h.body){if(!h.hasHeader("Content-Type")||h.getHeader("Content-Type").toLowerCase()!=="application/sdp"){d.call(this);return}}else{d.call(this);return}const _={originator:"remote",type:"answer",sdp:h.body};z.debug('emit "sdp"'),this.emit("sdp",_);const g=new RTCSessionDescription({type:"answer",sdp:_.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(g)).then(()=>{a.succeeded&&a.succeeded(h)}).catch(T=>{d.call(this),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function d(h){a.failed&&a.failed(h)}}_sendUpdate(t={}){z.debug("sendUpdate()");const n=xe.cloneArray(t.extraHeaders),a=xe.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null,s=t.sdpOffer||!1;let r=!1;n.push(`Contact: ${this._contact}`),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),s?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(_=>{_=this._mangleOffer(_);const g={originator:"local",type:"offer",sdp:_};z.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(L.UPDATE,{extraHeaders:n,body:_,eventHandlers:{onSuccessResponse:T=>{d.call(this,T),r=!0},onErrorResponse:T=>{h.call(this,T)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{h.call(this)})):this.sendRequest(L.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:_=>{d.call(this,_)},onErrorResponse:_=>{h.call(this,_)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function d(_){if(this._status!==te.STATUS_TERMINATED&&!r)if(this._handleSessionTimersInIncomingResponse(_),s){if(_.body){if(!_.hasHeader("Content-Type")||_.getHeader("Content-Type").toLowerCase()!=="application/sdp"){h.call(this);return}}else{h.call(this);return}const g={originator:"remote",type:"answer",sdp:_.body};z.debug('emit "sdp"'),this.emit("sdp",g);const T=new RTCSessionDescription({type:"answer",sdp:g.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(T)).then(()=>{a.succeeded&&a.succeeded(_)}).catch(E=>{h.call(this),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),this.emit("peerconnection:setremotedescriptionfailed",E)})}else a.succeeded&&a.succeeded(_)}function h(_){a.failed&&a.failed(_)}}_acceptAndTerminate(t,n,a){z.debug("acceptAndTerminate()");const o=[];n&&(a=a||L.REASON_PHRASE[n]||"",o.push(`Reason: SIP ;cause=${n}; text="${a}"`)),(this._dialog||this._createDialog(t,"UAC"))&&(this.sendRequest(L.ACK),this.sendRequest(L.BYE,{extraHeaders:o})),this._status=te.STATUS_TERMINATED}_mangleOffer(t){if(!this._localHold&&!this._remoteHold)return t;if(t=Ut.parse(t),this._localHold&&!this._remoteHold){z.debug("mangleOffer() | me on hold, mangling offer");for(const n of t.media)Ea.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="sendonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="sendonly")}else if(this._localHold&&this._remoteHold){z.debug("mangleOffer() | both on hold, mangling offer");for(const n of t.media)Ea.indexOf(n.type)!==-1&&(n.direction="inactive")}else if(this._remoteHold){z.debug("mangleOffer() | remote on hold, mangling offer");for(const n of t.media)Ea.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="recvonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="recvonly")}return Ut.write(t)}_setLocalMediaStatus(){let t=!0,n=!0;(this._localHold||this._remoteHold)&&(t=!1,n=!1),this._audioMuted&&(t=!1),this._videoMuted&&(n=!1),this._toggleMuteAudio(!t),this._toggleMuteVideo(!n)}_handleSessionTimersInIncomingRequest(t,n){if(!this._sessionTimers.enabled)return;let a;t.session_expires&&t.session_expires>=L.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,a=t.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,a="uas"),n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${a}`),this._sessionTimers.refresher=a==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(t){if(!this._sessionTimers.enabled)return;let n;t.session_expires&&t.session_expires>=L.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,n=t.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uac"),this._sessionTimers.refresher=n==="uac",this._runSessionTimer()}_runSessionTimer(){const t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(()=>{this._status!==te.STATUS_TERMINATED&&this._isReadyToReOffer()&&(z.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===L.UPDATE?this._sendUpdate():this._sendReinvite())},t*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==te.STATUS_TERMINATED&&(z.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:L.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},t*1100)}_toggleMuteAudio(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="audio");for(const a of n)a.track.enabled=!t}_toggleMuteVideo(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="video");for(const a of n)a.track.enabled=!t}_newJanusSession(t,n){z.debug("newRTCSession()"),this._ua.newJanusSession(this,{originator:t,session:this,request:n})}_connecting(t){z.debug("session connecting"),z.debug('emit "connecting"'),this.emit("connecting",{request:t})}_progress(t,n){z.debug("session progress"),z.debug('emit "progress"'),this.emit("progress",{originator:t,response:n||null})}_accepted(t,n){z.debug("session accepted"),this._start_time=new Date,z.debug('emit "accepted"'),this.emit("accepted",{originator:t,response:n||null})}_confirmed(t,n){z.debug("session confirmed"),this._is_confirmed=!0,z.debug('emit "confirmed"'),this.emit("confirmed",{originator:t,ack:n||null})}_ended(t,n,a){z.debug("session ended"),this._end_time=new Date,this._close(),z.debug('emit "ended"'),this.emit("ended",{originator:t,message:n||null,cause:a})}_failed(t,n,a){z.debug("session failed"),z.debug('emit "_failed"'),this.emit("_failed",{originator:t,message:n||null,cause:a}),this._close(),z.debug('emit "failed"'),this.emit("failed",{originator:t,message:n||null,cause:a})}_onhold(t){z.debug("session onhold"),this._setLocalMediaStatus(),z.debug('emit "hold"'),this.emit("hold",{originator:t})}_onunhold(t){z.debug("session onunhold"),this._setLocalMediaStatus(),z.debug('emit "unhold"'),this.emit("unhold",{originator:t})}_onmute({audio:t,video:n}){z.debug("session onmute"),this._setLocalMediaStatus(),z.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}_onunmute({audio:t,video:n}){z.debug("session onunmute"),this._setLocalMediaStatus(),z.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}class qn{constructor(t){if(this.headers={},t.length>0){let n=!1;const a=t.split(`\r
|
134
|
+
`,oh.send(a)}const Qg=Me(uh);var si={};const jn=mt(),rn=De,du=Jt(),ch=ps(),_u=au,pu=Ts;si.settings={authorization_user:null,password:null,realm:null,ha1:null,authorization_jwt:null,display_name:null,uri:null,contact_uri:null,instance_id:null,use_preloaded_route:!1,session_timers:!0,session_timers_refresh_method:rn.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:rn.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:rn.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:`${jn.createRandomToken(12)}.invalid`};const ma={mandatory:{sockets(c){const t=[];if(_u.isSocket(c))t.push({socket:c});else if(Array.isArray(c)&&c.length)for(const n of c)Object.prototype.hasOwnProperty.call(n,"socket")&&_u.isSocket(n.socket)?t.push(n):_u.isSocket(n)&&t.push({socket:n});else return;return t},uri(c){/^sip:/i.test(c)||(c=`${rn.SIP}:${c}`);const t=ch.parse(c);if(t)return t.user?t:void 0}},optional:{authorization_user(c){if(du.parse(`"${c}"`,"quoted_string")!==-1)return c},authorization_jwt(c){if(typeof c=="string")return c},user_agent(c){if(typeof c=="string")return c},connection_recovery_max_interval(c){if(jn.isDecimal(c)){const t=Number(c);if(t>0)return t}},connection_recovery_min_interval(c){if(jn.isDecimal(c)){const t=Number(c);if(t>0)return t}},contact_uri(c){if(typeof c=="string"){const t=du.parse(c,"SIP_URI");if(t!==-1)return t}},display_name(c){return c},instance_id(c){if(/^uuid:/i.test(c)&&(c=c.substr(5)),du.parse(c,"uuid")!==-1)return c},no_answer_timeout(c){if(jn.isDecimal(c)){const t=Number(c);if(t>0)return t}},session_timers(c){if(typeof c=="boolean")return c},session_timers_refresh_method(c){if(typeof c=="string"&&(c=c.toUpperCase(),c===rn.INVITE||c===rn.UPDATE))return c},session_timers_force_refresher(c){if(typeof c=="boolean")return c},password(c){return String(c)},realm(c){return String(c)},ha1(c){return String(c)},register(c){if(typeof c=="boolean")return c},register_expires(c){if(jn.isDecimal(c)){const t=Number(c);if(t>0)return t}},registrar_server(c){/^sip:/i.test(c)||(c=`${rn.SIP}:${c}`);const t=ch.parse(c);if(t)return t.user?void 0:t},use_preloaded_route(c){if(typeof c=="boolean")return c},extra_headers(c){const t=[];if(Array.isArray(c)&&c.length)for(const n of c)typeof n=="string"&&t.push(n);else return;return t}}};si.load=(c,t)=>{for(const n in ma.mandatory)if(t.hasOwnProperty(n)){const a=t[n],o=ma.mandatory[n](a);if(o!==void 0)c[n]=o;else throw new pu.ConfigurationError(n,a)}else throw new pu.ConfigurationError(n);for(const n in ma.optional)if(t.hasOwnProperty(n)){const a=t[n];if(jn.isEmpty(a))continue;const o=ma.optional[n](a);if(o!==void 0)c[n]=o;else throw new pu.ConfigurationError(n,a)}};const Zg=ct.EventEmitter,eT=at,vt=De,tT=Vm,fh=eh,hh=bg,dh=Ug,mu=Hn,sT=rh,ga=mt(),nT=Ts,rT=ps(),iT=ih,gu=Tt,lT=uh,Tu=si,qe=new eT("UA"),Et={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};var _h=class extends Zg{static get C(){return Et}constructor(t){if(qe.debug("new() [configuration:%o]",t),super(),this._cache={credentials:{}},this._configuration=Object.assign({},Tu.settings),this._dynConfiguration={},this._dialogs={},this._applicants={},this._sessions={},this._transport=null,this._contact=null,this._status=Et.STATUS_INIT,this._error=null,this._transactions={nist:{},nict:{},ist:{},ict:{}},this._data={},this._closeTimer=null,t===void 0)throw new TypeError("Not enough arguments");try{this._loadConfig(t)}catch(n){throw this._status=Et.STATUS_NOT_READY,this._error=Et.CONFIGURATION_ERROR,n}this._registrator=new tT(this)}get C(){return Et}get status(){return this._status}get contact(){return this._contact}get configuration(){return this._configuration}get transport(){return this._transport}start(){qe.debug("start()"),this._status===Et.STATUS_INIT?this._transport.connect():this._status===Et.STATUS_USER_CLOSED?(qe.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=Et.STATUS_INIT,this._transport.connect()):this._status===Et.STATUS_READY?qe.debug("UA is in READY status, not restarted"):qe.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}register(){qe.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}unregister(t){qe.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(t)}registrator(){return this._registrator}isRegistered(){return this._registrator.registered}isConnected(){return this._transport.isConnected()}call(t,n){qe.debug("call()");const a=new fh(this);return a.connect(t,n),a}sendMessage(t,n,a){qe.debug("sendMessage()");const o=new hh(this);return o.send(t,n,a),o}sendOptions(t,n,a){qe.debug("sendOptions()");const o=new dh(this);return o.send(t,n,a),o}terminateSessions(t){qe.debug("terminateSessions()");for(const n in this._sessions)this._sessions[n].isEnded()||this._sessions[n].terminate(t)}stop(){if(qe.debug("stop()"),this._dynConfiguration={},this._status===Et.STATUS_USER_CLOSED){qe.debug("UA already closed");return}this._registrator.close();const t=Object.keys(this._sessions).length;for(const a in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,a)){qe.debug(`closing session ${a}`);try{this._sessions[a].terminate()}catch{}}for(const a in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,a))try{this._applicants[a].close()}catch{}this._status=Et.STATUS_USER_CLOSED,Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length===0&&t===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}normalizeTarget(t){return ga.normalizeTarget(t,this._configuration.hostport_params)}get(t){switch(t){case"authorization_user":return this._configuration.authorization_user;case"realm":return this._configuration.realm;case"ha1":return this._configuration.ha1;case"authorization_jwt":return this._configuration.authorization_jwt;default:qe.warn('get() | cannot get "%s" parameter in runtime',t);return}}set(t,n){switch(t){case"authorization_user":{this._configuration.authorization_user=String(n);break}case"password":{this._configuration.password=String(n);break}case"realm":{this._configuration.realm=String(n);break}case"ha1":{this._configuration.ha1=String(n),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(n);break}case"display_name":{this._configuration.display_name=n;break}default:return qe.warn('set() | cannot set "%s" parameter in runtime',t),!1}return!0}newTransaction(t){this._transactions[t.type][t.id]=t,this.emit("newTransaction",{transaction:t})}destroyTransaction(t){delete this._transactions[t.type][t.id],this.emit("transactionDestroyed",{transaction:t})}newDialog(t){this._dialogs[t.id]=t}destroyDialog(t){delete this._dialogs[t.id]}newMessage(t,n){this._applicants[t]=t,this.emit("newMessage",n)}newOptions(t,n){this._applicants[t]=t,this.emit("newOptions",n)}destroyMessage(t){delete this._applicants[t]}newRTCSession(t,n){this._sessions[t.id]=t,this.emit("newRTCSession",n)}destroyRTCSession(t){delete this._sessions[t.id]}registered(t){this.emit("registered",t)}unregistered(t){this.emit("unregistered",t)}registrationFailed(t){this.emit("registrationFailed",t)}receiveRequest(t){console.log("receiveRequest");const n=t.method;if(t.ruri.user!==this._configuration.uri.user&&t.ruri.user!==this._contact.uri.user){qe.debug("Request-URI does not point to us"),t.method!==vt.ACK&&t.reply_sl(404);return}if(t.ruri.scheme===vt.SIPS){t.reply_sl(416);return}if(mu.checkTransaction(this,t))return;if(n===vt.INVITE?new mu.InviteServerTransaction(this,this._transport,t):n!==vt.ACK&&n!==vt.CANCEL&&new mu.NonInviteServerTransaction(this,this._transport,t),n===vt.OPTIONS){if(console.log("OPPP in option"),this.listeners("newOptions").length===0){t.reply(200);return}new dh(this).init_incoming(t)}else if(n===vt.MESSAGE){if(this.listeners("newMessage").length===0){t.reply(405);return}new hh(this).init_incoming(t)}else if(n===vt.INVITE&&!t.to_tag&&this.listeners("newRTCSession").length===0){t.reply(405);return}let a,o;if(t.to_tag)a=this._findDialog(t.call_id,t.from_tag,t.to_tag),a?a.receiveRequest(t):n===vt.NOTIFY?(o=this._findSession(t),o?o.receiveRequest(t):(qe.debug("received NOTIFY request for a non existent subscription"),t.reply(481,"Subscription does not exist"))):n!==vt.ACK&&t.reply(481);else switch(n){case vt.INVITE:if(window.RTCPeerConnection)if(t.hasHeader("replaces")){const s=t.replaces;a=this._findDialog(s.call_id,s.from_tag,s.to_tag),a?(o=a.owner,o.isEnded()?t.reply(603):o.receiveRequest(t)):t.reply(481)}else o=new fh(this),o.init_incoming(t);else qe.warn("INVITE received but WebRTC is not supported"),t.reply(488);break;case vt.BYE:t.reply(481);break;case vt.CANCEL:o=this._findSession(t),o?o.receiveRequest(t):qe.debug("received CANCEL request for a non existent session");break;case vt.ACK:break;case vt.NOTIFY:this.emit("sipEvent",{event:t.event,request:t}),t.reply(200);break;default:t.reply(405);break}}_findSession({call_id:t,from_tag:n,to_tag:a}){const o=t+n,s=this._sessions[o],r=t+a,d=this._sessions[r];return s||d||null}_findDialog(t,n,a){let o=t+n+a,s=this._dialogs[o];return s||(o=t+a+n,s=this._dialogs[o],s||null)}_loadConfig(t){console.log("in _loadConfig");try{console.log("config.load"),Tu.load(this._configuration,t)}catch(o){throw console.log("throw in _loadConfig",o),o}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=ga.newUUID()),this._configuration.jssip_id=ga.createRandomToken(5);const n=this._configuration.uri.clone();n.user=null,this._configuration.hostport_params=n.toString().replace(/^sip:/i,"");try{console.log("new transport"),this._transport=new sT(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=aT.bind(this),this._transport.onconnect=oT.bind(this),this._transport.ondisconnect=uT.bind(this),this._transport.ondata=cT.bind(this)}catch(o){throw qe.warn(o),new nT.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){const o=this._configuration.uri.clone();o.user=null,o.clearParams(),o.clearHeaders(),this._configuration.registrar_server=o}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:(console.log("this._configuration.contact_uri 1"),this._configuration.contact_uri=new rT("sip",ga.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),console.log("this._configuration.contact_uri 2",this._configuration.contact_uri)),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(o={}){const s=o.anonymous||null,r=o.outbound||null;let d="<";return s?d+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":d+=this.pub_gruu||this.uri.toString(),r&&(s?!this.temp_gruu:!this.pub_gruu)&&(d+=";ob"),d+=">",console.log("contact",d),d}};const a=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const o in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,o)&&(a.indexOf(o)!==-1?Object.defineProperty(this._configuration,o,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,o,{writable:!1,configurable:!1}));qe.debug("configuration parameters after validation:"),qe.debug("this._contact.toString:",this._contact.toString());for(const o in this._configuration)if(Object.prototype.hasOwnProperty.call(Tu.settings,o))switch(o){case"uri":case"registrar_server":qe.debug(`- ${o}: ${this._configuration[o]}`);break;case"password":case"ha1":case"authorization_jwt":qe.debug(`- ${o}: NOT SHOWN`);break;default:qe.debug(`- ${o}: ${JSON.stringify(this._configuration[o])}`)}console.log("_loadConfig retun")}};function aT(c){this.emit("connecting",c)}function oT(c){this._status!==Et.STATUS_USER_CLOSED&&(this._status=Et.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function uT(c){const t=["nict","ict","nist","ist"];for(const n of t)for(const a in this._transactions[n])Object.prototype.hasOwnProperty.call(this._transactions[n],a)&&this._transactions[n][a].onTransportError();this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==Et.STATUS_USER_CLOSED&&(this._status=Et.STATUS_NOT_READY,this._error=Et.NETWORK_ERROR)}function cT(c){console.log("onTransportData",c);const t=c.transport;let n=c.message;if(n=iT.parseMessage(n,this),!!n&&!(this._status===Et.STATUS_USER_CLOSED&&n instanceof gu.IncomingRequest)&&lT(n,this,t)){if(n instanceof gu.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof gu.IncomingResponse){let a;switch(n.method){case vt.INVITE:a=this._transactions.ict[n.via_branch],a&&a.receiveResponse(n);break;case vt.ACK:break;default:a=this._transactions.nict[n.via_branch],a&&a.receiveResponse(n);break}}}}const fT=Me(_h);for(var St=[],vu=0;vu<256;++vu)St.push((vu+256).toString(16).slice(1));function hT(c,t=0){return(St[c[t+0]]+St[c[t+1]]+St[c[t+2]]+St[c[t+3]]+"-"+St[c[t+4]]+St[c[t+5]]+"-"+St[c[t+6]]+St[c[t+7]]+"-"+St[c[t+8]]+St[c[t+9]]+"-"+St[c[t+10]]+St[c[t+11]]+St[c[t+12]]+St[c[t+13]]+St[c[t+14]]+St[c[t+15]]).toLowerCase()}var Ta,dT=new Uint8Array(16);function _T(){if(!Ta&&(Ta=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Ta))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ta(dT)}var pT=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const ph={randomUUID:pT};function mh(c,t,n){if(ph.randomUUID&&!t&&!c)return ph.randomUUID();c=c||{};var a=c.random||(c.rng||_T)();if(a[6]=a[6]&15|64,a[8]=a[8]&63|128,t){n=n||0;for(var o=0;o<16;++o)t[n+o]=a[o];return t}return hT(a)}var xe=mt();const vs=Me(xe),Eu=new ra("Dialog"),xs={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};class va{static get C(){return xs}constructor(t,n,a,o=xs.STATUS_CONFIRMED){if(this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,n instanceof Tt.IncomingResponse&&(o=n.status_code<200?xs.STATUS_EARLY:xs.STATUS_CONFIRMED),a==="UAS"){this._id={call_id:n.call_id,local_tag:n.to_tag,remote_tag:n.from_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri;let s=n.getHeaders("to")[0].split(";")[0];s=s.match(/<([^>]*)>/)[1],this._remote_target=s,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum}else if(a==="UAC"){this._id={call_id:n.call_id,local_tag:n.from_tag,remote_tag:n.to_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri;let s=n.getHeaders("to")[0].split(";")[0];s=s.match(/<([^>]*)>/)[1],this._remote_target=s,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null}this._ua.newDialog(this),Eu.debug(`new ${a} dialog created with status ${this._state===xs.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(t){this._local_seqnum=t}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(t){this._uac_pending_reply=t}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===xs.STATUS_TERMINATED}update(t,n){this._state=xs.STATUS_CONFIRMED,Eu.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),n==="UAC"&&(this._route_set=t.getHeaders("record-route").reverse())}terminate(){Eu.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=xs.STATUS_TERMINATED}sendRequest(t,n={}){const a=vs.cloneArray(n.extraHeaders),o=vs.cloneObject(n.eventHandlers),s=n.body||null,r=this._createRequest(t,a,s);return o.onAuthenticated=()=>{this._local_seqnum+=1},new Jm(this,r,o).send(),r}receiveRequest(t){this._checkInDialogRequest(t)&&(t.method===L.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:t.method===L.INVITE&&(this._ack_seqnum=t.cseq),this._owner.receiveRequest(t))}_createRequest(t,n,a){n=vs.cloneArray(n),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const o=t===L.CANCEL||t===L.ACK?this._local_seqnum:this._local_seqnum+=1;return new Tt.OutgoingRequest(t,this._remote_target,this._ua,{cseq:o,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},n,a)}_checkInDialogRequest(t){if(!this._remote_seqnum)this._remote_seqnum=t.cseq;else if(t.cseq<this._remote_seqnum)if(t.method===L.ACK){if(this._ack_seqnum===null||t.cseq!==this._ack_seqnum)return!1}else return t.reply(500),!1;else t.cseq>this._remote_seqnum&&(this._remote_seqnum=t.cseq);if(t.method===L.INVITE||t.method===L.UPDATE&&t.body){if(this._uac_pending_reply===!0)t.reply(491);else if(this._uas_pending_reply===!0){const n=(Math.random()*10|0)+1;return t.reply(500,null,[`Retry-After:${n}`]),!1}else{this._uas_pending_reply=!0;const n=()=>{(t.server_transaction.state===jt.C.STATUS_ACCEPTED||t.server_transaction.state===jt.C.STATUS_COMPLETED||t.server_transaction.state===jt.C.STATUS_TERMINATED)&&(t.server_transaction.removeListener("stateChanged",n),this._uas_pending_reply=!1)};t.server_transaction.on("stateChanged",n)}t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===jt.C.STATUS_ACCEPTED&&(this._remote_target=t.parseHeader("contact").uri)})}else t.method===L.NOTIFY&&t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===jt.C.STATUS_COMPLETED&&(this._remote_target=t.parseHeader("contact").uri)});return!0}}class mT{constructor(t,n){ts(this,"plugin",null);ts(this,"rtcpPeer",null);ts(this,"handleId",0);ts(this,"info",null);ts(this,"joinResult",null);ts(this,"state",{});ts(this,"stream",null);ts(this,"loaded",!1);ts(this,"aTracks",[]);ts(this,"vTracks",[]);this.info=t,this.plugin=n,this.rtcpPeer=new RTCPeerConnection({iceServers:[]})}get memberInfo(){return{stream:this.stream,joinResult:this.joinResult,sender:this.handleId,type:"subscriber",name:this.info.display,state:this.state,id:this.handleId}}updateMemberState(t){var n;this.state={...this.state,...t||{}},(n=this.plugin)==null||n.session.emit("member:update",this.memberInfo)}updateMemberStateFromMessage(t){var s,r,d,h;const n=(r=(s=t==null?void 0:t.plugindata)==null?void 0:s.data)==null?void 0:r.newStatePublisher,o=((h=(d=t==null?void 0:t.plugindata)==null?void 0:d.data)==null?void 0:h.publisher_state).find(_=>_.id===n);this.updateMemberState(o==null?void 0:o.state)}hangup(){this.rtcpPeer&&(this.rtcpPeer.close(),this.rtcpPeer=null),this.stream&&this.stream.getTracks().forEach(t=>{t.stop()})}}class Xt{static canGetMediaDevices(){return!(!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices)}static async getDevices(t){return Xt.canGetMediaDevices()?(await navigator.mediaDevices.enumerateDevices()).filter(a=>a.kind===t):[]}static async getMicrophoneList(){return(await Xt.getDevices("audioinput")).map((n,a)=>({...n,deviceId:n.deviceId,label:n.label||`microphone ${a+1}`,kind:n.kind,groupId:n.groupId}))}static async getSpeakerList(){return(await Xt.getDevices("audiooutput")).map((n,a)=>({...n,deviceId:n.deviceId,label:n.label||`speaker ${a+1}`,kind:n.kind,groupId:n.groupId}))}static async getCameraList(){return(await Xt.getDevices("videoinput")).map((n,a)=>({...n,deviceId:n.deviceId,label:n.label||`camera ${a+1}`,kind:n.kind,groupId:n.groupId}))}static stopStreamTracks(t){t&&t.getTracks().forEach(n=>{n.stop()})}static async getMediaFromInputs({videoInput:t,audioInput:n}){let a,o;t==="default"?a=!0:t&&t!=="default"&&(a={deviceId:{exact:t}}),n==="default"?o=!0:n&&n!=="default"&&(o={deviceId:{exact:n}});const s={audio:o,video:a};return Xt.getUserMedia(s)}static async getUserMedia(t){return await navigator.mediaDevices.getUserMedia(t)}static async changeAudioOutput(t,n){if(!(!t||!n))if(typeof t.sinkId<"u")try{await t.setSinkId(n)}catch(a){let o=a;a.name==="SecurityError"&&(o=`You need to use HTTPS for selecting audio output device: ${a}`),console.error(o)}else console.warn("Browser does not support output device selection.")}static toggleAudioMute(t){const n=t.getAudioTracks();if(n.length!==0)return n.forEach(a=>{a.enabled=!a.enabled}),n[0].enabled}static toggleVideoMute(t){const n=t.getVideoTracks();if(n.length!==0)return n.forEach(a=>{a.enabled=!a.enabled}),n[0].enabled}static async getStream(t={video:!0,audio:!0}){try{const n=await navigator.mediaDevices.getUserMedia(t);let a=n.getTracks();return t.video?a=n.getVideoTracks():t.audio&&(a=n.getAudioTracks()),a.length===0?{stream:n,track:null}:{stream:n,track:a[0]}}catch(n){return console.warn(n),{stream:null,track:null}}}}var gT=ps();const ln=Me(gT),kt={LEAVE:"Leave",DETACH:"Detach",AUDIO_CHANGE:"AudioChange",VIDEO_CHANGE:"VideoChange",STATE:"State",ICE:"Ice",CONFIGURE:"Configure",TRICKLE:"Trickle",SUBSCRIBER:"Subscriber",PUBLISHER:"Publisher"},z=new ra("JanusSession"),TT="/opt/recordings/",te={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9},Ea=["audio","video"];class Sa extends ct.EventEmitter{static get C(){return te}constructor(t){z.debug("new"),super(),this._id=null,this._ua=t,this._status=te.STATUS_NULL,this._dialog=null,this._earlyDialogs={},this._contact=null,this._from_tag=null,this._to_tag=null,this.lastTransaction=0,this._connection=null,this._connectionPromiseQueue=Promise.resolve(),this._request=null,this._is_canceled=!1,this._cancel_reason="",this._is_confirmed=!1,this._late_sdp=!1,this._rtcOfferConstraints=null,this._rtcAnswerConstraints=null,this._localMediaStream=null,this._localMediaStreamLocallyGenerated=!1,this._rtcReady=!0,this._iceReady=!1,this._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},this._direction=null,this._local_identity=null,this._remote_identity=null,this._start_time=null,this._end_time=null,this._audioMuted=!1,this._videoMuted=!1,this._localHold=!1,this._remoteHold=!1,this._sessionTimers={enabled:this._ua.configuration.session_timers,refreshMethod:this._ua.configuration.session_timers_refresh_method,defaultExpires:L.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._referSubscribers={},this._candidates=[],this.publishers=[],this.private_id=null,this.memberList={},this.myFeedList=[],this.display_name="",this.stunServers=[{urls:"stun:turn.voicenter.co",credential:"kxsjahnsdjns3eds23esd",username:"turn2es21e"}],this.opaque_id=this.generateOpaqueId(),this.screen_share_opaque_id=this.generateOpaqueId(),this._data={},this.isAudioOn=!0,this.isVideoOn=!0,this.mediaConstraints={}}get C(){return te}get causes(){return L.causes}get id(){return this._id}get connection(){return this._connection}get contact(){return this._contact}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}get start_time(){return this._start_time}get end_time(){return this._end_time}get data(){return this._data}set data(t){this._data=t}get status(){return this._status}isInProgress(){switch(this._status){case te.STATUS_NULL:case te.STATUS_INVITE_SENT:case te.STATUS_1XX_RECEIVED:case te.STATUS_INVITE_RECEIVED:case te.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case te.STATUS_ANSWERED:case te.STATUS_WAITING_FOR_ACK:case te.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case te.STATUS_CANCELED:case te.STATUS_TERMINATED:return!0;default:return!1}}isMuted(){return{audio:this._audioMuted,video:this._videoMuted}}isOnHold(){return{local:this._localHold,remote:this._remoteHold}}getPTypeHeader(t){return`PTYPE: ${t}`}generateOpaqueId(){return`videoroomtest-${mh().replace(/-/g,"").slice(0,12)}`}connect(t,n,a={},o){z.debug("connect()"),this.display_name=n;const s=t,r=xe.cloneObject(a.eventHandlers),d=xe.cloneArray(a.extraHeaders),h=xe.cloneObject(a.mediaConstraints,{audio:!0,video:!0});this.mediaConstraints={...h};const _=a.mediaStream||null,g=xe.cloneObject(a.pcConfig,{iceServers:[]}),T=a.rtcConstraints||null,E=a.rtcOfferConstraints||null;if(this._rtcOfferConstraints=E,this._rtcAnswerConstraints=a.rtcAnswerConstraints||null,this._data=a.data||this._data,t===void 0)throw new TypeError("Not enough arguments");if(this._status!==te.STATUS_NULL)throw new Ns.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new Ns.NotSupportedError("WebRTC not supported");if(t=this._ua.normalizeTarget(t),this.room_id=t.user,this.target=t,!t)throw new TypeError(`Invalid target: ${s}`);this._sessionTimers.enabled&&xe.isDecimal(a.sessionTimersExpires)&&(a.sessionTimersExpires>=L.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=a.sessionTimersExpires:this._sessionTimers.defaultExpires=L.SESSION_EXPIRES);for(const A in r)Object.prototype.hasOwnProperty.call(r,A)&&this.on(A,r[A]);this._from_tag=xe.newTag();const y=a.anonymous||!1,C={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:y,outbound:!0}),y?(C.from_display_name="Anonymous",C.from_uri=new ln("sip","anonymous","anonymous.invalid"),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),d.push("Privacy: id")):a.fromUserName&&(C.from_uri=new ln("sip",a.fromUserName,this._ua.configuration.uri.host),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),a.fromDisplayName&&(C.from_display_name=a.fromDisplayName),d.push(`Contact: ${this._contact}`),d.push("Content-Type: application/json"),this._sessionTimers.enabled&&d.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new Tt.InitialOutgoingInviteRequest(t,this._ua,C,d),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(g,T),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,o&&o(this),this._newJanusSession("local",this._request),this._sendInitialRequest(h,E,_)}_overrideSenderTracks(t,n){t.getTracks().forEach(a=>{n.getSenders().forEach(async s=>{s.track.kind===a.kind&&(a.kind==="audio"&&!this.isAudioOn&&(a.enabled=!1),a.kind==="video"&&!this.isVideoOn&&(a.enabled=!1),await s.replaceTrack(a))})})}init_incoming(t,n){z.debug("init_incoming()");let a;const o=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;if(t.body&&o!=="application/sdp"){t.reply(415);return}if(this._status=te.STATUS_INVITE_RECEIVED,this._from_tag=t.from_tag,this._id=t.call_id+this._from_tag,this._request=t,this._contact=this._ua.contact.toString(),t.hasHeader("expires")&&(a=t.getHeader("expires")*1e3),t.to_tag=xe.newTag(),!this._createDialog(t,"UAS",!0)){t.reply(500,"Missing Contact header field");return}t.body?this._late_sdp=!1:this._late_sdp=!0,this._status=te.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{t.reply(408),this._failed("local",null,L.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),a&&(this._timers.expiresTimer=setTimeout(()=>{this._status===te.STATUS_WAITING_FOR_ANSWER&&(t.reply(487),this._failed("system",null,L.causes.EXPIRES))},a)),this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from,n&&n(this),this._newJanusSession("remote",t),this._status!==te.STATUS_TERMINATED&&(t.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(t={}){z.debug("answer()");const n=this._request,a=xe.cloneArray(t.extraHeaders),o=xe.cloneObject(t.mediaConstraints),s=t.mediaStream||null,r=xe.cloneObject(t.pcConfig,{iceServers:[]}),d=t.rtcConstraints||null,h=t.rtcAnswerConstraints||null,_=xe.cloneObject(t.rtcOfferConstraints);let g,T=!1,E=!1,y=!1,C=!1;if(this._rtcAnswerConstraints=h,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,this._direction!=="incoming")throw new Ns.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==te.STATUS_WAITING_FOR_ANSWER)throw new Ns.InvalidStateError(this._status);if(this._sessionTimers.enabled&&xe.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=L.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=L.SESSION_EXPIRES),this._status=te.STATUS_ANSWERED,!this._createDialog(n,"UAS")){n.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),a.unshift(`Contact: ${this._contact}`);const A=n.parseSDP();Array.isArray(A.media)||(A.media=[A.media]);for(const I of A.media)I.type==="audio"&&(T=!0,(!I.direction||I.direction==="sendrecv")&&(y=!0)),I.type==="video"&&(E=!0,(!I.direction||I.direction==="sendrecv")&&(C=!0));if(s&&o.audio===!1){g=s.getAudioTracks();for(const I of g)s.removeTrack(I)}if(s&&o.video===!1){g=s.getVideoTracks();for(const I of g)s.removeTrack(I)}!s&&o.audio===void 0&&(o.audio=y),!s&&o.video===void 0&&(o.video=C),!s&&!T&&!_.offerToReceiveAudio&&(o.audio=!1),!s&&!E&&!_.offerToReceiveVideo&&(o.video=!1),this._createRTCConnection(r,d),Promise.resolve().then(()=>{if(s)return s;if(o.audio||o.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(I=>{throw this._status===te.STATUS_TERMINATED?new Error("terminated"):(n.reply(480),this._failed("local",null,L.causes.USER_DENIED_MEDIA_ACCESS),z.warn('emit "getusermediafailed" [error:%o]',I),this.emit("getusermediafailed",I),new Error("getUserMedia() failed"))})}).then(I=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=I,I&&I.getTracks().forEach(H=>{this._connection.addTrack(H,I)})}).then(()=>{if(this._late_sdp)return;const I={originator:"remote",type:"offer",sdp:n.body};z.debug('emit "sdp"'),this.emit("sdp",I);const H=new RTCSessionDescription({type:"offer",sdp:I.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(H)).catch($=>{throw n.reply(488),this._failed("system",null,L.causes.WEBRTC_ERROR),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',$),this.emit("peerconnection:setremotedescriptionfailed",$),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(n),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",h).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(I=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,a),n.reply(200,null,a,I,()=>{this._status=te.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,I),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,L.causes.CONNECTION_ERROR)})}).catch(I=>{this._status!==te.STATUS_TERMINATED&&z.warn(I)})}terminate(t={}){z.debug("terminate()");const n=t.cause||L.causes.BYE,a=xe.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,d=t.reason_phrase;if(this._status===te.STATUS_TERMINATED)throw new Ns.InvalidStateError(this._status);switch(this._status){case te.STATUS_NULL:case te.STATUS_INVITE_SENT:case te.STATUS_1XX_RECEIVED:if(z.debug("canceling session"),r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);r&&(d=d||L.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${d}"`),this._status===te.STATUS_NULL||this._status===te.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===te.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=te.STATUS_CANCELED,this._failed("local",null,L.causes.CANCELED);break;case te.STATUS_WAITING_FOR_ANSWER:case te.STATUS_ANSWERED:if(z.debug("rejecting session"),r=r||480,r<300||r>=700)throw new TypeError(`Invalid status_code: ${r}`);this._request.reply(r,d,a,o),this._failed("local",null,L.causes.REJECTED);break;case te.STATUS_WAITING_FOR_ACK:case te.STATUS_CONFIRMED:if(z.debug("terminating session"),d=t.reason_phrase||L.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);if(r&&a.push(`Reason: SIP ;cause=${r}; text="${d}"`),this._status===te.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==jt.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:_})=>{_===L.ACK&&(this.sendRequest(L.BYE,{extraHeaders:a,body:o}),h.terminate(),this.closeSession())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===jt.C.STATUS_TERMINATED&&(this.sendRequest(L.BYE,{extraHeaders:a,body:o}),h.terminate(),this.closeSession())}),this._ended("local",null,n),this._dialog=h,this._ua.newDialog(h)}else{const h={janus:"leave"},_=["Content-Type: application/json",this.getPTypeHeader(kt.LEAVE)];this.sendRequest(L.BYE,{extraHeaders:_,body:JSON.stringify(h)}),this.closeSession(),this._ended("local",null,n)}}}configureMedia(t){this.isAudioOn=t.audio,this.isVideoOn=t.video}enableAudio(t){const n={janus:"message",body:{audio:t},handle_id:this.handle_id,session_id:this.session_id},a=["Content-Type: application/json",this.getPTypeHeader(kt.AUDIO_CHANGE)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{o.status_code===200&&(this._ua.emit("changeAudioState",t),this.sendStateMessage({audio:t}))}}})}startAudio(){Xt.toggleAudioMute(this.stream),this._toggleMuteAudio(!1),this.enableAudio(!0),this.isAudioOn=!0}stopAudio(){Xt.toggleAudioMute(this.stream),this._toggleMuteAudio(!0),this.enableAudio(!1),this.isAudioOn=!1}enableVideo(t){const n={janus:"message",body:{video:t},handle_id:this.handle_id,session_id:this.session_id},a=["Content-Type: application/json",this.getPTypeHeader(kt.VIDEO_CHANGE)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{o.status_code===200&&(this._ua.emit("changeVideoState",t),this.sendStateMessage({video:t}))}}})}startVideo(){Xt.toggleVideoMute(this.stream),this._toggleMuteVideo(!1),this.enableVideo(!0),this.isVideoOn=!0}stopVideo(){Xt.toggleVideoMute(this.stream),this._toggleMuteVideo(!0),this.enableVideo(!1),this.isVideoOn=!1}sendStateMessage(t){const n={janus:"message",body:{request:"state",data:t},handle_id:this.handle_id,session_id:this.session_id},a=["Content-Type: application/json",this.getPTypeHeader(kt.STATE)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n)})}sendInfo(t,n,a={}){if(z.debug("sendInfo()"),this._status!==te.STATUS_CONFIRMED&&this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_1XX_RECEIVED)throw new Ns.InvalidStateError(this._status);new nu(this).send(t,n,a)}mute(t={audio:!0,video:!1}){z.debug("mute()");let n=!1,a=!1;this._audioMuted===!1&&t.audio&&(n=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&t.video&&(a=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(n===!0||a===!0)&&this._onmute({audio:n,video:a})}unmute(t={audio:!0,video:!0}){z.debug("unmute()");let n=!1,a=!1;this._audioMuted===!0&&t.audio&&(n=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&t.video&&(a=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(n===!0||a===!0)&&this._onunmute({audio:n,video:a})}hold(t={},n){if(z.debug("hold()"),this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:L.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}unhold(t={},n){if(z.debug("unhold()"),this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:L.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}renegotiate(t={},n){z.debug("renegotiate()");const a=t.rtcOfferConstraints||null;if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const o={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:L.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}),!0}refer(t,n){z.debug("refer()");const a=t;if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${a}`);const o=new _g(this);o.sendRefer(t,n);const s=o.id;return this._referSubscribers[s]=o,o.on("requestFailed",()=>{delete this._referSubscribers[s]}),o.on("accepted",()=>{delete this._referSubscribers[s]}),o.on("failed",()=>{delete this._referSubscribers[s]}),o}sendRequest(t,n){return z.debug("sendRequest()"),this._dialog.sendRequest(t,n)}receiveNotify(t){z.debug("receiveRequest()")}receiveRequest(t){if(z.debug("receiveRequest()"),t.method===L.CANCEL)(this._status===te.STATUS_WAITING_FOR_ANSWER||this._status===te.STATUS_ANSWERED)&&(this._status=te.STATUS_CANCELED,this._request.reply(487),this._failed("remote",t,L.causes.CANCELED));else switch(t.method){case L.ACK:if(this._status!==te.STATUS_WAITING_FOR_ACK)return;if(this._status=te.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!t.body){this.terminate({cause:L.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:t.body};z.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>{this._is_confirmed||this._confirmed("remote",t)}).catch(o=>{this.terminate({cause:L.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})}else this._is_confirmed||this._confirmed("remote",t);break;case L.BYE:this._status===te.STATUS_CONFIRMED||this._status===te.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,L.causes.BYE)):this._status===te.STATUS_INVITE_RECEIVED||this._status===te.STATUS_WAITING_FOR_ANSWER?(t.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",t,L.causes.BYE)):t.reply(403,"Wrong Status");break;case L.INVITE:this._status===te.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case L.INFO:if(this._status===te.STATUS_1XX_RECEIVED||this._status===te.STATUS_WAITING_FOR_ANSWER||this._status===te.STATUS_ANSWERED||this._status===te.STATUS_WAITING_FOR_ACK||this._status===te.STATUS_CONFIRMED){const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;n&&n.match(/^application\/dtmf-relay/i)?new ng(this).init_incoming(t):n!==void 0?new nu(this).init_incoming(t):t.reply(415)}else t.reply(403,"Wrong Status");break;case L.UPDATE:this._status===te.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case L.REFER:this._status===te.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case L.NOTIFY:this._status===te.STATUS_CONFIRMED?this._receiveNotify(t):t.reply(403,"Wrong Status");break;default:t.reply(501)}}onTransportError(){z.warn("onTransportError()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.CONNECTION_ERROR,cause:L.causes.CONNECTION_ERROR})}onRequestTimeout(){z.warn("onRequestTimeout()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:L.causes.REQUEST_TIMEOUT,cause:L.causes.REQUEST_TIMEOUT})}onDialogError(){z.warn("onDialogError()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.DIALOG_ERROR,cause:L.causes.DIALOG_ERROR})}newDTMF(t){z.debug("newDTMF()"),this.emit("newDTMF",t)}newInfo(t){z.debug("newInfo()"),this.emit("newInfo",t)}_isReadyToReOffer(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(z.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(z.debug("_isReadyToReOffer() | session not established yet"),!1):(z.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}_close(){if(z.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(z.debug("close() | closing local MediaStream"),xe.closeMediaStream(this._localMediaStream)),this._status!==te.STATUS_TERMINATED){if(this._status=te.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(t){z.warn("close() | error closing the RTCPeerConnection: %o",t)}for(const t in this._timers)Object.prototype.hasOwnProperty.call(this._timers,t)&&clearTimeout(this._timers[t]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const t in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(const t in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,t)&&delete this._referSubscribers[t];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(t,n){let a=Vr.T1;function o(){this._status===te.STATUS_WAITING_FOR_ACK&&(t.reply(200,null,[`Contact: ${this._contact}`],n),a<Vr.T2&&(a=a*2,a>Vr.T2&&(a=Vr.T2)),this._timers.invite2xxTimer=setTimeout(o.bind(this),a))}this._timers.invite2xxTimer=setTimeout(o.bind(this),a)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===te.STATUS_WAITING_FOR_ACK&&(z.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(L.BYE),this._ended("remote",null,L.causes.NO_ACK))},Vr.TIMER_H)}_createRTCConnection(t,n){this.stunServers,this._connection=new RTCPeerConnection(t,n),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:L.causes.RTP_TIMEOUT,status_code:408,reason_phrase:L.causes.RTP_TIMEOUT})});let a;const o=s=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||s.candidate&&(this._candidates.push(s.candidate),clearTimeout(a),a=setTimeout(()=>{this.lastTrickleReceived=!0,this.subscribeSent&&!this.isConfigureSent&&(this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream}),this._sendConfigureMessage({audio:!0,video:!0}).then(()=>{}))},500))};this._connection.onicecandidate=o,z.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(t,n){if(z.debug("createLocalDescription()"),t!=="offer"&&t!=="answer")throw new Error(`createLocalDescription() | invalid type "${t}"`);const a=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>t==="offer"?a.createOffer(n).catch(o=>(z.warn('emit "peerconnection:createofferfailed" [error:%o]',o),this.emit("peerconnection:createofferfailed",o),Promise.reject(o))):a.createAnswer(n).catch(o=>(z.warn('emit "peerconnection:createanswerfailed" [error:%o]',o),this.emit("peerconnection:createanswerfailed",o),Promise.reject(o)))).then(o=>(this.jsepOffer=o,a.setLocalDescription(o).catch(s=>(this._rtcReady=!0,z.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',s),this.emit("peerconnection:setlocaldescriptionfailed",s),Promise.reject(s))))).then(()=>{const o=n&&n.iceRestart;if(a.iceGatheringState==="complete"&&!o||a.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const s={originator:"local",type:t,sdp:a.localDescription.sdp};return z.debug('emit "sdp"'),this.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(s=>{let r=!1,d,h;this._iceReady=!1;const _=()=>{a.removeEventListener("icecandidate",d),a.removeEventListener("icegatheringstatechange",h),r=!0,this._rtcReady=!0,this._iceReady=!0;const g={originator:"local",type:t,sdp:a.localDescription.sdp};z.debug('emit "sdp"'),this.emit("sdp",g),s(g.sdp)};a.addEventListener("icecandidate",d=g=>{const T=g.candidate;T?this.emit("icecandidate",{candidate:T,ready:_}):r||_()}),a.addEventListener("icegatheringstatechange",h=()=>{a.iceGatheringState==="complete"&&!r&&_()})})})}_createDialog(t,n,a){const o=n==="UAS"?t.to_tag:t.from_tag,s=n==="UAS"?t.from_tag:t.to_tag,r=t.call_id+o+s;let d=this._earlyDialogs[r];if(a)return d?!0:(d=new va(this,t,n,va.C.STATUS_EARLY),d.error?(z.debug(d.error),this._failed("remote",t,L.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=d,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,d)return d.update(t,n),this._dialog=d,delete this._earlyDialogs[r],!0;const h=new va(this,t,n);return h.error?(z.debug(h.error),this._failed("remote",t,L.causes.INTERNAL_ERROR),!1):(this._dialog=h,!0)}}_receiveReinvite(t){z.debug("receiveReinvite()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=xe.cloneArray(d.extraHeaders);if(this._status!==te.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("reinvite",a),o)return;if(this._late_sdp=!1,!t.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(d=>{r.call(this,d)}).catch(()=>{t.reply(500)});return}if(n!=="application/sdp"){z.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==te.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{z.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),this._late_sdp&&(d=this._mangleOffer(d)),t.reply(200,null,h,d,()=>{this._status=te.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(t,d),this._setACKTimer()}),typeof a.callback=="function"&&a.callback()}}_receiveUpdate(t){z.debug("receiveUpdate()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=xe.cloneArray(d.extraHeaders);if(this._status!==te.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("update",a),o)return;if(!t.body){r.call(this,null);return}if(n!=="application/sdp"){z.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==te.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{z.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),t.reply(200,null,h,d),typeof a.callback=="function"&&a.callback()}}_processInDialogSdpOffer(t){z.debug("_processInDialogSdpOffer()");const n=t.parseSDP();let a=!1;for(const r of n.media){if(Ea.indexOf(r.type)===-1)continue;const d=r.direction||n.direction||"sendrecv";if(d==="sendonly"||d==="inactive")a=!0;else{a=!1;break}}const o={originator:"remote",type:"offer",sdp:t.body};z.debug('emit "sdp"'),this.emit("sdp",o);const s=new RTCSessionDescription({type:"offer",sdp:o.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(s).catch(r=>{throw t.reply(488),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',r),this.emit("peerconnection:setremotedescriptionfailed",r),r})}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&a===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&a===!0&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(r=>{throw t.reply(500),z.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',r),r})}).catch(r=>{z.warn("_processInDialogSdpOffer() failed [error: %o]",r)}),this._connectionPromiseQueue}_receiveRefer(t){if(z.debug("receiveRefer()"),!t.refer_to){z.debug("no Refer-To header field present in REFER"),t.reply(400);return}if(t.refer_to.uri.scheme!==L.SIP){z.debug("Refer-To header field points to a non-SIP URI scheme"),t.reply(416);return}t.reply(202);const n=new cg(this,t.cseq);z.debug('emit "refer"'),this.emit("refer",{request:t,accept:(s,r)=>{a.call(this,s,r)},reject:()=>{o.call(this)}});function a(s,r={}){if(s=typeof s=="function"?s:null,this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;const d=new Sa(this._ua);if(d.on("progress",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("accepted",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("_failed",({message:h,cause:_})=>{h?n.notify(h.status_code,h.reason_phrase):n.notify(487,_)}),t.refer_to.uri.hasHeader("replaces")){const h=decodeURIComponent(t.refer_to.uri.getHeader("replaces"));r.extraHeaders=xe.cloneArray(r.extraHeaders),r.extraHeaders.push(`Replaces: ${h}`)}d.connect(t.refer_to.uri.toAor(),r,s)}function o(){n.notify(603)}}_receiveNotify(t){switch(z.debug("receiveNotify()"),t.event||t.reply(400),t.event.event){case"refer":{let n,a;if(t.event.params&&t.event.params.id)n=t.event.params.id,a=this._referSubscribers[n];else if(Object.keys(this._referSubscribers).length===1)a=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{t.reply(400,"Missing event id parameter");return}if(!a){t.reply(481,"Subscription does not exist");return}a.receiveNotify(t),t.reply(200);break}default:t.reply(489)}}_receiveReplaces(t){z.debug("receiveReplaces()");function n(o){if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;const s=new Sa(this._ua);s.on("confirmed",()=>{this.terminate()}),s.init_incoming(t,o)}function a(){z.debug("Replaced INVITE rejected by the user"),t.reply(486)}this.emit("replaces",{request:t,accept:o=>{n.call(this,o)},reject:()=>{a.call(this)}})}_getNextTransactionId(){return(this.lastTransaction+1).toString()}_sendInitialRequest(t,n,a){this.ackSent=!1,this.publisherSubscribeSent=!1;const o=new Kr(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});Promise.resolve().then(()=>{if(a)return a;if(t.audio||t.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(s=>{throw this._status===te.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,L.causes.USER_DENIED_MEDIA_ACCESS),z.warn('emit "getusermediafailed" [error:%o]',s),this.emit("getusermediafailed",s),s)})}).then(s=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=s,s&&s.getTracks().forEach(r=>{this._connection.addTrack(r,s)}),this._connecting(this._request),this._createLocalDescription("offer",n).catch(r=>{throw this._failed("local",null,L.causes.WEBRTC_ERROR),r})}).then(s=>{if(this._is_canceled||this._status===te.STATUS_TERMINATED)throw new Error("terminated");const r={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaque_id},d=JSON.stringify(r);this._request.body=d,this._status=te.STATUS_INVITE_SENT,z.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),o.send()}).catch(s=>{this._status!==te.STATUS_TERMINATED&&z.warn(s)})}async requestAudioAndVideoPermissions(){this.stream=await this.loadStream()}async setupMediaStream(){await this.requestAudioAndVideoPermissions(),await this.processPlugins()}async changeMediaConstraints(t){this.mediaConstraints={...t},await this.processPlugins(),this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream})}async loadStream(){const t={};this.isAudioOn?this.mediaConstraints.audio?t.audio=this.mediaConstraints.audio:t.audio=!0:t.audio=!1,this.isVideoOn?this.mediaConstraints.video?t.video=this.mediaConstraints.video:t.video=!0:t.video=!1;let n=null;try{n=await navigator.mediaDevices.getUserMedia(t)}catch{try{t.video=!1,n=await navigator.mediaDevices.getUserMedia(t)}catch{t.audio=!1,t.video=!1,n=await navigator.mediaDevices.getUserMedia(t)}}return n}addTracks(t){this._connection.getSenders().forEach(n=>{this._connection.removeTrack(n)}),t.forEach(n=>{this._connection.addTrack(n)})}getRecordFileName(){return TT+this.room_id+btoa(unescape(encodeURIComponent(this.displayName)))+Date.now()}async processIceCandidates(){for(let t=0;t<this.iceCandidates.length;t++)await this._connection.addIceCandidate(this.iceCandidates[t]);this.iceCandidates=[]}async _sendConfigureMessage(t){const n=this._candidates.map(r=>({janus:"trickle",candidate:r,handle_id:this.handle_id,session_id:this.session_id})),o={configure:{janus:"message",body:{request:"configure",record:!0,filename:this.getRecordFileName(),...t},jsep:this.jsepOffer,handle_id:this.handle_id,session_id:this.session_id},trickles:[...n]},s=["Content-Type: application/json",this.getPTypeHeader(kt.ICE)];this.sendRequest(L.INFO,{extraHeaders:s,body:JSON.stringify(o),eventHandlers:{onSuccessResponse:async r=>{this.isConfigureSent=!0;const h=r.data.split(`\r
|
135
|
+
`),_=h[h.length-1],g=JSON.parse(_);await this._connection.setRemoteDescription(g.jsep),this._candidates=[]}}})}_sendMemberStartMessage(t,n){const a={janus:"message",body:{request:"start",room:this.room_id},handle_id:t.handleId,session_id:this.session_id,jsep:n},o=["Content-Type: application/json",this.getPTypeHeader(kt.CONFIGURE)];this.sendRequest(L.INFO,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{s.status_code===200&&await t.rtcpPeer.setLocalDescription(n)}}})}_sendTrickleMessage(t){const a={trickles:[...t.map(s=>({janus:"trickle",candidate:s,handle_id:this.handle_id,session_id:this.session_id}))]},o=[this.getPTypeHeader(kt.TRICKLE)];this.sendRequest(L.INFO,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{}}})}async _answerAttachedStream(t,n){let a=null;const o=async h=>{if(!t.rtcpPeer||t.loaded)return;{t.loaded=!0;const y={audio:!0,video:!0};await new Promise(C=>{setTimeout(C,100)}),a=await t.rtcpPeer.createAnswer(y),this._sendMemberStartMessage(t,a)}const _=h.streams[0].getAudioTracks(),g=h.streams[0].getVideoTracks(),T=[];_[0]&&T.push(_[0]),g[0]&&T.push(g[0]);const E=new MediaStream(T);t.stream=E,this._ua.emit("memberJoin",t.memberInfo)};let s,r=[];const d=h=>{t.rtcpPeer.signalingState!=="stable"&&t.rtcpPeer.signalingState!=="have-local-offer"||(r.push(h.candidate||null),clearTimeout(s),s=setTimeout(()=>{this._sendTrickleMessage(r)},500))};t.rtcpPeer=new RTCPeerConnection,t.rtcpPeer.ontrack=o,t.rtcpPeer.onicecandidate=d,t.rtcpPeer.sender=n.sender,await t.rtcpPeer.setRemoteDescription(n.jsep)}_sendJoinMemberRequest(t){const n={janus:"message",body:{request:"join",room:this.room_id,feed:t.info.id,ptype:"subscriber"},handle_id:t.handleId,session_id:this.session_id},a=[this.getPTypeHeader(kt.SUBSCRIBER)];this.sendRequest(L.SUBSCRIBE,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{var s,r;if(o.status_code===200){const d=JSON.parse(o.body);(r=(s=d==null?void 0:d.plugindata)==null?void 0:s.data)!=null&&r.id&&await this._answerAttachedStream(t,d)}}}})}_attachMember(t){const n={janus:"attach",opaque_id:this.opaque_id,plugin:"janus.plugin.videoroom",session_id:this.session_id},a=[this.getPTypeHeader(kt.SUBSCRIBER)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{if(o.status_code===200){const r=JSON.parse(o.body).data.id;t.handleId=r,this._sendJoinMemberRequest(t)}}}})}_detachMember(t){const n={janus:"detach",handle_id:t.handleId,session_id:this.session_id},a=[this.getPTypeHeader(kt.SUBSCRIBER)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n)}),Xt.stopStreamTracks(t.memberInfo.stream),this._ua.emit("memberHangup",t.memberInfo)}receivePublishers(t){var a,o,s,r,d,h,_,g;const n={...this.memberList};(o=(a=t==null?void 0:t.plugindata)==null?void 0:a.data)==null||o.publishers.forEach(T=>{delete n[T.id],!this.memberList[T.id]&&!this.myFeedList.includes(T.id)&&T.clientID!==this.client_id&&(this.memberList[T.id]=new mT(T,this),this._attachMember(this.memberList[T.id]))}),((r=(s=t==null?void 0:t.plugindata)==null?void 0:s.data)==null?void 0:r.videoroom)==="synced"&&Object.keys(n).forEach(T=>{n[T].hangup(),delete this.memberList[T]}),this.publishers=(h=(d=t==null?void 0:t.plugindata)==null?void 0:d.data)==null?void 0:h.publishers,this.private_id=(g=(_=t==null?void 0:t.plugindata)==null?void 0:_.data)==null?void 0:g.private_id}receiveUnpublished(t){const n=this.memberList[t];n&&(n.hangup(),this._detachMember(n),delete this.memberList[t])}closeSession(){this.stream&&this.stream.getTracks().forEach(n=>{n.stop()}),Object.values(this.memberList).forEach(n=>{n.hangup(),this._detachMember(n)}),this._ua.emit("conferenceEnd",this.id)}async processPlugins(){const t=this._ua.processStreamPlugins;let n=await this.loadStream();for(const a of t)n=await a.process(n);this.stream.getTracks().forEach(a=>{this.stream.removeTrack(a),a.stop()}),n.getTracks().forEach(a=>{this.stream.addTrack(a)})}async resyncPlugins(t){const n=this._ua.processStreamPlugins.filter(a=>a.type===t);for(const a of n)a.running&&a.terminate();if(t==="video"){let a=await this.loadStream();for(const o of n)o.running&&(a=await o.start(a));this.stream.getTracks().forEach(o=>{this.stream.removeTrack(o),o.stop()}),a.getTracks().forEach(o=>{this.stream.addTrack(o)}),this._overrideSenderTracks(this.stream,this._connection),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream})}else{const a=this._ua.newStreamPlugins.find(d=>d.type===t);let s=a.getStream().clone();for(const d of n)d.running&&(s=await d.start(s));const r=a.getConnection();this._overrideSenderTracks(s,r),this._ua.emit("changePluginStream",{type:t,stream:s})}}stopProcessPlugins(t){const n=this._ua.processStreamPlugins.filter(a=>a.type===t);for(const a of n)a.running&&a.kill()}_receiveInviteResponse(t){if(z.debug("receiveInviteResponse()"),this._dialog&&t.status_code>=200&&t.status_code<=299&&!this.ackSent)if(this._dialog.id.call_id===t.call_id&&this._dialog.id.local_tag===t.from_tag&&this._dialog.id.remote_tag===t.to_tag){this.ackSent=!0,this.sendRequest(L.ACK);return}else{const n=new va(this,t,"UAC");if(n.error!==void 0){z.debug(n.error);return}this.sendRequest(L.ACK),this.sendRequest(L.BYE);return}if(this.ackSent&&!this.publisherSubscribeSent){const n=JSON.parse(t.body);this.setupMediaStream().then(()=>{this.session_id=n.session_id,this.handle_id=n.data.id,this.client_id=mh();const a={janus:"message",body:{request:"join",room:this.room_id,ptype:"publisher",display:this.display_name,clientID:this.client_id,opaque_id:this.opaque_id},handle_id:this.handle_id},o=[this.getPTypeHeader(kt.PUBLISHER)];this.sendRequest(L.SUBSCRIBE,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{var r,d,h,_;if(s.status_code===200){if(this.subscribeSent=!0,s.body)try{const g=JSON.parse(s.body)||{};((d=(r=g.plugindata)==null?void 0:r.data)==null?void 0:d.videoroom)==="joined"&&this.myFeedList.push(g.plugindata.data.id),(_=(h=g.plugindata)==null?void 0:h.data)!=null&&_.publishers&&this.receivePublishers(g)}catch(g){console.error(g)}this.lastTrickleReceived&&!this.isConfigureSent&&(this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream}),this._sendConfigureMessage({audio:!0,video:!0}).then(()=>{})),this._ua.emit("conferenceStart")}}}}),this.publisherSubscribeSent=!0})}if(this._is_canceled){t.status_code>=100&&t.status_code<200?this._request.cancel(this._cancel_reason):t.status_code>=200&&t.status_code<299&&this._acceptAndTerminate(t);return}if(!(this._status!==te.STATUS_INVITE_SENT&&this._status!==te.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(t.status_code):this._status=te.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(t.status_code):{if(!t.to_tag){z.debug("1xx response received without to tag");break}if(t.hasHeader("contact")&&!this._createDialog(t,"UAC",!0))break;if(this._status=te.STATUS_1XX_RECEIVED,!t.body){this._progress("remote",t);break}const n={originator:"remote",type:"answer",sdp:t.body};z.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>this._progress("remote",t)).catch(o=>{z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)});break}case/^2[0-9]{2}$/.test(t.status_code):{if(this._status=te.STATUS_CONFIRMED,!t.body){this._acceptAndTerminate(t,400,L.causes.MISSING_SDP),this._failed("remote",t,L.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(t,"UAC"))break;break}default:{const n=xe.sipErrorCause(t.status_code);this._failed("remote",t,n)}}}_sendReinvite(t={}){z.debug("sendReinvite()");const n=xe.cloneArray(t.extraHeaders),a=xe.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null;let s=!1;n.push(`Contact: ${this._contact}`),n.push("Content-Type: application/sdp"),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(h=>{h=this._mangleOffer(h);const _={originator:"local",type:"offer",sdp:h};z.debug('emit "sdp"'),this.emit("sdp",_),this.sendRequest(L.INVITE,{extraHeaders:n,body:h,eventHandlers:{onSuccessResponse:g=>{r.call(this,g),s=!0},onErrorResponse:g=>{d.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{d()});function r(h){if(this._status===te.STATUS_TERMINATED||(this.sendRequest(L.ACK),s))return;if(this._handleSessionTimersInIncomingResponse(h),h.body){if(!h.hasHeader("Content-Type")||h.getHeader("Content-Type").toLowerCase()!=="application/sdp"){d.call(this);return}}else{d.call(this);return}const _={originator:"remote",type:"answer",sdp:h.body};z.debug('emit "sdp"'),this.emit("sdp",_);const g=new RTCSessionDescription({type:"answer",sdp:_.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(g)).then(()=>{a.succeeded&&a.succeeded(h)}).catch(T=>{d.call(this),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function d(h){a.failed&&a.failed(h)}}_sendUpdate(t={}){z.debug("sendUpdate()");const n=xe.cloneArray(t.extraHeaders),a=xe.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null,s=t.sdpOffer||!1;let r=!1;n.push(`Contact: ${this._contact}`),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),s?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(_=>{_=this._mangleOffer(_);const g={originator:"local",type:"offer",sdp:_};z.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(L.UPDATE,{extraHeaders:n,body:_,eventHandlers:{onSuccessResponse:T=>{d.call(this,T),r=!0},onErrorResponse:T=>{h.call(this,T)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{h.call(this)})):this.sendRequest(L.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:_=>{d.call(this,_)},onErrorResponse:_=>{h.call(this,_)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function d(_){if(this._status!==te.STATUS_TERMINATED&&!r)if(this._handleSessionTimersInIncomingResponse(_),s){if(_.body){if(!_.hasHeader("Content-Type")||_.getHeader("Content-Type").toLowerCase()!=="application/sdp"){h.call(this);return}}else{h.call(this);return}const g={originator:"remote",type:"answer",sdp:_.body};z.debug('emit "sdp"'),this.emit("sdp",g);const T=new RTCSessionDescription({type:"answer",sdp:g.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(T)).then(()=>{a.succeeded&&a.succeeded(_)}).catch(E=>{h.call(this),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),this.emit("peerconnection:setremotedescriptionfailed",E)})}else a.succeeded&&a.succeeded(_)}function h(_){a.failed&&a.failed(_)}}_acceptAndTerminate(t,n,a){z.debug("acceptAndTerminate()");const o=[];n&&(a=a||L.REASON_PHRASE[n]||"",o.push(`Reason: SIP ;cause=${n}; text="${a}"`)),(this._dialog||this._createDialog(t,"UAC"))&&(this.sendRequest(L.ACK),this.sendRequest(L.BYE,{extraHeaders:o})),this._status=te.STATUS_TERMINATED}_mangleOffer(t){if(!this._localHold&&!this._remoteHold)return t;if(t=Ut.parse(t),this._localHold&&!this._remoteHold){z.debug("mangleOffer() | me on hold, mangling offer");for(const n of t.media)Ea.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="sendonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="sendonly")}else if(this._localHold&&this._remoteHold){z.debug("mangleOffer() | both on hold, mangling offer");for(const n of t.media)Ea.indexOf(n.type)!==-1&&(n.direction="inactive")}else if(this._remoteHold){z.debug("mangleOffer() | remote on hold, mangling offer");for(const n of t.media)Ea.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="recvonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="recvonly")}return Ut.write(t)}_setLocalMediaStatus(){let t=!0,n=!0;(this._localHold||this._remoteHold)&&(t=!1,n=!1),this._audioMuted&&(t=!1),this._videoMuted&&(n=!1),this._toggleMuteAudio(!t),this._toggleMuteVideo(!n)}_handleSessionTimersInIncomingRequest(t,n){if(!this._sessionTimers.enabled)return;let a;t.session_expires&&t.session_expires>=L.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,a=t.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,a="uas"),n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${a}`),this._sessionTimers.refresher=a==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(t){if(!this._sessionTimers.enabled)return;let n;t.session_expires&&t.session_expires>=L.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,n=t.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uac"),this._sessionTimers.refresher=n==="uac",this._runSessionTimer()}_runSessionTimer(){const t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(()=>{this._status!==te.STATUS_TERMINATED&&this._isReadyToReOffer()&&(z.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===L.UPDATE?this._sendUpdate():this._sendReinvite())},t*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==te.STATUS_TERMINATED&&(z.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:L.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},t*1100)}_toggleMuteAudio(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="audio");for(const a of n)a.track.enabled=!t}_toggleMuteVideo(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="video");for(const a of n)a.track.enabled=!t}_newJanusSession(t,n){z.debug("newRTCSession()"),this._ua.newJanusSession(this,{originator:t,session:this,request:n})}_connecting(t){z.debug("session connecting"),z.debug('emit "connecting"'),this.emit("connecting",{request:t})}_progress(t,n){z.debug("session progress"),z.debug('emit "progress"'),this.emit("progress",{originator:t,response:n||null})}_accepted(t,n){z.debug("session accepted"),this._start_time=new Date,z.debug('emit "accepted"'),this.emit("accepted",{originator:t,response:n||null})}_confirmed(t,n){z.debug("session confirmed"),this._is_confirmed=!0,z.debug('emit "confirmed"'),this.emit("confirmed",{originator:t,ack:n||null})}_ended(t,n,a){z.debug("session ended"),this._end_time=new Date,this._close(),z.debug('emit "ended"'),this.emit("ended",{originator:t,message:n||null,cause:a})}_failed(t,n,a){z.debug("session failed"),z.debug('emit "_failed"'),this.emit("_failed",{originator:t,message:n||null,cause:a}),this._close(),z.debug('emit "failed"'),this.emit("failed",{originator:t,message:n||null,cause:a})}_onhold(t){z.debug("session onhold"),this._setLocalMediaStatus(),z.debug('emit "hold"'),this.emit("hold",{originator:t})}_onunhold(t){z.debug("session onunhold"),this._setLocalMediaStatus(),z.debug('emit "unhold"'),this.emit("unhold",{originator:t})}_onmute({audio:t,video:n}){z.debug("session onmute"),this._setLocalMediaStatus(),z.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}_onunmute({audio:t,video:n}){z.debug("session onunmute"),this._setLocalMediaStatus(),z.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}class qn{constructor(t){if(this.headers={},t.length>0){let n=!1;const a=t.split(`\r
|
136
136
|
`),o=a.shift().split(/\s/);this.protocol=o[0],this.ident=o[1],this.code=o.length>3?parseInt(o[2]):0,this.method=o.length>3?o[3]:o[2],this.body="";for(const s of a){if(s==`-------${this.ident}$`)break;if(s===""){n=!0;continue}if(s&&n)this.body+=`${s}\r
|
137
137
|
`;else{const r=s.split(": ");this.addHeader(r[0],r[1].trim())}}}else this.ident=xe.createRandomToken(12),this.protocol="MSRP"}addHeader(t,n){this.headers[t]=n}getHeader(t){return this.headers[t]}toString(){let t=`${this.protocol} ${this.ident} ${this.code} ${this.method}`.replaceAll(/null\s|undefined\s/ig,"")+`\r
|
138
138
|
`;for(const n in this.headers)t+=`${n}: ${this.headers[n]}\r
|
139
139
|
`;return this.body&&(t+=`\r
|
140
140
|
${this.body}\r
|
141
141
|
`),t+=`-------${this.ident}$\r
|
142
|
-
`,t}}const
|
142
|
+
`,t}}const Ae={STATUS_NULL:0,STATUS_INVITE_SENT:1,STATUS_1XX_RECEIVED:2,STATUS_INVITE_RECEIVED:3,STATUS_WAITING_FOR_ANSWER:4,STATUS_ANSWERED:5,STATUS_WAITING_FOR_ACK:6,STATUS_CANCELED:7,STATUS_TERMINATED:8,STATUS_CONFIRMED:9};class Su extends ct.EventEmitter{constructor(t){super(),this._id=null,this.my_ip="127.0.0.1",this._ua=t,this.auth_id=xe.createRandomToken(10),this._status=Ae.STATUS_NULL,this._dialog=null,this._earlyDialogs={},this._contact=null,this._from_tag=null,this._to_tag=null,this._msgHistory=[],this.target_addr=[],this.my_addr=[],this.credentials={username:t._configuration.authorization_user,ha1:t._configuration.ha1,realm:t._configuration.realm},this._request=null,this.status="new",this.target="",this.message="",this._connectionPromiseQueue=Promise.resolve(),this._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},this._direction=null,this._local_identity=null,this._remote_identity=null,this._start_time=null,this._end_time=null,this._tones=null,this._sessionTimers={enabled:this._ua.configuration.session_timers,refreshMethod:this._ua.configuration.session_timers_refresh_method,defaultExpires:L.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._msrpKeepAliveTimer=null}static get C(){return Ae}get direction(){return this._direction}get connection(){return this._connection}get id(){return this._id}connect(t=""){t!==""&&(this._direction="outgoing"),this.target=t,this._connection=new WebSocket(`wss://${this._ua._configuration.realm}`,"msrp"),this._connection.binaryType="arraybuffer",this._connection.onopen=n=>{console.log("open",n),this.onopen()},this._connection.onclose=n=>{console.log("close",n),this.onclose()},this._connection.onmessage=n=>{console.log("msg",n),this.onmessage(n)},this._connection.onerror=n=>{console.log("error",n),this.onerror()}}_sendKeepAlive(){const t=new qn("");t.method="SEND",t.addHeader("To-Path",`${this.my_addr[1]}`),t.addHeader("From-Path",`${this.my_addr[0]}`),t.addHeader("Message-ID",xe.createRandomToken(10)),this._connection.send(t.toString())}answer(){if(!this._createDialog(this._request,"UAS")){this._request.reply(500,"Error creating dialog");return}this._status=Ae.STATUS_ANSWERED,clearTimeout(this._timers.userNoAnswerTimer),this.connect()}acceptParty(t){this._request.parseSDP(!0),this._request.reply(200,"OK",[],`v=0
|
143
143
|
o=- 4232740119537112802 2 IN IP4 ${this.my_ip}
|
144
144
|
c=IN IP4 ${this.my_ip}
|
145
145
|
t=0 0
|
@@ -153,7 +153,7 @@ t=0 0
|
|
153
153
|
m=message 2856 TCP/TLS/MSRP *
|
154
154
|
a=accept-types:text/plain text/html
|
155
155
|
a=path:${t.getHeader("Use-Path")} msrp://${this._ua._configuration.authorization_user}.${this._ua._configuration.realm}:2856/${this.auth_id};ws
|
156
|
-
`),this._newMSRPSession("local",this._request),this._id=this._request.call_id+this._from_tag,new Kr(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout(),console.log("to")},onTransportError:s=>{this.onTransportError(),console.log(s)},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s),s.status_code===200&&(s.parseSDP(!0),this._status=Ce.STATUS_CONFIRMED,this.target_addr=s.sdp.media[0].invalid[1].value.replaceAll("path:","").split(" ").reverse(),this.status="active",this.emit("active"),this.emit("confirmed"))}}).send(),this._status=Ce.STATUS_INVITE_SENT}terminate(t={}){const n=t.cause||L.causes.BYE,a=xe.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,d=t.reason_phrase;if(this._status===Ce.STATUS_TERMINATED)throw new Ns.InvalidStateError(this._status);switch(this.status="terminated",this._status){case Ce.STATUS_NULL:case Ce.STATUS_INVITE_SENT:case Ce.STATUS_1XX_RECEIVED:if(r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);r&&(d=d||L.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${d}"`),this._status===Ce.STATUS_NULL||this._status===Ce.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===Ce.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=Ce.STATUS_CANCELED,this._failed("local",null,L.causes.CANCELED);break;case Ce.STATUS_WAITING_FOR_ANSWER:case Ce.STATUS_ANSWERED:if(r=r||480,r<300||r>=700)throw new TypeError(`Invalid status_code: ${r}`);this._request.reply(r,d,a,o),this._failed("local",null,L.causes.REJECTED);break;case Ce.STATUS_WAITING_FOR_ACK:case Ce.STATUS_CONFIRMED:if(d=t.reason_phrase||L.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);if(r&&a.push(`Reason: SIP ;cause=${r}; text="${d}"`),this._status===Ce.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==jt.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:_})=>{_===L.ACK&&(this.sendRequest(L.BYE,{extraHeaders:a,body:o}),h.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===jt.C.STATUS_TERMINATED&&(this.sendRequest(L.BYE,{extraHeaders:a,body:o}),h.terminate())}),this._ended("local",null,n),this._dialog=h,this._ua.newDialog(h)}else this.sendRequest(L.BYE,{extraHeaders:a,body:o}),this._ended("local",null,n)}}sendRequest(t,n){return this._dialog.sendRequest(t,n)}authenticate(t){this.status="auth";let n=new qn("");n.method="AUTH",n.addHeader("To-Path",`msrp://${this._ua._configuration.realm}:2856;ws`),n.addHeader("From-Path",`msrp://${this.credentials.username}.${this.credentials.realm}:2856/${this.auth_id};ws`),t&&n.addHeader("Authorization",t.toString());let a=n.toString(),o=[];for(var s=0;s<a.length;s++)o.push(a.charCodeAt(s).toString(16));this._connection.send(n.toString())}onmessage(t){const n=new qn(t.data);if(this.status==="auth"&&n.code===401){const a=this.parseAuth(n.getHeader("WWW-Authenticate")),o=new Dm(this.credentials);o.authenticate({method:"AUTH",ruri:`msrp://${this._ua._configuration.realm}:2856;ws`,body:null},a,xe.createRandomToken(12)),this.authenticate(o)}this.status==="auth"&&n.code===200&&this._direction==="outgoing"?(this.my_addr.push(n.getHeader("To-Path")),this.my_addr.push(n.getHeader("Use-Path")),this.status="active",this.inviteParty(n)):this.status==="auth"&&n.code===200&&this._direction==="incoming"?(this.my_addr.push(n.getHeader("To-Path")),this.my_addr.push(n.getHeader("Use-Path")),this.status="active",this.acceptParty(n),this.emit("confirmed")):n.method==="SEND"&&(this._sendOk(n),this._sendReport(n),n.direction="incoming",this.emit("newMessage",n),this._msgHistory.push(n),this.emit("msgHistoryUpdate",this._msgHistory)),n.code===480&&this._close()}onclose(){console.log("close")}onopen(){const t=new RTCPeerConnection({iceServers:[]});t.createDataChannel(""),t.createOffer().then(t.setLocalDescription.bind(t)),t.onicecandidate=n=>{if(!n||!n.candidate||!n.candidate.candidate)return;const a=/([0-9]{1,3}(\.[0-9]{1,3}){3})/,o=n.candidate.candidate.match(a);this.my_ip=o&&o[1],t.onicecandidate=()=>{},this.authenticate(null)}}onerror(t){console.log(t)}_receiveInviteResponse(t){if(console.log("resp0000000000000",t),this._dialog&&t.status_code>=200&&t.status_code<=299)if(console.log("200000000000000"),this._dialog.id.call_id===t.call_id&&this._dialog.id.local_tag===t.from_tag&&this._dialog.id.remote_tag===t.to_tag){this.sendRequest(L.ACK);return}else{const n=new ca(this,t,"UAC");if(n.error!==void 0){console.log(n.error);return}this.sendRequest(L.ACK),this.sendRequest(L.BYE);return}if(this._is_canceled){t.status_code>=100&&t.status_code<200?this._request.cancel(this._cancel_reason):t.status_code>=200&&t.status_code<299&&this._acceptAndTerminate(t);return}if(!(this._status!==Ce.STATUS_INVITE_SENT&&this._status!==Ce.STATUS_1XX_RECEIVED))switch(console.log("start Switch"),!0){case/^100$/.test(t.status_code):this._status=Ce.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(t.status_code):{if(!t.to_tag){console.log("1xx response received without to tag");break}if(t.hasHeader("contact")&&!this._createDialog(t,"UAC",!0))break;if(this._status=Ce.STATUS_1XX_RECEIVED,!t.body){this._progress("remote",t);break}const n={originator:"remote",type:"answer",sdp:t.body};console.log('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>this._progress("remote",t)).catch(o=>{console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)});break}case/^2[0-9]{2}$/.test(t.status_code):{if(console.log("maybe here???"),this._status=Ce.STATUS_CONFIRMED,!t.body){this._acceptAndTerminate(t,400,L.causes.MISSING_SDP),console.log("failed 3"),this._failed("remote",t,L.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(t,"UAC"))break;const n={originator:"remote",type:"answer",sdp:t.body};console.log('emit "sdp"'),this.emit("sdp",n),new RTCSessionDescription({type:"answer",sdp:n.sdp}),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._connection.signalingState==="stable")return this._connection.createOffer(this._rtcOfferConstraints).then(a=>this._connection.setLocalDescription(a)).catch(a=>{this._acceptAndTerminate(t,500,a.toString()),console.log("failed 4"),this._failed("local",t,L.causes.WEBRTC_ERROR)})}).then(()=>{this._handleSessionTimersInIncomingResponse(t),this._accepted("remote",t),this.sendRequest(L.ACK),this._confirmed("local",null)});break}default:{const n=xe.sipErrorCause(t.status_code);console.log("failed 5"),this._failed("remote",t,n)}}}sendMSRP(t){const n=new qn("");n.method="SEND",n.addHeader("To-Path",`${this.my_addr[1]} ${this.target_addr[1]} ${this.target_addr[0]}`),n.addHeader("From-Path",`${this.my_addr[0]}`),n.addHeader("Message-ID",xe.createRandomToken(10)),n.addHeader("Byte-Range","1-25/25"),n.addHeader("Content-Type","text/plain"),n.addHeader("Success-Report","yes"),n.addHeader("Failure-Report","yes"),n.body=t;let a=n.toString();console.log(a);let o=[];for(var s=0;s<a.length;s++)o.push(a.charCodeAt(s).toString(16));console.log(o),this._connection.send(n.toString()),n.direction="outgoing",this.emit("newMessage",n),this._msgHistory.push(n),this.emit("msgHistoryUpdate",this._msgHistory)}_sendOk(t){let n=t.ident,a=t.getHeader("Message-ID"),o=new qn("");o.method="200 OK",o.addHeader("To-Path",`${this.my_addr[1]}`),o.addHeader("From-Path",`${this.my_addr[0]}`),o.addHeader("Message-ID",a),o.ident=n;let s=o.toString();console.log(s);let r=[];for(var d=0;d<s.length;d++)r.push(s.charCodeAt(d).toString(16));console.log(r),this._connection.send(o.toString())}_sendReport(t){let n=t.ident,a=t.getHeader("Message-ID"),o=new qn("");o.method="REPORT",o.addHeader("To-Path",`${t.getHeader("From-Path")}`),o.addHeader("From-Path",`${this.my_addr[0]}`),o.addHeader("Message-ID",a),o.addHeader("Byte-Range","1-25/25"),o.addHeader("Status","000 200 OK"),o.ident=n;let s=o.toString();console.log(s);let r=[];for(var d=0;d<s.length;d++)r.push(s.charCodeAt(d).toString(16));console.log(r),this._connection.send(o.toString())}parseAuth(t){const n={},a=t.replace("Digest","").split(",");for(const o of a){const s=o.trim().split("=");n[s[0]]=s[1].match('^"(.+)"$')[1]}return n}init_incoming(t,n){let a;const o=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;if(t.body&&o!=="application/sdp"){t.reply(415);return}if(this._status=Ce.STATUS_INVITE_RECEIVED,this._from_tag=t.from_tag,this._id=t.call_id+this._from_tag,this._request=t,this._contact=this._ua.contact.toString(),t.hasHeader("expires")&&(a=t.getHeader("expires")*1e3),t.to_tag=xe.newTag(),!this._createDialog(t,"UAS",!0)){t.reply(500,"Missing Contact header field");return}t.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Ce.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{t.reply(408),console.log("failed 6"),this._failed("local",null,L.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),a&&(this._timers.expiresTimer=setTimeout(()=>{this._status===Ce.STATUS_WAITING_FOR_ANSWER&&(t.reply(487),console.log("failed 7"),this._failed("system",null,L.causes.EXPIRES))},a)),this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from,n&&n(this),t.parseSDP(!0),this.target_addr=t.sdp.media[0].invalid[1].value.replaceAll("path:","").split(" ").reverse(),this._newMSRPSession("remote",t),this._status!==Ce.STATUS_TERMINATED&&(t.reply(180,null,[`Contact: ${this._ua._contact}`]),this._progress("local",null))}_failed(t,n,a){this.emit("_failed",{originator:t,message:n||null,cause:a}),this._close(),this.emit("failed",{originator:t,message:n||null,cause:a})}_close(){if(console.log("CLOSE SESSION"),this._status!==Ce.STATUS_TERMINATED){if(this._status=Ce.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(t){console.log("close() | error closing the RTCPeerConnection: %o",t)}for(const t in this._timers)Object.prototype.hasOwnProperty.call(this._timers,t)&&clearTimeout(this._timers[t]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const t in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(const t in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,t)&&delete this._referSubscribers[t];this._ua.destroyMSRPSession(this)}}_createDialog(t,n,a){const o=n==="UAS"?t.to_tag:t.from_tag,s=n==="UAS"?t.from_tag:t.to_tag,r=t.call_id+o+s;let d=this._earlyDialogs[r];if(a)return d?!0:(d=new ca(this,t,n,ca.C.STATUS_EARLY),d.error?(console.log("failed 8"),this._failed("remote",t,L.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=d,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,d)return d.update(t,n),this._dialog=d,delete this._earlyDialogs[r],!0;const h=new ca(this,t,n);return h.error?(console.log("failed 9"),this._failed("remote",t,L.causes.INTERNAL_ERROR),!1):(this._dialog=h,!0)}}_newMSRPSession(t,n){this._ua.newMSRPSession(this,{originator:t,session:this,request:n})}_progress(t,n){this.emit("progress",{originator:t,response:n||null})}isEnded(){switch(this._status){case Ce.STATUS_CANCELED:case Ce.STATUS_TERMINATED:return!0;default:return!1}}_accepted(t,n){console.log("session accepted"),this._start_time=new Date,console.log('emit "accepted"'),this.emit("accepted",{originator:t,response:n||null})}_confirmed(t,n){console.log("session confirmed"),this._is_confirmed=!0,console.log('emit "confirmed"'),this.emit("confirmed",{originator:t,ack:n||null})}_ended(t,n,a){console.log("session ended"),this._end_time=new Date,this._close(),console.log('emit "ended"'),this.emit("ended",{originator:t,message:n||null,cause:a})}_handleSessionTimersInIncomingResponse(t){if(!this._sessionTimers.enabled)return;let n;t.session_expires&&t.session_expires>=L.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,n=t.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uac"),this._sessionTimers.refresher=n==="uac",this._runSessionTimer()}receiveRequest(t){if(console.log("receiveRequest()"),t.method===L.CANCEL)(this._status===Ce.STATUS_WAITING_FOR_ANSWER||this._status===Ce.STATUS_ANSWERED)&&(this._status=Ce.STATUS_CANCELED,this._request.reply(487),console.log("failed 10"),this._failed("remote",t,L.causes.CANCELED));else switch(t.method){case L.ACK:if(this._status!==Ce.STATUS_WAITING_FOR_ACK)return;if(this._status=Ce.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!t.body){this.terminate({cause:L.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:t.body};console.log('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>{this._is_confirmed||this._confirmed("remote",t)}).catch(o=>{this.terminate({cause:L.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})}else this._is_confirmed||this._confirmed("remote",t);break;case L.BYE:this._status===Ce.STATUS_CONFIRMED||this._status===Ce.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,L.causes.BYE)):this._status===Ce.STATUS_INVITE_RECEIVED||this._status===Ce.STATUS_WAITING_FOR_ANSWER?(t.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",t,L.causes.BYE)):t.reply(403,"Wrong Status");break;case L.INVITE:this._status===Ce.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case L.INFO:this._status===Ce.STATUS_1XX_RECEIVED||this._status===Ce.STATUS_WAITING_FOR_ANSWER||this._status===Ce.STATUS_ANSWERED||this._status===Ce.STATUS_WAITING_FOR_ACK||this._status===Ce.STATUS_CONFIRMED?(t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0)!==void 0?new nu(this).init_incoming(t):t.reply(415):t.reply(403,"Wrong Status");break;case L.UPDATE:this._status===Ce.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case L.REFER:this._status===Ce.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case L.NOTIFY:this._status===Ce.STATUS_CONFIRMED?this._receiveNotify(t):t.reply(403,"Wrong Status");break;default:t.reply(501)}}onTransportError(){console.log("onTransportError()"),this._status!==Ce.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.CONNECTION_ERROR,cause:L.causes.CONNECTION_ERROR})}onRequestTimeout(){console.log("onRequestTimeout()"),this._status!==Ce.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:L.causes.REQUEST_TIMEOUT,cause:L.causes.REQUEST_TIMEOUT})}onDialogError(){console.log("onDialogError()"),this._status!==Ce.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.DIALOG_ERROR,cause:L.causes.DIALOG_ERROR})}}var vT=Jt();const yu=Me(vT),ya=new ra("Parser"),ET=(c,t)=>{let n,a,o=c.indexOf(`\r
|
156
|
+
`),this._newMSRPSession("local",this._request),this._id=this._request.call_id+this._from_tag,new Kr(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout(),console.log("to")},onTransportError:s=>{this.onTransportError(),console.log(s)},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s),s.status_code===200&&(s.parseSDP(!0),this._status=Ae.STATUS_CONFIRMED,this.target_addr=s.sdp.media[0].invalid[1].value.replaceAll("path:","").split(" ").reverse(),this.status="active",this.emit("active"),this.emit("confirmed"))}}).send(),this._status=Ae.STATUS_INVITE_SENT}terminate(t={}){const n=t.cause||L.causes.BYE,a=xe.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,d=t.reason_phrase;if(this._status===Ae.STATUS_TERMINATED)throw new Ns.InvalidStateError(this._status);switch(this.status="terminated",this._status){case Ae.STATUS_NULL:case Ae.STATUS_INVITE_SENT:case Ae.STATUS_1XX_RECEIVED:if(r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);r&&(d=d||L.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${d}"`),this._status===Ae.STATUS_NULL||this._status===Ae.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===Ae.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=Ae.STATUS_CANCELED,this._failed("local",null,L.causes.CANCELED);break;case Ae.STATUS_WAITING_FOR_ANSWER:case Ae.STATUS_ANSWERED:if(r=r||480,r<300||r>=700)throw new TypeError(`Invalid status_code: ${r}`);this._request.reply(r,d,a,o),this._failed("local",null,L.causes.REJECTED);break;case Ae.STATUS_WAITING_FOR_ACK:case Ae.STATUS_CONFIRMED:if(d=t.reason_phrase||L.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);if(r&&a.push(`Reason: SIP ;cause=${r}; text="${d}"`),this._status===Ae.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==jt.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:_})=>{_===L.ACK&&(this.sendRequest(L.BYE,{extraHeaders:a,body:o}),h.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===jt.C.STATUS_TERMINATED&&(this.sendRequest(L.BYE,{extraHeaders:a,body:o}),h.terminate())}),this._ended("local",null,n),this._dialog=h,this._ua.newDialog(h)}else this.sendRequest(L.BYE,{extraHeaders:a,body:o}),this._ended("local",null,n)}}sendRequest(t,n){return this._dialog.sendRequest(t,n)}authenticate(t){this.status="auth";let n=new qn("");n.method="AUTH",n.addHeader("To-Path",`msrp://${this._ua._configuration.realm}:2856;ws`),n.addHeader("From-Path",`msrp://${this.credentials.username}.${this.credentials.realm}:2856/${this.auth_id};ws`),t&&n.addHeader("Authorization",t.toString());let a=n.toString(),o=[];for(var s=0;s<a.length;s++)o.push(a.charCodeAt(s).toString(16));this._connection.send(n.toString())}onmessage(t){const n=new qn(t.data);if(this.status==="auth"&&n.code===401){const a=this.parseAuth(n.getHeader("WWW-Authenticate")),o=new Dm(this.credentials);o.authenticate({method:"AUTH",ruri:`msrp://${this._ua._configuration.realm}:2856;ws`,body:null},a,xe.createRandomToken(12)),this.authenticate(o)}this.status==="auth"&&n.code===200&&this._direction==="outgoing"?(this.my_addr.push(n.getHeader("To-Path")),this.my_addr.push(n.getHeader("Use-Path")),this.status="active",this.inviteParty(n)):this.status==="auth"&&n.code===200&&this._direction==="incoming"?(this.my_addr.push(n.getHeader("To-Path")),this.my_addr.push(n.getHeader("Use-Path")),this.status="active",this.acceptParty(n),this.emit("confirmed")):n.method==="SEND"&&(this._sendOk(n),this._sendReport(n),n.direction="incoming",this.emit("newMessage",n),this._msgHistory.push(n),this.emit("msgHistoryUpdate",this._msgHistory)),n.code===480&&this._close()}onclose(){console.log("close")}onopen(){const t=new RTCPeerConnection({iceServers:[]});t.createDataChannel(""),t.createOffer().then(t.setLocalDescription.bind(t)),t.onicecandidate=n=>{if(!n||!n.candidate||!n.candidate.candidate)return;const a=/([0-9]{1,3}(\.[0-9]{1,3}){3})/,o=n.candidate.candidate.match(a);this.my_ip=o&&o[1],t.onicecandidate=()=>{},this.authenticate(null)}}onerror(t){console.log(t)}_receiveInviteResponse(t){if(console.log("resp0000000000000",t),this._dialog&&t.status_code>=200&&t.status_code<=299)if(console.log("200000000000000"),this._dialog.id.call_id===t.call_id&&this._dialog.id.local_tag===t.from_tag&&this._dialog.id.remote_tag===t.to_tag){this.sendRequest(L.ACK);return}else{const n=new ca(this,t,"UAC");if(n.error!==void 0){console.log(n.error);return}this.sendRequest(L.ACK),this.sendRequest(L.BYE);return}if(this._is_canceled){t.status_code>=100&&t.status_code<200?this._request.cancel(this._cancel_reason):t.status_code>=200&&t.status_code<299&&this._acceptAndTerminate(t);return}if(!(this._status!==Ae.STATUS_INVITE_SENT&&this._status!==Ae.STATUS_1XX_RECEIVED))switch(console.log("start Switch"),!0){case/^100$/.test(t.status_code):this._status=Ae.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(t.status_code):{if(!t.to_tag){console.log("1xx response received without to tag");break}if(t.hasHeader("contact")&&!this._createDialog(t,"UAC",!0))break;if(this._status=Ae.STATUS_1XX_RECEIVED,!t.body){this._progress("remote",t);break}const n={originator:"remote",type:"answer",sdp:t.body};console.log('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>this._progress("remote",t)).catch(o=>{console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)});break}case/^2[0-9]{2}$/.test(t.status_code):{if(console.log("maybe here???"),this._status=Ae.STATUS_CONFIRMED,!t.body){this._acceptAndTerminate(t,400,L.causes.MISSING_SDP),console.log("failed 3"),this._failed("remote",t,L.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(t,"UAC"))break;const n={originator:"remote",type:"answer",sdp:t.body};console.log('emit "sdp"'),this.emit("sdp",n),new RTCSessionDescription({type:"answer",sdp:n.sdp}),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._connection.signalingState==="stable")return this._connection.createOffer(this._rtcOfferConstraints).then(a=>this._connection.setLocalDescription(a)).catch(a=>{this._acceptAndTerminate(t,500,a.toString()),console.log("failed 4"),this._failed("local",t,L.causes.WEBRTC_ERROR)})}).then(()=>{this._handleSessionTimersInIncomingResponse(t),this._accepted("remote",t),this.sendRequest(L.ACK),this._confirmed("local",null)});break}default:{const n=xe.sipErrorCause(t.status_code);console.log("failed 5"),this._failed("remote",t,n)}}}sendMSRP(t){const n=new qn("");n.method="SEND",n.addHeader("To-Path",`${this.my_addr[1]} ${this.target_addr[1]} ${this.target_addr[0]}`),n.addHeader("From-Path",`${this.my_addr[0]}`),n.addHeader("Message-ID",xe.createRandomToken(10)),n.addHeader("Byte-Range","1-25/25"),n.addHeader("Content-Type","text/plain"),n.addHeader("Success-Report","yes"),n.addHeader("Failure-Report","yes"),n.body=t;let a=n.toString();console.log(a);let o=[];for(var s=0;s<a.length;s++)o.push(a.charCodeAt(s).toString(16));console.log(o),this._connection.send(n.toString()),n.direction="outgoing",this.emit("newMessage",n),this._msgHistory.push(n),this.emit("msgHistoryUpdate",this._msgHistory)}_sendOk(t){let n=t.ident,a=t.getHeader("Message-ID"),o=new qn("");o.method="200 OK",o.addHeader("To-Path",`${this.my_addr[1]}`),o.addHeader("From-Path",`${this.my_addr[0]}`),o.addHeader("Message-ID",a),o.ident=n;let s=o.toString();console.log(s);let r=[];for(var d=0;d<s.length;d++)r.push(s.charCodeAt(d).toString(16));console.log(r),this._connection.send(o.toString())}_sendReport(t){let n=t.ident,a=t.getHeader("Message-ID"),o=new qn("");o.method="REPORT",o.addHeader("To-Path",`${t.getHeader("From-Path")}`),o.addHeader("From-Path",`${this.my_addr[0]}`),o.addHeader("Message-ID",a),o.addHeader("Byte-Range","1-25/25"),o.addHeader("Status","000 200 OK"),o.ident=n;let s=o.toString();console.log(s);let r=[];for(var d=0;d<s.length;d++)r.push(s.charCodeAt(d).toString(16));console.log(r),this._connection.send(o.toString())}parseAuth(t){const n={},a=t.replace("Digest","").split(",");for(const o of a){const s=o.trim().split("=");n[s[0]]=s[1].match('^"(.+)"$')[1]}return n}init_incoming(t,n){let a;const o=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;if(t.body&&o!=="application/sdp"){t.reply(415);return}if(this._status=Ae.STATUS_INVITE_RECEIVED,this._from_tag=t.from_tag,this._id=t.call_id+this._from_tag,this._request=t,this._contact=this._ua.contact.toString(),t.hasHeader("expires")&&(a=t.getHeader("expires")*1e3),t.to_tag=xe.newTag(),!this._createDialog(t,"UAS",!0)){t.reply(500,"Missing Contact header field");return}t.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Ae.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{t.reply(408),console.log("failed 6"),this._failed("local",null,L.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),a&&(this._timers.expiresTimer=setTimeout(()=>{this._status===Ae.STATUS_WAITING_FOR_ANSWER&&(t.reply(487),console.log("failed 7"),this._failed("system",null,L.causes.EXPIRES))},a)),this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from,n&&n(this),t.parseSDP(!0),this.target_addr=t.sdp.media[0].invalid[1].value.replaceAll("path:","").split(" ").reverse(),this._newMSRPSession("remote",t),this._status!==Ae.STATUS_TERMINATED&&(t.reply(180,null,[`Contact: ${this._ua._contact}`]),this._progress("local",null))}_failed(t,n,a){this.emit("_failed",{originator:t,message:n||null,cause:a}),this._close(),this.emit("failed",{originator:t,message:n||null,cause:a})}_close(){if(console.log("CLOSE SESSION"),this._status!==Ae.STATUS_TERMINATED){if(this._status=Ae.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(t){console.log("close() | error closing the RTCPeerConnection: %o",t)}for(const t in this._timers)Object.prototype.hasOwnProperty.call(this._timers,t)&&clearTimeout(this._timers[t]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const t in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(const t in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,t)&&delete this._referSubscribers[t];this._ua.destroyMSRPSession(this)}}_createDialog(t,n,a){const o=n==="UAS"?t.to_tag:t.from_tag,s=n==="UAS"?t.from_tag:t.to_tag,r=t.call_id+o+s;let d=this._earlyDialogs[r];if(a)return d?!0:(d=new ca(this,t,n,ca.C.STATUS_EARLY),d.error?(console.log("failed 8"),this._failed("remote",t,L.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=d,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,d)return d.update(t,n),this._dialog=d,delete this._earlyDialogs[r],!0;const h=new ca(this,t,n);return h.error?(console.log("failed 9"),this._failed("remote",t,L.causes.INTERNAL_ERROR),!1):(this._dialog=h,!0)}}_newMSRPSession(t,n){this._ua.newMSRPSession(this,{originator:t,session:this,request:n})}_progress(t,n){this.emit("progress",{originator:t,response:n||null})}isEnded(){switch(this._status){case Ae.STATUS_CANCELED:case Ae.STATUS_TERMINATED:return!0;default:return!1}}_accepted(t,n){console.log("session accepted"),this._start_time=new Date,console.log('emit "accepted"'),this.emit("accepted",{originator:t,response:n||null})}_confirmed(t,n){console.log("session confirmed"),this._is_confirmed=!0,console.log('emit "confirmed"'),this.emit("confirmed",{originator:t,ack:n||null})}_ended(t,n,a){console.log("session ended"),this._end_time=new Date,this._close(),console.log('emit "ended"'),this.emit("ended",{originator:t,message:n||null,cause:a})}_handleSessionTimersInIncomingResponse(t){if(!this._sessionTimers.enabled)return;let n;t.session_expires&&t.session_expires>=L.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,n=t.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uac"),this._sessionTimers.refresher=n==="uac",this._runSessionTimer()}receiveRequest(t){if(console.log("receiveRequest()"),t.method===L.CANCEL)(this._status===Ae.STATUS_WAITING_FOR_ANSWER||this._status===Ae.STATUS_ANSWERED)&&(this._status=Ae.STATUS_CANCELED,this._request.reply(487),console.log("failed 10"),this._failed("remote",t,L.causes.CANCELED));else switch(t.method){case L.ACK:if(this._status!==Ae.STATUS_WAITING_FOR_ACK)return;if(this._status=Ae.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!t.body){this.terminate({cause:L.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:t.body};console.log('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>{this._is_confirmed||this._confirmed("remote",t)}).catch(o=>{this.terminate({cause:L.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})}else this._is_confirmed||this._confirmed("remote",t);break;case L.BYE:this._status===Ae.STATUS_CONFIRMED||this._status===Ae.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,L.causes.BYE)):this._status===Ae.STATUS_INVITE_RECEIVED||this._status===Ae.STATUS_WAITING_FOR_ANSWER?(t.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",t,L.causes.BYE)):t.reply(403,"Wrong Status");break;case L.INVITE:this._status===Ae.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case L.INFO:this._status===Ae.STATUS_1XX_RECEIVED||this._status===Ae.STATUS_WAITING_FOR_ANSWER||this._status===Ae.STATUS_ANSWERED||this._status===Ae.STATUS_WAITING_FOR_ACK||this._status===Ae.STATUS_CONFIRMED?(t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0)!==void 0?new nu(this).init_incoming(t):t.reply(415):t.reply(403,"Wrong Status");break;case L.UPDATE:this._status===Ae.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case L.REFER:this._status===Ae.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case L.NOTIFY:this._status===Ae.STATUS_CONFIRMED?this._receiveNotify(t):t.reply(403,"Wrong Status");break;default:t.reply(501)}}onTransportError(){console.log("onTransportError()"),this._status!==Ae.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.CONNECTION_ERROR,cause:L.causes.CONNECTION_ERROR})}onRequestTimeout(){console.log("onRequestTimeout()"),this._status!==Ae.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:L.causes.REQUEST_TIMEOUT,cause:L.causes.REQUEST_TIMEOUT})}onDialogError(){console.log("onDialogError()"),this._status!==Ae.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.DIALOG_ERROR,cause:L.causes.DIALOG_ERROR})}}var vT=Jt();const yu=Me(vT),ya=new ra("Parser"),ET=(c,t)=>{let n,a,o=c.indexOf(`\r
|
157
157
|
`);if(o===-1){ya.warn("parseMessage() | no CRLF found, not a SIP message");return}const s=c.substring(0,o);let r=yu.parse(s,"Request_Response");if(r===-1){ya.warn(`parseMessage() | error parsing first line of SIP message: "${s}"`);return}else r.status_code?(n=new $n.IncomingResponse,n.status_code=r.status_code,n.reason_phrase=r.reason_phrase):(n=new $n.IncomingRequest(t),n.method=r.method,n.ruri=r.uri);n.data=c;let d=o+2;for(;;){if(o=ST(c,d),o===-2){a=d+2;break}else if(o===-1){ya.warn("parseMessage() | malformed message");return}if(r=yT(n,c,d,o),r!==!0){ya.warn("parseMessage() |",r.error);return}d=o+2}if(n.hasHeader("content-length")){const h=n.getHeader("content-length");n.body=c.substr(a,h)}else n.body=c.substring(a);return n};function ST(c,t){let n=t,a=0,o=0;if(c.substring(n,n+2).match(/(^\r\n)/))return-2;for(;a===0;){if(o=c.indexOf(`\r
|
158
|
-
`,n),o===-1)return o;!c.substring(o+2,o+4).match(/(^\r\n)/)&&c.charAt(o+2).match(/(^\s+)/)?n=o+2:a=o}return a}function yT(c,t,n,a){let o;const s=t.indexOf(":",n),r=t.substring(n,s).trim(),d=t.substring(s+1,a).trim();switch(r.toLowerCase()){case"via":case"v":c.addHeader("via",d),c.getHeaders("via").length===1?(o=c.parseHeader("Via"),o&&(c.via=o,c.via_branch=o.branch)):o=0;break;case"from":case"f":c.setHeader("from",d),o=c.parseHeader("from"),o&&(c.from=o,c.from_tag=o.getParam("tag"));break;case"to":case"t":c.setHeader("to",d),o=c.parseHeader("to"),o&&(c.to=o,c.to_tag=o.getParam("tag"));break;case"record-route":if(o=yu.parse(d,"Record_Route"),o===-1)o=void 0;else for(const h of o)c.addHeader("record-route",d.substring(h.possition,h.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=h.parsed;break;case"call-id":case"i":c.setHeader("call-id",d),o=c.parseHeader("call-id"),o&&(c.call_id=d);break;case"contact":case"m":if(o=yu.parse(d,"Contact"),o===-1)o=void 0;else for(const h of o)c.addHeader("contact",d.substring(h.possition,h.offset)),c.headers.Contact[c.getHeaders("contact").length-1].parsed=h.parsed;break;case"content-length":case"l":c.setHeader("content-length",d),o=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",d),o=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",d),o=c.parseHeader("cseq"),o&&(c.cseq=o.value),c instanceof $n.IncomingResponse&&(c.method=o.method);break;case"max-forwards":c.setHeader("max-forwards",d),o=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",d),o=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",d),o=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",d),o=c.parseHeader("session-expires"),o&&(c.session_expires=o.expires,c.session_expires_refresher=o.refresher);break;case"refer-to":case"r":c.setHeader("refer-to",d),o=c.parseHeader("refer-to"),o&&(c.refer_to=o);break;case"replaces":c.setHeader("replaces",d),o=c.parseHeader("replaces"),o&&(c.replaces=o);break;case"event":case"o":c.setHeader("event",d),o=c.parseHeader("event"),o&&(c.event=o);break;default:c.addHeader(r,d),o=0}return o===void 0?{error:`error parsing header "${r}"`}:!0}const AT={parseMessage:ET},ni=new ra("Registrator"),Aa=10;class CT{constructor(t,n){this._reg_id=1,this._ua=t,this._transport=n,this._registrar=t.configuration.registrar_server,this._expires=t.configuration.register_expires,this._call_id=vs.createRandomToken(22),this._cseq=0,this._to_uri=t.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString();const a=this._contact.indexOf(">");if(a!==-1){const o=this._contact.slice(0,a)+this._contact.slice(a+1,this._contact.length);this._contact=o}this._extra_contact="",this._extraContactParams="",this._extra_contact+=";+sip.ice",this._extraHeaders=[],this._sipInstance=`"<urn:uuid:${this._ua.configuration.instance_id}>"`,this._extra_contact+=`;reg-id=${this._reg_id}`,this._extra_contact+=`;+sip.instance=${this._sipInstance}`}get registered(){return this._registered}setExtraHeaders(t){Array.isArray(t)||(t=[]),this._extraHeaders=t.slice()}setExtraContactParams(t){t instanceof Object||(t={}),this._extraContactParams="";for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)){const a=t[n];this._extraContactParams+=`;${n}`,a&&(this._extraContactParams+=`=${a}`)}}setExtraContactUriParams(t){t instanceof Object||(t={}),this._extraContactParams="";for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)){const a=t[n];this._extraContactParams+=`;${n}`,a&&(this._extraContactParams+=`=${a}`)}}register(){if(this._registering){ni.debug("Register request in progress...");return}const t=this._extraHeaders.slice();t.push(`Contact: ${this._contact}${this._extraContactParams}>${this._extra_contact};expires=${this._expires}`),t.push(`Expires: ${this._expires}`);const n=new Tt.OutgoingRequest(L.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),a=new Kr(this._ua,n,{onRequestTimeout:()=>{this._registrationFailure(null,L.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,L.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:o=>{if(o.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):{if(this._registering=!1,!o.hasHeader("Contact")){ni.debug("no Contact header in response to REGISTER, response ignored");break}const s=o.headers.Contact.reduce((_,g)=>_.concat(g.parsed),[]);let r=s.find(_=>this._sipInstance===_.getParam("+sip.instance")&&this._reg_id===parseInt(_.getParam("reg-id")));if(r||(r=s.find(_=>_.uri.user===this._ua.contact.uri.user)),!r){ni.debug("no Contact header pointing to us, response ignored");break}let d=r.getParam("expires");!d&&o.hasHeader("expires")&&(d=o.getHeader("expires")),d||(d=this._expires),d=Number(d),d<Aa&&(d=Aa);const h=d>64?d*1e3/2+Math.floor((d/2-32)*1e3*Math.random()):d*1e3-5e3;this._registrationTimer=setTimeout(()=>{this._registrationTimer=null,this._ua.listeners("registrationExpiring").length===0?this.register():this._ua.emit("registrationExpiring")},h),r.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),this._registered||(this._registered=!0,this._ua.registered({response:o}));break}case/^423$/.test(o.status_code):{o.hasHeader("min-expires")?(this._expires=Number(o.getHeader("min-expires")),this._expires<Aa&&(this._expires=Aa),this.register()):(ni.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(o,L.causes.SIP_FAILURE_CODE));break}default:{const s=vs.sipErrorCause(o.status_code);this._registrationFailure(o,s)}}}});this._registering=!0,a.send()}unregister(t={}){if(!this._registered){ni.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const n=this._extraHeaders.slice();t.all?n.push(`Contact: *${this._extraContactParams}`):n.push(`Contact: ${this._contact}${this._extraContactParams}>${this._extra_contact};expires=0`),n.push("Expires: 0");const a=new Tt.OutgoingRequest(L.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new Kr(this._ua,a,{onRequestTimeout:()=>{this._unregistered(null,L.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,L.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:s=>{switch(!0){case/^1[0-9]{2}$/.test(s.status_code):break;case/^2[0-9]{2}$/.test(s.status_code):this._unregistered(s);break;default:{const r=vs.sipErrorCause(s.status_code);this._unregistered(s,r)}}}}).send()}close(){this._registered&&this.unregister()}onTransportClosed(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}_registrationFailure(t,n){this._registering=!1,this._ua.registrationFailed({response:t||null,cause:n}),this._registered&&(this._registered=!1,this._ua.unregistered({response:t||null,cause:n}))}_unregistered(t,n){this._registering=!1,this._registered=!1,this._ua.unregistered({response:t||null,cause:n||null})}}const et=console,ks={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},RT=fT;class IT extends RT{constructor(t){super(t),this._msrp_sessions=[],this._transactions={nist:{},nict:{},ist:{},ict:{}},this._janus_sessions=[],this.newStreamPlugins=[],this.processStreamPlugins=[],this._registrator=new CT(this)}call(t,n){return super.call(t,n)}joinVideoCall(t,n,a){et.debug("call()");const o=new Sa(this);return o.configureMedia({audio:!0,video:!0}),o.connect(t,n,a),o}startScreenShare(){et.debug("startScreenShare()");for(const t in this._janus_sessions)this._janus_sessions[t].connectScreenShare()}changeMediaConstraints(t){for(const n in this._janus_sessions)this._janus_sessions[n].changeMediaConstraints(t)}startBlur(){for(const t in this._janus_sessions)this._janus_sessions[t].connectBlur()}stopBlur(){for(const t in this._janus_sessions)this._janus_sessions[t].stopBlur()}_loadConfig(t){try{si.load(this._configuration,t)}catch(s){throw s}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=vs.newUUID());let n;typeof window<"u"&&typeof window.document<"u"?n=window==null?void 0:window.navigator.userAgent:typeof self<"u"&&self.navigator&&(n=self.navigator.userAgent),n+=" "+De.USER_AGENT,this._configuration.user_agent=t.overrideUserAgent&&typeof t.overrideUserAgent=="function"?t.overrideUserAgent(n):n,this._configuration.jssip_id=vs.createRandomToken(5);const a=this._configuration.uri.clone();a.user=null,this._configuration.hostport_params=a.toString().replace(/^sip:/i,"");try{this._transport=new Lg(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=bT.bind(this),this._transport.onconnect=wT.bind(this),this._transport.ondisconnect=OT.bind(this),this._transport.ondata=DT.bind(this)}catch(s){throw et.warn(s),new Ns.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){const s=this._configuration.uri.clone();s.user=null,s.clearParams(),s.clearHeaders(),this._configuration.registrar_server=s}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new ln("sip",vs.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(s={}){const r=s.anonymous||null,d=s.outbound||null;let h="<";return r?h+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":h+=this.pub_gruu||this.uri.toString(),d&&(r?!this.temp_gruu:!this.pub_gruu)&&(h+=";ob"),h+=">",h}};const o=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const s in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,s)&&(o.indexOf(s)!==-1?Object.defineProperty(this._configuration,s,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,s,{writable:!1,configurable:!1}));et.debug("configuration parameters after validation:");for(const s in this._configuration)if(Object.prototype.hasOwnProperty.call(si.settings,s))switch(s){case"uri":case"registrar_server":et.debug(`- ${s}: ${this._configuration[s]}`);break;case"password":case"ha1":case"authorization_jwt":et.debug(`- ${s}: NOT SHOWN`);break;default:et.debug(`- ${s}: ${JSON.stringify(this._configuration[s])}`)}}newMSRPSession(t,n){t.on("msgHistoryUpdate",a=>{console.log(a)}),this._msrp_sessions[t.id]=t,this.emit("newMSRPSession",n)}newJanusSession(t,n){this._janus_sessions[t.id]=t,this.newStreamPlugins.forEach(a=>{a.setSession(t)}),this.processStreamPlugins.forEach(a=>{a.setSession(t)}),this.emit("newJanusSession",n)}kill(){}destroyMSRPSession(t){delete this._msrp_sessions[t.id]}destroyJanusSession(t){delete this._janus_sessions[t.id]}receiveRequest(t){var s,r,d,h;const n=t.method;if(t.ruri.user!==this._configuration.uri.user&&t.ruri.user!==this._contact.uri.user){et.debug("Request-URI does not point to us"),t.method!==De.ACK&&t.reply_sl(404);return}if(t.ruri.scheme===De.SIPS){t.reply_sl(416);return}if(jt.checkTransaction(this,t))return;if(n===De.INVITE?new jt.InviteServerTransaction(this,this._transport,t):n!==De.ACK&&n!==De.CANCEL&&new jt.NonInviteServerTransaction(this,this._transport,t),n===De.OPTIONS){if(this.listeners("newOptions").length===0){t.reply(200);return}new yf.Options(this).init_incoming(t)}else if(n===De.MESSAGE){if(this.listeners("newMessage").length===0){t.reply(405);return}new yf.Message(this).init_incoming(t)}else if(n===De.INVITE&&!t.to_tag&&this.listeners("newRTCSession").length===0){t.reply(405);return}let a,o;if(t.to_tag)if(a=this._findDialog(t.call_id,t.from_tag,t.to_tag),a)a.receiveRequest(t);else if(n===De.NOTIFY)if(o=this._findSession(t),o)o.receiveRequest(t);else{if(t.body)try{const _=JSON.parse(t.body)||{};(r=(s=_.plugindata)==null?void 0:s.data)!=null&&r.publishers&&Object.values(this._janus_sessions)[0].receivePublishers(_),(h=(d=_.plugindata)==null?void 0:d.data)!=null&&h.unpublished&&Object.values(this._janus_sessions)[0].receiveUnpublished(_.plugindata.data.unpublished)}catch(_){console.error(_)}t.reply(200)}else n!==De.ACK&&t.reply(481);else switch(n){case De.INVITE:if(window.RTCPeerConnection)if(t.hasHeader("replaces")){const _=t.replaces;a=this._findDialog(_.call_id,_.from_tag,_.to_tag),a?(o=a.owner,o.isEnded()?t.reply(603):o.receiveRequest(t)):t.reply(481)}else t.body.search(/MSRP/ig)>-1?(o=new Su(this),o.init_incoming(t)):t.body.search(/JANUS/ig)>-1||(o=new Sg(this),o.init_incoming(t));else et.warn("INVITE received but WebRTC is not supported"),t.reply(488);break;case De.BYE:t.reply(481);break;case De.CANCEL:o=this._findSession(t),o?o.receiveRequest(t):et.debug("received CANCEL request for a non existent session");break;case De.ACK:break;case De.NOTIFY:this.emit("sipEvent",{event:t.event,request:t}),t.reply(200);break;default:t.reply(405);break}}startMSRP(t,n){et.debug("startMSRP()",n);const a=new Su(this);return a.connect(t),a}startJanus(t,n){et.debug("startJanus()",n);const a=new Su(this);return a.connect(t),a}terminateMSRPSessions(t){et.debug("terminateSessions()");for(const n in this._msrp_sessions)this._msrp_sessions[n].isEnded()||this._msrp_sessions[n].terminate(t)}terminateJanusSessions(t){et.debug("terminateSessions()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||this._janus_sessions[n].terminate(t)}enableJanusAudio(t){et.debug("enableJanusAudio()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||(t?this._janus_sessions[n].startAudio():this._janus_sessions[n].stopAudio())}enableJanusVideo(t){et.debug("enableJanusVideo()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||(t?this._janus_sessions[n].startVideo():this._janus_sessions[n].stopVideo())}stop(){if(et.debug("stop()"),this._dynConfiguration={},this._status===ks.STATUS_USER_CLOSED){et.debug("UA already closed");return}this._registrator.close();const t=Object.keys(this._sessions).length;for(const a in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,a)){et.debug(`closing session ${a}`);try{this._sessions[a].terminate()}catch(o){console.error(o)}}for(const a in this._msrp_sessions)if(Object.prototype.hasOwnProperty.call(this._msrp_sessions,a)){et.debug(`closing session ${a}`);try{this._msrp_sessions[a].terminate()}catch(o){console.error(o)}}for(const a in this._janus_sessions)if(Object.prototype.hasOwnProperty.call(this._janus_sessions,a)){et.debug(`closing session ${a}`);try{this._janus_sessions[a].terminate()}catch(o){console.error(o)}}for(const a in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,a))try{this._applicants[a].close()}catch(o){console.error(o)}this._status=ks.STATUS_USER_CLOSED,Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length===0&&t===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}}function bT(c){this.emit("connecting",c)}function wT(c){this._status!==ks.STATUS_USER_CLOSED&&(this._status=ks.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function OT(c){const t=["nict","ict","nist","ist"];for(const n of t)for(const a in this._transactions[n])Object.prototype.hasOwnProperty.call(this._transactions[n],a)&&this._transactions[n][a].onTransportError();this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==ks.STATUS_USER_CLOSED&&(this._status=ks.STATUS_NOT_READY,this._error=ks.NETWORK_ERROR)}function DT(c){const t=c.transport;let n=c.message;if(n=AT.parseMessage(n,this),!!n&&!(this._status===ks.STATUS_USER_CLOSED&&n instanceof $n.IncomingRequest)&&Qg(n,this,t)){if(n instanceof $n.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof $n.IncomingResponse){let a;switch(n.method){case De.INVITE:a=this._transactions.ict[n.via_branch],a&&a.receiveResponse(n);break;case De.ACK:break;default:a=this._transactions.nict[n.via_branch],a&&a.receiveResponse(n);break}}}}const NT=["roomId","_audioMuted","_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","_localHold","_videoMuted","status","start_time","_remote_identity","audioTag","isOnHold","localMuted","autoAnswer","putOnHoldTimestamp"],UT=["_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","status","start_time","_remote_identity","target_addr"];function gh(c){const t={};return NT.forEach(n=>{c[n]!==void 0&&(t[n]=c[n])}),t.localHold=c._localHold,t}function Th(c){const t={};return UT.forEach(n=>{c[n]!==void 0&&(t[n]=c[n])}),t}function vh(c,t){const n=new AudioContext,a=n.createMediaStreamSource(c),o=n.createMediaStreamDestination(),s=n.createGain();return a.connect(s),s.connect(o),s.gain.value=t,o.stream}function PT(c,t,n,a){const o=document.createElement("audio");o.id=t._id,o.className="audioTag",o.srcObject=c,Eh()||(o.setSinkId(n),o.volume=a),o.play(),t.audioTag=o}function xT(c){if(c&&typeof c.log=="function"&&typeof c.warn=="function"&&typeof c.error=="function")return!0}function Eh(){return/Mobi|Android|iPhone/i.test(navigator.userAgent)}const kT=at,MT=Jt(),Ot=new kT("WebSocketInterface");var LT=class{constructor(t){Ot.debug('new() [url:"%s"]',t),this._url=t,this._sip_uri=null,this._via_transport=null,this._ws=null;const n=MT.parse(t,"absoluteURI");if(n===-1)throw Ot.warn(`invalid WebSocket URI: ${t}`),new TypeError(`Invalid argument: ${t}`);if(n.scheme!=="wss"&&n.scheme!=="ws")throw Ot.warn(`invalid WebSocket URI scheme: ${n.scheme}`),new TypeError(`Invalid argument: ${t}`);this._sip_uri=`sip:${n.host}${n.port?`:${n.port}`:""};transport=ws`,this._via_transport=n.scheme.toUpperCase()}get via_transport(){return this._via_transport}set via_transport(t){this._via_transport=t.toUpperCase()}get sip_uri(){return this._sip_uri}get url(){return this._url}connect(){if(Ot.debug("connect()"),this.isConnected()){Ot.debug(`WebSocket ${this._url} is already connected`);return}else if(this.isConnecting()){Ot.debug(`WebSocket ${this._url} is connecting`);return}this._ws&&this.disconnect(),Ot.debug(`connecting to WebSocket ${this._url}`);try{this._ws=new WebSocket(this._url,"sip"),this._ws.binaryType="arraybuffer",this._ws.onopen=this._onOpen.bind(this),this._ws.onclose=this._onClose.bind(this),this._ws.onmessage=this._onMessage.bind(this),this._ws.onerror=this._onError.bind(this)}catch(t){this._onError(t)}}disconnect(){Ot.debug("disconnect()"),this._ws&&(this._ws.onopen=()=>{},this._ws.onclose=()=>{},this._ws.onmessage=()=>{},this._ws.onerror=()=>{},this._ws.close(),this._ws=null)}send(t){return Ot.debug("send()"),this.isConnected()?(this._ws.send(t),!0):(Ot.warn("unable to send message, WebSocket is not open"),!1)}isConnected(){return this._ws&&this._ws.readyState===this._ws.OPEN}isConnecting(){return this._ws&&this._ws.readyState===this._ws.CONNECTING}_onOpen(){Ot.debug(`WebSocket ${this._url} connected`),this.onconnect()}_onClose({wasClean:t,code:n,reason:a}){Ot.debug(`WebSocket ${this._url} closed`),t===!1&&Ot.debug("WebSocket abrupt disconnection"),this.ondisconnect(!t,n,a)}_onMessage({data:t}){Ot.debug("received WebSocket message"),this.ondata(t)}_onError(t){Ot.warn(`WebSocket ${this._url} error: `,t)}};const Au=vl,$T=De,HT=Ts,FT=mt(),jT=_h,qT=ps(),VT=Vo(),BT=Jt(),GT=LT;Un("JsSIP")("version %s",Au.version);var WT={C:$T,Exceptions:HT,Utils:FT,UA:jT,URI:qT,NameAddrHeader:VT,WebSocketInterface:GT,Grammar:BT,debug:Un,get name(){return Au.title},get version(){return Au.version}};const KT=Me(WT);function Cu(c){return c<10?`0${c}`:`${c}`}function YT(c){let t=c.hours||0,n=c.minutes||0,a=c.seconds||0;a++,a===60&&(a=0,n++,n===60&&(n=0,t++));const o=`${Cu(t)}:${Cu(n)}:${Cu(a)}`;return{seconds:a,minutes:n,hours:t,formatted:o}}var yt={};yt.forEach=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)if(o in c){const s=Promise.resolve(c[o]).then(r=>t.call(n||globalThis,r,o,c));a.push(s)}await Promise.all(a)},yt.forEachSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)a in c&&await t.call(n||globalThis,await c[a],a,c)},yt.map=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)o in c&&(a[o]=Promise.resolve(c[o]).then(s=>t.call(n||globalThis,s,o,c)));return Promise.all(a)},yt.mapSeries=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)o in c&&(a[o]=await t.call(n||globalThis,await c[o],o,c));return a},yt.find=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a();let s=1;for(let r=0;r<c.length;r++){const d=h=>{h?a(c[r]):s===c.length&&a(),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}}),yt.findSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(await t.call(n||globalThis,await c[a],a,c))return c[a]},yt.findIndex=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a(-1);let s=1;for(let r=0;r<c.length;r++){const d=h=>{h?a(r):s===c.length&&a(-1),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}}),yt.findIndexSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(await t.call(n||globalThis,await c[a],a,c))return a},yt.some=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a(!1);let s=1;for(let r=0;r<c.length;r++){if(!(r in c)){s++;continue}const d=h=>{h?a(!0):s===c.length&&a(!1),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}}),yt.someSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(a in c&&await t.call(n||globalThis,await c[a],a,c))return!0;return!1},yt.every=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a(!0);let s=1;for(let r=0;r<c.length;r++){if(!(r in c)){s++;continue}const d=h=>{h?s===c.length&&a(!0):a(!1),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}}),yt.everySeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(a in c&&!await t.call(n||globalThis,await c[a],a,c))return!1;return!0},yt.filter=(c,t,n)=>new Promise(async(a,o)=>{const s=[];for(let d=0;d<c.length;d++)d in c&&(s[d]=Promise.resolve(c[d]).then(h=>t.call(n||globalThis,h,d,c)).catch(o));const r=[];for(let d=0;d<s.length;d++)await s[d]&&r.push(await c[d]);a(r)}),yt.filterSeries=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)o in c&&await t.call(n||globalThis,await c[o],o,c)&&a.push(await c[o]);return a},yt.reduce=async(c,t,n)=>{if(c.length===0&&n===void 0)throw TypeError("Reduce of empty array with no initial value");let a,o;for(n!==void 0?(o=n,a=0):(o=c[0],a=1),a;a<c.length;a++)a in c&&(o=await t(await o,await c[a],a,c));return o};var Sh={};(function(c){const t=yt;Object.keys(t).forEach(n=>{const a=n.charAt(0).toUpperCase()+n.slice(1);c[`async${a}`]=async function(...o){return t[n](this,...o)}})})(Sh);var JT=Object.assign(yt,{instanceMethods:Sh});const an=new AudioContext,Qt={NEW_CALL:"new_call",CALL_CONFIRMED:"confirmed",CALL_FAILED:"failed",CALL_PROGRESS:"progress",CALL_ENDED:"ended"};var zT={exports:{}};(function(c){var t=function(n){var a=Object.prototype,o=a.hasOwnProperty,s=Object.defineProperty||function(ee,Y,G){ee[Y]=G.value},r,d=typeof Symbol=="function"?Symbol:{},h=d.iterator||"@@iterator",_=d.asyncIterator||"@@asyncIterator",g=d.toStringTag||"@@toStringTag";function T(ee,Y,G){return Object.defineProperty(ee,Y,{value:G,enumerable:!0,configurable:!0,writable:!0}),ee[Y]}try{T({},"")}catch{T=function(Y,G,re){return Y[G]=re}}function E(ee,Y,G,re){var ge=Y&&Y.prototype instanceof oe?Y:oe,be=Object.create(ge.prototype),ke=new P(re||[]);return s(be,"_invoke",{value:J(ee,G,ke)}),be}n.wrap=E;function y(ee,Y,G){try{return{type:"normal",arg:ee.call(Y,G)}}catch(re){return{type:"throw",arg:re}}}var A="suspendedStart",C="suspendedYield",I="executing",H="completed",$={};function oe(){}function N(){}function j(){}var Se={};T(Se,h,function(){return this});var ve=Object.getPrototypeOf,k=ve&&ve(ve(se([])));k&&k!==a&&o.call(k,h)&&(Se=k);var D=j.prototype=oe.prototype=Object.create(Se);N.prototype=j,s(D,"constructor",{value:j,configurable:!0}),s(j,"constructor",{value:N,configurable:!0}),N.displayName=T(j,g,"GeneratorFunction");function B(ee){["next","throw","return"].forEach(function(Y){T(ee,Y,function(G){return this._invoke(Y,G)})})}n.isGeneratorFunction=function(ee){var Y=typeof ee=="function"&&ee.constructor;return Y?Y===N||(Y.displayName||Y.name)==="GeneratorFunction":!1},n.mark=function(ee){return Object.setPrototypeOf?Object.setPrototypeOf(ee,j):(ee.__proto__=j,T(ee,g,"GeneratorFunction")),ee.prototype=Object.create(D),ee},n.awrap=function(ee){return{__await:ee}};function V(ee,Y){function G(be,ke,Re,le){var ye=y(ee[be],ee,ke);if(ye.type==="throw")le(ye.arg);else{var lt=ye.arg,ot=lt.value;return ot&&typeof ot=="object"&&o.call(ot,"__await")?Y.resolve(ot.__await).then(function(Ee){G("next",Ee,Re,le)},function(Ee){G("throw",Ee,Re,le)}):Y.resolve(ot).then(function(Ee){lt.value=Ee,Re(lt)},function(Ee){return G("throw",Ee,Re,le)})}}var re;function ge(be,ke){function Re(){return new Y(function(le,ye){G(be,ke,le,ye)})}return re=re?re.then(Re,Re):Re()}s(this,"_invoke",{value:ge})}B(V.prototype),T(V.prototype,_,function(){return this}),n.AsyncIterator=V,n.async=function(ee,Y,G,re,ge){ge===void 0&&(ge=Promise);var be=new V(E(ee,Y,G,re),ge);return n.isGeneratorFunction(Y)?be:be.next().then(function(ke){return ke.done?ke.value:be.next()})};function J(ee,Y,G){var re=A;return function(be,ke){if(re===I)throw new Error("Generator is already running");if(re===H){if(be==="throw")throw ke;return it()}for(G.method=be,G.arg=ke;;){var Re=G.delegate;if(Re){var le=F(Re,G);if(le){if(le===$)continue;return le}}if(G.method==="next")G.sent=G._sent=G.arg;else if(G.method==="throw"){if(re===A)throw re=H,G.arg;G.dispatchException(G.arg)}else G.method==="return"&&G.abrupt("return",G.arg);re=I;var ye=y(ee,Y,G);if(ye.type==="normal"){if(re=G.done?H:C,ye.arg===$)continue;return{value:ye.arg,done:G.done}}else ye.type==="throw"&&(re=H,G.method="throw",G.arg=ye.arg)}}}function F(ee,Y){var G=Y.method,re=ee.iterator[G];if(re===r)return Y.delegate=null,G==="throw"&&ee.iterator.return&&(Y.method="return",Y.arg=r,F(ee,Y),Y.method==="throw")||G!=="return"&&(Y.method="throw",Y.arg=new TypeError("The iterator does not provide a '"+G+"' method")),$;var ge=y(re,ee.iterator,Y.arg);if(ge.type==="throw")return Y.method="throw",Y.arg=ge.arg,Y.delegate=null,$;var be=ge.arg;if(!be)return Y.method="throw",Y.arg=new TypeError("iterator result is not an object"),Y.delegate=null,$;if(be.done)Y[ee.resultName]=be.value,Y.next=ee.nextLoc,Y.method!=="return"&&(Y.method="next",Y.arg=r);else return be;return Y.delegate=null,$}B(D),T(D,g,"Generator"),T(D,h,function(){return this}),T(D,"toString",function(){return"[object Generator]"});function Z(ee){var Y={tryLoc:ee[0]};1 in ee&&(Y.catchLoc=ee[1]),2 in ee&&(Y.finallyLoc=ee[2],Y.afterLoc=ee[3]),this.tryEntries.push(Y)}function U(ee){var Y=ee.completion||{};Y.type="normal",delete Y.arg,ee.completion=Y}function P(ee){this.tryEntries=[{tryLoc:"root"}],ee.forEach(Z,this),this.reset(!0)}n.keys=function(ee){var Y=Object(ee),G=[];for(var re in Y)G.push(re);return G.reverse(),function ge(){for(;G.length;){var be=G.pop();if(be in Y)return ge.value=be,ge.done=!1,ge}return ge.done=!0,ge}};function se(ee){if(ee){var Y=ee[h];if(Y)return Y.call(ee);if(typeof ee.next=="function")return ee;if(!isNaN(ee.length)){var G=-1,re=function ge(){for(;++G<ee.length;)if(o.call(ee,G))return ge.value=ee[G],ge.done=!1,ge;return ge.value=r,ge.done=!0,ge};return re.next=re}}return{next:it}}n.values=se;function it(){return{value:r,done:!0}}return P.prototype={constructor:P,reset:function(ee){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(U),!ee)for(var Y in this)Y.charAt(0)==="t"&&o.call(this,Y)&&!isNaN(+Y.slice(1))&&(this[Y]=r)},stop:function(){this.done=!0;var ee=this.tryEntries[0],Y=ee.completion;if(Y.type==="throw")throw Y.arg;return this.rval},dispatchException:function(ee){if(this.done)throw ee;var Y=this;function G(le,ye){return be.type="throw",be.arg=ee,Y.next=le,ye&&(Y.method="next",Y.arg=r),!!ye}for(var re=this.tryEntries.length-1;re>=0;--re){var ge=this.tryEntries[re],be=ge.completion;if(ge.tryLoc==="root")return G("end");if(ge.tryLoc<=this.prev){var ke=o.call(ge,"catchLoc"),Re=o.call(ge,"finallyLoc");if(ke&&Re){if(this.prev<ge.catchLoc)return G(ge.catchLoc,!0);if(this.prev<ge.finallyLoc)return G(ge.finallyLoc)}else if(ke){if(this.prev<ge.catchLoc)return G(ge.catchLoc,!0)}else if(Re){if(this.prev<ge.finallyLoc)return G(ge.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(ee,Y){for(var G=this.tryEntries.length-1;G>=0;--G){var re=this.tryEntries[G];if(re.tryLoc<=this.prev&&o.call(re,"finallyLoc")&&this.prev<re.finallyLoc){var ge=re;break}}ge&&(ee==="break"||ee==="continue")&&ge.tryLoc<=Y&&Y<=ge.finallyLoc&&(ge=null);var be=ge?ge.completion:{};return be.type=ee,be.arg=Y,ge?(this.method="next",this.next=ge.finallyLoc,$):this.complete(be)},complete:function(ee,Y){if(ee.type==="throw")throw ee.arg;return ee.type==="break"||ee.type==="continue"?this.next=ee.arg:ee.type==="return"?(this.rval=this.arg=ee.arg,this.method="return",this.next="end"):ee.type==="normal"&&Y&&(this.next=Y),$},finish:function(ee){for(var Y=this.tryEntries.length-1;Y>=0;--Y){var G=this.tryEntries[Y];if(G.finallyLoc===ee)return this.complete(G.completion,G.afterLoc),U(G),$}},catch:function(ee){for(var Y=this.tryEntries.length-1;Y>=0;--Y){var G=this.tryEntries[Y];if(G.tryLoc===ee){var re=G.completion;if(re.type==="throw"){var ge=re.arg;U(G)}return ge}}throw new Error("illegal catch attempt")},delegateYield:function(ee,Y,G){return this.delegate={iterator:se(ee),resultName:Y,nextLoc:G},this.method==="next"&&(this.arg=r),$}},n}(c.exports);try{regeneratorRuntime=t}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}})(zT);var yh={exports:{}};(function(c){(function(t,n){c.exports?c.exports=n():t.log=n()})(Mt,function(){var t=function(){},n="undefined",a=typeof window!==n&&typeof window.navigator!==n&&/Trident\/|MSIE /.test(window.navigator.userAgent),o=["trace","debug","info","warn","error"];function s(C,I){var H=C[I];if(typeof H.bind=="function")return H.bind(C);try{return Function.prototype.bind.call(H,C)}catch{return function(){return Function.prototype.apply.apply(H,[C,arguments])}}}function r(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function d(C){return C==="debug"&&(C="log"),typeof console===n?!1:C==="trace"&&a?r:console[C]!==void 0?s(console,C):console.log!==void 0?s(console,"log"):t}function h(C,I){for(var H=0;H<o.length;H++){var $=o[H];this[$]=H<C?t:this.methodFactory($,C,I)}this.log=this.debug}function _(C,I,H){return function(){typeof console!==n&&(h.call(this,I,H),this[C].apply(this,arguments))}}function g(C,I,H){return d(C)||_.apply(this,arguments)}function T(C,I,H){var $=this,oe;I=I??"WARN";var N="loglevel";typeof C=="string"?N+=":"+C:typeof C=="symbol"&&(N=void 0);function j(D){var B=(o[D]||"silent").toUpperCase();if(!(typeof window===n||!N)){try{window.localStorage[N]=B;return}catch{}try{window.document.cookie=encodeURIComponent(N)+"="+B+";"}catch{}}}function Se(){var D;if(!(typeof window===n||!N)){try{D=window.localStorage[N]}catch{}if(typeof D===n)try{var B=window.document.cookie,V=B.indexOf(encodeURIComponent(N)+"=");V!==-1&&(D=/^([^;]+)/.exec(B.slice(V))[1])}catch{}return $.levels[D]===void 0&&(D=void 0),D}}function ve(){if(!(typeof window===n||!N)){try{window.localStorage.removeItem(N);return}catch{}try{window.document.cookie=encodeURIComponent(N)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}$.name=C,$.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},$.methodFactory=H||g,$.getLevel=function(){return oe},$.setLevel=function(D,B){if(typeof D=="string"&&$.levels[D.toUpperCase()]!==void 0&&(D=$.levels[D.toUpperCase()]),typeof D=="number"&&D>=0&&D<=$.levels.SILENT){if(oe=D,B!==!1&&j(D),h.call($,D,C),typeof console===n&&D<$.levels.SILENT)return"No console available for logging"}else throw"log.setLevel() called with invalid level: "+D},$.setDefaultLevel=function(D){I=D,Se()||$.setLevel(D,!1)},$.resetLevel=function(){$.setLevel(I,!1),ve()},$.enableAll=function(D){$.setLevel($.levels.TRACE,D)},$.disableAll=function(D){$.setLevel($.levels.SILENT,D)};var k=Se();k==null&&(k=I),$.setLevel(k,!1)}var E=new T,y={};E.getLogger=function(I){if(typeof I!="symbol"&&typeof I!="string"||I==="")throw new TypeError("You must supply a name when creating a logger.");var H=y[I];return H||(H=y[I]=new T(I,E.getLevel(),E.methodFactory)),H};var A=typeof window!==n?window.log:void 0;return E.noConflict=function(){return typeof window!==n&&window.log===E&&(window.log=A),E},E.getLoggers=function(){return y},E.default=E,E})})(yh);var It=yh.exports;const Es=()=>`${new Date().toISOString()} | metrics`,Ss=(c,t,n)=>`${c} | ${t} | ${n}`;It.setDefaultLevel(It.levels.TRACE);const XT=c=>{It.info(Ss(Es(),"log ",`set log level to ${c?"verbose":"info"}`)),It.setLevel(c?It.levels.TRACE:It.levels.INFO)},QT=c=>{const t=[...Object.keys(It.levels)];t.includes(c)?(It.info(Ss(Es(),"log ",`update log level to ${c.toLowerCase()}`)),It.setLevel(c)):It.warn(Ss(Es(),"log ","Incorrect log level please choose one of "),t)},Pe=(c,t,n)=>{n?It.debug(Ss(Es(),c,t),n):It.debug(Ss(Es(),c,t))},Ru=(c,t)=>{It.info(Ss(Es(),c,t))},on=(c,t)=>{It.info(Ss(Es(),c,t))},Ca=(c,t)=>{It.warn(Ss(Es(),c,t))},Vn=(c,t)=>{It.error(Ss(Es(),c,t))};function ZT(c){return Math.floor(Math.random()*c).toString()}function Ah(c,t){let n=t;return c.forEach(a=>{n=n.replace(a,"")}),n}function ev(c,t){let n="";for(let a=0;a<t;a+=1)n+=c[ZT(c.length)];return n}function tv({length:c=20,useLetters:t=!0,useNumbers:n=!0,includeSymbols:a=[],excludeSymbols:o=[]}={}){let s="abcdefghijklmnopqrstuvwxyz",r="0123456789",d=[],h=[],_=[];return t&&(o.length&&(s=Ah(o,s)),h=s.split("")),n&&(o.length&&(r=Ah(o,r)),_=r.split("")),d=[...h,..._,...a],ev(d,c)}var sv=tv;const ri=Me(sv),nv=()=>"WebRTCMetrics",rv=()=>"5.0.3",$e={INBOUND:"inbound",OUTBOUND:"outbound"},ys={IDLE:"idle",RUNNING:"running",MUTED:"muted"},ii={NEW:"new",CHECKING:"checking",CONNECTED:"connected",COMPLETED:"completed",DISCONNECTED:"disconnected",FAILED:"failed",CLOSED:"closed"},iv=()=>({...{delta_time_to_measure_probes_ms:0,delta_time_consumed_to_measure_ms:0,delta_KBytes_in:0,delta_KBytes_out:0,delta_kbs_in:0,delta_kbs_out:0,total_time_decoded_in:0,total_time_encoded_out:0,probes:[]}}),Ch={level_in:0,codec_id_in:"",codec_in:{mime_type:null,clock_rate:null,sdp_fmtp_line:null},delta_jitter_ms_in:0,percent_packets_lost_in:0,delta_packets_in:0,delta_packets_lost_in:0,total_packets_in:0,total_packets_lost_in:0,total_KBytes_in:0,delta_KBytes_in:0,delta_kbs_in:0,mos_in:0,mos_emodel_in:0,ssrc:"",direction:$e.INBOUND},Rh={level_out:0,codec_id_out:"",codec_out:{mime_type:null,clock_rate:null,sdp_fmtp_line:null},delta_jitter_ms_out:0,delta_rtt_ms_out:null,total_rtt_ms_out:0,total_rtt_measure_out:0,percent_packets_lost_out:0,delta_packets_out:0,delta_packets_lost_out:0,total_packets_out:0,total_packets_lost_out:0,total_KBytes_out:0,delta_KBytes_out:0,delta_kbs_out:0,timestamp_out:null,mos_out:0,mos_emodel_out:0,ssrc:"",direction:$e.OUTBOUND},Ih={codec_id_in:"",size_in:{width:null,height:null,framerate:null},codec_in:{mime_type:null,clock_rate:null},delta_jitter_ms_in:0,percent_packets_lost_in:0,delta_packets_in:0,delta_packets_lost_in:0,total_packets_in:0,total_packets_lost_in:0,total_KBytes_in:0,delta_KBytes_in:0,delta_kbs_in:0,decoder_in:null,delta_ms_decode_frame_in:0,total_frames_decoded_in:0,total_time_decoded_in:0,delta_nack_sent_in:0,delta_pli_sent_in:0,total_nack_sent_in:0,total_pli_sent_in:0,ssrc:"",direction:$e.INBOUND},bh={codec_id_out:"",size_out:{width:null,height:null,framerate:null},codec_out:{mime_type:null,clock_rate:null},delta_jitter_ms_out:0,delta_rtt_ms_out:null,total_rtt_ms_out:0,total_rtt_measure_out:0,percent_packets_lost_out:0,delta_packets_out:0,delta_packets_lost_out:0,total_packets_out:0,total_packets_lost_out:0,total_KBytes_out:0,delta_KBytes_out:0,delta_kbs_out:0,encoder_out:null,delta_ms_encode_frame_out:0,total_time_encoded_out:0,total_frames_encoded_out:0,delta_nack_received_out:0,delta_pli_received_out:0,total_nack_received_out:0,total_pli_received_out:0,limitation_out:{reason:null,durations:null,resolutionChanges:0},timestamp_out:null,ssrc:"",direction:$e.OUTBOUND},lv=c=>{const t={pname:"",call_id:"",user_id:"",timestamp:null,count:0,audio:{},video:{},network:{infrastructure:3,local_candidate_id:"",local_candidate_type:"",local_candidate_protocol:"",local_candidate_relay_protocol:"",remote_candidate_id:"",remote_candidate_type:"",remote_candidate_protocol:""},data:{total_KBytes_in:0,total_KBytes_out:0,delta_KBytes_in:0,delta_KBytes_out:0,delta_kbs_in:0,delta_kbs_out:0,delta_kbs_bandwidth_in:0,delta_kbs_bandwidth_out:0,delta_rtt_connectivity_ms:null,total_rtt_connectivity_ms:0,total_rtt_connectivity_measure:0},experimental:{time_to_measure_ms:0}};if(c){const n={...c,audio:{},video:{},data:{...c.data},network:{...c.network},experimental:{...c.experimental}};return Object.keys(c.audio).forEach(a=>{n.audio[a]={...c.audio[a]}}),Object.keys(c.video).forEach(a=>{n.video[a]={...c.video[a]}}),n}return{...t,audio:{},video:{},data:{...t.data},network:{...t.network},experimental:{...t.experimental}}},av={refreshEvery:2e3,startAfter:0,stopAfter:-1,verbose:!1,pname:`p-${ri()}`,cid:`c-${ri()}`,uid:`u-${ri()}`,record:!1,ticket:!0},Zt={CANDIDATE_PAIR:"candidate-pair",CODEC:"codec",INBOUND_RTP:"inbound-rtp",LOCAL_CANDIDATE:"local-candidate",MEDIA_SOURCE:"media-source",OUTBOUND_RTP:"outbound-rtp",REMOTE_CANDIDATE:"remote-candidate",REMOTE_INBOUND_RTP:"remote-inbound-rtp",TRACK:"track"},q={AUDIO_LEVEL:"audioLevel",AVAILABLE_OUTGOING_BITRATE:"availableOutgoingBitrate",AVAILABLE_INCOMING_BITRATE:"availableIncomingBitrate",BYTES_RECEIVED:"bytesReceived",BYTES_SENT:"bytesSent",CANDIDATE_TYPE:"candidateType",CHANNELS:"channels",CLOCK_RATE:"clockRate",CODEC_ID:"codecId",CURRENT_ROUND_TRIP_TIME:"currentRoundTripTime",ROUND_TRIP_TIME:"roundTripTime",FRACTION_LOST:"fractionLost",FRAME_HEIGHT:"frameHeight",FRAME_WIDTH:"frameWidth",QUALITY_LIMITATION_REASON:"qualityLimitationReason",QUALITY_LIMITATION_DURATIONS:"qualityLimitationDurations",QUALITY_LIMITATION_RESOLUTION_CHANGES:"qualityLimitationResolutionChanges",ID:"id",JITTER:"jitter",KIND:"kind",MEDIA_TYPE:"mediaType",MIME_TYPE:"mimeType",LOCAL_CANDIDATE_ID:"localCandidateId",NETWORK_TYPE:"networkType",RELAY_PROTOCOL:"relayProtocol",NOMINATED:"nominated",PACKETS_LOST:"packetsLost",PACKETS_RECEIVED:"packetsReceived",PACKETS_SENT:"packetsSent",PROTOCOL:"protocol",PORT:"port",REMOTE_CANDIDATE_ID:"remoteCandidateId",REMOTE_SOURCE:"remoteSource",RESPONSES_RECEIVED:"responsesReceived",SDP_FMTP_LINE:"sdpFmtpLine",SSRC:"ssrc",SELECTED:"selected",STATE:"state",TIMESTAMP:"timestamp",TOTAL_ROUND_TRIP_TIME:"totalRoundTripTime",TOTAL_ROUND_TRIP_TIME_MEASUREMENTS:"roundTripTimeMeasurements",TYPE:"type",DECODER_IMPLEMENTATION:"decoderImplementation",ENCODER_IMPLEMENTATION:"encoderImplementation",FRAMES_DECODED:"framesDecoded",FRAMES_ENCODED:"framesEncoded",FRAMES_PER_SECOND:"framesPerSecond",TOTAL_DECODE_TIME:"totalDecodeTime",TOTAL_ENCODE_TIME:"totalEncodeTime",PLI:"pliCount",NACK:"nackCount"},x={SUCCEEDED:"succeeded",AUDIO:"audio",VIDEO:"video"},li={ETHERNET:0,CELLULAR_5G:2,WIFI:3,CELLULAR_4G:5,CELLULAR:10},Iu={ETHERNET:"ethernet",CELLULAR_4G:"cellular",WIFI:"wifi"},ne={AUDIO:"audio",VIDEO:"video",NETWORK:"network",DATA:"data"},bu="config ",ov=(c,t={},n)=>{const a={...n,...t};return t.pname||Ca(bu,`Argument [String] 'cfg.pname' for the peerConnection name or id is missing - use generated '${n.pname}'`),t.cid||Ca(bu,`Argument [String] 'cfg.cid' for the call name or id is missing - use generated '${n.cid}'`),t.uid||Ca(bu,`Argument [String] 'cfg.uid' for the user name or id is missing - use generated '${n.uid}'`),a.pc=c,a},uv=(c={})=>{const t={...av,...c};return t.name=nv(),t.version=rv(),t},ai=(c,t,n,a=!1,o)=>{let s=c.map(r=>{if(!n)return r[t];if(!o)return r[t][n];const d=r[t][o];return d?d[n]:null});return s=s.filter(r=>a?Number.isFinite(r)&&r>0:Number.isFinite(r)),s.length===0?[]:s},Ms=c=>c.reduce((t,n)=>t+n,0)/c.length,cv=()=>`probe-${ri()}`,fv=()=>`coltr-${ri()}`,wh=c=>new Promise(t=>setTimeout(t,c)),wu=(c,t,n)=>{t?c.call(t,n):c(n)},We=(c,t,n,a)=>{const o=ai(c,t,n,!0,a);if(o.length===0)return null;const s=o.reduce((_,g)=>_+g,0)/o.length;return s===0?null:o.map(_=>Math.abs(s-_)).reduce((_,g)=>_+g,0)/o.length*100/s},Xe=(c,t,n,a=!1,o)=>{const s=ai(c,t,n,a,o);return s.length===0?null:s.reduce((r,d)=>r+d,0)/s.length},un=(c,t,n)=>ai(c,t,n).reduce((o,s)=>o+s,0),Ke=(c,t,n,a)=>{const o=ai(c,t,n,!0,a);return o.length===0?null:Math.min(...o)},Ye=(c,t,n,a)=>{const o=ai(c,t,n,!1,a);return o.length===0?null:Math.max(...o)},At=(c,t,n,a)=>{const o=c.slice().pop();if(!o)return null;if(!n)return o[t];if(!a)return o[t][n];const s=o[t][a];return s?s[n]:null},hv=c=>c.slice().pop(),ht=(c,t,n)=>{if(!t)return null;const a={};let o=t[x.AUDIO][c];o||(o=n===$e.INBOUND?{...Ch}:{...Rh}),a[x.AUDIO]=o;let s=t[x.VIDEO][c];return s||(s=n===$e.INBOUND?{...Ih}:{...bh}),a[x.VIDEO]=s,a},oi="exporter ",dv="2.0",Oh=(c,t,n)=>{if(!c||c.length===0)return 0;const a=c[c.length-1];if(!a)return 0;const o=a[t][n];if(o){const s=o.total_rtt_ms_out,r=o.total_rtt_measure_out;return!r||!s?Xe(c,t,"delta_rtt_ms_out",!1,n):Number(s/r)}return null},_v=(c,t)=>{if(!c||c.length===0)return 0;const n=c[c.length-1];if(!n)return 0;const a=n[t].total_rtt_connectivity_ms,o=n[t].total_rtt_connectivity_measure;return!o||!a?Xe(c,t,"delta_rtt_connectivity_ms"):Number(a/o)},pv=c=>At(c,"network","local_candidate_type")!=="relay"?`direct/${At(c,"network","local_candidate_protocol")}`:`turn/${At(c,"network","local_candidate_relay_protocol")}`,mv=c=>{const t=At(c,"network","remote_candidate_type"),n=At(c,"network","remote_candidate_protocol");return t!=="relay"?`direct/${n}`:`turn/${n}`};class gv{constructor(t){this._start=null,this._end=null,this._cfg=t,this._referenceReport=null,this._reports=[],this._events=[]}start(){Ru(oi,"start() - start exporter...");const t=new Date;return this._start=t.toJSON(),t}stop(){Ru(oi,"stop() - stop exporter...");const t=new Date;return this._end=t.toJSON(),t}saveReferenceReport(t){this._referenceReport=t}getReferenceReport(){return this._referenceReport}addReport(t){this._cfg.ticket&&(Pe(oi,`addReport() - add report to exporter at ${t.timestamp}`),this._reports.push(t))}addCustomEvent(t){this._events.push(t)}reset(){Ru(oi,"resetReports() - reset reports"),this._reports=[],this._referenceReport=null,this._start=null,this._end=null}get ticket(){Pe(oi,"ticket() - generate ticket");const t=At(this._reports,"audio","total_packets_lost_in"),n=At(this._reports,"audio","total_packets_in"),a=At(this._reports,"video","total_packets_lost_in"),o=At(this._reports,"video","total_packets_in"),s={},r=hv(this._reports);return r&&(Object.keys(r[x.AUDIO]).forEach(d=>{const h=r[x.AUDIO][d];if(s[h.ssrc]={type:x.AUDIO,direction:h.direction},h.direction===$e.INBOUND){const _={avg:Xe(this._reports,x.AUDIO,"delta_jitter_ms_in",!1,d),min:Ke(this._reports,x.AUDIO,"delta_jitter_ms_in",d),max:Ye(this._reports,x.AUDIO,"delta_jitter_ms_in",d),volatility:We(this._reports,x.AUDIO,"delta_jitter_ms_in",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Xe(this._reports,x.AUDIO,"delta_kbs_in",!1,d),min:Ke(this._reports,x.AUDIO,"delta_kbs_in",d),max:Ye(this._reports,x.AUDIO,"delta_kbs_in",d),volatility:We(this._reports,x.AUDIO,"delta_kbs_in",d),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,x.AUDIO,"delta_KBytes_in",!1,d),min:Ke(this._reports,x.AUDIO,"delta_KBytes_in",d),max:Ye(this._reports,x.AUDIO,"delta_KBytes_in",d),volatility:We(this._reports,x.AUDIO,"delta_KBytes_in",d),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},E={emodel:{avg:Xe(this._reports,x.AUDIO,"mos_emodel_in",!1,d),min:Ke(this._reports,x.AUDIO,"mos_emodel_in",d),max:Ye(this._reports,x.AUDIO,"mos_emodel_in",d),volatility:We(this._reports,x.AUDIO,"mos_emodel_in",d)},effective:{avg:Xe(this._reports,x.AUDIO,"mos_in",!1,d),min:Ke(this._reports,x.AUDIO,"mos_in",d),max:Ye(this._reports,x.AUDIO,"mos_in",d),volatility:We(this._reports,x.AUDIO,"mos_in",d)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}},y=At(this._reports,x.AUDIO,"total_packets_lost_in",d),A=At(this._reports,x.AUDIO,"total_packets_in",d),C={lost:y,avg:Math.round((y/(y+A)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[d].jitter=_,s[d].mos=E,s[d].traffic=T,s[d].bitrate=g,s[d].loss=C}else{const _={avg:Xe(this._reports,x.AUDIO,"delta_jitter_ms_out",!1,d),min:Ke(this._reports,x.AUDIO,"delta_jitter_ms_out",d),max:Ye(this._reports,x.AUDIO,"delta_jitter_ms_out",d),volatility:We(this._reports,x.AUDIO,"delta_jitter_ms_out",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Xe(this._reports,x.AUDIO,"delta_kbs_out",!1,d),min:Ke(this._reports,x.AUDIO,"delta_kbs_out",d),max:Ye(this._reports,x.AUDIO,"delta_kbs_out",d),volatility:We(this._reports,x.AUDIO,"delta_kbs_out",d),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,x.AUDIO,"delta_KBytes_out",!1,d),min:Ke(this._reports,x.AUDIO,"delta_KBytes_out",d),max:Ye(this._reports,x.AUDIO,"delta_KBytes_out",d),volatility:We(this._reports,x.AUDIO,"delta_KBytes_out",d),_unit:{avg:"KB",min:"KB",max:"KB",bitrate:"kbs",volatility:"percent"}},E={avg:Oh(this._reports,x.AUDIO,d),min:Ke(this._reports,x.AUDIO,"delta_rtt_ms_out",d),max:Ye(this._reports,x.AUDIO,"delta_rtt_ms_out",d),volatility:We(this._reports,x.AUDIO,"delta_rtt_ms_out",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},y=At(this._reports,x.AUDIO,"total_packets_lost_out",d),A=At(this._reports,x.AUDIO,"total_packets_out",d),C={lost:y,avg:Math.round((y/(y+A)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}},I={emodel:{avg:Xe(this._reports,x.AUDIO,"mos_emodel_out",!1,d),min:Ke(this._reports,x.AUDIO,"mos_emodel_out",d),max:Ye(this._reports,x.AUDIO,"mos_emodel_out",d),volatility:We(this._reports,x.AUDIO,"mos_emodel_out",d)},effective:{avg:Xe(this._reports,x.AUDIO,"mos_out",!1,d),min:Ke(this._reports,x.AUDIO,"mos_out",d),max:Ye(this._reports,x.AUDIO,"mos_out",d),volatility:We(this._reports,x.AUDIO,"mos_out",d)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}};s[d].jitter=_,s[d].rtt=E,s[d].traffic=T,s[d].bitrate=g,s[d].loss=C,s[d].mos=I}}),Object.keys(r[x.VIDEO]).forEach(d=>{const h=r[x.VIDEO][d];if(s[d]={type:x.VIDEO,direction:h.direction},h.direction===$e.INBOUND){const _={avg:Xe(this._reports,x.VIDEO,"delta_jitter_ms_in",!1,d),min:Ke(this._reports,x.VIDEO,"delta_jitter_ms_in",d),max:Ye(this._reports,x.VIDEO,"delta_jitter_ms_in",d),volatility:We(this._reports,x.VIDEO,"delta_jitter_ms_in",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Xe(this._reports,x.VIDEO,"delta_kbs_in",!1,d),min:Ke(this._reports,x.VIDEO,"delta_kbs_in",d),max:Ye(this._reports,x.VIDEO,"delta_kbs_in",d),volatility:We(this._reports,x.VIDEO,"delta_kbs_in",d),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,x.VIDEO,"delta_KBytes_in",!1,d),min:Ke(this._reports,x.VIDEO,"delta_KBytes_in",d),max:Ye(this._reports,x.VIDEO,"delta_KBytes_in",d),volatility:We(this._reports,x.VIDEO,"delta_KBytes_in",d),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},E=At(this._reports,x.VIDEO,"total_packets_lost_in",d),y=At(this._reports,x.VIDEO,"total_packets_in",d),A={lost:E,avg:Math.round((E/(E+y)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[d].jitter=_,s[d].traffic=T,s[d].bitrate=g,s[d].loss=A}else{const _={avg:Xe(this._reports,x.VIDEO,"delta_jitter_ms_out",!1,d),min:Ke(this._reports,x.VIDEO,"delta_jitter_ms_out",d),max:Ye(this._reports,x.VIDEO,"delta_jitter_ms_out",d),volatility:We(this._reports,x.VIDEO,"delta_jitter_ms_out",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Xe(this._reports,x.VIDEO,"delta_kbs_out",!1,d),min:Ke(this._reports,x.VIDEO,"delta_kbs_out",d),max:Ye(this._reports,x.VIDEO,"delta_kbs_out",d),volatility:We(this._reports,x.VIDEO,"delta_kbs_out",d),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,x.VIDEO,"delta_KBytes_out",!1,d),min:Ke(this._reports,x.VIDEO,"delta_KBytes_out",d),max:Ye(this._reports,x.VIDEO,"delta_KBytes_out",d),volatility:We(this._reports,x.VIDEO,"delta_KBytes_out",d),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},E={avg:Oh(this._reports,x.VIDEO,d),min:Ke(this._reports,x.VIDEO,"delta_rtt_ms_out",d),max:Ye(this._reports,x.VIDEO,"delta_rtt_ms_out",d),volatility:We(this._reports,x.VIDEO,"delta_rtt_ms_out",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},y=At(this._reports,x.VIDEO,"total_packets_lost_out",d),A=At(this._reports,x.VIDEO,"total_packets_out",d),C={lost:y,avg:Math.round((y/(y+A)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[d].jitter=_,s[d].rtt=E,s[d].traffic=T,s[d].bitrate=g,s[d].loss=C}})),{version:dv,configuration:{frequency:this._cfg.refreshEvery},started:this._start,ended:this._end,ua:{agent:navigator.userAgent,pname:this._cfg.pname,user_id:this._cfg.uid},call:{call_id:this._cfg.cid,events:this._events},details:{count:this._reports.length,reports:this._cfg.record?this._reports:[],reference:this._referenceReport||null},ssrc:s,data:{rtt:{avg:_v(this._reports,"data"),min:Ke(this._reports,"data","delta_rtt_connectivity_ms"),max:Ye(this._reports,"data","delta_rtt_connectivity_ms"),volatility:We(this._reports,"data","delta_rtt_connectivity_ms"),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},packetsLost:{audio:{in:{avg:Math.round((t/(t+n)*100||0)*100)/100}},video:{in:{avg:Math.round((a/(a+o)*100||0)*100)/100}},unit:{avg:"percent"}},bitrate:{in:{avg:Xe(this._reports,"data","delta_kbs_in"),min:Ke(this._reports,"data","delta_kbs_in"),max:Ye(this._reports,"data","delta_kbs_in"),volatility:We(this._reports,"data","delta_kbs_in")},out:{avg:Xe(this._reports,"data","delta_kbs_out"),min:Ke(this._reports,"data","delta_kbs_out"),max:Ye(this._reports,"data","delta_kbs_out"),volatility:We(this._reports,"data","delta_kbs_out")},unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},traffic:{in:{avg:Xe(this._reports,"data","delta_KBytes_in"),min:Ke(this._reports,"data","delta_KBytes_in"),max:Ye(this._reports,"data","delta_KBytes_in"),volatility:We(this._reports,"data","delta_KBytes_in")},out:{avg:Xe(this._reports,"data","delta_KBytes_out"),min:Ke(this._reports,"data","delta_KBytes_out"),max:Ye(this._reports,"data","delta_KBytes_out"),volatility:We(this._reports,"data","delta_KBytes_out")},unit:{avg:"KBytes",min:"KBytes",max:"KBytes",volatility:"percent"}},network:{localConnection:pv(this._reports),remoteConnection:mv(this._reports)}}}}updateConfig(t){this._cfg=t}getLastReport(){return this._reports.slice().pop()||null}getBeforeLastReport(){const t=this._reports.slice();return t.pop(),t.pop()||null}getReportsNumber(){return this._reports.length}}const Ls="extractor ",Dh=(c,t,n,a)=>{let o=!1;const s=a[t].total_rtt_ms_out,r=a[t].total_rtt_measure_out,d=n?n[t].total_rtt_ms_out:0,h=n?n[t].total_rtt_measure_out:0,_={rtt:null,totalRTT:s,totalRTTMeasurements:r};if(c[q.TIMESTAMP]===a[t].timestamp_out||!Object.prototype.hasOwnProperty.call(c,q.ROUND_TRIP_TIME)||Object.prototype.hasOwnProperty.call(c,q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS)&&(o=!0,Number(c[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])===0||Number(c[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-h===r))return _;const g=1e3*Number(c[q.ROUND_TRIP_TIME]);let T=s+g,E=r+1;return o&&(T=1e3*Number(c[q.TOTAL_ROUND_TRIP_TIME])-d,E=Number(c[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-h),{rtt:g,totalRTT:T,totalRTTMeasurements:E}},Tv=(c,t,n,a)=>{if(!Object.prototype.hasOwnProperty.call(c,q.CURRENT_ROUND_TRIP_TIME))return{rtt:null,totalRTT:a[t].total_rtt_connectivity_ms,totalRTTMeasurements:a[t].total_rtt_connectivity_measure};const o=1e3*Number(c[q.CURRENT_ROUND_TRIP_TIME]);let s=a[t].total_rtt_connectivity_ms+o,r=a[t].total_rtt_connectivity_measure+1;return Object.prototype.hasOwnProperty.call(c,q.TOTAL_ROUND_TRIP_TIME)&&(s=1e3*Number(c[q.TOTAL_ROUND_TRIP_TIME])-(n?n[t].total_rtt_connectivity_ms:0)),Object.prototype.hasOwnProperty.call(c,q.RESPONSES_RECEIVED)&&(r=Number(c[q.RESPONSES_RECEIVED])-(n?n[t].total_rtt_connectivity_measure:0)),{rtt:o,totalRTT:s,totalRTTMeasurements:r}},Ra=(c,t,n)=>c[q.TIMESTAMP]===n[t].timestamp_out||!Object.prototype.hasOwnProperty.call(c,q.JITTER)?null:1e3*(Number(c[q.JITTER])||0),vv=(c,t)=>{if(!Object.prototype.hasOwnProperty.call(c,q.FRAMES_DECODED)||!Object.prototype.hasOwnProperty.call(c,q.TOTAL_DECODE_TIME))return{delta_ms_decode_frame:t[x.VIDEO].delta_ms_decode_frame_in,frames_decoded:t[x.VIDEO].total_frames_decoded_in,total_decode_time:t[x.VIDEO].total_time_decoded_in};const n=c[q.FRAMES_DECODED],a=c[q.TOTAL_DECODE_TIME],o=a-t[x.VIDEO].total_time_decoded_in,s=n-t[x.VIDEO].total_frames_decoded_in;return{delta_ms_decode_frame:s>0?o*1e3/s:0,frames_decoded:n,total_decode_time:a}},Ev=(c,t)=>{if(!Object.prototype.hasOwnProperty.call(c,q.FRAMES_ENCODED)||!Object.prototype.hasOwnProperty.call(c,q.TOTAL_ENCODE_TIME))return{delta_ms_encode_frame:t[x.VIDEO].delta_ms_encode_frame_out,frames_encoded:t[x.VIDEO].total_frames_encoded_out,total_encode_time:t[x.VIDEO].total_time_encoded_out};const n=c[q.FRAMES_ENCODED],a=c[q.TOTAL_ENCODE_TIME],o=a-t[x.VIDEO].total_time_encoded_out,s=n-t[x.VIDEO].total_frames_encoded_out;return{delta_ms_encode_frame:s>0&&o?o*1e3/s:0,frames_encoded:n,total_encode_time:a}},Nh=(c,t,n,a)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PACKETS_SENT)||!Object.prototype.hasOwnProperty.call(c,q.BYTES_SENT))return{packetsSent:n[t].total_packets_out,packetsLost:n[t].total_packets_lost_out,bytesSent:n[t].total_KBytes_out};const o=Number(c[q.PACKETS_SENT])||0-(a?a[t].total_packets_out:0),s=o-n[t].total_packets_out,r=Number(c[q.BYTES_SENT])/1024-(a?a[t].total_KBytes_out:0),d=r-n[t].total_KBytes_out,h=c[q.TIMESTAMP]||Date.now(),_=a?a.timestamp:null;let g=n.timestamp;!g&&_&&(g=_);const T=g?h-g:0,E=T>0?d*.008*1024/T*1e3:0;return{packetsSent:o,deltaPacketsSent:s,KBytesSent:r,deltaKBytesSent:d,kbsSent:E}},Uh=(c,t,n,a)=>{let o=n[t].total_packets_lost_out,s=0,r=0;return Object.prototype.hasOwnProperty.call(c,q.PACKETS_LOST)&&(o=Number(c[q.PACKETS_LOST])||0-(a?a[t].total_packets_lost_out:0),s=o-n[t].total_packets_lost_out),Object.prototype.hasOwnProperty.call(c,q.FRACTION_LOST)&&(r=Number(100*c[q.FRACTION_LOST])),{packetsLost:o,deltaPacketsLost:s,fractionLost:r}},Ph=(c,t,n,a)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PACKETS_RECEIVED)||!Object.prototype.hasOwnProperty.call(c,q.PACKETS_LOST)||!Object.prototype.hasOwnProperty.call(c,q.BYTES_RECEIVED))return{percent_packets_lost:n[t].percent_packets_lost_in,packetsReceived:n[t].total_packets_in,packetsLost:n[t].total_packets_lost_in,bytesReceived:n[t].total_KBytes_in};const o=Number(c[q.PACKETS_RECEIVED])||0-(a?a[t].total_packets_in:0),s=Number(c[q.PACKETS_LOST])||0-(a?a[t].total_packets_lost_in:0),r=s-n[t].total_packets_lost_in,d=o-n[t].total_packets_in,h=o!==n[t].total_packets_in?r*100/(r+d):0,_=Number(c[q.BYTES_RECEIVED])/1024-(a?a[t].total_KBytes_in:0),g=_-n[t].total_KBytes_in,T=c[q.TIMESTAMP]||Date.now(),E=a?a.timestamp:null;let y=n.timestamp;!y&&E&&(y=E);const A=y?T-y:0,C=A>0?g*.008*1024/A*1e3:0;return{percentPacketsLost:h,packetsReceived:o,deltaPacketsReceived:d,packetsLost:s,deltaPacketsLost:r,KBytesReceived:_,deltaKBytesReceived:g,kbsReceived:C}},Sv=c=>c[q.CANDIDATE_TYPE]!=="relay"?"":c[q.RELAY_PROTOCOL]||"",yv=c=>{if(!Object.prototype.hasOwnProperty.call(c,q.NETWORK_TYPE))return li.WIFI;switch(c[q.NETWORK_TYPE]){case Iu.ETHERNET:return li.ETHERNET;case Iu.CELLULAR_4G:return li.CELLULAR_4G;case Iu.WIFI:return li.WIFI;default:return li.CELLULAR}},xh=c=>!Object.prototype.hasOwnProperty.call(c,q.FRAME_HEIGHT)||!Object.prototype.hasOwnProperty.call(c,q.FRAME_WIDTH)?{width:null,height:null,framerate:null}:{width:c[q.FRAME_WIDTH]||null,height:c[q.FRAME_HEIGHT]||null,framerate:c[q.FRAMES_PER_SECOND]},Av=c=>{const t=Object.prototype.hasOwnProperty.call(c,q.QUALITY_LIMITATION_REASON)?c[q.QUALITY_LIMITATION_REASON]:null,n=Object.prototype.hasOwnProperty.call(c,q.QUALITY_LIMITATION_RESOLUTION_CHANGES)?c[q.QUALITY_LIMITATION_RESOLUTION_CHANGES]:null,a=Object.prototype.hasOwnProperty.call(c,q.QUALITY_LIMITATION_DURATIONS)?c[q.QUALITY_LIMITATION_DURATIONS]:null;return a&&Object.keys(a).forEach(o=>{a[o]>1e3&&(a[o]=Number(a[o]/1e3))}),{reason:t,durations:a,resolutionChanges:n}},Cv=(c,t,n)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PLI)||!Object.prototype.hasOwnProperty.call(c,q.NACK))return{pliCount:t.total_pli_sent_in,nackCount:t.total_nack_sent_in,deltaPliCount:0,deltaNackCount:0};const a=(c[q.PLI]||0)-(n?n[x.VIDEO].total_pli_sent_in:0),o=(c[q.NACK]||0)-(n?n[x.VIDEO].total_nack_sent_in:0);return{pliCount:a,nackCount:o,deltaPliCount:a-t[x.VIDEO].total_pli_sent_in,deltaNackCount:o-t[x.VIDEO].total_nack_sent_in}},Rv=(c,t,n)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PLI)||!Object.prototype.hasOwnProperty.call(c,q.NACK))return{pliCount:t.total_pli_received_out,nackCount:t.total_nack_received_out,deltaPliCount:0,deltaNackCount:0};const a=(c[q.PLI]||0)-(n?n[x.VIDEO].total_pli_received_out:0),o=(c[q.NACK]||0)-(n?n[x.VIDEO].total_nack_received_out:0);return{pliCount:a,nackCount:o,deltaPliCount:a-t[x.VIDEO].total_pli_received_out,deltaNackCount:o-t[x.VIDEO].total_nack_received_out}},Iv=c=>({channels:c[q.CHANNELS]||null,clock_rate:c[q.CLOCK_RATE]||null,mime_type:c[q.MIME_TYPE]||null,sdp_fmtp_line:c[q.SDP_FMTP_LINE]||null}),bv=c=>({clock_rate:c[q.CLOCK_RATE]||null,mime_type:c[q.MIME_TYPE]||null}),wv=(c,t,n)=>{const a=(c[q.BYTES_RECEIVED]||0)/1024-(n?n.data.total_KBytes_in:0),o=(c[q.BYTES_SENT]||0)/1024-(n?n.data.total_KBytes_out:0),s=c[q.TIMESTAMP]||Date.now(),r=a-t.data.total_KBytes_in,d=o-t.data.total_KBytes_out,h=n?n.timestamp:null;let _=t.timestamp;!_&&h&&(_=h);const g=_?s-_:0,T=g>0?r*.008*1024/g*1e3:0,E=g>0?d*.008*1024/g*1e3:0;return{total_KBytes_received:a,total_KBytes_sent:o,delta_KBytes_received:r,delta_KBytes_sent:d,kbs_speed_received:T,kbs_speed_sent:E}},Ov=c=>{const t=c[q.AVAILABLE_INCOMING_BITRATE]/1024||0,n=c[q.AVAILABLE_OUTGOING_BITRATE]/1024||0;return{kbs_incoming_bandwidth:t,kbs_outgoing_bandwidth:n}},Dv=(c,t,n,a)=>{if(!c)return[];switch(c[q.TYPE]){case Zt.CANDIDATE_PAIR:let o=!1;if(c[q.NOMINATED]&&c[q.STATE]===x.SUCCEEDED&&(o=!0,Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c),q.SELECTED in c&&!c[q.SELECTED]&&(o=!1)),o){const r=c[q.LOCAL_CANDIDATE_ID],d=c[q.REMOTE_CANDIDATE_ID],h=wv(c,t,a),_=Ov(c),g=Tv(c,"data",a,t);return[{type:ne.NETWORK,value:{local_candidate_id:r}},{type:ne.NETWORK,value:{remote_candidate_id:d}},{type:ne.DATA,value:{total_KBytes_in:h.total_KBytes_received}},{type:ne.DATA,value:{total_KBytes_out:h.total_KBytes_sent}},{type:ne.DATA,value:{delta_KBytes_in:h.delta_KBytes_received}},{type:ne.DATA,value:{delta_KBytes_out:h.delta_KBytes_sent}},{type:ne.DATA,value:{delta_kbs_in:h.kbs_speed_received}},{type:ne.DATA,value:{delta_kbs_out:h.kbs_speed_sent}},{type:ne.DATA,value:{delta_kbs_bandwidth_in:_.kbs_incoming_bandwidth}},{type:ne.DATA,value:{delta_kbs_bandwidth_out:_.kbs_outgoing_bandwidth}},{type:ne.DATA,value:{delta_rtt_connectivity_ms:g.rtt}},{type:ne.DATA,value:{total_rtt_connectivity_ms:g.totalRTT}},{type:ne.DATA,value:{total_rtt_connectivity_measure:g.totalRTTMeasurements}}]}break;case Zt.LOCAL_CANDIDATE:if(c[q.ID]===t.network.local_candidate_id)return[{type:ne.NETWORK,value:{infrastructure:yv(c)}},{type:ne.NETWORK,value:{local_candidate_type:c[q.CANDIDATE_TYPE]||""}},{type:ne.NETWORK,value:{local_candidate_protocol:c[q.PROTOCOL]||""}},{type:ne.NETWORK,value:{local_candidate_relay_protocol:Sv(c)}}];break;case Zt.REMOTE_CANDIDATE:if(c[q.ID]===t.network.remote_candidate_id)return[{type:ne.NETWORK,value:{remote_candidate_type:c[q.CANDIDATE_TYPE]||""}},{type:ne.NETWORK,value:{remote_candidate_protocol:c[q.PROTOCOL]||""}}];break;case Zt.INBOUND_RTP:{Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const r=c[q.SSRC],d=ht(r,t,$e.INBOUND);d&&(d.timestamp=t.timestamp);const h=ht(r,a,$e.INBOUND);if(h&&(h.timestamp=a.timestamp),c[q.MEDIA_TYPE]===x.AUDIO){const _=Ph(c,x.AUDIO,d,h),g=Ra(c,x.AUDIO,d),T=c[q.CODEC_ID]||"";return[{ssrc:r,type:ne.AUDIO,value:{codec_id_in:T}},{ssrc:r,type:ne.AUDIO,value:{total_packets_in:_.packetsReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_in:_.deltaPacketsReceived}},{ssrc:r,type:ne.AUDIO,value:{total_packets_lost_in:_.packetsLost}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_lost_in:_.deltaPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{percent_packets_lost_in:_.percentPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{total_KBytes_in:_.KBytesReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_KBytes_in:_.deltaKBytesReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_kbs_in:_.kbsReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_jitter_ms_in:g}}]}if(c[q.MEDIA_TYPE]===x.VIDEO){const _=vv(c,d),g=Ph(c,x.VIDEO,d,h),T=Ra(c,x.VIDEO,d),E=c[q.DECODER_IMPLEMENTATION]||null,y=c[q.CODEC_ID]||null,A=xh(c),C=Cv(c,d,h);return[{ssrc:r,type:ne.VIDEO,value:{codec_id_in:y}},{ssrc:r,type:ne.VIDEO,value:{total_packets_in:g.packetsReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_in:g.deltaPacketsReceived}},{ssrc:r,type:ne.VIDEO,value:{total_packets_lost_in:g.packetsLost}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_lost_in:g.deltaPacketsLost}},{ssrc:r,type:ne.VIDEO,value:{percent_packets_lost_in:g.percentPacketsLost}},{ssrc:r,type:ne.VIDEO,value:{total_KBytes_in:g.KBytesReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_KBytes_in:g.deltaKBytesReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_kbs_in:g.kbsReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_jitter_ms_in:T}},{ssrc:r,type:ne.VIDEO,value:{decoder_in:E}},{ssrc:r,type:ne.VIDEO,value:{delta_ms_decode_frame_in:_.delta_ms_decode_frame}},{ssrc:r,type:ne.VIDEO,value:{total_frames_decoded_in:_.frames_decoded}},{ssrc:r,type:ne.VIDEO,value:{total_time_decoded_in:_.total_decode_time}},{ssrc:r,type:ne.VIDEO,value:{total_nack_sent_in:C.nackCount}},{ssrc:r,type:ne.VIDEO,value:{delta_nack_sent_in:C.deltaNackCount}},{ssrc:r,type:ne.VIDEO,value:{total_pli_sent_in:C.pliCount}},{ssrc:r,type:ne.VIDEO,value:{delta_pli_sent_in:C.deltaPliCount}},{ssrc:r,type:ne.VIDEO,value:{size_in:A}}]}break}case Zt.OUTBOUND_RTP:{Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const r=c[q.SSRC],d=ht(r,t,$e.OUTBOUND);d&&(d.timestamp=t.timestamp);const h=ht(r,a,$e.OUTBOUND);if(h&&(h.timestamp=a.timestamp),c[q.MEDIA_TYPE]===x.AUDIO){const _=c[q.CODEC_ID]||null,g=Nh(c,x.AUDIO,d,h);return[{ssrc:r,type:ne.AUDIO,value:{codec_id_out:_}},{ssrc:r,type:ne.AUDIO,value:{total_packets_out:g.packetsSent}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_out:g.deltaPacketsSent}},{ssrc:r,type:ne.AUDIO,value:{total_KBytes_out:g.KBytesSent}},{ssrc:r,type:ne.AUDIO,value:{delta_KBytes_out:g.deltaKBytesSent}},{ssrc:r,type:ne.AUDIO,value:{delta_kbs_out:g.kbsSent}}]}if(c[q.MEDIA_TYPE]===x.VIDEO){const _=c[q.ENCODER_IMPLEMENTATION]||null,g=c[q.CODEC_ID]||null,T=Ev(c,d),E=xh(c),y=Av(c),A=Rv(c,d,h),C=Nh(c,x.VIDEO,d,h);return[{ssrc:r,type:ne.VIDEO,value:{codec_id_out:g}},{ssrc:r,type:ne.VIDEO,value:{total_packets_out:C.packetsSent}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_out:C.deltaPacketsSent}},{ssrc:r,type:ne.VIDEO,value:{total_KBytes_out:C.KBytesSent}},{ssrc:r,type:ne.VIDEO,value:{delta_KBytes_out:C.deltaKBytesSent}},{ssrc:r,type:ne.VIDEO,value:{delta_kbs_out:C.kbsSent}},{ssrc:r,type:ne.VIDEO,value:{encoder_out:_}},{ssrc:r,type:ne.VIDEO,value:{delta_ms_encode_frame_out:T.delta_ms_encode_frame}},{ssrc:r,type:ne.VIDEO,value:{total_frames_encoded_out:T.frames_encoded}},{ssrc:r,type:ne.VIDEO,value:{total_time_encoded_out:T.total_encode_time}},{ssrc:r,type:ne.VIDEO,value:{total_nack_received_out:A.nackCount}},{ssrc:r,type:ne.VIDEO,value:{delta_nack_received_out:A.deltaNackCount}},{ssrc:r,type:ne.VIDEO,value:{total_pli_received_out:A.pliCount}},{ssrc:r,type:ne.VIDEO,value:{delta_pli_received_out:A.deltaPliCount}},{ssrc:r,type:ne.VIDEO,value:{size_out:E}},{ssrc:r,type:ne.VIDEO,value:{limitation_out:y}}]}break}case Zt.MEDIA_SOURCE:{Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);break}case Zt.TRACK:{Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);break}case Zt.CODEC:const s=[];return Object.keys(t[x.AUDIO]).forEach(r=>{const d=t[x.AUDIO][r];if(d.codec_id_in===c[q.ID]||d.codec_id_out===c[q.ID]){Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const h=Iv(c);c[q.ID]===d.codec_id_in?s.push({ssrc:d.ssrc,type:ne.AUDIO,value:{codec_in:h}}):s.push({ssrc:d.ssrc,type:ne.AUDIO,value:{codec_out:h}})}}),Object.keys(t[x.VIDEO]).forEach(r=>{const d=t[x.VIDEO][r];if(d.codec_id_in===c[q.ID]||d.codec_id_out===c[q.ID]){Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const h=bv(c);c[q.ID]===d.codec_id_in?s.push({ssrc:d.ssrc,type:ne.VIDEO,value:{codec_in:h}}):s.push({ssrc:d.ssrc,type:ne.VIDEO,value:{codec_out:h}})}}),s;case Zt.REMOTE_INBOUND_RTP:{Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const r=c[q.SSRC],d=ht(r,t,$e.OUTBOUND),h=ht(r,a,$e.OUTBOUND);if(c[q.KIND]===x.AUDIO){const _=Dh(c,x.AUDIO,h,d),g=Ra(c,x.AUDIO,d),T=Uh(c,x.AUDIO,d,h);return[{ssrc:r,type:ne.AUDIO,value:{delta_rtt_ms_out:_.rtt}},{ssrc:r,type:ne.AUDIO,value:{total_rtt_ms_out:_.totalRTT}},{ssrc:r,type:ne.AUDIO,value:{total_rtt_measure_out:_.totalRTTMeasurements}},{ssrc:r,type:ne.AUDIO,value:{delta_jitter_ms_out:g}},{ssrc:r,type:ne.AUDIO,value:{timestamp_out:c[q.TIMESTAMP]}},{ssrc:r,type:ne.AUDIO,value:{total_packets_lost_out:T.packetsLost}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_lost_out:T.deltaPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{percent_packets_lost_out:T.fractionLost}}]}if(c[q.KIND]===x.VIDEO){const _=Dh(c,x.VIDEO,h,d),g=Ra(c,x.VIDEO,d),T=Uh(c,x.VIDEO,d,h);return[{ssrc:r,type:ne.VIDEO,value:{delta_rtt_ms_out:_.rtt}},{ssrc:r,type:ne.VIDEO,value:{total_rtt_ms_out:_.totalRTT}},{ssrc:r,type:ne.VIDEO,value:{total_rtt_measure_out:_.totalRTTMeasurements}},{ssrc:r,type:ne.VIDEO,value:{delta_jitter_ms_out:g}},{ssrc:r,type:ne.VIDEO,value:{timestamp_out:c[q.TIMESTAMP]}},{ssrc:r,type:ne.VIDEO,value:{total_packets_lost_out:T.packetsLost}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_lost_out:T.deltaPacketsLost}},{ssrc:r,type:ne.VIDEO,value:{percent_packets_lost_out:T.fractionLost}}]}break}}return[]},Ia=c=>c<0?1:c>100?4.5:1+.035*c+7/1e6*c*(c-60)*(100-c),Nv=(c,t=x.AUDIO,n,a,o)=>{const s=ht(o,c,$e.INBOUND),r=ht(o,n,$e.INBOUND),d=ht(o,a,$e.INBOUND),h=[],_=[],g=s[t].percent_packets_lost_in,T=s[t].delta_jitter_ms_in,E=r&&r[t].delta_jitter_ms_in||null,y=d&&d[t].delta_jitter_ms_in||null,A=c.data.delta_rtt_connectivity_ms,C=n&&n.data.delta_rtt_connectivity_ms||null,I=a&&a.data.delta_rtt_connectivity_ms||null;A&&h.push(A),C&&h.push(C),I&&h.push(I),T&&_.push(T),n&&E&&_.push(E),a&&y&&_.push(y);const H=h.length>0?Ms(h):100,$=_.length>0?Ms(_):10,oe=93.2-g,N=.18*oe*oe-27.9*oe+1126.62,j=(H+$)/2,Se=j-177.3<0?0:1,ve=.024*j+.11*(j-177.3)*Se,k=N-ve;return Ia(k)},Uv=(c,t=x.AUDIO,n,a,o)=>{const s=ht(o,c,$e.OUTBOUND),r=ht(o,n,$e.OUTBOUND),d=ht(o,a,$e.OUTBOUND),h=[],_=[],g=s[t].percent_packets_lost_out,T=s[t].delta_rtt_ms_out,E=r&&r[t].delta_rtt_ms_out||null,y=d&&d[t].delta_rtt_ms_out||null,A=s[t].delta_jitter_ms_out,C=r&&r[t].delta_jitter_ms_out||null,I=d&&d[t].delta_jitter_ms_out||null,H=c.data.delta_rtt_connectivity_ms,$=n&&n.data.delta_rtt_connectivity_ms||null,oe=a&&a.data.delta_rtt_connectivity_ms||null;T?h.push(T):H&&h.push(H),E?h.push(E):$&&h.push($),y?h.push(y):oe&&h.push(oe),A&&_.push(A),n&&C&&_.push(C),a&&I&&_.push(I);const N=h.length>0?Ms(h):100,j=_.length>0?Ms(_):10,Se=93.2-g,ve=.18*Se*Se-27.9*Se+1126.62,k=(N+j)/2,D=k-177.3<0?0:1,B=.024*k+.11*(k-177.3)*D,V=ve-B;return Ia(V)},Pv=(c,t=x.AUDIO,n,a,o)=>{const s=ht(o,c,$e.INBOUND),r=ht(o,n,$e.INBOUND),d=ht(o,a,$e.INBOUND),h=[],_=[],g=s[t].percent_packets_lost_in/100,T=s[t].delta_jitter_ms_in,E=r&&r[t].delta_jitter_ms_in||null,y=d&&d[t].delta_jitter_ms_in||null,A=c.data.delta_rtt_connectivity_ms,C=n&&n.data.delta_rtt_connectivity_ms||null,I=a&&a.data.delta_rtt_connectivity_ms||null;A&&h.push(A),C&&h.push(C),I&&h.push(I),T&&_.push(T),r&&E&&_.push(E),d&&y&&_.push(y);const H=h.length>0?Ms(h):100,$=_.length>0?Ms(_):10,oe=0,N=19.8,j=29.7,Se=30,ve=(H+$)/2+Se,k=ve-177.3<0?0:1,D=.024*ve+.11*(ve-177.3)*k,V=93.2-(oe+N*Math.log(1+j*g)+D);return Ia(V)},xv=(c,t=x.AUDIO,n,a,o)=>{const s=ht(o,c,$e.OUTBOUND),r=ht(o,n,$e.OUTBOUND),d=ht(o,a,$e.OUTBOUND),h=[],_=[],g=s[t].percent_packets_lost_out/100,T=s[t].delta_rtt_ms_out,E=r&&r[t].delta_rtt_ms_out||null,y=d&&d[t].delta_rtt_ms_out||null,A=s[t].delta_jitter_ms_out,C=r&&r[t].delta_jitter_ms_out||null,I=d&&d[t].delta_jitter_ms_out||null,H=c.data.delta_rtt_connectivity_ms,$=n&&n.data.delta_rtt_connectivity_ms||null,oe=a&&a.data.delta_rtt_connectivity_ms||null;T?h.push(T):H&&h.push(H),E?h.push(E):$&&h.push($),y?h.push(y):oe&&h.push(oe),A&&_.push(A),r&&C&&_.push(C),d&&I&&_.push(I);const N=h.length>0?Ms(h):100,j=_.length>0?Ms(_):10,Se=0,ve=19.8,k=29.7,D=30,B=(N+j)/2+D,V=B-177.3<0?0:1,J=.024*B+.11*(B-177.3)*V,Z=93.2-(Se+ve*Math.log(1+k*g)+J);return Ia(Z)};class kv{constructor(t,n){this._callbacks={onreport:null,onticket:null},this._id=fv(),this._moduleName=this._id,this._probeId=n,this._config=t,this._exporter=new gv(t),this._state=ys.IDLE,this.registerToPCEvents(),on(this._moduleName,`new collector created for probe ${this._probeId}`)}analyze(t,n,a,o){const s=(h,_)=>h===x.AUDIO?_===Zt.INBOUND_RTP?{...Ch}:{...Rh}:_===Zt.INBOUND_RTP?{...Ih}:{...bh},r=lv(n);r.pname=this._config.pname,r.call_id=this._config.cid,r.user_id=this._config.uid,r.count=n?n.count+1:1;let d=null;return t.forEach(h=>{!d&&h.timestamp&&(d=h.timestamp),Dv(h,r,r.pname,o).forEach(g=>{if(g.value&&g.type)if(g.ssrc){let T=r[g.type][g.ssrc];T||(T=s(g.type,h.type),T.ssrc=g.ssrc,r[g.type][g.ssrc]=T),Object.keys(g.value).forEach(E=>{T[E]=g.value[E]})}else Object.keys(g.value).forEach(T=>{r[g.type][T]=g.value[T]})})}),r.timestamp=d,Object.keys(r[x.AUDIO]).forEach(h=>{const _=r[x.AUDIO][h];_.direction===$e.INBOUND?(_.mos_emodel_in=Nv(r,x.AUDIO,n,a,_.ssrc),_.mos_in=Pv(r,x.AUDIO,n,a,_.ssrc)):(_.mos_emodel_out=Uv(r,x.AUDIO,n,a,_.ssrc),_.mos_out=xv(r,x.AUDIO,n,a,_.ssrc))}),r}async takeReferenceStats(){return new Promise((t,n)=>{const a=Date.now();setTimeout(async()=>{try{const o=Date.now()-a,s=Date.now(),r=await this._config.pc.getStats(),d=this.analyze(r,null,null,null),h=Date.now();d.experimental.time_to_measure_ms=h-s,d.experimental.time_to_wait_ms=o,this._exporter.saveReferenceReport(d),Pe(this._moduleName,`got reference report for probe ${this._probeId}`),t()}catch(o){n(o)}},this._config.startAfter)})}async collectStats(){try{if(this._state!==ys.RUNNING||!this._config.pc)return Pe(this._moduleName,`report discarded (too late) for probe ${this._probeId}`),null;const t=Date.now(),n=await this._config.pc.getStats(),a=this.analyze(n,this._exporter.getLastReport(),this._exporter.getBeforeLastReport(),this._exporter.getReferenceReport()),o=Date.now();return a.experimental.time_to_measure_ms=o-t,this._exporter.addReport(a),Pe(this._moduleName,`got report for probe ${this._probeId}#${this._exporter.getReportsNumber()+1}`),this.fireOnReport(a),a}catch(t){return Vn(this._moduleName,`got error ${t}`),null}}async start(){Pe(this._moduleName,"starting"),this.state=ys.RUNNING,this._startedTime=this._exporter.start(),Pe(this._moduleName,"started")}async mute(){this.state=ys.MUTED,Pe(this._moduleName,"muted")}async unmute(){this.state=ys.RUNNING,Pe(this._moduleName,"unmuted")}async stop(t){if(Pe(this._moduleName,`stopping${t?" by watchdog":""}...`),this._stoppedTime=this._exporter.stop(),this.state=ys.IDLE,this._config.ticket){const{ticket:n}=this._exporter;this.fireOnTicket(n)}this._exporter.reset(),Pe(this._moduleName,"stopped")}registerCallback(t,n,a){t in this._callbacks?(this._callbacks[t]={callback:n,context:a},Pe(this._moduleName,`registered callback '${t}'`)):Vn(this._moduleName,`can't register callback for '${t}' - not found`)}unregisterCallback(t){t in this._callbacks?(this._callbacks[t]=null,delete this._callbacks[t],Pe(this._moduleName,`unregistered callback '${t}'`)):Vn(this._moduleName,`can't unregister callback for '${t}' - not found`)}fireOnReport(t){this._callbacks.onreport&&wu(this._callbacks.onreport.callback,this._callbacks.onreport.context,t)}fireOnTicket(t){this._callbacks.onticket&&wu(this._callbacks.onticket.callback,this._callbacks.onticket.context,t)}updateConfig(t){this._config=t,this._exporter.updateConfig(t)}get state(){return this._state}set state(t){this._state=t,Pe(this._moduleName,`state changed to ${t}`)}addCustomEvent(t,n,a,o){this._exporter.addCustomEvent({at:typeof t=="object"?t.toJSON():t,category:n,name:a,description:o})}async registerToPCEvents(){const{pc:t}=this._config;if(navigator.mediaDevices.ondevicechange=async()=>{try{const n=await navigator.mediaDevices.enumerateDevices();this.addCustomEvent(new Date().toJSON(),"device",`${n.length} devices found`,"Media Devices state")}catch{Vn(this._moduleName,"can't get devices")}},t){t.oniceconnectionstatechange=()=>{const a=t.iceConnectionState;a===ii.CONNECTED||a===ii.COMPLETED?this.addCustomEvent(new Date().toJSON(),"call",a,"ICE connection state"):a===ii.DISCONNECTED||a===ii.FAILED?this.addCustomEvent(new Date().toJSON(),"call",a,"ICE connection state"):a===ii.CLOSED&&this.addCustomEvent(new Date().toJSON(),"call","ended","ICE connection state")},t.onicegatheringstatechange=()=>{const a=t.iceGatheringState;this.addCustomEvent(new Date().toJSON(),"call",a,"ICE gathering state")},t.ontrack=a=>{this.addCustomEvent(new Date().toJSON(),"call",`${a.track.kind}track`,"MediaStreamTrack received")},t.onnegotiationneeded=()=>{this.addCustomEvent(new Date().toJSON(),"call","negotiation","Media changed")};const n=t.getReceivers();if(n&&n.length>0){const a=n[0],{transport:o}=a;if(o){const{iceTransport:s}=o;s&&(s.onselectedcandidatepairchange=()=>{this.addCustomEvent(new Date().toJSON(),"call","transport","Candidates Pair changed")})}}}}}class Mv{constructor(t){this._id=t.pname&&t.pname.substr(0,12).padEnd(12," ")||cv(),this._moduleName=this._id,on(this._moduleName,"probe created"),this._config=t,this._collector=new kv(this._config,this._id)}set onreport(t){t?this._collector.registerCallback("onreport",t):this._collector.unregisterCallback("onreport")}set onticket(t){t?this._collector.registerCallback("onticket",t):this._collector.unregisterCallback("onticket")}get id(){return this._id}get pname(){return this._config.pname}get cid(){return this._config.cid}get uid(){return this._config.uid}get state(){return this._collector.state}set state(t){this._collector.state=t}addCustomEvent(t,n,a,o=new Date().toJSON()){this._collector.addCustomEvent(o,n,t,a)}get isRunning(){return this._collector.state===ys.RUNNING}get isIdle(){return this._collector.state===ys.IDLE}updateUserId(t){this._config.uid=t,this._collector.updateConfig(this._config)}updateCallId(t){this._config.cid=t,this._collector.updateConfig(this._config)}start(){if(!this.isIdle){Ca(this._moduleName,"probe is already running");return}this._collector.start()}stop(t=!1){this.isRunning&&this._collector.stop(t)}async takeReferenceStats(){return this._collector.takeReferenceStats()}async collectStats(){return this._collector.collectStats()}}const bt="engine ";class Lv{constructor(t){this._config=t,this._probes=[],this._startedTime=null,this._callbacks={onresult:null},on(bt,`configured for probing every ${this._config.refreshEvery}ms`),on(bt,`configured for starting after ${this._config.startAfter}ms`),on(bt,`${!this._config.stopAfter||this._config.stopAfter!==-1?`configured for stopped after ${this._config.stopAfter}ms`:"configured for never stopped"}`),Pe(bt,"engine initialized")}get probes(){return this._probes}get isRunning(){return this._probes.some(t=>t.isRunning)}get isIdle(){return this._probes.every(t=>t.isIdle)}addNewProbe(t,n){if(!t)throw new Error("undefined peer connection");const a=ov(t,n,this._config),o=new Mv(a);return this._probes.push(o),Pe(bt,`${this._probes.length} probes registered`),o}removeExistingProbe(t){if(!t)throw new Error("undefined probe");t.state===ys.RUNNING&&t.stop(),this._probes=this._probes.filter(n=>t.id!==n.id)}async start(){const t=()=>{this._probes.forEach(s=>s.start())},n=async()=>Promise.all(this._probes.map(s=>s.takeReferenceStats())),a=()=>this.isIdle?!1:!this._config.stopAfter||this._config.stopAfter<0?!0:Date.now()<this._startedTime+this._config.stopAfter,o=async()=>{const s=iv(),r=this._probes.filter(d=>d.isRunning);for(const d of r){const h=await d.collectStats();h&&s.probes.push(h),Pe(bt,`got probe ${d.id}`),await wh(0)}return s.delta_time_to_measure_probes_ms=un(s.probes,"experimental","time_to_measure_ms"),s.delta_KBytes_in=un(s.probes,"data","delta_KBytes_in"),s.delta_KBytes_out=un(s.probes,"data","delta_KBytes_out"),s.delta_kbs_in=un(s.probes,"data","delta_kbs_in"),s.delta_kbs_out=un(s.probes,"data","delta_kbs_out"),s.total_time_decoded_in=un(s.probes,"video","total_time_decoded_in"),s.total_time_encoded_out=un(s.probes,"video","total_time_encoded_out"),s};for(Pe(bt,"starting to collect"),t(),Pe(bt,"generating reference reports..."),await n(),Pe(bt,"reference reports generated"),this._startedTime=Date.now();a();)if(Pe(bt,`wait ${this._config.refreshEvery}ms before collecting`),await wh(this._config.refreshEvery),a()){Pe(bt,"collecting...");const s=Date.now(),r=await o(),d=Date.now();r.delta_time_consumed_to_measure_ms=d-s,this.fireOnReports(r),Pe(bt,"collected")}Pe(bt,"reaching end of the collecting period..."),this.isRunning&&setTimeout(()=>{this.stop()},0)}stop(t){const n=a=>{this._probes.forEach(o=>{o.stop(a)})};on(bt,"stop collecting"),n(t)}registerCallback(t,n,a){t in this._callbacks?(this._callbacks[t]={callback:n,context:a},Pe(bt,`registered callback '${t}'`)):Vn(bt,`can't register callback for '${t}' - not found`)}unregisterCallback(t){t in this._callbacks?(this._callbacks[t]=null,delete this._callbacks[t],Pe(this._moduleName,`unregistered callback '${t}'`)):Vn(this._moduleName,`can't unregister callback for '${t}' - not found`)}fireOnReports(t){this._callbacks.onresult&&t.probes.length>0&&wu(this._callbacks.onresult.callback,this._callbacks.onresult.context,t)}}const $v="interface ";class Hv{constructor(t){this._config=uv(t),on($v,`welcome to ${this._config.name} version ${this._config.version}`),XT(this._config.verbose||!1),this._engine=new Lv(this._config)}setupLogLevel(t){QT(t)}get version(){return this._config.version}get name(){return this._config.name}get probes(){return this._engine.probes}createProbe(t,n){return this._engine.addNewProbe(t,n)}startAllProbes(){this._engine.start()}stopAllProbes(){this._engine.stop()}get running(){return this._engine.isRunning}get idle(){return this._engine.isIdle}removeProbe(t){this._engine.removeExistingProbe(t)}set onresult(t){t?this._engine.registerCallback("onresult",t):this._engine.unregisterCallback("onresult")}}function Fv(c,t){return Object.keys(c).filter(n=>t.includes(n)).reduce((n,a)=>{const o=a;return{...n,[o]:c[o]}},{})}const jv=["mos_in","codec_in","delta_KBytes_in","delta_kbs_in","delta_jitter_ms_in","delta_packets_lost_in"];class qv{constructor(t){this.intervals={},this.emitInterval=t.emitInterval||200,this.onChangeFunction=t.onChangeFunction}start(t,n){t&&t.getTracks().length&&requestAnimationFrame(()=>this.beginCalculation(t,n))}stop(t){this.clearVolumeInterval(t)}clearVolumeInterval(t){clearInterval(this.intervals[t]),delete this.intervals[t]}clearAllIntervals(){Object.keys(this.intervals).forEach(t=>{clearInterval(this.intervals[t])}),this.intervals={}}beginCalculation(t,n){this.clearVolumeInterval(n);const a=an.createAnalyser(),o=an.createMediaStreamSource(t),s=an.createScriptProcessor(2048,1,1);a.smoothingTimeConstant=.8,a.fftSize=1024,o.connect(a),a.connect(s),s.connect(an.destination),this.intervals[n]=setInterval(()=>{const r=new Uint8Array(a.frequencyBinCount);a.getByteFrequencyData(r);let d=0;const h=r.length;for(let g=0;g<h;g++)d+=r[g];const _=d/h;this.onChangeFunction(n,_)},this.emitInterval)}}const ba={SELECTED_INPUT_DEVICE:"OpensipsJSInputDevice",SELECTED_OUTPUT_DEVICE:"OpensipsJSOutputDevice"},Vv=0;class Bv{constructor(t){this.isAutoAnswer=!1,this.muteWhenJoinEnabled=!1,this.isDNDEnabled=!1,this.muted=!1,this.microphoneInputLevelValue=1,this.speakerVolumeValue=1,this.activeRooms={},this.activeCalls={},this.extendedCalls={},this.availableMediaDevices=[],this.selectedMediaDevices={input:"default",output:"default"},this.callStatus={},this.callTime={},this.callMetrics={},this.timeIntervals={},this.metricConfig={refreshEvery:1e3},this.activeStreamValue=null,this.initialStreamValue=null,this.context=t,this.context.on(this.context.newRTCSessionEventName,this.newRTCSessionCallback.bind(this)),this.VUMeter=new qv({onChangeFunction:this.emitVolumeChange.bind(this)}),this.initializeMediaDevices()}get sipOptions(){return{...this.context.options.sipOptions,mediaConstraints:this.getUserMediaConstraints}}get currentActiveRoomId(){return this.currentActiveRoomIdValue}set currentActiveRoomId(t){this.currentActiveRoomIdValue=t,this.context.emit("currentActiveRoomChanged",t)}get autoAnswer(){return this.isAutoAnswer}get callAddingInProgress(){return this.isCallAddingInProgress}set callAddingInProgress(t){this.isCallAddingInProgress=t,this.context.emit("callAddingInProgressChanged",t)}get muteWhenJoin(){return this.muteWhenJoinEnabled}get isDND(){return this.isDNDEnabled}get speakerVolume(){return this.speakerVolumeValue}get microphoneInputLevel(){return this.microphoneInputLevelValue}get getActiveCalls(){return this.activeCalls}get hasActiveCalls(){return Object.values(this.extendedCalls).length>0}get getActiveRooms(){return this.activeRooms}get isMuted(){return this.muted}get getInputDeviceList(){return this.availableMediaDevices.filter(t=>t.kind==="audioinput")}get getOutputDeviceList(){return this.availableMediaDevices.filter(t=>t.kind==="audiooutput")}get getUserMediaConstraints(){return Eh()?{video:!1,audio:!0}:{audio:{deviceId:{exact:this.selectedMediaDevices.input}},video:!1}}get selectedInputDevice(){return this.selectedMediaDevices.input}get selectedOutputDevice(){return this.selectedMediaDevices.output}get activeStream(){return this.activeStreamValue}setAvailableMediaDevices(t){this.availableMediaDevices=t,this.context.emit("changeAvailableDeviceList",t)}async updateDeviceList(){await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);const t=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(t)}async initializeMediaDevices(){const t=localStorage.getItem(ba.SELECTED_INPUT_DEVICE)||"default",n=localStorage.getItem(ba.SELECTED_OUTPUT_DEVICE)||"default";try{const a=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints),o=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(o),await this.setMicrophone(t),await this.setSpeaker(n),navigator.mediaDevices.addEventListener("devicechange",async()=>{const s=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(s)}),a.getTracks().forEach(s=>s.stop())}catch(a){console.error(a)}}setCallTime(t){const n={...t};delete n.callId,this.callTime={...this.callTime,[t.callId]:n},this.context.emit("changeCallTime",this.callTime)}removeCallTime(t){const n={...this.callTime};delete n[t],this.callTime={...n},this.context.emit("changeCallTime",this.callTime)}setTimeInterval(t,n){this.timeIntervals={...this.timeIntervals,[t]:n}}removeTimeInterval(t){const n={...this.timeIntervals};n[t]&&(clearInterval(n[t]),delete n[t],this.timeIntervals={...n})}stopCallTimer(t){this.removeTimeInterval(t),this.removeCallTime(t)}emitVolumeChange(t,n){this.context.emit("changeCallVolume",{callId:t,volume:n})}setMetricsConfig(t){this.metricConfig={...this.metricConfig,...t}}sendDTMF(t,n){if(!/^[A-D0-9]+$/g.test(n))throw new Error("Not allowed character in DTMF input");this.extendedCalls[t].sendDTMF(n)}setIsMuted(t){this.muted=t,this.context.emit("changeIsMuted",t)}processMute(t){const n=this.currentActiveRoomId;this.setIsMuted(t),this.initialStreamValue.getTracks().forEach(a=>a.enabled=!t),this.roomReconfigure(n)}mute(){this.processMute(!0)}unmute(){this.processMute(!1)}async processHold({callId:t,toHold:n,automatic:a}){const o=this.extendedCalls[t];o._automaticHold=a??!1,await new Promise(d=>{const h=()=>{o.putOnHoldTimestamp=n?Date.now():void 0,d()};n?o.hold({},h):o.unhold({},h)}),this.updateCall(o);const r=Object.values(this.extendedCalls).filter(d=>d.roomId===this.currentActiveRoomId&&(n?t!==d._id:!0));r.length>1&&await this.doConference(r)}holdCall(t,n=!1){return this.processHold({callId:t,automatic:n,toHold:!0})}unholdCall(t){return this.processHold({callId:t,toHold:!1})}cancelAllOutgoingUnanswered(){Object.values(this.getActiveCalls).filter(t=>t.direction==="outgoing"&&t.status===Vv).forEach(t=>this.terminateCall(t._id))}answerCall(t){const n=this.extendedCalls[t];this.cancelAllOutgoingUnanswered(),n.answer(this.sipOptions),this.updateCall(n),this.setActiveRoom(n.roomId),n.connection.addEventListener("track",a=>{this.triggerAddStream(a,n)})}async moveCall(t,n){this.updateCallStatus({callId:t,isMoving:!0}),await this.processRoomChange({callId:t,roomId:n}),this.updateCallStatus({callId:t,isMoving:!1})}updateCall(t){this.activeCalls[t._id]=gh(t),this.context.emit("changeActiveCalls",this.activeCalls)}updateRoom(t){const a={...this.activeRooms[t.roomId],...t};this.activeRooms={...this.activeRooms,[t.roomId]:{...a}},this.context.emit("updateRoom",{room:a,roomList:this.activeRooms})}hasAutoAnswerHeaders(t){const n=/answer-after=0/,o=t.request.getHeader("Call-Info");return o&&n.test(o)}addCall(t,n=!0){this.activeCalls={...this.activeCalls,[t._id]:gh(t)},this.extendedCalls[t._id]=t,n&&this.context.emit("changeActiveCalls",this.activeCalls)}addCallStatus(t){this.callStatus={...this.callStatus,[t]:{isMoving:!1,isTransferring:!1,isMerging:!1}},this.context.emit("changeCallStatus",this.callStatus)}updateCallStatus(t){const a={...{...this.callStatus[t.callId]}};t.isMoving!==void 0&&(a.isMoving=t.isMoving),t.isTransferring!==void 0&&(a.isTransferring=t.isTransferring),t.isMerging!==void 0&&(a.isMerging=t.isMerging),this.callStatus={...this.callStatus,[t.callId]:{...a}},this.context.emit("changeCallStatus",this.callStatus)}removeCallStatus(t){const n={...this.callStatus};delete n[t],this.callStatus={...n},this.context.emit("changeCallStatus",this.callStatus)}addRoom(t){this.activeRooms={...this.activeRooms,[t.roomId]:t},this.context.emit("addRoom",{room:t,roomList:this.activeRooms})}getActiveStream(){const t=vh(this.initialStreamValue,this.microphoneInputLevel*2);return t.getTracks().forEach(n=>n.enabled=!this.isMuted),this.setActiveStream(t),t}async setMicrophone(t){if(!this.getInputDeviceList.find(({deviceId:a})=>a===t)||(this.setSelectedInputDevice(t),Object.keys(this.getActiveCalls).length===0))return;await this.setupStream();const n=Object.values(this.extendedCalls).filter(a=>a.roomId===this.currentActiveRoomId);n.length===1?Object.values(n).forEach(async a=>{const o=this.getActiveStream();a.connection.getSenders()[0].replaceTrack(o.getTracks()[0]),this.updateCall(a)}):await this.doConference(n)}setActiveStream(t){this.activeStream&&this.stopVUMeter("origin"),this.setupVUMeter(t,"origin"),this.activeStreamValue=t,this.context.emit("changeActiveStream",t)}async setSpeaker(t){if(!this.getOutputDeviceList.find(({deviceId:o})=>o===t))return;this.setSelectedOutputDevice(t);const n=Object.values(this.extendedCalls);if(n.length===0)return;const a=n.filter(o=>o.roomId===this.currentActiveRoomId);a.length===1?n.forEach(o=>{var s;(s=o.audioTag)==null||s.setSinkId(t),this.updateCall(o)}):await this.doConference(a)}removeRoom(t){const n={...this.activeRooms},a={...n[t]};delete n[t],this.activeRooms={...n},this.context.emit("removeRoom",{room:a,roomList:this.activeRooms})}deleteRoomIfEmpty(t){t!==void 0&&Object.values(this.extendedCalls).filter(n=>n.roomId===t).length===0&&(this.removeRoom(t),this.currentActiveRoomId===t&&(this.currentActiveRoomId=void 0))}checkInitialized(){if(!this.context.initialized)throw new Error("[OpenSIPSJS] You must call `start` method first!")}muteReconfigure(t){this.muted?t.mute({audio:!0}):t.unmute({audio:!0})}async roomReconfigure(t){var a;if(t===void 0)return;const n=Object.values(this.extendedCalls).filter(o=>o.roomId===t);if(this.currentActiveRoomId===t?n.forEach(o=>{o.audioTag&&(this.muteReconfigure(o),o.audioTag.muted=!1,this.updateCall(o))}):n.forEach(o=>{o.audioTag&&(o.audioTag.muted=!0,this.updateCall(o))}),n.length===0)this.deleteRoomIfEmpty(t);else if(n.length===1&&this.currentActiveRoomId!==t)n[0].isOnHold().local||await this.holdCall(n[0].id,!0);else if(n.length===1&&this.currentActiveRoomId===t){if(n[0].isOnHold().local&&n[0]._automaticHold&&await this.unholdCall(n[0].id),n[0].connection&&((a=n[0].connection)!=null&&a.getSenders()[0])){const o=this.getActiveStream();await n[0].connection.getSenders()[0].replaceTrack(o.getTracks()[0]),this.muteReconfigure(n[0])}}else n.length>1&&await this.doConference(n)}async doConference(t){const n=[];t.forEach(a=>{a!=null&&a.connection.getReceivers().forEach(o=>{n.push(o.track)})}),await JT.forEach(t,async a=>{var r;if(a==null)return;const o=new MediaStream,s=an.createMediaStreamDestination();if(a.connection.getReceivers().forEach(d=>{n.forEach(h=>{o.addTrack(d.track),d.track.id!==h.id&&an.createMediaStreamSource(new MediaStream([h])).connect(s)})}),t[0].roomId===this.currentActiveRoomId){const d=this.getActiveStream();an.createMediaStreamSource(d).connect(s)}(r=a.connection)!=null&&r.getSenders()[0]&&(await a.connection.getSenders()[0].replaceTrack(s.stream.getTracks()[0]),this.muteReconfigure(a))})}processCallerMute(t,n){const a=this.extendedCalls[t];a&&a.connection.getReceivers().length&&(a.localMuted=n,a.connection.getReceivers().forEach(o=>{o.track.enabled=!n}),this.updateCall(a))}muteCaller(t){this.processCallerMute(t,!0)}unmuteCaller(t){this.processCallerMute(t,!1)}terminateCall(t){const n=this.extendedCalls[t];n._status!==8&&n.terminate()}transferCall(t,n){if(n.toString().length===0)return new Error("Target must be passed");const a=this.extendedCalls[t];if(!a._is_confirmed&&!a._is_canceled){const o=`sip:${n}@${this.context.sipDomain}`;a.terminate({status_code:302,reason_phrase:"Moved Temporarily",extraHeaders:[`Contact: ${o}`]});return}this.updateCallStatus({callId:t,isTransferring:!0}),a.refer(`sip:${n}@${this.context.sipDomain}`),this.updateCall(a)}mergeCall(t){const n=Object.values(this.extendedCalls).filter(s=>s.roomId===t);if(n.length!==2)return;const a=n[0],o=n[1];!a||!o||(this.updateCallStatus({callId:a._id,isMerging:!0}),this.updateCallStatus({callId:o._id,isMerging:!0}),a.refer(o.remote_identity.uri.toString(),{replaces:o}),this.updateCall(a))}mergeCallByIds(t,n){const a=Object.values(this.extendedCalls).find(s=>s._id===t),o=Object.values(this.extendedCalls).find(s=>s._id===n);if(!a||!o)throw new Error("Call ID is not provided");this.updateCallStatus({callId:t,isMerging:!0}),this.updateCallStatus({callId:n,isMerging:!0}),a.refer(o.remote_identity.uri.toString(),{replaces:o}),this.updateCall(a)}setDND(t){this.isDNDEnabled=t,this.context.emit("changeIsDND",t)}startCallTimer(t){this.removeTimeInterval(t);const n={callId:t,hours:0,minutes:0,seconds:0,formatted:""};this.setCallTime(n);const a=setInterval(()=>{const o={...this.callTime[t]},s=YT(o);this.setCallTime({callId:t,...s})},1e3);this.setTimeInterval(t,a)}async setActiveRoom(t){const n=this.currentActiveRoomId;t!==n&&(this.currentActiveRoomId=t,await this.roomReconfigure(n),await this.roomReconfigure(t))}getNewRoomId(){const t=Object.keys(this.activeRooms);return t.length===0?1:parseInt(t.sort()[t.length-1])+1}async setupCall(t){var _,g;const n=t.session;if(this.getActiveCalls[n.id]!==void 0)return;const o=this.getNewRoomId(),s={started:new Date,incomingInProgress:!1,roomId:o};n.direction==="incoming"?(this.context.logger.log("New incoming call from",(g=(_=n._remote_identity)==null?void 0:_._uri)==null?void 0:g._user),s.incomingInProgress=!0,this.context.subscribe(Qt.CALL_CONFIRMED,T=>{n.id===T.id&&(this.updateRoom({incomingInProgress:!1,roomId:o}),this.startCallTimer(n.id))}),this.context.subscribe(Qt.CALL_FAILED,T=>{n.id===T.id&&(this.updateRoom({incomingInProgress:!1,roomId:o}),this.deleteRoomIfEmpty(o))})):n.direction==="outgoing"&&(n.once("confirmed",()=>{this.startCallTimer(n.id)}),this.startCallTimer(n.id));const r=n,d=this.hasAutoAnswerHeaders(t),h=r.direction==="incoming"&&!this.hasActiveCalls&&(d||this.autoAnswer);r.roomId=o,r.localMuted=!1,r.autoAnswer=h,h?this.addCall(r,!1):this.addCall(r),this.addCallStatus(n.id),this.addRoom(s),h&&this.answerCall(r._id)}removeCall(t){const n={...this.activeCalls};delete n[t],this.activeCalls={...n};const a={...this.extendedCalls};delete a[t],this.extendedCalls={...a},this.context.emit("changeActiveCalls",this.activeCalls)}activeCallListRemove(t){var o;const n=this.extendedCalls[t._id];this.stopVUMeter("origin"),(o=n.connection)==null||o.getSenders().forEach(s=>{s.track.stop()});const a=n.roomId;this.removeCall(t._id),this.roomReconfigure(a)}async newRTCSessionCallback(t){const n=t.session;if(this.isDND){n.terminate({status_code:486,reason_phrase:"Do Not Disturb"});return}if(this.context.triggerListener({listenerType:Qt.NEW_CALL,session:n,event:t}),n.on("ended",a=>{var s,r,d;this.stopVUMeter(n.id),this.context.logger.log("Session ended for",(r=(s=n._remote_identity)==null?void 0:s._uri)==null?void 0:r._user),this.context.triggerListener({listenerType:Qt.CALL_ENDED,session:n,event:a});const o=this.getActiveCalls[n.id];o&&this.activeCallListRemove(o),this.stopCallTimer(n.id),this.removeCallStatus(n.id),this.removeCallMetrics(n.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(d=this.initialStreamValue)==null||d.getTracks().forEach(h=>h.stop()),this.initialStreamValue=null)}),n.on("progress",a=>{var o,s;this.context.logger.log("Session in progress for",(s=(o=n._remote_identity)==null?void 0:o._uri)==null?void 0:s._user),this.context.triggerListener({listenerType:Qt.CALL_PROGRESS,session:n,event:a})}),n.on("failed",a=>{var s,r,d;this.stopVUMeter(n.id),this.context.logger.log("Session failed for",(r=(s=n._remote_identity)==null?void 0:s._uri)==null?void 0:r._user),this.context.triggerListener({listenerType:Qt.CALL_FAILED,session:n,event:a}),n.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0);const o=this.getActiveCalls[n.id];o&&this.activeCallListRemove(o),this.stopCallTimer(n.id),this.removeCallStatus(n.id),this.removeCallMetrics(n.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(d=this.initialStreamValue)==null||d.getTracks().forEach(h=>h.stop()),this.initialStreamValue=null)}),n.on("confirmed",a=>{var o,s;this.context.logger.log("Session confirmed for",(s=(o=n._remote_identity)==null?void 0:o._uri)==null?void 0:s._user),this.context.triggerListener({listenerType:Qt.CALL_CONFIRMED,session:n,event:a}),this.updateCall(n),n.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0)}),await this.setupCall(t),n.direction==="outgoing"){const a=this.getActiveCalls[n.id].roomId;this.setActiveRoom(a)}}setMuteWhenJoin(t){this.muteWhenJoinEnabled=t,this.context.emit("changeMuteWhenJoin",t)}setMicrophoneSensitivity(t){if(t<0||t>1)throw new Error("Value should be in range from 0 to 1!");this.microphoneInputLevelValue=t,this.roomReconfigure(this.currentActiveRoomId)}setSpeakerVolume(t){this.speakerVolumeValue=t,Object.values(this.extendedCalls).forEach(n=>{n.audioTag&&(n.audioTag.volume=t,this.updateCall(n))})}setAutoAnswer(t){this.isAutoAnswer=t}setSelectedInputDevice(t){localStorage.setItem(ba.SELECTED_INPUT_DEVICE,t),this.selectedMediaDevices.input=t,this.context.emit("changeActiveInputMediaDevice",t)}setSelectedOutputDevice(t){localStorage.setItem(ba.SELECTED_OUTPUT_DEVICE,t),this.selectedMediaDevices.output=t,this.context.emit("changeActiveOutputMediaDevice",t)}setCallMetrics(t){const n={...t};delete n.callId,this.callMetrics={...this.callMetrics,[t.callId]:n},this.context.emit("changeCallMetrics",this.callMetrics)}removeCallMetrics(t){const n={...this.callMetrics};delete n[t],this.callMetrics={...n},this.context.emit("changeCallMetrics",this.callMetrics)}getCallQuality(t){this.context.logger.log("LOG 1 before createProbe");const n=new Hv(this.metricConfig),a=n.createProbe(t.connection,{cid:t._id});this.context.logger.log("LOG 2 after createProbe");const o=[];let s;a.onreport=r=>{this.context.logger.log("LOG 3 in onreport"),Object.entries(r.audio).forEach(([_,g])=>{g.direction==="inbound"&&!o.includes(_)&&(o.push(_),s=_)});const d=r.audio[s];if(!d)return;const h=Fv(d,jv);h.callId=t._id,this.setCallMetrics(h)},this.context.subscribe(Qt.CALL_ENDED,r=>{r._id===t._id&&n.stopAllProbes()}),n.startAllProbes()}setupVUMeter(t,n){this.VUMeter.start(t,n)}stopVUMeter(t){this.VUMeter.stop(t)}async setupStream(){const t=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);this.initialStreamValue&&(this.initialStreamValue.getTracks().forEach(n=>n.stop()),this.initialStreamValue=null),this.initialStreamValue=t}async triggerAddStream(t,n){this.context.logger.log("LOG triggerAddStream 1"),this.setIsMuted(this.muteWhenJoin||this.isMuted),this.initialStreamValue||await this.setupStream();const a=vh(this.initialStreamValue,this.microphoneInputLevel*2),o=this.isMuted||this.muteWhenJoin;a.getTracks().forEach(r=>r.enabled=!o),this.setActiveStream(a),await n.connection.getSenders()[0].replaceTrack(a.getTracks()[0]),this.context.logger.log("LOG triggerAddStream 2");const s=new MediaStream([t.track]);this.context.logger.log("LOG triggerAddStream 3"),PT(s,n,this.selectedOutputDevice,this.speakerVolume),this.context.logger.log("LOG triggerAddStream 4"),this.setupVUMeter(s,n._id),this.context.logger.log("LOG triggerAddStream 5"),this.getCallQuality(n),this.updateCall(n)}initCall(t,n,a=!1){if(t.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${t}@${this.context.sipDomain}...`);const o=this.context.call(`sip:${t}@${this.context.sipDomain}`,this.sipOptions);if(this.callAddingInProgress=o.id,n&&this.currentActiveRoomId!==void 0&&(this.processRoomChange({callId:o.id,roomId:this.currentActiveRoomId}),a)){const s=Object.values(this.extendedCalls).filter(r=>r.roomId===this.currentActiveRoomId&&r._id!==o.id);for(const r of s)this.holdCall(r._id,!0)}o.connection.addEventListener("track",s=>{this.triggerAddStream(s,o)})}async processRoomChange({callId:t,roomId:n}){const a=this.extendedCalls[t].roomId;this.extendedCalls[t].roomId=n;const o=this.extendedCalls[t];return this.updateCall(o),await this.setActiveRoom(n),Promise.all([this.roomReconfigure(a),this.roomReconfigure(n)]).then(()=>{this.deleteRoomIfEmpty(a),this.deleteRoomIfEmpty(n)})}}class Gv{constructor(t){this.context=t}get sipOptions(){return{...this.context.options.sipOptions}}initCall(t,n){if(t.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${t}@${this.context.sipDomain}...`),this.context.joinVideoCall(`sip:${t}@${this.context.sipDomain}`,n,this.sipOptions)}stop(t={}){this.context.terminateJanusSessions(t)}startAudio(){this.context.enableJanusAudio(!0)}stopAudio(){this.context.enableJanusAudio(!1)}startVideo(){this.context.enableJanusVideo(!0)}stopVideo(){this.context.enableJanusVideo(!1)}changeMediaConstraints(t){this.context.changeMediaConstraints(t)}startScreenShare(){this.context.startScreenShare()}startBlur(){this.context.startBlur()}stopBlur(){this.context.stopBlur()}}class Wv{constructor(t){this.activeMessages={},this.extendedMessages={},this.msrpHistory={},this.context=t,this.context.on(this.context.newMSRPSessionEventName,this.newMSRPSessionCallback.bind(this.context))}get isMSRPInitializing(){return this.isMSRPInitializingValue}get getActiveMessages(){return this.activeMessages}msrpAnswer(t){const n=this.extendedMessages[t];this.updateMSRPSession(n)}updateMSRPSession(t){this.activeMessages[t._id]=Th(t),this.context.emit("changeActiveMessages",this.activeMessages)}addMMSRPSession(t){this.activeMessages={...this.activeMessages,[t._id]:Th(t)},this.extendedMessages[t._id]=t,this.context.emit("changeActiveMessages",this.activeMessages)}addMSRPMessage(t,n){const a=this.msrpHistory[n.id]||[];a.push(t),this.msrpHistory={...this.msrpHistory,[n.id]:[...a]},this.context.emit("newMSRPMessage",{message:t,session:n})}messageTerminate(t){const n=this.extendedMessages[t];n._status!==8&&n.terminate()}addMessageSession(t){if(!t._id||this.getActiveMessages[t._id]!==void 0)return;const a=t;this.addMMSRPSession(a)}triggerMSRPListener({listenerType:t,session:n,event:a}){const o=this.context.listenersList[t];!o||!o.length||o.forEach(s=>{s(n,a)})}removeMMSRPSession(t){const n={...this.activeMessages};delete n[t],this.activeMessages={...n};const a={...this.extendedMessages};delete a[t],this.extendedMessages={...a},this.context.emit("changeActiveMessages",this.activeMessages)}activeMessageListRemove(t){this.removeMMSRPSession(t._id)}newMSRPSessionCallback(t){const n=t.session;n.on("ended",a=>{this.triggerMSRPListener({listenerType:Qt.CALL_ENDED,session:n,event:a});const o=this.getActiveMessages[n.id];this.activeMessageListRemove(o)}),n.on("failed",a=>{this.triggerMSRPListener({listenerType:Qt.CALL_FAILED,session:n,event:a});const o=this.getActiveMessages[n.id];this.activeMessageListRemove(o)}),n.on("confirmed",a=>{this.triggerMSRPListener({listenerType:Qt.CALL_CONFIRMED,session:n,event:a}),this.updateMSRPSession(n)}),n.on("newMessage",a=>{this.addMSRPMessage(a,n)}),this.addMessageSession(n)}setIsMSRPInitializing(t){this.isMSRPInitializingValue=t,this.context.emit("isMSRPInitializingChanged",t)}initMSRP(t,n,a){if(t.length===0)return console.error("Target must be a valid string");const o=this.context.startMSRP(t,a);o.on("active",()=>{this.addMessageSession(o),o.sendMSRP(n),this.setIsMSRPInitializing(!1)}),this.setIsMSRPInitializing(!0)}sendMSRP(t,n){const a=this.extendedMessages[t];if(!a)throw new Error(`MSRP session with id ${t} doesn't exist!`);a.sendMSRP(n)}}const Ou={AUDIO:"audio",VIDEO:"video",MSRP:"msrp"};class kh{constructor(t){this.opensips=null,this.session=null,this.name=null,this.name=t}setOpensips(t){this.opensips=t}setSession(t){this.session=t}kill(){this.opensips.kill(this.name)}}class Mh extends kh{constructor(t,n){super(t),this._candidates=[],this._subscribeSent=!1,this._configureSent=!1,this._lastTrickleReceived=!1,this.type=n}connect(t={}){this.opaqueId=this.session.generateOpaqueId();const n=xe.cloneArray(t.extraHeaders),a={from_tag:this.session._from_tag};t.fromUserName&&(a.from_uri=new ln("sip",t.fromUserName,this.session._ua.configuration.uri.host),n.push(`P-Preferred-Identity: ${this.session._ua.configuration.uri.toString()}`)),t.fromDisplayName&&(a.from_display_name=t.fromDisplayName),n.push(`Contact: ${this.session._contact}`),n.push("Content-Type: application/json"),this.session._sessionTimers.enabled&&n.push(`Session-Expires: ${this.session._sessionTimers.defaultExpires}${this.session._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new Tt.InitialOutgoingInviteRequest(this.session.target,this.session._ua,a,n),this._createRTCConnection(),this._sendInitialRequest()}getStream(){return this.stream}getConnection(){return this._connection}_createRTCConnection(){this._connection=new RTCPeerConnection({iceServers:[{urls:"stun:turn.voicenter.co",credential:"kxsjahnsdjns3eds23esd",username:"turn2es21e"}]});let t;this._connection.onicecandidate=n=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||n.candidate&&(this._candidates.push(n.candidate),clearTimeout(t),t=setTimeout(()=>{this._lastTrickleReceived=!0,this._subscribeSent&&!this._configureSent&&this._sendConfigureMessage({audio:!0,video:!0})},500))}}addTracks(t){t.forEach(n=>{this._connection.addTrack(n)})}async _sendInitialRequest(){const t=new Kr(this.session._ua,this._request,{onRequestTimeout:()=>{this.session.onRequestTimeout()},onTransportError:()=>{this.session.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});if(await this.generateStream(),!this.stream||!this.stream.getTracks().length)return;this.addTracks(this.stream.getTracks());const n={audio:!1,video:!0};this.jsep_offer=await this._connection.createOffer(n),await this._connection.setLocalDescription(this.jsep_offer);const a={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaqueId},o=JSON.stringify(a);this._request.body=o,t.send()}_receiveInviteResponse(t){if(this._publisherSubscribeSent||!t.body)return;const n=JSON.parse(t.body);this.handleId=n.data.id;const a={janus:"message",body:{request:"join",room:this.session.room_id,ptype:"publisher",display:this.session.display_name+" (Screen Share)",opaque_id:this.opaqueId},handle_id:this.handleId},o=[this.session.getPTypeHeader(kt.PUBLISHER)];this.session.sendRequest(L.SUBSCRIBE,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{var r,d,h,_;if(s.status_code===200){if(this._subscribeSent=!0,s.body)try{const g=JSON.parse(s.body)||{};((d=(r=g.plugindata)==null?void 0:r.data)==null?void 0:d.videoroom)==="joined"&&this.session.myFeedList.push(g.plugindata.data.id),(_=(h=g.plugindata)==null?void 0:h.data)!=null&&_.publishers&&this.session.receivePublishers(g)}catch(g){console.error(g)}this._lastTrickleReceived&&!this._configureSent&&this._sendConfigureMessage({audio:!0,video:!0})}}}}),this._publisherSubscribeSent=!0}async _sendConfigureMessage(t){const n=this._candidates.map(r=>({janus:"trickle",candidate:r,handle_id:this.handleId,session_id:this.session.session_id})),o={configure:{janus:"message",body:{request:"configure",record:!0,filename:this.session.getRecordFileName(),...t},jsep:this.jsep_offer,handle_id:this.handleId,session_id:this.session.session_id},trickles:[...n]},s=["Content-Type: application/json",this.session.getPTypeHeader(kt.ICE)];this.session.sendRequest(L.INFO,{extraHeaders:s,body:JSON.stringify(o),eventHandlers:{onSuccessResponse:async r=>{this._configureSent=!0;const h=r.data.split(`\r
|
158
|
+
`,n),o===-1)return o;!c.substring(o+2,o+4).match(/(^\r\n)/)&&c.charAt(o+2).match(/(^\s+)/)?n=o+2:a=o}return a}function yT(c,t,n,a){let o;const s=t.indexOf(":",n),r=t.substring(n,s).trim(),d=t.substring(s+1,a).trim();switch(r.toLowerCase()){case"via":case"v":c.addHeader("via",d),c.getHeaders("via").length===1?(o=c.parseHeader("Via"),o&&(c.via=o,c.via_branch=o.branch)):o=0;break;case"from":case"f":c.setHeader("from",d),o=c.parseHeader("from"),o&&(c.from=o,c.from_tag=o.getParam("tag"));break;case"to":case"t":c.setHeader("to",d),o=c.parseHeader("to"),o&&(c.to=o,c.to_tag=o.getParam("tag"));break;case"record-route":if(o=yu.parse(d,"Record_Route"),o===-1)o=void 0;else for(const h of o)c.addHeader("record-route",d.substring(h.possition,h.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=h.parsed;break;case"call-id":case"i":c.setHeader("call-id",d),o=c.parseHeader("call-id"),o&&(c.call_id=d);break;case"contact":case"m":if(o=yu.parse(d,"Contact"),o===-1)o=void 0;else for(const h of o)c.addHeader("contact",d.substring(h.possition,h.offset)),c.headers.Contact[c.getHeaders("contact").length-1].parsed=h.parsed;break;case"content-length":case"l":c.setHeader("content-length",d),o=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",d),o=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",d),o=c.parseHeader("cseq"),o&&(c.cseq=o.value),c instanceof $n.IncomingResponse&&(c.method=o.method);break;case"max-forwards":c.setHeader("max-forwards",d),o=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",d),o=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",d),o=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",d),o=c.parseHeader("session-expires"),o&&(c.session_expires=o.expires,c.session_expires_refresher=o.refresher);break;case"refer-to":case"r":c.setHeader("refer-to",d),o=c.parseHeader("refer-to"),o&&(c.refer_to=o);break;case"replaces":c.setHeader("replaces",d),o=c.parseHeader("replaces"),o&&(c.replaces=o);break;case"event":case"o":c.setHeader("event",d),o=c.parseHeader("event"),o&&(c.event=o);break;default:c.addHeader(r,d),o=0}return o===void 0?{error:`error parsing header "${r}"`}:!0}const CT={parseMessage:ET},ni=new ra("Registrator"),Ca=10;class AT{constructor(t,n){this._reg_id=1,this._ua=t,this._transport=n,this._registrar=t.configuration.registrar_server,this._expires=t.configuration.register_expires,this._call_id=vs.createRandomToken(22),this._cseq=0,this._to_uri=t.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString();const a=this._contact.indexOf(">");if(a!==-1){const o=this._contact.slice(0,a)+this._contact.slice(a+1,this._contact.length);this._contact=o}this._extra_contact="",this._extraContactParams="",this._extra_contact+=";+sip.ice",this._extraHeaders=[],this._sipInstance=`"<urn:uuid:${this._ua.configuration.instance_id}>"`,this._extra_contact+=`;reg-id=${this._reg_id}`,this._extra_contact+=`;+sip.instance=${this._sipInstance}`}get registered(){return this._registered}setExtraHeaders(t){Array.isArray(t)||(t=[]),this._extraHeaders=t.slice()}setExtraContactParams(t){t instanceof Object||(t={}),this._extraContactParams="";for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)){const a=t[n];this._extraContactParams+=`;${n}`,a&&(this._extraContactParams+=`=${a}`)}}setExtraContactUriParams(t){t instanceof Object||(t={}),this._extraContactParams="";for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)){const a=t[n];this._extraContactParams+=`;${n}`,a&&(this._extraContactParams+=`=${a}`)}}register(){if(this._registering){ni.debug("Register request in progress...");return}const t=this._extraHeaders.slice();t.push(`Contact: ${this._contact}${this._extraContactParams}>${this._extra_contact};expires=${this._expires}`),t.push(`Expires: ${this._expires}`);const n=new Tt.OutgoingRequest(L.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),a=new Kr(this._ua,n,{onRequestTimeout:()=>{this._registrationFailure(null,L.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,L.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:o=>{if(o.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):{if(this._registering=!1,!o.hasHeader("Contact")){ni.debug("no Contact header in response to REGISTER, response ignored");break}const s=o.headers.Contact.reduce((_,g)=>_.concat(g.parsed),[]);let r=s.find(_=>this._sipInstance===_.getParam("+sip.instance")&&this._reg_id===parseInt(_.getParam("reg-id")));if(r||(r=s.find(_=>_.uri.user===this._ua.contact.uri.user)),!r){ni.debug("no Contact header pointing to us, response ignored");break}let d=r.getParam("expires");!d&&o.hasHeader("expires")&&(d=o.getHeader("expires")),d||(d=this._expires),d=Number(d),d<Ca&&(d=Ca);const h=d>64?d*1e3/2+Math.floor((d/2-32)*1e3*Math.random()):d*1e3-5e3;this._registrationTimer=setTimeout(()=>{this._registrationTimer=null,this._ua.listeners("registrationExpiring").length===0?this.register():this._ua.emit("registrationExpiring")},h),r.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),this._registered||(this._registered=!0,this._ua.registered({response:o}));break}case/^423$/.test(o.status_code):{o.hasHeader("min-expires")?(this._expires=Number(o.getHeader("min-expires")),this._expires<Ca&&(this._expires=Ca),this.register()):(ni.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(o,L.causes.SIP_FAILURE_CODE));break}default:{const s=vs.sipErrorCause(o.status_code);this._registrationFailure(o,s)}}}});this._registering=!0,a.send()}unregister(t={}){if(!this._registered){ni.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const n=this._extraHeaders.slice();t.all?n.push(`Contact: *${this._extraContactParams}`):n.push(`Contact: ${this._contact}${this._extraContactParams}>${this._extra_contact};expires=0`),n.push("Expires: 0");const a=new Tt.OutgoingRequest(L.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new Kr(this._ua,a,{onRequestTimeout:()=>{this._unregistered(null,L.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,L.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:s=>{switch(!0){case/^1[0-9]{2}$/.test(s.status_code):break;case/^2[0-9]{2}$/.test(s.status_code):this._unregistered(s);break;default:{const r=vs.sipErrorCause(s.status_code);this._unregistered(s,r)}}}}).send()}close(){this._registered&&this.unregister()}onTransportClosed(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}_registrationFailure(t,n){this._registering=!1,this._ua.registrationFailed({response:t||null,cause:n}),this._registered&&(this._registered=!1,this._ua.unregistered({response:t||null,cause:n}))}_unregistered(t,n){this._registering=!1,this._registered=!1,this._ua.unregistered({response:t||null,cause:n||null})}}const et=console,ks={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},RT=fT;class IT extends RT{constructor(t){super(t),this._msrp_sessions=[],this._transactions={nist:{},nict:{},ist:{},ict:{}},this._janus_sessions=[],this.newStreamPlugins=[],this.processStreamPlugins=[],this._registrator=new AT(this)}call(t,n){return super.call(t,n)}joinVideoCall(t,n,a){et.debug("call()");const o=new Sa(this);return o.configureMedia({audio:!0,video:!0}),o.connect(t,n,a),o}startScreenShare(){et.debug("startScreenShare()");for(const t in this._janus_sessions)this._janus_sessions[t].connectScreenShare()}changeMediaConstraints(t){for(const n in this._janus_sessions)this._janus_sessions[n].changeMediaConstraints(t)}startBlur(){for(const t in this._janus_sessions)this._janus_sessions[t].connectBlur()}stopBlur(){for(const t in this._janus_sessions)this._janus_sessions[t].stopBlur()}_loadConfig(t){try{si.load(this._configuration,t)}catch(s){throw s}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=vs.newUUID());let n;typeof window<"u"&&typeof window.document<"u"?n=window==null?void 0:window.navigator.userAgent:typeof self<"u"&&self.navigator&&(n=self.navigator.userAgent),n+=" "+De.USER_AGENT,this._configuration.user_agent=t.overrideUserAgent&&typeof t.overrideUserAgent=="function"?t.overrideUserAgent(n):n,this._configuration.jssip_id=vs.createRandomToken(5);const a=this._configuration.uri.clone();a.user=null,this._configuration.hostport_params=a.toString().replace(/^sip:/i,"");try{this._transport=new Lg(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=bT.bind(this),this._transport.onconnect=wT.bind(this),this._transport.ondisconnect=OT.bind(this),this._transport.ondata=DT.bind(this)}catch(s){throw et.warn(s),new Ns.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){const s=this._configuration.uri.clone();s.user=null,s.clearParams(),s.clearHeaders(),this._configuration.registrar_server=s}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new ln("sip",vs.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(s={}){const r=s.anonymous||null,d=s.outbound||null;let h="<";return r?h+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":h+=this.pub_gruu||this.uri.toString(),d&&(r?!this.temp_gruu:!this.pub_gruu)&&(h+=";ob"),h+=">",h}};const o=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const s in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,s)&&(o.indexOf(s)!==-1?Object.defineProperty(this._configuration,s,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,s,{writable:!1,configurable:!1}));et.debug("configuration parameters after validation:");for(const s in this._configuration)if(Object.prototype.hasOwnProperty.call(si.settings,s))switch(s){case"uri":case"registrar_server":et.debug(`- ${s}: ${this._configuration[s]}`);break;case"password":case"ha1":case"authorization_jwt":et.debug(`- ${s}: NOT SHOWN`);break;default:et.debug(`- ${s}: ${JSON.stringify(this._configuration[s])}`)}}newMSRPSession(t,n){t.on("msgHistoryUpdate",a=>{console.log(a)}),this._msrp_sessions[t.id]=t,this.emit("newMSRPSession",n)}newJanusSession(t,n){this._janus_sessions[t.id]=t,this.newStreamPlugins.forEach(a=>{a.setSession(t)}),this.processStreamPlugins.forEach(a=>{a.setSession(t)}),this.emit("newJanusSession",n)}kill(){}destroyMSRPSession(t){delete this._msrp_sessions[t.id]}destroyJanusSession(t){delete this._janus_sessions[t.id]}receiveRequest(t){var s,r,d,h;const n=t.method;if(t.ruri.user!==this._configuration.uri.user&&t.ruri.user!==this._contact.uri.user){et.debug("Request-URI does not point to us"),t.method!==De.ACK&&t.reply_sl(404);return}if(t.ruri.scheme===De.SIPS){t.reply_sl(416);return}if(jt.checkTransaction(this,t))return;if(n===De.INVITE?new jt.InviteServerTransaction(this,this._transport,t):n!==De.ACK&&n!==De.CANCEL&&new jt.NonInviteServerTransaction(this,this._transport,t),n===De.OPTIONS){if(this.listeners("newOptions").length===0){t.reply(200);return}new yf.Options(this).init_incoming(t)}else if(n===De.MESSAGE){if(this.listeners("newMessage").length===0){t.reply(405);return}new yf.Message(this).init_incoming(t)}else if(n===De.INVITE&&!t.to_tag&&this.listeners("newRTCSession").length===0){t.reply(405);return}let a,o;if(t.to_tag)if(a=this._findDialog(t.call_id,t.from_tag,t.to_tag),a)a.receiveRequest(t);else if(n===De.NOTIFY)if(o=this._findSession(t),o)o.receiveRequest(t);else{if(t.body)try{const _=JSON.parse(t.body)||{};(r=(s=_.plugindata)==null?void 0:s.data)!=null&&r.publishers&&Object.values(this._janus_sessions)[0].receivePublishers(_),(h=(d=_.plugindata)==null?void 0:d.data)!=null&&h.unpublished&&Object.values(this._janus_sessions)[0].receiveUnpublished(_.plugindata.data.unpublished)}catch(_){console.error(_)}t.reply(200)}else n!==De.ACK&&t.reply(481);else switch(n){case De.INVITE:if(window.RTCPeerConnection)if(t.hasHeader("replaces")){const _=t.replaces;a=this._findDialog(_.call_id,_.from_tag,_.to_tag),a?(o=a.owner,o.isEnded()?t.reply(603):o.receiveRequest(t)):t.reply(481)}else t.body.search(/MSRP/ig)>-1?(o=new Su(this),o.init_incoming(t)):t.body.search(/JANUS/ig)>-1||(o=new Sg(this),o.init_incoming(t));else et.warn("INVITE received but WebRTC is not supported"),t.reply(488);break;case De.BYE:t.reply(481);break;case De.CANCEL:o=this._findSession(t),o?o.receiveRequest(t):et.debug("received CANCEL request for a non existent session");break;case De.ACK:break;case De.NOTIFY:this.emit("sipEvent",{event:t.event,request:t}),t.reply(200);break;default:t.reply(405);break}}startMSRP(t,n){et.debug("startMSRP()",n);const a=new Su(this);return a.connect(t),a}startJanus(t,n){et.debug("startJanus()",n);const a=new Su(this);return a.connect(t),a}terminateMSRPSessions(t){et.debug("terminateSessions()");for(const n in this._msrp_sessions)this._msrp_sessions[n].isEnded()||this._msrp_sessions[n].terminate(t)}terminateJanusSessions(t){et.debug("terminateSessions()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||this._janus_sessions[n].terminate(t)}enableJanusAudio(t){et.debug("enableJanusAudio()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||(t?this._janus_sessions[n].startAudio():this._janus_sessions[n].stopAudio())}enableJanusVideo(t){et.debug("enableJanusVideo()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||(t?this._janus_sessions[n].startVideo():this._janus_sessions[n].stopVideo())}stop(){if(et.debug("stop()"),this._dynConfiguration={},this._status===ks.STATUS_USER_CLOSED){et.debug("UA already closed");return}this._registrator.close();const t=Object.keys(this._sessions).length;for(const a in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,a)){et.debug(`closing session ${a}`);try{this._sessions[a].terminate()}catch(o){console.error(o)}}for(const a in this._msrp_sessions)if(Object.prototype.hasOwnProperty.call(this._msrp_sessions,a)){et.debug(`closing session ${a}`);try{this._msrp_sessions[a].terminate()}catch(o){console.error(o)}}for(const a in this._janus_sessions)if(Object.prototype.hasOwnProperty.call(this._janus_sessions,a)){et.debug(`closing session ${a}`);try{this._janus_sessions[a].terminate()}catch(o){console.error(o)}}for(const a in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,a))try{this._applicants[a].close()}catch(o){console.error(o)}this._status=ks.STATUS_USER_CLOSED,Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length===0&&t===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}}function bT(c){this.emit("connecting",c)}function wT(c){this._status!==ks.STATUS_USER_CLOSED&&(this._status=ks.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function OT(c){const t=["nict","ict","nist","ist"];for(const n of t)for(const a in this._transactions[n])Object.prototype.hasOwnProperty.call(this._transactions[n],a)&&this._transactions[n][a].onTransportError();this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==ks.STATUS_USER_CLOSED&&(this._status=ks.STATUS_NOT_READY,this._error=ks.NETWORK_ERROR)}function DT(c){const t=c.transport;let n=c.message;if(n=CT.parseMessage(n,this),!!n&&!(this._status===ks.STATUS_USER_CLOSED&&n instanceof $n.IncomingRequest)&&Qg(n,this,t)){if(n instanceof $n.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof $n.IncomingResponse){let a;switch(n.method){case De.INVITE:a=this._transactions.ict[n.via_branch],a&&a.receiveResponse(n);break;case De.ACK:break;default:a=this._transactions.nict[n.via_branch],a&&a.receiveResponse(n);break}}}}const NT=["roomId","_audioMuted","_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","_localHold","_videoMuted","status","start_time","_remote_identity","audioTag","isOnHold","localMuted","autoAnswer","putOnHoldTimestamp"],UT=["_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","status","start_time","_remote_identity","target_addr"];function gh(c){const t={};return NT.forEach(n=>{c[n]!==void 0&&(t[n]=c[n])}),t.localHold=c._localHold,t}function Th(c){const t={};return UT.forEach(n=>{c[n]!==void 0&&(t[n]=c[n])}),t}function vh(c,t){const n=new AudioContext,a=n.createMediaStreamSource(c),o=n.createMediaStreamDestination(),s=n.createGain();return a.connect(s),s.connect(o),s.gain.value=t,o.stream}function PT(c,t,n,a){if(Eh())return;const o=document.createElement("audio");o.id=t._id,o.className="audioTag",o.srcObject=c,o.setSinkId(n),o.volume=a,o.play(),t.audioTag=o}function xT(c){if(c&&typeof c.log=="function"&&typeof c.warn=="function"&&typeof c.error=="function")return!0}function Eh(){return/Mobi|react-native|Android|iPhone/i.test(navigator.userAgent)}const kT=at,MT=Jt(),Ot=new kT("WebSocketInterface");var LT=class{constructor(t){Ot.debug('new() [url:"%s"]',t),this._url=t,this._sip_uri=null,this._via_transport=null,this._ws=null;const n=MT.parse(t,"absoluteURI");if(n===-1)throw Ot.warn(`invalid WebSocket URI: ${t}`),new TypeError(`Invalid argument: ${t}`);if(n.scheme!=="wss"&&n.scheme!=="ws")throw Ot.warn(`invalid WebSocket URI scheme: ${n.scheme}`),new TypeError(`Invalid argument: ${t}`);this._sip_uri=`sip:${n.host}${n.port?`:${n.port}`:""};transport=ws`,this._via_transport=n.scheme.toUpperCase()}get via_transport(){return this._via_transport}set via_transport(t){this._via_transport=t.toUpperCase()}get sip_uri(){return this._sip_uri}get url(){return this._url}connect(){if(Ot.debug("connect()"),this.isConnected()){Ot.debug(`WebSocket ${this._url} is already connected`);return}else if(this.isConnecting()){Ot.debug(`WebSocket ${this._url} is connecting`);return}this._ws&&this.disconnect(),Ot.debug(`connecting to WebSocket ${this._url}`);try{this._ws=new WebSocket(this._url,"sip"),this._ws.binaryType="arraybuffer",this._ws.onopen=this._onOpen.bind(this),this._ws.onclose=this._onClose.bind(this),this._ws.onmessage=this._onMessage.bind(this),this._ws.onerror=this._onError.bind(this)}catch(t){this._onError(t)}}disconnect(){Ot.debug("disconnect()"),this._ws&&(this._ws.onopen=()=>{},this._ws.onclose=()=>{},this._ws.onmessage=()=>{},this._ws.onerror=()=>{},this._ws.close(),this._ws=null)}send(t){return Ot.debug("send()"),this.isConnected()?(this._ws.send(t),!0):(Ot.warn("unable to send message, WebSocket is not open"),!1)}isConnected(){return this._ws&&this._ws.readyState===this._ws.OPEN}isConnecting(){return this._ws&&this._ws.readyState===this._ws.CONNECTING}_onOpen(){Ot.debug(`WebSocket ${this._url} connected`),this.onconnect()}_onClose({wasClean:t,code:n,reason:a}){Ot.debug(`WebSocket ${this._url} closed`),t===!1&&Ot.debug("WebSocket abrupt disconnection"),this.ondisconnect(!t,n,a)}_onMessage({data:t}){Ot.debug("received WebSocket message"),this.ondata(t)}_onError(t){Ot.warn(`WebSocket ${this._url} error: `,t)}};const Cu=vl,$T=De,HT=Ts,FT=mt(),jT=_h,qT=ps(),VT=Vo(),BT=Jt(),GT=LT;Un("JsSIP")("version %s",Cu.version);var WT={C:$T,Exceptions:HT,Utils:FT,UA:jT,URI:qT,NameAddrHeader:VT,WebSocketInterface:GT,Grammar:BT,debug:Un,get name(){return Cu.title},get version(){return Cu.version}};const KT=Me(WT);function Au(c){return c<10?`0${c}`:`${c}`}function YT(c){let t=c.hours||0,n=c.minutes||0,a=c.seconds||0;a++,a===60&&(a=0,n++,n===60&&(n=0,t++));const o=`${Au(t)}:${Au(n)}:${Au(a)}`;return{seconds:a,minutes:n,hours:t,formatted:o}}var yt={};yt.forEach=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)if(o in c){const s=Promise.resolve(c[o]).then(r=>t.call(n||globalThis,r,o,c));a.push(s)}await Promise.all(a)},yt.forEachSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)a in c&&await t.call(n||globalThis,await c[a],a,c)},yt.map=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)o in c&&(a[o]=Promise.resolve(c[o]).then(s=>t.call(n||globalThis,s,o,c)));return Promise.all(a)},yt.mapSeries=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)o in c&&(a[o]=await t.call(n||globalThis,await c[o],o,c));return a},yt.find=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a();let s=1;for(let r=0;r<c.length;r++){const d=h=>{h?a(c[r]):s===c.length&&a(),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}}),yt.findSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(await t.call(n||globalThis,await c[a],a,c))return c[a]},yt.findIndex=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a(-1);let s=1;for(let r=0;r<c.length;r++){const d=h=>{h?a(r):s===c.length&&a(-1),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}}),yt.findIndexSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(await t.call(n||globalThis,await c[a],a,c))return a},yt.some=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a(!1);let s=1;for(let r=0;r<c.length;r++){if(!(r in c)){s++;continue}const d=h=>{h?a(!0):s===c.length&&a(!1),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}}),yt.someSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(a in c&&await t.call(n||globalThis,await c[a],a,c))return!0;return!1},yt.every=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a(!0);let s=1;for(let r=0;r<c.length;r++){if(!(r in c)){s++;continue}const d=h=>{h?s===c.length&&a(!0):a(!1),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}}),yt.everySeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(a in c&&!await t.call(n||globalThis,await c[a],a,c))return!1;return!0},yt.filter=(c,t,n)=>new Promise(async(a,o)=>{const s=[];for(let d=0;d<c.length;d++)d in c&&(s[d]=Promise.resolve(c[d]).then(h=>t.call(n||globalThis,h,d,c)).catch(o));const r=[];for(let d=0;d<s.length;d++)await s[d]&&r.push(await c[d]);a(r)}),yt.filterSeries=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)o in c&&await t.call(n||globalThis,await c[o],o,c)&&a.push(await c[o]);return a},yt.reduce=async(c,t,n)=>{if(c.length===0&&n===void 0)throw TypeError("Reduce of empty array with no initial value");let a,o;for(n!==void 0?(o=n,a=0):(o=c[0],a=1),a;a<c.length;a++)a in c&&(o=await t(await o,await c[a],a,c));return o};var Sh={};(function(c){const t=yt;Object.keys(t).forEach(n=>{const a=n.charAt(0).toUpperCase()+n.slice(1);c[`async${a}`]=async function(...o){return t[n](this,...o)}})})(Sh);var JT=Object.assign(yt,{instanceMethods:Sh});const an=new AudioContext,Qt={NEW_CALL:"new_call",CALL_CONFIRMED:"confirmed",CALL_FAILED:"failed",CALL_PROGRESS:"progress",CALL_ENDED:"ended"};var zT={exports:{}};(function(c){var t=function(n){var a=Object.prototype,o=a.hasOwnProperty,s=Object.defineProperty||function(ee,Y,G){ee[Y]=G.value},r,d=typeof Symbol=="function"?Symbol:{},h=d.iterator||"@@iterator",_=d.asyncIterator||"@@asyncIterator",g=d.toStringTag||"@@toStringTag";function T(ee,Y,G){return Object.defineProperty(ee,Y,{value:G,enumerable:!0,configurable:!0,writable:!0}),ee[Y]}try{T({},"")}catch{T=function(Y,G,re){return Y[G]=re}}function E(ee,Y,G,re){var ge=Y&&Y.prototype instanceof oe?Y:oe,be=Object.create(ge.prototype),ke=new P(re||[]);return s(be,"_invoke",{value:J(ee,G,ke)}),be}n.wrap=E;function y(ee,Y,G){try{return{type:"normal",arg:ee.call(Y,G)}}catch(re){return{type:"throw",arg:re}}}var C="suspendedStart",A="suspendedYield",I="executing",H="completed",$={};function oe(){}function N(){}function j(){}var Se={};T(Se,h,function(){return this});var ve=Object.getPrototypeOf,k=ve&&ve(ve(se([])));k&&k!==a&&o.call(k,h)&&(Se=k);var D=j.prototype=oe.prototype=Object.create(Se);N.prototype=j,s(D,"constructor",{value:j,configurable:!0}),s(j,"constructor",{value:N,configurable:!0}),N.displayName=T(j,g,"GeneratorFunction");function B(ee){["next","throw","return"].forEach(function(Y){T(ee,Y,function(G){return this._invoke(Y,G)})})}n.isGeneratorFunction=function(ee){var Y=typeof ee=="function"&&ee.constructor;return Y?Y===N||(Y.displayName||Y.name)==="GeneratorFunction":!1},n.mark=function(ee){return Object.setPrototypeOf?Object.setPrototypeOf(ee,j):(ee.__proto__=j,T(ee,g,"GeneratorFunction")),ee.prototype=Object.create(D),ee},n.awrap=function(ee){return{__await:ee}};function V(ee,Y){function G(be,ke,Re,le){var ye=y(ee[be],ee,ke);if(ye.type==="throw")le(ye.arg);else{var lt=ye.arg,ot=lt.value;return ot&&typeof ot=="object"&&o.call(ot,"__await")?Y.resolve(ot.__await).then(function(Ee){G("next",Ee,Re,le)},function(Ee){G("throw",Ee,Re,le)}):Y.resolve(ot).then(function(Ee){lt.value=Ee,Re(lt)},function(Ee){return G("throw",Ee,Re,le)})}}var re;function ge(be,ke){function Re(){return new Y(function(le,ye){G(be,ke,le,ye)})}return re=re?re.then(Re,Re):Re()}s(this,"_invoke",{value:ge})}B(V.prototype),T(V.prototype,_,function(){return this}),n.AsyncIterator=V,n.async=function(ee,Y,G,re,ge){ge===void 0&&(ge=Promise);var be=new V(E(ee,Y,G,re),ge);return n.isGeneratorFunction(Y)?be:be.next().then(function(ke){return ke.done?ke.value:be.next()})};function J(ee,Y,G){var re=C;return function(be,ke){if(re===I)throw new Error("Generator is already running");if(re===H){if(be==="throw")throw ke;return it()}for(G.method=be,G.arg=ke;;){var Re=G.delegate;if(Re){var le=F(Re,G);if(le){if(le===$)continue;return le}}if(G.method==="next")G.sent=G._sent=G.arg;else if(G.method==="throw"){if(re===C)throw re=H,G.arg;G.dispatchException(G.arg)}else G.method==="return"&&G.abrupt("return",G.arg);re=I;var ye=y(ee,Y,G);if(ye.type==="normal"){if(re=G.done?H:A,ye.arg===$)continue;return{value:ye.arg,done:G.done}}else ye.type==="throw"&&(re=H,G.method="throw",G.arg=ye.arg)}}}function F(ee,Y){var G=Y.method,re=ee.iterator[G];if(re===r)return Y.delegate=null,G==="throw"&&ee.iterator.return&&(Y.method="return",Y.arg=r,F(ee,Y),Y.method==="throw")||G!=="return"&&(Y.method="throw",Y.arg=new TypeError("The iterator does not provide a '"+G+"' method")),$;var ge=y(re,ee.iterator,Y.arg);if(ge.type==="throw")return Y.method="throw",Y.arg=ge.arg,Y.delegate=null,$;var be=ge.arg;if(!be)return Y.method="throw",Y.arg=new TypeError("iterator result is not an object"),Y.delegate=null,$;if(be.done)Y[ee.resultName]=be.value,Y.next=ee.nextLoc,Y.method!=="return"&&(Y.method="next",Y.arg=r);else return be;return Y.delegate=null,$}B(D),T(D,g,"Generator"),T(D,h,function(){return this}),T(D,"toString",function(){return"[object Generator]"});function Z(ee){var Y={tryLoc:ee[0]};1 in ee&&(Y.catchLoc=ee[1]),2 in ee&&(Y.finallyLoc=ee[2],Y.afterLoc=ee[3]),this.tryEntries.push(Y)}function U(ee){var Y=ee.completion||{};Y.type="normal",delete Y.arg,ee.completion=Y}function P(ee){this.tryEntries=[{tryLoc:"root"}],ee.forEach(Z,this),this.reset(!0)}n.keys=function(ee){var Y=Object(ee),G=[];for(var re in Y)G.push(re);return G.reverse(),function ge(){for(;G.length;){var be=G.pop();if(be in Y)return ge.value=be,ge.done=!1,ge}return ge.done=!0,ge}};function se(ee){if(ee){var Y=ee[h];if(Y)return Y.call(ee);if(typeof ee.next=="function")return ee;if(!isNaN(ee.length)){var G=-1,re=function ge(){for(;++G<ee.length;)if(o.call(ee,G))return ge.value=ee[G],ge.done=!1,ge;return ge.value=r,ge.done=!0,ge};return re.next=re}}return{next:it}}n.values=se;function it(){return{value:r,done:!0}}return P.prototype={constructor:P,reset:function(ee){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(U),!ee)for(var Y in this)Y.charAt(0)==="t"&&o.call(this,Y)&&!isNaN(+Y.slice(1))&&(this[Y]=r)},stop:function(){this.done=!0;var ee=this.tryEntries[0],Y=ee.completion;if(Y.type==="throw")throw Y.arg;return this.rval},dispatchException:function(ee){if(this.done)throw ee;var Y=this;function G(le,ye){return be.type="throw",be.arg=ee,Y.next=le,ye&&(Y.method="next",Y.arg=r),!!ye}for(var re=this.tryEntries.length-1;re>=0;--re){var ge=this.tryEntries[re],be=ge.completion;if(ge.tryLoc==="root")return G("end");if(ge.tryLoc<=this.prev){var ke=o.call(ge,"catchLoc"),Re=o.call(ge,"finallyLoc");if(ke&&Re){if(this.prev<ge.catchLoc)return G(ge.catchLoc,!0);if(this.prev<ge.finallyLoc)return G(ge.finallyLoc)}else if(ke){if(this.prev<ge.catchLoc)return G(ge.catchLoc,!0)}else if(Re){if(this.prev<ge.finallyLoc)return G(ge.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(ee,Y){for(var G=this.tryEntries.length-1;G>=0;--G){var re=this.tryEntries[G];if(re.tryLoc<=this.prev&&o.call(re,"finallyLoc")&&this.prev<re.finallyLoc){var ge=re;break}}ge&&(ee==="break"||ee==="continue")&&ge.tryLoc<=Y&&Y<=ge.finallyLoc&&(ge=null);var be=ge?ge.completion:{};return be.type=ee,be.arg=Y,ge?(this.method="next",this.next=ge.finallyLoc,$):this.complete(be)},complete:function(ee,Y){if(ee.type==="throw")throw ee.arg;return ee.type==="break"||ee.type==="continue"?this.next=ee.arg:ee.type==="return"?(this.rval=this.arg=ee.arg,this.method="return",this.next="end"):ee.type==="normal"&&Y&&(this.next=Y),$},finish:function(ee){for(var Y=this.tryEntries.length-1;Y>=0;--Y){var G=this.tryEntries[Y];if(G.finallyLoc===ee)return this.complete(G.completion,G.afterLoc),U(G),$}},catch:function(ee){for(var Y=this.tryEntries.length-1;Y>=0;--Y){var G=this.tryEntries[Y];if(G.tryLoc===ee){var re=G.completion;if(re.type==="throw"){var ge=re.arg;U(G)}return ge}}throw new Error("illegal catch attempt")},delegateYield:function(ee,Y,G){return this.delegate={iterator:se(ee),resultName:Y,nextLoc:G},this.method==="next"&&(this.arg=r),$}},n}(c.exports);try{regeneratorRuntime=t}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}})(zT);var yh={exports:{}};(function(c){(function(t,n){c.exports?c.exports=n():t.log=n()})(Mt,function(){var t=function(){},n="undefined",a=typeof window!==n&&typeof window.navigator!==n&&/Trident\/|MSIE /.test(window.navigator.userAgent),o=["trace","debug","info","warn","error"];function s(A,I){var H=A[I];if(typeof H.bind=="function")return H.bind(A);try{return Function.prototype.bind.call(H,A)}catch{return function(){return Function.prototype.apply.apply(H,[A,arguments])}}}function r(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function d(A){return A==="debug"&&(A="log"),typeof console===n?!1:A==="trace"&&a?r:console[A]!==void 0?s(console,A):console.log!==void 0?s(console,"log"):t}function h(A,I){for(var H=0;H<o.length;H++){var $=o[H];this[$]=H<A?t:this.methodFactory($,A,I)}this.log=this.debug}function _(A,I,H){return function(){typeof console!==n&&(h.call(this,I,H),this[A].apply(this,arguments))}}function g(A,I,H){return d(A)||_.apply(this,arguments)}function T(A,I,H){var $=this,oe;I=I??"WARN";var N="loglevel";typeof A=="string"?N+=":"+A:typeof A=="symbol"&&(N=void 0);function j(D){var B=(o[D]||"silent").toUpperCase();if(!(typeof window===n||!N)){try{window.localStorage[N]=B;return}catch{}try{window.document.cookie=encodeURIComponent(N)+"="+B+";"}catch{}}}function Se(){var D;if(!(typeof window===n||!N)){try{D=window.localStorage[N]}catch{}if(typeof D===n)try{var B=window.document.cookie,V=B.indexOf(encodeURIComponent(N)+"=");V!==-1&&(D=/^([^;]+)/.exec(B.slice(V))[1])}catch{}return $.levels[D]===void 0&&(D=void 0),D}}function ve(){if(!(typeof window===n||!N)){try{window.localStorage.removeItem(N);return}catch{}try{window.document.cookie=encodeURIComponent(N)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}$.name=A,$.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},$.methodFactory=H||g,$.getLevel=function(){return oe},$.setLevel=function(D,B){if(typeof D=="string"&&$.levels[D.toUpperCase()]!==void 0&&(D=$.levels[D.toUpperCase()]),typeof D=="number"&&D>=0&&D<=$.levels.SILENT){if(oe=D,B!==!1&&j(D),h.call($,D,A),typeof console===n&&D<$.levels.SILENT)return"No console available for logging"}else throw"log.setLevel() called with invalid level: "+D},$.setDefaultLevel=function(D){I=D,Se()||$.setLevel(D,!1)},$.resetLevel=function(){$.setLevel(I,!1),ve()},$.enableAll=function(D){$.setLevel($.levels.TRACE,D)},$.disableAll=function(D){$.setLevel($.levels.SILENT,D)};var k=Se();k==null&&(k=I),$.setLevel(k,!1)}var E=new T,y={};E.getLogger=function(I){if(typeof I!="symbol"&&typeof I!="string"||I==="")throw new TypeError("You must supply a name when creating a logger.");var H=y[I];return H||(H=y[I]=new T(I,E.getLevel(),E.methodFactory)),H};var C=typeof window!==n?window.log:void 0;return E.noConflict=function(){return typeof window!==n&&window.log===E&&(window.log=C),E},E.getLoggers=function(){return y},E.default=E,E})})(yh);var It=yh.exports;const Es=()=>`${new Date().toISOString()} | metrics`,Ss=(c,t,n)=>`${c} | ${t} | ${n}`;It.setDefaultLevel(It.levels.TRACE);const XT=c=>{It.info(Ss(Es(),"log ",`set log level to ${c?"verbose":"info"}`)),It.setLevel(c?It.levels.TRACE:It.levels.INFO)},QT=c=>{const t=[...Object.keys(It.levels)];t.includes(c)?(It.info(Ss(Es(),"log ",`update log level to ${c.toLowerCase()}`)),It.setLevel(c)):It.warn(Ss(Es(),"log ","Incorrect log level please choose one of "),t)},Pe=(c,t,n)=>{n?It.debug(Ss(Es(),c,t),n):It.debug(Ss(Es(),c,t))},Ru=(c,t)=>{It.info(Ss(Es(),c,t))},on=(c,t)=>{It.info(Ss(Es(),c,t))},Aa=(c,t)=>{It.warn(Ss(Es(),c,t))},Vn=(c,t)=>{It.error(Ss(Es(),c,t))};function ZT(c){return Math.floor(Math.random()*c).toString()}function Ch(c,t){let n=t;return c.forEach(a=>{n=n.replace(a,"")}),n}function ev(c,t){let n="";for(let a=0;a<t;a+=1)n+=c[ZT(c.length)];return n}function tv({length:c=20,useLetters:t=!0,useNumbers:n=!0,includeSymbols:a=[],excludeSymbols:o=[]}={}){let s="abcdefghijklmnopqrstuvwxyz",r="0123456789",d=[],h=[],_=[];return t&&(o.length&&(s=Ch(o,s)),h=s.split("")),n&&(o.length&&(r=Ch(o,r)),_=r.split("")),d=[...h,..._,...a],ev(d,c)}var sv=tv;const ri=Me(sv),nv=()=>"WebRTCMetrics",rv=()=>"5.0.3",$e={INBOUND:"inbound",OUTBOUND:"outbound"},ys={IDLE:"idle",RUNNING:"running",MUTED:"muted"},ii={NEW:"new",CHECKING:"checking",CONNECTED:"connected",COMPLETED:"completed",DISCONNECTED:"disconnected",FAILED:"failed",CLOSED:"closed"},iv=()=>({...{delta_time_to_measure_probes_ms:0,delta_time_consumed_to_measure_ms:0,delta_KBytes_in:0,delta_KBytes_out:0,delta_kbs_in:0,delta_kbs_out:0,total_time_decoded_in:0,total_time_encoded_out:0,probes:[]}}),Ah={level_in:0,codec_id_in:"",codec_in:{mime_type:null,clock_rate:null,sdp_fmtp_line:null},delta_jitter_ms_in:0,percent_packets_lost_in:0,delta_packets_in:0,delta_packets_lost_in:0,total_packets_in:0,total_packets_lost_in:0,total_KBytes_in:0,delta_KBytes_in:0,delta_kbs_in:0,mos_in:0,mos_emodel_in:0,ssrc:"",direction:$e.INBOUND},Rh={level_out:0,codec_id_out:"",codec_out:{mime_type:null,clock_rate:null,sdp_fmtp_line:null},delta_jitter_ms_out:0,delta_rtt_ms_out:null,total_rtt_ms_out:0,total_rtt_measure_out:0,percent_packets_lost_out:0,delta_packets_out:0,delta_packets_lost_out:0,total_packets_out:0,total_packets_lost_out:0,total_KBytes_out:0,delta_KBytes_out:0,delta_kbs_out:0,timestamp_out:null,mos_out:0,mos_emodel_out:0,ssrc:"",direction:$e.OUTBOUND},Ih={codec_id_in:"",size_in:{width:null,height:null,framerate:null},codec_in:{mime_type:null,clock_rate:null},delta_jitter_ms_in:0,percent_packets_lost_in:0,delta_packets_in:0,delta_packets_lost_in:0,total_packets_in:0,total_packets_lost_in:0,total_KBytes_in:0,delta_KBytes_in:0,delta_kbs_in:0,decoder_in:null,delta_ms_decode_frame_in:0,total_frames_decoded_in:0,total_time_decoded_in:0,delta_nack_sent_in:0,delta_pli_sent_in:0,total_nack_sent_in:0,total_pli_sent_in:0,ssrc:"",direction:$e.INBOUND},bh={codec_id_out:"",size_out:{width:null,height:null,framerate:null},codec_out:{mime_type:null,clock_rate:null},delta_jitter_ms_out:0,delta_rtt_ms_out:null,total_rtt_ms_out:0,total_rtt_measure_out:0,percent_packets_lost_out:0,delta_packets_out:0,delta_packets_lost_out:0,total_packets_out:0,total_packets_lost_out:0,total_KBytes_out:0,delta_KBytes_out:0,delta_kbs_out:0,encoder_out:null,delta_ms_encode_frame_out:0,total_time_encoded_out:0,total_frames_encoded_out:0,delta_nack_received_out:0,delta_pli_received_out:0,total_nack_received_out:0,total_pli_received_out:0,limitation_out:{reason:null,durations:null,resolutionChanges:0},timestamp_out:null,ssrc:"",direction:$e.OUTBOUND},lv=c=>{const t={pname:"",call_id:"",user_id:"",timestamp:null,count:0,audio:{},video:{},network:{infrastructure:3,local_candidate_id:"",local_candidate_type:"",local_candidate_protocol:"",local_candidate_relay_protocol:"",remote_candidate_id:"",remote_candidate_type:"",remote_candidate_protocol:""},data:{total_KBytes_in:0,total_KBytes_out:0,delta_KBytes_in:0,delta_KBytes_out:0,delta_kbs_in:0,delta_kbs_out:0,delta_kbs_bandwidth_in:0,delta_kbs_bandwidth_out:0,delta_rtt_connectivity_ms:null,total_rtt_connectivity_ms:0,total_rtt_connectivity_measure:0},experimental:{time_to_measure_ms:0}};if(c){const n={...c,audio:{},video:{},data:{...c.data},network:{...c.network},experimental:{...c.experimental}};return Object.keys(c.audio).forEach(a=>{n.audio[a]={...c.audio[a]}}),Object.keys(c.video).forEach(a=>{n.video[a]={...c.video[a]}}),n}return{...t,audio:{},video:{},data:{...t.data},network:{...t.network},experimental:{...t.experimental}}},av={refreshEvery:2e3,startAfter:0,stopAfter:-1,verbose:!1,pname:`p-${ri()}`,cid:`c-${ri()}`,uid:`u-${ri()}`,record:!1,ticket:!0},Zt={CANDIDATE_PAIR:"candidate-pair",CODEC:"codec",INBOUND_RTP:"inbound-rtp",LOCAL_CANDIDATE:"local-candidate",MEDIA_SOURCE:"media-source",OUTBOUND_RTP:"outbound-rtp",REMOTE_CANDIDATE:"remote-candidate",REMOTE_INBOUND_RTP:"remote-inbound-rtp",TRACK:"track"},q={AUDIO_LEVEL:"audioLevel",AVAILABLE_OUTGOING_BITRATE:"availableOutgoingBitrate",AVAILABLE_INCOMING_BITRATE:"availableIncomingBitrate",BYTES_RECEIVED:"bytesReceived",BYTES_SENT:"bytesSent",CANDIDATE_TYPE:"candidateType",CHANNELS:"channels",CLOCK_RATE:"clockRate",CODEC_ID:"codecId",CURRENT_ROUND_TRIP_TIME:"currentRoundTripTime",ROUND_TRIP_TIME:"roundTripTime",FRACTION_LOST:"fractionLost",FRAME_HEIGHT:"frameHeight",FRAME_WIDTH:"frameWidth",QUALITY_LIMITATION_REASON:"qualityLimitationReason",QUALITY_LIMITATION_DURATIONS:"qualityLimitationDurations",QUALITY_LIMITATION_RESOLUTION_CHANGES:"qualityLimitationResolutionChanges",ID:"id",JITTER:"jitter",KIND:"kind",MEDIA_TYPE:"mediaType",MIME_TYPE:"mimeType",LOCAL_CANDIDATE_ID:"localCandidateId",NETWORK_TYPE:"networkType",RELAY_PROTOCOL:"relayProtocol",NOMINATED:"nominated",PACKETS_LOST:"packetsLost",PACKETS_RECEIVED:"packetsReceived",PACKETS_SENT:"packetsSent",PROTOCOL:"protocol",PORT:"port",REMOTE_CANDIDATE_ID:"remoteCandidateId",REMOTE_SOURCE:"remoteSource",RESPONSES_RECEIVED:"responsesReceived",SDP_FMTP_LINE:"sdpFmtpLine",SSRC:"ssrc",SELECTED:"selected",STATE:"state",TIMESTAMP:"timestamp",TOTAL_ROUND_TRIP_TIME:"totalRoundTripTime",TOTAL_ROUND_TRIP_TIME_MEASUREMENTS:"roundTripTimeMeasurements",TYPE:"type",DECODER_IMPLEMENTATION:"decoderImplementation",ENCODER_IMPLEMENTATION:"encoderImplementation",FRAMES_DECODED:"framesDecoded",FRAMES_ENCODED:"framesEncoded",FRAMES_PER_SECOND:"framesPerSecond",TOTAL_DECODE_TIME:"totalDecodeTime",TOTAL_ENCODE_TIME:"totalEncodeTime",PLI:"pliCount",NACK:"nackCount"},x={SUCCEEDED:"succeeded",AUDIO:"audio",VIDEO:"video"},li={ETHERNET:0,CELLULAR_5G:2,WIFI:3,CELLULAR_4G:5,CELLULAR:10},Iu={ETHERNET:"ethernet",CELLULAR_4G:"cellular",WIFI:"wifi"},ne={AUDIO:"audio",VIDEO:"video",NETWORK:"network",DATA:"data"},bu="config ",ov=(c,t={},n)=>{const a={...n,...t};return t.pname||Aa(bu,`Argument [String] 'cfg.pname' for the peerConnection name or id is missing - use generated '${n.pname}'`),t.cid||Aa(bu,`Argument [String] 'cfg.cid' for the call name or id is missing - use generated '${n.cid}'`),t.uid||Aa(bu,`Argument [String] 'cfg.uid' for the user name or id is missing - use generated '${n.uid}'`),a.pc=c,a},uv=(c={})=>{const t={...av,...c};return t.name=nv(),t.version=rv(),t},ai=(c,t,n,a=!1,o)=>{let s=c.map(r=>{if(!n)return r[t];if(!o)return r[t][n];const d=r[t][o];return d?d[n]:null});return s=s.filter(r=>a?Number.isFinite(r)&&r>0:Number.isFinite(r)),s.length===0?[]:s},Ms=c=>c.reduce((t,n)=>t+n,0)/c.length,cv=()=>`probe-${ri()}`,fv=()=>`coltr-${ri()}`,wh=c=>new Promise(t=>setTimeout(t,c)),wu=(c,t,n)=>{t?c.call(t,n):c(n)},We=(c,t,n,a)=>{const o=ai(c,t,n,!0,a);if(o.length===0)return null;const s=o.reduce((_,g)=>_+g,0)/o.length;return s===0?null:o.map(_=>Math.abs(s-_)).reduce((_,g)=>_+g,0)/o.length*100/s},Xe=(c,t,n,a=!1,o)=>{const s=ai(c,t,n,a,o);return s.length===0?null:s.reduce((r,d)=>r+d,0)/s.length},un=(c,t,n)=>ai(c,t,n).reduce((o,s)=>o+s,0),Ke=(c,t,n,a)=>{const o=ai(c,t,n,!0,a);return o.length===0?null:Math.min(...o)},Ye=(c,t,n,a)=>{const o=ai(c,t,n,!1,a);return o.length===0?null:Math.max(...o)},Ct=(c,t,n,a)=>{const o=c.slice().pop();if(!o)return null;if(!n)return o[t];if(!a)return o[t][n];const s=o[t][a];return s?s[n]:null},hv=c=>c.slice().pop(),ht=(c,t,n)=>{if(!t)return null;const a={};let o=t[x.AUDIO][c];o||(o=n===$e.INBOUND?{...Ah}:{...Rh}),a[x.AUDIO]=o;let s=t[x.VIDEO][c];return s||(s=n===$e.INBOUND?{...Ih}:{...bh}),a[x.VIDEO]=s,a},oi="exporter ",dv="2.0",Oh=(c,t,n)=>{if(!c||c.length===0)return 0;const a=c[c.length-1];if(!a)return 0;const o=a[t][n];if(o){const s=o.total_rtt_ms_out,r=o.total_rtt_measure_out;return!r||!s?Xe(c,t,"delta_rtt_ms_out",!1,n):Number(s/r)}return null},_v=(c,t)=>{if(!c||c.length===0)return 0;const n=c[c.length-1];if(!n)return 0;const a=n[t].total_rtt_connectivity_ms,o=n[t].total_rtt_connectivity_measure;return!o||!a?Xe(c,t,"delta_rtt_connectivity_ms"):Number(a/o)},pv=c=>Ct(c,"network","local_candidate_type")!=="relay"?`direct/${Ct(c,"network","local_candidate_protocol")}`:`turn/${Ct(c,"network","local_candidate_relay_protocol")}`,mv=c=>{const t=Ct(c,"network","remote_candidate_type"),n=Ct(c,"network","remote_candidate_protocol");return t!=="relay"?`direct/${n}`:`turn/${n}`};class gv{constructor(t){this._start=null,this._end=null,this._cfg=t,this._referenceReport=null,this._reports=[],this._events=[]}start(){Ru(oi,"start() - start exporter...");const t=new Date;return this._start=t.toJSON(),t}stop(){Ru(oi,"stop() - stop exporter...");const t=new Date;return this._end=t.toJSON(),t}saveReferenceReport(t){this._referenceReport=t}getReferenceReport(){return this._referenceReport}addReport(t){this._cfg.ticket&&(Pe(oi,`addReport() - add report to exporter at ${t.timestamp}`),this._reports.push(t))}addCustomEvent(t){this._events.push(t)}reset(){Ru(oi,"resetReports() - reset reports"),this._reports=[],this._referenceReport=null,this._start=null,this._end=null}get ticket(){Pe(oi,"ticket() - generate ticket");const t=Ct(this._reports,"audio","total_packets_lost_in"),n=Ct(this._reports,"audio","total_packets_in"),a=Ct(this._reports,"video","total_packets_lost_in"),o=Ct(this._reports,"video","total_packets_in"),s={},r=hv(this._reports);return r&&(Object.keys(r[x.AUDIO]).forEach(d=>{const h=r[x.AUDIO][d];if(s[h.ssrc]={type:x.AUDIO,direction:h.direction},h.direction===$e.INBOUND){const _={avg:Xe(this._reports,x.AUDIO,"delta_jitter_ms_in",!1,d),min:Ke(this._reports,x.AUDIO,"delta_jitter_ms_in",d),max:Ye(this._reports,x.AUDIO,"delta_jitter_ms_in",d),volatility:We(this._reports,x.AUDIO,"delta_jitter_ms_in",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Xe(this._reports,x.AUDIO,"delta_kbs_in",!1,d),min:Ke(this._reports,x.AUDIO,"delta_kbs_in",d),max:Ye(this._reports,x.AUDIO,"delta_kbs_in",d),volatility:We(this._reports,x.AUDIO,"delta_kbs_in",d),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,x.AUDIO,"delta_KBytes_in",!1,d),min:Ke(this._reports,x.AUDIO,"delta_KBytes_in",d),max:Ye(this._reports,x.AUDIO,"delta_KBytes_in",d),volatility:We(this._reports,x.AUDIO,"delta_KBytes_in",d),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},E={emodel:{avg:Xe(this._reports,x.AUDIO,"mos_emodel_in",!1,d),min:Ke(this._reports,x.AUDIO,"mos_emodel_in",d),max:Ye(this._reports,x.AUDIO,"mos_emodel_in",d),volatility:We(this._reports,x.AUDIO,"mos_emodel_in",d)},effective:{avg:Xe(this._reports,x.AUDIO,"mos_in",!1,d),min:Ke(this._reports,x.AUDIO,"mos_in",d),max:Ye(this._reports,x.AUDIO,"mos_in",d),volatility:We(this._reports,x.AUDIO,"mos_in",d)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}},y=Ct(this._reports,x.AUDIO,"total_packets_lost_in",d),C=Ct(this._reports,x.AUDIO,"total_packets_in",d),A={lost:y,avg:Math.round((y/(y+C)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[d].jitter=_,s[d].mos=E,s[d].traffic=T,s[d].bitrate=g,s[d].loss=A}else{const _={avg:Xe(this._reports,x.AUDIO,"delta_jitter_ms_out",!1,d),min:Ke(this._reports,x.AUDIO,"delta_jitter_ms_out",d),max:Ye(this._reports,x.AUDIO,"delta_jitter_ms_out",d),volatility:We(this._reports,x.AUDIO,"delta_jitter_ms_out",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Xe(this._reports,x.AUDIO,"delta_kbs_out",!1,d),min:Ke(this._reports,x.AUDIO,"delta_kbs_out",d),max:Ye(this._reports,x.AUDIO,"delta_kbs_out",d),volatility:We(this._reports,x.AUDIO,"delta_kbs_out",d),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,x.AUDIO,"delta_KBytes_out",!1,d),min:Ke(this._reports,x.AUDIO,"delta_KBytes_out",d),max:Ye(this._reports,x.AUDIO,"delta_KBytes_out",d),volatility:We(this._reports,x.AUDIO,"delta_KBytes_out",d),_unit:{avg:"KB",min:"KB",max:"KB",bitrate:"kbs",volatility:"percent"}},E={avg:Oh(this._reports,x.AUDIO,d),min:Ke(this._reports,x.AUDIO,"delta_rtt_ms_out",d),max:Ye(this._reports,x.AUDIO,"delta_rtt_ms_out",d),volatility:We(this._reports,x.AUDIO,"delta_rtt_ms_out",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},y=Ct(this._reports,x.AUDIO,"total_packets_lost_out",d),C=Ct(this._reports,x.AUDIO,"total_packets_out",d),A={lost:y,avg:Math.round((y/(y+C)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}},I={emodel:{avg:Xe(this._reports,x.AUDIO,"mos_emodel_out",!1,d),min:Ke(this._reports,x.AUDIO,"mos_emodel_out",d),max:Ye(this._reports,x.AUDIO,"mos_emodel_out",d),volatility:We(this._reports,x.AUDIO,"mos_emodel_out",d)},effective:{avg:Xe(this._reports,x.AUDIO,"mos_out",!1,d),min:Ke(this._reports,x.AUDIO,"mos_out",d),max:Ye(this._reports,x.AUDIO,"mos_out",d),volatility:We(this._reports,x.AUDIO,"mos_out",d)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}};s[d].jitter=_,s[d].rtt=E,s[d].traffic=T,s[d].bitrate=g,s[d].loss=A,s[d].mos=I}}),Object.keys(r[x.VIDEO]).forEach(d=>{const h=r[x.VIDEO][d];if(s[d]={type:x.VIDEO,direction:h.direction},h.direction===$e.INBOUND){const _={avg:Xe(this._reports,x.VIDEO,"delta_jitter_ms_in",!1,d),min:Ke(this._reports,x.VIDEO,"delta_jitter_ms_in",d),max:Ye(this._reports,x.VIDEO,"delta_jitter_ms_in",d),volatility:We(this._reports,x.VIDEO,"delta_jitter_ms_in",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Xe(this._reports,x.VIDEO,"delta_kbs_in",!1,d),min:Ke(this._reports,x.VIDEO,"delta_kbs_in",d),max:Ye(this._reports,x.VIDEO,"delta_kbs_in",d),volatility:We(this._reports,x.VIDEO,"delta_kbs_in",d),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,x.VIDEO,"delta_KBytes_in",!1,d),min:Ke(this._reports,x.VIDEO,"delta_KBytes_in",d),max:Ye(this._reports,x.VIDEO,"delta_KBytes_in",d),volatility:We(this._reports,x.VIDEO,"delta_KBytes_in",d),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},E=Ct(this._reports,x.VIDEO,"total_packets_lost_in",d),y=Ct(this._reports,x.VIDEO,"total_packets_in",d),C={lost:E,avg:Math.round((E/(E+y)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[d].jitter=_,s[d].traffic=T,s[d].bitrate=g,s[d].loss=C}else{const _={avg:Xe(this._reports,x.VIDEO,"delta_jitter_ms_out",!1,d),min:Ke(this._reports,x.VIDEO,"delta_jitter_ms_out",d),max:Ye(this._reports,x.VIDEO,"delta_jitter_ms_out",d),volatility:We(this._reports,x.VIDEO,"delta_jitter_ms_out",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:Xe(this._reports,x.VIDEO,"delta_kbs_out",!1,d),min:Ke(this._reports,x.VIDEO,"delta_kbs_out",d),max:Ye(this._reports,x.VIDEO,"delta_kbs_out",d),volatility:We(this._reports,x.VIDEO,"delta_kbs_out",d),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:Xe(this._reports,x.VIDEO,"delta_KBytes_out",!1,d),min:Ke(this._reports,x.VIDEO,"delta_KBytes_out",d),max:Ye(this._reports,x.VIDEO,"delta_KBytes_out",d),volatility:We(this._reports,x.VIDEO,"delta_KBytes_out",d),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},E={avg:Oh(this._reports,x.VIDEO,d),min:Ke(this._reports,x.VIDEO,"delta_rtt_ms_out",d),max:Ye(this._reports,x.VIDEO,"delta_rtt_ms_out",d),volatility:We(this._reports,x.VIDEO,"delta_rtt_ms_out",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},y=Ct(this._reports,x.VIDEO,"total_packets_lost_out",d),C=Ct(this._reports,x.VIDEO,"total_packets_out",d),A={lost:y,avg:Math.round((y/(y+C)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[d].jitter=_,s[d].rtt=E,s[d].traffic=T,s[d].bitrate=g,s[d].loss=A}})),{version:dv,configuration:{frequency:this._cfg.refreshEvery},started:this._start,ended:this._end,ua:{agent:navigator.userAgent,pname:this._cfg.pname,user_id:this._cfg.uid},call:{call_id:this._cfg.cid,events:this._events},details:{count:this._reports.length,reports:this._cfg.record?this._reports:[],reference:this._referenceReport||null},ssrc:s,data:{rtt:{avg:_v(this._reports,"data"),min:Ke(this._reports,"data","delta_rtt_connectivity_ms"),max:Ye(this._reports,"data","delta_rtt_connectivity_ms"),volatility:We(this._reports,"data","delta_rtt_connectivity_ms"),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},packetsLost:{audio:{in:{avg:Math.round((t/(t+n)*100||0)*100)/100}},video:{in:{avg:Math.round((a/(a+o)*100||0)*100)/100}},unit:{avg:"percent"}},bitrate:{in:{avg:Xe(this._reports,"data","delta_kbs_in"),min:Ke(this._reports,"data","delta_kbs_in"),max:Ye(this._reports,"data","delta_kbs_in"),volatility:We(this._reports,"data","delta_kbs_in")},out:{avg:Xe(this._reports,"data","delta_kbs_out"),min:Ke(this._reports,"data","delta_kbs_out"),max:Ye(this._reports,"data","delta_kbs_out"),volatility:We(this._reports,"data","delta_kbs_out")},unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},traffic:{in:{avg:Xe(this._reports,"data","delta_KBytes_in"),min:Ke(this._reports,"data","delta_KBytes_in"),max:Ye(this._reports,"data","delta_KBytes_in"),volatility:We(this._reports,"data","delta_KBytes_in")},out:{avg:Xe(this._reports,"data","delta_KBytes_out"),min:Ke(this._reports,"data","delta_KBytes_out"),max:Ye(this._reports,"data","delta_KBytes_out"),volatility:We(this._reports,"data","delta_KBytes_out")},unit:{avg:"KBytes",min:"KBytes",max:"KBytes",volatility:"percent"}},network:{localConnection:pv(this._reports),remoteConnection:mv(this._reports)}}}}updateConfig(t){this._cfg=t}getLastReport(){return this._reports.slice().pop()||null}getBeforeLastReport(){const t=this._reports.slice();return t.pop(),t.pop()||null}getReportsNumber(){return this._reports.length}}const Ls="extractor ",Dh=(c,t,n,a)=>{let o=!1;const s=a[t].total_rtt_ms_out,r=a[t].total_rtt_measure_out,d=n?n[t].total_rtt_ms_out:0,h=n?n[t].total_rtt_measure_out:0,_={rtt:null,totalRTT:s,totalRTTMeasurements:r};if(c[q.TIMESTAMP]===a[t].timestamp_out||!Object.prototype.hasOwnProperty.call(c,q.ROUND_TRIP_TIME)||Object.prototype.hasOwnProperty.call(c,q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS)&&(o=!0,Number(c[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])===0||Number(c[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-h===r))return _;const g=1e3*Number(c[q.ROUND_TRIP_TIME]);let T=s+g,E=r+1;return o&&(T=1e3*Number(c[q.TOTAL_ROUND_TRIP_TIME])-d,E=Number(c[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-h),{rtt:g,totalRTT:T,totalRTTMeasurements:E}},Tv=(c,t,n,a)=>{if(!Object.prototype.hasOwnProperty.call(c,q.CURRENT_ROUND_TRIP_TIME))return{rtt:null,totalRTT:a[t].total_rtt_connectivity_ms,totalRTTMeasurements:a[t].total_rtt_connectivity_measure};const o=1e3*Number(c[q.CURRENT_ROUND_TRIP_TIME]);let s=a[t].total_rtt_connectivity_ms+o,r=a[t].total_rtt_connectivity_measure+1;return Object.prototype.hasOwnProperty.call(c,q.TOTAL_ROUND_TRIP_TIME)&&(s=1e3*Number(c[q.TOTAL_ROUND_TRIP_TIME])-(n?n[t].total_rtt_connectivity_ms:0)),Object.prototype.hasOwnProperty.call(c,q.RESPONSES_RECEIVED)&&(r=Number(c[q.RESPONSES_RECEIVED])-(n?n[t].total_rtt_connectivity_measure:0)),{rtt:o,totalRTT:s,totalRTTMeasurements:r}},Ra=(c,t,n)=>c[q.TIMESTAMP]===n[t].timestamp_out||!Object.prototype.hasOwnProperty.call(c,q.JITTER)?null:1e3*(Number(c[q.JITTER])||0),vv=(c,t)=>{if(!Object.prototype.hasOwnProperty.call(c,q.FRAMES_DECODED)||!Object.prototype.hasOwnProperty.call(c,q.TOTAL_DECODE_TIME))return{delta_ms_decode_frame:t[x.VIDEO].delta_ms_decode_frame_in,frames_decoded:t[x.VIDEO].total_frames_decoded_in,total_decode_time:t[x.VIDEO].total_time_decoded_in};const n=c[q.FRAMES_DECODED],a=c[q.TOTAL_DECODE_TIME],o=a-t[x.VIDEO].total_time_decoded_in,s=n-t[x.VIDEO].total_frames_decoded_in;return{delta_ms_decode_frame:s>0?o*1e3/s:0,frames_decoded:n,total_decode_time:a}},Ev=(c,t)=>{if(!Object.prototype.hasOwnProperty.call(c,q.FRAMES_ENCODED)||!Object.prototype.hasOwnProperty.call(c,q.TOTAL_ENCODE_TIME))return{delta_ms_encode_frame:t[x.VIDEO].delta_ms_encode_frame_out,frames_encoded:t[x.VIDEO].total_frames_encoded_out,total_encode_time:t[x.VIDEO].total_time_encoded_out};const n=c[q.FRAMES_ENCODED],a=c[q.TOTAL_ENCODE_TIME],o=a-t[x.VIDEO].total_time_encoded_out,s=n-t[x.VIDEO].total_frames_encoded_out;return{delta_ms_encode_frame:s>0&&o?o*1e3/s:0,frames_encoded:n,total_encode_time:a}},Nh=(c,t,n,a)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PACKETS_SENT)||!Object.prototype.hasOwnProperty.call(c,q.BYTES_SENT))return{packetsSent:n[t].total_packets_out,packetsLost:n[t].total_packets_lost_out,bytesSent:n[t].total_KBytes_out};const o=Number(c[q.PACKETS_SENT])||0-(a?a[t].total_packets_out:0),s=o-n[t].total_packets_out,r=Number(c[q.BYTES_SENT])/1024-(a?a[t].total_KBytes_out:0),d=r-n[t].total_KBytes_out,h=c[q.TIMESTAMP]||Date.now(),_=a?a.timestamp:null;let g=n.timestamp;!g&&_&&(g=_);const T=g?h-g:0,E=T>0?d*.008*1024/T*1e3:0;return{packetsSent:o,deltaPacketsSent:s,KBytesSent:r,deltaKBytesSent:d,kbsSent:E}},Uh=(c,t,n,a)=>{let o=n[t].total_packets_lost_out,s=0,r=0;return Object.prototype.hasOwnProperty.call(c,q.PACKETS_LOST)&&(o=Number(c[q.PACKETS_LOST])||0-(a?a[t].total_packets_lost_out:0),s=o-n[t].total_packets_lost_out),Object.prototype.hasOwnProperty.call(c,q.FRACTION_LOST)&&(r=Number(100*c[q.FRACTION_LOST])),{packetsLost:o,deltaPacketsLost:s,fractionLost:r}},Ph=(c,t,n,a)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PACKETS_RECEIVED)||!Object.prototype.hasOwnProperty.call(c,q.PACKETS_LOST)||!Object.prototype.hasOwnProperty.call(c,q.BYTES_RECEIVED))return{percent_packets_lost:n[t].percent_packets_lost_in,packetsReceived:n[t].total_packets_in,packetsLost:n[t].total_packets_lost_in,bytesReceived:n[t].total_KBytes_in};const o=Number(c[q.PACKETS_RECEIVED])||0-(a?a[t].total_packets_in:0),s=Number(c[q.PACKETS_LOST])||0-(a?a[t].total_packets_lost_in:0),r=s-n[t].total_packets_lost_in,d=o-n[t].total_packets_in,h=o!==n[t].total_packets_in?r*100/(r+d):0,_=Number(c[q.BYTES_RECEIVED])/1024-(a?a[t].total_KBytes_in:0),g=_-n[t].total_KBytes_in,T=c[q.TIMESTAMP]||Date.now(),E=a?a.timestamp:null;let y=n.timestamp;!y&&E&&(y=E);const C=y?T-y:0,A=C>0?g*.008*1024/C*1e3:0;return{percentPacketsLost:h,packetsReceived:o,deltaPacketsReceived:d,packetsLost:s,deltaPacketsLost:r,KBytesReceived:_,deltaKBytesReceived:g,kbsReceived:A}},Sv=c=>c[q.CANDIDATE_TYPE]!=="relay"?"":c[q.RELAY_PROTOCOL]||"",yv=c=>{if(!Object.prototype.hasOwnProperty.call(c,q.NETWORK_TYPE))return li.WIFI;switch(c[q.NETWORK_TYPE]){case Iu.ETHERNET:return li.ETHERNET;case Iu.CELLULAR_4G:return li.CELLULAR_4G;case Iu.WIFI:return li.WIFI;default:return li.CELLULAR}},xh=c=>!Object.prototype.hasOwnProperty.call(c,q.FRAME_HEIGHT)||!Object.prototype.hasOwnProperty.call(c,q.FRAME_WIDTH)?{width:null,height:null,framerate:null}:{width:c[q.FRAME_WIDTH]||null,height:c[q.FRAME_HEIGHT]||null,framerate:c[q.FRAMES_PER_SECOND]},Cv=c=>{const t=Object.prototype.hasOwnProperty.call(c,q.QUALITY_LIMITATION_REASON)?c[q.QUALITY_LIMITATION_REASON]:null,n=Object.prototype.hasOwnProperty.call(c,q.QUALITY_LIMITATION_RESOLUTION_CHANGES)?c[q.QUALITY_LIMITATION_RESOLUTION_CHANGES]:null,a=Object.prototype.hasOwnProperty.call(c,q.QUALITY_LIMITATION_DURATIONS)?c[q.QUALITY_LIMITATION_DURATIONS]:null;return a&&Object.keys(a).forEach(o=>{a[o]>1e3&&(a[o]=Number(a[o]/1e3))}),{reason:t,durations:a,resolutionChanges:n}},Av=(c,t,n)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PLI)||!Object.prototype.hasOwnProperty.call(c,q.NACK))return{pliCount:t.total_pli_sent_in,nackCount:t.total_nack_sent_in,deltaPliCount:0,deltaNackCount:0};const a=(c[q.PLI]||0)-(n?n[x.VIDEO].total_pli_sent_in:0),o=(c[q.NACK]||0)-(n?n[x.VIDEO].total_nack_sent_in:0);return{pliCount:a,nackCount:o,deltaPliCount:a-t[x.VIDEO].total_pli_sent_in,deltaNackCount:o-t[x.VIDEO].total_nack_sent_in}},Rv=(c,t,n)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PLI)||!Object.prototype.hasOwnProperty.call(c,q.NACK))return{pliCount:t.total_pli_received_out,nackCount:t.total_nack_received_out,deltaPliCount:0,deltaNackCount:0};const a=(c[q.PLI]||0)-(n?n[x.VIDEO].total_pli_received_out:0),o=(c[q.NACK]||0)-(n?n[x.VIDEO].total_nack_received_out:0);return{pliCount:a,nackCount:o,deltaPliCount:a-t[x.VIDEO].total_pli_received_out,deltaNackCount:o-t[x.VIDEO].total_nack_received_out}},Iv=c=>({channels:c[q.CHANNELS]||null,clock_rate:c[q.CLOCK_RATE]||null,mime_type:c[q.MIME_TYPE]||null,sdp_fmtp_line:c[q.SDP_FMTP_LINE]||null}),bv=c=>({clock_rate:c[q.CLOCK_RATE]||null,mime_type:c[q.MIME_TYPE]||null}),wv=(c,t,n)=>{const a=(c[q.BYTES_RECEIVED]||0)/1024-(n?n.data.total_KBytes_in:0),o=(c[q.BYTES_SENT]||0)/1024-(n?n.data.total_KBytes_out:0),s=c[q.TIMESTAMP]||Date.now(),r=a-t.data.total_KBytes_in,d=o-t.data.total_KBytes_out,h=n?n.timestamp:null;let _=t.timestamp;!_&&h&&(_=h);const g=_?s-_:0,T=g>0?r*.008*1024/g*1e3:0,E=g>0?d*.008*1024/g*1e3:0;return{total_KBytes_received:a,total_KBytes_sent:o,delta_KBytes_received:r,delta_KBytes_sent:d,kbs_speed_received:T,kbs_speed_sent:E}},Ov=c=>{const t=c[q.AVAILABLE_INCOMING_BITRATE]/1024||0,n=c[q.AVAILABLE_OUTGOING_BITRATE]/1024||0;return{kbs_incoming_bandwidth:t,kbs_outgoing_bandwidth:n}},Dv=(c,t,n,a)=>{if(!c)return[];switch(c[q.TYPE]){case Zt.CANDIDATE_PAIR:let o=!1;if(c[q.NOMINATED]&&c[q.STATE]===x.SUCCEEDED&&(o=!0,Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c),q.SELECTED in c&&!c[q.SELECTED]&&(o=!1)),o){const r=c[q.LOCAL_CANDIDATE_ID],d=c[q.REMOTE_CANDIDATE_ID],h=wv(c,t,a),_=Ov(c),g=Tv(c,"data",a,t);return[{type:ne.NETWORK,value:{local_candidate_id:r}},{type:ne.NETWORK,value:{remote_candidate_id:d}},{type:ne.DATA,value:{total_KBytes_in:h.total_KBytes_received}},{type:ne.DATA,value:{total_KBytes_out:h.total_KBytes_sent}},{type:ne.DATA,value:{delta_KBytes_in:h.delta_KBytes_received}},{type:ne.DATA,value:{delta_KBytes_out:h.delta_KBytes_sent}},{type:ne.DATA,value:{delta_kbs_in:h.kbs_speed_received}},{type:ne.DATA,value:{delta_kbs_out:h.kbs_speed_sent}},{type:ne.DATA,value:{delta_kbs_bandwidth_in:_.kbs_incoming_bandwidth}},{type:ne.DATA,value:{delta_kbs_bandwidth_out:_.kbs_outgoing_bandwidth}},{type:ne.DATA,value:{delta_rtt_connectivity_ms:g.rtt}},{type:ne.DATA,value:{total_rtt_connectivity_ms:g.totalRTT}},{type:ne.DATA,value:{total_rtt_connectivity_measure:g.totalRTTMeasurements}}]}break;case Zt.LOCAL_CANDIDATE:if(c[q.ID]===t.network.local_candidate_id)return[{type:ne.NETWORK,value:{infrastructure:yv(c)}},{type:ne.NETWORK,value:{local_candidate_type:c[q.CANDIDATE_TYPE]||""}},{type:ne.NETWORK,value:{local_candidate_protocol:c[q.PROTOCOL]||""}},{type:ne.NETWORK,value:{local_candidate_relay_protocol:Sv(c)}}];break;case Zt.REMOTE_CANDIDATE:if(c[q.ID]===t.network.remote_candidate_id)return[{type:ne.NETWORK,value:{remote_candidate_type:c[q.CANDIDATE_TYPE]||""}},{type:ne.NETWORK,value:{remote_candidate_protocol:c[q.PROTOCOL]||""}}];break;case Zt.INBOUND_RTP:{Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const r=c[q.SSRC],d=ht(r,t,$e.INBOUND);d&&(d.timestamp=t.timestamp);const h=ht(r,a,$e.INBOUND);if(h&&(h.timestamp=a.timestamp),c[q.MEDIA_TYPE]===x.AUDIO){const _=Ph(c,x.AUDIO,d,h),g=Ra(c,x.AUDIO,d),T=c[q.CODEC_ID]||"";return[{ssrc:r,type:ne.AUDIO,value:{codec_id_in:T}},{ssrc:r,type:ne.AUDIO,value:{total_packets_in:_.packetsReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_in:_.deltaPacketsReceived}},{ssrc:r,type:ne.AUDIO,value:{total_packets_lost_in:_.packetsLost}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_lost_in:_.deltaPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{percent_packets_lost_in:_.percentPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{total_KBytes_in:_.KBytesReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_KBytes_in:_.deltaKBytesReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_kbs_in:_.kbsReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_jitter_ms_in:g}}]}if(c[q.MEDIA_TYPE]===x.VIDEO){const _=vv(c,d),g=Ph(c,x.VIDEO,d,h),T=Ra(c,x.VIDEO,d),E=c[q.DECODER_IMPLEMENTATION]||null,y=c[q.CODEC_ID]||null,C=xh(c),A=Av(c,d,h);return[{ssrc:r,type:ne.VIDEO,value:{codec_id_in:y}},{ssrc:r,type:ne.VIDEO,value:{total_packets_in:g.packetsReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_in:g.deltaPacketsReceived}},{ssrc:r,type:ne.VIDEO,value:{total_packets_lost_in:g.packetsLost}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_lost_in:g.deltaPacketsLost}},{ssrc:r,type:ne.VIDEO,value:{percent_packets_lost_in:g.percentPacketsLost}},{ssrc:r,type:ne.VIDEO,value:{total_KBytes_in:g.KBytesReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_KBytes_in:g.deltaKBytesReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_kbs_in:g.kbsReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_jitter_ms_in:T}},{ssrc:r,type:ne.VIDEO,value:{decoder_in:E}},{ssrc:r,type:ne.VIDEO,value:{delta_ms_decode_frame_in:_.delta_ms_decode_frame}},{ssrc:r,type:ne.VIDEO,value:{total_frames_decoded_in:_.frames_decoded}},{ssrc:r,type:ne.VIDEO,value:{total_time_decoded_in:_.total_decode_time}},{ssrc:r,type:ne.VIDEO,value:{total_nack_sent_in:A.nackCount}},{ssrc:r,type:ne.VIDEO,value:{delta_nack_sent_in:A.deltaNackCount}},{ssrc:r,type:ne.VIDEO,value:{total_pli_sent_in:A.pliCount}},{ssrc:r,type:ne.VIDEO,value:{delta_pli_sent_in:A.deltaPliCount}},{ssrc:r,type:ne.VIDEO,value:{size_in:C}}]}break}case Zt.OUTBOUND_RTP:{Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const r=c[q.SSRC],d=ht(r,t,$e.OUTBOUND);d&&(d.timestamp=t.timestamp);const h=ht(r,a,$e.OUTBOUND);if(h&&(h.timestamp=a.timestamp),c[q.MEDIA_TYPE]===x.AUDIO){const _=c[q.CODEC_ID]||null,g=Nh(c,x.AUDIO,d,h);return[{ssrc:r,type:ne.AUDIO,value:{codec_id_out:_}},{ssrc:r,type:ne.AUDIO,value:{total_packets_out:g.packetsSent}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_out:g.deltaPacketsSent}},{ssrc:r,type:ne.AUDIO,value:{total_KBytes_out:g.KBytesSent}},{ssrc:r,type:ne.AUDIO,value:{delta_KBytes_out:g.deltaKBytesSent}},{ssrc:r,type:ne.AUDIO,value:{delta_kbs_out:g.kbsSent}}]}if(c[q.MEDIA_TYPE]===x.VIDEO){const _=c[q.ENCODER_IMPLEMENTATION]||null,g=c[q.CODEC_ID]||null,T=Ev(c,d),E=xh(c),y=Cv(c),C=Rv(c,d,h),A=Nh(c,x.VIDEO,d,h);return[{ssrc:r,type:ne.VIDEO,value:{codec_id_out:g}},{ssrc:r,type:ne.VIDEO,value:{total_packets_out:A.packetsSent}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_out:A.deltaPacketsSent}},{ssrc:r,type:ne.VIDEO,value:{total_KBytes_out:A.KBytesSent}},{ssrc:r,type:ne.VIDEO,value:{delta_KBytes_out:A.deltaKBytesSent}},{ssrc:r,type:ne.VIDEO,value:{delta_kbs_out:A.kbsSent}},{ssrc:r,type:ne.VIDEO,value:{encoder_out:_}},{ssrc:r,type:ne.VIDEO,value:{delta_ms_encode_frame_out:T.delta_ms_encode_frame}},{ssrc:r,type:ne.VIDEO,value:{total_frames_encoded_out:T.frames_encoded}},{ssrc:r,type:ne.VIDEO,value:{total_time_encoded_out:T.total_encode_time}},{ssrc:r,type:ne.VIDEO,value:{total_nack_received_out:C.nackCount}},{ssrc:r,type:ne.VIDEO,value:{delta_nack_received_out:C.deltaNackCount}},{ssrc:r,type:ne.VIDEO,value:{total_pli_received_out:C.pliCount}},{ssrc:r,type:ne.VIDEO,value:{delta_pli_received_out:C.deltaPliCount}},{ssrc:r,type:ne.VIDEO,value:{size_out:E}},{ssrc:r,type:ne.VIDEO,value:{limitation_out:y}}]}break}case Zt.MEDIA_SOURCE:{Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);break}case Zt.TRACK:{Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);break}case Zt.CODEC:const s=[];return Object.keys(t[x.AUDIO]).forEach(r=>{const d=t[x.AUDIO][r];if(d.codec_id_in===c[q.ID]||d.codec_id_out===c[q.ID]){Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const h=Iv(c);c[q.ID]===d.codec_id_in?s.push({ssrc:d.ssrc,type:ne.AUDIO,value:{codec_in:h}}):s.push({ssrc:d.ssrc,type:ne.AUDIO,value:{codec_out:h}})}}),Object.keys(t[x.VIDEO]).forEach(r=>{const d=t[x.VIDEO][r];if(d.codec_id_in===c[q.ID]||d.codec_id_out===c[q.ID]){Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const h=bv(c);c[q.ID]===d.codec_id_in?s.push({ssrc:d.ssrc,type:ne.VIDEO,value:{codec_in:h}}):s.push({ssrc:d.ssrc,type:ne.VIDEO,value:{codec_out:h}})}}),s;case Zt.REMOTE_INBOUND_RTP:{Pe(Ls,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const r=c[q.SSRC],d=ht(r,t,$e.OUTBOUND),h=ht(r,a,$e.OUTBOUND);if(c[q.KIND]===x.AUDIO){const _=Dh(c,x.AUDIO,h,d),g=Ra(c,x.AUDIO,d),T=Uh(c,x.AUDIO,d,h);return[{ssrc:r,type:ne.AUDIO,value:{delta_rtt_ms_out:_.rtt}},{ssrc:r,type:ne.AUDIO,value:{total_rtt_ms_out:_.totalRTT}},{ssrc:r,type:ne.AUDIO,value:{total_rtt_measure_out:_.totalRTTMeasurements}},{ssrc:r,type:ne.AUDIO,value:{delta_jitter_ms_out:g}},{ssrc:r,type:ne.AUDIO,value:{timestamp_out:c[q.TIMESTAMP]}},{ssrc:r,type:ne.AUDIO,value:{total_packets_lost_out:T.packetsLost}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_lost_out:T.deltaPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{percent_packets_lost_out:T.fractionLost}}]}if(c[q.KIND]===x.VIDEO){const _=Dh(c,x.VIDEO,h,d),g=Ra(c,x.VIDEO,d),T=Uh(c,x.VIDEO,d,h);return[{ssrc:r,type:ne.VIDEO,value:{delta_rtt_ms_out:_.rtt}},{ssrc:r,type:ne.VIDEO,value:{total_rtt_ms_out:_.totalRTT}},{ssrc:r,type:ne.VIDEO,value:{total_rtt_measure_out:_.totalRTTMeasurements}},{ssrc:r,type:ne.VIDEO,value:{delta_jitter_ms_out:g}},{ssrc:r,type:ne.VIDEO,value:{timestamp_out:c[q.TIMESTAMP]}},{ssrc:r,type:ne.VIDEO,value:{total_packets_lost_out:T.packetsLost}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_lost_out:T.deltaPacketsLost}},{ssrc:r,type:ne.VIDEO,value:{percent_packets_lost_out:T.fractionLost}}]}break}}return[]},Ia=c=>c<0?1:c>100?4.5:1+.035*c+7/1e6*c*(c-60)*(100-c),Nv=(c,t=x.AUDIO,n,a,o)=>{const s=ht(o,c,$e.INBOUND),r=ht(o,n,$e.INBOUND),d=ht(o,a,$e.INBOUND),h=[],_=[],g=s[t].percent_packets_lost_in,T=s[t].delta_jitter_ms_in,E=r&&r[t].delta_jitter_ms_in||null,y=d&&d[t].delta_jitter_ms_in||null,C=c.data.delta_rtt_connectivity_ms,A=n&&n.data.delta_rtt_connectivity_ms||null,I=a&&a.data.delta_rtt_connectivity_ms||null;C&&h.push(C),A&&h.push(A),I&&h.push(I),T&&_.push(T),n&&E&&_.push(E),a&&y&&_.push(y);const H=h.length>0?Ms(h):100,$=_.length>0?Ms(_):10,oe=93.2-g,N=.18*oe*oe-27.9*oe+1126.62,j=(H+$)/2,Se=j-177.3<0?0:1,ve=.024*j+.11*(j-177.3)*Se,k=N-ve;return Ia(k)},Uv=(c,t=x.AUDIO,n,a,o)=>{const s=ht(o,c,$e.OUTBOUND),r=ht(o,n,$e.OUTBOUND),d=ht(o,a,$e.OUTBOUND),h=[],_=[],g=s[t].percent_packets_lost_out,T=s[t].delta_rtt_ms_out,E=r&&r[t].delta_rtt_ms_out||null,y=d&&d[t].delta_rtt_ms_out||null,C=s[t].delta_jitter_ms_out,A=r&&r[t].delta_jitter_ms_out||null,I=d&&d[t].delta_jitter_ms_out||null,H=c.data.delta_rtt_connectivity_ms,$=n&&n.data.delta_rtt_connectivity_ms||null,oe=a&&a.data.delta_rtt_connectivity_ms||null;T?h.push(T):H&&h.push(H),E?h.push(E):$&&h.push($),y?h.push(y):oe&&h.push(oe),C&&_.push(C),n&&A&&_.push(A),a&&I&&_.push(I);const N=h.length>0?Ms(h):100,j=_.length>0?Ms(_):10,Se=93.2-g,ve=.18*Se*Se-27.9*Se+1126.62,k=(N+j)/2,D=k-177.3<0?0:1,B=.024*k+.11*(k-177.3)*D,V=ve-B;return Ia(V)},Pv=(c,t=x.AUDIO,n,a,o)=>{const s=ht(o,c,$e.INBOUND),r=ht(o,n,$e.INBOUND),d=ht(o,a,$e.INBOUND),h=[],_=[],g=s[t].percent_packets_lost_in/100,T=s[t].delta_jitter_ms_in,E=r&&r[t].delta_jitter_ms_in||null,y=d&&d[t].delta_jitter_ms_in||null,C=c.data.delta_rtt_connectivity_ms,A=n&&n.data.delta_rtt_connectivity_ms||null,I=a&&a.data.delta_rtt_connectivity_ms||null;C&&h.push(C),A&&h.push(A),I&&h.push(I),T&&_.push(T),r&&E&&_.push(E),d&&y&&_.push(y);const H=h.length>0?Ms(h):100,$=_.length>0?Ms(_):10,oe=0,N=19.8,j=29.7,Se=30,ve=(H+$)/2+Se,k=ve-177.3<0?0:1,D=.024*ve+.11*(ve-177.3)*k,V=93.2-(oe+N*Math.log(1+j*g)+D);return Ia(V)},xv=(c,t=x.AUDIO,n,a,o)=>{const s=ht(o,c,$e.OUTBOUND),r=ht(o,n,$e.OUTBOUND),d=ht(o,a,$e.OUTBOUND),h=[],_=[],g=s[t].percent_packets_lost_out/100,T=s[t].delta_rtt_ms_out,E=r&&r[t].delta_rtt_ms_out||null,y=d&&d[t].delta_rtt_ms_out||null,C=s[t].delta_jitter_ms_out,A=r&&r[t].delta_jitter_ms_out||null,I=d&&d[t].delta_jitter_ms_out||null,H=c.data.delta_rtt_connectivity_ms,$=n&&n.data.delta_rtt_connectivity_ms||null,oe=a&&a.data.delta_rtt_connectivity_ms||null;T?h.push(T):H&&h.push(H),E?h.push(E):$&&h.push($),y?h.push(y):oe&&h.push(oe),C&&_.push(C),r&&A&&_.push(A),d&&I&&_.push(I);const N=h.length>0?Ms(h):100,j=_.length>0?Ms(_):10,Se=0,ve=19.8,k=29.7,D=30,B=(N+j)/2+D,V=B-177.3<0?0:1,J=.024*B+.11*(B-177.3)*V,Z=93.2-(Se+ve*Math.log(1+k*g)+J);return Ia(Z)};class kv{constructor(t,n){this._callbacks={onreport:null,onticket:null},this._id=fv(),this._moduleName=this._id,this._probeId=n,this._config=t,this._exporter=new gv(t),this._state=ys.IDLE,this.registerToPCEvents(),on(this._moduleName,`new collector created for probe ${this._probeId}`)}analyze(t,n,a,o){const s=(h,_)=>h===x.AUDIO?_===Zt.INBOUND_RTP?{...Ah}:{...Rh}:_===Zt.INBOUND_RTP?{...Ih}:{...bh},r=lv(n);r.pname=this._config.pname,r.call_id=this._config.cid,r.user_id=this._config.uid,r.count=n?n.count+1:1;let d=null;return t.forEach(h=>{!d&&h.timestamp&&(d=h.timestamp),Dv(h,r,r.pname,o).forEach(g=>{if(g.value&&g.type)if(g.ssrc){let T=r[g.type][g.ssrc];T||(T=s(g.type,h.type),T.ssrc=g.ssrc,r[g.type][g.ssrc]=T),Object.keys(g.value).forEach(E=>{T[E]=g.value[E]})}else Object.keys(g.value).forEach(T=>{r[g.type][T]=g.value[T]})})}),r.timestamp=d,Object.keys(r[x.AUDIO]).forEach(h=>{const _=r[x.AUDIO][h];_.direction===$e.INBOUND?(_.mos_emodel_in=Nv(r,x.AUDIO,n,a,_.ssrc),_.mos_in=Pv(r,x.AUDIO,n,a,_.ssrc)):(_.mos_emodel_out=Uv(r,x.AUDIO,n,a,_.ssrc),_.mos_out=xv(r,x.AUDIO,n,a,_.ssrc))}),r}async takeReferenceStats(){return new Promise((t,n)=>{const a=Date.now();setTimeout(async()=>{try{const o=Date.now()-a,s=Date.now(),r=await this._config.pc.getStats(),d=this.analyze(r,null,null,null),h=Date.now();d.experimental.time_to_measure_ms=h-s,d.experimental.time_to_wait_ms=o,this._exporter.saveReferenceReport(d),Pe(this._moduleName,`got reference report for probe ${this._probeId}`),t()}catch(o){n(o)}},this._config.startAfter)})}async collectStats(){try{if(this._state!==ys.RUNNING||!this._config.pc)return Pe(this._moduleName,`report discarded (too late) for probe ${this._probeId}`),null;const t=Date.now(),n=await this._config.pc.getStats(),a=this.analyze(n,this._exporter.getLastReport(),this._exporter.getBeforeLastReport(),this._exporter.getReferenceReport()),o=Date.now();return a.experimental.time_to_measure_ms=o-t,this._exporter.addReport(a),Pe(this._moduleName,`got report for probe ${this._probeId}#${this._exporter.getReportsNumber()+1}`),this.fireOnReport(a),a}catch(t){return Vn(this._moduleName,`got error ${t}`),null}}async start(){Pe(this._moduleName,"starting"),this.state=ys.RUNNING,this._startedTime=this._exporter.start(),Pe(this._moduleName,"started")}async mute(){this.state=ys.MUTED,Pe(this._moduleName,"muted")}async unmute(){this.state=ys.RUNNING,Pe(this._moduleName,"unmuted")}async stop(t){if(Pe(this._moduleName,`stopping${t?" by watchdog":""}...`),this._stoppedTime=this._exporter.stop(),this.state=ys.IDLE,this._config.ticket){const{ticket:n}=this._exporter;this.fireOnTicket(n)}this._exporter.reset(),Pe(this._moduleName,"stopped")}registerCallback(t,n,a){t in this._callbacks?(this._callbacks[t]={callback:n,context:a},Pe(this._moduleName,`registered callback '${t}'`)):Vn(this._moduleName,`can't register callback for '${t}' - not found`)}unregisterCallback(t){t in this._callbacks?(this._callbacks[t]=null,delete this._callbacks[t],Pe(this._moduleName,`unregistered callback '${t}'`)):Vn(this._moduleName,`can't unregister callback for '${t}' - not found`)}fireOnReport(t){this._callbacks.onreport&&wu(this._callbacks.onreport.callback,this._callbacks.onreport.context,t)}fireOnTicket(t){this._callbacks.onticket&&wu(this._callbacks.onticket.callback,this._callbacks.onticket.context,t)}updateConfig(t){this._config=t,this._exporter.updateConfig(t)}get state(){return this._state}set state(t){this._state=t,Pe(this._moduleName,`state changed to ${t}`)}addCustomEvent(t,n,a,o){this._exporter.addCustomEvent({at:typeof t=="object"?t.toJSON():t,category:n,name:a,description:o})}async registerToPCEvents(){const{pc:t}=this._config;if(navigator.mediaDevices.ondevicechange=async()=>{try{const n=await navigator.mediaDevices.enumerateDevices();this.addCustomEvent(new Date().toJSON(),"device",`${n.length} devices found`,"Media Devices state")}catch{Vn(this._moduleName,"can't get devices")}},t){t.oniceconnectionstatechange=()=>{const a=t.iceConnectionState;a===ii.CONNECTED||a===ii.COMPLETED?this.addCustomEvent(new Date().toJSON(),"call",a,"ICE connection state"):a===ii.DISCONNECTED||a===ii.FAILED?this.addCustomEvent(new Date().toJSON(),"call",a,"ICE connection state"):a===ii.CLOSED&&this.addCustomEvent(new Date().toJSON(),"call","ended","ICE connection state")},t.onicegatheringstatechange=()=>{const a=t.iceGatheringState;this.addCustomEvent(new Date().toJSON(),"call",a,"ICE gathering state")},t.ontrack=a=>{this.addCustomEvent(new Date().toJSON(),"call",`${a.track.kind}track`,"MediaStreamTrack received")},t.onnegotiationneeded=()=>{this.addCustomEvent(new Date().toJSON(),"call","negotiation","Media changed")};const n=t.getReceivers();if(n&&n.length>0){const a=n[0],{transport:o}=a;if(o){const{iceTransport:s}=o;s&&(s.onselectedcandidatepairchange=()=>{this.addCustomEvent(new Date().toJSON(),"call","transport","Candidates Pair changed")})}}}}}class Mv{constructor(t){this._id=t.pname&&t.pname.substr(0,12).padEnd(12," ")||cv(),this._moduleName=this._id,on(this._moduleName,"probe created"),this._config=t,this._collector=new kv(this._config,this._id)}set onreport(t){t?this._collector.registerCallback("onreport",t):this._collector.unregisterCallback("onreport")}set onticket(t){t?this._collector.registerCallback("onticket",t):this._collector.unregisterCallback("onticket")}get id(){return this._id}get pname(){return this._config.pname}get cid(){return this._config.cid}get uid(){return this._config.uid}get state(){return this._collector.state}set state(t){this._collector.state=t}addCustomEvent(t,n,a,o=new Date().toJSON()){this._collector.addCustomEvent(o,n,t,a)}get isRunning(){return this._collector.state===ys.RUNNING}get isIdle(){return this._collector.state===ys.IDLE}updateUserId(t){this._config.uid=t,this._collector.updateConfig(this._config)}updateCallId(t){this._config.cid=t,this._collector.updateConfig(this._config)}start(){if(!this.isIdle){Aa(this._moduleName,"probe is already running");return}this._collector.start()}stop(t=!1){this.isRunning&&this._collector.stop(t)}async takeReferenceStats(){return this._collector.takeReferenceStats()}async collectStats(){return this._collector.collectStats()}}const bt="engine ";class Lv{constructor(t){this._config=t,this._probes=[],this._startedTime=null,this._callbacks={onresult:null},on(bt,`configured for probing every ${this._config.refreshEvery}ms`),on(bt,`configured for starting after ${this._config.startAfter}ms`),on(bt,`${!this._config.stopAfter||this._config.stopAfter!==-1?`configured for stopped after ${this._config.stopAfter}ms`:"configured for never stopped"}`),Pe(bt,"engine initialized")}get probes(){return this._probes}get isRunning(){return this._probes.some(t=>t.isRunning)}get isIdle(){return this._probes.every(t=>t.isIdle)}addNewProbe(t,n){if(!t)throw new Error("undefined peer connection");const a=ov(t,n,this._config),o=new Mv(a);return this._probes.push(o),Pe(bt,`${this._probes.length} probes registered`),o}removeExistingProbe(t){if(!t)throw new Error("undefined probe");t.state===ys.RUNNING&&t.stop(),this._probes=this._probes.filter(n=>t.id!==n.id)}async start(){const t=()=>{this._probes.forEach(s=>s.start())},n=async()=>Promise.all(this._probes.map(s=>s.takeReferenceStats())),a=()=>this.isIdle?!1:!this._config.stopAfter||this._config.stopAfter<0?!0:Date.now()<this._startedTime+this._config.stopAfter,o=async()=>{const s=iv(),r=this._probes.filter(d=>d.isRunning);for(const d of r){const h=await d.collectStats();h&&s.probes.push(h),Pe(bt,`got probe ${d.id}`),await wh(0)}return s.delta_time_to_measure_probes_ms=un(s.probes,"experimental","time_to_measure_ms"),s.delta_KBytes_in=un(s.probes,"data","delta_KBytes_in"),s.delta_KBytes_out=un(s.probes,"data","delta_KBytes_out"),s.delta_kbs_in=un(s.probes,"data","delta_kbs_in"),s.delta_kbs_out=un(s.probes,"data","delta_kbs_out"),s.total_time_decoded_in=un(s.probes,"video","total_time_decoded_in"),s.total_time_encoded_out=un(s.probes,"video","total_time_encoded_out"),s};for(Pe(bt,"starting to collect"),t(),Pe(bt,"generating reference reports..."),await n(),Pe(bt,"reference reports generated"),this._startedTime=Date.now();a();)if(Pe(bt,`wait ${this._config.refreshEvery}ms before collecting`),await wh(this._config.refreshEvery),a()){Pe(bt,"collecting...");const s=Date.now(),r=await o(),d=Date.now();r.delta_time_consumed_to_measure_ms=d-s,this.fireOnReports(r),Pe(bt,"collected")}Pe(bt,"reaching end of the collecting period..."),this.isRunning&&setTimeout(()=>{this.stop()},0)}stop(t){const n=a=>{this._probes.forEach(o=>{o.stop(a)})};on(bt,"stop collecting"),n(t)}registerCallback(t,n,a){t in this._callbacks?(this._callbacks[t]={callback:n,context:a},Pe(bt,`registered callback '${t}'`)):Vn(bt,`can't register callback for '${t}' - not found`)}unregisterCallback(t){t in this._callbacks?(this._callbacks[t]=null,delete this._callbacks[t],Pe(this._moduleName,`unregistered callback '${t}'`)):Vn(this._moduleName,`can't unregister callback for '${t}' - not found`)}fireOnReports(t){this._callbacks.onresult&&t.probes.length>0&&wu(this._callbacks.onresult.callback,this._callbacks.onresult.context,t)}}const $v="interface ";class Hv{constructor(t){this._config=uv(t),on($v,`welcome to ${this._config.name} version ${this._config.version}`),XT(this._config.verbose||!1),this._engine=new Lv(this._config)}setupLogLevel(t){QT(t)}get version(){return this._config.version}get name(){return this._config.name}get probes(){return this._engine.probes}createProbe(t,n){return this._engine.addNewProbe(t,n)}startAllProbes(){this._engine.start()}stopAllProbes(){this._engine.stop()}get running(){return this._engine.isRunning}get idle(){return this._engine.isIdle}removeProbe(t){this._engine.removeExistingProbe(t)}set onresult(t){t?this._engine.registerCallback("onresult",t):this._engine.unregisterCallback("onresult")}}function Fv(c,t){return Object.keys(c).filter(n=>t.includes(n)).reduce((n,a)=>{const o=a;return{...n,[o]:c[o]}},{})}const jv=["mos_in","codec_in","delta_KBytes_in","delta_kbs_in","delta_jitter_ms_in","delta_packets_lost_in"];class qv{constructor(t){this.intervals={},this.emitInterval=t.emitInterval||200,this.onChangeFunction=t.onChangeFunction}start(t,n){t&&t.getTracks().length&&requestAnimationFrame(()=>this.beginCalculation(t,n))}stop(t){this.clearVolumeInterval(t)}clearVolumeInterval(t){clearInterval(this.intervals[t]),delete this.intervals[t]}clearAllIntervals(){Object.keys(this.intervals).forEach(t=>{clearInterval(this.intervals[t])}),this.intervals={}}beginCalculation(t,n){this.clearVolumeInterval(n);const a=an.createAnalyser(),o=an.createMediaStreamSource(t),s=an.createScriptProcessor(2048,1,1);a.smoothingTimeConstant=.8,a.fftSize=1024,o.connect(a),a.connect(s),s.connect(an.destination),this.intervals[n]=setInterval(()=>{const r=new Uint8Array(a.frequencyBinCount);a.getByteFrequencyData(r);let d=0;const h=r.length;for(let g=0;g<h;g++)d+=r[g];const _=d/h;this.onChangeFunction(n,_)},this.emitInterval)}}const ba={SELECTED_INPUT_DEVICE:"OpensipsJSInputDevice",SELECTED_OUTPUT_DEVICE:"OpensipsJSOutputDevice"},Vv=0;class Bv{constructor(t){this.isAutoAnswer=!1,this.muteWhenJoinEnabled=!1,this.isDNDEnabled=!1,this.muted=!1,this.microphoneInputLevelValue=1,this.speakerVolumeValue=1,this.activeRooms={},this.activeCalls={},this.extendedCalls={},this.availableMediaDevices=[],this.selectedMediaDevices={input:"default",output:"default"},this.callStatus={},this.callTime={},this.callMetrics={},this.timeIntervals={},this.metricConfig={refreshEvery:1e3},this.activeStreamValue=null,this.initialStreamValue=null,this.context=t,this.context.on(this.context.newRTCSessionEventName,this.newRTCSessionCallback.bind(this)),this.VUMeter=new qv({onChangeFunction:this.emitVolumeChange.bind(this)}),this.initializeMediaDevices()}get sipOptions(){return{...this.context.options.sipOptions,mediaConstraints:this.getUserMediaConstraints}}get currentActiveRoomId(){return this.currentActiveRoomIdValue}set currentActiveRoomId(t){this.currentActiveRoomIdValue=t,this.context.emit("currentActiveRoomChanged",t)}get autoAnswer(){return this.isAutoAnswer}get callAddingInProgress(){return this.isCallAddingInProgress}set callAddingInProgress(t){this.isCallAddingInProgress=t,this.context.emit("callAddingInProgressChanged",t)}get muteWhenJoin(){return this.muteWhenJoinEnabled}get isDND(){return this.isDNDEnabled}get speakerVolume(){return this.speakerVolumeValue}get microphoneInputLevel(){return this.microphoneInputLevelValue}get getActiveCalls(){return this.activeCalls}get hasActiveCalls(){return Object.values(this.extendedCalls).length>0}get getActiveRooms(){return this.activeRooms}get isMuted(){return this.muted}get getInputDeviceList(){return this.availableMediaDevices.filter(t=>t.kind==="audioinput")}get getOutputDeviceList(){return this.availableMediaDevices.filter(t=>t.kind==="audiooutput")}get getUserMediaConstraints(){return Eh()?{video:!1,audio:!0}:{audio:{deviceId:{exact:this.selectedMediaDevices.input}},video:!1}}get selectedInputDevice(){return this.selectedMediaDevices.input}get selectedOutputDevice(){return this.selectedMediaDevices.output}get activeStream(){return this.activeStreamValue}setAvailableMediaDevices(t){this.availableMediaDevices=t,this.context.emit("changeAvailableDeviceList",t)}async updateDeviceList(){await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);const t=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(t)}async initializeMediaDevices(){const t=localStorage.getItem(ba.SELECTED_INPUT_DEVICE)||"default",n=localStorage.getItem(ba.SELECTED_OUTPUT_DEVICE)||"default";try{const a=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints),o=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(o),await this.setMicrophone(t),await this.setSpeaker(n),navigator.mediaDevices.addEventListener("devicechange",async()=>{const s=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(s)}),a.getTracks().forEach(s=>s.stop())}catch(a){console.error(a)}}setCallTime(t){const n={...t};delete n.callId,this.callTime={...this.callTime,[t.callId]:n},this.context.emit("changeCallTime",this.callTime)}removeCallTime(t){const n={...this.callTime};delete n[t],this.callTime={...n},this.context.emit("changeCallTime",this.callTime)}setTimeInterval(t,n){this.timeIntervals={...this.timeIntervals,[t]:n}}removeTimeInterval(t){const n={...this.timeIntervals};n[t]&&(clearInterval(n[t]),delete n[t],this.timeIntervals={...n})}stopCallTimer(t){this.removeTimeInterval(t),this.removeCallTime(t)}emitVolumeChange(t,n){this.context.emit("changeCallVolume",{callId:t,volume:n})}setMetricsConfig(t){this.metricConfig={...this.metricConfig,...t}}sendDTMF(t,n){if(!/^[A-D0-9]+$/g.test(n))throw new Error("Not allowed character in DTMF input");this.extendedCalls[t].sendDTMF(n)}setIsMuted(t){this.muted=t,this.context.emit("changeIsMuted",t)}processMute(t){const n=this.currentActiveRoomId;this.setIsMuted(t),this.initialStreamValue.getTracks().forEach(a=>a.enabled=!t),this.roomReconfigure(n)}mute(){this.processMute(!0)}unmute(){this.processMute(!1)}async processHold({callId:t,toHold:n,automatic:a}){const o=this.extendedCalls[t];o._automaticHold=a??!1,await new Promise(d=>{const h=()=>{o.putOnHoldTimestamp=n?Date.now():void 0,d()};n?o.hold({},h):o.unhold({},h)}),this.updateCall(o);const r=Object.values(this.extendedCalls).filter(d=>d.roomId===this.currentActiveRoomId&&(n?t!==d._id:!0));r.length>1&&await this.doConference(r)}holdCall(t,n=!1){return this.processHold({callId:t,automatic:n,toHold:!0})}unholdCall(t){return this.processHold({callId:t,toHold:!1})}cancelAllOutgoingUnanswered(){Object.values(this.getActiveCalls).filter(t=>t.direction==="outgoing"&&t.status===Vv).forEach(t=>this.terminateCall(t._id))}answerCall(t){const n=this.extendedCalls[t];this.cancelAllOutgoingUnanswered(),n.answer(this.sipOptions),this.updateCall(n),this.setActiveRoom(n.roomId),n.connection.addEventListener("track",a=>{this.triggerAddStream(a,n)})}async moveCall(t,n){this.updateCallStatus({callId:t,isMoving:!0}),await this.processRoomChange({callId:t,roomId:n}),this.updateCallStatus({callId:t,isMoving:!1})}updateCall(t){this.activeCalls[t._id]=gh(t),this.context.emit("changeActiveCalls",this.activeCalls)}updateRoom(t){const a={...this.activeRooms[t.roomId],...t};this.activeRooms={...this.activeRooms,[t.roomId]:{...a}},this.context.emit("updateRoom",{room:a,roomList:this.activeRooms})}hasAutoAnswerHeaders(t){const n=/answer-after=0/,o=t.request.getHeader("Call-Info");return o&&n.test(o)}addCall(t,n=!0){this.activeCalls={...this.activeCalls,[t._id]:gh(t)},this.extendedCalls[t._id]=t,n&&this.context.emit("changeActiveCalls",this.activeCalls)}addCallStatus(t){this.callStatus={...this.callStatus,[t]:{isMoving:!1,isTransferring:!1,isMerging:!1}},this.context.emit("changeCallStatus",this.callStatus)}updateCallStatus(t){const a={...{...this.callStatus[t.callId]}};t.isMoving!==void 0&&(a.isMoving=t.isMoving),t.isTransferring!==void 0&&(a.isTransferring=t.isTransferring),t.isMerging!==void 0&&(a.isMerging=t.isMerging),this.callStatus={...this.callStatus,[t.callId]:{...a}},this.context.emit("changeCallStatus",this.callStatus)}removeCallStatus(t){const n={...this.callStatus};delete n[t],this.callStatus={...n},this.context.emit("changeCallStatus",this.callStatus)}addRoom(t){this.activeRooms={...this.activeRooms,[t.roomId]:t},this.context.emit("addRoom",{room:t,roomList:this.activeRooms})}getActiveStream(){const t=vh(this.initialStreamValue,this.microphoneInputLevel*2);return t.getTracks().forEach(n=>n.enabled=!this.isMuted),this.setActiveStream(t),t}async setMicrophone(t){if(!this.getInputDeviceList.find(({deviceId:a})=>a===t)||(this.setSelectedInputDevice(t),Object.keys(this.getActiveCalls).length===0))return;await this.setupStream();const n=Object.values(this.extendedCalls).filter(a=>a.roomId===this.currentActiveRoomId);n.length===1?Object.values(n).forEach(async a=>{const o=this.getActiveStream();a.connection.getSenders()[0].replaceTrack(o.getTracks()[0]),this.updateCall(a)}):await this.doConference(n)}setActiveStream(t){this.activeStream&&this.stopVUMeter("origin"),this.setupVUMeter(t,"origin"),this.activeStreamValue=t,this.context.emit("changeActiveStream",t)}async setSpeaker(t){if(!this.getOutputDeviceList.find(({deviceId:o})=>o===t))return;this.setSelectedOutputDevice(t);const n=Object.values(this.extendedCalls);if(n.length===0)return;const a=n.filter(o=>o.roomId===this.currentActiveRoomId);a.length===1?n.forEach(o=>{var s;(s=o.audioTag)==null||s.setSinkId(t),this.updateCall(o)}):await this.doConference(a)}removeRoom(t){const n={...this.activeRooms},a={...n[t]};delete n[t],this.activeRooms={...n},this.context.emit("removeRoom",{room:a,roomList:this.activeRooms})}deleteRoomIfEmpty(t){t!==void 0&&Object.values(this.extendedCalls).filter(n=>n.roomId===t).length===0&&(this.removeRoom(t),this.currentActiveRoomId===t&&(this.currentActiveRoomId=void 0))}checkInitialized(){if(!this.context.initialized)throw new Error("[OpenSIPSJS] You must call `start` method first!")}muteReconfigure(t){this.muted?t.mute({audio:!0}):t.unmute({audio:!0})}async roomReconfigure(t){var a;if(t===void 0)return;const n=Object.values(this.extendedCalls).filter(o=>o.roomId===t);if(this.currentActiveRoomId===t?n.forEach(o=>{o.audioTag&&(this.muteReconfigure(o),o.audioTag.muted=!1,this.updateCall(o))}):n.forEach(o=>{o.audioTag&&(o.audioTag.muted=!0,this.updateCall(o))}),n.length===0)this.deleteRoomIfEmpty(t);else if(n.length===1&&this.currentActiveRoomId!==t)n[0].isOnHold().local||await this.holdCall(n[0].id,!0);else if(n.length===1&&this.currentActiveRoomId===t){if(n[0].isOnHold().local&&n[0]._automaticHold&&await this.unholdCall(n[0].id),n[0].connection&&((a=n[0].connection)!=null&&a.getSenders()[0])){const o=this.getActiveStream();await n[0].connection.getSenders()[0].replaceTrack(o.getTracks()[0]),this.muteReconfigure(n[0])}}else n.length>1&&await this.doConference(n)}async doConference(t){const n=[];t.forEach(a=>{a!=null&&a.connection.getReceivers().forEach(o=>{n.push(o.track)})}),await JT.forEach(t,async a=>{var r;if(a==null)return;const o=new MediaStream,s=an.createMediaStreamDestination();if(a.connection.getReceivers().forEach(d=>{n.forEach(h=>{o.addTrack(d.track),d.track.id!==h.id&&an.createMediaStreamSource(new MediaStream([h])).connect(s)})}),t[0].roomId===this.currentActiveRoomId){const d=this.getActiveStream();an.createMediaStreamSource(d).connect(s)}(r=a.connection)!=null&&r.getSenders()[0]&&(await a.connection.getSenders()[0].replaceTrack(s.stream.getTracks()[0]),this.muteReconfigure(a))})}processCallerMute(t,n){const a=this.extendedCalls[t];a&&a.connection.getReceivers().length&&(a.localMuted=n,a.connection.getReceivers().forEach(o=>{o.track.enabled=!n}),this.updateCall(a))}muteCaller(t){this.processCallerMute(t,!0)}unmuteCaller(t){this.processCallerMute(t,!1)}terminateCall(t){const n=this.extendedCalls[t];n._status!==8&&n.terminate()}transferCall(t,n){if(n.toString().length===0)return new Error("Target must be passed");const a=this.extendedCalls[t];if(!a._is_confirmed&&!a._is_canceled){const o=`sip:${n}@${this.context.sipDomain}`;a.terminate({status_code:302,reason_phrase:"Moved Temporarily",extraHeaders:[`Contact: ${o}`]});return}this.updateCallStatus({callId:t,isTransferring:!0}),a.refer(`sip:${n}@${this.context.sipDomain}`),this.updateCall(a)}mergeCall(t){const n=Object.values(this.extendedCalls).filter(s=>s.roomId===t);if(n.length!==2)return;const a=n[0],o=n[1];!a||!o||(this.updateCallStatus({callId:a._id,isMerging:!0}),this.updateCallStatus({callId:o._id,isMerging:!0}),a.refer(o.remote_identity.uri.toString(),{replaces:o}),this.updateCall(a))}mergeCallByIds(t,n){const a=Object.values(this.extendedCalls).find(s=>s._id===t),o=Object.values(this.extendedCalls).find(s=>s._id===n);if(!a||!o)throw new Error("Call ID is not provided");this.updateCallStatus({callId:t,isMerging:!0}),this.updateCallStatus({callId:n,isMerging:!0}),a.refer(o.remote_identity.uri.toString(),{replaces:o}),this.updateCall(a)}setDND(t){this.isDNDEnabled=t,this.context.emit("changeIsDND",t)}startCallTimer(t){this.removeTimeInterval(t);const n={callId:t,hours:0,minutes:0,seconds:0,formatted:""};this.setCallTime(n);const a=setInterval(()=>{const o={...this.callTime[t]},s=YT(o);this.setCallTime({callId:t,...s})},1e3);this.setTimeInterval(t,a)}async setActiveRoom(t){const n=this.currentActiveRoomId;t!==n&&(this.currentActiveRoomId=t,await this.roomReconfigure(n),await this.roomReconfigure(t))}getNewRoomId(){const t=Object.keys(this.activeRooms);return t.length===0?1:parseInt(t.sort()[t.length-1])+1}async setupCall(t){var _,g;const n=t.session;if(this.getActiveCalls[n.id]!==void 0)return;const o=this.getNewRoomId(),s={started:new Date,incomingInProgress:!1,roomId:o};n.direction==="incoming"?(this.context.logger.log("New incoming call from",(g=(_=n._remote_identity)==null?void 0:_._uri)==null?void 0:g._user),s.incomingInProgress=!0,this.context.subscribe(Qt.CALL_CONFIRMED,T=>{n.id===T.id&&(this.updateRoom({incomingInProgress:!1,roomId:o}),this.startCallTimer(n.id))}),this.context.subscribe(Qt.CALL_FAILED,T=>{n.id===T.id&&(this.updateRoom({incomingInProgress:!1,roomId:o}),this.deleteRoomIfEmpty(o))})):n.direction==="outgoing"&&(n.once("confirmed",()=>{this.startCallTimer(n.id)}),this.startCallTimer(n.id));const r=n,d=this.hasAutoAnswerHeaders(t),h=r.direction==="incoming"&&!this.hasActiveCalls&&(d||this.autoAnswer);r.roomId=o,r.localMuted=!1,r.autoAnswer=h,h?this.addCall(r,!1):this.addCall(r),this.addCallStatus(n.id),this.addRoom(s),h&&this.answerCall(r._id)}removeCall(t){const n={...this.activeCalls};delete n[t],this.activeCalls={...n};const a={...this.extendedCalls};delete a[t],this.extendedCalls={...a},this.context.emit("changeActiveCalls",this.activeCalls)}activeCallListRemove(t){var o;const n=this.extendedCalls[t._id];this.stopVUMeter("origin"),(o=n.connection)==null||o.getSenders().forEach(s=>{s.track.stop()});const a=n.roomId;this.removeCall(t._id),this.roomReconfigure(a)}async newRTCSessionCallback(t){const n=t.session;if(this.isDND){n.terminate({status_code:486,reason_phrase:"Do Not Disturb"});return}if(this.context.triggerListener({listenerType:Qt.NEW_CALL,session:n,event:t}),n.on("ended",a=>{var s,r,d;this.stopVUMeter(n.id),this.context.logger.log("Session ended for",(r=(s=n._remote_identity)==null?void 0:s._uri)==null?void 0:r._user),this.context.triggerListener({listenerType:Qt.CALL_ENDED,session:n,event:a});const o=this.getActiveCalls[n.id];o&&this.activeCallListRemove(o),this.stopCallTimer(n.id),this.removeCallStatus(n.id),this.removeCallMetrics(n.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(d=this.initialStreamValue)==null||d.getTracks().forEach(h=>h.stop()),this.initialStreamValue=null)}),n.on("progress",a=>{var o,s;this.context.logger.log("Session in progress for",(s=(o=n._remote_identity)==null?void 0:o._uri)==null?void 0:s._user),this.context.triggerListener({listenerType:Qt.CALL_PROGRESS,session:n,event:a})}),n.on("failed",a=>{var s,r,d;this.stopVUMeter(n.id),this.context.logger.log("Session failed for",(r=(s=n._remote_identity)==null?void 0:s._uri)==null?void 0:r._user),this.context.triggerListener({listenerType:Qt.CALL_FAILED,session:n,event:a}),n.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0);const o=this.getActiveCalls[n.id];o&&this.activeCallListRemove(o),this.stopCallTimer(n.id),this.removeCallStatus(n.id),this.removeCallMetrics(n.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(d=this.initialStreamValue)==null||d.getTracks().forEach(h=>h.stop()),this.initialStreamValue=null)}),n.on("confirmed",a=>{var o,s;this.context.logger.log("Session confirmed for",(s=(o=n._remote_identity)==null?void 0:o._uri)==null?void 0:s._user),this.context.triggerListener({listenerType:Qt.CALL_CONFIRMED,session:n,event:a}),this.updateCall(n),n.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0)}),await this.setupCall(t),n.direction==="outgoing"){const a=this.getActiveCalls[n.id].roomId;this.setActiveRoom(a)}}setMuteWhenJoin(t){this.muteWhenJoinEnabled=t,this.context.emit("changeMuteWhenJoin",t)}setMicrophoneSensitivity(t){if(t<0||t>1)throw new Error("Value should be in range from 0 to 1!");this.microphoneInputLevelValue=t,this.roomReconfigure(this.currentActiveRoomId)}setSpeakerVolume(t){this.speakerVolumeValue=t,Object.values(this.extendedCalls).forEach(n=>{n.audioTag&&(n.audioTag.volume=t,this.updateCall(n))})}setAutoAnswer(t){this.isAutoAnswer=t}setSelectedInputDevice(t){localStorage.setItem(ba.SELECTED_INPUT_DEVICE,t),this.selectedMediaDevices.input=t,this.context.emit("changeActiveInputMediaDevice",t)}setSelectedOutputDevice(t){localStorage.setItem(ba.SELECTED_OUTPUT_DEVICE,t),this.selectedMediaDevices.output=t,this.context.emit("changeActiveOutputMediaDevice",t)}setCallMetrics(t){const n={...t};delete n.callId,this.callMetrics={...this.callMetrics,[t.callId]:n},this.context.emit("changeCallMetrics",this.callMetrics)}removeCallMetrics(t){const n={...this.callMetrics};delete n[t],this.callMetrics={...n},this.context.emit("changeCallMetrics",this.callMetrics)}getCallQuality(t){const n=new Hv(this.metricConfig),a=n.createProbe(t.connection,{cid:t._id}),o=[];let s;a.onreport=r=>{Object.entries(r.audio).forEach(([_,g])=>{g.direction==="inbound"&&!o.includes(_)&&(o.push(_),s=_)});const d=r.audio[s];if(!d)return;const h=Fv(d,jv);h.callId=t._id,this.setCallMetrics(h)},this.context.subscribe(Qt.CALL_ENDED,r=>{r._id===t._id&&n.stopAllProbes()}),n.startAllProbes()}setupVUMeter(t,n){this.VUMeter.start(t,n)}stopVUMeter(t){this.VUMeter.stop(t)}async setupStream(){const t=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);this.initialStreamValue&&(this.initialStreamValue.getTracks().forEach(n=>n.stop()),this.initialStreamValue=null),this.initialStreamValue=t}async triggerAddStream(t,n){this.setIsMuted(this.muteWhenJoin||this.isMuted),this.initialStreamValue||await this.setupStream();const a=vh(this.initialStreamValue,this.microphoneInputLevel*2),o=this.isMuted||this.muteWhenJoin;a.getTracks().forEach(r=>r.enabled=!o),this.setActiveStream(a),await n.connection.getSenders()[0].replaceTrack(a.getTracks()[0]);const s=new MediaStream([t.track]);PT(s,n,this.selectedOutputDevice,this.speakerVolume),this.setupVUMeter(s,n._id),this.getCallQuality(n),this.updateCall(n)}initCall(t,n,a=!1){if(t.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${t}@${this.context.sipDomain}...`);const o=this.context.call(`sip:${t}@${this.context.sipDomain}`,this.sipOptions);if(this.callAddingInProgress=o.id,n&&this.currentActiveRoomId!==void 0&&(this.processRoomChange({callId:o.id,roomId:this.currentActiveRoomId}),a)){const s=Object.values(this.extendedCalls).filter(r=>r.roomId===this.currentActiveRoomId&&r._id!==o.id);for(const r of s)this.holdCall(r._id,!0)}o.connection.addEventListener("track",s=>{this.triggerAddStream(s,o)})}async processRoomChange({callId:t,roomId:n}){const a=this.extendedCalls[t].roomId;this.extendedCalls[t].roomId=n;const o=this.extendedCalls[t];return this.updateCall(o),await this.setActiveRoom(n),Promise.all([this.roomReconfigure(a),this.roomReconfigure(n)]).then(()=>{this.deleteRoomIfEmpty(a),this.deleteRoomIfEmpty(n)})}}class Gv{constructor(t){this.context=t}get sipOptions(){return{...this.context.options.sipOptions}}initCall(t,n){if(t.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${t}@${this.context.sipDomain}...`),this.context.joinVideoCall(`sip:${t}@${this.context.sipDomain}`,n,this.sipOptions)}stop(t={}){this.context.terminateJanusSessions(t)}startAudio(){this.context.enableJanusAudio(!0)}stopAudio(){this.context.enableJanusAudio(!1)}startVideo(){this.context.enableJanusVideo(!0)}stopVideo(){this.context.enableJanusVideo(!1)}changeMediaConstraints(t){this.context.changeMediaConstraints(t)}startScreenShare(){this.context.startScreenShare()}startBlur(){this.context.startBlur()}stopBlur(){this.context.stopBlur()}}class Wv{constructor(t){this.activeMessages={},this.extendedMessages={},this.msrpHistory={},this.context=t,this.context.on(this.context.newMSRPSessionEventName,this.newMSRPSessionCallback.bind(this.context))}get isMSRPInitializing(){return this.isMSRPInitializingValue}get getActiveMessages(){return this.activeMessages}msrpAnswer(t){const n=this.extendedMessages[t];this.updateMSRPSession(n)}updateMSRPSession(t){this.activeMessages[t._id]=Th(t),this.context.emit("changeActiveMessages",this.activeMessages)}addMMSRPSession(t){this.activeMessages={...this.activeMessages,[t._id]:Th(t)},this.extendedMessages[t._id]=t,this.context.emit("changeActiveMessages",this.activeMessages)}addMSRPMessage(t,n){const a=this.msrpHistory[n.id]||[];a.push(t),this.msrpHistory={...this.msrpHistory,[n.id]:[...a]},this.context.emit("newMSRPMessage",{message:t,session:n})}messageTerminate(t){const n=this.extendedMessages[t];n._status!==8&&n.terminate()}addMessageSession(t){if(!t._id||this.getActiveMessages[t._id]!==void 0)return;const a=t;this.addMMSRPSession(a)}triggerMSRPListener({listenerType:t,session:n,event:a}){const o=this.context.listenersList[t];!o||!o.length||o.forEach(s=>{s(n,a)})}removeMMSRPSession(t){const n={...this.activeMessages};delete n[t],this.activeMessages={...n};const a={...this.extendedMessages};delete a[t],this.extendedMessages={...a},this.context.emit("changeActiveMessages",this.activeMessages)}activeMessageListRemove(t){this.removeMMSRPSession(t._id)}newMSRPSessionCallback(t){const n=t.session;n.on("ended",a=>{this.triggerMSRPListener({listenerType:Qt.CALL_ENDED,session:n,event:a});const o=this.getActiveMessages[n.id];this.activeMessageListRemove(o)}),n.on("failed",a=>{this.triggerMSRPListener({listenerType:Qt.CALL_FAILED,session:n,event:a});const o=this.getActiveMessages[n.id];this.activeMessageListRemove(o)}),n.on("confirmed",a=>{this.triggerMSRPListener({listenerType:Qt.CALL_CONFIRMED,session:n,event:a}),this.updateMSRPSession(n)}),n.on("newMessage",a=>{this.addMSRPMessage(a,n)}),this.addMessageSession(n)}setIsMSRPInitializing(t){this.isMSRPInitializingValue=t,this.context.emit("isMSRPInitializingChanged",t)}initMSRP(t,n,a){if(t.length===0)return console.error("Target must be a valid string");const o=this.context.startMSRP(t,a);o.on("active",()=>{this.addMessageSession(o),o.sendMSRP(n),this.setIsMSRPInitializing(!1)}),this.setIsMSRPInitializing(!0)}sendMSRP(t,n){const a=this.extendedMessages[t];if(!a)throw new Error(`MSRP session with id ${t} doesn't exist!`);a.sendMSRP(n)}}const Ou={AUDIO:"audio",VIDEO:"video",MSRP:"msrp"};class kh{constructor(t){this.opensips=null,this.session=null,this.name=null,this.name=t}setOpensips(t){this.opensips=t}setSession(t){this.session=t}kill(){this.opensips.kill(this.name)}}class Mh extends kh{constructor(t,n){super(t),this._candidates=[],this._subscribeSent=!1,this._configureSent=!1,this._lastTrickleReceived=!1,this.type=n}connect(t={}){this.opaqueId=this.session.generateOpaqueId();const n=xe.cloneArray(t.extraHeaders),a={from_tag:this.session._from_tag};t.fromUserName&&(a.from_uri=new ln("sip",t.fromUserName,this.session._ua.configuration.uri.host),n.push(`P-Preferred-Identity: ${this.session._ua.configuration.uri.toString()}`)),t.fromDisplayName&&(a.from_display_name=t.fromDisplayName),n.push(`Contact: ${this.session._contact}`),n.push("Content-Type: application/json"),this.session._sessionTimers.enabled&&n.push(`Session-Expires: ${this.session._sessionTimers.defaultExpires}${this.session._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new Tt.InitialOutgoingInviteRequest(this.session.target,this.session._ua,a,n),this._createRTCConnection(),this._sendInitialRequest()}getStream(){return this.stream}getConnection(){return this._connection}_createRTCConnection(){this._connection=new RTCPeerConnection({iceServers:[{urls:"stun:turn.voicenter.co",credential:"kxsjahnsdjns3eds23esd",username:"turn2es21e"}]});let t;this._connection.onicecandidate=n=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||n.candidate&&(this._candidates.push(n.candidate),clearTimeout(t),t=setTimeout(()=>{this._lastTrickleReceived=!0,this._subscribeSent&&!this._configureSent&&this._sendConfigureMessage({audio:!0,video:!0})},500))}}addTracks(t){t.forEach(n=>{this._connection.addTrack(n)})}async _sendInitialRequest(){const t=new Kr(this.session._ua,this._request,{onRequestTimeout:()=>{this.session.onRequestTimeout()},onTransportError:()=>{this.session.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});if(await this.generateStream(),!this.stream||!this.stream.getTracks().length)return;this.addTracks(this.stream.getTracks());const n={audio:!1,video:!0};this.jsep_offer=await this._connection.createOffer(n),await this._connection.setLocalDescription(this.jsep_offer);const a={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaqueId},o=JSON.stringify(a);this._request.body=o,t.send()}_receiveInviteResponse(t){if(this._publisherSubscribeSent||!t.body)return;const n=JSON.parse(t.body);this.handleId=n.data.id;const a={janus:"message",body:{request:"join",room:this.session.room_id,ptype:"publisher",display:this.session.display_name+" (Screen Share)",opaque_id:this.opaqueId},handle_id:this.handleId},o=[this.session.getPTypeHeader(kt.PUBLISHER)];this.session.sendRequest(L.SUBSCRIBE,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{var r,d,h,_;if(s.status_code===200){if(this._subscribeSent=!0,s.body)try{const g=JSON.parse(s.body)||{};((d=(r=g.plugindata)==null?void 0:r.data)==null?void 0:d.videoroom)==="joined"&&this.session.myFeedList.push(g.plugindata.data.id),(_=(h=g.plugindata)==null?void 0:h.data)!=null&&_.publishers&&this.session.receivePublishers(g)}catch(g){console.error(g)}this._lastTrickleReceived&&!this._configureSent&&this._sendConfigureMessage({audio:!0,video:!0})}}}}),this._publisherSubscribeSent=!0}async _sendConfigureMessage(t){const n=this._candidates.map(r=>({janus:"trickle",candidate:r,handle_id:this.handleId,session_id:this.session.session_id})),o={configure:{janus:"message",body:{request:"configure",record:!0,filename:this.session.getRecordFileName(),...t},jsep:this.jsep_offer,handle_id:this.handleId,session_id:this.session.session_id},trickles:[...n]},s=["Content-Type: application/json",this.session.getPTypeHeader(kt.ICE)];this.session.sendRequest(L.INFO,{extraHeaders:s,body:JSON.stringify(o),eventHandlers:{onSuccessResponse:async r=>{this._configureSent=!0;const h=r.data.split(`\r
|
159
159
|
`),_=h[h.length-1],g=JSON.parse(_);await this._connection.setRemoteDescription(g.jsep),this._candidates=[]}}})}_sendDetach(){const t={janus:"detach",handle_id:this.handleId,session_id:this.session.session_id},n=[this.session.getPTypeHeader(kt.DETACH)];this.session.sendRequest(L.INFO,{extraHeaders:n,body:JSON.stringify(t)}),this.session._ua.emit("pluginDetach",this.name)}async stopMedia(){this._connection&&(this._connection.close(),this._connection=null),this.stream&&(this.stream=null)}async stop(){await this.session.stopProcessPlugins(this.type);const t=this._connection.getSenders();t.forEach(n=>{const a=n.track;a&&a.stop()}),t.forEach(n=>{this._connection.removeTrack(n)}),await this.stopMedia(),this._sendDetach()}async generateStream(){throw new Error("generateStream method is not implemented")}}class Lh extends kh{constructor(t,n,a={}){super(t),this.stream=null,this.running=!1,this.immediate=!1,this.type="video",this.immediate=a.immediate||!1,this.type=n}start(t){return t}stop(){throw new Error("stop method is not implemented")}async process(t){if(this.immediate){const n=await this.start(t);return this.running=!0,n}return t}async connect(){this.running=!0,await this.session.resyncPlugins(this.type)}terminate(){this.stop()}async kill(){this.stop(),this.running=!1,await this.session.resyncPlugins(this.type)}}class Kv extends IT{constructor(t,n){if(!t.modules.length)throw new Error("options.modules should include at least 1 module");const a={...t.configuration,sockets:t.socketInterfaces.map(o=>new KT.WebSocketInterface(o))};super(a),this.initialized=!1,this.connected=!1,this.logger=console,this.newRTCSessionEventName="newRTCSession",this.registeredEventName="registered",this.unregisteredEventName="unregistered",this.disconnectedEventName="disconnected",this.connectedEventName="connected",this.newMSRPSessionEventName="newMSRPSession",this.isReconnecting=!1,this.activeConnection=!1,this.audio=null,this.msrp=null,this.video=null,this.listenersList={},this.modules=[],t.pnExtraHeaders&&Object.keys(t.pnExtraHeaders).length&&this.registrator().setExtraContactUriParams(t.pnExtraHeaders),this.options=t,this.modules=t.modules,n&&xT(n)&&(this.logger=n)}on(t,n){return super.on(t,n)}off(t,n){return super.off(t,n)}emit(t,n){return super.emit(t,n)}get sipDomain(){return this.options.sipDomain}use(t){if(this.newStreamPlugins.find(n=>n.name===t.name)||this.processStreamPlugins.find(n=>n.name===t.name))throw new Error(`Plugin with name ${t.name} already exists`);if(t instanceof Mh)t.setOpensips(this),this.newStreamPlugins.push(t);else if(t instanceof Lh)t.setOpensips(this),this.processStreamPlugins.push(t);else throw new Error("Wrong plugin instance")}getPlugin(t){return this.newStreamPlugins.find(n=>n.name===t)||this.processStreamPlugins.find(n=>n.name===t)}begin(){if(this.isConnected()){console.error("Connection is already established");return}return this.modules.includes(Ou.AUDIO)&&(this.audio=new Bv(this)),this.modules.includes(Ou.MSRP)&&(this.msrp=new Wv(this)),this.modules.includes(Ou.VIDEO)&&(this.video=new Gv(this)),this.on(this.registeredEventName,()=>{this.logger.log("Successfully registered to",this.options.socketInterfaces[0]),this.setInitialized(!0)}),this.on(this.unregisteredEventName,()=>{this.logger.log("Unregistered from",this.options.socketInterfaces[0]),this.setInitialized(!1)}),this.on(this.connectedEventName,()=>{this.logger.log("Connected to",this.options.socketInterfaces[0]),this.setConnected(!0),this.setReconnecting(!1),this.activeConnection=!0}),this.on(this.disconnectedEventName,()=>{this.isReconnecting||(this.setReconnecting(!0),this.logger.log("Disconnected from",this.options.socketInterfaces[0]),this.logger.log("Reconnecting to",this.options.socketInterfaces[0]),this.stop(),this.setInitialized(!1),this.setConnected(!1),this.activeConnection&&setTimeout(this.start.bind(this),5e3))}),this.logger.log("Connecting to",this.options.socketInterfaces[0]),this.start(),this}disconnect(){this.activeConnection=!1,this.stop()}subscribe(t,n){const o=!this.listenersList[t]||!this.listenersList[t].length?[n]:[...this.listenersList[t],n];this.listenersList={...this.listenersList,[t]:o}}removeIListener(t){const n={...this.listenersList};delete n[t],this.listenersList={...n}}triggerListener({listenerType:t,session:n,event:a}){const o=this.listenersList[t];!o||!o.length||o.forEach(s=>{s(n,a)})}setInitialized(t){this.initialized=t,this.emit("ready",t)}setConnected(t){this.connected=t,this.emit("connection",t)}setReconnecting(t){this.isReconnecting=t,this.emit("reconnecting",t)}}Nt.BaseNewStreamPlugin=Mh,Nt.BaseProcessStreamPlugin=Lh,Nt.default=Kv,Object.defineProperties(Nt,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|