@voicenter-team/opensips-js 1.0.91 → 1.0.93

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,156 +1,158 @@
1
- "use strict";var U_=Object.defineProperty;var P_=(c,s,r)=>s in c?U_(c,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):c[s]=r;var Wt=(c,s,r)=>(P_(c,typeof s!="symbol"?s+"":s,r),r);var x_=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Xe(c){return c&&c.__esModule&&Object.prototype.hasOwnProperty.call(c,"default")?c.default:c}const M_="jssip",k_="JsSIP",L_="the Javascript SIP library",$_="3.10.0",H_="https://jssip.net",F_=["José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)","Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)"],j_="lib/JsSIP.d.ts",q_="lib-es5/JsSIP.js",V_=["sip","websocket","webrtc","node","browser","library"],B_="MIT",G_={type:"git",url:"https://github.com/versatica/JsSIP.git"},W_={url:"https://github.com/versatica/JsSIP/issues"},K_={"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},Y_={"@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"},J_={lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"},Lo={name:M_,title:k_,description:L_,version:$_,homepage:H_,contributors:F_,types:j_,main:q_,keywords:V_,license:B_,repository:G_,bugs:W_,dependencies:K_,devDependencies:Y_,scripts:J_};var qu=Lo,it={USER_AGENT:"".concat(qu.title," ").concat(qu.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 fo(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?fo=function(r){return typeof r}:fo=function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},fo(c)}function $o(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function Ho(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&zi(c,s)}function Fo(c){var s=Hf();return function(){var o=Xi(c),a;if(s){var t=Xi(this).constructor;a=Reflect.construct(o,arguments,t)}else a=o.apply(this,arguments);return z_(this,a)}}function z_(c,s){return s&&(fo(s)==="object"||typeof s=="function")?s:X_(c)}function X_(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function hr(c){var s=typeof Map=="function"?new Map:void 0;return hr=function(o){if(o===null||!Q_(o))return o;if(typeof o!="function")throw new TypeError("Super expression must either be null or a function");if(typeof s<"u"){if(s.has(o))return s.get(o);s.set(o,a)}function a(){return _o(o,arguments,Xi(this).constructor)}return a.prototype=Object.create(o.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),zi(a,o)},hr(c)}function _o(c,s,r){return Hf()?_o=Reflect.construct:_o=function(a,t,n){var d=[null];d.push.apply(d,t);var _=Function.bind.apply(a,d),h=new _;return n&&zi(h,n.prototype),h},_o.apply(null,arguments)}function Hf(){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 Q_(c){return Function.toString.call(c).indexOf("[native code]")!==-1}function zi(c,s){return zi=Object.setPrototypeOf||function(o,a){return o.__proto__=a,o},zi(c,s)}function Xi(c){return Xi=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)},Xi(c)}var Z_=function(c){Ho(r,c);var s=Fo(r);function r(o,a){var t;return $o(this,r),t=s.call(this),t.code=1,t.name="CONFIGURATION_ERROR",t.parameter=o,t.value=a,t.message=t.value?"Invalid value ".concat(JSON.stringify(t.value),' for parameter "').concat(t.parameter,'"'):"Missing parameter: ".concat(t.parameter),t}return r}(hr(Error)),eh=function(c){Ho(r,c);var s=Fo(r);function r(o){var a;return $o(this,r),a=s.call(this),a.code=2,a.name="INVALID_STATE_ERROR",a.status=o,a.message="Invalid status: ".concat(o),a}return r}(hr(Error)),th=function(c){Ho(r,c);var s=Fo(r);function r(o){var a;return $o(this,r),a=s.call(this),a.code=3,a.name="NOT_SUPPORTED_ERROR",a.message=o,a}return r}(hr(Error)),sh=function(c){Ho(r,c);var s=Fo(r);function r(o){var a;return $o(this,r),a=s.call(this),a.code=4,a.name="NOT_READY_ERROR",a.message=o,a}return r}(hr(Error)),Bs={ConfigurationError:Z_,InvalidStateError:eh,NotSupportedError:th,NotReadyError:sh},Ze={},oa,Vu;function Cu(){if(Vu)return oa;Vu=1;function c(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}function s(t,n){for(var d=0;d<n.length;d++){var _=n[d];_.enumerable=_.enumerable||!1,_.configurable=!0,"value"in _&&(_.writable=!0),Object.defineProperty(t,_.key,_)}}function r(t,n,d){return n&&s(t.prototype,n),d&&s(t,d),t}var o=Gs(),a=is();return oa=function(){r(t,null,[{key:"parse",value:function(d){if(d=a.parse(d,"Name_Addr_Header"),d!==-1)return d}}]);function t(n,d,_){if(c(this,t),!n||!(n instanceof o))throw new TypeError('missing or invalid "uri" parameter');this._uri=n,this._parameters={},this.display_name=d;for(var h in _)Object.prototype.hasOwnProperty.call(_,h)&&this.setParam(h,_[h])}return r(t,[{key:"setParam",value:function(d,_){d&&(this._parameters[d.toLowerCase()]=typeof _>"u"||_===null?null:_.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 _=this._parameters[d];return delete this._parameters[d],_}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"clone",value:function(){return new t(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 _ in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,_)&&(d+=";".concat(_),this._parameters[_]!==null&&(d+="=".concat(this._parameters[_])));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}}]),t}(),oa}var aa,Bu;function is(){return Bu||(Bu=1,aa=function(){function c(r){return'"'+r.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 s={parse:function(o,a){var t={CRLF:g,DIGIT:T,ALPHA:E,HEXDIG:y,WSP:A,OCTET:C,DQUOTE:I,SP:H,HTAB:L,alphanum:ae,reserved:N,unreserved:j,mark:Se,escaped:ve,LWS:M,SWS:D,HCOLON:B,TEXT_UTF8_TRIM:V,TEXT_UTF8char:J,UTF8_NONASCII:F,UTF8_CONT:X,LHEX:U,token:P,token_nodot:se,separators:tt,word:ee,STAR:W,SLASH:G,EQUAL:re,LPAREN:ge,RPAREN:be,RAQUOT:xe,LAQUOT:Ce,COMMA:le,SEMI:ye,COLON:st,LDQUOT:lt,RDQUOT:Ee,comment:Ae,ctext:Ie,quoted_string:Oe,quoted_string_clean:pe,qdtext:ue,quoted_pair:de,SIP_URI_noparams:we,SIP_URI:Ne,uri_scheme:Qe,uri_scheme_sips:Le,uri_scheme_sip:kt,userinfo:ht,user:Rn,user_unreserved:In,password:Ws,hostport:Xt,host:os,hostname:Ks,domainlabel:bn,toplabel:wn,IPv6reference:Ys,IPv6address:me,h16:oe,ls32:ot,IPv4address:Gt,dec_octet:ys,port:gr,uri_parameters:On,uri_parameter:Dn,transport_param:Tr,user_param:vr,method_param:Er,ttl_param:Sr,maddr_param:yr,lr_param:Ar,other_param:Cr,pname:Rr,pvalue:As,paramchar:Cs,param_unreserved:Ir,headers:Js,header:zs,hname:br,hvalue:Rs,hnv_unreserved:Xs,Request_Response:hl,Request_Line:wr,Request_URI:Nn,absoluteURI:Un,hier_part:Or,net_path:Qs,abs_path:Zs,opaque_part:Is,uric:bs,uric_no_slash:Dr,path_segments:en,segment:ws,param:as,pchar:Os,scheme:Nr,authority:Ur,srvr:Pr,reg_name:xr,query:Pn,SIP_Version:xn,INVITEm:Mr,ACKm:kr,OPTIONSm:Lr,BYEm:$r,CANCELm:Hr,REGISTERm:Fr,SUBSCRIBEm:jr,NOTIFYm:qr,REFERm:tn,Method:sn,Status_Line:Vr,Status_Code:Br,extension_code:Gr,Reason_Phrase:dl,Allow_Events:Go,Call_ID:Wo,Contact:Mn,contact_param:Lt,name_addr:$t,display_name:Ds,contact_params:kn,c_p_q:Wr,c_p_expires:Qt,delta_seconds:Zt,qvalue:Ge,generic_param:We,gen_value:pl,Content_Disposition:ml,disp_type:Ln,disp_param:$n,handling_param:gl,Content_Encoding:Ko,Content_Length:Yo,Content_Type:Tl,media_type:Kr,m_type:Yr,discrete_type:Jr,composite_type:nn,extension_token:rn,x_token:zr,m_subtype:Hn,m_parameter:Fn,m_value:vl,CSeq:El,CSeq_value:Sl,Expires:Jo,Event:ln,event_type:on,From:Xr,from_param:an,tag_param:Qr,Max_Forwards:zo,Min_Expires:Xo,Name_Addr_Header:Qo,Proxy_Authenticate:Zr,challenge:jn,other_challenge:Ns,auth_param:es,digest_cln:un,realm:ei,realm_value:ti,domain:cn,URI:fn,nonce:si,nonce_value:ni,opaque:ri,stale:ii,algorithm:li,qop_options:_n,qop_value:qn,Proxy_Require:Zo,Record_Route:Vn,rec_route:Bn,Reason:oi,reason_param:Gn,reason_cause:yl,Require:ea,Route:Wn,route_param:Kn,Subscription_State:Al,substate_value:Yn,subexp_params:Jn,event_reason_value:Cl,Subject:ta,Supported:sa,To:ai,to_param:ui,Via:zn,via_param:Us,via_params:Xn,via_ttl:ci,via_maddr:fi,via_received:_i,via_branch:hi,response_port:di,rport:pi,sent_protocol:mi,protocol_name:gi,transport:Ti,sent_by:vi,via_host:Ei,via_port:Qn,ttl:Si,WWW_Authenticate:na,Session_Expires:Rl,s_e_expires:Zn,s_e_params:er,s_e_refresher:Il,extension_header:bl,header_value:wl,message_body:ra,uuid_URI:Ol,uuid:Ht,hex4:Ft,hex8:yi,hex12:Dl,Refer_To:ia,Replaces:Nl,call_id:tr,replaces_param:sr,to_tag:Ai,from_tag:Ci,early_flag:Ul};if(a!==void 0){if(t[a]===void 0)throw new Error("Invalid rule name: "+c(a)+".")}else a="CRLF";var n=0,d=0,_=[];function h(e){n<d||(n>d&&(d=n,_=[]),_.push(e))}function g(){var e;return o.substr(n,2)===`\r
2
- `?(e=`\r
3
- `,n+=2):(e=null,h('"\\r\\n"')),e}function T(){var e;return/^[0-9]/.test(o.charAt(n))?(e=o.charAt(n),n++):(e=null,h("[0-9]")),e}function E(){var e;return/^[a-zA-Z]/.test(o.charAt(n))?(e=o.charAt(n),n++):(e=null,h("[a-zA-Z]")),e}function y(){var e;return/^[0-9a-fA-F]/.test(o.charAt(n))?(e=o.charAt(n),n++):(e=null,h("[0-9a-fA-F]")),e}function A(){var e;return e=H(),e===null&&(e=L()),e}function C(){var e;return/^[\0-\xFF]/.test(o.charAt(n))?(e=o.charAt(n),n++):(e=null,h("[\\0-\\xFF]")),e}function I(){var e;return/^["]/.test(o.charAt(n))?(e=o.charAt(n),n++):(e=null,h('["]')),e}function H(){var e;return o.charCodeAt(n)===32?(e=" ",n++):(e=null,h('" "')),e}function L(){var e;return o.charCodeAt(n)===9?(e=" ",n++):(e=null,h('"\\t"')),e}function ae(){var e;return/^[a-zA-Z0-9]/.test(o.charAt(n))?(e=o.charAt(n),n++):(e=null,h("[a-zA-Z0-9]")),e}function N(){var e;return o.charCodeAt(n)===59?(e=";",n++):(e=null,h('";"')),e===null&&(o.charCodeAt(n)===47?(e="/",n++):(e=null,h('"/"')),e===null&&(o.charCodeAt(n)===63?(e="?",n++):(e=null,h('"?"')),e===null&&(o.charCodeAt(n)===58?(e=":",n++):(e=null,h('":"')),e===null&&(o.charCodeAt(n)===64?(e="@",n++):(e=null,h('"@"')),e===null&&(o.charCodeAt(n)===38?(e="&",n++):(e=null,h('"&"')),e===null&&(o.charCodeAt(n)===61?(e="=",n++):(e=null,h('"="')),e===null&&(o.charCodeAt(n)===43?(e="+",n++):(e=null,h('"+"')),e===null&&(o.charCodeAt(n)===36?(e="$",n++):(e=null,h('"$"')),e===null&&(o.charCodeAt(n)===44?(e=",",n++):(e=null,h('","'))))))))))),e}function j(){var e;return e=ae(),e===null&&(e=Se()),e}function Se(){var e;return o.charCodeAt(n)===45?(e="-",n++):(e=null,h('"-"')),e===null&&(o.charCodeAt(n)===95?(e="_",n++):(e=null,h('"_"')),e===null&&(o.charCodeAt(n)===46?(e=".",n++):(e=null,h('"."')),e===null&&(o.charCodeAt(n)===33?(e="!",n++):(e=null,h('"!"')),e===null&&(o.charCodeAt(n)===126?(e="~",n++):(e=null,h('"~"')),e===null&&(o.charCodeAt(n)===42?(e="*",n++):(e=null,h('"*"')),e===null&&(o.charCodeAt(n)===39?(e="'",n++):(e=null,h(`"'"`)),e===null&&(o.charCodeAt(n)===40?(e="(",n++):(e=null,h('"("')),e===null&&(o.charCodeAt(n)===41?(e=")",n++):(e=null,h('")"')))))))))),e}function ve(){var e,l,u,f,p;return f=n,p=n,o.charCodeAt(n)===37?(e="%",n++):(e=null,h('"%"')),e!==null?(l=y(),l!==null?(u=y(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m,v){return v.join("")}(f,e)),e===null&&(n=f),e}function M(){var e,l,u,f,p,m;for(f=n,p=n,m=n,e=[],l=A();l!==null;)e.push(l),l=A();if(e!==null?(l=g(),l!==null?e=[e,l]:(e=null,n=m)):(e=null,n=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,n=p)}else e=null,n=p;return e!==null&&(e=function(v){return" "}()),e===null&&(n=f),e}function D(){var e;return e=M(),e=e!==null?e:"",e}function B(){var e,l,u,f,p;for(f=n,p=n,e=[],l=H(),l===null&&(l=L());l!==null;)e.push(l),l=H(),l===null&&(l=L());return e!==null?(o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m){return":"}()),e===null&&(n=f),e}function V(){var e,l,u,f,p,m,v;if(p=n,m=n,l=J(),l!==null)for(e=[];l!==null;)e.push(l),l=J();else e=null;if(e!==null){for(l=[],v=n,u=[],f=M();f!==null;)u.push(f),f=M();for(u!==null?(f=J(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);u!==null;){for(l.push(u),v=n,u=[],f=M();f!==null;)u.push(f),f=M();u!==null?(f=J(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v)}l!==null?e=[e,l]:(e=null,n=m)}else e=null,n=m;return e!==null&&(e=function(S){return o.substring(n,S)}(p)),e===null&&(n=p),e}function J(){var e;return/^[!-~]/.test(o.charAt(n))?(e=o.charAt(n),n++):(e=null,h("[!-~]")),e===null&&(e=F()),e}function F(){var e;return/^[\x80-\uFFFF]/.test(o.charAt(n))?(e=o.charAt(n),n++):(e=null,h("[\\x80-\\uFFFF]")),e}function X(){var e;return/^[\x80-\xBF]/.test(o.charAt(n))?(e=o.charAt(n),n++):(e=null,h("[\\x80-\\xBF]")),e}function U(){var e;return e=T(),e===null&&(/^[a-f]/.test(o.charAt(n))?(e=o.charAt(n),n++):(e=null,h("[a-f]"))),e}function P(){var e,l,u;if(u=n,l=ae(),l===null&&(o.charCodeAt(n)===45?(l="-",n++):(l=null,h('"-"')),l===null&&(o.charCodeAt(n)===46?(l=".",n++):(l=null,h('"."')),l===null&&(o.charCodeAt(n)===33?(l="!",n++):(l=null,h('"!"')),l===null&&(o.charCodeAt(n)===37?(l="%",n++):(l=null,h('"%"')),l===null&&(o.charCodeAt(n)===42?(l="*",n++):(l=null,h('"*"')),l===null&&(o.charCodeAt(n)===95?(l="_",n++):(l=null,h('"_"')),l===null&&(o.charCodeAt(n)===43?(l="+",n++):(l=null,h('"+"')),l===null&&(o.charCodeAt(n)===96?(l="`",n++):(l=null,h('"`"')),l===null&&(o.charCodeAt(n)===39?(l="'",n++):(l=null,h(`"'"`)),l===null&&(o.charCodeAt(n)===126?(l="~",n++):(l=null,h('"~"')))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=ae(),l===null&&(o.charCodeAt(n)===45?(l="-",n++):(l=null,h('"-"')),l===null&&(o.charCodeAt(n)===46?(l=".",n++):(l=null,h('"."')),l===null&&(o.charCodeAt(n)===33?(l="!",n++):(l=null,h('"!"')),l===null&&(o.charCodeAt(n)===37?(l="%",n++):(l=null,h('"%"')),l===null&&(o.charCodeAt(n)===42?(l="*",n++):(l=null,h('"*"')),l===null&&(o.charCodeAt(n)===95?(l="_",n++):(l=null,h('"_"')),l===null&&(o.charCodeAt(n)===43?(l="+",n++):(l=null,h('"+"')),l===null&&(o.charCodeAt(n)===96?(l="`",n++):(l=null,h('"`"')),l===null&&(o.charCodeAt(n)===39?(l="'",n++):(l=null,h(`"'"`)),l===null&&(o.charCodeAt(n)===126?(l="~",n++):(l=null,h('"~"'))))))))))));else e=null;return e!==null&&(e=function(f){return o.substring(n,f)}(u)),e===null&&(n=u),e}function se(){var e,l,u;if(u=n,l=ae(),l===null&&(o.charCodeAt(n)===45?(l="-",n++):(l=null,h('"-"')),l===null&&(o.charCodeAt(n)===33?(l="!",n++):(l=null,h('"!"')),l===null&&(o.charCodeAt(n)===37?(l="%",n++):(l=null,h('"%"')),l===null&&(o.charCodeAt(n)===42?(l="*",n++):(l=null,h('"*"')),l===null&&(o.charCodeAt(n)===95?(l="_",n++):(l=null,h('"_"')),l===null&&(o.charCodeAt(n)===43?(l="+",n++):(l=null,h('"+"')),l===null&&(o.charCodeAt(n)===96?(l="`",n++):(l=null,h('"`"')),l===null&&(o.charCodeAt(n)===39?(l="'",n++):(l=null,h(`"'"`)),l===null&&(o.charCodeAt(n)===126?(l="~",n++):(l=null,h('"~"'))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=ae(),l===null&&(o.charCodeAt(n)===45?(l="-",n++):(l=null,h('"-"')),l===null&&(o.charCodeAt(n)===33?(l="!",n++):(l=null,h('"!"')),l===null&&(o.charCodeAt(n)===37?(l="%",n++):(l=null,h('"%"')),l===null&&(o.charCodeAt(n)===42?(l="*",n++):(l=null,h('"*"')),l===null&&(o.charCodeAt(n)===95?(l="_",n++):(l=null,h('"_"')),l===null&&(o.charCodeAt(n)===43?(l="+",n++):(l=null,h('"+"')),l===null&&(o.charCodeAt(n)===96?(l="`",n++):(l=null,h('"`"')),l===null&&(o.charCodeAt(n)===39?(l="'",n++):(l=null,h(`"'"`)),l===null&&(o.charCodeAt(n)===126?(l="~",n++):(l=null,h('"~"')))))))))));else e=null;return e!==null&&(e=function(f){return o.substring(n,f)}(u)),e===null&&(n=u),e}function tt(){var e;return o.charCodeAt(n)===40?(e="(",n++):(e=null,h('"("')),e===null&&(o.charCodeAt(n)===41?(e=")",n++):(e=null,h('")"')),e===null&&(o.charCodeAt(n)===60?(e="<",n++):(e=null,h('"<"')),e===null&&(o.charCodeAt(n)===62?(e=">",n++):(e=null,h('">"')),e===null&&(o.charCodeAt(n)===64?(e="@",n++):(e=null,h('"@"')),e===null&&(o.charCodeAt(n)===44?(e=",",n++):(e=null,h('","')),e===null&&(o.charCodeAt(n)===59?(e=";",n++):(e=null,h('";"')),e===null&&(o.charCodeAt(n)===58?(e=":",n++):(e=null,h('":"')),e===null&&(o.charCodeAt(n)===92?(e="\\",n++):(e=null,h('"\\\\"')),e===null&&(e=I(),e===null&&(o.charCodeAt(n)===47?(e="/",n++):(e=null,h('"/"')),e===null&&(o.charCodeAt(n)===91?(e="[",n++):(e=null,h('"["')),e===null&&(o.charCodeAt(n)===93?(e="]",n++):(e=null,h('"]"')),e===null&&(o.charCodeAt(n)===63?(e="?",n++):(e=null,h('"?"')),e===null&&(o.charCodeAt(n)===61?(e="=",n++):(e=null,h('"="')),e===null&&(o.charCodeAt(n)===123?(e="{",n++):(e=null,h('"{"')),e===null&&(o.charCodeAt(n)===125?(e="}",n++):(e=null,h('"}"')),e===null&&(e=H(),e===null&&(e=L())))))))))))))))))),e}function ee(){var e,l,u;if(u=n,l=ae(),l===null&&(o.charCodeAt(n)===45?(l="-",n++):(l=null,h('"-"')),l===null&&(o.charCodeAt(n)===46?(l=".",n++):(l=null,h('"."')),l===null&&(o.charCodeAt(n)===33?(l="!",n++):(l=null,h('"!"')),l===null&&(o.charCodeAt(n)===37?(l="%",n++):(l=null,h('"%"')),l===null&&(o.charCodeAt(n)===42?(l="*",n++):(l=null,h('"*"')),l===null&&(o.charCodeAt(n)===95?(l="_",n++):(l=null,h('"_"')),l===null&&(o.charCodeAt(n)===43?(l="+",n++):(l=null,h('"+"')),l===null&&(o.charCodeAt(n)===96?(l="`",n++):(l=null,h('"`"')),l===null&&(o.charCodeAt(n)===39?(l="'",n++):(l=null,h(`"'"`)),l===null&&(o.charCodeAt(n)===126?(l="~",n++):(l=null,h('"~"')),l===null&&(o.charCodeAt(n)===40?(l="(",n++):(l=null,h('"("')),l===null&&(o.charCodeAt(n)===41?(l=")",n++):(l=null,h('")"')),l===null&&(o.charCodeAt(n)===60?(l="<",n++):(l=null,h('"<"')),l===null&&(o.charCodeAt(n)===62?(l=">",n++):(l=null,h('">"')),l===null&&(o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l===null&&(o.charCodeAt(n)===92?(l="\\",n++):(l=null,h('"\\\\"')),l===null&&(l=I(),l===null&&(o.charCodeAt(n)===47?(l="/",n++):(l=null,h('"/"')),l===null&&(o.charCodeAt(n)===91?(l="[",n++):(l=null,h('"["')),l===null&&(o.charCodeAt(n)===93?(l="]",n++):(l=null,h('"]"')),l===null&&(o.charCodeAt(n)===63?(l="?",n++):(l=null,h('"?"')),l===null&&(o.charCodeAt(n)===123?(l="{",n++):(l=null,h('"{"')),l===null&&(o.charCodeAt(n)===125?(l="}",n++):(l=null,h('"}"'))))))))))))))))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=ae(),l===null&&(o.charCodeAt(n)===45?(l="-",n++):(l=null,h('"-"')),l===null&&(o.charCodeAt(n)===46?(l=".",n++):(l=null,h('"."')),l===null&&(o.charCodeAt(n)===33?(l="!",n++):(l=null,h('"!"')),l===null&&(o.charCodeAt(n)===37?(l="%",n++):(l=null,h('"%"')),l===null&&(o.charCodeAt(n)===42?(l="*",n++):(l=null,h('"*"')),l===null&&(o.charCodeAt(n)===95?(l="_",n++):(l=null,h('"_"')),l===null&&(o.charCodeAt(n)===43?(l="+",n++):(l=null,h('"+"')),l===null&&(o.charCodeAt(n)===96?(l="`",n++):(l=null,h('"`"')),l===null&&(o.charCodeAt(n)===39?(l="'",n++):(l=null,h(`"'"`)),l===null&&(o.charCodeAt(n)===126?(l="~",n++):(l=null,h('"~"')),l===null&&(o.charCodeAt(n)===40?(l="(",n++):(l=null,h('"("')),l===null&&(o.charCodeAt(n)===41?(l=")",n++):(l=null,h('")"')),l===null&&(o.charCodeAt(n)===60?(l="<",n++):(l=null,h('"<"')),l===null&&(o.charCodeAt(n)===62?(l=">",n++):(l=null,h('">"')),l===null&&(o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l===null&&(o.charCodeAt(n)===92?(l="\\",n++):(l=null,h('"\\\\"')),l===null&&(l=I(),l===null&&(o.charCodeAt(n)===47?(l="/",n++):(l=null,h('"/"')),l===null&&(o.charCodeAt(n)===91?(l="[",n++):(l=null,h('"["')),l===null&&(o.charCodeAt(n)===93?(l="]",n++):(l=null,h('"]"')),l===null&&(o.charCodeAt(n)===63?(l="?",n++):(l=null,h('"?"')),l===null&&(o.charCodeAt(n)===123?(l="{",n++):(l=null,h('"{"')),l===null&&(o.charCodeAt(n)===125?(l="}",n++):(l=null,h('"}"')))))))))))))))))))))))));else e=null;return e!==null&&(e=function(f){return o.substring(n,f)}(u)),e===null&&(n=u),e}function W(){var e,l,u,f,p;return f=n,p=n,e=D(),e!==null?(o.charCodeAt(n)===42?(l="*",n++):(l=null,h('"*"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m){return"*"}()),e===null&&(n=f),e}function G(){var e,l,u,f,p;return f=n,p=n,e=D(),e!==null?(o.charCodeAt(n)===47?(l="/",n++):(l=null,h('"/"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m){return"/"}()),e===null&&(n=f),e}function re(){var e,l,u,f,p;return f=n,p=n,e=D(),e!==null?(o.charCodeAt(n)===61?(l="=",n++):(l=null,h('"="')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m){return"="}()),e===null&&(n=f),e}function ge(){var e,l,u,f,p;return f=n,p=n,e=D(),e!==null?(o.charCodeAt(n)===40?(l="(",n++):(l=null,h('"("')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m){return"("}()),e===null&&(n=f),e}function be(){var e,l,u,f,p;return f=n,p=n,e=D(),e!==null?(o.charCodeAt(n)===41?(l=")",n++):(l=null,h('")"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m){return")"}()),e===null&&(n=f),e}function xe(){var e,l,u,f;return u=n,f=n,o.charCodeAt(n)===62?(e=">",n++):(e=null,h('">"')),e!==null?(l=D(),l!==null?e=[e,l]:(e=null,n=f)):(e=null,n=f),e!==null&&(e=function(p){return">"}()),e===null&&(n=u),e}function Ce(){var e,l,u,f;return u=n,f=n,e=D(),e!==null?(o.charCodeAt(n)===60?(l="<",n++):(l=null,h('"<"')),l!==null?e=[e,l]:(e=null,n=f)):(e=null,n=f),e!==null&&(e=function(p){return"<"}()),e===null&&(n=u),e}function le(){var e,l,u,f,p;return f=n,p=n,e=D(),e!==null?(o.charCodeAt(n)===44?(l=",",n++):(l=null,h('","')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m){return","}()),e===null&&(n=f),e}function ye(){var e,l,u,f,p;return f=n,p=n,e=D(),e!==null?(o.charCodeAt(n)===59?(l=";",n++):(l=null,h('";"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m){return";"}()),e===null&&(n=f),e}function st(){var e,l,u,f,p;return f=n,p=n,e=D(),e!==null?(o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m){return":"}()),e===null&&(n=f),e}function lt(){var e,l,u,f;return u=n,f=n,e=D(),e!==null?(l=I(),l!==null?e=[e,l]:(e=null,n=f)):(e=null,n=f),e!==null&&(e=function(p){return'"'}()),e===null&&(n=u),e}function Ee(){var e,l,u,f;return u=n,f=n,e=I(),e!==null?(l=D(),l!==null?e=[e,l]:(e=null,n=f)):(e=null,n=f),e!==null&&(e=function(p){return'"'}()),e===null&&(n=u),e}function Ae(){var e,l,u,f;if(f=n,e=ge(),e!==null){for(l=[],u=Ie(),u===null&&(u=de(),u===null&&(u=Ae()));u!==null;)l.push(u),u=Ie(),u===null&&(u=de(),u===null&&(u=Ae()));l!==null?(u=be(),u!==null?e=[e,l,u]:(e=null,n=f)):(e=null,n=f)}else e=null,n=f;return e}function Ie(){var e;return/^[!-']/.test(o.charAt(n))?(e=o.charAt(n),n++):(e=null,h("[!-']")),e===null&&(/^[*-[]/.test(o.charAt(n))?(e=o.charAt(n),n++):(e=null,h("[*-[]")),e===null&&(/^[\]-~]/.test(o.charAt(n))?(e=o.charAt(n),n++):(e=null,h("[\\]-~]")),e===null&&(e=F(),e===null&&(e=M())))),e}function Oe(){var e,l,u,f,p,m;if(p=n,m=n,e=D(),e!==null)if(l=I(),l!==null){for(u=[],f=ue(),f===null&&(f=de());f!==null;)u.push(f),f=ue(),f===null&&(f=de());u!==null?(f=I(),f!==null?e=[e,l,u,f]:(e=null,n=m)):(e=null,n=m)}else e=null,n=m;else e=null,n=m;return e!==null&&(e=function(v){return o.substring(n,v)}(p)),e===null&&(n=p),e}function pe(){var e,l,u,f,p,m;if(p=n,m=n,e=D(),e!==null)if(l=I(),l!==null){for(u=[],f=ue(),f===null&&(f=de());f!==null;)u.push(f),f=ue(),f===null&&(f=de());u!==null?(f=I(),f!==null?e=[e,l,u,f]:(e=null,n=m)):(e=null,n=m)}else e=null,n=m;else e=null,n=m;return e!==null&&(e=function(v){var S=o.substring(n,v).trim();return S.substring(1,S.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(p)),e===null&&(n=p),e}function ue(){var e;return e=M(),e===null&&(o.charCodeAt(n)===33?(e="!",n++):(e=null,h('"!"')),e===null&&(/^[#-[]/.test(o.charAt(n))?(e=o.charAt(n),n++):(e=null,h("[#-[]")),e===null&&(/^[\]-~]/.test(o.charAt(n))?(e=o.charAt(n),n++):(e=null,h("[\\]-~]")),e===null&&(e=F())))),e}function de(){var e,l,u;return u=n,o.charCodeAt(n)===92?(e="\\",n++):(e=null,h('"\\\\"')),e!==null?(/^[\0-\t]/.test(o.charAt(n))?(l=o.charAt(n),n++):(l=null,h("[\\0-\\t]")),l===null&&(/^[\x0B-\f]/.test(o.charAt(n))?(l=o.charAt(n),n++):(l=null,h("[\\x0B-\\f]")),l===null&&(/^[\x0E-]/.test(o.charAt(n))?(l=o.charAt(n),n++):(l=null,h("[\\x0E-]")))),l!==null?e=[e,l]:(e=null,n=u)):(e=null,n=u),e}function we(){var e,l,u,f,p,m;return p=n,m=n,e=Qe(),e!==null?(o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l!==null?(u=ht(),u=u!==null?u:"",u!==null?(f=Xt(),f!==null?e=[e,l,u,f]:(e=null,n=m)):(e=null,n=m)):(e=null,n=m)):(e=null,n=m),e!==null&&(e=function(v){try{w.uri=new us(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&&(n=p),e}function Ne(){var e,l,u,f,p,m,v,S;return v=n,S=n,e=Qe(),e!==null?(o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l!==null?(u=ht(),u=u!==null?u:"",u!==null?(f=Xt(),f!==null?(p=On(),p!==null?(m=Js(),m=m!==null?m:"",m!==null?e=[e,l,u,f,p,m]:(e=null,n=S)):(e=null,n=S)):(e=null,n=S)):(e=null,n=S)):(e=null,n=S)):(e=null,n=S),e!==null&&(e=function(O){try{w.uri=new us(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,a==="SIP_URI"&&(w=w.uri)}catch{w=-1}}()),e===null&&(n=v),e}function Qe(){var e;return e=Le(),e===null&&(e=kt()),e}function Le(){var e,l;return l=n,o.substr(n,4).toLowerCase()==="sips"?(e=o.substr(n,4),n+=4):(e=null,h('"sips"')),e!==null&&(e=function(u,f){w.scheme=f.toLowerCase()}(l,e)),e===null&&(n=l),e}function kt(){var e,l;return l=n,o.substr(n,3).toLowerCase()==="sip"?(e=o.substr(n,3),n+=3):(e=null,h('"sip"')),e!==null&&(e=function(u,f){w.scheme=f.toLowerCase()}(l,e)),e===null&&(n=l),e}function ht(){var e,l,u,f,p,m;return f=n,p=n,e=Rn(),e!==null?(m=n,o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l!==null?(u=Ws(),u!==null?l=[l,u]:(l=null,n=m)):(l=null,n=m),l=l!==null?l:"",l!==null?(o.charCodeAt(n)===64?(u="@",n++):(u=null,h('"@"')),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(v){w.user=decodeURIComponent(o.substring(n-1,v))}(f)),e===null&&(n=f),e}function Rn(){var e,l;if(l=j(),l===null&&(l=ve(),l===null&&(l=In())),l!==null)for(e=[];l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(l=In()));else e=null;return e}function In(){var e;return o.charCodeAt(n)===38?(e="&",n++):(e=null,h('"&"')),e===null&&(o.charCodeAt(n)===61?(e="=",n++):(e=null,h('"="')),e===null&&(o.charCodeAt(n)===43?(e="+",n++):(e=null,h('"+"')),e===null&&(o.charCodeAt(n)===36?(e="$",n++):(e=null,h('"$"')),e===null&&(o.charCodeAt(n)===44?(e=",",n++):(e=null,h('","')),e===null&&(o.charCodeAt(n)===59?(e=";",n++):(e=null,h('";"')),e===null&&(o.charCodeAt(n)===63?(e="?",n++):(e=null,h('"?"')),e===null&&(o.charCodeAt(n)===47?(e="/",n++):(e=null,h('"/"'))))))))),e}function Ws(){var e,l,u;for(u=n,e=[],l=j(),l===null&&(l=ve(),l===null&&(o.charCodeAt(n)===38?(l="&",n++):(l=null,h('"&"')),l===null&&(o.charCodeAt(n)===61?(l="=",n++):(l=null,h('"="')),l===null&&(o.charCodeAt(n)===43?(l="+",n++):(l=null,h('"+"')),l===null&&(o.charCodeAt(n)===36?(l="$",n++):(l=null,h('"$"')),l===null&&(o.charCodeAt(n)===44?(l=",",n++):(l=null,h('","'))))))));l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(o.charCodeAt(n)===38?(l="&",n++):(l=null,h('"&"')),l===null&&(o.charCodeAt(n)===61?(l="=",n++):(l=null,h('"="')),l===null&&(o.charCodeAt(n)===43?(l="+",n++):(l=null,h('"+"')),l===null&&(o.charCodeAt(n)===36?(l="$",n++):(l=null,h('"$"')),l===null&&(o.charCodeAt(n)===44?(l=",",n++):(l=null,h('","'))))))));return e!==null&&(e=function(f){w.password=o.substring(n,f)}(u)),e===null&&(n=u),e}function Xt(){var e,l,u,f,p;return f=n,e=os(),e!==null?(p=n,o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l!==null?(u=gr(),u!==null?l=[l,u]:(l=null,n=p)):(l=null,n=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,n=f)):(e=null,n=f),e}function os(){var e,l;return l=n,e=Ks(),e===null&&(e=Gt(),e===null&&(e=Ys())),e!==null&&(e=function(u){return w.host=o.substring(n,u).toLowerCase(),w.host}(l)),e===null&&(n=l),e}function Ks(){var e,l,u,f,p,m;for(f=n,p=n,e=[],m=n,l=bn(),l!==null?(o.charCodeAt(n)===46?(u=".",n++):(u=null,h('"."')),u!==null?l=[l,u]:(l=null,n=m)):(l=null,n=m);l!==null;)e.push(l),m=n,l=bn(),l!==null?(o.charCodeAt(n)===46?(u=".",n++):(u=null,h('"."')),u!==null?l=[l,u]:(l=null,n=m)):(l=null,n=m);return e!==null?(l=wn(),l!==null?(o.charCodeAt(n)===46?(u=".",n++):(u=null,h('"."')),u=u!==null?u:"",u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(v){return w.host_type="domain",o.substring(n,v)}(f)),e===null&&(n=f),e}function bn(){var e,l,u,f;if(f=n,e=ae(),e!==null){for(l=[],u=ae(),u===null&&(o.charCodeAt(n)===45?(u="-",n++):(u=null,h('"-"')),u===null&&(o.charCodeAt(n)===95?(u="_",n++):(u=null,h('"_"'))));u!==null;)l.push(u),u=ae(),u===null&&(o.charCodeAt(n)===45?(u="-",n++):(u=null,h('"-"')),u===null&&(o.charCodeAt(n)===95?(u="_",n++):(u=null,h('"_"'))));l!==null?e=[e,l]:(e=null,n=f)}else e=null,n=f;return e}function wn(){var e,l,u,f;if(f=n,e=E(),e!==null){for(l=[],u=ae(),u===null&&(o.charCodeAt(n)===45?(u="-",n++):(u=null,h('"-"')),u===null&&(o.charCodeAt(n)===95?(u="_",n++):(u=null,h('"_"'))));u!==null;)l.push(u),u=ae(),u===null&&(o.charCodeAt(n)===45?(u="-",n++):(u=null,h('"-"')),u===null&&(o.charCodeAt(n)===95?(u="_",n++):(u=null,h('"_"'))));l!==null?e=[e,l]:(e=null,n=f)}else e=null,n=f;return e}function Ys(){var e,l,u,f,p;return f=n,p=n,o.charCodeAt(n)===91?(e="[",n++):(e=null,h('"["')),e!==null?(l=me(),l!==null?(o.charCodeAt(n)===93?(u="]",n++):(u=null,h('"]"')),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m){return w.host_type="IPv6",o.substring(n,m)}(f)),e===null&&(n=f),e}function me(){var e,l,u,f,p,m,v,S,O,ie,Ue,wt,Ps,k,R,Te;return k=n,R=n,e=oe(),e!==null?(o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l!==null?(u=oe(),u!==null?(o.charCodeAt(n)===58?(f=":",n++):(f=null,h('":"')),f!==null?(p=oe(),p!==null?(o.charCodeAt(n)===58?(m=":",n++):(m=null,h('":"')),m!==null?(v=oe(),v!==null?(o.charCodeAt(n)===58?(S=":",n++):(S=null,h('":"')),S!==null?(O=oe(),O!==null?(o.charCodeAt(n)===58?(ie=":",n++):(ie=null,h('":"')),ie!==null?(Ue=oe(),Ue!==null?(o.charCodeAt(n)===58?(wt=":",n++):(wt=null,h('":"')),wt!==null?(Ps=ot(),Ps!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue,wt,Ps]:(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R),e===null&&(R=n,o.substr(n,2)==="::"?(e="::",n+=2):(e=null,h('"::"')),e!==null?(l=oe(),l!==null?(o.charCodeAt(n)===58?(u=":",n++):(u=null,h('":"')),u!==null?(f=oe(),f!==null?(o.charCodeAt(n)===58?(p=":",n++):(p=null,h('":"')),p!==null?(m=oe(),m!==null?(o.charCodeAt(n)===58?(v=":",n++):(v=null,h('":"')),v!==null?(S=oe(),S!==null?(o.charCodeAt(n)===58?(O=":",n++):(O=null,h('":"')),O!==null?(ie=oe(),ie!==null?(o.charCodeAt(n)===58?(Ue=":",n++):(Ue=null,h('":"')),Ue!==null?(wt=ot(),wt!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue,wt]:(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R),e===null&&(R=n,o.substr(n,2)==="::"?(e="::",n+=2):(e=null,h('"::"')),e!==null?(l=oe(),l!==null?(o.charCodeAt(n)===58?(u=":",n++):(u=null,h('":"')),u!==null?(f=oe(),f!==null?(o.charCodeAt(n)===58?(p=":",n++):(p=null,h('":"')),p!==null?(m=oe(),m!==null?(o.charCodeAt(n)===58?(v=":",n++):(v=null,h('":"')),v!==null?(S=oe(),S!==null?(o.charCodeAt(n)===58?(O=":",n++):(O=null,h('":"')),O!==null?(ie=ot(),ie!==null?e=[e,l,u,f,p,m,v,S,O,ie]:(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R),e===null&&(R=n,o.substr(n,2)==="::"?(e="::",n+=2):(e=null,h('"::"')),e!==null?(l=oe(),l!==null?(o.charCodeAt(n)===58?(u=":",n++):(u=null,h('":"')),u!==null?(f=oe(),f!==null?(o.charCodeAt(n)===58?(p=":",n++):(p=null,h('":"')),p!==null?(m=oe(),m!==null?(o.charCodeAt(n)===58?(v=":",n++):(v=null,h('":"')),v!==null?(S=ot(),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R),e===null&&(R=n,o.substr(n,2)==="::"?(e="::",n+=2):(e=null,h('"::"')),e!==null?(l=oe(),l!==null?(o.charCodeAt(n)===58?(u=":",n++):(u=null,h('":"')),u!==null?(f=oe(),f!==null?(o.charCodeAt(n)===58?(p=":",n++):(p=null,h('":"')),p!==null?(m=ot(),m!==null?e=[e,l,u,f,p,m]:(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R),e===null&&(R=n,o.substr(n,2)==="::"?(e="::",n+=2):(e=null,h('"::"')),e!==null?(l=oe(),l!==null?(o.charCodeAt(n)===58?(u=":",n++):(u=null,h('":"')),u!==null?(f=ot(),f!==null?e=[e,l,u,f]:(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R),e===null&&(R=n,o.substr(n,2)==="::"?(e="::",n+=2):(e=null,h('"::"')),e!==null?(l=ot(),l!==null?e=[e,l]:(e=null,n=R)):(e=null,n=R),e===null&&(R=n,o.substr(n,2)==="::"?(e="::",n+=2):(e=null,h('"::"')),e!==null?(l=oe(),l!==null?e=[e,l]:(e=null,n=R)):(e=null,n=R),e===null&&(R=n,e=oe(),e!==null?(o.substr(n,2)==="::"?(l="::",n+=2):(l=null,h('"::"')),l!==null?(u=oe(),u!==null?(o.charCodeAt(n)===58?(f=":",n++):(f=null,h('":"')),f!==null?(p=oe(),p!==null?(o.charCodeAt(n)===58?(m=":",n++):(m=null,h('":"')),m!==null?(v=oe(),v!==null?(o.charCodeAt(n)===58?(S=":",n++):(S=null,h('":"')),S!==null?(O=oe(),O!==null?(o.charCodeAt(n)===58?(ie=":",n++):(ie=null,h('":"')),ie!==null?(Ue=ot(),Ue!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue]:(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R),e===null&&(R=n,e=oe(),e!==null?(Te=n,o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l!==null?(u=oe(),u!==null?l=[l,u]:(l=null,n=Te)):(l=null,n=Te),l=l!==null?l:"",l!==null?(o.substr(n,2)==="::"?(u="::",n+=2):(u=null,h('"::"')),u!==null?(f=oe(),f!==null?(o.charCodeAt(n)===58?(p=":",n++):(p=null,h('":"')),p!==null?(m=oe(),m!==null?(o.charCodeAt(n)===58?(v=":",n++):(v=null,h('":"')),v!==null?(S=oe(),S!==null?(o.charCodeAt(n)===58?(O=":",n++):(O=null,h('":"')),O!==null?(ie=ot(),ie!==null?e=[e,l,u,f,p,m,v,S,O,ie]:(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R),e===null&&(R=n,e=oe(),e!==null?(Te=n,o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l!==null?(u=oe(),u!==null?l=[l,u]:(l=null,n=Te)):(l=null,n=Te),l=l!==null?l:"",l!==null?(Te=n,o.charCodeAt(n)===58?(u=":",n++):(u=null,h('":"')),u!==null?(f=oe(),f!==null?u=[u,f]:(u=null,n=Te)):(u=null,n=Te),u=u!==null?u:"",u!==null?(o.substr(n,2)==="::"?(f="::",n+=2):(f=null,h('"::"')),f!==null?(p=oe(),p!==null?(o.charCodeAt(n)===58?(m=":",n++):(m=null,h('":"')),m!==null?(v=oe(),v!==null?(o.charCodeAt(n)===58?(S=":",n++):(S=null,h('":"')),S!==null?(O=ot(),O!==null?e=[e,l,u,f,p,m,v,S,O]:(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R),e===null&&(R=n,e=oe(),e!==null?(Te=n,o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l!==null?(u=oe(),u!==null?l=[l,u]:(l=null,n=Te)):(l=null,n=Te),l=l!==null?l:"",l!==null?(Te=n,o.charCodeAt(n)===58?(u=":",n++):(u=null,h('":"')),u!==null?(f=oe(),f!==null?u=[u,f]:(u=null,n=Te)):(u=null,n=Te),u=u!==null?u:"",u!==null?(Te=n,o.charCodeAt(n)===58?(f=":",n++):(f=null,h('":"')),f!==null?(p=oe(),p!==null?f=[f,p]:(f=null,n=Te)):(f=null,n=Te),f=f!==null?f:"",f!==null?(o.substr(n,2)==="::"?(p="::",n+=2):(p=null,h('"::"')),p!==null?(m=oe(),m!==null?(o.charCodeAt(n)===58?(v=":",n++):(v=null,h('":"')),v!==null?(S=ot(),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R),e===null&&(R=n,e=oe(),e!==null?(Te=n,o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l!==null?(u=oe(),u!==null?l=[l,u]:(l=null,n=Te)):(l=null,n=Te),l=l!==null?l:"",l!==null?(Te=n,o.charCodeAt(n)===58?(u=":",n++):(u=null,h('":"')),u!==null?(f=oe(),f!==null?u=[u,f]:(u=null,n=Te)):(u=null,n=Te),u=u!==null?u:"",u!==null?(Te=n,o.charCodeAt(n)===58?(f=":",n++):(f=null,h('":"')),f!==null?(p=oe(),p!==null?f=[f,p]:(f=null,n=Te)):(f=null,n=Te),f=f!==null?f:"",f!==null?(Te=n,o.charCodeAt(n)===58?(p=":",n++):(p=null,h('":"')),p!==null?(m=oe(),m!==null?p=[p,m]:(p=null,n=Te)):(p=null,n=Te),p=p!==null?p:"",p!==null?(o.substr(n,2)==="::"?(m="::",n+=2):(m=null,h('"::"')),m!==null?(v=ot(),v!==null?e=[e,l,u,f,p,m,v]:(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R),e===null&&(R=n,e=oe(),e!==null?(Te=n,o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l!==null?(u=oe(),u!==null?l=[l,u]:(l=null,n=Te)):(l=null,n=Te),l=l!==null?l:"",l!==null?(Te=n,o.charCodeAt(n)===58?(u=":",n++):(u=null,h('":"')),u!==null?(f=oe(),f!==null?u=[u,f]:(u=null,n=Te)):(u=null,n=Te),u=u!==null?u:"",u!==null?(Te=n,o.charCodeAt(n)===58?(f=":",n++):(f=null,h('":"')),f!==null?(p=oe(),p!==null?f=[f,p]:(f=null,n=Te)):(f=null,n=Te),f=f!==null?f:"",f!==null?(Te=n,o.charCodeAt(n)===58?(p=":",n++):(p=null,h('":"')),p!==null?(m=oe(),m!==null?p=[p,m]:(p=null,n=Te)):(p=null,n=Te),p=p!==null?p:"",p!==null?(Te=n,o.charCodeAt(n)===58?(m=":",n++):(m=null,h('":"')),m!==null?(v=oe(),v!==null?m=[m,v]:(m=null,n=Te)):(m=null,n=Te),m=m!==null?m:"",m!==null?(o.substr(n,2)==="::"?(v="::",n+=2):(v=null,h('"::"')),v!==null?(S=oe(),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R),e===null&&(R=n,e=oe(),e!==null?(Te=n,o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l!==null?(u=oe(),u!==null?l=[l,u]:(l=null,n=Te)):(l=null,n=Te),l=l!==null?l:"",l!==null?(Te=n,o.charCodeAt(n)===58?(u=":",n++):(u=null,h('":"')),u!==null?(f=oe(),f!==null?u=[u,f]:(u=null,n=Te)):(u=null,n=Te),u=u!==null?u:"",u!==null?(Te=n,o.charCodeAt(n)===58?(f=":",n++):(f=null,h('":"')),f!==null?(p=oe(),p!==null?f=[f,p]:(f=null,n=Te)):(f=null,n=Te),f=f!==null?f:"",f!==null?(Te=n,o.charCodeAt(n)===58?(p=":",n++):(p=null,h('":"')),p!==null?(m=oe(),m!==null?p=[p,m]:(p=null,n=Te)):(p=null,n=Te),p=p!==null?p:"",p!==null?(Te=n,o.charCodeAt(n)===58?(m=":",n++):(m=null,h('":"')),m!==null?(v=oe(),v!==null?m=[m,v]:(m=null,n=Te)):(m=null,n=Te),m=m!==null?m:"",m!==null?(Te=n,o.charCodeAt(n)===58?(v=":",n++):(v=null,h('":"')),v!==null?(S=oe(),S!==null?v=[v,S]:(v=null,n=Te)):(v=null,n=Te),v=v!==null?v:"",v!==null?(o.substr(n,2)==="::"?(S="::",n+=2):(S=null,h('"::"')),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R)):(e=null,n=R))))))))))))))),e!==null&&(e=function(N_){return w.host_type="IPv6",o.substring(n,N_)}(k)),e===null&&(n=k),e}function oe(){var e,l,u,f,p;return p=n,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,n=p)):(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e}function ot(){var e,l,u,f;return f=n,e=oe(),e!==null?(o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l!==null?(u=oe(),u!==null?e=[e,l,u]:(e=null,n=f)):(e=null,n=f)):(e=null,n=f),e===null&&(e=Gt()),e}function Gt(){var e,l,u,f,p,m,v,S,O;return S=n,O=n,e=ys(),e!==null?(o.charCodeAt(n)===46?(l=".",n++):(l=null,h('"."')),l!==null?(u=ys(),u!==null?(o.charCodeAt(n)===46?(f=".",n++):(f=null,h('"."')),f!==null?(p=ys(),p!==null?(o.charCodeAt(n)===46?(m=".",n++):(m=null,h('"."')),m!==null?(v=ys(),v!==null?e=[e,l,u,f,p,m,v]:(e=null,n=O)):(e=null,n=O)):(e=null,n=O)):(e=null,n=O)):(e=null,n=O)):(e=null,n=O)):(e=null,n=O),e!==null&&(e=function(ie){return w.host_type="IPv4",o.substring(n,ie)}(S)),e===null&&(n=S),e}function ys(){var e,l,u,f;return f=n,o.substr(n,2)==="25"?(e="25",n+=2):(e=null,h('"25"')),e!==null?(/^[0-5]/.test(o.charAt(n))?(l=o.charAt(n),n++):(l=null,h("[0-5]")),l!==null?e=[e,l]:(e=null,n=f)):(e=null,n=f),e===null&&(f=n,o.charCodeAt(n)===50?(e="2",n++):(e=null,h('"2"')),e!==null?(/^[0-4]/.test(o.charAt(n))?(l=o.charAt(n),n++):(l=null,h("[0-4]")),l!==null?(u=T(),u!==null?e=[e,l,u]:(e=null,n=f)):(e=null,n=f)):(e=null,n=f),e===null&&(f=n,o.charCodeAt(n)===49?(e="1",n++):(e=null,h('"1"')),e!==null?(l=T(),l!==null?(u=T(),u!==null?e=[e,l,u]:(e=null,n=f)):(e=null,n=f)):(e=null,n=f),e===null&&(f=n,/^[1-9]/.test(o.charAt(n))?(e=o.charAt(n),n++):(e=null,h("[1-9]")),e!==null?(l=T(),l!==null?e=[e,l]:(e=null,n=f)):(e=null,n=f),e===null&&(e=T())))),e}function gr(){var e,l,u,f,p,m,v;return m=n,v=n,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,n=v)):(e=null,n=v)):(e=null,n=v)):(e=null,n=v)):(e=null,n=v),e!==null&&(e=function(S,O){return O=parseInt(O.join("")),w.port=O,O}(m,e)),e===null&&(n=m),e}function On(){var e,l,u,f;for(e=[],f=n,o.charCodeAt(n)===59?(l=";",n++):(l=null,h('";"')),l!==null?(u=Dn(),u!==null?l=[l,u]:(l=null,n=f)):(l=null,n=f);l!==null;)e.push(l),f=n,o.charCodeAt(n)===59?(l=";",n++):(l=null,h('";"')),l!==null?(u=Dn(),u!==null?l=[l,u]:(l=null,n=f)):(l=null,n=f);return e}function Dn(){var e;return e=Tr(),e===null&&(e=vr(),e===null&&(e=Er(),e===null&&(e=Sr(),e===null&&(e=yr(),e===null&&(e=Ar(),e===null&&(e=Cr())))))),e}function Tr(){var e,l,u,f;return u=n,f=n,o.substr(n,10).toLowerCase()==="transport="?(e=o.substr(n,10),n+=10):(e=null,h('"transport="')),e!==null?(o.substr(n,3).toLowerCase()==="udp"?(l=o.substr(n,3),n+=3):(l=null,h('"udp"')),l===null&&(o.substr(n,3).toLowerCase()==="tcp"?(l=o.substr(n,3),n+=3):(l=null,h('"tcp"')),l===null&&(o.substr(n,4).toLowerCase()==="sctp"?(l=o.substr(n,4),n+=4):(l=null,h('"sctp"')),l===null&&(o.substr(n,3).toLowerCase()==="tls"?(l=o.substr(n,3),n+=3):(l=null,h('"tls"')),l===null&&(l=P())))),l!==null?e=[e,l]:(e=null,n=f)):(e=null,n=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.transport=m.toLowerCase()}(u,e[1])),e===null&&(n=u),e}function vr(){var e,l,u,f;return u=n,f=n,o.substr(n,5).toLowerCase()==="user="?(e=o.substr(n,5),n+=5):(e=null,h('"user="')),e!==null?(o.substr(n,5).toLowerCase()==="phone"?(l=o.substr(n,5),n+=5):(l=null,h('"phone"')),l===null&&(o.substr(n,2).toLowerCase()==="ip"?(l=o.substr(n,2),n+=2):(l=null,h('"ip"')),l===null&&(l=P())),l!==null?e=[e,l]:(e=null,n=f)):(e=null,n=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.user=m.toLowerCase()}(u,e[1])),e===null&&(n=u),e}function Er(){var e,l,u,f;return u=n,f=n,o.substr(n,7).toLowerCase()==="method="?(e=o.substr(n,7),n+=7):(e=null,h('"method="')),e!==null?(l=sn(),l!==null?e=[e,l]:(e=null,n=f)):(e=null,n=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.method=m}(u,e[1])),e===null&&(n=u),e}function Sr(){var e,l,u,f;return u=n,f=n,o.substr(n,4).toLowerCase()==="ttl="?(e=o.substr(n,4),n+=4):(e=null,h('"ttl="')),e!==null?(l=Si(),l!==null?e=[e,l]:(e=null,n=f)):(e=null,n=f),e!==null&&(e=function(p,m){w.params||(w.params={}),w.params.ttl=m}(u,e[1])),e===null&&(n=u),e}function yr(){var e,l,u,f;return u=n,f=n,o.substr(n,6).toLowerCase()==="maddr="?(e=o.substr(n,6),n+=6):(e=null,h('"maddr="')),e!==null?(l=os(),l!==null?e=[e,l]:(e=null,n=f)):(e=null,n=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.maddr=m}(u,e[1])),e===null&&(n=u),e}function Ar(){var e,l,u,f,p,m;return f=n,p=n,o.substr(n,2).toLowerCase()==="lr"?(e=o.substr(n,2),n+=2):(e=null,h('"lr"')),e!==null?(m=n,o.charCodeAt(n)===61?(l="=",n++):(l=null,h('"="')),l!==null?(u=P(),u!==null?l=[l,u]:(l=null,n=m)):(l=null,n=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(v){w.uri_params||(w.uri_params={}),w.uri_params.lr=void 0}()),e===null&&(n=f),e}function Cr(){var e,l,u,f,p,m;return f=n,p=n,e=Rr(),e!==null?(m=n,o.charCodeAt(n)===61?(l="=",n++):(l=null,h('"="')),l!==null?(u=As(),u!==null?l=[l,u]:(l=null,n=m)):(l=null,n=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,n=p)):(e=null,n=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&&(n=f),e}function Rr(){var e,l,u;if(u=n,l=Cs(),l!==null)for(e=[];l!==null;)e.push(l),l=Cs();else e=null;return e!==null&&(e=function(f,p){return p.join("")}(u,e)),e===null&&(n=u),e}function As(){var e,l,u;if(u=n,l=Cs(),l!==null)for(e=[];l!==null;)e.push(l),l=Cs();else e=null;return e!==null&&(e=function(f,p){return p.join("")}(u,e)),e===null&&(n=u),e}function Cs(){var e;return e=Ir(),e===null&&(e=j(),e===null&&(e=ve())),e}function Ir(){var e;return o.charCodeAt(n)===91?(e="[",n++):(e=null,h('"["')),e===null&&(o.charCodeAt(n)===93?(e="]",n++):(e=null,h('"]"')),e===null&&(o.charCodeAt(n)===47?(e="/",n++):(e=null,h('"/"')),e===null&&(o.charCodeAt(n)===58?(e=":",n++):(e=null,h('":"')),e===null&&(o.charCodeAt(n)===38?(e="&",n++):(e=null,h('"&"')),e===null&&(o.charCodeAt(n)===43?(e="+",n++):(e=null,h('"+"')),e===null&&(o.charCodeAt(n)===36?(e="$",n++):(e=null,h('"$"')))))))),e}function Js(){var e,l,u,f,p,m,v;if(m=n,o.charCodeAt(n)===63?(e="?",n++):(e=null,h('"?"')),e!==null)if(l=zs(),l!==null){for(u=[],v=n,o.charCodeAt(n)===38?(f="&",n++):(f=null,h('"&"')),f!==null?(p=zs(),p!==null?f=[f,p]:(f=null,n=v)):(f=null,n=v);f!==null;)u.push(f),v=n,o.charCodeAt(n)===38?(f="&",n++):(f=null,h('"&"')),f!==null?(p=zs(),p!==null?f=[f,p]:(f=null,n=v)):(f=null,n=v);u!==null?e=[e,l,u]:(e=null,n=m)}else e=null,n=m;else e=null,n=m;return e}function zs(){var e,l,u,f,p;return f=n,p=n,e=br(),e!==null?(o.charCodeAt(n)===61?(l="=",n++):(l=null,h('"="')),l!==null?(u=Rs(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=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&&(n=f),e}function br(){var e,l;if(l=Xs(),l===null&&(l=j(),l===null&&(l=ve())),l!==null)for(e=[];l!==null;)e.push(l),l=Xs(),l===null&&(l=j(),l===null&&(l=ve()));else e=null;return e}function Rs(){var e,l;for(e=[],l=Xs(),l===null&&(l=j(),l===null&&(l=ve()));l!==null;)e.push(l),l=Xs(),l===null&&(l=j(),l===null&&(l=ve()));return e}function Xs(){var e;return o.charCodeAt(n)===91?(e="[",n++):(e=null,h('"["')),e===null&&(o.charCodeAt(n)===93?(e="]",n++):(e=null,h('"]"')),e===null&&(o.charCodeAt(n)===47?(e="/",n++):(e=null,h('"/"')),e===null&&(o.charCodeAt(n)===63?(e="?",n++):(e=null,h('"?"')),e===null&&(o.charCodeAt(n)===58?(e=":",n++):(e=null,h('":"')),e===null&&(o.charCodeAt(n)===43?(e="+",n++):(e=null,h('"+"')),e===null&&(o.charCodeAt(n)===36?(e="$",n++):(e=null,h('"$"')))))))),e}function hl(){var e;return e=Vr(),e===null&&(e=wr()),e}function wr(){var e,l,u,f,p,m;return m=n,e=sn(),e!==null?(l=H(),l!==null?(u=Nn(),u!==null?(f=H(),f!==null?(p=xn(),p!==null?e=[e,l,u,f,p]:(e=null,n=m)):(e=null,n=m)):(e=null,n=m)):(e=null,n=m)):(e=null,n=m),e}function Nn(){var e;return e=Ne(),e===null&&(e=Un()),e}function Un(){var e,l,u,f;return f=n,e=Nr(),e!==null?(o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l!==null?(u=Or(),u===null&&(u=Is()),u!==null?e=[e,l,u]:(e=null,n=f)):(e=null,n=f)):(e=null,n=f),e}function Or(){var e,l,u,f,p;return f=n,e=Qs(),e===null&&(e=Zs()),e!==null?(p=n,o.charCodeAt(n)===63?(l="?",n++):(l=null,h('"?"')),l!==null?(u=Pn(),u!==null?l=[l,u]:(l=null,n=p)):(l=null,n=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,n=f)):(e=null,n=f),e}function Qs(){var e,l,u,f;return f=n,o.substr(n,2)==="//"?(e="//",n+=2):(e=null,h('"//"')),e!==null?(l=Ur(),l!==null?(u=Zs(),u=u!==null?u:"",u!==null?e=[e,l,u]:(e=null,n=f)):(e=null,n=f)):(e=null,n=f),e}function Zs(){var e,l,u;return u=n,o.charCodeAt(n)===47?(e="/",n++):(e=null,h('"/"')),e!==null?(l=en(),l!==null?e=[e,l]:(e=null,n=u)):(e=null,n=u),e}function Is(){var e,l,u,f;if(f=n,e=Dr(),e!==null){for(l=[],u=bs();u!==null;)l.push(u),u=bs();l!==null?e=[e,l]:(e=null,n=f)}else e=null,n=f;return e}function bs(){var e;return e=N(),e===null&&(e=j(),e===null&&(e=ve())),e}function Dr(){var e;return e=j(),e===null&&(e=ve(),e===null&&(o.charCodeAt(n)===59?(e=";",n++):(e=null,h('";"')),e===null&&(o.charCodeAt(n)===63?(e="?",n++):(e=null,h('"?"')),e===null&&(o.charCodeAt(n)===58?(e=":",n++):(e=null,h('":"')),e===null&&(o.charCodeAt(n)===64?(e="@",n++):(e=null,h('"@"')),e===null&&(o.charCodeAt(n)===38?(e="&",n++):(e=null,h('"&"')),e===null&&(o.charCodeAt(n)===61?(e="=",n++):(e=null,h('"="')),e===null&&(o.charCodeAt(n)===43?(e="+",n++):(e=null,h('"+"')),e===null&&(o.charCodeAt(n)===36?(e="$",n++):(e=null,h('"$"')),e===null&&(o.charCodeAt(n)===44?(e=",",n++):(e=null,h('","')))))))))))),e}function en(){var e,l,u,f,p,m;if(p=n,e=ws(),e!==null){for(l=[],m=n,o.charCodeAt(n)===47?(u="/",n++):(u=null,h('"/"')),u!==null?(f=ws(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);u!==null;)l.push(u),m=n,o.charCodeAt(n)===47?(u="/",n++):(u=null,h('"/"')),u!==null?(f=ws(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);l!==null?e=[e,l]:(e=null,n=p)}else e=null,n=p;return e}function ws(){var e,l,u,f,p,m;for(p=n,e=[],l=Os();l!==null;)e.push(l),l=Os();if(e!==null){for(l=[],m=n,o.charCodeAt(n)===59?(u=";",n++):(u=null,h('";"')),u!==null?(f=as(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);u!==null;)l.push(u),m=n,o.charCodeAt(n)===59?(u=";",n++):(u=null,h('";"')),u!==null?(f=as(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);l!==null?e=[e,l]:(e=null,n=p)}else e=null,n=p;return e}function as(){var e,l;for(e=[],l=Os();l!==null;)e.push(l),l=Os();return e}function Os(){var e;return e=j(),e===null&&(e=ve(),e===null&&(o.charCodeAt(n)===58?(e=":",n++):(e=null,h('":"')),e===null&&(o.charCodeAt(n)===64?(e="@",n++):(e=null,h('"@"')),e===null&&(o.charCodeAt(n)===38?(e="&",n++):(e=null,h('"&"')),e===null&&(o.charCodeAt(n)===61?(e="=",n++):(e=null,h('"="')),e===null&&(o.charCodeAt(n)===43?(e="+",n++):(e=null,h('"+"')),e===null&&(o.charCodeAt(n)===36?(e="$",n++):(e=null,h('"$"')),e===null&&(o.charCodeAt(n)===44?(e=",",n++):(e=null,h('","')))))))))),e}function Nr(){var e,l,u,f,p;if(f=n,p=n,e=E(),e!==null){for(l=[],u=E(),u===null&&(u=T(),u===null&&(o.charCodeAt(n)===43?(u="+",n++):(u=null,h('"+"')),u===null&&(o.charCodeAt(n)===45?(u="-",n++):(u=null,h('"-"')),u===null&&(o.charCodeAt(n)===46?(u=".",n++):(u=null,h('"."'))))));u!==null;)l.push(u),u=E(),u===null&&(u=T(),u===null&&(o.charCodeAt(n)===43?(u="+",n++):(u=null,h('"+"')),u===null&&(o.charCodeAt(n)===45?(u="-",n++):(u=null,h('"-"')),u===null&&(o.charCodeAt(n)===46?(u=".",n++):(u=null,h('"."'))))));l!==null?e=[e,l]:(e=null,n=p)}else e=null,n=p;return e!==null&&(e=function(m){w.scheme=o.substring(n,m)}(f)),e===null&&(n=f),e}function Ur(){var e;return e=Pr(),e===null&&(e=xr()),e}function Pr(){var e,l,u,f;return u=n,f=n,e=ht(),e!==null?(o.charCodeAt(n)===64?(l="@",n++):(l=null,h('"@"')),l!==null?e=[e,l]:(e=null,n=f)):(e=null,n=f),e=e!==null?e:"",e!==null?(l=Xt(),l!==null?e=[e,l]:(e=null,n=u)):(e=null,n=u),e=e!==null?e:"",e}function xr(){var e,l;if(l=j(),l===null&&(l=ve(),l===null&&(o.charCodeAt(n)===36?(l="$",n++):(l=null,h('"$"')),l===null&&(o.charCodeAt(n)===44?(l=",",n++):(l=null,h('","')),l===null&&(o.charCodeAt(n)===59?(l=";",n++):(l=null,h('";"')),l===null&&(o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l===null&&(o.charCodeAt(n)===64?(l="@",n++):(l=null,h('"@"')),l===null&&(o.charCodeAt(n)===38?(l="&",n++):(l=null,h('"&"')),l===null&&(o.charCodeAt(n)===61?(l="=",n++):(l=null,h('"="')),l===null&&(o.charCodeAt(n)===43?(l="+",n++):(l=null,h('"+"'))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(o.charCodeAt(n)===36?(l="$",n++):(l=null,h('"$"')),l===null&&(o.charCodeAt(n)===44?(l=",",n++):(l=null,h('","')),l===null&&(o.charCodeAt(n)===59?(l=";",n++):(l=null,h('";"')),l===null&&(o.charCodeAt(n)===58?(l=":",n++):(l=null,h('":"')),l===null&&(o.charCodeAt(n)===64?(l="@",n++):(l=null,h('"@"')),l===null&&(o.charCodeAt(n)===38?(l="&",n++):(l=null,h('"&"')),l===null&&(o.charCodeAt(n)===61?(l="=",n++):(l=null,h('"="')),l===null&&(o.charCodeAt(n)===43?(l="+",n++):(l=null,h('"+"')))))))))));else e=null;return e}function Pn(){var e,l;for(e=[],l=bs();l!==null;)e.push(l),l=bs();return e}function xn(){var e,l,u,f,p,m,v,S;if(v=n,S=n,o.substr(n,3).toLowerCase()==="sip"?(e=o.substr(n,3),n+=3):(e=null,h('"SIP"')),e!==null)if(o.charCodeAt(n)===47?(l="/",n++):(l=null,h('"/"')),l!==null){if(f=T(),f!==null)for(u=[];f!==null;)u.push(f),f=T();else u=null;if(u!==null)if(o.charCodeAt(n)===46?(f=".",n++):(f=null,h('"."')),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,n=S)}else e=null,n=S;else e=null,n=S}else e=null,n=S;else e=null,n=S;return e!==null&&(e=function(O){w.sip_version=o.substring(n,O)}(v)),e===null&&(n=v),e}function Mr(){var e;return o.substr(n,6)==="INVITE"?(e="INVITE",n+=6):(e=null,h('"INVITE"')),e}function kr(){var e;return o.substr(n,3)==="ACK"?(e="ACK",n+=3):(e=null,h('"ACK"')),e}function Lr(){var e;return o.substr(n,7)==="OPTIONS"?(e="OPTIONS",n+=7):(e=null,h('"OPTIONS"')),e}function $r(){var e;return o.substr(n,3)==="BYE"?(e="BYE",n+=3):(e=null,h('"BYE"')),e}function Hr(){var e;return o.substr(n,6)==="CANCEL"?(e="CANCEL",n+=6):(e=null,h('"CANCEL"')),e}function Fr(){var e;return o.substr(n,8)==="REGISTER"?(e="REGISTER",n+=8):(e=null,h('"REGISTER"')),e}function jr(){var e;return o.substr(n,9)==="SUBSCRIBE"?(e="SUBSCRIBE",n+=9):(e=null,h('"SUBSCRIBE"')),e}function qr(){var e;return o.substr(n,6)==="NOTIFY"?(e="NOTIFY",n+=6):(e=null,h('"NOTIFY"')),e}function tn(){var e;return o.substr(n,5)==="REFER"?(e="REFER",n+=5):(e=null,h('"REFER"')),e}function sn(){var e,l;return l=n,e=Mr(),e===null&&(e=kr(),e===null&&(e=Lr(),e===null&&(e=$r(),e===null&&(e=Hr(),e===null&&(e=Fr(),e===null&&(e=jr(),e===null&&(e=qr(),e===null&&(e=tn(),e===null&&(e=P()))))))))),e!==null&&(e=function(u){return w.method=o.substring(n,u),w.method}(l)),e===null&&(n=l),e}function Vr(){var e,l,u,f,p,m;return m=n,e=xn(),e!==null?(l=H(),l!==null?(u=Br(),u!==null?(f=H(),f!==null?(p=dl(),p!==null?e=[e,l,u,f,p]:(e=null,n=m)):(e=null,n=m)):(e=null,n=m)):(e=null,n=m)):(e=null,n=m),e}function Br(){var e,l;return l=n,e=Gr(),e!==null&&(e=function(u,f){w.status_code=parseInt(f.join(""))}(l,e)),e===null&&(n=l),e}function Gr(){var e,l,u,f;return f=n,e=T(),e!==null?(l=T(),l!==null?(u=T(),u!==null?e=[e,l,u]:(e=null,n=f)):(e=null,n=f)):(e=null,n=f),e}function dl(){var e,l,u;for(u=n,e=[],l=N(),l===null&&(l=j(),l===null&&(l=ve(),l===null&&(l=F(),l===null&&(l=X(),l===null&&(l=H(),l===null&&(l=L()))))));l!==null;)e.push(l),l=N(),l===null&&(l=j(),l===null&&(l=ve(),l===null&&(l=F(),l===null&&(l=X(),l===null&&(l=H(),l===null&&(l=L()))))));return e!==null&&(e=function(f){w.reason_phrase=o.substring(n,f)}(u)),e===null&&(n=u),e}function Go(){var e,l,u,f,p,m;if(p=n,e=on(),e!==null){for(l=[],m=n,u=le(),u!==null?(f=on(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);u!==null;)l.push(u),m=n,u=le(),u!==null?(f=on(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);l!==null?e=[e,l]:(e=null,n=p)}else e=null,n=p;return e}function Wo(){var e,l,u,f,p,m;return f=n,p=n,e=ee(),e!==null?(m=n,o.charCodeAt(n)===64?(l="@",n++):(l=null,h('"@"')),l!==null?(u=ee(),u!==null?l=[l,u]:(l=null,n=m)):(l=null,n=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(v){w=o.substring(n,v)}(f)),e===null&&(n=f),e}function Mn(){var e,l,u,f,p,m,v;if(p=n,e=W(),e===null)if(m=n,e=Lt(),e!==null){for(l=[],v=n,u=le(),u!==null?(f=Lt(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);u!==null;)l.push(u),v=n,u=le(),u!==null?(f=Lt(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);l!==null?e=[e,l]:(e=null,n=m)}else e=null,n=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&&(n=p),e}function Lt(){var e,l,u,f,p,m,v;if(p=n,m=n,e=we(),e===null&&(e=$t()),e!==null){for(l=[],v=n,u=ye(),u!==null?(f=kn(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);u!==null;)l.push(u),v=n,u=ye(),u!==null?(f=kn(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);l!==null?e=[e,l]:(e=null,n=m)}else e=null,n=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:n,offset:S,parsed:O})}(p)),e===null&&(n=p),e}function $t(){var e,l,u,f,p;return p=n,e=Ds(),e=e!==null?e:"",e!==null?(l=Ce(),l!==null?(u=Ne(),u!==null?(f=xe(),f!==null?e=[e,l,u,f]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e}function Ds(){var e,l,u,f,p,m,v;if(p=n,m=n,e=P(),e!==null){for(l=[],v=n,u=M(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);u!==null;)l.push(u),v=n,u=M(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);l!==null?e=[e,l]:(e=null,n=m)}else e=null,n=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&&(n=p),e}function kn(){var e;return e=Wr(),e===null&&(e=Qt(),e===null&&(e=We())),e}function Wr(){var e,l,u,f,p;return f=n,p=n,o.substr(n,1).toLowerCase()==="q"?(e=o.substr(n,1),n++):(e=null,h('"q"')),e!==null?(l=re(),l!==null?(u=Ge(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m,v){w.params||(w.params={}),w.params.q=v}(f,e[2])),e===null&&(n=f),e}function Qt(){var e,l,u,f,p;return f=n,p=n,o.substr(n,7).toLowerCase()==="expires"?(e=o.substr(n,7),n+=7):(e=null,h('"expires"')),e!==null?(l=re(),l!==null?(u=Zt(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m,v){w.params||(w.params={}),w.params.expires=v}(f,e[2])),e===null&&(n=f),e}function Zt(){var e,l,u;if(u=n,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&&(n=u),e}function Ge(){var e,l,u,f,p,m,v,S;return m=n,v=n,o.charCodeAt(n)===48?(e="0",n++):(e=null,h('"0"')),e!==null?(S=n,o.charCodeAt(n)===46?(l=".",n++):(l=null,h('"."')),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,n=S)):(l=null,n=S)):(l=null,n=S)):(l=null,n=S),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,n=v)):(e=null,n=v),e!==null&&(e=function(O){return parseFloat(o.substring(n,O))}(m)),e===null&&(n=m),e}function We(){var e,l,u,f,p,m;return f=n,p=n,e=P(),e!==null?(m=n,l=re(),l!==null?(u=pl(),u!==null?l=[l,u]:(l=null,n=m)):(l=null,n=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,n=p)):(e=null,n=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&&(n=f),e}function pl(){var e;return e=P(),e===null&&(e=os(),e===null&&(e=Oe())),e}function ml(){var e,l,u,f,p,m;if(p=n,e=Ln(),e!==null){for(l=[],m=n,u=ye(),u!==null?(f=$n(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);u!==null;)l.push(u),m=n,u=ye(),u!==null?(f=$n(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);l!==null?e=[e,l]:(e=null,n=p)}else e=null,n=p;return e}function Ln(){var e;return o.substr(n,6).toLowerCase()==="render"?(e=o.substr(n,6),n+=6):(e=null,h('"render"')),e===null&&(o.substr(n,7).toLowerCase()==="session"?(e=o.substr(n,7),n+=7):(e=null,h('"session"')),e===null&&(o.substr(n,4).toLowerCase()==="icon"?(e=o.substr(n,4),n+=4):(e=null,h('"icon"')),e===null&&(o.substr(n,5).toLowerCase()==="alert"?(e=o.substr(n,5),n+=5):(e=null,h('"alert"')),e===null&&(e=P())))),e}function $n(){var e;return e=gl(),e===null&&(e=We()),e}function gl(){var e,l,u,f;return f=n,o.substr(n,8).toLowerCase()==="handling"?(e=o.substr(n,8),n+=8):(e=null,h('"handling"')),e!==null?(l=re(),l!==null?(o.substr(n,8).toLowerCase()==="optional"?(u=o.substr(n,8),n+=8):(u=null,h('"optional"')),u===null&&(o.substr(n,8).toLowerCase()==="required"?(u=o.substr(n,8),n+=8):(u=null,h('"required"')),u===null&&(u=P())),u!==null?e=[e,l,u]:(e=null,n=f)):(e=null,n=f)):(e=null,n=f),e}function Ko(){var e,l,u,f,p,m;if(p=n,e=P(),e!==null){for(l=[],m=n,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);u!==null;)l.push(u),m=n,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);l!==null?e=[e,l]:(e=null,n=p)}else e=null,n=p;return e}function Yo(){var e,l,u;if(u=n,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&&(n=u),e}function Tl(){var e,l;return l=n,e=Kr(),e!==null&&(e=function(u){w=o.substring(n,u)}(l)),e===null&&(n=l),e}function Kr(){var e,l,u,f,p,m,v,S;if(v=n,e=Yr(),e!==null)if(l=G(),l!==null)if(u=Hn(),u!==null){for(f=[],S=n,p=ye(),p!==null?(m=Fn(),m!==null?p=[p,m]:(p=null,n=S)):(p=null,n=S);p!==null;)f.push(p),S=n,p=ye(),p!==null?(m=Fn(),m!==null?p=[p,m]:(p=null,n=S)):(p=null,n=S);f!==null?e=[e,l,u,f]:(e=null,n=v)}else e=null,n=v;else e=null,n=v;else e=null,n=v;return e}function Yr(){var e;return e=Jr(),e===null&&(e=nn()),e}function Jr(){var e;return o.substr(n,4).toLowerCase()==="text"?(e=o.substr(n,4),n+=4):(e=null,h('"text"')),e===null&&(o.substr(n,5).toLowerCase()==="image"?(e=o.substr(n,5),n+=5):(e=null,h('"image"')),e===null&&(o.substr(n,5).toLowerCase()==="audio"?(e=o.substr(n,5),n+=5):(e=null,h('"audio"')),e===null&&(o.substr(n,5).toLowerCase()==="video"?(e=o.substr(n,5),n+=5):(e=null,h('"video"')),e===null&&(o.substr(n,11).toLowerCase()==="application"?(e=o.substr(n,11),n+=11):(e=null,h('"application"')),e===null&&(e=rn()))))),e}function nn(){var e;return o.substr(n,7).toLowerCase()==="message"?(e=o.substr(n,7),n+=7):(e=null,h('"message"')),e===null&&(o.substr(n,9).toLowerCase()==="multipart"?(e=o.substr(n,9),n+=9):(e=null,h('"multipart"')),e===null&&(e=rn())),e}function rn(){var e;return e=P(),e===null&&(e=zr()),e}function zr(){var e,l,u;return u=n,o.substr(n,2).toLowerCase()==="x-"?(e=o.substr(n,2),n+=2):(e=null,h('"x-"')),e!==null?(l=P(),l!==null?e=[e,l]:(e=null,n=u)):(e=null,n=u),e}function Hn(){var e;return e=rn(),e===null&&(e=P()),e}function Fn(){var e,l,u,f;return f=n,e=P(),e!==null?(l=re(),l!==null?(u=vl(),u!==null?e=[e,l,u]:(e=null,n=f)):(e=null,n=f)):(e=null,n=f),e}function vl(){var e;return e=P(),e===null&&(e=Oe()),e}function El(){var e,l,u,f;return f=n,e=Sl(),e!==null?(l=M(),l!==null?(u=sn(),u!==null?e=[e,l,u]:(e=null,n=f)):(e=null,n=f)):(e=null,n=f),e}function Sl(){var e,l,u;if(u=n,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&&(n=u),e}function Jo(){var e,l;return l=n,e=Zt(),e!==null&&(e=function(u,f){w=f}(l,e)),e===null&&(n=l),e}function ln(){var e,l,u,f,p,m,v;if(p=n,m=n,e=on(),e!==null){for(l=[],v=n,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);u!==null;)l.push(u),v=n,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);l!==null?e=[e,l]:(e=null,n=m)}else e=null,n=m;return e!==null&&(e=function(S,O){w.event=O.join("").toLowerCase()}(p,e[0])),e===null&&(n=p),e}function on(){var e,l,u,f,p,m;if(p=n,e=se(),e!==null){for(l=[],m=n,o.charCodeAt(n)===46?(u=".",n++):(u=null,h('"."')),u!==null?(f=se(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);u!==null;)l.push(u),m=n,o.charCodeAt(n)===46?(u=".",n++):(u=null,h('"."')),u!==null?(f=se(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);l!==null?e=[e,l]:(e=null,n=p)}else e=null,n=p;return e}function Xr(){var e,l,u,f,p,m,v;if(p=n,m=n,e=we(),e===null&&(e=$t()),e!==null){for(l=[],v=n,u=ye(),u!==null?(f=an(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);u!==null;)l.push(u),v=n,u=ye(),u!==null?(f=an(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);l!==null?e=[e,l]:(e=null,n=m)}else e=null,n=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&&(n=p),e}function an(){var e;return e=Qr(),e===null&&(e=We()),e}function Qr(){var e,l,u,f,p;return f=n,p=n,o.substr(n,3).toLowerCase()==="tag"?(e=o.substr(n,3),n+=3):(e=null,h('"tag"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m,v){w.tag=v}(f,e[2])),e===null&&(n=f),e}function zo(){var e,l,u;if(u=n,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&&(n=u),e}function Xo(){var e,l;return l=n,e=Zt(),e!==null&&(e=function(u,f){w=f}(l,e)),e===null&&(n=l),e}function Qo(){var e,l,u,f,p,m,v,S,O,ie;for(S=n,O=n,e=[],l=Ds();l!==null;)e.push(l),l=Ds();if(e!==null)if(l=Ce(),l!==null)if(u=Ne(),u!==null)if(f=xe(),f!==null){for(p=[],ie=n,m=ye(),m!==null?(v=We(),v!==null?m=[m,v]:(m=null,n=ie)):(m=null,n=ie);m!==null;)p.push(m),ie=n,m=ye(),m!==null?(v=We(),v!==null?m=[m,v]:(m=null,n=ie)):(m=null,n=ie);p!==null?e=[e,l,u,f,p]:(e=null,n=O)}else e=null,n=O;else e=null,n=O;else e=null,n=O;else e=null,n=O;return e!==null&&(e=function(Ue){try{w=new b(w.uri,w.display_name,w.params)}catch{w=-1}}()),e===null&&(n=S),e}function Zr(){var e;return e=jn(),e}function jn(){var e,l,u,f,p,m,v,S;if(v=n,o.substr(n,6).toLowerCase()==="digest"?(e=o.substr(n,6),n+=6):(e=null,h('"Digest"')),e!==null)if(l=M(),l!==null)if(u=un(),u!==null){for(f=[],S=n,p=le(),p!==null?(m=un(),m!==null?p=[p,m]:(p=null,n=S)):(p=null,n=S);p!==null;)f.push(p),S=n,p=le(),p!==null?(m=un(),m!==null?p=[p,m]:(p=null,n=S)):(p=null,n=S);f!==null?e=[e,l,u,f]:(e=null,n=v)}else e=null,n=v;else e=null,n=v;else e=null,n=v;return e===null&&(e=Ns()),e}function Ns(){var e,l,u,f,p,m,v,S;if(v=n,e=P(),e!==null)if(l=M(),l!==null)if(u=es(),u!==null){for(f=[],S=n,p=le(),p!==null?(m=es(),m!==null?p=[p,m]:(p=null,n=S)):(p=null,n=S);p!==null;)f.push(p),S=n,p=le(),p!==null?(m=es(),m!==null?p=[p,m]:(p=null,n=S)):(p=null,n=S);f!==null?e=[e,l,u,f]:(e=null,n=v)}else e=null,n=v;else e=null,n=v;else e=null,n=v;return e}function es(){var e,l,u,f;return f=n,e=P(),e!==null?(l=re(),l!==null?(u=P(),u===null&&(u=Oe()),u!==null?e=[e,l,u]:(e=null,n=f)):(e=null,n=f)):(e=null,n=f),e}function un(){var e;return e=ei(),e===null&&(e=cn(),e===null&&(e=si(),e===null&&(e=ri(),e===null&&(e=ii(),e===null&&(e=li(),e===null&&(e=_n(),e===null&&(e=es()))))))),e}function ei(){var e,l,u,f;return f=n,o.substr(n,5).toLowerCase()==="realm"?(e=o.substr(n,5),n+=5):(e=null,h('"realm"')),e!==null?(l=re(),l!==null?(u=ti(),u!==null?e=[e,l,u]:(e=null,n=f)):(e=null,n=f)):(e=null,n=f),e}function ti(){var e,l;return l=n,e=pe(),e!==null&&(e=function(u,f){w.realm=f}(l,e)),e===null&&(n=l),e}function cn(){var e,l,u,f,p,m,v,S,O;if(S=n,o.substr(n,6).toLowerCase()==="domain"?(e=o.substr(n,6),n+=6):(e=null,h('"domain"')),e!==null)if(l=re(),l!==null)if(u=lt(),u!==null)if(f=fn(),f!==null){if(p=[],O=n,v=H(),v!==null)for(m=[];v!==null;)m.push(v),v=H();else m=null;for(m!==null?(v=fn(),v!==null?m=[m,v]:(m=null,n=O)):(m=null,n=O);m!==null;){if(p.push(m),O=n,v=H(),v!==null)for(m=[];v!==null;)m.push(v),v=H();else m=null;m!==null?(v=fn(),v!==null?m=[m,v]:(m=null,n=O)):(m=null,n=O)}p!==null?(m=Ee(),m!==null?e=[e,l,u,f,p,m]:(e=null,n=S)):(e=null,n=S)}else e=null,n=S;else e=null,n=S;else e=null,n=S;else e=null,n=S;return e}function fn(){var e;return e=Un(),e===null&&(e=Zs()),e}function si(){var e,l,u,f;return f=n,o.substr(n,5).toLowerCase()==="nonce"?(e=o.substr(n,5),n+=5):(e=null,h('"nonce"')),e!==null?(l=re(),l!==null?(u=ni(),u!==null?e=[e,l,u]:(e=null,n=f)):(e=null,n=f)):(e=null,n=f),e}function ni(){var e,l;return l=n,e=pe(),e!==null&&(e=function(u,f){w.nonce=f}(l,e)),e===null&&(n=l),e}function ri(){var e,l,u,f,p;return f=n,p=n,o.substr(n,6).toLowerCase()==="opaque"?(e=o.substr(n,6),n+=6):(e=null,h('"opaque"')),e!==null?(l=re(),l!==null?(u=pe(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m,v){w.opaque=v}(f,e[2])),e===null&&(n=f),e}function ii(){var e,l,u,f,p;return f=n,o.substr(n,5).toLowerCase()==="stale"?(e=o.substr(n,5),n+=5):(e=null,h('"stale"')),e!==null?(l=re(),l!==null?(p=n,o.substr(n,4).toLowerCase()==="true"?(u=o.substr(n,4),n+=4):(u=null,h('"true"')),u!==null&&(u=function(m){w.stale=!0}()),u===null&&(n=p),u===null&&(p=n,o.substr(n,5).toLowerCase()==="false"?(u=o.substr(n,5),n+=5):(u=null,h('"false"')),u!==null&&(u=function(m){w.stale=!1}()),u===null&&(n=p)),u!==null?e=[e,l,u]:(e=null,n=f)):(e=null,n=f)):(e=null,n=f),e}function li(){var e,l,u,f,p;return f=n,p=n,o.substr(n,9).toLowerCase()==="algorithm"?(e=o.substr(n,9),n+=9):(e=null,h('"algorithm"')),e!==null?(l=re(),l!==null?(o.substr(n,3).toLowerCase()==="md5"?(u=o.substr(n,3),n+=3):(u=null,h('"MD5"')),u===null&&(o.substr(n,8).toLowerCase()==="md5-sess"?(u=o.substr(n,8),n+=8):(u=null,h('"MD5-sess"')),u===null&&(u=P())),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m,v){w.algorithm=v.toUpperCase()}(f,e[2])),e===null&&(n=f),e}function _n(){var e,l,u,f,p,m,v,S,O,ie;if(S=n,o.substr(n,3).toLowerCase()==="qop"?(e=o.substr(n,3),n+=3):(e=null,h('"qop"')),e!==null)if(l=re(),l!==null)if(u=lt(),u!==null){if(O=n,f=qn(),f!==null){for(p=[],ie=n,o.charCodeAt(n)===44?(m=",",n++):(m=null,h('","')),m!==null?(v=qn(),v!==null?m=[m,v]:(m=null,n=ie)):(m=null,n=ie);m!==null;)p.push(m),ie=n,o.charCodeAt(n)===44?(m=",",n++):(m=null,h('","')),m!==null?(v=qn(),v!==null?m=[m,v]:(m=null,n=ie)):(m=null,n=ie);p!==null?f=[f,p]:(f=null,n=O)}else f=null,n=O;f!==null?(p=Ee(),p!==null?e=[e,l,u,f,p]:(e=null,n=S)):(e=null,n=S)}else e=null,n=S;else e=null,n=S;else e=null,n=S;return e}function qn(){var e,l;return l=n,o.substr(n,8).toLowerCase()==="auth-int"?(e=o.substr(n,8),n+=8):(e=null,h('"auth-int"')),e===null&&(o.substr(n,4).toLowerCase()==="auth"?(e=o.substr(n,4),n+=4):(e=null,h('"auth"')),e===null&&(e=P())),e!==null&&(e=function(u,f){w.qop||(w.qop=[]),w.qop.push(f.toLowerCase())}(l,e)),e===null&&(n=l),e}function Zo(){var e,l,u,f,p,m;if(p=n,e=P(),e!==null){for(l=[],m=n,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);u!==null;)l.push(u),m=n,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);l!==null?e=[e,l]:(e=null,n=p)}else e=null,n=p;return e}function Vn(){var e,l,u,f,p,m,v;if(p=n,m=n,e=Bn(),e!==null){for(l=[],v=n,u=le(),u!==null?(f=Bn(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);u!==null;)l.push(u),v=n,u=le(),u!==null?(f=Bn(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);l!==null?e=[e,l]:(e=null,n=m)}else e=null,n=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&&(n=p),e}function Bn(){var e,l,u,f,p,m,v;if(p=n,m=n,e=$t(),e!==null){for(l=[],v=n,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);u!==null;)l.push(u),v=n,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);l!==null?e=[e,l]:(e=null,n=m)}else e=null,n=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:n,offset:S,parsed:O})}(p)),e===null&&(n=p),e}function oi(){var e,l,u,f,p,m,v;if(p=n,m=n,o.substr(n,3).toLowerCase()==="sip"?(e=o.substr(n,3),n+=3):(e=null,h('"SIP"')),e===null&&(e=P()),e!==null){for(l=[],v=n,u=ye(),u!==null?(f=Gn(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);u!==null;)l.push(u),v=n,u=ye(),u!==null?(f=Gn(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);l!==null?e=[e,l]:(e=null,n=m)}else e=null,n=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&&(n=p),e}function Gn(){var e;return e=yl(),e===null&&(e=We()),e}function yl(){var e,l,u,f,p,m;if(p=n,m=n,o.substr(n,5).toLowerCase()==="cause"?(e=o.substr(n,5),n+=5):(e=null,h('"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,n=m)}else e=null,n=m;else e=null,n=m;return e!==null&&(e=function(v,S){w.cause=parseInt(S.join(""))}(p,e[2])),e===null&&(n=p),e}function ea(){var e,l,u,f,p,m;if(p=n,e=P(),e!==null){for(l=[],m=n,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);u!==null;)l.push(u),m=n,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);l!==null?e=[e,l]:(e=null,n=p)}else e=null,n=p;return e}function Wn(){var e,l,u,f,p,m;if(p=n,e=Kn(),e!==null){for(l=[],m=n,u=le(),u!==null?(f=Kn(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);u!==null;)l.push(u),m=n,u=le(),u!==null?(f=Kn(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);l!==null?e=[e,l]:(e=null,n=p)}else e=null,n=p;return e}function Kn(){var e,l,u,f,p,m;if(p=n,e=$t(),e!==null){for(l=[],m=n,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);u!==null;)l.push(u),m=n,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);l!==null?e=[e,l]:(e=null,n=p)}else e=null,n=p;return e}function Al(){var e,l,u,f,p,m;if(p=n,e=Yn(),e!==null){for(l=[],m=n,u=ye(),u!==null?(f=Jn(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);u!==null;)l.push(u),m=n,u=ye(),u!==null?(f=Jn(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);l!==null?e=[e,l]:(e=null,n=p)}else e=null,n=p;return e}function Yn(){var e,l;return l=n,o.substr(n,6).toLowerCase()==="active"?(e=o.substr(n,6),n+=6):(e=null,h('"active"')),e===null&&(o.substr(n,7).toLowerCase()==="pending"?(e=o.substr(n,7),n+=7):(e=null,h('"pending"')),e===null&&(o.substr(n,10).toLowerCase()==="terminated"?(e=o.substr(n,10),n+=10):(e=null,h('"terminated"')),e===null&&(e=P()))),e!==null&&(e=function(u){w.state=o.substring(n,u)}(l)),e===null&&(n=l),e}function Jn(){var e,l,u,f,p;return f=n,p=n,o.substr(n,6).toLowerCase()==="reason"?(e=o.substr(n,6),n+=6):(e=null,h('"reason"')),e!==null?(l=re(),l!==null?(u=Cl(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m,v){typeof v<"u"&&(w.reason=v)}(f,e[2])),e===null&&(n=f),e===null&&(f=n,p=n,o.substr(n,7).toLowerCase()==="expires"?(e=o.substr(n,7),n+=7):(e=null,h('"expires"')),e!==null?(l=re(),l!==null?(u=Zt(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m,v){typeof v<"u"&&(w.expires=v)}(f,e[2])),e===null&&(n=f),e===null&&(f=n,p=n,o.substr(n,11).toLowerCase()==="retry_after"?(e=o.substr(n,11),n+=11):(e=null,h('"retry_after"')),e!==null?(l=re(),l!==null?(u=Zt(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m,v){typeof v<"u"&&(w.retry_after=v)}(f,e[2])),e===null&&(n=f),e===null&&(e=We()))),e}function Cl(){var e;return o.substr(n,11).toLowerCase()==="deactivated"?(e=o.substr(n,11),n+=11):(e=null,h('"deactivated"')),e===null&&(o.substr(n,9).toLowerCase()==="probation"?(e=o.substr(n,9),n+=9):(e=null,h('"probation"')),e===null&&(o.substr(n,8).toLowerCase()==="rejected"?(e=o.substr(n,8),n+=8):(e=null,h('"rejected"')),e===null&&(o.substr(n,7).toLowerCase()==="timeout"?(e=o.substr(n,7),n+=7):(e=null,h('"timeout"')),e===null&&(o.substr(n,6).toLowerCase()==="giveup"?(e=o.substr(n,6),n+=6):(e=null,h('"giveup"')),e===null&&(o.substr(n,10).toLowerCase()==="noresource"?(e=o.substr(n,10),n+=10):(e=null,h('"noresource"')),e===null&&(o.substr(n,9).toLowerCase()==="invariant"?(e=o.substr(n,9),n+=9):(e=null,h('"invariant"')),e===null&&(e=P()))))))),e}function ta(){var e;return e=V(),e=e!==null?e:"",e}function sa(){var e,l,u,f,p,m;if(p=n,e=P(),e!==null){for(l=[],m=n,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);u!==null;)l.push(u),m=n,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);l!==null?e=[e,l]:(e=null,n=p)}else e=null,n=p;return e=e!==null?e:"",e}function ai(){var e,l,u,f,p,m,v;if(p=n,m=n,e=we(),e===null&&(e=$t()),e!==null){for(l=[],v=n,u=ye(),u!==null?(f=ui(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);u!==null;)l.push(u),v=n,u=ye(),u!==null?(f=ui(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);l!==null?e=[e,l]:(e=null,n=m)}else e=null,n=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&&(n=p),e}function ui(){var e;return e=Qr(),e===null&&(e=We()),e}function zn(){var e,l,u,f,p,m;if(p=n,e=Us(),e!==null){for(l=[],m=n,u=le(),u!==null?(f=Us(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);u!==null;)l.push(u),m=n,u=le(),u!==null?(f=Us(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);l!==null?e=[e,l]:(e=null,n=p)}else e=null,n=p;return e}function Us(){var e,l,u,f,p,m,v,S;if(v=n,e=mi(),e!==null)if(l=M(),l!==null)if(u=vi(),u!==null){for(f=[],S=n,p=ye(),p!==null?(m=Xn(),m!==null?p=[p,m]:(p=null,n=S)):(p=null,n=S);p!==null;)f.push(p),S=n,p=ye(),p!==null?(m=Xn(),m!==null?p=[p,m]:(p=null,n=S)):(p=null,n=S);f!==null?e=[e,l,u,f]:(e=null,n=v)}else e=null,n=v;else e=null,n=v;else e=null,n=v;return e}function Xn(){var e;return e=ci(),e===null&&(e=fi(),e===null&&(e=_i(),e===null&&(e=hi(),e===null&&(e=di(),e===null&&(e=We()))))),e}function ci(){var e,l,u,f,p;return f=n,p=n,o.substr(n,3).toLowerCase()==="ttl"?(e=o.substr(n,3),n+=3):(e=null,h('"ttl"')),e!==null?(l=re(),l!==null?(u=Si(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m,v){w.ttl=v}(f,e[2])),e===null&&(n=f),e}function fi(){var e,l,u,f,p;return f=n,p=n,o.substr(n,5).toLowerCase()==="maddr"?(e=o.substr(n,5),n+=5):(e=null,h('"maddr"')),e!==null?(l=re(),l!==null?(u=os(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m,v){w.maddr=v}(f,e[2])),e===null&&(n=f),e}function _i(){var e,l,u,f,p;return f=n,p=n,o.substr(n,8).toLowerCase()==="received"?(e=o.substr(n,8),n+=8):(e=null,h('"received"')),e!==null?(l=re(),l!==null?(u=Gt(),u===null&&(u=me()),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m,v){w.received=v}(f,e[2])),e===null&&(n=f),e}function hi(){var e,l,u,f,p;return f=n,p=n,o.substr(n,6).toLowerCase()==="branch"?(e=o.substr(n,6),n+=6):(e=null,h('"branch"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m,v){w.branch=v}(f,e[2])),e===null&&(n=f),e}function di(){var e,l,u,f,p;return f=n,o.substr(n,5).toLowerCase()==="rport"?(e=o.substr(n,5),n+=5):(e=null,h('"rport"')),e!==null?(p=n,l=re(),l!==null?(u=pi(),u!==null?l=[l,u]:(l=null,n=p)):(l=null,n=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,n=f)):(e=null,n=f),e}function pi(){var e,l,u,f,p,m,v;return m=n,v=n,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,n=v)):(e=null,n=v)):(e=null,n=v)):(e=null,n=v)):(e=null,n=v),e!==null&&(e=function(S,O){w.rport=parseInt(O.join(""))}(m,e)),e===null&&(n=m),e}function mi(){var e,l,u,f,p,m;return m=n,e=gi(),e!==null?(l=G(),l!==null?(u=P(),u!==null?(f=G(),f!==null?(p=Ti(),p!==null?e=[e,l,u,f,p]:(e=null,n=m)):(e=null,n=m)):(e=null,n=m)):(e=null,n=m)):(e=null,n=m),e}function gi(){var e,l;return l=n,o.substr(n,3).toLowerCase()==="sip"?(e=o.substr(n,3),n+=3):(e=null,h('"SIP"')),e===null&&(e=P()),e!==null&&(e=function(u,f){w.protocol=f}(l,e)),e===null&&(n=l),e}function Ti(){var e,l;return l=n,o.substr(n,3).toLowerCase()==="udp"?(e=o.substr(n,3),n+=3):(e=null,h('"UDP"')),e===null&&(o.substr(n,3).toLowerCase()==="tcp"?(e=o.substr(n,3),n+=3):(e=null,h('"TCP"')),e===null&&(o.substr(n,3).toLowerCase()==="tls"?(e=o.substr(n,3),n+=3):(e=null,h('"TLS"')),e===null&&(o.substr(n,4).toLowerCase()==="sctp"?(e=o.substr(n,4),n+=4):(e=null,h('"SCTP"')),e===null&&(e=P())))),e!==null&&(e=function(u,f){w.transport=f}(l,e)),e===null&&(n=l),e}function vi(){var e,l,u,f,p;return f=n,e=Ei(),e!==null?(p=n,l=st(),l!==null?(u=Qn(),u!==null?l=[l,u]:(l=null,n=p)):(l=null,n=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,n=f)):(e=null,n=f),e}function Ei(){var e,l;return l=n,e=Gt(),e===null&&(e=Ys(),e===null&&(e=Ks())),e!==null&&(e=function(u){w.host=o.substring(n,u)}(l)),e===null&&(n=l),e}function Qn(){var e,l,u,f,p,m,v;return m=n,v=n,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,n=v)):(e=null,n=v)):(e=null,n=v)):(e=null,n=v)):(e=null,n=v),e!==null&&(e=function(S,O){w.port=parseInt(O.join(""))}(m,e)),e===null&&(n=m),e}function Si(){var e,l,u,f,p;return f=n,p=n,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,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m,v){return parseInt(v.join(""))}(f,e)),e===null&&(n=f),e}function na(){var e;return e=jn(),e}function Rl(){var e,l,u,f,p,m;if(p=n,e=Zn(),e!==null){for(l=[],m=n,u=ye(),u!==null?(f=er(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);u!==null;)l.push(u),m=n,u=ye(),u!==null?(f=er(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);l!==null?e=[e,l]:(e=null,n=p)}else e=null,n=p;return e}function Zn(){var e,l;return l=n,e=Zt(),e!==null&&(e=function(u,f){w.expires=f}(l,e)),e===null&&(n=l),e}function er(){var e;return e=Il(),e===null&&(e=We()),e}function Il(){var e,l,u,f,p;return f=n,p=n,o.substr(n,9).toLowerCase()==="refresher"?(e=o.substr(n,9),n+=9):(e=null,h('"refresher"')),e!==null?(l=re(),l!==null?(o.substr(n,3).toLowerCase()==="uac"?(u=o.substr(n,3),n+=3):(u=null,h('"uac"')),u===null&&(o.substr(n,3).toLowerCase()==="uas"?(u=o.substr(n,3),n+=3):(u=null,h('"uas"'))),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m,v){w.refresher=v.toLowerCase()}(f,e[2])),e===null&&(n=f),e}function bl(){var e,l,u,f;return f=n,e=P(),e!==null?(l=B(),l!==null?(u=wl(),u!==null?e=[e,l,u]:(e=null,n=f)):(e=null,n=f)):(e=null,n=f),e}function wl(){var e,l;for(e=[],l=J(),l===null&&(l=X(),l===null&&(l=M()));l!==null;)e.push(l),l=J(),l===null&&(l=X(),l===null&&(l=M()));return e}function ra(){var e,l;for(e=[],l=C();l!==null;)e.push(l),l=C();return e}function Ol(){var e,l,u;return u=n,o.substr(n,5)==="uuid:"?(e="uuid:",n+=5):(e=null,h('"uuid:"')),e!==null?(l=Ht(),l!==null?e=[e,l]:(e=null,n=u)):(e=null,n=u),e}function Ht(){var e,l,u,f,p,m,v,S,O,ie,Ue;return ie=n,Ue=n,e=yi(),e!==null?(o.charCodeAt(n)===45?(l="-",n++):(l=null,h('"-"')),l!==null?(u=Ft(),u!==null?(o.charCodeAt(n)===45?(f="-",n++):(f=null,h('"-"')),f!==null?(p=Ft(),p!==null?(o.charCodeAt(n)===45?(m="-",n++):(m=null,h('"-"')),m!==null?(v=Ft(),v!==null?(o.charCodeAt(n)===45?(S="-",n++):(S=null,h('"-"')),S!==null?(O=Dl(),O!==null?e=[e,l,u,f,p,m,v,S,O]:(e=null,n=Ue)):(e=null,n=Ue)):(e=null,n=Ue)):(e=null,n=Ue)):(e=null,n=Ue)):(e=null,n=Ue)):(e=null,n=Ue)):(e=null,n=Ue)):(e=null,n=Ue),e!==null&&(e=function(wt,Ps){w=o.substring(n+5,wt)}(ie,e[0])),e===null&&(n=ie),e}function Ft(){var e,l,u,f,p;return p=n,e=y(),e!==null?(l=y(),l!==null?(u=y(),u!==null?(f=y(),f!==null?e=[e,l,u,f]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e}function yi(){var e,l,u;return u=n,e=Ft(),e!==null?(l=Ft(),l!==null?e=[e,l]:(e=null,n=u)):(e=null,n=u),e}function Dl(){var e,l,u,f;return f=n,e=Ft(),e!==null?(l=Ft(),l!==null?(u=Ft(),u!==null?e=[e,l,u]:(e=null,n=f)):(e=null,n=f)):(e=null,n=f),e}function ia(){var e,l,u,f,p,m,v;if(p=n,m=n,e=we(),e===null&&(e=$t()),e!==null){for(l=[],v=n,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);u!==null;)l.push(u),v=n,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,n=v)):(u=null,n=v);l!==null?e=[e,l]:(e=null,n=m)}else e=null,n=m;return e!==null&&(e=function(S){try{w=new b(w.uri,w.display_name,w.params)}catch{w=-1}}()),e===null&&(n=p),e}function Nl(){var e,l,u,f,p,m;if(p=n,e=tr(),e!==null){for(l=[],m=n,u=ye(),u!==null?(f=sr(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);u!==null;)l.push(u),m=n,u=ye(),u!==null?(f=sr(),f!==null?u=[u,f]:(u=null,n=m)):(u=null,n=m);l!==null?e=[e,l]:(e=null,n=p)}else e=null,n=p;return e}function tr(){var e,l,u,f,p,m;return f=n,p=n,e=ee(),e!==null?(m=n,o.charCodeAt(n)===64?(l="@",n++):(l=null,h('"@"')),l!==null?(u=ee(),u!==null?l=[l,u]:(l=null,n=m)):(l=null,n=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(v){w.call_id=o.substring(n,v)}(f)),e===null&&(n=f),e}function sr(){var e;return e=Ai(),e===null&&(e=Ci(),e===null&&(e=Ul(),e===null&&(e=We()))),e}function Ai(){var e,l,u,f,p;return f=n,p=n,o.substr(n,6)==="to-tag"?(e="to-tag",n+=6):(e=null,h('"to-tag"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m,v){w.to_tag=v}(f,e[2])),e===null&&(n=f),e}function Ci(){var e,l,u,f,p;return f=n,p=n,o.substr(n,8)==="from-tag"?(e="from-tag",n+=8):(e=null,h('"from-tag"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,n=p)):(e=null,n=p)):(e=null,n=p),e!==null&&(e=function(m,v){w.from_tag=v}(f,e[2])),e===null&&(n=f),e}function Ul(){var e,l;return l=n,o.substr(n,10)==="early-only"?(e="early-only",n+=10):(e=null,h('"early-only"')),e!==null&&(e=function(u){w.early_only=!0}()),e===null&&(n=l),e}function la(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 Pl(){for(var e=1,l=1,u=!1,f=0;f<Math.max(n,d);f++){var p=o.charAt(f);p===`
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 us=Gs(),b=Cu(),w={},Ri=t[a]();if(Ri===null||n!==o.length){var Ii=Math.max(n,d),xl=Ii<o.length?o.charAt(Ii):null,i=Pl();return new this.SyntaxError(la(_),xl,Ii,i.line,i.column),-1}return w},toSource:function(){return this._source}};return s.SyntaxError=function(r,o,a,t,n){function d(_,h){var g,T;switch(_.length){case 0:g="end of input";break;case 1:g=_[0];break;default:g=_.slice(0,_.length-1).join(", ")+" or "+_[_.length-1]}return T=h?c(h):"end of input","Expected "+g+" but "+T+" found."}this.name="SyntaxError",this.expected=r,this.found=o,this.message=d(r,o),this.offset=a,this.line=t,this.column=n},s.SyntaxError.prototype=Error.prototype,s}()),aa}var ua,Gu;function Gs(){if(Gu)return ua;Gu=1;function c(h,g){var T;if(typeof Symbol>"u"||h[Symbol.iterator]==null){if(Array.isArray(h)||(T=s(h))||g&&h&&typeof h.length=="number"){T&&(h=T);var E=0,y=function(){};return{s:y,n:function(){return E>=h.length?{done:!0}:{done:!1,value:h[E++]}},e:function(L){throw L},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 A=!0,C=!1,I;return{s:function(){T=h[Symbol.iterator]()},n:function(){var L=T.next();return A=L.done,L},e:function(L){C=!0,I=L},f:function(){try{!A&&T.return!=null&&T.return()}finally{if(C)throw I}}}}function s(h,g){if(h){if(typeof h=="string")return r(h,g);var T=Object.prototype.toString.call(h).slice(8,-1);if(T==="Object"&&h.constructor&&(T=h.constructor.name),T==="Map"||T==="Set")return Array.from(h);if(T==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(T))return r(h,g)}}function r(h,g){(g==null||g>h.length)&&(g=h.length);for(var T=0,E=new Array(g);T<g;T++)E[T]=h[T];return E}function o(h,g){if(!(h instanceof g))throw new TypeError("Cannot call a class as a function")}function a(h,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(h,E.key,E)}}function t(h,g,T){return g&&a(h.prototype,g),T&&a(h,T),h}var n=it,d=bt(),_=is();return ua=function(){t(h,null,[{key:"parse",value:function(T){if(T=_.parse(T,"SIP_URI"),T!==-1)return T}}]);function h(g,T,E,y){var A=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{},C=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{};if(o(this,h),!E)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=g||n.SIP,this._user=T,this._host=E,this._port=y;for(var I in A)Object.prototype.hasOwnProperty.call(A,I)&&this.setParam(I,A[I]);for(var H in C)Object.prototype.hasOwnProperty.call(C,H)&&this.setHeader(H,C[H])}return t(h,[{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 h(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 A in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,A)){var C=c(this._headers[A]),I;try{for(C.s();!(I=C.n()).done;){var H=I.value;T.push("".concat(A,"=").concat(H))}}catch(L){C.e(L)}finally{C.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}}]),h}(),ua}var Wu;function bt(){if(Wu)return Ze;Wu=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 s(g,T){var E;if(typeof Symbol>"u"||g[Symbol.iterator]==null){if(Array.isArray(g)||(E=r(g))||T&&g&&typeof g.length=="number"){E&&(g=E);var y=0,A=function(){};return{s:A,n:function(){return y>=g.length?{done:!0}:{done:!1,value:g[y++]}},e:function(ae){throw ae},f:A}}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 C=!0,I=!1,H;return{s:function(){E=g[Symbol.iterator]()},n:function(){var ae=E.next();return C=ae.done,ae},e:function(ae){I=!0,H=ae},f:function(){try{!C&&E.return!=null&&E.return()}finally{if(I)throw H}}}}function r(g,T){if(g){if(typeof g=="string")return o(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 o(g,T)}}function o(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 a=it,t=Gs(),n=is();Ze.str_utf8_length=function(g){return unescape(encodeURIComponent(g)).length};var d=Ze.isFunction=function(g){return g!==void 0?Object.prototype.toString.call(g)==="[object Function]":!1};Ze.isString=function(g){return g!==void 0?Object.prototype.toString.call(g)==="[object String]":!1},Ze.isDecimal=function(g){return!isNaN(g)&&parseFloat(g)===parseInt(g,10)},Ze.isEmpty=function(g){return g===null||g===""||g===void 0||Array.isArray(g)&&g.length===0||typeof g=="number"&&isNaN(g)},Ze.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 _=Ze.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};Ze.newTag=function(){return _(10)},Ze.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},Ze.hostType=function(g){if(g){if(g=n.parse(g,"host"),g!==-1)return g.host_type}else return};var h=Ze.escapeUser=function(g){return encodeURIComponent(decodeURIComponent(g)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/")};return Ze.normalizeTarget=function(g,T){if(g){if(g instanceof t)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(a.SIP,":").concat(h(y),"@").concat(A);var C;return(C=t.parse(g))?C:void 0}else return}else return},Ze.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},Ze.sipErrorCause=function(g){for(var T in a.SIP_ERROR_CAUSES)if(a.SIP_ERROR_CAUSES[T].indexOf(g)!==-1)return a.causes[T];return a.causes.SIP_FAILURE_CODE},Ze.getRandomTestNetIP=function(){function g(T,E){return Math.floor(Math.random()*(E-T+1)+T)}return"192.0.2.".concat(g(1,254))},Ze.calculateMD5=function(g){function T(pe,ue){return pe<<ue|pe>>>32-ue}function E(pe,ue){var de=pe&2147483648,we=ue&2147483648,Ne=pe&1073741824,Qe=ue&1073741824,Le=(pe&1073741823)+(ue&1073741823);return Ne&Qe?Le^2147483648^de^we:Ne|Qe?Le&1073741824?Le^3221225472^de^we:Le^1073741824^de^we:Le^de^we}function y(pe,ue,de){return pe&ue|~pe&de}function A(pe,ue,de){return pe&de|ue&~de}function C(pe,ue,de){return pe^ue^de}function I(pe,ue,de){return ue^(pe|~de)}function H(pe,ue,de,we,Ne,Qe,Le){return pe=E(pe,E(E(y(ue,de,we),Ne),Le)),E(T(pe,Qe),ue)}function L(pe,ue,de,we,Ne,Qe,Le){return pe=E(pe,E(E(A(ue,de,we),Ne),Le)),E(T(pe,Qe),ue)}function ae(pe,ue,de,we,Ne,Qe,Le){return pe=E(pe,E(E(C(ue,de,we),Ne),Le)),E(T(pe,Qe),ue)}function N(pe,ue,de,we,Ne,Qe,Le){return pe=E(pe,E(E(I(ue,de,we),Ne),Le)),E(T(pe,Qe),ue)}function j(pe){for(var ue,de=pe.length,we=de+8,Ne=(we-we%64)/64,Qe=(Ne+1)*16,Le=new Array(Qe-1),kt=0,ht=0;ht<de;)ue=(ht-ht%4)/4,kt=ht%4*8,Le[ue]=Le[ue]|pe.charCodeAt(ht)<<kt,ht++;return ue=(ht-ht%4)/4,kt=ht%4*8,Le[ue]=Le[ue]|128<<kt,Le[Qe-2]=de<<3,Le[Qe-1]=de>>>29,Le}function Se(pe){var ue="",de="",we,Ne;for(Ne=0;Ne<=3;Ne++)we=pe>>>Ne*8&255,de="0".concat(we.toString(16)),ue=ue+de.substr(de.length-2,2);return ue}function ve(pe){for(var ue="",de=0;de<pe.length;de++){var we=pe.charCodeAt(de);we<128?ue+=String.fromCharCode(we):we>127&&we<2048?(ue+=String.fromCharCode(we>>6|192),ue+=String.fromCharCode(we&63|128)):(ue+=String.fromCharCode(we>>12|224),ue+=String.fromCharCode(we>>6&63|128),ue+=String.fromCharCode(we&63|128))}return ue}var M=[],D,B,V,J,F,X,U,P,se,tt=7,ee=12,W=17,G=22,re=5,ge=9,be=14,xe=20,Ce=4,le=11,ye=16,st=23,lt=6,Ee=10,Ae=15,Ie=21;for(g=ve(g),M=j(g),X=1732584193,U=4023233417,P=2562383102,se=271733878,D=0;D<M.length;D+=16)B=X,V=U,J=P,F=se,X=H(X,U,P,se,M[D+0],tt,3614090360),se=H(se,X,U,P,M[D+1],ee,3905402710),P=H(P,se,X,U,M[D+2],W,606105819),U=H(U,P,se,X,M[D+3],G,3250441966),X=H(X,U,P,se,M[D+4],tt,4118548399),se=H(se,X,U,P,M[D+5],ee,1200080426),P=H(P,se,X,U,M[D+6],W,2821735955),U=H(U,P,se,X,M[D+7],G,4249261313),X=H(X,U,P,se,M[D+8],tt,1770035416),se=H(se,X,U,P,M[D+9],ee,2336552879),P=H(P,se,X,U,M[D+10],W,4294925233),U=H(U,P,se,X,M[D+11],G,2304563134),X=H(X,U,P,se,M[D+12],tt,1804603682),se=H(se,X,U,P,M[D+13],ee,4254626195),P=H(P,se,X,U,M[D+14],W,2792965006),U=H(U,P,se,X,M[D+15],G,1236535329),X=L(X,U,P,se,M[D+1],re,4129170786),se=L(se,X,U,P,M[D+6],ge,3225465664),P=L(P,se,X,U,M[D+11],be,643717713),U=L(U,P,se,X,M[D+0],xe,3921069994),X=L(X,U,P,se,M[D+5],re,3593408605),se=L(se,X,U,P,M[D+10],ge,38016083),P=L(P,se,X,U,M[D+15],be,3634488961),U=L(U,P,se,X,M[D+4],xe,3889429448),X=L(X,U,P,se,M[D+9],re,568446438),se=L(se,X,U,P,M[D+14],ge,3275163606),P=L(P,se,X,U,M[D+3],be,4107603335),U=L(U,P,se,X,M[D+8],xe,1163531501),X=L(X,U,P,se,M[D+13],re,2850285829),se=L(se,X,U,P,M[D+2],ge,4243563512),P=L(P,se,X,U,M[D+7],be,1735328473),U=L(U,P,se,X,M[D+12],xe,2368359562),X=ae(X,U,P,se,M[D+5],Ce,4294588738),se=ae(se,X,U,P,M[D+8],le,2272392833),P=ae(P,se,X,U,M[D+11],ye,1839030562),U=ae(U,P,se,X,M[D+14],st,4259657740),X=ae(X,U,P,se,M[D+1],Ce,2763975236),se=ae(se,X,U,P,M[D+4],le,1272893353),P=ae(P,se,X,U,M[D+7],ye,4139469664),U=ae(U,P,se,X,M[D+10],st,3200236656),X=ae(X,U,P,se,M[D+13],Ce,681279174),se=ae(se,X,U,P,M[D+0],le,3936430074),P=ae(P,se,X,U,M[D+3],ye,3572445317),U=ae(U,P,se,X,M[D+6],st,76029189),X=ae(X,U,P,se,M[D+9],Ce,3654602809),se=ae(se,X,U,P,M[D+12],le,3873151461),P=ae(P,se,X,U,M[D+15],ye,530742520),U=ae(U,P,se,X,M[D+2],st,3299628645),X=N(X,U,P,se,M[D+0],lt,4096336452),se=N(se,X,U,P,M[D+7],Ee,1126891415),P=N(P,se,X,U,M[D+14],Ae,2878612391),U=N(U,P,se,X,M[D+5],Ie,4237533241),X=N(X,U,P,se,M[D+12],lt,1700485571),se=N(se,X,U,P,M[D+3],Ee,2399980690),P=N(P,se,X,U,M[D+10],Ae,4293915773),U=N(U,P,se,X,M[D+1],Ie,2240044497),X=N(X,U,P,se,M[D+8],lt,1873313359),se=N(se,X,U,P,M[D+15],Ee,4264355552),P=N(P,se,X,U,M[D+6],Ae,2734768916),U=N(U,P,se,X,M[D+13],Ie,1309151649),X=N(X,U,P,se,M[D+4],lt,4149444226),se=N(se,X,U,P,M[D+11],Ee,3174756917),P=N(P,se,X,U,M[D+2],Ae,718787259),U=N(U,P,se,X,M[D+9],Ie,3951481745),X=E(X,B),U=E(U,V),P=E(P,J),se=E(se,F);var Oe=Se(X)+Se(U)+Se(P)+Se(se);return Oe.toLowerCase()},Ze.closeMediaStream=function(g){if(g)try{var T;if(g.getTracks){T=g.getTracks();var E=s(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=s(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 L=s(T),ae;try{for(L.s();!(ae=L.n()).done;){var N=ae.value;N.stop()}}catch(j){L.e(j)}finally{L.f()}}}catch{(typeof g.stop=="function"||c(g.stop)==="object")&&g.stop()}},Ze.cloneArray=function(g){return g&&g.slice()||[]},Ze.cloneObject=function(g){var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return g&&Object.assign({},g)||T},Ze}var Ru={exports:{}},fr=typeof Reflect=="object"?Reflect:null,Ku=fr&&typeof fr.apply=="function"?fr.apply:function(s,r,o){return Function.prototype.apply.call(s,r,o)},ho;fr&&typeof fr.ownKeys=="function"?ho=fr.ownKeys:Object.getOwnPropertySymbols?ho=function(s){return Object.getOwnPropertyNames(s).concat(Object.getOwnPropertySymbols(s))}:ho=function(s){return Object.getOwnPropertyNames(s)};function nh(c){console&&console.warn&&console.warn(c)}var Ff=Number.isNaN||function(s){return s!==s};function ke(){ke.init.call(this)}Ru.exports=ke;Ru.exports.once=oh;ke.EventEmitter=ke;ke.prototype._events=void 0;ke.prototype._eventsCount=0;ke.prototype._maxListeners=void 0;var Yu=10;function jo(c){if(typeof c!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof c)}Object.defineProperty(ke,"defaultMaxListeners",{enumerable:!0,get:function(){return Yu},set:function(c){if(typeof c!="number"||c<0||Ff(c))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+c+".");Yu=c}});ke.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};ke.prototype.setMaxListeners=function(s){if(typeof s!="number"||s<0||Ff(s))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+s+".");return this._maxListeners=s,this};function jf(c){return c._maxListeners===void 0?ke.defaultMaxListeners:c._maxListeners}ke.prototype.getMaxListeners=function(){return jf(this)};ke.prototype.emit=function(s){for(var r=[],o=1;o<arguments.length;o++)r.push(arguments[o]);var a=s==="error",t=this._events;if(t!==void 0)a=a&&t.error===void 0;else if(!a)return!1;if(a){var n;if(r.length>0&&(n=r[0]),n instanceof Error)throw n;var d=new Error("Unhandled error."+(n?" ("+n.message+")":""));throw d.context=n,d}var _=t[s];if(_===void 0)return!1;if(typeof _=="function")Ku(_,this,r);else for(var h=_.length,g=Wf(_,h),o=0;o<h;++o)Ku(g[o],this,r);return!0};function qf(c,s,r,o){var a,t,n;if(jo(r),t=c._events,t===void 0?(t=c._events=Object.create(null),c._eventsCount=0):(t.newListener!==void 0&&(c.emit("newListener",s,r.listener?r.listener:r),t=c._events),n=t[s]),n===void 0)n=t[s]=r,++c._eventsCount;else if(typeof n=="function"?n=t[s]=o?[r,n]:[n,r]:o?n.unshift(r):n.push(r),a=jf(c),a>0&&n.length>a&&!n.warned){n.warned=!0;var d=new Error("Possible EventEmitter memory leak detected. "+n.length+" "+String(s)+" listeners added. Use emitter.setMaxListeners() to increase limit");d.name="MaxListenersExceededWarning",d.emitter=c,d.type=s,d.count=n.length,nh(d)}return c}ke.prototype.addListener=function(s,r){return qf(this,s,r,!1)};ke.prototype.on=ke.prototype.addListener;ke.prototype.prependListener=function(s,r){return qf(this,s,r,!0)};function rh(){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 Vf(c,s,r){var o={fired:!1,wrapFn:void 0,target:c,type:s,listener:r},a=rh.bind(o);return a.listener=r,o.wrapFn=a,a}ke.prototype.once=function(s,r){return jo(r),this.on(s,Vf(this,s,r)),this};ke.prototype.prependOnceListener=function(s,r){return jo(r),this.prependListener(s,Vf(this,s,r)),this};ke.prototype.removeListener=function(s,r){var o,a,t,n,d;if(jo(r),a=this._events,a===void 0)return this;if(o=a[s],o===void 0)return this;if(o===r||o.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete a[s],a.removeListener&&this.emit("removeListener",s,o.listener||r));else if(typeof o!="function"){for(t=-1,n=o.length-1;n>=0;n--)if(o[n]===r||o[n].listener===r){d=o[n].listener,t=n;break}if(t<0)return this;t===0?o.shift():ih(o,t),o.length===1&&(a[s]=o[0]),a.removeListener!==void 0&&this.emit("removeListener",s,d||r)}return this};ke.prototype.off=ke.prototype.removeListener;ke.prototype.removeAllListeners=function(s){var r,o,a;if(o=this._events,o===void 0)return this;if(o.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):o[s]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete o[s]),this;if(arguments.length===0){var t=Object.keys(o),n;for(a=0;a<t.length;++a)n=t[a],n!=="removeListener"&&this.removeAllListeners(n);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(r=o[s],typeof r=="function")this.removeListener(s,r);else if(r!==void 0)for(a=r.length-1;a>=0;a--)this.removeListener(s,r[a]);return this};function Bf(c,s,r){var o=c._events;if(o===void 0)return[];var a=o[s];return a===void 0?[]:typeof a=="function"?r?[a.listener||a]:[a]:r?lh(a):Wf(a,a.length)}ke.prototype.listeners=function(s){return Bf(this,s,!0)};ke.prototype.rawListeners=function(s){return Bf(this,s,!1)};ke.listenerCount=function(c,s){return typeof c.listenerCount=="function"?c.listenerCount(s):Gf.call(c,s)};ke.prototype.listenerCount=Gf;function Gf(c){var s=this._events;if(s!==void 0){var r=s[c];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}ke.prototype.eventNames=function(){return this._eventsCount>0?ho(this._events):[]};function Wf(c,s){for(var r=new Array(s),o=0;o<s;++o)r[o]=c[o];return r}function ih(c,s){for(;s+1<c.length;s++)c[s]=c[s+1];c.pop()}function lh(c){for(var s=new Array(c.length),r=0;r<s.length;++r)s[r]=c[r].listener||c[r];return s}function oh(c,s){return new Promise(function(r,o){function a(n){c.removeListener(s,t),o(n)}function t(){typeof c.removeListener=="function"&&c.removeListener("error",a),r([].slice.call(arguments))}Kf(c,s,t,{once:!0}),s!=="error"&&ah(c,a,{once:!0})})}function ah(c,s,r){typeof c.on=="function"&&Kf(c,"error",s,r)}function Kf(c,s,r,o){if(typeof c.on=="function")o.once?c.once(s,r):c.on(s,r);else if(typeof c.addEventListener=="function")c.addEventListener(s,function a(t){o.once&&c.removeEventListener(s,a),r(t)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof c)}var ft=Ru.exports,iu={exports:{}},ca,Ju;function uh(){if(Ju)return ca;Ju=1;var c=1e3,s=c*60,r=s*60,o=r*24,a=o*7,t=o*365.25;ca=function(g,T){T=T||{};var E=typeof g;if(E==="string"&&g.length>0)return n(g);if(E==="number"&&isFinite(g))return T.long?_(g):d(g);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(g))};function n(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*t;case"weeks":case"week":case"w":return E*a;case"days":case"day":case"d":return E*o;case"hours":case"hour":case"hrs":case"hr":case"h":return E*r;case"minutes":case"minute":case"mins":case"min":case"m":return E*s;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>=o?Math.round(g/o)+"d":T>=r?Math.round(g/r)+"h":T>=s?Math.round(g/s)+"m":T>=c?Math.round(g/c)+"s":g+"ms"}function _(g){var T=Math.abs(g);return T>=o?h(g,T,o,"day"):T>=r?h(g,T,r,"hour"):T>=s?h(g,T,s,"minute"):T>=c?h(g,T,c,"second"):g+" ms"}function h(g,T,E,y){var A=T>=E*1.5;return Math.round(g/E)+" "+y+(A?"s":"")}return ca}function ch(c){r.debug=r,r.default=r,r.coerce=_,r.disable=t,r.enable=a,r.enabled=n,r.humanize=uh(),r.destroy=h,Object.keys(c).forEach(g=>{r[g]=c[g]}),r.names=[],r.skips=[],r.formatters={};function s(g){let T=0;for(let E=0;E<g.length;E++)T=(T<<5)-T+g.charCodeAt(E),T|=0;return r.colors[Math.abs(T)%r.colors.length]}r.selectColor=s;function r(g){let T,E=null,y,A;function C(...I){if(!C.enabled)return;const H=C,L=Number(new Date),ae=L-(T||L);H.diff=ae,H.prev=T,H.curr=L,T=L,I[0]=r.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 M=r.formatters[ve];if(typeof M=="function"){const D=I[N];Se=M.call(H,D),I.splice(N,1),N--}return Se}),r.formatArgs.call(H,I),(H.log||r.log).apply(H,I)}return C.namespace=g,C.useColors=r.useColors(),C.color=r.selectColor(g),C.extend=o,C.destroy=r.destroy,Object.defineProperty(C,"enabled",{enumerable:!0,configurable:!1,get:()=>E!==null?E:(y!==r.namespaces&&(y=r.namespaces,A=r.enabled(g)),A),set:I=>{E=I}}),typeof r.init=="function"&&r.init(C),C}function o(g,T){const E=r(this.namespace+(typeof T>"u"?":":T)+g);return E.log=this.log,E}function a(g){r.save(g),r.namespaces=g,r.names=[],r.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]==="-"?r.skips.push(new RegExp("^"+g.slice(1)+"$")):r.names.push(new RegExp("^"+g+"$")))}function t(){const g=[...r.names.map(d),...r.skips.map(d).map(T=>"-"+T)].join(",");return r.enable(""),g}function n(g){if(g[g.length-1]==="*")return!0;let T,E;for(T=0,E=r.skips.length;T<E;T++)if(r.skips[T].test(g))return!1;for(T=0,E=r.names.length;T<E;T++)if(r.names[T].test(g))return!0;return!1}function d(g){return g.toString().substring(2,g.toString().length-2).replace(/\.\*\?$/,"*")}function _(g){return g instanceof Error?g.stack||g.message:g}function h(){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 r.enable(r.load()),r}var fh=ch;(function(c,s){s.formatArgs=o,s.save=a,s.load=t,s.useColors=r,s.storage=n(),s.destroy=(()=>{let _=!1;return()=>{_||(_=!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`."))}})(),s.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 r(){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 o(_){if(_[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+_[0]+(this.useColors?"%c ":" ")+"+"+c.exports.humanize(this.diff),!this.useColors)return;const h="color: "+this.color;_.splice(1,0,h,"color: inherit");let g=0,T=0;_[0].replace(/%[a-zA-Z%]/g,E=>{E!=="%%"&&(g++,E==="%c"&&(T=g))}),_.splice(T,0,h)}s.log=console.debug||console.log||(()=>{});function a(_){try{_?s.storage.setItem("debug",_):s.storage.removeItem("debug")}catch{}}function t(){let _;try{_=s.storage.getItem("debug")}catch{}return!_&&typeof process<"u"&&"env"in process&&(_=process.env.DEBUG),_}function n(){try{return localStorage}catch{}}c.exports=fh(s);const{formatters:d}=c.exports;d.j=function(_){try{return JSON.stringify(_)}catch(h){return"[UnexpectedJSONParseError]: "+h.message}}})(iu,iu.exports);var dr=iu.exports;function _h(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function zu(c,s){for(var r=0;r<s.length;r++){var o=s[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function hh(c,s,r){return s&&zu(c.prototype,s),r&&zu(c,r),c}var nr=dr,rr="JsSIP",_t=function(){function c(s){_h(this,c),s?(this._debug=nr.default("".concat(rr,":").concat(s)),this._warn=nr.default("".concat(rr,":WARN:").concat(s)),this._error=nr.default("".concat(rr,":ERROR:").concat(s))):(this._debug=nr.default(rr),this._warn=nr.default("".concat(rr,":WARN")),this._error=nr.default("".concat(rr,":ERROR"))),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}return hh(c,[{key:"debug",get:function(){return this._debug}},{key:"warn",get:function(){return this._warn}},{key:"error",get:function(){return this._error}}]),c}(),Pt={},Yf={},Jf={exports:{}},Xu=Jf.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 s="candidate:%s %d %s %d %s %d typ %s";return s+=c.raddr!=null?" raddr %s rport %d":"%v%v",s+=c.tcptype!=null?" tcptype %s":"%v",c.generation!=null&&(s+=" generation %d"),s+=c["network-id"]!=null?" network-id %d":"%v",s+=c["network-cost"]!=null?" network-cost %d":"%v",s}},{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 s="ssrc:%d";return c.attribute!=null&&(s+=" %s",c.value!=null&&(s+=":%s")),s}},{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 s="mediaclk:";return s+=c.id!=null?"id=%s %s":"%v%s",s+=c.mediaClockValue!=null?"=%s":"",s+=c.rateNumerator!=null?" rate=%s":"",s+=c.rateDenominator!=null?"/%s":"",s}},{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(Xu).forEach(function(c){var s=Xu[c];s.forEach(function(r){r.reg||(r.reg=/(.*)/),r.format||(r.format="%s")})});var zf=Jf.exports;(function(c){var s=function(d){return String(Number(d))===d?Number(d):d},r=function(d,_,h,g){if(g&&!h)_[g]=s(d[1]);else for(var T=0;T<h.length;T+=1)d[T+1]!=null&&(_[h[T]]=s(d[T+1]))},o=function(d,_,h){var g=d.name&&d.names;d.push&&!_[d.push]?_[d.push]=[]:g&&!_[d.name]&&(_[d.name]={});var T=d.push?{}:g?_[d.name]:_;r(h.match(d.reg),T,d.names,d.name),d.push&&_[d.push].push(T)},a=zf,t=RegExp.prototype.test.bind(/^([a-z])=(.*)/);c.parse=function(d){var _={},h=[],g=_;return d.split(/(\r\n|\r|\n)/).filter(t).forEach(function(T){var E=T[0],y=T.slice(2);E==="m"&&(h.push({rtp:[],fmtp:[]}),g=h[h.length-1]);for(var A=0;A<(a[E]||[]).length;A+=1){var C=a[E][A];if(C.reg.test(y))return o(C,g,y)}}),_.media=h,_};var n=function(d,_){var h=_.split(/=(.+)/,2);return h.length===2?d[h[0]]=s(h[1]):h.length===1&&_.length>1&&(d[h[0]]=void 0),d};c.parseParams=function(d){return d.split(/;\s?/).reduce(n,{})},c.parseFmtpConfig=c.parseParams,c.parsePayloads=function(d){return d.toString().split(" ").map(Number)},c.parseRemoteCandidates=function(d){for(var _=[],h=d.split(" ").map(s),g=0;g<h.length;g+=3)_.push({component:h[g],ip:h[g+1],port:h[g+2]});return _},c.parseImageAttributes=function(d){return d.split(" ").map(function(_){return _.substring(1,_.length-1).split(",").reduce(n,{})})},c.parseSimulcastStreamList=function(d){return d.split(";").map(function(_){return _.split(",").map(function(h){var g,T=!1;return h[0]!=="~"?g=s(h):(g=s(h.substring(1,h.length)),T=!0),{scid:g,paused:T}})})}})(Yf);var fa=zf,dh=/%[sdv%]/g,ph=function(c){var s=1,r=arguments,o=r.length;return c.replace(dh,function(a){if(s>=o)return a;var t=r[s];switch(s+=1,a){case"%%":return"%";case"%s":return String(t);case"%d":return Number(t);case"%v":return""}})},bi=function(c,s,r){var o=s.format instanceof Function?s.format(s.push?r:r[s.name]):s.format,a=[c+"="+o];if(s.names)for(var t=0;t<s.names.length;t+=1){var n=s.names[t];s.name?a.push(r[s.name][n]):a.push(r[s.names[t]])}else a.push(r[s.name]);return ph.apply(null,a)},mh=["v","o","s","i","u","e","p","c","b","t","r","z","a"],gh=["i","c","b","a"],Th=function(c,s){s=s||{},c.version==null&&(c.version=0),c.name==null&&(c.name=" "),c.media.forEach(function(t){t.payloads==null&&(t.payloads="")});var r=s.outerOrder||mh,o=s.innerOrder||gh,a=[];return r.forEach(function(t){fa[t].forEach(function(n){n.name in c&&c[n.name]!=null?a.push(bi(t,n,c)):n.push in c&&c[n.push]!=null&&c[n.push].forEach(function(d){a.push(bi(t,n,d))})})}),c.media.forEach(function(t){a.push(bi("m",fa.m[0],t)),o.forEach(function(n){fa[n].forEach(function(d){d.name in t&&t[d.name]!=null?a.push(bi(n,d,t)):d.push in t&&t[d.push]!=null&&t[d.push].forEach(function(_){a.push(bi(n,d,_))})})})}),a.join(`\r
1
+ "use strict";var L_=Object.defineProperty;var $_=(c,s,i)=>s in c?L_(c,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):c[s]=i;var Kt=(c,s,i)=>($_(c,typeof s!="symbol"?s+"":s,i),i);var H_=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function tt(c){return c&&c.__esModule&&Object.prototype.hasOwnProperty.call(c,"default")?c.default:c}const F_="jssip",j_="JsSIP",q_="the Javascript SIP library",V_="3.10.0",B_="https://jssip.net",G_=["José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)","Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)"],W_="lib/JsSIP.d.ts",K_="lib-es5/JsSIP.js",Y_=["sip","websocket","webrtc","node","browser","library"],J_="MIT",z_={type:"git",url:"https://github.com/versatica/JsSIP.git"},X_={url:"https://github.com/versatica/JsSIP/issues"},Q_={"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},Z_={"@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"},eh={lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"},Ka={name:F_,title:j_,description:q_,version:V_,homepage:B_,contributors:G_,types:W_,main:K_,keywords:Y_,license:J_,repository:z_,bugs:X_,dependencies:Q_,devDependencies:Z_,scripts:eh};var Gu=Ka,ot={USER_AGENT:"".concat(Gu.title," ").concat(Gu.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 ya(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?ya=function(i){return typeof i}:ya=function(i){return i&&typeof Symbol=="function"&&i.constructor===Symbol&&i!==Symbol.prototype?"symbol":typeof i},ya(c)}function Ya(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function Ja(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&zi(c,s)}function za(c){var s=Vf();return function(){var l=Xi(c),a;if(s){var _=Xi(this).constructor;a=Reflect.construct(l,arguments,_)}else a=l.apply(this,arguments);return th(this,a)}}function th(c,s){return s&&(ya(s)==="object"||typeof s=="function")?s:sh(c)}function sh(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function or(c){var s=typeof Map=="function"?new Map:void 0;return or=function(l){if(l===null||!nh(l))return l;if(typeof l!="function")throw new TypeError("Super expression must either be null or a function");if(typeof s<"u"){if(s.has(l))return s.get(l);s.set(l,a)}function a(){return Aa(l,arguments,Xi(this).constructor)}return a.prototype=Object.create(l.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),zi(a,l)},or(c)}function Aa(c,s,i){return Vf()?Aa=Reflect.construct:Aa=function(a,_,e){var p=[null];p.push.apply(p,_);var g=Function.bind.apply(a,p),n=new g;return e&&zi(n,e.prototype),n},Aa.apply(null,arguments)}function Vf(){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 nh(c){return Function.toString.call(c).indexOf("[native code]")!==-1}function zi(c,s){return zi=Object.setPrototypeOf||function(l,a){return l.__proto__=a,l},zi(c,s)}function Xi(c){return Xi=Object.setPrototypeOf?Object.getPrototypeOf:function(i){return i.__proto__||Object.getPrototypeOf(i)},Xi(c)}var rh=function(c){Ja(i,c);var s=za(i);function i(l,a){var _;return Ya(this,i),_=s.call(this),_.code=1,_.name="CONFIGURATION_ERROR",_.parameter=l,_.value=a,_.message=_.value?"Invalid value ".concat(JSON.stringify(_.value),' for parameter "').concat(_.parameter,'"'):"Missing parameter: ".concat(_.parameter),_}return i}(or(Error)),ih=function(c){Ja(i,c);var s=za(i);function i(l){var a;return Ya(this,i),a=s.call(this),a.code=2,a.name="INVALID_STATE_ERROR",a.status=l,a.message="Invalid status: ".concat(l),a}return i}(or(Error)),lh=function(c){Ja(i,c);var s=za(i);function i(l){var a;return Ya(this,i),a=s.call(this),a.code=3,a.name="NOT_SUPPORTED_ERROR",a.message=l,a}return i}(or(Error)),ah=function(c){Ja(i,c);var s=za(i);function i(l){var a;return Ya(this,i),a=s.call(this),a.code=4,a.name="NOT_READY_ERROR",a.message=l,a}return i}(or(Error)),en={ConfigurationError:rh,InvalidStateError:ih,NotSupportedError:lh,NotReadyError:ah},nt={},fo,Wu;function Ou(){if(Wu)return fo;Wu=1;function c(_,e){if(!(_ instanceof e))throw new TypeError("Cannot call a class as a function")}function s(_,e){for(var p=0;p<e.length;p++){var g=e[p];g.enumerable=g.enumerable||!1,g.configurable=!0,"value"in g&&(g.writable=!0),Object.defineProperty(_,g.key,g)}}function i(_,e,p){return e&&s(_.prototype,e),p&&s(_,p),_}var l=tn(),a=us();return fo=function(){i(_,null,[{key:"parse",value:function(p){if(p=a.parse(p,"Name_Addr_Header"),p!==-1)return p}}]);function _(e,p,g){if(c(this,_),!e||!(e instanceof l))throw new TypeError('missing or invalid "uri" parameter');this._uri=e,this._parameters={},this.display_name=p;for(var n in g)Object.prototype.hasOwnProperty.call(g,n)&&this.setParam(n,g[n])}return i(_,[{key:"setParam",value:function(p,g){p&&(this._parameters[p.toLowerCase()]=typeof g>"u"||g===null?null:g.toString())}},{key:"getParam",value:function(p){if(p)return this._parameters[p.toLowerCase()]}},{key:"hasParam",value:function(p){if(p)return this._parameters.hasOwnProperty(p.toLowerCase())&&!0||!1}},{key:"deleteParam",value:function(p){if(p=p.toLowerCase(),this._parameters.hasOwnProperty(p)){var g=this._parameters[p];return delete this._parameters[p],g}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"clone",value:function(){return new _(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}},{key:"_quote",value:function(p){return p.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}},{key:"toString",value:function(){var p=this._display_name?'"'.concat(this._quote(this._display_name),'" '):"";p+="<".concat(this._uri.toString(),">");for(var g in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,g)&&(p+=";".concat(g),this._parameters[g]!==null&&(p+="=".concat(this._parameters[g])));return p}},{key:"uri",get:function(){return this._uri}},{key:"display_name",get:function(){return this._display_name},set:function(p){this._display_name=p===0?"0":p}}]),_}(),fo}var _o,Ku;function us(){return Ku||(Ku=1,_o=function(){function c(i){return'"'+i.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 s={parse:function(l,a){var _={CRLF:v,DIGIT:S,ALPHA:m,HEXDIG:C,WSP:A,OCTET:R,DQUOTE:I,SP:V,HTAB:W,alphanum:oe,reserved:x,unreserved:$,mark:Re,escaped:Ie,LWS:H,SWS:D,HCOLON:L,TEXT_UTF8_TRIM:q,TEXT_UTF8char:j,UTF8_NONASCII:B,UTF8_CONT:X,LHEX:Q,token:U,token_nodot:se,separators:It,word:N,STAR:Y,SLASH:re,EQUAL:ae,LPAREN:Te,RPAREN:De,RAQUOT:Ce,LAQUOT:Le,COMMA:we,SEMI:Se,COLON:it,LDQUOT:Ue,RDQUOT:le,comment:Ae,ctext:Oe,quoted_string:Pe,quoted_string_clean:ve,qdtext:he,quoted_pair:pe,SIP_URI_noparams:Ne,SIP_URI:xe,uri_scheme:Ve,uri_scheme_sips:He,uri_scheme_sip:Ht,userinfo:ct,user:_r,user_unreserved:Mn,password:sn,hostport:nn,host:cs,hostname:kn,domainlabel:ws,toplabel:Os,IPv6reference:rn,IPv6address:ln,h16:ge,ls32:pt,IPv4address:fs,dec_octet:de,port:bt,uri_parameters:Ds,uri_parameter:_s,transport_param:hr,user_param:dr,method_param:Ln,ttl_param:pr,maddr_param:mr,lr_param:gr,other_param:Tr,pname:vr,pvalue:Er,paramchar:Ns,param_unreserved:Sr,headers:yr,header:Zt,hname:Ar,hvalue:Cr,hnv_unreserved:es,Request_Response:hl,Request_Line:Rr,Request_URI:Us,absoluteURI:Ir,hier_part:br,net_path:wr,abs_path:Ps,opaque_part:Or,uric:xs,uric_no_slash:an,path_segments:Dr,segment:ts,param:$n,pchar:Ms,scheme:on,authority:Hn,srvr:ks,reg_name:Nr,query:Ur,SIP_Version:Fn,INVITEm:Pr,ACKm:xr,OPTIONSm:jn,BYEm:Mr,CANCELm:kr,REGISTERm:Lr,SUBSCRIBEm:$r,NOTIFYm:Hr,REFERm:Fr,Method:un,Status_Line:jr,Status_Code:qr,extension_code:cn,Reason_Phrase:Vr,Allow_Events:dl,Call_ID:pl,Contact:ml,contact_param:qn,name_addr:hs,display_name:Vn,contact_params:Ls,c_p_q:ss,c_p_expires:fn,delta_seconds:Bt,qvalue:Br,generic_param:ze,gen_value:ns,Content_Disposition:gl,disp_type:Xe,disp_param:Bn,handling_param:Tl,Content_Encoding:vl,Content_Length:Gr,Content_Type:El,media_type:Sl,m_type:yl,discrete_type:Al,composite_type:Wr,extension_token:_n,x_token:Kr,m_subtype:Yr,m_parameter:$s,m_value:Jr,CSeq:Cl,CSeq_value:Gn,Expires:Rl,Event:so,event_type:Hs,From:no,from_param:zr,tag_param:ds,Max_Forwards:ro,Min_Expires:Xr,Name_Addr_Header:Qr,Proxy_Authenticate:io,challenge:Zr,other_challenge:Il,auth_param:hn,digest_cln:Fs,realm:ei,realm_value:js,domain:dn,URI:pn,nonce:ti,nonce_value:si,opaque:mn,stale:ni,algorithm:ri,qop_options:ii,qop_value:gn,Proxy_Require:bl,Record_Route:wl,rec_route:ps,Reason:lo,reason_param:li,reason_cause:Tn,Require:ao,Route:ai,route_param:vn,Subscription_State:oo,substate_value:Ol,subexp_params:qs,event_reason_value:Dl,Subject:Nl,Supported:oi,To:Ul,to_param:ui,Via:uo,via_param:Wn,via_params:En,via_ttl:Pl,via_maddr:Sn,via_received:Kn,via_branch:ci,response_port:fi,rport:_i,sent_protocol:hi,protocol_name:di,transport:pi,sent_by:mi,via_host:gi,via_port:Ti,ttl:Yn,WWW_Authenticate:xl,Session_Expires:Ml,s_e_expires:Jn,s_e_params:vi,s_e_refresher:kl,extension_header:Ll,header_value:zn,message_body:$l,uuid_URI:co,uuid:Ei,hex4:Gt,hex8:Hl,hex12:Si,Refer_To:Wt,Replaces:Fl,call_id:yi,replaces_param:Ai,to_tag:jl,from_tag:Ci,early_flag:Xn};if(a!==void 0){if(_[a]===void 0)throw new Error("Invalid rule name: "+c(a)+".")}else a="CRLF";var e=0,p=0,g=[];function n(r){e<p||(e>p&&(p=e,g=[]),g.push(r))}function v(){var r;return l.substr(e,2)===`\r
2
+ `?(r=`\r
3
+ `,e+=2):(r=null,n('"\\r\\n"')),r}function S(){var r;return/^[0-9]/.test(l.charAt(e))?(r=l.charAt(e),e++):(r=null,n("[0-9]")),r}function m(){var r;return/^[a-zA-Z]/.test(l.charAt(e))?(r=l.charAt(e),e++):(r=null,n("[a-zA-Z]")),r}function C(){var r;return/^[0-9a-fA-F]/.test(l.charAt(e))?(r=l.charAt(e),e++):(r=null,n("[0-9a-fA-F]")),r}function A(){var r;return r=V(),r===null&&(r=W()),r}function R(){var r;return/^[\0-\xFF]/.test(l.charAt(e))?(r=l.charAt(e),e++):(r=null,n("[\\0-\\xFF]")),r}function I(){var r;return/^["]/.test(l.charAt(e))?(r=l.charAt(e),e++):(r=null,n('["]')),r}function V(){var r;return l.charCodeAt(e)===32?(r=" ",e++):(r=null,n('" "')),r}function W(){var r;return l.charCodeAt(e)===9?(r=" ",e++):(r=null,n('"\\t"')),r}function oe(){var r;return/^[a-zA-Z0-9]/.test(l.charAt(e))?(r=l.charAt(e),e++):(r=null,n("[a-zA-Z0-9]")),r}function x(){var r;return l.charCodeAt(e)===59?(r=";",e++):(r=null,n('";"')),r===null&&(l.charCodeAt(e)===47?(r="/",e++):(r=null,n('"/"')),r===null&&(l.charCodeAt(e)===63?(r="?",e++):(r=null,n('"?"')),r===null&&(l.charCodeAt(e)===58?(r=":",e++):(r=null,n('":"')),r===null&&(l.charCodeAt(e)===64?(r="@",e++):(r=null,n('"@"')),r===null&&(l.charCodeAt(e)===38?(r="&",e++):(r=null,n('"&"')),r===null&&(l.charCodeAt(e)===61?(r="=",e++):(r=null,n('"="')),r===null&&(l.charCodeAt(e)===43?(r="+",e++):(r=null,n('"+"')),r===null&&(l.charCodeAt(e)===36?(r="$",e++):(r=null,n('"$"')),r===null&&(l.charCodeAt(e)===44?(r=",",e++):(r=null,n('","'))))))))))),r}function $(){var r;return r=oe(),r===null&&(r=Re()),r}function Re(){var r;return l.charCodeAt(e)===45?(r="-",e++):(r=null,n('"-"')),r===null&&(l.charCodeAt(e)===95?(r="_",e++):(r=null,n('"_"')),r===null&&(l.charCodeAt(e)===46?(r=".",e++):(r=null,n('"."')),r===null&&(l.charCodeAt(e)===33?(r="!",e++):(r=null,n('"!"')),r===null&&(l.charCodeAt(e)===126?(r="~",e++):(r=null,n('"~"')),r===null&&(l.charCodeAt(e)===42?(r="*",e++):(r=null,n('"*"')),r===null&&(l.charCodeAt(e)===39?(r="'",e++):(r=null,n(`"'"`)),r===null&&(l.charCodeAt(e)===40?(r="(",e++):(r=null,n('"("')),r===null&&(l.charCodeAt(e)===41?(r=")",e++):(r=null,n('")"')))))))))),r}function Ie(){var r,f,h,t,o;return t=e,o=e,l.charCodeAt(e)===37?(r="%",e++):(r=null,n('"%"')),r!==null?(f=C(),f!==null?(h=C(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u,d){return d.join("")}(t,r)),r===null&&(e=t),r}function H(){var r,f,h,t,o,u;for(t=e,o=e,u=e,r=[],f=A();f!==null;)r.push(f),f=A();if(r!==null?(f=v(),f!==null?r=[r,f]:(r=null,e=u)):(r=null,e=u),r=r!==null?r:"",r!==null){if(h=A(),h!==null)for(f=[];h!==null;)f.push(h),h=A();else f=null;f!==null?r=[r,f]:(r=null,e=o)}else r=null,e=o;return r!==null&&(r=function(d){return" "}()),r===null&&(e=t),r}function D(){var r;return r=H(),r=r!==null?r:"",r}function L(){var r,f,h,t,o;for(t=e,o=e,r=[],f=V(),f===null&&(f=W());f!==null;)r.push(f),f=V(),f===null&&(f=W());return r!==null?(l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f!==null?(h=D(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u){return":"}()),r===null&&(e=t),r}function q(){var r,f,h,t,o,u,d;if(o=e,u=e,f=j(),f!==null)for(r=[];f!==null;)r.push(f),f=j();else r=null;if(r!==null){for(f=[],d=e,h=[],t=H();t!==null;)h.push(t),t=H();for(h!==null?(t=j(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);h!==null;){for(f.push(h),d=e,h=[],t=H();t!==null;)h.push(t),t=H();h!==null?(t=j(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d)}f!==null?r=[r,f]:(r=null,e=u)}else r=null,e=u;return r!==null&&(r=function(T){return l.substring(e,T)}(o)),r===null&&(e=o),r}function j(){var r;return/^[!-~]/.test(l.charAt(e))?(r=l.charAt(e),e++):(r=null,n("[!-~]")),r===null&&(r=B()),r}function B(){var r;return/^[\x80-\uFFFF]/.test(l.charAt(e))?(r=l.charAt(e),e++):(r=null,n("[\\x80-\\uFFFF]")),r}function X(){var r;return/^[\x80-\xBF]/.test(l.charAt(e))?(r=l.charAt(e),e++):(r=null,n("[\\x80-\\xBF]")),r}function Q(){var r;return r=S(),r===null&&(/^[a-f]/.test(l.charAt(e))?(r=l.charAt(e),e++):(r=null,n("[a-f]"))),r}function U(){var r,f,h;if(h=e,f=oe(),f===null&&(l.charCodeAt(e)===45?(f="-",e++):(f=null,n('"-"')),f===null&&(l.charCodeAt(e)===46?(f=".",e++):(f=null,n('"."')),f===null&&(l.charCodeAt(e)===33?(f="!",e++):(f=null,n('"!"')),f===null&&(l.charCodeAt(e)===37?(f="%",e++):(f=null,n('"%"')),f===null&&(l.charCodeAt(e)===42?(f="*",e++):(f=null,n('"*"')),f===null&&(l.charCodeAt(e)===95?(f="_",e++):(f=null,n('"_"')),f===null&&(l.charCodeAt(e)===43?(f="+",e++):(f=null,n('"+"')),f===null&&(l.charCodeAt(e)===96?(f="`",e++):(f=null,n('"`"')),f===null&&(l.charCodeAt(e)===39?(f="'",e++):(f=null,n(`"'"`)),f===null&&(l.charCodeAt(e)===126?(f="~",e++):(f=null,n('"~"')))))))))))),f!==null)for(r=[];f!==null;)r.push(f),f=oe(),f===null&&(l.charCodeAt(e)===45?(f="-",e++):(f=null,n('"-"')),f===null&&(l.charCodeAt(e)===46?(f=".",e++):(f=null,n('"."')),f===null&&(l.charCodeAt(e)===33?(f="!",e++):(f=null,n('"!"')),f===null&&(l.charCodeAt(e)===37?(f="%",e++):(f=null,n('"%"')),f===null&&(l.charCodeAt(e)===42?(f="*",e++):(f=null,n('"*"')),f===null&&(l.charCodeAt(e)===95?(f="_",e++):(f=null,n('"_"')),f===null&&(l.charCodeAt(e)===43?(f="+",e++):(f=null,n('"+"')),f===null&&(l.charCodeAt(e)===96?(f="`",e++):(f=null,n('"`"')),f===null&&(l.charCodeAt(e)===39?(f="'",e++):(f=null,n(`"'"`)),f===null&&(l.charCodeAt(e)===126?(f="~",e++):(f=null,n('"~"'))))))))))));else r=null;return r!==null&&(r=function(t){return l.substring(e,t)}(h)),r===null&&(e=h),r}function se(){var r,f,h;if(h=e,f=oe(),f===null&&(l.charCodeAt(e)===45?(f="-",e++):(f=null,n('"-"')),f===null&&(l.charCodeAt(e)===33?(f="!",e++):(f=null,n('"!"')),f===null&&(l.charCodeAt(e)===37?(f="%",e++):(f=null,n('"%"')),f===null&&(l.charCodeAt(e)===42?(f="*",e++):(f=null,n('"*"')),f===null&&(l.charCodeAt(e)===95?(f="_",e++):(f=null,n('"_"')),f===null&&(l.charCodeAt(e)===43?(f="+",e++):(f=null,n('"+"')),f===null&&(l.charCodeAt(e)===96?(f="`",e++):(f=null,n('"`"')),f===null&&(l.charCodeAt(e)===39?(f="'",e++):(f=null,n(`"'"`)),f===null&&(l.charCodeAt(e)===126?(f="~",e++):(f=null,n('"~"'))))))))))),f!==null)for(r=[];f!==null;)r.push(f),f=oe(),f===null&&(l.charCodeAt(e)===45?(f="-",e++):(f=null,n('"-"')),f===null&&(l.charCodeAt(e)===33?(f="!",e++):(f=null,n('"!"')),f===null&&(l.charCodeAt(e)===37?(f="%",e++):(f=null,n('"%"')),f===null&&(l.charCodeAt(e)===42?(f="*",e++):(f=null,n('"*"')),f===null&&(l.charCodeAt(e)===95?(f="_",e++):(f=null,n('"_"')),f===null&&(l.charCodeAt(e)===43?(f="+",e++):(f=null,n('"+"')),f===null&&(l.charCodeAt(e)===96?(f="`",e++):(f=null,n('"`"')),f===null&&(l.charCodeAt(e)===39?(f="'",e++):(f=null,n(`"'"`)),f===null&&(l.charCodeAt(e)===126?(f="~",e++):(f=null,n('"~"')))))))))));else r=null;return r!==null&&(r=function(t){return l.substring(e,t)}(h)),r===null&&(e=h),r}function It(){var r;return l.charCodeAt(e)===40?(r="(",e++):(r=null,n('"("')),r===null&&(l.charCodeAt(e)===41?(r=")",e++):(r=null,n('")"')),r===null&&(l.charCodeAt(e)===60?(r="<",e++):(r=null,n('"<"')),r===null&&(l.charCodeAt(e)===62?(r=">",e++):(r=null,n('">"')),r===null&&(l.charCodeAt(e)===64?(r="@",e++):(r=null,n('"@"')),r===null&&(l.charCodeAt(e)===44?(r=",",e++):(r=null,n('","')),r===null&&(l.charCodeAt(e)===59?(r=";",e++):(r=null,n('";"')),r===null&&(l.charCodeAt(e)===58?(r=":",e++):(r=null,n('":"')),r===null&&(l.charCodeAt(e)===92?(r="\\",e++):(r=null,n('"\\\\"')),r===null&&(r=I(),r===null&&(l.charCodeAt(e)===47?(r="/",e++):(r=null,n('"/"')),r===null&&(l.charCodeAt(e)===91?(r="[",e++):(r=null,n('"["')),r===null&&(l.charCodeAt(e)===93?(r="]",e++):(r=null,n('"]"')),r===null&&(l.charCodeAt(e)===63?(r="?",e++):(r=null,n('"?"')),r===null&&(l.charCodeAt(e)===61?(r="=",e++):(r=null,n('"="')),r===null&&(l.charCodeAt(e)===123?(r="{",e++):(r=null,n('"{"')),r===null&&(l.charCodeAt(e)===125?(r="}",e++):(r=null,n('"}"')),r===null&&(r=V(),r===null&&(r=W())))))))))))))))))),r}function N(){var r,f,h;if(h=e,f=oe(),f===null&&(l.charCodeAt(e)===45?(f="-",e++):(f=null,n('"-"')),f===null&&(l.charCodeAt(e)===46?(f=".",e++):(f=null,n('"."')),f===null&&(l.charCodeAt(e)===33?(f="!",e++):(f=null,n('"!"')),f===null&&(l.charCodeAt(e)===37?(f="%",e++):(f=null,n('"%"')),f===null&&(l.charCodeAt(e)===42?(f="*",e++):(f=null,n('"*"')),f===null&&(l.charCodeAt(e)===95?(f="_",e++):(f=null,n('"_"')),f===null&&(l.charCodeAt(e)===43?(f="+",e++):(f=null,n('"+"')),f===null&&(l.charCodeAt(e)===96?(f="`",e++):(f=null,n('"`"')),f===null&&(l.charCodeAt(e)===39?(f="'",e++):(f=null,n(`"'"`)),f===null&&(l.charCodeAt(e)===126?(f="~",e++):(f=null,n('"~"')),f===null&&(l.charCodeAt(e)===40?(f="(",e++):(f=null,n('"("')),f===null&&(l.charCodeAt(e)===41?(f=")",e++):(f=null,n('")"')),f===null&&(l.charCodeAt(e)===60?(f="<",e++):(f=null,n('"<"')),f===null&&(l.charCodeAt(e)===62?(f=">",e++):(f=null,n('">"')),f===null&&(l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f===null&&(l.charCodeAt(e)===92?(f="\\",e++):(f=null,n('"\\\\"')),f===null&&(f=I(),f===null&&(l.charCodeAt(e)===47?(f="/",e++):(f=null,n('"/"')),f===null&&(l.charCodeAt(e)===91?(f="[",e++):(f=null,n('"["')),f===null&&(l.charCodeAt(e)===93?(f="]",e++):(f=null,n('"]"')),f===null&&(l.charCodeAt(e)===63?(f="?",e++):(f=null,n('"?"')),f===null&&(l.charCodeAt(e)===123?(f="{",e++):(f=null,n('"{"')),f===null&&(l.charCodeAt(e)===125?(f="}",e++):(f=null,n('"}"'))))))))))))))))))))))))),f!==null)for(r=[];f!==null;)r.push(f),f=oe(),f===null&&(l.charCodeAt(e)===45?(f="-",e++):(f=null,n('"-"')),f===null&&(l.charCodeAt(e)===46?(f=".",e++):(f=null,n('"."')),f===null&&(l.charCodeAt(e)===33?(f="!",e++):(f=null,n('"!"')),f===null&&(l.charCodeAt(e)===37?(f="%",e++):(f=null,n('"%"')),f===null&&(l.charCodeAt(e)===42?(f="*",e++):(f=null,n('"*"')),f===null&&(l.charCodeAt(e)===95?(f="_",e++):(f=null,n('"_"')),f===null&&(l.charCodeAt(e)===43?(f="+",e++):(f=null,n('"+"')),f===null&&(l.charCodeAt(e)===96?(f="`",e++):(f=null,n('"`"')),f===null&&(l.charCodeAt(e)===39?(f="'",e++):(f=null,n(`"'"`)),f===null&&(l.charCodeAt(e)===126?(f="~",e++):(f=null,n('"~"')),f===null&&(l.charCodeAt(e)===40?(f="(",e++):(f=null,n('"("')),f===null&&(l.charCodeAt(e)===41?(f=")",e++):(f=null,n('")"')),f===null&&(l.charCodeAt(e)===60?(f="<",e++):(f=null,n('"<"')),f===null&&(l.charCodeAt(e)===62?(f=">",e++):(f=null,n('">"')),f===null&&(l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f===null&&(l.charCodeAt(e)===92?(f="\\",e++):(f=null,n('"\\\\"')),f===null&&(f=I(),f===null&&(l.charCodeAt(e)===47?(f="/",e++):(f=null,n('"/"')),f===null&&(l.charCodeAt(e)===91?(f="[",e++):(f=null,n('"["')),f===null&&(l.charCodeAt(e)===93?(f="]",e++):(f=null,n('"]"')),f===null&&(l.charCodeAt(e)===63?(f="?",e++):(f=null,n('"?"')),f===null&&(l.charCodeAt(e)===123?(f="{",e++):(f=null,n('"{"')),f===null&&(l.charCodeAt(e)===125?(f="}",e++):(f=null,n('"}"')))))))))))))))))))))))));else r=null;return r!==null&&(r=function(t){return l.substring(e,t)}(h)),r===null&&(e=h),r}function Y(){var r,f,h,t,o;return t=e,o=e,r=D(),r!==null?(l.charCodeAt(e)===42?(f="*",e++):(f=null,n('"*"')),f!==null?(h=D(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u){return"*"}()),r===null&&(e=t),r}function re(){var r,f,h,t,o;return t=e,o=e,r=D(),r!==null?(l.charCodeAt(e)===47?(f="/",e++):(f=null,n('"/"')),f!==null?(h=D(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u){return"/"}()),r===null&&(e=t),r}function ae(){var r,f,h,t,o;return t=e,o=e,r=D(),r!==null?(l.charCodeAt(e)===61?(f="=",e++):(f=null,n('"="')),f!==null?(h=D(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u){return"="}()),r===null&&(e=t),r}function Te(){var r,f,h,t,o;return t=e,o=e,r=D(),r!==null?(l.charCodeAt(e)===40?(f="(",e++):(f=null,n('"("')),f!==null?(h=D(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u){return"("}()),r===null&&(e=t),r}function De(){var r,f,h,t,o;return t=e,o=e,r=D(),r!==null?(l.charCodeAt(e)===41?(f=")",e++):(f=null,n('")"')),f!==null?(h=D(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u){return")"}()),r===null&&(e=t),r}function Ce(){var r,f,h,t;return h=e,t=e,l.charCodeAt(e)===62?(r=">",e++):(r=null,n('">"')),r!==null?(f=D(),f!==null?r=[r,f]:(r=null,e=t)):(r=null,e=t),r!==null&&(r=function(o){return">"}()),r===null&&(e=h),r}function Le(){var r,f,h,t;return h=e,t=e,r=D(),r!==null?(l.charCodeAt(e)===60?(f="<",e++):(f=null,n('"<"')),f!==null?r=[r,f]:(r=null,e=t)):(r=null,e=t),r!==null&&(r=function(o){return"<"}()),r===null&&(e=h),r}function we(){var r,f,h,t,o;return t=e,o=e,r=D(),r!==null?(l.charCodeAt(e)===44?(f=",",e++):(f=null,n('","')),f!==null?(h=D(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u){return","}()),r===null&&(e=t),r}function Se(){var r,f,h,t,o;return t=e,o=e,r=D(),r!==null?(l.charCodeAt(e)===59?(f=";",e++):(f=null,n('";"')),f!==null?(h=D(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u){return";"}()),r===null&&(e=t),r}function it(){var r,f,h,t,o;return t=e,o=e,r=D(),r!==null?(l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f!==null?(h=D(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u){return":"}()),r===null&&(e=t),r}function Ue(){var r,f,h,t;return h=e,t=e,r=D(),r!==null?(f=I(),f!==null?r=[r,f]:(r=null,e=t)):(r=null,e=t),r!==null&&(r=function(o){return'"'}()),r===null&&(e=h),r}function le(){var r,f,h,t;return h=e,t=e,r=I(),r!==null?(f=D(),f!==null?r=[r,f]:(r=null,e=t)):(r=null,e=t),r!==null&&(r=function(o){return'"'}()),r===null&&(e=h),r}function Ae(){var r,f,h,t;if(t=e,r=Te(),r!==null){for(f=[],h=Oe(),h===null&&(h=pe(),h===null&&(h=Ae()));h!==null;)f.push(h),h=Oe(),h===null&&(h=pe(),h===null&&(h=Ae()));f!==null?(h=De(),h!==null?r=[r,f,h]:(r=null,e=t)):(r=null,e=t)}else r=null,e=t;return r}function Oe(){var r;return/^[!-']/.test(l.charAt(e))?(r=l.charAt(e),e++):(r=null,n("[!-']")),r===null&&(/^[*-[]/.test(l.charAt(e))?(r=l.charAt(e),e++):(r=null,n("[*-[]")),r===null&&(/^[\]-~]/.test(l.charAt(e))?(r=l.charAt(e),e++):(r=null,n("[\\]-~]")),r===null&&(r=B(),r===null&&(r=H())))),r}function Pe(){var r,f,h,t,o,u;if(o=e,u=e,r=D(),r!==null)if(f=I(),f!==null){for(h=[],t=he(),t===null&&(t=pe());t!==null;)h.push(t),t=he(),t===null&&(t=pe());h!==null?(t=I(),t!==null?r=[r,f,h,t]:(r=null,e=u)):(r=null,e=u)}else r=null,e=u;else r=null,e=u;return r!==null&&(r=function(d){return l.substring(e,d)}(o)),r===null&&(e=o),r}function ve(){var r,f,h,t,o,u;if(o=e,u=e,r=D(),r!==null)if(f=I(),f!==null){for(h=[],t=he(),t===null&&(t=pe());t!==null;)h.push(t),t=he(),t===null&&(t=pe());h!==null?(t=I(),t!==null?r=[r,f,h,t]:(r=null,e=u)):(r=null,e=u)}else r=null,e=u;else r=null,e=u;return r!==null&&(r=function(d){var T=l.substring(e,d).trim();return T.substring(1,T.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(o)),r===null&&(e=o),r}function he(){var r;return r=H(),r===null&&(l.charCodeAt(e)===33?(r="!",e++):(r=null,n('"!"')),r===null&&(/^[#-[]/.test(l.charAt(e))?(r=l.charAt(e),e++):(r=null,n("[#-[]")),r===null&&(/^[\]-~]/.test(l.charAt(e))?(r=l.charAt(e),e++):(r=null,n("[\\]-~]")),r===null&&(r=B())))),r}function pe(){var r,f,h;return h=e,l.charCodeAt(e)===92?(r="\\",e++):(r=null,n('"\\\\"')),r!==null?(/^[\0-\t]/.test(l.charAt(e))?(f=l.charAt(e),e++):(f=null,n("[\\0-\\t]")),f===null&&(/^[\x0B-\f]/.test(l.charAt(e))?(f=l.charAt(e),e++):(f=null,n("[\\x0B-\\f]")),f===null&&(/^[\x0E-]/.test(l.charAt(e))?(f=l.charAt(e),e++):(f=null,n("[\\x0E-]")))),f!==null?r=[r,f]:(r=null,e=h)):(r=null,e=h),r}function Ne(){var r,f,h,t,o,u;return o=e,u=e,r=Ve(),r!==null?(l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f!==null?(h=ct(),h=h!==null?h:"",h!==null?(t=nn(),t!==null?r=[r,f,h,t]:(r=null,e=u)):(r=null,e=u)):(r=null,e=u)):(r=null,e=u),r!==null&&(r=function(d){try{b.uri=new Ri(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}}()),r===null&&(e=o),r}function xe(){var r,f,h,t,o,u,d,T;return d=e,T=e,r=Ve(),r!==null?(l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f!==null?(h=ct(),h=h!==null?h:"",h!==null?(t=nn(),t!==null?(o=Ds(),o!==null?(u=yr(),u=u!==null?u:"",u!==null?r=[r,f,h,t,o,u]:(r=null,e=T)):(r=null,e=T)):(r=null,e=T)):(r=null,e=T)):(r=null,e=T)):(r=null,e=T),r!==null&&(r=function(E){try{b.uri=new Ri(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}}()),r===null&&(e=d),r}function Ve(){var r;return r=He(),r===null&&(r=Ht()),r}function He(){var r,f;return f=e,l.substr(e,4).toLowerCase()==="sips"?(r=l.substr(e,4),e+=4):(r=null,n('"sips"')),r!==null&&(r=function(h,t){b.scheme=t.toLowerCase()}(f,r)),r===null&&(e=f),r}function Ht(){var r,f;return f=e,l.substr(e,3).toLowerCase()==="sip"?(r=l.substr(e,3),e+=3):(r=null,n('"sip"')),r!==null&&(r=function(h,t){b.scheme=t.toLowerCase()}(f,r)),r===null&&(e=f),r}function ct(){var r,f,h,t,o,u;return t=e,o=e,r=_r(),r!==null?(u=e,l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f!==null?(h=sn(),h!==null?f=[f,h]:(f=null,e=u)):(f=null,e=u),f=f!==null?f:"",f!==null?(l.charCodeAt(e)===64?(h="@",e++):(h=null,n('"@"')),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(d){b.user=decodeURIComponent(l.substring(e-1,d))}(t)),r===null&&(e=t),r}function _r(){var r,f;if(f=$(),f===null&&(f=Ie(),f===null&&(f=Mn())),f!==null)for(r=[];f!==null;)r.push(f),f=$(),f===null&&(f=Ie(),f===null&&(f=Mn()));else r=null;return r}function Mn(){var r;return l.charCodeAt(e)===38?(r="&",e++):(r=null,n('"&"')),r===null&&(l.charCodeAt(e)===61?(r="=",e++):(r=null,n('"="')),r===null&&(l.charCodeAt(e)===43?(r="+",e++):(r=null,n('"+"')),r===null&&(l.charCodeAt(e)===36?(r="$",e++):(r=null,n('"$"')),r===null&&(l.charCodeAt(e)===44?(r=",",e++):(r=null,n('","')),r===null&&(l.charCodeAt(e)===59?(r=";",e++):(r=null,n('";"')),r===null&&(l.charCodeAt(e)===63?(r="?",e++):(r=null,n('"?"')),r===null&&(l.charCodeAt(e)===47?(r="/",e++):(r=null,n('"/"'))))))))),r}function sn(){var r,f,h;for(h=e,r=[],f=$(),f===null&&(f=Ie(),f===null&&(l.charCodeAt(e)===38?(f="&",e++):(f=null,n('"&"')),f===null&&(l.charCodeAt(e)===61?(f="=",e++):(f=null,n('"="')),f===null&&(l.charCodeAt(e)===43?(f="+",e++):(f=null,n('"+"')),f===null&&(l.charCodeAt(e)===36?(f="$",e++):(f=null,n('"$"')),f===null&&(l.charCodeAt(e)===44?(f=",",e++):(f=null,n('","'))))))));f!==null;)r.push(f),f=$(),f===null&&(f=Ie(),f===null&&(l.charCodeAt(e)===38?(f="&",e++):(f=null,n('"&"')),f===null&&(l.charCodeAt(e)===61?(f="=",e++):(f=null,n('"="')),f===null&&(l.charCodeAt(e)===43?(f="+",e++):(f=null,n('"+"')),f===null&&(l.charCodeAt(e)===36?(f="$",e++):(f=null,n('"$"')),f===null&&(l.charCodeAt(e)===44?(f=",",e++):(f=null,n('","'))))))));return r!==null&&(r=function(t){b.password=l.substring(e,t)}(h)),r===null&&(e=h),r}function nn(){var r,f,h,t,o;return t=e,r=cs(),r!==null?(o=e,l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f!==null?(h=bt(),h!==null?f=[f,h]:(f=null,e=o)):(f=null,e=o),f=f!==null?f:"",f!==null?r=[r,f]:(r=null,e=t)):(r=null,e=t),r}function cs(){var r,f;return f=e,r=kn(),r===null&&(r=fs(),r===null&&(r=rn())),r!==null&&(r=function(h){return b.host=l.substring(e,h).toLowerCase(),b.host}(f)),r===null&&(e=f),r}function kn(){var r,f,h,t,o,u;for(t=e,o=e,r=[],u=e,f=ws(),f!==null?(l.charCodeAt(e)===46?(h=".",e++):(h=null,n('"."')),h!==null?f=[f,h]:(f=null,e=u)):(f=null,e=u);f!==null;)r.push(f),u=e,f=ws(),f!==null?(l.charCodeAt(e)===46?(h=".",e++):(h=null,n('"."')),h!==null?f=[f,h]:(f=null,e=u)):(f=null,e=u);return r!==null?(f=Os(),f!==null?(l.charCodeAt(e)===46?(h=".",e++):(h=null,n('"."')),h=h!==null?h:"",h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(d){return b.host_type="domain",l.substring(e,d)}(t)),r===null&&(e=t),r}function ws(){var r,f,h,t;if(t=e,r=oe(),r!==null){for(f=[],h=oe(),h===null&&(l.charCodeAt(e)===45?(h="-",e++):(h=null,n('"-"')),h===null&&(l.charCodeAt(e)===95?(h="_",e++):(h=null,n('"_"'))));h!==null;)f.push(h),h=oe(),h===null&&(l.charCodeAt(e)===45?(h="-",e++):(h=null,n('"-"')),h===null&&(l.charCodeAt(e)===95?(h="_",e++):(h=null,n('"_"'))));f!==null?r=[r,f]:(r=null,e=t)}else r=null,e=t;return r}function Os(){var r,f,h,t;if(t=e,r=m(),r!==null){for(f=[],h=oe(),h===null&&(l.charCodeAt(e)===45?(h="-",e++):(h=null,n('"-"')),h===null&&(l.charCodeAt(e)===95?(h="_",e++):(h=null,n('"_"'))));h!==null;)f.push(h),h=oe(),h===null&&(l.charCodeAt(e)===45?(h="-",e++):(h=null,n('"-"')),h===null&&(l.charCodeAt(e)===95?(h="_",e++):(h=null,n('"_"'))));f!==null?r=[r,f]:(r=null,e=t)}else r=null,e=t;return r}function rn(){var r,f,h,t,o;return t=e,o=e,l.charCodeAt(e)===91?(r="[",e++):(r=null,n('"["')),r!==null?(f=ln(),f!==null?(l.charCodeAt(e)===93?(h="]",e++):(h=null,n('"]"')),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u){return b.host_type="IPv6",l.substring(e,u)}(t)),r===null&&(e=t),r}function ln(){var r,f,h,t,o,u,d,T,E,y,O,G,ye,Fe,P,me;return Fe=e,P=e,r=ge(),r!==null?(l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f!==null?(h=ge(),h!==null?(l.charCodeAt(e)===58?(t=":",e++):(t=null,n('":"')),t!==null?(o=ge(),o!==null?(l.charCodeAt(e)===58?(u=":",e++):(u=null,n('":"')),u!==null?(d=ge(),d!==null?(l.charCodeAt(e)===58?(T=":",e++):(T=null,n('":"')),T!==null?(E=ge(),E!==null?(l.charCodeAt(e)===58?(y=":",e++):(y=null,n('":"')),y!==null?(O=ge(),O!==null?(l.charCodeAt(e)===58?(G=":",e++):(G=null,n('":"')),G!==null?(ye=pt(),ye!==null?r=[r,f,h,t,o,u,d,T,E,y,O,G,ye]:(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P),r===null&&(P=e,l.substr(e,2)==="::"?(r="::",e+=2):(r=null,n('"::"')),r!==null?(f=ge(),f!==null?(l.charCodeAt(e)===58?(h=":",e++):(h=null,n('":"')),h!==null?(t=ge(),t!==null?(l.charCodeAt(e)===58?(o=":",e++):(o=null,n('":"')),o!==null?(u=ge(),u!==null?(l.charCodeAt(e)===58?(d=":",e++):(d=null,n('":"')),d!==null?(T=ge(),T!==null?(l.charCodeAt(e)===58?(E=":",e++):(E=null,n('":"')),E!==null?(y=ge(),y!==null?(l.charCodeAt(e)===58?(O=":",e++):(O=null,n('":"')),O!==null?(G=pt(),G!==null?r=[r,f,h,t,o,u,d,T,E,y,O,G]:(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P),r===null&&(P=e,l.substr(e,2)==="::"?(r="::",e+=2):(r=null,n('"::"')),r!==null?(f=ge(),f!==null?(l.charCodeAt(e)===58?(h=":",e++):(h=null,n('":"')),h!==null?(t=ge(),t!==null?(l.charCodeAt(e)===58?(o=":",e++):(o=null,n('":"')),o!==null?(u=ge(),u!==null?(l.charCodeAt(e)===58?(d=":",e++):(d=null,n('":"')),d!==null?(T=ge(),T!==null?(l.charCodeAt(e)===58?(E=":",e++):(E=null,n('":"')),E!==null?(y=pt(),y!==null?r=[r,f,h,t,o,u,d,T,E,y]:(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P),r===null&&(P=e,l.substr(e,2)==="::"?(r="::",e+=2):(r=null,n('"::"')),r!==null?(f=ge(),f!==null?(l.charCodeAt(e)===58?(h=":",e++):(h=null,n('":"')),h!==null?(t=ge(),t!==null?(l.charCodeAt(e)===58?(o=":",e++):(o=null,n('":"')),o!==null?(u=ge(),u!==null?(l.charCodeAt(e)===58?(d=":",e++):(d=null,n('":"')),d!==null?(T=pt(),T!==null?r=[r,f,h,t,o,u,d,T]:(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P),r===null&&(P=e,l.substr(e,2)==="::"?(r="::",e+=2):(r=null,n('"::"')),r!==null?(f=ge(),f!==null?(l.charCodeAt(e)===58?(h=":",e++):(h=null,n('":"')),h!==null?(t=ge(),t!==null?(l.charCodeAt(e)===58?(o=":",e++):(o=null,n('":"')),o!==null?(u=pt(),u!==null?r=[r,f,h,t,o,u]:(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P),r===null&&(P=e,l.substr(e,2)==="::"?(r="::",e+=2):(r=null,n('"::"')),r!==null?(f=ge(),f!==null?(l.charCodeAt(e)===58?(h=":",e++):(h=null,n('":"')),h!==null?(t=pt(),t!==null?r=[r,f,h,t]:(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P),r===null&&(P=e,l.substr(e,2)==="::"?(r="::",e+=2):(r=null,n('"::"')),r!==null?(f=pt(),f!==null?r=[r,f]:(r=null,e=P)):(r=null,e=P),r===null&&(P=e,l.substr(e,2)==="::"?(r="::",e+=2):(r=null,n('"::"')),r!==null?(f=ge(),f!==null?r=[r,f]:(r=null,e=P)):(r=null,e=P),r===null&&(P=e,r=ge(),r!==null?(l.substr(e,2)==="::"?(f="::",e+=2):(f=null,n('"::"')),f!==null?(h=ge(),h!==null?(l.charCodeAt(e)===58?(t=":",e++):(t=null,n('":"')),t!==null?(o=ge(),o!==null?(l.charCodeAt(e)===58?(u=":",e++):(u=null,n('":"')),u!==null?(d=ge(),d!==null?(l.charCodeAt(e)===58?(T=":",e++):(T=null,n('":"')),T!==null?(E=ge(),E!==null?(l.charCodeAt(e)===58?(y=":",e++):(y=null,n('":"')),y!==null?(O=pt(),O!==null?r=[r,f,h,t,o,u,d,T,E,y,O]:(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P),r===null&&(P=e,r=ge(),r!==null?(me=e,l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f!==null?(h=ge(),h!==null?f=[f,h]:(f=null,e=me)):(f=null,e=me),f=f!==null?f:"",f!==null?(l.substr(e,2)==="::"?(h="::",e+=2):(h=null,n('"::"')),h!==null?(t=ge(),t!==null?(l.charCodeAt(e)===58?(o=":",e++):(o=null,n('":"')),o!==null?(u=ge(),u!==null?(l.charCodeAt(e)===58?(d=":",e++):(d=null,n('":"')),d!==null?(T=ge(),T!==null?(l.charCodeAt(e)===58?(E=":",e++):(E=null,n('":"')),E!==null?(y=pt(),y!==null?r=[r,f,h,t,o,u,d,T,E,y]:(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P),r===null&&(P=e,r=ge(),r!==null?(me=e,l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f!==null?(h=ge(),h!==null?f=[f,h]:(f=null,e=me)):(f=null,e=me),f=f!==null?f:"",f!==null?(me=e,l.charCodeAt(e)===58?(h=":",e++):(h=null,n('":"')),h!==null?(t=ge(),t!==null?h=[h,t]:(h=null,e=me)):(h=null,e=me),h=h!==null?h:"",h!==null?(l.substr(e,2)==="::"?(t="::",e+=2):(t=null,n('"::"')),t!==null?(o=ge(),o!==null?(l.charCodeAt(e)===58?(u=":",e++):(u=null,n('":"')),u!==null?(d=ge(),d!==null?(l.charCodeAt(e)===58?(T=":",e++):(T=null,n('":"')),T!==null?(E=pt(),E!==null?r=[r,f,h,t,o,u,d,T,E]:(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P),r===null&&(P=e,r=ge(),r!==null?(me=e,l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f!==null?(h=ge(),h!==null?f=[f,h]:(f=null,e=me)):(f=null,e=me),f=f!==null?f:"",f!==null?(me=e,l.charCodeAt(e)===58?(h=":",e++):(h=null,n('":"')),h!==null?(t=ge(),t!==null?h=[h,t]:(h=null,e=me)):(h=null,e=me),h=h!==null?h:"",h!==null?(me=e,l.charCodeAt(e)===58?(t=":",e++):(t=null,n('":"')),t!==null?(o=ge(),o!==null?t=[t,o]:(t=null,e=me)):(t=null,e=me),t=t!==null?t:"",t!==null?(l.substr(e,2)==="::"?(o="::",e+=2):(o=null,n('"::"')),o!==null?(u=ge(),u!==null?(l.charCodeAt(e)===58?(d=":",e++):(d=null,n('":"')),d!==null?(T=pt(),T!==null?r=[r,f,h,t,o,u,d,T]:(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P),r===null&&(P=e,r=ge(),r!==null?(me=e,l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f!==null?(h=ge(),h!==null?f=[f,h]:(f=null,e=me)):(f=null,e=me),f=f!==null?f:"",f!==null?(me=e,l.charCodeAt(e)===58?(h=":",e++):(h=null,n('":"')),h!==null?(t=ge(),t!==null?h=[h,t]:(h=null,e=me)):(h=null,e=me),h=h!==null?h:"",h!==null?(me=e,l.charCodeAt(e)===58?(t=":",e++):(t=null,n('":"')),t!==null?(o=ge(),o!==null?t=[t,o]:(t=null,e=me)):(t=null,e=me),t=t!==null?t:"",t!==null?(me=e,l.charCodeAt(e)===58?(o=":",e++):(o=null,n('":"')),o!==null?(u=ge(),u!==null?o=[o,u]:(o=null,e=me)):(o=null,e=me),o=o!==null?o:"",o!==null?(l.substr(e,2)==="::"?(u="::",e+=2):(u=null,n('"::"')),u!==null?(d=pt(),d!==null?r=[r,f,h,t,o,u,d]:(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P),r===null&&(P=e,r=ge(),r!==null?(me=e,l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f!==null?(h=ge(),h!==null?f=[f,h]:(f=null,e=me)):(f=null,e=me),f=f!==null?f:"",f!==null?(me=e,l.charCodeAt(e)===58?(h=":",e++):(h=null,n('":"')),h!==null?(t=ge(),t!==null?h=[h,t]:(h=null,e=me)):(h=null,e=me),h=h!==null?h:"",h!==null?(me=e,l.charCodeAt(e)===58?(t=":",e++):(t=null,n('":"')),t!==null?(o=ge(),o!==null?t=[t,o]:(t=null,e=me)):(t=null,e=me),t=t!==null?t:"",t!==null?(me=e,l.charCodeAt(e)===58?(o=":",e++):(o=null,n('":"')),o!==null?(u=ge(),u!==null?o=[o,u]:(o=null,e=me)):(o=null,e=me),o=o!==null?o:"",o!==null?(me=e,l.charCodeAt(e)===58?(u=":",e++):(u=null,n('":"')),u!==null?(d=ge(),d!==null?u=[u,d]:(u=null,e=me)):(u=null,e=me),u=u!==null?u:"",u!==null?(l.substr(e,2)==="::"?(d="::",e+=2):(d=null,n('"::"')),d!==null?(T=ge(),T!==null?r=[r,f,h,t,o,u,d,T]:(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P),r===null&&(P=e,r=ge(),r!==null?(me=e,l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f!==null?(h=ge(),h!==null?f=[f,h]:(f=null,e=me)):(f=null,e=me),f=f!==null?f:"",f!==null?(me=e,l.charCodeAt(e)===58?(h=":",e++):(h=null,n('":"')),h!==null?(t=ge(),t!==null?h=[h,t]:(h=null,e=me)):(h=null,e=me),h=h!==null?h:"",h!==null?(me=e,l.charCodeAt(e)===58?(t=":",e++):(t=null,n('":"')),t!==null?(o=ge(),o!==null?t=[t,o]:(t=null,e=me)):(t=null,e=me),t=t!==null?t:"",t!==null?(me=e,l.charCodeAt(e)===58?(o=":",e++):(o=null,n('":"')),o!==null?(u=ge(),u!==null?o=[o,u]:(o=null,e=me)):(o=null,e=me),o=o!==null?o:"",o!==null?(me=e,l.charCodeAt(e)===58?(u=":",e++):(u=null,n('":"')),u!==null?(d=ge(),d!==null?u=[u,d]:(u=null,e=me)):(u=null,e=me),u=u!==null?u:"",u!==null?(me=e,l.charCodeAt(e)===58?(d=":",e++):(d=null,n('":"')),d!==null?(T=ge(),T!==null?d=[d,T]:(d=null,e=me)):(d=null,e=me),d=d!==null?d:"",d!==null?(l.substr(e,2)==="::"?(T="::",e+=2):(T=null,n('"::"')),T!==null?r=[r,f,h,t,o,u,d,T]:(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P)):(r=null,e=P))))))))))))))),r!==null&&(r=function(Ii){return b.host_type="IPv6",l.substring(e,Ii)}(Fe)),r===null&&(e=Fe),r}function ge(){var r,f,h,t,o;return o=e,r=C(),r!==null?(f=C(),f=f!==null?f:"",f!==null?(h=C(),h=h!==null?h:"",h!==null?(t=C(),t=t!==null?t:"",t!==null?r=[r,f,h,t]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r}function pt(){var r,f,h,t;return t=e,r=ge(),r!==null?(l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f!==null?(h=ge(),h!==null?r=[r,f,h]:(r=null,e=t)):(r=null,e=t)):(r=null,e=t),r===null&&(r=fs()),r}function fs(){var r,f,h,t,o,u,d,T,E;return T=e,E=e,r=de(),r!==null?(l.charCodeAt(e)===46?(f=".",e++):(f=null,n('"."')),f!==null?(h=de(),h!==null?(l.charCodeAt(e)===46?(t=".",e++):(t=null,n('"."')),t!==null?(o=de(),o!==null?(l.charCodeAt(e)===46?(u=".",e++):(u=null,n('"."')),u!==null?(d=de(),d!==null?r=[r,f,h,t,o,u,d]:(r=null,e=E)):(r=null,e=E)):(r=null,e=E)):(r=null,e=E)):(r=null,e=E)):(r=null,e=E)):(r=null,e=E),r!==null&&(r=function(y){return b.host_type="IPv4",l.substring(e,y)}(T)),r===null&&(e=T),r}function de(){var r,f,h,t;return t=e,l.substr(e,2)==="25"?(r="25",e+=2):(r=null,n('"25"')),r!==null?(/^[0-5]/.test(l.charAt(e))?(f=l.charAt(e),e++):(f=null,n("[0-5]")),f!==null?r=[r,f]:(r=null,e=t)):(r=null,e=t),r===null&&(t=e,l.charCodeAt(e)===50?(r="2",e++):(r=null,n('"2"')),r!==null?(/^[0-4]/.test(l.charAt(e))?(f=l.charAt(e),e++):(f=null,n("[0-4]")),f!==null?(h=S(),h!==null?r=[r,f,h]:(r=null,e=t)):(r=null,e=t)):(r=null,e=t),r===null&&(t=e,l.charCodeAt(e)===49?(r="1",e++):(r=null,n('"1"')),r!==null?(f=S(),f!==null?(h=S(),h!==null?r=[r,f,h]:(r=null,e=t)):(r=null,e=t)):(r=null,e=t),r===null&&(t=e,/^[1-9]/.test(l.charAt(e))?(r=l.charAt(e),e++):(r=null,n("[1-9]")),r!==null?(f=S(),f!==null?r=[r,f]:(r=null,e=t)):(r=null,e=t),r===null&&(r=S())))),r}function bt(){var r,f,h,t,o,u,d;return u=e,d=e,r=S(),r=r!==null?r:"",r!==null?(f=S(),f=f!==null?f:"",f!==null?(h=S(),h=h!==null?h:"",h!==null?(t=S(),t=t!==null?t:"",t!==null?(o=S(),o=o!==null?o:"",o!==null?r=[r,f,h,t,o]:(r=null,e=d)):(r=null,e=d)):(r=null,e=d)):(r=null,e=d)):(r=null,e=d),r!==null&&(r=function(T,E){return E=parseInt(E.join("")),b.port=E,E}(u,r)),r===null&&(e=u),r}function Ds(){var r,f,h,t;for(r=[],t=e,l.charCodeAt(e)===59?(f=";",e++):(f=null,n('";"')),f!==null?(h=_s(),h!==null?f=[f,h]:(f=null,e=t)):(f=null,e=t);f!==null;)r.push(f),t=e,l.charCodeAt(e)===59?(f=";",e++):(f=null,n('";"')),f!==null?(h=_s(),h!==null?f=[f,h]:(f=null,e=t)):(f=null,e=t);return r}function _s(){var r;return r=hr(),r===null&&(r=dr(),r===null&&(r=Ln(),r===null&&(r=pr(),r===null&&(r=mr(),r===null&&(r=gr(),r===null&&(r=Tr())))))),r}function hr(){var r,f,h,t;return h=e,t=e,l.substr(e,10).toLowerCase()==="transport="?(r=l.substr(e,10),e+=10):(r=null,n('"transport="')),r!==null?(l.substr(e,3).toLowerCase()==="udp"?(f=l.substr(e,3),e+=3):(f=null,n('"udp"')),f===null&&(l.substr(e,3).toLowerCase()==="tcp"?(f=l.substr(e,3),e+=3):(f=null,n('"tcp"')),f===null&&(l.substr(e,4).toLowerCase()==="sctp"?(f=l.substr(e,4),e+=4):(f=null,n('"sctp"')),f===null&&(l.substr(e,3).toLowerCase()==="tls"?(f=l.substr(e,3),e+=3):(f=null,n('"tls"')),f===null&&(f=U())))),f!==null?r=[r,f]:(r=null,e=t)):(r=null,e=t),r!==null&&(r=function(o,u){b.uri_params||(b.uri_params={}),b.uri_params.transport=u.toLowerCase()}(h,r[1])),r===null&&(e=h),r}function dr(){var r,f,h,t;return h=e,t=e,l.substr(e,5).toLowerCase()==="user="?(r=l.substr(e,5),e+=5):(r=null,n('"user="')),r!==null?(l.substr(e,5).toLowerCase()==="phone"?(f=l.substr(e,5),e+=5):(f=null,n('"phone"')),f===null&&(l.substr(e,2).toLowerCase()==="ip"?(f=l.substr(e,2),e+=2):(f=null,n('"ip"')),f===null&&(f=U())),f!==null?r=[r,f]:(r=null,e=t)):(r=null,e=t),r!==null&&(r=function(o,u){b.uri_params||(b.uri_params={}),b.uri_params.user=u.toLowerCase()}(h,r[1])),r===null&&(e=h),r}function Ln(){var r,f,h,t;return h=e,t=e,l.substr(e,7).toLowerCase()==="method="?(r=l.substr(e,7),e+=7):(r=null,n('"method="')),r!==null?(f=un(),f!==null?r=[r,f]:(r=null,e=t)):(r=null,e=t),r!==null&&(r=function(o,u){b.uri_params||(b.uri_params={}),b.uri_params.method=u}(h,r[1])),r===null&&(e=h),r}function pr(){var r,f,h,t;return h=e,t=e,l.substr(e,4).toLowerCase()==="ttl="?(r=l.substr(e,4),e+=4):(r=null,n('"ttl="')),r!==null?(f=Yn(),f!==null?r=[r,f]:(r=null,e=t)):(r=null,e=t),r!==null&&(r=function(o,u){b.params||(b.params={}),b.params.ttl=u}(h,r[1])),r===null&&(e=h),r}function mr(){var r,f,h,t;return h=e,t=e,l.substr(e,6).toLowerCase()==="maddr="?(r=l.substr(e,6),e+=6):(r=null,n('"maddr="')),r!==null?(f=cs(),f!==null?r=[r,f]:(r=null,e=t)):(r=null,e=t),r!==null&&(r=function(o,u){b.uri_params||(b.uri_params={}),b.uri_params.maddr=u}(h,r[1])),r===null&&(e=h),r}function gr(){var r,f,h,t,o,u;return t=e,o=e,l.substr(e,2).toLowerCase()==="lr"?(r=l.substr(e,2),e+=2):(r=null,n('"lr"')),r!==null?(u=e,l.charCodeAt(e)===61?(f="=",e++):(f=null,n('"="')),f!==null?(h=U(),h!==null?f=[f,h]:(f=null,e=u)):(f=null,e=u),f=f!==null?f:"",f!==null?r=[r,f]:(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(d){b.uri_params||(b.uri_params={}),b.uri_params.lr=void 0}()),r===null&&(e=t),r}function Tr(){var r,f,h,t,o,u;return t=e,o=e,r=vr(),r!==null?(u=e,l.charCodeAt(e)===61?(f="=",e++):(f=null,n('"="')),f!==null?(h=Er(),h!==null?f=[f,h]:(f=null,e=u)):(f=null,e=u),f=f!==null?f:"",f!==null?r=[r,f]:(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(d,T,E){b.uri_params||(b.uri_params={}),typeof E>"u"?E=void 0:E=E[1],b.uri_params[T.toLowerCase()]=E}(t,r[0],r[1])),r===null&&(e=t),r}function vr(){var r,f,h;if(h=e,f=Ns(),f!==null)for(r=[];f!==null;)r.push(f),f=Ns();else r=null;return r!==null&&(r=function(t,o){return o.join("")}(h,r)),r===null&&(e=h),r}function Er(){var r,f,h;if(h=e,f=Ns(),f!==null)for(r=[];f!==null;)r.push(f),f=Ns();else r=null;return r!==null&&(r=function(t,o){return o.join("")}(h,r)),r===null&&(e=h),r}function Ns(){var r;return r=Sr(),r===null&&(r=$(),r===null&&(r=Ie())),r}function Sr(){var r;return l.charCodeAt(e)===91?(r="[",e++):(r=null,n('"["')),r===null&&(l.charCodeAt(e)===93?(r="]",e++):(r=null,n('"]"')),r===null&&(l.charCodeAt(e)===47?(r="/",e++):(r=null,n('"/"')),r===null&&(l.charCodeAt(e)===58?(r=":",e++):(r=null,n('":"')),r===null&&(l.charCodeAt(e)===38?(r="&",e++):(r=null,n('"&"')),r===null&&(l.charCodeAt(e)===43?(r="+",e++):(r=null,n('"+"')),r===null&&(l.charCodeAt(e)===36?(r="$",e++):(r=null,n('"$"')))))))),r}function yr(){var r,f,h,t,o,u,d;if(u=e,l.charCodeAt(e)===63?(r="?",e++):(r=null,n('"?"')),r!==null)if(f=Zt(),f!==null){for(h=[],d=e,l.charCodeAt(e)===38?(t="&",e++):(t=null,n('"&"')),t!==null?(o=Zt(),o!==null?t=[t,o]:(t=null,e=d)):(t=null,e=d);t!==null;)h.push(t),d=e,l.charCodeAt(e)===38?(t="&",e++):(t=null,n('"&"')),t!==null?(o=Zt(),o!==null?t=[t,o]:(t=null,e=d)):(t=null,e=d);h!==null?r=[r,f,h]:(r=null,e=u)}else r=null,e=u;else r=null,e=u;return r}function Zt(){var r,f,h,t,o;return t=e,o=e,r=Ar(),r!==null?(l.charCodeAt(e)===61?(f="=",e++):(f=null,n('"="')),f!==null?(h=Cr(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u,d,T){d=d.join("").toLowerCase(),T=T.join(""),b.uri_headers||(b.uri_headers={}),b.uri_headers[d]?b.uri_headers[d].push(T):b.uri_headers[d]=[T]}(t,r[0],r[2])),r===null&&(e=t),r}function Ar(){var r,f;if(f=es(),f===null&&(f=$(),f===null&&(f=Ie())),f!==null)for(r=[];f!==null;)r.push(f),f=es(),f===null&&(f=$(),f===null&&(f=Ie()));else r=null;return r}function Cr(){var r,f;for(r=[],f=es(),f===null&&(f=$(),f===null&&(f=Ie()));f!==null;)r.push(f),f=es(),f===null&&(f=$(),f===null&&(f=Ie()));return r}function es(){var r;return l.charCodeAt(e)===91?(r="[",e++):(r=null,n('"["')),r===null&&(l.charCodeAt(e)===93?(r="]",e++):(r=null,n('"]"')),r===null&&(l.charCodeAt(e)===47?(r="/",e++):(r=null,n('"/"')),r===null&&(l.charCodeAt(e)===63?(r="?",e++):(r=null,n('"?"')),r===null&&(l.charCodeAt(e)===58?(r=":",e++):(r=null,n('":"')),r===null&&(l.charCodeAt(e)===43?(r="+",e++):(r=null,n('"+"')),r===null&&(l.charCodeAt(e)===36?(r="$",e++):(r=null,n('"$"')))))))),r}function hl(){var r;return r=jr(),r===null&&(r=Rr()),r}function Rr(){var r,f,h,t,o,u;return u=e,r=un(),r!==null?(f=V(),f!==null?(h=Us(),h!==null?(t=V(),t!==null?(o=Fn(),o!==null?r=[r,f,h,t,o]:(r=null,e=u)):(r=null,e=u)):(r=null,e=u)):(r=null,e=u)):(r=null,e=u),r}function Us(){var r;return r=xe(),r===null&&(r=Ir()),r}function Ir(){var r,f,h,t;return t=e,r=on(),r!==null?(l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f!==null?(h=br(),h===null&&(h=Or()),h!==null?r=[r,f,h]:(r=null,e=t)):(r=null,e=t)):(r=null,e=t),r}function br(){var r,f,h,t,o;return t=e,r=wr(),r===null&&(r=Ps()),r!==null?(o=e,l.charCodeAt(e)===63?(f="?",e++):(f=null,n('"?"')),f!==null?(h=Ur(),h!==null?f=[f,h]:(f=null,e=o)):(f=null,e=o),f=f!==null?f:"",f!==null?r=[r,f]:(r=null,e=t)):(r=null,e=t),r}function wr(){var r,f,h,t;return t=e,l.substr(e,2)==="//"?(r="//",e+=2):(r=null,n('"//"')),r!==null?(f=Hn(),f!==null?(h=Ps(),h=h!==null?h:"",h!==null?r=[r,f,h]:(r=null,e=t)):(r=null,e=t)):(r=null,e=t),r}function Ps(){var r,f,h;return h=e,l.charCodeAt(e)===47?(r="/",e++):(r=null,n('"/"')),r!==null?(f=Dr(),f!==null?r=[r,f]:(r=null,e=h)):(r=null,e=h),r}function Or(){var r,f,h,t;if(t=e,r=an(),r!==null){for(f=[],h=xs();h!==null;)f.push(h),h=xs();f!==null?r=[r,f]:(r=null,e=t)}else r=null,e=t;return r}function xs(){var r;return r=x(),r===null&&(r=$(),r===null&&(r=Ie())),r}function an(){var r;return r=$(),r===null&&(r=Ie(),r===null&&(l.charCodeAt(e)===59?(r=";",e++):(r=null,n('";"')),r===null&&(l.charCodeAt(e)===63?(r="?",e++):(r=null,n('"?"')),r===null&&(l.charCodeAt(e)===58?(r=":",e++):(r=null,n('":"')),r===null&&(l.charCodeAt(e)===64?(r="@",e++):(r=null,n('"@"')),r===null&&(l.charCodeAt(e)===38?(r="&",e++):(r=null,n('"&"')),r===null&&(l.charCodeAt(e)===61?(r="=",e++):(r=null,n('"="')),r===null&&(l.charCodeAt(e)===43?(r="+",e++):(r=null,n('"+"')),r===null&&(l.charCodeAt(e)===36?(r="$",e++):(r=null,n('"$"')),r===null&&(l.charCodeAt(e)===44?(r=",",e++):(r=null,n('","')))))))))))),r}function Dr(){var r,f,h,t,o,u;if(o=e,r=ts(),r!==null){for(f=[],u=e,l.charCodeAt(e)===47?(h="/",e++):(h=null,n('"/"')),h!==null?(t=ts(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);h!==null;)f.push(h),u=e,l.charCodeAt(e)===47?(h="/",e++):(h=null,n('"/"')),h!==null?(t=ts(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);f!==null?r=[r,f]:(r=null,e=o)}else r=null,e=o;return r}function ts(){var r,f,h,t,o,u;for(o=e,r=[],f=Ms();f!==null;)r.push(f),f=Ms();if(r!==null){for(f=[],u=e,l.charCodeAt(e)===59?(h=";",e++):(h=null,n('";"')),h!==null?(t=$n(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);h!==null;)f.push(h),u=e,l.charCodeAt(e)===59?(h=";",e++):(h=null,n('";"')),h!==null?(t=$n(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);f!==null?r=[r,f]:(r=null,e=o)}else r=null,e=o;return r}function $n(){var r,f;for(r=[],f=Ms();f!==null;)r.push(f),f=Ms();return r}function Ms(){var r;return r=$(),r===null&&(r=Ie(),r===null&&(l.charCodeAt(e)===58?(r=":",e++):(r=null,n('":"')),r===null&&(l.charCodeAt(e)===64?(r="@",e++):(r=null,n('"@"')),r===null&&(l.charCodeAt(e)===38?(r="&",e++):(r=null,n('"&"')),r===null&&(l.charCodeAt(e)===61?(r="=",e++):(r=null,n('"="')),r===null&&(l.charCodeAt(e)===43?(r="+",e++):(r=null,n('"+"')),r===null&&(l.charCodeAt(e)===36?(r="$",e++):(r=null,n('"$"')),r===null&&(l.charCodeAt(e)===44?(r=",",e++):(r=null,n('","')))))))))),r}function on(){var r,f,h,t,o;if(t=e,o=e,r=m(),r!==null){for(f=[],h=m(),h===null&&(h=S(),h===null&&(l.charCodeAt(e)===43?(h="+",e++):(h=null,n('"+"')),h===null&&(l.charCodeAt(e)===45?(h="-",e++):(h=null,n('"-"')),h===null&&(l.charCodeAt(e)===46?(h=".",e++):(h=null,n('"."'))))));h!==null;)f.push(h),h=m(),h===null&&(h=S(),h===null&&(l.charCodeAt(e)===43?(h="+",e++):(h=null,n('"+"')),h===null&&(l.charCodeAt(e)===45?(h="-",e++):(h=null,n('"-"')),h===null&&(l.charCodeAt(e)===46?(h=".",e++):(h=null,n('"."'))))));f!==null?r=[r,f]:(r=null,e=o)}else r=null,e=o;return r!==null&&(r=function(u){b.scheme=l.substring(e,u)}(t)),r===null&&(e=t),r}function Hn(){var r;return r=ks(),r===null&&(r=Nr()),r}function ks(){var r,f,h,t;return h=e,t=e,r=ct(),r!==null?(l.charCodeAt(e)===64?(f="@",e++):(f=null,n('"@"')),f!==null?r=[r,f]:(r=null,e=t)):(r=null,e=t),r=r!==null?r:"",r!==null?(f=nn(),f!==null?r=[r,f]:(r=null,e=h)):(r=null,e=h),r=r!==null?r:"",r}function Nr(){var r,f;if(f=$(),f===null&&(f=Ie(),f===null&&(l.charCodeAt(e)===36?(f="$",e++):(f=null,n('"$"')),f===null&&(l.charCodeAt(e)===44?(f=",",e++):(f=null,n('","')),f===null&&(l.charCodeAt(e)===59?(f=";",e++):(f=null,n('";"')),f===null&&(l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f===null&&(l.charCodeAt(e)===64?(f="@",e++):(f=null,n('"@"')),f===null&&(l.charCodeAt(e)===38?(f="&",e++):(f=null,n('"&"')),f===null&&(l.charCodeAt(e)===61?(f="=",e++):(f=null,n('"="')),f===null&&(l.charCodeAt(e)===43?(f="+",e++):(f=null,n('"+"'))))))))))),f!==null)for(r=[];f!==null;)r.push(f),f=$(),f===null&&(f=Ie(),f===null&&(l.charCodeAt(e)===36?(f="$",e++):(f=null,n('"$"')),f===null&&(l.charCodeAt(e)===44?(f=",",e++):(f=null,n('","')),f===null&&(l.charCodeAt(e)===59?(f=";",e++):(f=null,n('";"')),f===null&&(l.charCodeAt(e)===58?(f=":",e++):(f=null,n('":"')),f===null&&(l.charCodeAt(e)===64?(f="@",e++):(f=null,n('"@"')),f===null&&(l.charCodeAt(e)===38?(f="&",e++):(f=null,n('"&"')),f===null&&(l.charCodeAt(e)===61?(f="=",e++):(f=null,n('"="')),f===null&&(l.charCodeAt(e)===43?(f="+",e++):(f=null,n('"+"')))))))))));else r=null;return r}function Ur(){var r,f;for(r=[],f=xs();f!==null;)r.push(f),f=xs();return r}function Fn(){var r,f,h,t,o,u,d,T;if(d=e,T=e,l.substr(e,3).toLowerCase()==="sip"?(r=l.substr(e,3),e+=3):(r=null,n('"SIP"')),r!==null)if(l.charCodeAt(e)===47?(f="/",e++):(f=null,n('"/"')),f!==null){if(t=S(),t!==null)for(h=[];t!==null;)h.push(t),t=S();else h=null;if(h!==null)if(l.charCodeAt(e)===46?(t=".",e++):(t=null,n('"."')),t!==null){if(u=S(),u!==null)for(o=[];u!==null;)o.push(u),u=S();else o=null;o!==null?r=[r,f,h,t,o]:(r=null,e=T)}else r=null,e=T;else r=null,e=T}else r=null,e=T;else r=null,e=T;return r!==null&&(r=function(E){b.sip_version=l.substring(e,E)}(d)),r===null&&(e=d),r}function Pr(){var r;return l.substr(e,6)==="INVITE"?(r="INVITE",e+=6):(r=null,n('"INVITE"')),r}function xr(){var r;return l.substr(e,3)==="ACK"?(r="ACK",e+=3):(r=null,n('"ACK"')),r}function jn(){var r;return l.substr(e,7)==="OPTIONS"?(r="OPTIONS",e+=7):(r=null,n('"OPTIONS"')),r}function Mr(){var r;return l.substr(e,3)==="BYE"?(r="BYE",e+=3):(r=null,n('"BYE"')),r}function kr(){var r;return l.substr(e,6)==="CANCEL"?(r="CANCEL",e+=6):(r=null,n('"CANCEL"')),r}function Lr(){var r;return l.substr(e,8)==="REGISTER"?(r="REGISTER",e+=8):(r=null,n('"REGISTER"')),r}function $r(){var r;return l.substr(e,9)==="SUBSCRIBE"?(r="SUBSCRIBE",e+=9):(r=null,n('"SUBSCRIBE"')),r}function Hr(){var r;return l.substr(e,6)==="NOTIFY"?(r="NOTIFY",e+=6):(r=null,n('"NOTIFY"')),r}function Fr(){var r;return l.substr(e,5)==="REFER"?(r="REFER",e+=5):(r=null,n('"REFER"')),r}function un(){var r,f;return f=e,r=Pr(),r===null&&(r=xr(),r===null&&(r=jn(),r===null&&(r=Mr(),r===null&&(r=kr(),r===null&&(r=Lr(),r===null&&(r=$r(),r===null&&(r=Hr(),r===null&&(r=Fr(),r===null&&(r=U()))))))))),r!==null&&(r=function(h){return b.method=l.substring(e,h),b.method}(f)),r===null&&(e=f),r}function jr(){var r,f,h,t,o,u;return u=e,r=Fn(),r!==null?(f=V(),f!==null?(h=qr(),h!==null?(t=V(),t!==null?(o=Vr(),o!==null?r=[r,f,h,t,o]:(r=null,e=u)):(r=null,e=u)):(r=null,e=u)):(r=null,e=u)):(r=null,e=u),r}function qr(){var r,f;return f=e,r=cn(),r!==null&&(r=function(h,t){b.status_code=parseInt(t.join(""))}(f,r)),r===null&&(e=f),r}function cn(){var r,f,h,t;return t=e,r=S(),r!==null?(f=S(),f!==null?(h=S(),h!==null?r=[r,f,h]:(r=null,e=t)):(r=null,e=t)):(r=null,e=t),r}function Vr(){var r,f,h;for(h=e,r=[],f=x(),f===null&&(f=$(),f===null&&(f=Ie(),f===null&&(f=B(),f===null&&(f=X(),f===null&&(f=V(),f===null&&(f=W()))))));f!==null;)r.push(f),f=x(),f===null&&(f=$(),f===null&&(f=Ie(),f===null&&(f=B(),f===null&&(f=X(),f===null&&(f=V(),f===null&&(f=W()))))));return r!==null&&(r=function(t){b.reason_phrase=l.substring(e,t)}(h)),r===null&&(e=h),r}function dl(){var r,f,h,t,o,u;if(o=e,r=Hs(),r!==null){for(f=[],u=e,h=we(),h!==null?(t=Hs(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);h!==null;)f.push(h),u=e,h=we(),h!==null?(t=Hs(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);f!==null?r=[r,f]:(r=null,e=o)}else r=null,e=o;return r}function pl(){var r,f,h,t,o,u;return t=e,o=e,r=N(),r!==null?(u=e,l.charCodeAt(e)===64?(f="@",e++):(f=null,n('"@"')),f!==null?(h=N(),h!==null?f=[f,h]:(f=null,e=u)):(f=null,e=u),f=f!==null?f:"",f!==null?r=[r,f]:(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(d){b=l.substring(e,d)}(t)),r===null&&(e=t),r}function ml(){var r,f,h,t,o,u,d;if(o=e,r=Y(),r===null)if(u=e,r=qn(),r!==null){for(f=[],d=e,h=we(),h!==null?(t=qn(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);h!==null;)f.push(h),d=e,h=we(),h!==null?(t=qn(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);f!==null?r=[r,f]:(r=null,e=u)}else r=null,e=u;return r!==null&&(r=function(T){var E,y;for(y=b.multi_header.length,E=0;E<y;E++)if(b.multi_header[E].parsed===null){b=null;break}b!==null?b=b.multi_header:b=-1}()),r===null&&(e=o),r}function qn(){var r,f,h,t,o,u,d;if(o=e,u=e,r=Ne(),r===null&&(r=hs()),r!==null){for(f=[],d=e,h=Se(),h!==null?(t=Ls(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);h!==null;)f.push(h),d=e,h=Se(),h!==null?(t=Ls(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);f!==null?r=[r,f]:(r=null,e=u)}else r=null,e=u;return r!==null&&(r=function(T){var E;b.multi_header||(b.multi_header=[]);try{E=new Vs(b.uri,b.display_name,b.params),delete b.uri,delete b.display_name,delete b.params}catch{E=null}b.multi_header.push({possition:e,offset:T,parsed:E})}(o)),r===null&&(e=o),r}function hs(){var r,f,h,t,o;return o=e,r=Vn(),r=r!==null?r:"",r!==null?(f=Le(),f!==null?(h=xe(),h!==null?(t=Ce(),t!==null?r=[r,f,h,t]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r}function Vn(){var r,f,h,t,o,u,d;if(o=e,u=e,r=U(),r!==null){for(f=[],d=e,h=H(),h!==null?(t=U(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);h!==null;)f.push(h),d=e,h=H(),h!==null?(t=U(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);f!==null?r=[r,f]:(r=null,e=u)}else r=null,e=u;return r===null&&(r=ve()),r!==null&&(r=function(T,E){typeof E=="string"?b.display_name=E:b.display_name=E[1].reduce(function(y,O){return y+O[0]+O[1]},E[0])}(o,r)),r===null&&(e=o),r}function Ls(){var r;return r=ss(),r===null&&(r=fn(),r===null&&(r=ze())),r}function ss(){var r,f,h,t,o;return t=e,o=e,l.substr(e,1).toLowerCase()==="q"?(r=l.substr(e,1),e++):(r=null,n('"q"')),r!==null?(f=ae(),f!==null?(h=Br(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u,d){b.params||(b.params={}),b.params.q=d}(t,r[2])),r===null&&(e=t),r}function fn(){var r,f,h,t,o;return t=e,o=e,l.substr(e,7).toLowerCase()==="expires"?(r=l.substr(e,7),e+=7):(r=null,n('"expires"')),r!==null?(f=ae(),f!==null?(h=Bt(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u,d){b.params||(b.params={}),b.params.expires=d}(t,r[2])),r===null&&(e=t),r}function Bt(){var r,f,h;if(h=e,f=S(),f!==null)for(r=[];f!==null;)r.push(f),f=S();else r=null;return r!==null&&(r=function(t,o){return parseInt(o.join(""))}(h,r)),r===null&&(e=h),r}function Br(){var r,f,h,t,o,u,d,T;return u=e,d=e,l.charCodeAt(e)===48?(r="0",e++):(r=null,n('"0"')),r!==null?(T=e,l.charCodeAt(e)===46?(f=".",e++):(f=null,n('"."')),f!==null?(h=S(),h=h!==null?h:"",h!==null?(t=S(),t=t!==null?t:"",t!==null?(o=S(),o=o!==null?o:"",o!==null?f=[f,h,t,o]:(f=null,e=T)):(f=null,e=T)):(f=null,e=T)):(f=null,e=T),f=f!==null?f:"",f!==null?r=[r,f]:(r=null,e=d)):(r=null,e=d),r!==null&&(r=function(E){return parseFloat(l.substring(e,E))}(u)),r===null&&(e=u),r}function ze(){var r,f,h,t,o,u;return t=e,o=e,r=U(),r!==null?(u=e,f=ae(),f!==null?(h=ns(),h!==null?f=[f,h]:(f=null,e=u)):(f=null,e=u),f=f!==null?f:"",f!==null?r=[r,f]:(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(d,T,E){b.params||(b.params={}),typeof E>"u"?E=void 0:E=E[1],b.params[T.toLowerCase()]=E}(t,r[0],r[1])),r===null&&(e=t),r}function ns(){var r;return r=U(),r===null&&(r=cs(),r===null&&(r=Pe())),r}function gl(){var r,f,h,t,o,u;if(o=e,r=Xe(),r!==null){for(f=[],u=e,h=Se(),h!==null?(t=Bn(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);h!==null;)f.push(h),u=e,h=Se(),h!==null?(t=Bn(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);f!==null?r=[r,f]:(r=null,e=o)}else r=null,e=o;return r}function Xe(){var r;return l.substr(e,6).toLowerCase()==="render"?(r=l.substr(e,6),e+=6):(r=null,n('"render"')),r===null&&(l.substr(e,7).toLowerCase()==="session"?(r=l.substr(e,7),e+=7):(r=null,n('"session"')),r===null&&(l.substr(e,4).toLowerCase()==="icon"?(r=l.substr(e,4),e+=4):(r=null,n('"icon"')),r===null&&(l.substr(e,5).toLowerCase()==="alert"?(r=l.substr(e,5),e+=5):(r=null,n('"alert"')),r===null&&(r=U())))),r}function Bn(){var r;return r=Tl(),r===null&&(r=ze()),r}function Tl(){var r,f,h,t;return t=e,l.substr(e,8).toLowerCase()==="handling"?(r=l.substr(e,8),e+=8):(r=null,n('"handling"')),r!==null?(f=ae(),f!==null?(l.substr(e,8).toLowerCase()==="optional"?(h=l.substr(e,8),e+=8):(h=null,n('"optional"')),h===null&&(l.substr(e,8).toLowerCase()==="required"?(h=l.substr(e,8),e+=8):(h=null,n('"required"')),h===null&&(h=U())),h!==null?r=[r,f,h]:(r=null,e=t)):(r=null,e=t)):(r=null,e=t),r}function vl(){var r,f,h,t,o,u;if(o=e,r=U(),r!==null){for(f=[],u=e,h=we(),h!==null?(t=U(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);h!==null;)f.push(h),u=e,h=we(),h!==null?(t=U(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);f!==null?r=[r,f]:(r=null,e=o)}else r=null,e=o;return r}function Gr(){var r,f,h;if(h=e,f=S(),f!==null)for(r=[];f!==null;)r.push(f),f=S();else r=null;return r!==null&&(r=function(t,o){b=parseInt(o.join(""))}(h,r)),r===null&&(e=h),r}function El(){var r,f;return f=e,r=Sl(),r!==null&&(r=function(h){b=l.substring(e,h)}(f)),r===null&&(e=f),r}function Sl(){var r,f,h,t,o,u,d,T;if(d=e,r=yl(),r!==null)if(f=re(),f!==null)if(h=Yr(),h!==null){for(t=[],T=e,o=Se(),o!==null?(u=$s(),u!==null?o=[o,u]:(o=null,e=T)):(o=null,e=T);o!==null;)t.push(o),T=e,o=Se(),o!==null?(u=$s(),u!==null?o=[o,u]:(o=null,e=T)):(o=null,e=T);t!==null?r=[r,f,h,t]:(r=null,e=d)}else r=null,e=d;else r=null,e=d;else r=null,e=d;return r}function yl(){var r;return r=Al(),r===null&&(r=Wr()),r}function Al(){var r;return l.substr(e,4).toLowerCase()==="text"?(r=l.substr(e,4),e+=4):(r=null,n('"text"')),r===null&&(l.substr(e,5).toLowerCase()==="image"?(r=l.substr(e,5),e+=5):(r=null,n('"image"')),r===null&&(l.substr(e,5).toLowerCase()==="audio"?(r=l.substr(e,5),e+=5):(r=null,n('"audio"')),r===null&&(l.substr(e,5).toLowerCase()==="video"?(r=l.substr(e,5),e+=5):(r=null,n('"video"')),r===null&&(l.substr(e,11).toLowerCase()==="application"?(r=l.substr(e,11),e+=11):(r=null,n('"application"')),r===null&&(r=_n()))))),r}function Wr(){var r;return l.substr(e,7).toLowerCase()==="message"?(r=l.substr(e,7),e+=7):(r=null,n('"message"')),r===null&&(l.substr(e,9).toLowerCase()==="multipart"?(r=l.substr(e,9),e+=9):(r=null,n('"multipart"')),r===null&&(r=_n())),r}function _n(){var r;return r=U(),r===null&&(r=Kr()),r}function Kr(){var r,f,h;return h=e,l.substr(e,2).toLowerCase()==="x-"?(r=l.substr(e,2),e+=2):(r=null,n('"x-"')),r!==null?(f=U(),f!==null?r=[r,f]:(r=null,e=h)):(r=null,e=h),r}function Yr(){var r;return r=_n(),r===null&&(r=U()),r}function $s(){var r,f,h,t;return t=e,r=U(),r!==null?(f=ae(),f!==null?(h=Jr(),h!==null?r=[r,f,h]:(r=null,e=t)):(r=null,e=t)):(r=null,e=t),r}function Jr(){var r;return r=U(),r===null&&(r=Pe()),r}function Cl(){var r,f,h,t;return t=e,r=Gn(),r!==null?(f=H(),f!==null?(h=un(),h!==null?r=[r,f,h]:(r=null,e=t)):(r=null,e=t)):(r=null,e=t),r}function Gn(){var r,f,h;if(h=e,f=S(),f!==null)for(r=[];f!==null;)r.push(f),f=S();else r=null;return r!==null&&(r=function(t,o){b.value=parseInt(o.join(""))}(h,r)),r===null&&(e=h),r}function Rl(){var r,f;return f=e,r=Bt(),r!==null&&(r=function(h,t){b=t}(f,r)),r===null&&(e=f),r}function so(){var r,f,h,t,o,u,d;if(o=e,u=e,r=Hs(),r!==null){for(f=[],d=e,h=Se(),h!==null?(t=ze(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);h!==null;)f.push(h),d=e,h=Se(),h!==null?(t=ze(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);f!==null?r=[r,f]:(r=null,e=u)}else r=null,e=u;return r!==null&&(r=function(T,E){b.event=E.join("").toLowerCase()}(o,r[0])),r===null&&(e=o),r}function Hs(){var r,f,h,t,o,u;if(o=e,r=se(),r!==null){for(f=[],u=e,l.charCodeAt(e)===46?(h=".",e++):(h=null,n('"."')),h!==null?(t=se(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);h!==null;)f.push(h),u=e,l.charCodeAt(e)===46?(h=".",e++):(h=null,n('"."')),h!==null?(t=se(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);f!==null?r=[r,f]:(r=null,e=o)}else r=null,e=o;return r}function no(){var r,f,h,t,o,u,d;if(o=e,u=e,r=Ne(),r===null&&(r=hs()),r!==null){for(f=[],d=e,h=Se(),h!==null?(t=zr(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);h!==null;)f.push(h),d=e,h=Se(),h!==null?(t=zr(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);f!==null?r=[r,f]:(r=null,e=u)}else r=null,e=u;return r!==null&&(r=function(T){var E=b.tag;try{b=new Vs(b.uri,b.display_name,b.params),E&&b.setParam("tag",E)}catch{b=-1}}()),r===null&&(e=o),r}function zr(){var r;return r=ds(),r===null&&(r=ze()),r}function ds(){var r,f,h,t,o;return t=e,o=e,l.substr(e,3).toLowerCase()==="tag"?(r=l.substr(e,3),e+=3):(r=null,n('"tag"')),r!==null?(f=ae(),f!==null?(h=U(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u,d){b.tag=d}(t,r[2])),r===null&&(e=t),r}function ro(){var r,f,h;if(h=e,f=S(),f!==null)for(r=[];f!==null;)r.push(f),f=S();else r=null;return r!==null&&(r=function(t,o){b=parseInt(o.join(""))}(h,r)),r===null&&(e=h),r}function Xr(){var r,f;return f=e,r=Bt(),r!==null&&(r=function(h,t){b=t}(f,r)),r===null&&(e=f),r}function Qr(){var r,f,h,t,o,u,d,T,E,y;for(T=e,E=e,r=[],f=Vn();f!==null;)r.push(f),f=Vn();if(r!==null)if(f=Le(),f!==null)if(h=xe(),h!==null)if(t=Ce(),t!==null){for(o=[],y=e,u=Se(),u!==null?(d=ze(),d!==null?u=[u,d]:(u=null,e=y)):(u=null,e=y);u!==null;)o.push(u),y=e,u=Se(),u!==null?(d=ze(),d!==null?u=[u,d]:(u=null,e=y)):(u=null,e=y);o!==null?r=[r,f,h,t,o]:(r=null,e=E)}else r=null,e=E;else r=null,e=E;else r=null,e=E;else r=null,e=E;return r!==null&&(r=function(O){try{b=new Vs(b.uri,b.display_name,b.params)}catch{b=-1}}()),r===null&&(e=T),r}function io(){var r;return r=Zr(),r}function Zr(){var r,f,h,t,o,u,d,T;if(d=e,l.substr(e,6).toLowerCase()==="digest"?(r=l.substr(e,6),e+=6):(r=null,n('"Digest"')),r!==null)if(f=H(),f!==null)if(h=Fs(),h!==null){for(t=[],T=e,o=we(),o!==null?(u=Fs(),u!==null?o=[o,u]:(o=null,e=T)):(o=null,e=T);o!==null;)t.push(o),T=e,o=we(),o!==null?(u=Fs(),u!==null?o=[o,u]:(o=null,e=T)):(o=null,e=T);t!==null?r=[r,f,h,t]:(r=null,e=d)}else r=null,e=d;else r=null,e=d;else r=null,e=d;return r===null&&(r=Il()),r}function Il(){var r,f,h,t,o,u,d,T;if(d=e,r=U(),r!==null)if(f=H(),f!==null)if(h=hn(),h!==null){for(t=[],T=e,o=we(),o!==null?(u=hn(),u!==null?o=[o,u]:(o=null,e=T)):(o=null,e=T);o!==null;)t.push(o),T=e,o=we(),o!==null?(u=hn(),u!==null?o=[o,u]:(o=null,e=T)):(o=null,e=T);t!==null?r=[r,f,h,t]:(r=null,e=d)}else r=null,e=d;else r=null,e=d;else r=null,e=d;return r}function hn(){var r,f,h,t;return t=e,r=U(),r!==null?(f=ae(),f!==null?(h=U(),h===null&&(h=Pe()),h!==null?r=[r,f,h]:(r=null,e=t)):(r=null,e=t)):(r=null,e=t),r}function Fs(){var r;return r=ei(),r===null&&(r=dn(),r===null&&(r=ti(),r===null&&(r=mn(),r===null&&(r=ni(),r===null&&(r=ri(),r===null&&(r=ii(),r===null&&(r=hn()))))))),r}function ei(){var r,f,h,t;return t=e,l.substr(e,5).toLowerCase()==="realm"?(r=l.substr(e,5),e+=5):(r=null,n('"realm"')),r!==null?(f=ae(),f!==null?(h=js(),h!==null?r=[r,f,h]:(r=null,e=t)):(r=null,e=t)):(r=null,e=t),r}function js(){var r,f;return f=e,r=ve(),r!==null&&(r=function(h,t){b.realm=t}(f,r)),r===null&&(e=f),r}function dn(){var r,f,h,t,o,u,d,T,E;if(T=e,l.substr(e,6).toLowerCase()==="domain"?(r=l.substr(e,6),e+=6):(r=null,n('"domain"')),r!==null)if(f=ae(),f!==null)if(h=Ue(),h!==null)if(t=pn(),t!==null){if(o=[],E=e,d=V(),d!==null)for(u=[];d!==null;)u.push(d),d=V();else u=null;for(u!==null?(d=pn(),d!==null?u=[u,d]:(u=null,e=E)):(u=null,e=E);u!==null;){if(o.push(u),E=e,d=V(),d!==null)for(u=[];d!==null;)u.push(d),d=V();else u=null;u!==null?(d=pn(),d!==null?u=[u,d]:(u=null,e=E)):(u=null,e=E)}o!==null?(u=le(),u!==null?r=[r,f,h,t,o,u]:(r=null,e=T)):(r=null,e=T)}else r=null,e=T;else r=null,e=T;else r=null,e=T;else r=null,e=T;return r}function pn(){var r;return r=Ir(),r===null&&(r=Ps()),r}function ti(){var r,f,h,t;return t=e,l.substr(e,5).toLowerCase()==="nonce"?(r=l.substr(e,5),e+=5):(r=null,n('"nonce"')),r!==null?(f=ae(),f!==null?(h=si(),h!==null?r=[r,f,h]:(r=null,e=t)):(r=null,e=t)):(r=null,e=t),r}function si(){var r,f;return f=e,r=ve(),r!==null&&(r=function(h,t){b.nonce=t}(f,r)),r===null&&(e=f),r}function mn(){var r,f,h,t,o;return t=e,o=e,l.substr(e,6).toLowerCase()==="opaque"?(r=l.substr(e,6),e+=6):(r=null,n('"opaque"')),r!==null?(f=ae(),f!==null?(h=ve(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u,d){b.opaque=d}(t,r[2])),r===null&&(e=t),r}function ni(){var r,f,h,t,o;return t=e,l.substr(e,5).toLowerCase()==="stale"?(r=l.substr(e,5),e+=5):(r=null,n('"stale"')),r!==null?(f=ae(),f!==null?(o=e,l.substr(e,4).toLowerCase()==="true"?(h=l.substr(e,4),e+=4):(h=null,n('"true"')),h!==null&&(h=function(u){b.stale=!0}()),h===null&&(e=o),h===null&&(o=e,l.substr(e,5).toLowerCase()==="false"?(h=l.substr(e,5),e+=5):(h=null,n('"false"')),h!==null&&(h=function(u){b.stale=!1}()),h===null&&(e=o)),h!==null?r=[r,f,h]:(r=null,e=t)):(r=null,e=t)):(r=null,e=t),r}function ri(){var r,f,h,t,o;return t=e,o=e,l.substr(e,9).toLowerCase()==="algorithm"?(r=l.substr(e,9),e+=9):(r=null,n('"algorithm"')),r!==null?(f=ae(),f!==null?(l.substr(e,3).toLowerCase()==="md5"?(h=l.substr(e,3),e+=3):(h=null,n('"MD5"')),h===null&&(l.substr(e,8).toLowerCase()==="md5-sess"?(h=l.substr(e,8),e+=8):(h=null,n('"MD5-sess"')),h===null&&(h=U())),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u,d){b.algorithm=d.toUpperCase()}(t,r[2])),r===null&&(e=t),r}function ii(){var r,f,h,t,o,u,d,T,E,y;if(T=e,l.substr(e,3).toLowerCase()==="qop"?(r=l.substr(e,3),e+=3):(r=null,n('"qop"')),r!==null)if(f=ae(),f!==null)if(h=Ue(),h!==null){if(E=e,t=gn(),t!==null){for(o=[],y=e,l.charCodeAt(e)===44?(u=",",e++):(u=null,n('","')),u!==null?(d=gn(),d!==null?u=[u,d]:(u=null,e=y)):(u=null,e=y);u!==null;)o.push(u),y=e,l.charCodeAt(e)===44?(u=",",e++):(u=null,n('","')),u!==null?(d=gn(),d!==null?u=[u,d]:(u=null,e=y)):(u=null,e=y);o!==null?t=[t,o]:(t=null,e=E)}else t=null,e=E;t!==null?(o=le(),o!==null?r=[r,f,h,t,o]:(r=null,e=T)):(r=null,e=T)}else r=null,e=T;else r=null,e=T;else r=null,e=T;return r}function gn(){var r,f;return f=e,l.substr(e,8).toLowerCase()==="auth-int"?(r=l.substr(e,8),e+=8):(r=null,n('"auth-int"')),r===null&&(l.substr(e,4).toLowerCase()==="auth"?(r=l.substr(e,4),e+=4):(r=null,n('"auth"')),r===null&&(r=U())),r!==null&&(r=function(h,t){b.qop||(b.qop=[]),b.qop.push(t.toLowerCase())}(f,r)),r===null&&(e=f),r}function bl(){var r,f,h,t,o,u;if(o=e,r=U(),r!==null){for(f=[],u=e,h=we(),h!==null?(t=U(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);h!==null;)f.push(h),u=e,h=we(),h!==null?(t=U(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);f!==null?r=[r,f]:(r=null,e=o)}else r=null,e=o;return r}function wl(){var r,f,h,t,o,u,d;if(o=e,u=e,r=ps(),r!==null){for(f=[],d=e,h=we(),h!==null?(t=ps(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);h!==null;)f.push(h),d=e,h=we(),h!==null?(t=ps(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);f!==null?r=[r,f]:(r=null,e=u)}else r=null,e=u;return r!==null&&(r=function(T){var E,y;for(y=b.multi_header.length,E=0;E<y;E++)if(b.multi_header[E].parsed===null){b=null;break}b!==null?b=b.multi_header:b=-1}()),r===null&&(e=o),r}function ps(){var r,f,h,t,o,u,d;if(o=e,u=e,r=hs(),r!==null){for(f=[],d=e,h=Se(),h!==null?(t=ze(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);h!==null;)f.push(h),d=e,h=Se(),h!==null?(t=ze(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);f!==null?r=[r,f]:(r=null,e=u)}else r=null,e=u;return r!==null&&(r=function(T){var E;b.multi_header||(b.multi_header=[]);try{E=new Vs(b.uri,b.display_name,b.params),delete b.uri,delete b.display_name,delete b.params}catch{E=null}b.multi_header.push({possition:e,offset:T,parsed:E})}(o)),r===null&&(e=o),r}function lo(){var r,f,h,t,o,u,d;if(o=e,u=e,l.substr(e,3).toLowerCase()==="sip"?(r=l.substr(e,3),e+=3):(r=null,n('"SIP"')),r===null&&(r=U()),r!==null){for(f=[],d=e,h=Se(),h!==null?(t=li(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);h!==null;)f.push(h),d=e,h=Se(),h!==null?(t=li(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);f!==null?r=[r,f]:(r=null,e=u)}else r=null,e=u;return r!==null&&(r=function(T,E){if(b.protocol=E.toLowerCase(),b.params||(b.params={}),b.params.text&&b.params.text[0]==='"'){var y=b.params.text;b.text=y.substring(1,y.length-1),delete b.params.text}}(o,r[0])),r===null&&(e=o),r}function li(){var r;return r=Tn(),r===null&&(r=ze()),r}function Tn(){var r,f,h,t,o,u;if(o=e,u=e,l.substr(e,5).toLowerCase()==="cause"?(r=l.substr(e,5),e+=5):(r=null,n('"cause"')),r!==null)if(f=ae(),f!==null){if(t=S(),t!==null)for(h=[];t!==null;)h.push(t),t=S();else h=null;h!==null?r=[r,f,h]:(r=null,e=u)}else r=null,e=u;else r=null,e=u;return r!==null&&(r=function(d,T){b.cause=parseInt(T.join(""))}(o,r[2])),r===null&&(e=o),r}function ao(){var r,f,h,t,o,u;if(o=e,r=U(),r!==null){for(f=[],u=e,h=we(),h!==null?(t=U(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);h!==null;)f.push(h),u=e,h=we(),h!==null?(t=U(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);f!==null?r=[r,f]:(r=null,e=o)}else r=null,e=o;return r}function ai(){var r,f,h,t,o,u;if(o=e,r=vn(),r!==null){for(f=[],u=e,h=we(),h!==null?(t=vn(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);h!==null;)f.push(h),u=e,h=we(),h!==null?(t=vn(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);f!==null?r=[r,f]:(r=null,e=o)}else r=null,e=o;return r}function vn(){var r,f,h,t,o,u;if(o=e,r=hs(),r!==null){for(f=[],u=e,h=Se(),h!==null?(t=ze(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);h!==null;)f.push(h),u=e,h=Se(),h!==null?(t=ze(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);f!==null?r=[r,f]:(r=null,e=o)}else r=null,e=o;return r}function oo(){var r,f,h,t,o,u;if(o=e,r=Ol(),r!==null){for(f=[],u=e,h=Se(),h!==null?(t=qs(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);h!==null;)f.push(h),u=e,h=Se(),h!==null?(t=qs(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);f!==null?r=[r,f]:(r=null,e=o)}else r=null,e=o;return r}function Ol(){var r,f;return f=e,l.substr(e,6).toLowerCase()==="active"?(r=l.substr(e,6),e+=6):(r=null,n('"active"')),r===null&&(l.substr(e,7).toLowerCase()==="pending"?(r=l.substr(e,7),e+=7):(r=null,n('"pending"')),r===null&&(l.substr(e,10).toLowerCase()==="terminated"?(r=l.substr(e,10),e+=10):(r=null,n('"terminated"')),r===null&&(r=U()))),r!==null&&(r=function(h){b.state=l.substring(e,h)}(f)),r===null&&(e=f),r}function qs(){var r,f,h,t,o;return t=e,o=e,l.substr(e,6).toLowerCase()==="reason"?(r=l.substr(e,6),e+=6):(r=null,n('"reason"')),r!==null?(f=ae(),f!==null?(h=Dl(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u,d){typeof d<"u"&&(b.reason=d)}(t,r[2])),r===null&&(e=t),r===null&&(t=e,o=e,l.substr(e,7).toLowerCase()==="expires"?(r=l.substr(e,7),e+=7):(r=null,n('"expires"')),r!==null?(f=ae(),f!==null?(h=Bt(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u,d){typeof d<"u"&&(b.expires=d)}(t,r[2])),r===null&&(e=t),r===null&&(t=e,o=e,l.substr(e,11).toLowerCase()==="retry_after"?(r=l.substr(e,11),e+=11):(r=null,n('"retry_after"')),r!==null?(f=ae(),f!==null?(h=Bt(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u,d){typeof d<"u"&&(b.retry_after=d)}(t,r[2])),r===null&&(e=t),r===null&&(r=ze()))),r}function Dl(){var r;return l.substr(e,11).toLowerCase()==="deactivated"?(r=l.substr(e,11),e+=11):(r=null,n('"deactivated"')),r===null&&(l.substr(e,9).toLowerCase()==="probation"?(r=l.substr(e,9),e+=9):(r=null,n('"probation"')),r===null&&(l.substr(e,8).toLowerCase()==="rejected"?(r=l.substr(e,8),e+=8):(r=null,n('"rejected"')),r===null&&(l.substr(e,7).toLowerCase()==="timeout"?(r=l.substr(e,7),e+=7):(r=null,n('"timeout"')),r===null&&(l.substr(e,6).toLowerCase()==="giveup"?(r=l.substr(e,6),e+=6):(r=null,n('"giveup"')),r===null&&(l.substr(e,10).toLowerCase()==="noresource"?(r=l.substr(e,10),e+=10):(r=null,n('"noresource"')),r===null&&(l.substr(e,9).toLowerCase()==="invariant"?(r=l.substr(e,9),e+=9):(r=null,n('"invariant"')),r===null&&(r=U()))))))),r}function Nl(){var r;return r=q(),r=r!==null?r:"",r}function oi(){var r,f,h,t,o,u;if(o=e,r=U(),r!==null){for(f=[],u=e,h=we(),h!==null?(t=U(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);h!==null;)f.push(h),u=e,h=we(),h!==null?(t=U(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);f!==null?r=[r,f]:(r=null,e=o)}else r=null,e=o;return r=r!==null?r:"",r}function Ul(){var r,f,h,t,o,u,d;if(o=e,u=e,r=Ne(),r===null&&(r=hs()),r!==null){for(f=[],d=e,h=Se(),h!==null?(t=ui(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);h!==null;)f.push(h),d=e,h=Se(),h!==null?(t=ui(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);f!==null?r=[r,f]:(r=null,e=u)}else r=null,e=u;return r!==null&&(r=function(T){var E=b.tag;try{b=new Vs(b.uri,b.display_name,b.params),E&&b.setParam("tag",E)}catch{b=-1}}()),r===null&&(e=o),r}function ui(){var r;return r=ds(),r===null&&(r=ze()),r}function uo(){var r,f,h,t,o,u;if(o=e,r=Wn(),r!==null){for(f=[],u=e,h=we(),h!==null?(t=Wn(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);h!==null;)f.push(h),u=e,h=we(),h!==null?(t=Wn(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);f!==null?r=[r,f]:(r=null,e=o)}else r=null,e=o;return r}function Wn(){var r,f,h,t,o,u,d,T;if(d=e,r=hi(),r!==null)if(f=H(),f!==null)if(h=mi(),h!==null){for(t=[],T=e,o=Se(),o!==null?(u=En(),u!==null?o=[o,u]:(o=null,e=T)):(o=null,e=T);o!==null;)t.push(o),T=e,o=Se(),o!==null?(u=En(),u!==null?o=[o,u]:(o=null,e=T)):(o=null,e=T);t!==null?r=[r,f,h,t]:(r=null,e=d)}else r=null,e=d;else r=null,e=d;else r=null,e=d;return r}function En(){var r;return r=Pl(),r===null&&(r=Sn(),r===null&&(r=Kn(),r===null&&(r=ci(),r===null&&(r=fi(),r===null&&(r=ze()))))),r}function Pl(){var r,f,h,t,o;return t=e,o=e,l.substr(e,3).toLowerCase()==="ttl"?(r=l.substr(e,3),e+=3):(r=null,n('"ttl"')),r!==null?(f=ae(),f!==null?(h=Yn(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u,d){b.ttl=d}(t,r[2])),r===null&&(e=t),r}function Sn(){var r,f,h,t,o;return t=e,o=e,l.substr(e,5).toLowerCase()==="maddr"?(r=l.substr(e,5),e+=5):(r=null,n('"maddr"')),r!==null?(f=ae(),f!==null?(h=cs(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u,d){b.maddr=d}(t,r[2])),r===null&&(e=t),r}function Kn(){var r,f,h,t,o;return t=e,o=e,l.substr(e,8).toLowerCase()==="received"?(r=l.substr(e,8),e+=8):(r=null,n('"received"')),r!==null?(f=ae(),f!==null?(h=fs(),h===null&&(h=ln()),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u,d){b.received=d}(t,r[2])),r===null&&(e=t),r}function ci(){var r,f,h,t,o;return t=e,o=e,l.substr(e,6).toLowerCase()==="branch"?(r=l.substr(e,6),e+=6):(r=null,n('"branch"')),r!==null?(f=ae(),f!==null?(h=U(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u,d){b.branch=d}(t,r[2])),r===null&&(e=t),r}function fi(){var r,f,h,t,o;return t=e,l.substr(e,5).toLowerCase()==="rport"?(r=l.substr(e,5),e+=5):(r=null,n('"rport"')),r!==null?(o=e,f=ae(),f!==null?(h=_i(),h!==null?f=[f,h]:(f=null,e=o)):(f=null,e=o),f=f!==null?f:"",f!==null?r=[r,f]:(r=null,e=t)):(r=null,e=t),r}function _i(){var r,f,h,t,o,u,d;return u=e,d=e,r=S(),r=r!==null?r:"",r!==null?(f=S(),f=f!==null?f:"",f!==null?(h=S(),h=h!==null?h:"",h!==null?(t=S(),t=t!==null?t:"",t!==null?(o=S(),o=o!==null?o:"",o!==null?r=[r,f,h,t,o]:(r=null,e=d)):(r=null,e=d)):(r=null,e=d)):(r=null,e=d)):(r=null,e=d),r!==null&&(r=function(T,E){b.rport=parseInt(E.join(""))}(u,r)),r===null&&(e=u),r}function hi(){var r,f,h,t,o,u;return u=e,r=di(),r!==null?(f=re(),f!==null?(h=U(),h!==null?(t=re(),t!==null?(o=pi(),o!==null?r=[r,f,h,t,o]:(r=null,e=u)):(r=null,e=u)):(r=null,e=u)):(r=null,e=u)):(r=null,e=u),r}function di(){var r,f;return f=e,l.substr(e,3).toLowerCase()==="sip"?(r=l.substr(e,3),e+=3):(r=null,n('"SIP"')),r===null&&(r=U()),r!==null&&(r=function(h,t){b.protocol=t}(f,r)),r===null&&(e=f),r}function pi(){var r,f;return f=e,l.substr(e,3).toLowerCase()==="udp"?(r=l.substr(e,3),e+=3):(r=null,n('"UDP"')),r===null&&(l.substr(e,3).toLowerCase()==="tcp"?(r=l.substr(e,3),e+=3):(r=null,n('"TCP"')),r===null&&(l.substr(e,3).toLowerCase()==="tls"?(r=l.substr(e,3),e+=3):(r=null,n('"TLS"')),r===null&&(l.substr(e,4).toLowerCase()==="sctp"?(r=l.substr(e,4),e+=4):(r=null,n('"SCTP"')),r===null&&(r=U())))),r!==null&&(r=function(h,t){b.transport=t}(f,r)),r===null&&(e=f),r}function mi(){var r,f,h,t,o;return t=e,r=gi(),r!==null?(o=e,f=it(),f!==null?(h=Ti(),h!==null?f=[f,h]:(f=null,e=o)):(f=null,e=o),f=f!==null?f:"",f!==null?r=[r,f]:(r=null,e=t)):(r=null,e=t),r}function gi(){var r,f;return f=e,r=fs(),r===null&&(r=rn(),r===null&&(r=kn())),r!==null&&(r=function(h){b.host=l.substring(e,h)}(f)),r===null&&(e=f),r}function Ti(){var r,f,h,t,o,u,d;return u=e,d=e,r=S(),r=r!==null?r:"",r!==null?(f=S(),f=f!==null?f:"",f!==null?(h=S(),h=h!==null?h:"",h!==null?(t=S(),t=t!==null?t:"",t!==null?(o=S(),o=o!==null?o:"",o!==null?r=[r,f,h,t,o]:(r=null,e=d)):(r=null,e=d)):(r=null,e=d)):(r=null,e=d)):(r=null,e=d),r!==null&&(r=function(T,E){b.port=parseInt(E.join(""))}(u,r)),r===null&&(e=u),r}function Yn(){var r,f,h,t,o;return t=e,o=e,r=S(),r!==null?(f=S(),f=f!==null?f:"",f!==null?(h=S(),h=h!==null?h:"",h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u,d){return parseInt(d.join(""))}(t,r)),r===null&&(e=t),r}function xl(){var r;return r=Zr(),r}function Ml(){var r,f,h,t,o,u;if(o=e,r=Jn(),r!==null){for(f=[],u=e,h=Se(),h!==null?(t=vi(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);h!==null;)f.push(h),u=e,h=Se(),h!==null?(t=vi(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);f!==null?r=[r,f]:(r=null,e=o)}else r=null,e=o;return r}function Jn(){var r,f;return f=e,r=Bt(),r!==null&&(r=function(h,t){b.expires=t}(f,r)),r===null&&(e=f),r}function vi(){var r;return r=kl(),r===null&&(r=ze()),r}function kl(){var r,f,h,t,o;return t=e,o=e,l.substr(e,9).toLowerCase()==="refresher"?(r=l.substr(e,9),e+=9):(r=null,n('"refresher"')),r!==null?(f=ae(),f!==null?(l.substr(e,3).toLowerCase()==="uac"?(h=l.substr(e,3),e+=3):(h=null,n('"uac"')),h===null&&(l.substr(e,3).toLowerCase()==="uas"?(h=l.substr(e,3),e+=3):(h=null,n('"uas"'))),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u,d){b.refresher=d.toLowerCase()}(t,r[2])),r===null&&(e=t),r}function Ll(){var r,f,h,t;return t=e,r=U(),r!==null?(f=L(),f!==null?(h=zn(),h!==null?r=[r,f,h]:(r=null,e=t)):(r=null,e=t)):(r=null,e=t),r}function zn(){var r,f;for(r=[],f=j(),f===null&&(f=X(),f===null&&(f=H()));f!==null;)r.push(f),f=j(),f===null&&(f=X(),f===null&&(f=H()));return r}function $l(){var r,f;for(r=[],f=R();f!==null;)r.push(f),f=R();return r}function co(){var r,f,h;return h=e,l.substr(e,5)==="uuid:"?(r="uuid:",e+=5):(r=null,n('"uuid:"')),r!==null?(f=Ei(),f!==null?r=[r,f]:(r=null,e=h)):(r=null,e=h),r}function Ei(){var r,f,h,t,o,u,d,T,E,y,O;return y=e,O=e,r=Hl(),r!==null?(l.charCodeAt(e)===45?(f="-",e++):(f=null,n('"-"')),f!==null?(h=Gt(),h!==null?(l.charCodeAt(e)===45?(t="-",e++):(t=null,n('"-"')),t!==null?(o=Gt(),o!==null?(l.charCodeAt(e)===45?(u="-",e++):(u=null,n('"-"')),u!==null?(d=Gt(),d!==null?(l.charCodeAt(e)===45?(T="-",e++):(T=null,n('"-"')),T!==null?(E=Si(),E!==null?r=[r,f,h,t,o,u,d,T,E]:(r=null,e=O)):(r=null,e=O)):(r=null,e=O)):(r=null,e=O)):(r=null,e=O)):(r=null,e=O)):(r=null,e=O)):(r=null,e=O)):(r=null,e=O),r!==null&&(r=function(G,ye){b=l.substring(e+5,G)}(y,r[0])),r===null&&(e=y),r}function Gt(){var r,f,h,t,o;return o=e,r=C(),r!==null?(f=C(),f!==null?(h=C(),h!==null?(t=C(),t!==null?r=[r,f,h,t]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r}function Hl(){var r,f,h;return h=e,r=Gt(),r!==null?(f=Gt(),f!==null?r=[r,f]:(r=null,e=h)):(r=null,e=h),r}function Si(){var r,f,h,t;return t=e,r=Gt(),r!==null?(f=Gt(),f!==null?(h=Gt(),h!==null?r=[r,f,h]:(r=null,e=t)):(r=null,e=t)):(r=null,e=t),r}function Wt(){var r,f,h,t,o,u,d;if(o=e,u=e,r=Ne(),r===null&&(r=hs()),r!==null){for(f=[],d=e,h=Se(),h!==null?(t=ze(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);h!==null;)f.push(h),d=e,h=Se(),h!==null?(t=ze(),t!==null?h=[h,t]:(h=null,e=d)):(h=null,e=d);f!==null?r=[r,f]:(r=null,e=u)}else r=null,e=u;return r!==null&&(r=function(T){try{b=new Vs(b.uri,b.display_name,b.params)}catch{b=-1}}()),r===null&&(e=o),r}function Fl(){var r,f,h,t,o,u;if(o=e,r=yi(),r!==null){for(f=[],u=e,h=Se(),h!==null?(t=Ai(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);h!==null;)f.push(h),u=e,h=Se(),h!==null?(t=Ai(),t!==null?h=[h,t]:(h=null,e=u)):(h=null,e=u);f!==null?r=[r,f]:(r=null,e=o)}else r=null,e=o;return r}function yi(){var r,f,h,t,o,u;return t=e,o=e,r=N(),r!==null?(u=e,l.charCodeAt(e)===64?(f="@",e++):(f=null,n('"@"')),f!==null?(h=N(),h!==null?f=[f,h]:(f=null,e=u)):(f=null,e=u),f=f!==null?f:"",f!==null?r=[r,f]:(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(d){b.call_id=l.substring(e,d)}(t)),r===null&&(e=t),r}function Ai(){var r;return r=jl(),r===null&&(r=Ci(),r===null&&(r=Xn(),r===null&&(r=ze()))),r}function jl(){var r,f,h,t,o;return t=e,o=e,l.substr(e,6)==="to-tag"?(r="to-tag",e+=6):(r=null,n('"to-tag"')),r!==null?(f=ae(),f!==null?(h=U(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u,d){b.to_tag=d}(t,r[2])),r===null&&(e=t),r}function Ci(){var r,f,h,t,o;return t=e,o=e,l.substr(e,8)==="from-tag"?(r="from-tag",e+=8):(r=null,n('"from-tag"')),r!==null?(f=ae(),f!==null?(h=U(),h!==null?r=[r,f,h]:(r=null,e=o)):(r=null,e=o)):(r=null,e=o),r!==null&&(r=function(u,d){b.from_tag=d}(t,r[2])),r===null&&(e=t),r}function Xn(){var r,f;return f=e,l.substr(e,10)==="early-only"?(r="early-only",e+=10):(r=null,n('"early-only"')),r!==null&&(r=function(h){b.early_only=!0}()),r===null&&(e=f),r}function ql(r){r.sort();for(var f=null,h=[],t=0;t<r.length;t++)r[t]!==f&&(h.push(r[t]),f=r[t]);return h}function Vl(){for(var r=1,f=1,h=!1,t=0;t<Math.max(e,p);t++){var o=l.charAt(t);o===`
4
+ `?(h||r++,f=1,h=!1):o==="\r"||o==="\u2028"||o==="\u2029"?(r++,f=1,h=!0):(f++,h=!1)}return{line:r,column:f}}var Ri=tn(),Vs=Ou(),b={},Bl=_[a]();if(Bl===null||e!==l.length){var rs=Math.max(e,p),w=rs<l.length?l.charAt(rs):null,Gl=Vl();return new this.SyntaxError(ql(g),w,rs,Gl.line,Gl.column),-1}return b},toSource:function(){return this._source}};return s.SyntaxError=function(i,l,a,_,e){function p(g,n){var v,S;switch(g.length){case 0:v="end of input";break;case 1:v=g[0];break;default:v=g.slice(0,g.length-1).join(", ")+" or "+g[g.length-1]}return S=n?c(n):"end of input","Expected "+v+" but "+S+" found."}this.name="SyntaxError",this.expected=i,this.found=l,this.message=p(i,l),this.offset=a,this.line=_,this.column=e},s.SyntaxError.prototype=Error.prototype,s}()),_o}var ho,Yu;function tn(){if(Yu)return ho;Yu=1;function c(n,v){var S;if(typeof Symbol>"u"||n[Symbol.iterator]==null){if(Array.isArray(n)||(S=s(n))||v&&n&&typeof n.length=="number"){S&&(n=S);var m=0,C=function(){};return{s:C,n:function(){return m>=n.length?{done:!0}:{done:!1,value:n[m++]}},e:function(W){throw W},f:C}}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 A=!0,R=!1,I;return{s:function(){S=n[Symbol.iterator]()},n:function(){var W=S.next();return A=W.done,W},e:function(W){R=!0,I=W},f:function(){try{!A&&S.return!=null&&S.return()}finally{if(R)throw I}}}}function s(n,v){if(n){if(typeof n=="string")return i(n,v);var S=Object.prototype.toString.call(n).slice(8,-1);if(S==="Object"&&n.constructor&&(S=n.constructor.name),S==="Map"||S==="Set")return Array.from(n);if(S==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(S))return i(n,v)}}function i(n,v){(v==null||v>n.length)&&(v=n.length);for(var S=0,m=new Array(v);S<v;S++)m[S]=n[S];return m}function l(n,v){if(!(n instanceof v))throw new TypeError("Cannot call a class as a function")}function a(n,v){for(var S=0;S<v.length;S++){var m=v[S];m.enumerable=m.enumerable||!1,m.configurable=!0,"value"in m&&(m.writable=!0),Object.defineProperty(n,m.key,m)}}function _(n,v,S){return v&&a(n.prototype,v),S&&a(n,S),n}var e=ot,p=Nt(),g=us();return ho=function(){_(n,null,[{key:"parse",value:function(S){if(S=g.parse(S,"SIP_URI"),S!==-1)return S}}]);function n(v,S,m,C){var A=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{},R=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{};if(l(this,n),!m)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=v||e.SIP,this._user=S,this._host=m,this._port=C;for(var I in A)Object.prototype.hasOwnProperty.call(A,I)&&this.setParam(I,A[I]);for(var V in R)Object.prototype.hasOwnProperty.call(R,V)&&this.setHeader(V,R[V])}return _(n,[{key:"setParam",value:function(S,m){S&&(this._parameters[S.toLowerCase()]=typeof m>"u"||m===null?null:m.toString())}},{key:"getParam",value:function(S){if(S)return this._parameters[S.toLowerCase()]}},{key:"hasParam",value:function(S){if(S)return this._parameters.hasOwnProperty(S.toLowerCase())&&!0||!1}},{key:"deleteParam",value:function(S){if(S=S.toLowerCase(),this._parameters.hasOwnProperty(S)){var m=this._parameters[S];return delete this._parameters[S],m}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"setHeader",value:function(S,m){this._headers[p.headerize(S)]=Array.isArray(m)?m:[m]}},{key:"getHeader",value:function(S){if(S)return this._headers[p.headerize(S)]}},{key:"hasHeader",value:function(S){if(S)return this._headers.hasOwnProperty(p.headerize(S))&&!0||!1}},{key:"deleteHeader",value:function(S){if(S=p.headerize(S),this._headers.hasOwnProperty(S)){var m=this._headers[S];return delete this._headers[S],m}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new n(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 S=[],m="".concat(this._scheme,":");this._user&&(m+="".concat(p.escapeUser(this._user),"@")),m+=this._host,(this._port||this._port===0)&&(m+=":".concat(this._port));for(var C in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,C)&&(m+=";".concat(C),this._parameters[C]!==null&&(m+="=".concat(this._parameters[C])));for(var A in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,A)){var R=c(this._headers[A]),I;try{for(R.s();!(I=R.n()).done;){var V=I.value;S.push("".concat(A,"=").concat(V))}}catch(W){R.e(W)}finally{R.f()}}return S.length>0&&(m+="?".concat(S.join("&"))),m}},{key:"toAor",value:function(S){var m="".concat(this._scheme,":");return this._user&&(m+="".concat(p.escapeUser(this._user),"@")),m+=this._host,S&&(this._port||this._port===0)&&(m+=":".concat(this._port)),m}},{key:"scheme",get:function(){return this._scheme},set:function(S){this._scheme=S.toLowerCase()}},{key:"user",get:function(){return this._user},set:function(S){this._user=S}},{key:"host",get:function(){return this._host},set:function(S){this._host=S.toLowerCase()}},{key:"port",get:function(){return this._port},set:function(S){this._port=S===0?S:parseInt(S,10)||null}}]),n}(),ho}var Ju;function Nt(){if(Ju)return nt;Ju=1;function c(v){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?c=function(m){return typeof m}:c=function(m){return m&&typeof Symbol=="function"&&m.constructor===Symbol&&m!==Symbol.prototype?"symbol":typeof m},c(v)}function s(v,S){var m;if(typeof Symbol>"u"||v[Symbol.iterator]==null){if(Array.isArray(v)||(m=i(v))||S&&v&&typeof v.length=="number"){m&&(v=m);var C=0,A=function(){};return{s:A,n:function(){return C>=v.length?{done:!0}:{done:!1,value:v[C++]}},e:function(oe){throw oe},f:A}}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 R=!0,I=!1,V;return{s:function(){m=v[Symbol.iterator]()},n:function(){var oe=m.next();return R=oe.done,oe},e:function(oe){I=!0,V=oe},f:function(){try{!R&&m.return!=null&&m.return()}finally{if(I)throw V}}}}function i(v,S){if(v){if(typeof v=="string")return l(v,S);var m=Object.prototype.toString.call(v).slice(8,-1);if(m==="Object"&&v.constructor&&(m=v.constructor.name),m==="Map"||m==="Set")return Array.from(v);if(m==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(m))return l(v,S)}}function l(v,S){(S==null||S>v.length)&&(S=v.length);for(var m=0,C=new Array(S);m<S;m++)C[m]=v[m];return C}var a=ot,_=tn(),e=us();nt.str_utf8_length=function(v){return unescape(encodeURIComponent(v)).length};var p=nt.isFunction=function(v){return v!==void 0?Object.prototype.toString.call(v)==="[object Function]":!1};nt.isString=function(v){return v!==void 0?Object.prototype.toString.call(v)==="[object String]":!1},nt.isDecimal=function(v){return!isNaN(v)&&parseFloat(v)===parseInt(v,10)},nt.isEmpty=function(v){return v===null||v===""||v===void 0||Array.isArray(v)&&v.length===0||typeof v=="number"&&isNaN(v)},nt.hasMethods=function(v){for(var S=arguments.length,m=new Array(S>1?S-1:0),C=1;C<S;C++)m[C-1]=arguments[C];for(var A=0,R=m;A<R.length;A++){var I=R[A];if(p(v[I]))return!1}return!0};var g=nt.createRandomToken=function(v){var S=arguments.length>1&&arguments[1]!==void 0?arguments[1]:32,m,C,A="";for(m=0;m<v;m++)C=Math.random()*S|0,A+=C.toString(S);return A};nt.newTag=function(){return g(10)},nt.newUUID=function(){var v="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(S){var m=Math.random()*16|0,C=S==="x"?m:m&3|8;return C.toString(16)});return v},nt.hostType=function(v){if(v){if(v=e.parse(v,"host"),v!==-1)return v.host_type}else return};var n=nt.escapeUser=function(v){return encodeURIComponent(decodeURIComponent(v)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/")};return nt.normalizeTarget=function(v,S){if(v){if(v instanceof _)return v;if(typeof v=="string"){var m=v.split("@"),C,A;switch(m.length){case 1:if(!S)return;C=v,A=S;break;case 2:C=m[0],A=m[1];break;default:C=m.slice(0,m.length-1).join("@"),A=m[m.length-1]}C=C.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(C)&&(C=C.replace(/[-.()]/g,"")),v="".concat(a.SIP,":").concat(n(C),"@").concat(A);var R;return(R=_.parse(v))?R:void 0}else return}else return},nt.headerize=function(v){var S={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},m=v.toLowerCase().replace(/_/g,"-").split("-"),C="",A=m.length,R;for(R=0;R<A;R++)R!==0&&(C+="-"),C+=m[R].charAt(0).toUpperCase()+m[R].substring(1);return S[C]&&(C=S[C]),C},nt.sipErrorCause=function(v){for(var S in a.SIP_ERROR_CAUSES)if(a.SIP_ERROR_CAUSES[S].indexOf(v)!==-1)return a.causes[S];return a.causes.SIP_FAILURE_CODE},nt.getRandomTestNetIP=function(){function v(S,m){return Math.floor(Math.random()*(m-S+1)+S)}return"192.0.2.".concat(v(1,254))},nt.calculateMD5=function(v){function S(ve,he){return ve<<he|ve>>>32-he}function m(ve,he){var pe=ve&2147483648,Ne=he&2147483648,xe=ve&1073741824,Ve=he&1073741824,He=(ve&1073741823)+(he&1073741823);return xe&Ve?He^2147483648^pe^Ne:xe|Ve?He&1073741824?He^3221225472^pe^Ne:He^1073741824^pe^Ne:He^pe^Ne}function C(ve,he,pe){return ve&he|~ve&pe}function A(ve,he,pe){return ve&pe|he&~pe}function R(ve,he,pe){return ve^he^pe}function I(ve,he,pe){return he^(ve|~pe)}function V(ve,he,pe,Ne,xe,Ve,He){return ve=m(ve,m(m(C(he,pe,Ne),xe),He)),m(S(ve,Ve),he)}function W(ve,he,pe,Ne,xe,Ve,He){return ve=m(ve,m(m(A(he,pe,Ne),xe),He)),m(S(ve,Ve),he)}function oe(ve,he,pe,Ne,xe,Ve,He){return ve=m(ve,m(m(R(he,pe,Ne),xe),He)),m(S(ve,Ve),he)}function x(ve,he,pe,Ne,xe,Ve,He){return ve=m(ve,m(m(I(he,pe,Ne),xe),He)),m(S(ve,Ve),he)}function $(ve){for(var he,pe=ve.length,Ne=pe+8,xe=(Ne-Ne%64)/64,Ve=(xe+1)*16,He=new Array(Ve-1),Ht=0,ct=0;ct<pe;)he=(ct-ct%4)/4,Ht=ct%4*8,He[he]=He[he]|ve.charCodeAt(ct)<<Ht,ct++;return he=(ct-ct%4)/4,Ht=ct%4*8,He[he]=He[he]|128<<Ht,He[Ve-2]=pe<<3,He[Ve-1]=pe>>>29,He}function Re(ve){var he="",pe="",Ne,xe;for(xe=0;xe<=3;xe++)Ne=ve>>>xe*8&255,pe="0".concat(Ne.toString(16)),he=he+pe.substr(pe.length-2,2);return he}function Ie(ve){for(var he="",pe=0;pe<ve.length;pe++){var Ne=ve.charCodeAt(pe);Ne<128?he+=String.fromCharCode(Ne):Ne>127&&Ne<2048?(he+=String.fromCharCode(Ne>>6|192),he+=String.fromCharCode(Ne&63|128)):(he+=String.fromCharCode(Ne>>12|224),he+=String.fromCharCode(Ne>>6&63|128),he+=String.fromCharCode(Ne&63|128))}return he}var H=[],D,L,q,j,B,X,Q,U,se,It=7,N=12,Y=17,re=22,ae=5,Te=9,De=14,Ce=20,Le=4,we=11,Se=16,it=23,Ue=6,le=10,Ae=15,Oe=21;for(v=Ie(v),H=$(v),X=1732584193,Q=4023233417,U=2562383102,se=271733878,D=0;D<H.length;D+=16)L=X,q=Q,j=U,B=se,X=V(X,Q,U,se,H[D+0],It,3614090360),se=V(se,X,Q,U,H[D+1],N,3905402710),U=V(U,se,X,Q,H[D+2],Y,606105819),Q=V(Q,U,se,X,H[D+3],re,3250441966),X=V(X,Q,U,se,H[D+4],It,4118548399),se=V(se,X,Q,U,H[D+5],N,1200080426),U=V(U,se,X,Q,H[D+6],Y,2821735955),Q=V(Q,U,se,X,H[D+7],re,4249261313),X=V(X,Q,U,se,H[D+8],It,1770035416),se=V(se,X,Q,U,H[D+9],N,2336552879),U=V(U,se,X,Q,H[D+10],Y,4294925233),Q=V(Q,U,se,X,H[D+11],re,2304563134),X=V(X,Q,U,se,H[D+12],It,1804603682),se=V(se,X,Q,U,H[D+13],N,4254626195),U=V(U,se,X,Q,H[D+14],Y,2792965006),Q=V(Q,U,se,X,H[D+15],re,1236535329),X=W(X,Q,U,se,H[D+1],ae,4129170786),se=W(se,X,Q,U,H[D+6],Te,3225465664),U=W(U,se,X,Q,H[D+11],De,643717713),Q=W(Q,U,se,X,H[D+0],Ce,3921069994),X=W(X,Q,U,se,H[D+5],ae,3593408605),se=W(se,X,Q,U,H[D+10],Te,38016083),U=W(U,se,X,Q,H[D+15],De,3634488961),Q=W(Q,U,se,X,H[D+4],Ce,3889429448),X=W(X,Q,U,se,H[D+9],ae,568446438),se=W(se,X,Q,U,H[D+14],Te,3275163606),U=W(U,se,X,Q,H[D+3],De,4107603335),Q=W(Q,U,se,X,H[D+8],Ce,1163531501),X=W(X,Q,U,se,H[D+13],ae,2850285829),se=W(se,X,Q,U,H[D+2],Te,4243563512),U=W(U,se,X,Q,H[D+7],De,1735328473),Q=W(Q,U,se,X,H[D+12],Ce,2368359562),X=oe(X,Q,U,se,H[D+5],Le,4294588738),se=oe(se,X,Q,U,H[D+8],we,2272392833),U=oe(U,se,X,Q,H[D+11],Se,1839030562),Q=oe(Q,U,se,X,H[D+14],it,4259657740),X=oe(X,Q,U,se,H[D+1],Le,2763975236),se=oe(se,X,Q,U,H[D+4],we,1272893353),U=oe(U,se,X,Q,H[D+7],Se,4139469664),Q=oe(Q,U,se,X,H[D+10],it,3200236656),X=oe(X,Q,U,se,H[D+13],Le,681279174),se=oe(se,X,Q,U,H[D+0],we,3936430074),U=oe(U,se,X,Q,H[D+3],Se,3572445317),Q=oe(Q,U,se,X,H[D+6],it,76029189),X=oe(X,Q,U,se,H[D+9],Le,3654602809),se=oe(se,X,Q,U,H[D+12],we,3873151461),U=oe(U,se,X,Q,H[D+15],Se,530742520),Q=oe(Q,U,se,X,H[D+2],it,3299628645),X=x(X,Q,U,se,H[D+0],Ue,4096336452),se=x(se,X,Q,U,H[D+7],le,1126891415),U=x(U,se,X,Q,H[D+14],Ae,2878612391),Q=x(Q,U,se,X,H[D+5],Oe,4237533241),X=x(X,Q,U,se,H[D+12],Ue,1700485571),se=x(se,X,Q,U,H[D+3],le,2399980690),U=x(U,se,X,Q,H[D+10],Ae,4293915773),Q=x(Q,U,se,X,H[D+1],Oe,2240044497),X=x(X,Q,U,se,H[D+8],Ue,1873313359),se=x(se,X,Q,U,H[D+15],le,4264355552),U=x(U,se,X,Q,H[D+6],Ae,2734768916),Q=x(Q,U,se,X,H[D+13],Oe,1309151649),X=x(X,Q,U,se,H[D+4],Ue,4149444226),se=x(se,X,Q,U,H[D+11],le,3174756917),U=x(U,se,X,Q,H[D+2],Ae,718787259),Q=x(Q,U,se,X,H[D+9],Oe,3951481745),X=m(X,L),Q=m(Q,q),U=m(U,j),se=m(se,B);var Pe=Re(X)+Re(Q)+Re(U)+Re(se);return Pe.toLowerCase()},nt.closeMediaStream=function(v){if(v)try{var S;if(v.getTracks){S=v.getTracks();var m=s(S),C;try{for(m.s();!(C=m.n()).done;){var A=C.value;A.stop()}}catch($){m.e($)}finally{m.f()}}else{S=v.getAudioTracks();var R=s(S),I;try{for(R.s();!(I=R.n()).done;){var V=I.value;V.stop()}}catch($){R.e($)}finally{R.f()}S=v.getVideoTracks();var W=s(S),oe;try{for(W.s();!(oe=W.n()).done;){var x=oe.value;x.stop()}}catch($){W.e($)}finally{W.f()}}}catch{(typeof v.stop=="function"||c(v.stop)==="object")&&v.stop()}},nt.cloneArray=function(v){return v&&v.slice()||[]},nt.cloneObject=function(v){var S=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return v&&Object.assign({},v)||S},nt}var Du={exports:{}},lr=typeof Reflect=="object"?Reflect:null,zu=lr&&typeof lr.apply=="function"?lr.apply:function(s,i,l){return Function.prototype.apply.call(s,i,l)},Ca;lr&&typeof lr.ownKeys=="function"?Ca=lr.ownKeys:Object.getOwnPropertySymbols?Ca=function(s){return Object.getOwnPropertyNames(s).concat(Object.getOwnPropertySymbols(s))}:Ca=function(s){return Object.getOwnPropertyNames(s)};function oh(c){console&&console.warn&&console.warn(c)}var Bf=Number.isNaN||function(s){return s!==s};function je(){je.init.call(this)}Du.exports=je;Du.exports.once=_h;je.EventEmitter=je;je.prototype._events=void 0;je.prototype._eventsCount=0;je.prototype._maxListeners=void 0;var Xu=10;function Xa(c){if(typeof c!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof c)}Object.defineProperty(je,"defaultMaxListeners",{enumerable:!0,get:function(){return Xu},set:function(c){if(typeof c!="number"||c<0||Bf(c))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+c+".");Xu=c}});je.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};je.prototype.setMaxListeners=function(s){if(typeof s!="number"||s<0||Bf(s))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+s+".");return this._maxListeners=s,this};function Gf(c){return c._maxListeners===void 0?je.defaultMaxListeners:c._maxListeners}je.prototype.getMaxListeners=function(){return Gf(this)};je.prototype.emit=function(s){for(var i=[],l=1;l<arguments.length;l++)i.push(arguments[l]);var a=s==="error",_=this._events;if(_!==void 0)a=a&&_.error===void 0;else if(!a)return!1;if(a){var e;if(i.length>0&&(e=i[0]),e instanceof Error)throw e;var p=new Error("Unhandled error."+(e?" ("+e.message+")":""));throw p.context=e,p}var g=_[s];if(g===void 0)return!1;if(typeof g=="function")zu(g,this,i);else for(var n=g.length,v=zf(g,n),l=0;l<n;++l)zu(v[l],this,i);return!0};function Wf(c,s,i,l){var a,_,e;if(Xa(i),_=c._events,_===void 0?(_=c._events=Object.create(null),c._eventsCount=0):(_.newListener!==void 0&&(c.emit("newListener",s,i.listener?i.listener:i),_=c._events),e=_[s]),e===void 0)e=_[s]=i,++c._eventsCount;else if(typeof e=="function"?e=_[s]=l?[i,e]:[e,i]:l?e.unshift(i):e.push(i),a=Gf(c),a>0&&e.length>a&&!e.warned){e.warned=!0;var p=new Error("Possible EventEmitter memory leak detected. "+e.length+" "+String(s)+" listeners added. Use emitter.setMaxListeners() to increase limit");p.name="MaxListenersExceededWarning",p.emitter=c,p.type=s,p.count=e.length,oh(p)}return c}je.prototype.addListener=function(s,i){return Wf(this,s,i,!1)};je.prototype.on=je.prototype.addListener;je.prototype.prependListener=function(s,i){return Wf(this,s,i,!0)};function uh(){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 Kf(c,s,i){var l={fired:!1,wrapFn:void 0,target:c,type:s,listener:i},a=uh.bind(l);return a.listener=i,l.wrapFn=a,a}je.prototype.once=function(s,i){return Xa(i),this.on(s,Kf(this,s,i)),this};je.prototype.prependOnceListener=function(s,i){return Xa(i),this.prependListener(s,Kf(this,s,i)),this};je.prototype.removeListener=function(s,i){var l,a,_,e,p;if(Xa(i),a=this._events,a===void 0)return this;if(l=a[s],l===void 0)return this;if(l===i||l.listener===i)--this._eventsCount===0?this._events=Object.create(null):(delete a[s],a.removeListener&&this.emit("removeListener",s,l.listener||i));else if(typeof l!="function"){for(_=-1,e=l.length-1;e>=0;e--)if(l[e]===i||l[e].listener===i){p=l[e].listener,_=e;break}if(_<0)return this;_===0?l.shift():ch(l,_),l.length===1&&(a[s]=l[0]),a.removeListener!==void 0&&this.emit("removeListener",s,p||i)}return this};je.prototype.off=je.prototype.removeListener;je.prototype.removeAllListeners=function(s){var i,l,a;if(l=this._events,l===void 0)return this;if(l.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):l[s]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete l[s]),this;if(arguments.length===0){var _=Object.keys(l),e;for(a=0;a<_.length;++a)e=_[a],e!=="removeListener"&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(i=l[s],typeof i=="function")this.removeListener(s,i);else if(i!==void 0)for(a=i.length-1;a>=0;a--)this.removeListener(s,i[a]);return this};function Yf(c,s,i){var l=c._events;if(l===void 0)return[];var a=l[s];return a===void 0?[]:typeof a=="function"?i?[a.listener||a]:[a]:i?fh(a):zf(a,a.length)}je.prototype.listeners=function(s){return Yf(this,s,!0)};je.prototype.rawListeners=function(s){return Yf(this,s,!1)};je.listenerCount=function(c,s){return typeof c.listenerCount=="function"?c.listenerCount(s):Jf.call(c,s)};je.prototype.listenerCount=Jf;function Jf(c){var s=this._events;if(s!==void 0){var i=s[c];if(typeof i=="function")return 1;if(i!==void 0)return i.length}return 0}je.prototype.eventNames=function(){return this._eventsCount>0?Ca(this._events):[]};function zf(c,s){for(var i=new Array(s),l=0;l<s;++l)i[l]=c[l];return i}function ch(c,s){for(;s+1<c.length;s++)c[s]=c[s+1];c.pop()}function fh(c){for(var s=new Array(c.length),i=0;i<s.length;++i)s[i]=c[i].listener||c[i];return s}function _h(c,s){return new Promise(function(i,l){function a(e){c.removeListener(s,_),l(e)}function _(){typeof c.removeListener=="function"&&c.removeListener("error",a),i([].slice.call(arguments))}Xf(c,s,_,{once:!0}),s!=="error"&&hh(c,a,{once:!0})})}function hh(c,s,i){typeof c.on=="function"&&Xf(c,"error",s,i)}function Xf(c,s,i,l){if(typeof c.on=="function")l.once?c.once(s,i):c.on(s,i);else if(typeof c.addEventListener=="function")c.addEventListener(s,function a(_){l.once&&c.removeEventListener(s,a),i(_)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof c)}var ht=Du.exports,uu={exports:{}},po,Qu;function dh(){if(Qu)return po;Qu=1;var c=1e3,s=c*60,i=s*60,l=i*24,a=l*7,_=l*365.25;po=function(v,S){S=S||{};var m=typeof v;if(m==="string"&&v.length>0)return e(v);if(m==="number"&&isFinite(v))return S.long?g(v):p(v);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(v))};function e(v){if(v=String(v),!(v.length>100)){var S=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(v);if(S){var m=parseFloat(S[1]),C=(S[2]||"ms").toLowerCase();switch(C){case"years":case"year":case"yrs":case"yr":case"y":return m*_;case"weeks":case"week":case"w":return m*a;case"days":case"day":case"d":return m*l;case"hours":case"hour":case"hrs":case"hr":case"h":return m*i;case"minutes":case"minute":case"mins":case"min":case"m":return m*s;case"seconds":case"second":case"secs":case"sec":case"s":return m*c;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return m;default:return}}}}function p(v){var S=Math.abs(v);return S>=l?Math.round(v/l)+"d":S>=i?Math.round(v/i)+"h":S>=s?Math.round(v/s)+"m":S>=c?Math.round(v/c)+"s":v+"ms"}function g(v){var S=Math.abs(v);return S>=l?n(v,S,l,"day"):S>=i?n(v,S,i,"hour"):S>=s?n(v,S,s,"minute"):S>=c?n(v,S,c,"second"):v+" ms"}function n(v,S,m,C){var A=S>=m*1.5;return Math.round(v/m)+" "+C+(A?"s":"")}return po}function ph(c){i.debug=i,i.default=i,i.coerce=g,i.disable=_,i.enable=a,i.enabled=e,i.humanize=dh(),i.destroy=n,Object.keys(c).forEach(v=>{i[v]=c[v]}),i.names=[],i.skips=[],i.formatters={};function s(v){let S=0;for(let m=0;m<v.length;m++)S=(S<<5)-S+v.charCodeAt(m),S|=0;return i.colors[Math.abs(S)%i.colors.length]}i.selectColor=s;function i(v){let S,m=null,C,A;function R(...I){if(!R.enabled)return;const V=R,W=Number(new Date),oe=W-(S||W);V.diff=oe,V.prev=S,V.curr=W,S=W,I[0]=i.coerce(I[0]),typeof I[0]!="string"&&I.unshift("%O");let x=0;I[0]=I[0].replace(/%([a-zA-Z%])/g,(Re,Ie)=>{if(Re==="%%")return"%";x++;const H=i.formatters[Ie];if(typeof H=="function"){const D=I[x];Re=H.call(V,D),I.splice(x,1),x--}return Re}),i.formatArgs.call(V,I),(V.log||i.log).apply(V,I)}return R.namespace=v,R.useColors=i.useColors(),R.color=i.selectColor(v),R.extend=l,R.destroy=i.destroy,Object.defineProperty(R,"enabled",{enumerable:!0,configurable:!1,get:()=>m!==null?m:(C!==i.namespaces&&(C=i.namespaces,A=i.enabled(v)),A),set:I=>{m=I}}),typeof i.init=="function"&&i.init(R),R}function l(v,S){const m=i(this.namespace+(typeof S>"u"?":":S)+v);return m.log=this.log,m}function a(v){i.save(v),i.namespaces=v,i.names=[],i.skips=[];let S;const m=(typeof v=="string"?v:"").split(/[\s,]+/),C=m.length;for(S=0;S<C;S++)m[S]&&(v=m[S].replace(/\*/g,".*?"),v[0]==="-"?i.skips.push(new RegExp("^"+v.slice(1)+"$")):i.names.push(new RegExp("^"+v+"$")))}function _(){const v=[...i.names.map(p),...i.skips.map(p).map(S=>"-"+S)].join(",");return i.enable(""),v}function e(v){if(v[v.length-1]==="*")return!0;let S,m;for(S=0,m=i.skips.length;S<m;S++)if(i.skips[S].test(v))return!1;for(S=0,m=i.names.length;S<m;S++)if(i.names[S].test(v))return!0;return!1}function p(v){return v.toString().substring(2,v.toString().length-2).replace(/\.\*\?$/,"*")}function g(v){return v instanceof Error?v.stack||v.message:v}function n(){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 i.enable(i.load()),i}var mh=ph;(function(c,s){s.formatArgs=l,s.save=a,s.load=_,s.useColors=i,s.storage=e(),s.destroy=(()=>{let g=!1;return()=>{g||(g=!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`."))}})(),s.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 i(){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 l(g){if(g[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+g[0]+(this.useColors?"%c ":" ")+"+"+c.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;g.splice(1,0,n,"color: inherit");let v=0,S=0;g[0].replace(/%[a-zA-Z%]/g,m=>{m!=="%%"&&(v++,m==="%c"&&(S=v))}),g.splice(S,0,n)}s.log=console.debug||console.log||(()=>{});function a(g){try{g?s.storage.setItem("debug",g):s.storage.removeItem("debug")}catch{}}function _(){let g;try{g=s.storage.getItem("debug")}catch{}return!g&&typeof process<"u"&&"env"in process&&(g=process.env.DEBUG),g}function e(){try{return localStorage}catch{}}c.exports=mh(s);const{formatters:p}=c.exports;p.j=function(g){try{return JSON.stringify(g)}catch(n){return"[UnexpectedJSONParseError]: "+n.message}}})(uu,uu.exports);var ur=uu.exports;function gh(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function Zu(c,s){for(var i=0;i<s.length;i++){var l=s[i];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(c,l.key,l)}}function Th(c,s,i){return s&&Zu(c.prototype,s),i&&Zu(c,i),c}var Qn=ur,Zn="JsSIP",dt=function(){function c(s){gh(this,c),s?(this._debug=Qn.default("".concat(Zn,":").concat(s)),this._warn=Qn.default("".concat(Zn,":WARN:").concat(s)),this._error=Qn.default("".concat(Zn,":ERROR:").concat(s))):(this._debug=Qn.default(Zn),this._warn=Qn.default("".concat(Zn,":WARN")),this._error=Qn.default("".concat(Zn,":ERROR"))),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}return Th(c,[{key:"debug",get:function(){return this._debug}},{key:"warn",get:function(){return this._warn}},{key:"error",get:function(){return this._error}}]),c}(),kt={},Qf={},Zf={exports:{}},ec=Zf.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 s="candidate:%s %d %s %d %s %d typ %s";return s+=c.raddr!=null?" raddr %s rport %d":"%v%v",s+=c.tcptype!=null?" tcptype %s":"%v",c.generation!=null&&(s+=" generation %d"),s+=c["network-id"]!=null?" network-id %d":"%v",s+=c["network-cost"]!=null?" network-cost %d":"%v",s}},{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 s="ssrc:%d";return c.attribute!=null&&(s+=" %s",c.value!=null&&(s+=":%s")),s}},{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 s="mediaclk:";return s+=c.id!=null?"id=%s %s":"%v%s",s+=c.mediaClockValue!=null?"=%s":"",s+=c.rateNumerator!=null?" rate=%s":"",s+=c.rateDenominator!=null?"/%s":"",s}},{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(ec).forEach(function(c){var s=ec[c];s.forEach(function(i){i.reg||(i.reg=/(.*)/),i.format||(i.format="%s")})});var e_=Zf.exports;(function(c){var s=function(p){return String(Number(p))===p?Number(p):p},i=function(p,g,n,v){if(v&&!n)g[v]=s(p[1]);else for(var S=0;S<n.length;S+=1)p[S+1]!=null&&(g[n[S]]=s(p[S+1]))},l=function(p,g,n){var v=p.name&&p.names;p.push&&!g[p.push]?g[p.push]=[]:v&&!g[p.name]&&(g[p.name]={});var S=p.push?{}:v?g[p.name]:g;i(n.match(p.reg),S,p.names,p.name),p.push&&g[p.push].push(S)},a=e_,_=RegExp.prototype.test.bind(/^([a-z])=(.*)/);c.parse=function(p){var g={},n=[],v=g;return p.split(/(\r\n|\r|\n)/).filter(_).forEach(function(S){var m=S[0],C=S.slice(2);m==="m"&&(n.push({rtp:[],fmtp:[]}),v=n[n.length-1]);for(var A=0;A<(a[m]||[]).length;A+=1){var R=a[m][A];if(R.reg.test(C))return l(R,v,C)}}),g.media=n,g};var e=function(p,g){var n=g.split(/=(.+)/,2);return n.length===2?p[n[0]]=s(n[1]):n.length===1&&g.length>1&&(p[n[0]]=void 0),p};c.parseParams=function(p){return p.split(/;\s?/).reduce(e,{})},c.parseFmtpConfig=c.parseParams,c.parsePayloads=function(p){return p.toString().split(" ").map(Number)},c.parseRemoteCandidates=function(p){for(var g=[],n=p.split(" ").map(s),v=0;v<n.length;v+=3)g.push({component:n[v],ip:n[v+1],port:n[v+2]});return g},c.parseImageAttributes=function(p){return p.split(" ").map(function(g){return g.substring(1,g.length-1).split(",").reduce(e,{})})},c.parseSimulcastStreamList=function(p){return p.split(";").map(function(g){return g.split(",").map(function(n){var v,S=!1;return n[0]!=="~"?v=s(n):(v=s(n.substring(1,n.length)),S=!0),{scid:v,paused:S}})})}})(Qf);var mo=e_,vh=/%[sdv%]/g,Eh=function(c){var s=1,i=arguments,l=i.length;return c.replace(vh,function(a){if(s>=l)return a;var _=i[s];switch(s+=1,a){case"%%":return"%";case"%s":return String(_);case"%d":return Number(_);case"%v":return""}})},bi=function(c,s,i){var l=s.format instanceof Function?s.format(s.push?i:i[s.name]):s.format,a=[c+"="+l];if(s.names)for(var _=0;_<s.names.length;_+=1){var e=s.names[_];s.name?a.push(i[s.name][e]):a.push(i[s.names[_]])}else a.push(i[s.name]);return Eh.apply(null,a)},Sh=["v","o","s","i","u","e","p","c","b","t","r","z","a"],yh=["i","c","b","a"],Ah=function(c,s){s=s||{},c.version==null&&(c.version=0),c.name==null&&(c.name=" "),c.media.forEach(function(_){_.payloads==null&&(_.payloads="")});var i=s.outerOrder||Sh,l=s.innerOrder||yh,a=[];return i.forEach(function(_){mo[_].forEach(function(e){e.name in c&&c[e.name]!=null?a.push(bi(_,e,c)):e.push in c&&c[e.push]!=null&&c[e.push].forEach(function(p){a.push(bi(_,e,p))})})}),c.media.forEach(function(_){a.push(bi("m",mo.m[0],_)),l.forEach(function(e){mo[e].forEach(function(p){p.name in _&&_[p.name]!=null?a.push(bi(e,p,_)):p.push in _&&_[p.push]!=null&&_[p.push].forEach(function(g){a.push(bi(e,p,g))})})})}),a.join(`\r
7
7
  `)+`\r
8
- `},Cn=Yf,vh=Th;Pt.write=vh;Pt.parse=Cn.parse;Pt.parseParams=Cn.parseParams;Pt.parseFmtpConfig=Cn.parseFmtpConfig;Pt.parsePayloads=Cn.parsePayloads;Pt.parseRemoteCandidates=Cn.parseRemoteCandidates;Pt.parseImageAttributes=Cn.parseImageAttributes;Pt.parseSimulcastStreamList=Cn.parseSimulcastStreamList;function po(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?po=function(r){return typeof r}:po=function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},po(c)}function Iu(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&lu(c,s)}function lu(c,s){return lu=Object.setPrototypeOf||function(o,a){return o.__proto__=a,o},lu(c,s)}function bu(c){var s=yh();return function(){var o=Io(c),a;if(s){var t=Io(this).constructor;a=Reflect.construct(o,arguments,t)}else a=o.apply(this,arguments);return Eh(this,a)}}function Eh(c,s){return s&&(po(s)==="object"||typeof s=="function")?s:Sh(c)}function Sh(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function yh(){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 Io(c){return Io=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)},Io(c)}function Vt(c,s){var r;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(r=Ah(c))||s&&c&&typeof c.length=="number"){r&&(c=r);var o=0,a=function(){};return{s:a,n:function(){return o>=c.length?{done:!0}:{done:!1,value:c[o++]}},e:function(h){throw h},f:a}}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 t=!0,n=!1,d;return{s:function(){r=c[Symbol.iterator]()},n:function(){var h=r.next();return t=h.done,h},e:function(h){n=!0,d=h},f:function(){try{!t&&r.return!=null&&r.return()}finally{if(n)throw d}}}}function Ah(c,s){if(c){if(typeof c=="string")return Qu(c,s);var r=Object.prototype.toString.call(c).slice(8,-1);if(r==="Object"&&c.constructor&&(r=c.constructor.name),r==="Map"||r==="Set")return Array.from(c);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return Qu(c,s)}}function Qu(c,s){(s==null||s>c.length)&&(s=c.length);for(var r=0,o=new Array(s);r<s;r++)o[r]=c[r];return o}function tl(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function Zu(c,s){for(var r=0;r<s.length;r++){var o=s[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function qo(c,s,r){return s&&Zu(c.prototype,s),r&&Zu(c,r),c}var Xf=Pt,Ch=_t,Et=it,nt=bt(),ec=Cu(),Rh=is(),_a=new Ch("SIPMessage"),Qf=function(){function c(s,r,o,a,t,n){if(tl(this,c),!s||!r||!o)return null;a=a||{},this.ua=o,this.headers={},this.method=s,this.ruri=r,this.body=n,this.extraHeaders=nt.cloneArray(t),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),a.route_set?this.setHeader("route",a.route_set):o.configuration.use_preloaded_route&&this.setHeader("route","<".concat(o.transport.sip_uri,";lr>")),this.setHeader("via",""),this.setHeader("max-forwards",Et.MAX_FORWARDS);var d=a.to_uri||r,_=a.to_tag?{tag:a.to_tag}:null,h=typeof a.to_display_name<"u"?a.to_display_name:null;this.to=new ec(d,h,_),this.setHeader("to",this.to.toString());var g=a.from_uri||o.configuration.uri,T={tag:a.from_tag||nt.newTag()},E;typeof a.from_display_name<"u"?E=a.from_display_name:o.configuration.display_name?E=o.configuration.display_name:E=null,this.from=new ec(g,E,T),this.setHeader("from",this.from.toString());var y=a.call_id||o.configuration.jssip_id+nt.createRandomToken(15);this.call_id=y,this.setHeader("call-id",y);var A=a.cseq||Math.floor(Math.random()*1e4);this.cseq=A,this.setHeader("cseq","".concat(A," ").concat(s))}return qo(c,[{key:"setHeader",value:function(r,o){for(var a=new RegExp("^\\s*".concat(r,"\\s*:"),"i"),t=0;t<this.extraHeaders.length;t++)a.test(this.extraHeaders[t])&&this.extraHeaders.splice(t,1);this.headers[nt.headerize(r)]=Array.isArray(o)?o:[o]}},{key:"getHeader",value:function(r){var o=this.headers[nt.headerize(r)];if(o){if(o[0])return o[0]}else{var a=new RegExp("^\\s*".concat(r,"\\s*:"),"i"),t=Vt(this.extraHeaders),n;try{for(t.s();!(n=t.n()).done;){var d=n.value;if(a.test(d))return d.substring(d.indexOf(":")+1).trim()}}catch(_){t.e(_)}finally{t.f()}}}},{key:"getHeaders",value:function(r){var o=this.headers[nt.headerize(r)],a=[];if(o){var t=Vt(o),n;try{for(t.s();!(n=t.n()).done;){var d=n.value;a.push(d)}}catch(E){t.e(E)}finally{t.f()}return a}else{var _=new RegExp("^\\s*".concat(r,"\\s*:"),"i"),h=Vt(this.extraHeaders),g;try{for(h.s();!(g=h.n()).done;){var T=g.value;_.test(T)&&a.push(T.substring(T.indexOf(":")+1).trim())}}catch(E){h.e(E)}finally{h.f()}return a}}},{key:"hasHeader",value:function(r){if(this.headers[nt.headerize(r)])return!0;var o=new RegExp("^\\s*".concat(r,"\\s*:"),"i"),a=Vt(this.extraHeaders),t;try{for(a.s();!(t=a.n()).done;){var n=t.value;if(o.test(n))return!0}}catch(d){a.e(d)}finally{a.f()}return!1}},{key:"parseSDP",value:function(r){return!r&&this.sdp?this.sdp:(this.sdp=Xf.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){var r="".concat(this.method," ").concat(this.ruri,` SIP/2.0\r
10
- `);for(var o in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,o)){var a=Vt(this.headers[o]),t;try{for(a.s();!(t=a.n()).done;){var n=t.value;r+="".concat(o,": ").concat(n,`\r
11
- `)}}catch(y){a.e(y)}finally{a.f()}}var d=Vt(this.extraHeaders),_;try{for(d.s();!(_=d.n()).done;){var h=_.value;r+="".concat(h.trim(),`\r
12
- `)}}catch(y){d.e(y)}finally{d.f()}var g=[];switch(this.method){case Et.REGISTER:g.push("path","gruu");break;case Et.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 Et.UPDATE:this.ua.configuration.session_timers&&g.push("timer"),g.push("ice");break}g.push("outbound");var T=this.ua.configuration.user_agent||Et.USER_AGENT;if(r+="Allow: ".concat(Et.ALLOWED_METHODS,`\r
13
- `),r+="Supported: ".concat(g,`\r
14
- `),r+="User-Agent: ".concat(T,`\r
15
- `),this.body){var E=nt.str_utf8_length(this.body);r+="Content-Length: ".concat(E,`\r
8
+ `},xn=Qf,Ch=Ah;kt.write=Ch;kt.parse=xn.parse;kt.parseParams=xn.parseParams;kt.parseFmtpConfig=xn.parseFmtpConfig;kt.parsePayloads=xn.parsePayloads;kt.parseRemoteCandidates=xn.parseRemoteCandidates;kt.parseImageAttributes=xn.parseImageAttributes;kt.parseSimulcastStreamList=xn.parseSimulcastStreamList;function Ra(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ra=function(i){return typeof i}:Ra=function(i){return i&&typeof Symbol=="function"&&i.constructor===Symbol&&i!==Symbol.prototype?"symbol":typeof i},Ra(c)}function Nu(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&cu(c,s)}function cu(c,s){return cu=Object.setPrototypeOf||function(l,a){return l.__proto__=a,l},cu(c,s)}function Uu(c){var s=bh();return function(){var l=ka(c),a;if(s){var _=ka(this).constructor;a=Reflect.construct(l,arguments,_)}else a=l.apply(this,arguments);return Rh(this,a)}}function Rh(c,s){return s&&(Ra(s)==="object"||typeof s=="function")?s:Ih(c)}function Ih(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function bh(){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 ka(c){return ka=Object.setPrototypeOf?Object.getPrototypeOf:function(i){return i.__proto__||Object.getPrototypeOf(i)},ka(c)}function qt(c,s){var i;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(i=wh(c))||s&&c&&typeof c.length=="number"){i&&(c=i);var l=0,a=function(){};return{s:a,n:function(){return l>=c.length?{done:!0}:{done:!1,value:c[l++]}},e:function(n){throw n},f:a}}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 _=!0,e=!1,p;return{s:function(){i=c[Symbol.iterator]()},n:function(){var n=i.next();return _=n.done,n},e:function(n){e=!0,p=n},f:function(){try{!_&&i.return!=null&&i.return()}finally{if(e)throw p}}}}function wh(c,s){if(c){if(typeof c=="string")return tc(c,s);var i=Object.prototype.toString.call(c).slice(8,-1);if(i==="Object"&&c.constructor&&(i=c.constructor.name),i==="Map"||i==="Set")return Array.from(c);if(i==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return tc(c,s)}}function tc(c,s){(s==null||s>c.length)&&(s=c.length);for(var i=0,l=new Array(s);i<s;i++)l[i]=c[i];return l}function tl(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function sc(c,s){for(var i=0;i<s.length;i++){var l=s[i];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(c,l.key,l)}}function Qa(c,s,i){return s&&sc(c.prototype,s),i&&sc(c,i),c}var t_=kt,Oh=dt,yt=ot,lt=Nt(),nc=Ou(),Dh=us(),go=new Oh("SIPMessage"),s_=function(){function c(s,i,l,a,_,e){if(tl(this,c),!s||!i||!l)return null;a=a||{},this.ua=l,this.headers={},this.method=s,this.ruri=i,this.body=e,this.extraHeaders=lt.cloneArray(_),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),a.route_set?this.setHeader("route",a.route_set):l.configuration.use_preloaded_route&&this.setHeader("route","<".concat(l.transport.sip_uri,";lr>")),this.setHeader("via",""),this.setHeader("max-forwards",yt.MAX_FORWARDS);var p=a.to_uri||i,g=a.to_tag?{tag:a.to_tag}:null,n=typeof a.to_display_name<"u"?a.to_display_name:null;this.to=new nc(p,n,g),this.setHeader("to",this.to.toString());var v=a.from_uri||l.configuration.uri,S={tag:a.from_tag||lt.newTag()},m;typeof a.from_display_name<"u"?m=a.from_display_name:l.configuration.display_name?m=l.configuration.display_name:m=null,this.from=new nc(v,m,S),this.setHeader("from",this.from.toString());var C=a.call_id||l.configuration.jssip_id+lt.createRandomToken(15);this.call_id=C,this.setHeader("call-id",C);var A=a.cseq||Math.floor(Math.random()*1e4);this.cseq=A,this.setHeader("cseq","".concat(A," ").concat(s))}return Qa(c,[{key:"setHeader",value:function(i,l){for(var a=new RegExp("^\\s*".concat(i,"\\s*:"),"i"),_=0;_<this.extraHeaders.length;_++)a.test(this.extraHeaders[_])&&this.extraHeaders.splice(_,1);this.headers[lt.headerize(i)]=Array.isArray(l)?l:[l]}},{key:"getHeader",value:function(i){var l=this.headers[lt.headerize(i)];if(l){if(l[0])return l[0]}else{var a=new RegExp("^\\s*".concat(i,"\\s*:"),"i"),_=qt(this.extraHeaders),e;try{for(_.s();!(e=_.n()).done;){var p=e.value;if(a.test(p))return p.substring(p.indexOf(":")+1).trim()}}catch(g){_.e(g)}finally{_.f()}}}},{key:"getHeaders",value:function(i){var l=this.headers[lt.headerize(i)],a=[];if(l){var _=qt(l),e;try{for(_.s();!(e=_.n()).done;){var p=e.value;a.push(p)}}catch(m){_.e(m)}finally{_.f()}return a}else{var g=new RegExp("^\\s*".concat(i,"\\s*:"),"i"),n=qt(this.extraHeaders),v;try{for(n.s();!(v=n.n()).done;){var S=v.value;g.test(S)&&a.push(S.substring(S.indexOf(":")+1).trim())}}catch(m){n.e(m)}finally{n.f()}return a}}},{key:"hasHeader",value:function(i){if(this.headers[lt.headerize(i)])return!0;var l=new RegExp("^\\s*".concat(i,"\\s*:"),"i"),a=qt(this.extraHeaders),_;try{for(a.s();!(_=a.n()).done;){var e=_.value;if(l.test(e))return!0}}catch(p){a.e(p)}finally{a.f()}return!1}},{key:"parseSDP",value:function(i){return!i&&this.sdp?this.sdp:(this.sdp=t_.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){var i="".concat(this.method," ").concat(this.ruri,` SIP/2.0\r
10
+ `);for(var l in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,l)){var a=qt(this.headers[l]),_;try{for(a.s();!(_=a.n()).done;){var e=_.value;i+="".concat(l,": ").concat(e,`\r
11
+ `)}}catch(C){a.e(C)}finally{a.f()}}var p=qt(this.extraHeaders),g;try{for(p.s();!(g=p.n()).done;){var n=g.value;i+="".concat(n.trim(),`\r
12
+ `)}}catch(C){p.e(C)}finally{p.f()}var v=[];switch(this.method){case yt.REGISTER:v.push("path","gruu");break;case yt.INVITE:this.ua.configuration.session_timers&&v.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&v.push("gruu"),v.push("ice","replaces");break;case yt.UPDATE:this.ua.configuration.session_timers&&v.push("timer"),v.push("ice");break}v.push("outbound");var S=this.ua.configuration.user_agent||yt.USER_AGENT;if(i+="Allow: ".concat(yt.ALLOWED_METHODS,`\r
13
+ `),i+="Supported: ".concat(v,`\r
14
+ `),i+="User-Agent: ".concat(S,`\r
15
+ `),this.body){var m=lt.str_utf8_length(this.body);i+="Content-Length: ".concat(m,`\r
16
16
  \r
17
- `),r+=this.body}else r+=`Content-Length: 0\r
17
+ `),i+=this.body}else i+=`Content-Length: 0\r
18
18
  \r
19
- `;return r}},{key:"clone",value:function(){var r=new c(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(o){r.headers[o]=this.headers[o].slice()},this),r.body=this.body,r.extraHeaders=nt.cloneArray(this.extraHeaders),r.to=this.to,r.from=this.from,r.call_id=this.call_id,r.cseq=this.cseq,r}}]),c}(),Ih=function(c){Iu(r,c);var s=bu(r);function r(o,a,t,n,d){var _;return tl(this,r),_=s.call(this,Et.INVITE,o,a,t,n,d),_.transaction=null,_}return qo(r,[{key:"cancel",value:function(a){this.transaction.cancel(a)}},{key:"clone",value:function(){var a=new r(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(t){a.headers[t]=this.headers[t].slice()},this),a.body=this.body,a.extraHeaders=nt.cloneArray(this.extraHeaders),a.to=this.to,a.from=this.from,a.call_id=this.call_id,a.cseq=this.cseq,a.transaction=this.transaction,a}}]),r}(Qf),Zf=function(){function c(){tl(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 qo(c,[{key:"addHeader",value:function(r,o){var a={raw:o};r=nt.headerize(r),this.headers[r]?this.headers[r].push(a):this.headers[r]=[a]}},{key:"getHeader",value:function(r){var o=this.headers[nt.headerize(r)];if(o){if(o[0])return o[0].raw}else return}},{key:"getHeaders",value:function(r){var o=this.headers[nt.headerize(r)],a=[];if(!o)return[];var t=Vt(o),n;try{for(t.s();!(n=t.n()).done;){var d=n.value;a.push(d.raw)}}catch(_){t.e(_)}finally{t.f()}return a}},{key:"hasHeader",value:function(r){return!!this.headers[nt.headerize(r)]}},{key:"parseHeader",value:function(r){var o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(r=nt.headerize(r),this.headers[r]){if(o>=this.headers[r].length){_a.debug('not so many "'.concat(r,'" headers present'));return}}else{_a.debug('header "'.concat(r,'" not present'));return}var a=this.headers[r][o],t=a.raw;if(a.parsed)return a.parsed;var n=Rh.parse(t,r.replace(/-/g,"_"));if(n===-1){this.headers[r].splice(o,1),_a.debug('error parsing "'.concat(r,'" header field with value "').concat(t,'"'));return}else return a.parsed=n,n}},{key:"s",value:function(r,o){return this.parseHeader(r,o)}},{key:"setHeader",value:function(r,o){var a={raw:o};this.headers[nt.headerize(r)]=[a]}},{key:"parseSDP",value:function(r){return!r&&this.sdp?this.sdp:(this.sdp=Xf.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}]),c}(),bh=function(c){Iu(r,c);var s=bu(r);function r(o){var a;return tl(this,r),a=s.call(this),a.ua=o,a.headers={},a.ruri=null,a.transport=null,a.server_transaction=null,a}return qo(r,[{key:"reply",value:function(a,t,n,d,_,h){var g=[],T=this.getHeader("To");if(a=a||null,t=t||null,!a||a<100||a>699)throw new TypeError("Invalid status_code: ".concat(a));if(t&&typeof t!="string"&&!(t instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(t));t=t||Et.REASON_PHRASE[a]||"",n=nt.cloneArray(n),this.ua.configuration.extra_headers&&(n=n.concat(this.ua.configuration.extra_headers));var E="SIP/2.0 ".concat(a," ").concat(t,`\r
20
- `);if(this.method===Et.INVITE&&a>100&&a<=200){var y=this.getHeaders("record-route"),A=Vt(y),C;try{for(A.s();!(C=A.n()).done;){var I=C.value;E+="Record-Route: ".concat(I,`\r
21
- `)}}catch(D){A.e(D)}finally{A.f()}}var H=this.getHeaders("via"),L=Vt(H),ae;try{for(L.s();!(ae=L.n()).done;){var N=ae.value;E+="Via: ".concat(N,`\r
22
- `)}}catch(D){L.e(D)}finally{L.f()}!this.to_tag&&a>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
- `),E+="From: ".concat(this.getHeader("From"),`\r
24
- `),E+="Call-ID: ".concat(this.call_id,`\r
25
- `),E+="CSeq: ".concat(this.cseq," ").concat(this.method,`\r
26
- `);var j=Vt(n),Se;try{for(j.s();!(Se=j.n()).done;){var ve=Se.value;E+="".concat(ve.trim(),`\r
27
- `)}}catch(D){j.e(D)}finally{j.f()}switch(this.method){case Et.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 Et.UPDATE:this.ua.configuration.session_timers&&g.push("timer"),d&&g.push("ice"),g.push("replaces")}if(g.push("outbound"),this.method===Et.OPTIONS?(E+="Allow: ".concat(Et.ALLOWED_METHODS,`\r
28
- `),E+="Accept: ".concat(Et.ACCEPTED_BODY_TYPES,`\r
29
- `)):a===405?E+="Allow: ".concat(Et.ALLOWED_METHODS,`\r
30
- `):a===415&&(E+="Accept: ".concat(Et.ACCEPTED_BODY_TYPES,`\r
31
- `)),E+="Supported: ".concat(g,`\r
32
- `),d){var M=nt.str_utf8_length(d);E+=`Content-Type: application/sdp\r
33
- `,E+="Content-Length: ".concat(M,`\r
19
+ `;return i}},{key:"clone",value:function(){var i=new c(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(l){i.headers[l]=this.headers[l].slice()},this),i.body=this.body,i.extraHeaders=lt.cloneArray(this.extraHeaders),i.to=this.to,i.from=this.from,i.call_id=this.call_id,i.cseq=this.cseq,i}}]),c}(),Nh=function(c){Nu(i,c);var s=Uu(i);function i(l,a,_,e,p){var g;return tl(this,i),g=s.call(this,yt.INVITE,l,a,_,e,p),g.transaction=null,g}return Qa(i,[{key:"cancel",value:function(a){this.transaction.cancel(a)}},{key:"clone",value:function(){var a=new i(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(_){a.headers[_]=this.headers[_].slice()},this),a.body=this.body,a.extraHeaders=lt.cloneArray(this.extraHeaders),a.to=this.to,a.from=this.from,a.call_id=this.call_id,a.cseq=this.cseq,a.transaction=this.transaction,a}}]),i}(s_),n_=function(){function c(){tl(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 Qa(c,[{key:"addHeader",value:function(i,l){var a={raw:l};i=lt.headerize(i),this.headers[i]?this.headers[i].push(a):this.headers[i]=[a]}},{key:"getHeader",value:function(i){var l=this.headers[lt.headerize(i)];if(l){if(l[0])return l[0].raw}else return}},{key:"getHeaders",value:function(i){var l=this.headers[lt.headerize(i)],a=[];if(!l)return[];var _=qt(l),e;try{for(_.s();!(e=_.n()).done;){var p=e.value;a.push(p.raw)}}catch(g){_.e(g)}finally{_.f()}return a}},{key:"hasHeader",value:function(i){return!!this.headers[lt.headerize(i)]}},{key:"parseHeader",value:function(i){var l=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(i=lt.headerize(i),this.headers[i]){if(l>=this.headers[i].length){go.debug('not so many "'.concat(i,'" headers present'));return}}else{go.debug('header "'.concat(i,'" not present'));return}var a=this.headers[i][l],_=a.raw;if(a.parsed)return a.parsed;var e=Dh.parse(_,i.replace(/-/g,"_"));if(e===-1){this.headers[i].splice(l,1),go.debug('error parsing "'.concat(i,'" header field with value "').concat(_,'"'));return}else return a.parsed=e,e}},{key:"s",value:function(i,l){return this.parseHeader(i,l)}},{key:"setHeader",value:function(i,l){var a={raw:l};this.headers[lt.headerize(i)]=[a]}},{key:"parseSDP",value:function(i){return!i&&this.sdp?this.sdp:(this.sdp=t_.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}]),c}(),Uh=function(c){Nu(i,c);var s=Uu(i);function i(l){var a;return tl(this,i),a=s.call(this),a.ua=l,a.headers={},a.ruri=null,a.transport=null,a.server_transaction=null,a}return Qa(i,[{key:"reply",value:function(a,_,e,p,g,n){var v=[],S=this.getHeader("To");if(a=a||null,_=_||null,!a||a<100||a>699)throw new TypeError("Invalid status_code: ".concat(a));if(_&&typeof _!="string"&&!(_ instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(_));_=_||yt.REASON_PHRASE[a]||"",e=lt.cloneArray(e),this.ua.configuration.extra_headers&&(e=e.concat(this.ua.configuration.extra_headers));var m="SIP/2.0 ".concat(a," ").concat(_,`\r
20
+ `);if(this.method===yt.INVITE&&a>100&&a<=200){var C=this.getHeaders("record-route"),A=qt(C),R;try{for(A.s();!(R=A.n()).done;){var I=R.value;m+="Record-Route: ".concat(I,`\r
21
+ `)}}catch(D){A.e(D)}finally{A.f()}}var V=this.getHeaders("via"),W=qt(V),oe;try{for(W.s();!(oe=W.n()).done;){var x=oe.value;m+="Via: ".concat(x,`\r
22
+ `)}}catch(D){W.e(D)}finally{W.f()}!this.to_tag&&a>100?S+=";tag=".concat(lt.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(S+=";tag=".concat(this.to_tag)),m+="To: ".concat(S,`\r
23
+ `),m+="From: ".concat(this.getHeader("From"),`\r
24
+ `),m+="Call-ID: ".concat(this.call_id,`\r
25
+ `),m+="CSeq: ".concat(this.cseq," ").concat(this.method,`\r
26
+ `);var $=qt(e),Re;try{for($.s();!(Re=$.n()).done;){var Ie=Re.value;m+="".concat(Ie.trim(),`\r
27
+ `)}}catch(D){$.e(D)}finally{$.f()}switch(this.method){case yt.INVITE:this.ua.configuration.session_timers&&v.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&v.push("gruu"),v.push("ice","replaces");break;case yt.UPDATE:this.ua.configuration.session_timers&&v.push("timer"),p&&v.push("ice"),v.push("replaces")}if(v.push("outbound"),this.method===yt.OPTIONS?(m+="Allow: ".concat(yt.ALLOWED_METHODS,`\r
28
+ `),m+="Accept: ".concat(yt.ACCEPTED_BODY_TYPES,`\r
29
+ `)):a===405?m+="Allow: ".concat(yt.ALLOWED_METHODS,`\r
30
+ `):a===415&&(m+="Accept: ".concat(yt.ACCEPTED_BODY_TYPES,`\r
31
+ `)),m+="Supported: ".concat(v,`\r
32
+ `),p){var H=lt.str_utf8_length(p);m+=`Content-Type: application/sdp\r
33
+ `,m+="Content-Length: ".concat(H,`\r
34
34
  \r
35
- `),E+=d}else E+="Content-Length: ".concat(0,`\r
35
+ `),m+=p}else m+="Content-Length: ".concat(0,`\r
36
36
  \r
37
- `);this.server_transaction.receiveResponse(a,E,_,h)}},{key:"reply_sl",value:function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:null,t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:null,n=this.getHeaders("via");if(!a||a<100||a>699)throw new TypeError("Invalid status_code: ".concat(a));if(t&&typeof t!="string"&&!(t instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(t));t=t||Et.REASON_PHRASE[a]||"";var d="SIP/2.0 ".concat(a," ").concat(t,`\r
38
- `),_=Vt(n),h;try{for(_.s();!(h=_.n()).done;){var g=h.value;d+="Via: ".concat(g,`\r
39
- `)}}catch(C){_.e(C)}finally{_.f()}var T=this.getHeader("To");if(!this.to_tag&&a>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
- `),d+="From: ".concat(this.getHeader("From"),`\r
41
- `),d+="Call-ID: ".concat(this.call_id,`\r
42
- `),d+="CSeq: ".concat(this.cseq," ").concat(this.method,`\r
43
- `),this.ua.configuration.extra_headers){var E=Vt(this.ua.configuration.extra_headers),y;try{for(E.s();!(y=E.n()).done;){var A=y.value;d+="".concat(A.trim(),`\r
44
- `)}}catch(C){E.e(C)}finally{E.f()}}d+="Content-Length: ".concat(0,`\r
37
+ `);this.server_transaction.receiveResponse(a,m,g,n)}},{key:"reply_sl",value:function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:null,_=arguments.length>1&&arguments[1]!==void 0?arguments[1]:null,e=this.getHeaders("via");if(!a||a<100||a>699)throw new TypeError("Invalid status_code: ".concat(a));if(_&&typeof _!="string"&&!(_ instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(_));_=_||yt.REASON_PHRASE[a]||"";var p="SIP/2.0 ".concat(a," ").concat(_,`\r
38
+ `),g=qt(e),n;try{for(g.s();!(n=g.n()).done;){var v=n.value;p+="Via: ".concat(v,`\r
39
+ `)}}catch(R){g.e(R)}finally{g.f()}var S=this.getHeader("To");if(!this.to_tag&&a>100?S+=";tag=".concat(lt.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(S+=";tag=".concat(this.to_tag)),p+="To: ".concat(S,`\r
40
+ `),p+="From: ".concat(this.getHeader("From"),`\r
41
+ `),p+="Call-ID: ".concat(this.call_id,`\r
42
+ `),p+="CSeq: ".concat(this.cseq," ").concat(this.method,`\r
43
+ `),this.ua.configuration.extra_headers){var m=qt(this.ua.configuration.extra_headers),C;try{for(m.s();!(C=m.n()).done;){var A=C.value;p+="".concat(A.trim(),`\r
44
+ `)}}catch(R){m.e(R)}finally{m.f()}}p+="Content-Length: ".concat(0,`\r
45
45
  \r
46
- `),this.transport.send(d)}}]),r}(Zf),wh=function(c){Iu(r,c);var s=bu(r);function r(){var o;return tl(this,r),o=s.call(this),o.headers={},o.status_code=null,o.reason_phrase=null,o}return r}(Zf),vs={OutgoingRequest:Qf,InitialOutgoingInviteRequest:Ih,IncomingRequest:bh,IncomingResponse:wh};function Oh(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function tc(c,s){for(var r=0;r<s.length;r++){var o=s[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Dh(c,s,r){return s&&tc(c.prototype,s),r&&tc(c,r),c}var Nh=_t,cs=bt(),Kt=new Nh("DigestAuthentication"),Uh=function(){function c(s){Oh(this,c),this._credentials=s,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 Dh(c,[{key:"get",value:function(r){switch(r){case"realm":return this._realm;case"ha1":return this._ha1;default:Kt.warn('get() | cannot get "%s" parameter',r);return}}},{key:"authenticate",value:function(r,o){var a=r.method,t=r.ruri,n=r.body,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]: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 Kt.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return Kt.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return Kt.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return Kt.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return Kt.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 Kt.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;else this._qop=null;this._method=a,this._uri=t,this._cnonce=d||cs.createRandomToken(12),this._nc+=1;var _=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-_.length)+_,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=cs.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1;var h,g;return this._qop==="auth"?(h="".concat(this._method,":").concat(this._uri),g=cs.calculateMD5(h),Kt.debug('authenticate() | using qop=auth [a2:"%s"]',h),this._response=cs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(g))):this._qop==="auth-int"?(h="".concat(this._method,":").concat(this._uri,":").concat(cs.calculateMD5(n||"")),g=cs.calculateMD5(h),Kt.debug('authenticate() | using qop=auth-int [a2:"%s"]',h),this._response=cs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(g))):this._qop===null&&(h="".concat(this._method,":").concat(this._uri),g=cs.calculateMD5(h),Kt.debug('authenticate() | using qop=null [a2:"%s"]',h),this._response=cs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(g))),Kt.debug("authenticate() | response generated"),!0}},{key:"toString",value:function(){var r=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return r.push("algorithm=".concat(this._algorithm)),r.push('username="'.concat(this._credentials.username,'"')),r.push('realm="'.concat(this._realm,'"')),r.push('nonce="'.concat(this._nonce,'"')),r.push('uri="'.concat(this._uri,'"')),r.push('response="'.concat(this._response,'"')),this._opaque&&r.push('opaque="'.concat(this._opaque,'"')),this._qop&&(r.push("qop=".concat(this._qop)),r.push('cnonce="'.concat(this._cnonce,'"')),r.push("nc=".concat(this._ncHex))),"Digest ".concat(r.join(", "))}}]),c}(),fs=500,Ph=4e3,sc=5e3,e_={T1:fs,T2:Ph,T4:sc,TIMER_B:64*fs,TIMER_D:0*fs,TIMER_F:64*fs,TIMER_H:64*fs,TIMER_I:0*fs,TIMER_J:0*fs,TIMER_K:0*sc,TIMER_L:64*fs,TIMER_M:64*fs,PROVISIONAL_RESPONSE_INTERVAL:6e4};function mo(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?mo=function(r){return typeof r}:mo=function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},mo(c)}function sl(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function nc(c,s){for(var r=0;r<s.length;r++){var o=s[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function nl(c,s,r){return s&&nc(c.prototype,s),r&&nc(c,r),c}function rl(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&ou(c,s)}function ou(c,s){return ou=Object.setPrototypeOf||function(o,a){return o.__proto__=a,o},ou(c,s)}function il(c){var s=Mh();return function(){var o=bo(c),a;if(s){var t=bo(this).constructor;a=Reflect.construct(o,arguments,t)}else a=o.apply(this,arguments);return xh(this,a)}}function xh(c,s){return s&&(mo(s)==="object"||typeof s=="function")?s:qs(c)}function qs(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Mh(){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 bo(c){return bo=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)},bo(c)}var ll=ft.EventEmitter,ol=_t,Ki=it,rc=vs,ns=e_,ic=new ol("NonInviteClientTransaction"),Ml=new ol("InviteClientTransaction"),kh=new ol("AckClientTransaction"),lc=new ol("NonInviteServerTransaction"),kl=new ol("InviteServerTransaction"),_e={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"},Lh=function(c){rl(r,c);var s=il(r);function r(o,a,t,n){var d;sl(this,r),d=s.call(this),d.type=_e.NON_INVITE_CLIENT,d.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),d.ua=o,d.transport=a,d.request=t,d.eventHandlers=n;var _="SIP/2.0/".concat(a.via_transport);return _+=" ".concat(o.configuration.via_host,";branch=").concat(d.id),d.request.setHeader("via",_),d.ua.newTransaction(qs(d)),d}return nl(r,[{key:"stateChanged",value:function(a){this.state=a,this.emit("stateChanged")}},{key:"send",value:function(){var a=this;this.stateChanged(_e.STATUS_TRYING),this.F=setTimeout(function(){a.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(_e.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(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}},{key:"timer_K",value:function(){this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"receiveResponse",value:function(a){var t=this,n=a.status_code;if(n<200)switch(this.state){case _e.STATUS_TRYING:case _e.STATUS_PROCEEDING:this.stateChanged(_e.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(a);break}else switch(this.state){case _e.STATUS_TRYING:case _e.STATUS_PROCEEDING:this.stateChanged(_e.STATUS_COMPLETED),clearTimeout(this.F),n===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(a),this.K=setTimeout(function(){t.timer_K()},ns.TIMER_K);break;case _e.STATUS_COMPLETED:break}}},{key:"C",get:function(){return _e}}]),r}(ll),$h=function(c){rl(r,c);var s=il(r);function r(o,a,t,n){var d;sl(this,r),d=s.call(this),d.type=_e.INVITE_CLIENT,d.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),d.ua=o,d.transport=a,d.request=t,d.eventHandlers=n,t.transaction=qs(d);var _="SIP/2.0/".concat(a.via_transport);return _+=" ".concat(o.configuration.via_host,";branch=").concat(d.id),d.request.setHeader("via",_),d.ua.newTransaction(qs(d)),d}return nl(r,[{key:"stateChanged",value:function(a){this.state=a,this.emit("stateChanged")}},{key:"send",value:function(){var a=this;this.stateChanged(_e.STATUS_CALLING),this.B=setTimeout(function(){a.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!==_e.STATUS_ACCEPTED&&(Ml.debug("transport error occurred, deleting transaction ".concat(this.id)),this.eventHandlers.onTransportError()),this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_M",value:function(){Ml.debug("Timer M expired for transaction ".concat(this.id)),this.state===_e.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"timer_B",value:function(){Ml.debug("Timer B expired for transaction ".concat(this.id)),this.state===_e.STATUS_CALLING&&(this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}},{key:"timer_D",value:function(){Ml.debug("Timer D expired for transaction ".concat(this.id)),clearTimeout(this.B),this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"sendACK",value:function(a){var t=this,n=new rc.OutgoingRequest(Ki.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",a.getHeader("to")),this.D=setTimeout(function(){t.timer_D()},ns.TIMER_D),this.transport.send(n)}},{key:"cancel",value:function(a){if(this.state===_e.STATUS_PROCEEDING){var t=new rc.OutgoingRequest(Ki.CANCEL,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});t.setHeader("from",this.request.getHeader("from")),t.setHeader("via",this.request.getHeader("via")),t.setHeader("to",this.request.getHeader("to")),a&&t.setHeader("reason",a),this.transport.send(t)}}},{key:"receiveResponse",value:function(a){var t=this,n=a.status_code;if(n>=100&&n<=199)switch(this.state){case _e.STATUS_CALLING:this.stateChanged(_e.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(a);break;case _e.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(a);break}else if(n>=200&&n<=299)switch(this.state){case _e.STATUS_CALLING:case _e.STATUS_PROCEEDING:this.stateChanged(_e.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},ns.TIMER_M),this.eventHandlers.onReceiveResponse(a);break;case _e.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(a);break}else if(n>=300&&n<=699)switch(this.state){case _e.STATUS_CALLING:case _e.STATUS_PROCEEDING:this.stateChanged(_e.STATUS_COMPLETED),this.sendACK(a),this.eventHandlers.onReceiveResponse(a);break;case _e.STATUS_COMPLETED:this.sendACK(a);break}}},{key:"C",get:function(){return _e}}]),r}(ll),Hh=function(c){rl(r,c);var s=il(r);function r(o,a,t,n){var d;sl(this,r),d=s.call(this),d.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),d.transport=a,d.request=t,d.eventHandlers=n;var _="SIP/2.0/".concat(a.via_transport);return _+=" ".concat(o.configuration.via_host,";branch=").concat(d.id),d.request.setHeader("via",_),d}return nl(r,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){kh.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return _e}}]),r}(ll),Fh=function(c){rl(r,c);var s=il(r);function r(o,a,t){var n;return sl(this,r),n=s.call(this),n.type=_e.NON_INVITE_SERVER,n.id=t.via_branch,n.ua=o,n.transport=a,n.request=t,n.last_response="",t.server_transaction=qs(n),n.state=_e.STATUS_TRYING,o.newTransaction(qs(n)),n}return nl(r,[{key:"stateChanged",value:function(a){this.state=a,this.emit("stateChanged")}},{key:"timer_J",value:function(){lc.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,lc.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(a,t,n,d){var _=this;if(a===100)switch(this.state){case _e.STATUS_TRYING:this.stateChanged(_e.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case _e.STATUS_PROCEEDING:this.last_response=t,this.transport.send(t)?n&&n():(this.onTransportError(),d&&d());break}else if(a>=200&&a<=699)switch(this.state){case _e.STATUS_TRYING:case _e.STATUS_PROCEEDING:this.stateChanged(_e.STATUS_COMPLETED),this.last_response=t,this.J=setTimeout(function(){_.timer_J()},ns.TIMER_J),this.transport.send(t)?n&&n():(this.onTransportError(),d&&d());break;case _e.STATUS_COMPLETED:break}}},{key:"C",get:function(){return _e}}]),r}(ll),jh=function(c){rl(r,c);var s=il(r);function r(o,a,t){var n;return sl(this,r),n=s.call(this),n.type=_e.INVITE_SERVER,n.id=t.via_branch,n.ua=o,n.transport=a,n.request=t,n.last_response="",t.server_transaction=qs(n),n.state=_e.STATUS_PROCEEDING,o.newTransaction(qs(n)),n.resendProvisionalTimer=null,t.reply(100),n}return nl(r,[{key:"stateChanged",value:function(a){this.state=a,this.emit("stateChanged")}},{key:"timer_H",value:function(){kl.debug("Timer H expired for transaction ".concat(this.id)),this.state===_e.STATUS_COMPLETED&&kl.debug("ACK not received, dialog will be terminated"),this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){kl.debug("Timer L expired for transaction ".concat(this.id)),this.state===_e.STATUS_ACCEPTED&&(this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,kl.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(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"resend_provisional",value:function(){this.transport.send(this.last_response)||this.onTransportError()}},{key:"receiveResponse",value:function(a,t,n,d){var _=this;if(a>=100&&a<=199)switch(this.state){case _e.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t;break}if(a>100&&a<=199&&this.state===_e.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(function(){_.resend_provisional()},ns.PROVISIONAL_RESPONSE_INTERVAL));else if(a>=200&&a<=299)switch(this.state){case _e.STATUS_PROCEEDING:this.stateChanged(_e.STATUS_ACCEPTED),this.last_response=t,this.L=setTimeout(function(){_.timer_L()},ns.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case _e.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),d&&d());break}else if(a>=300&&a<=699)switch(this.state){case _e.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(_e.STATUS_COMPLETED),this.H=setTimeout(function(){_.timer_H()},ns.TIMER_H),n&&n()):(this.onTransportError(),d&&d());break}}},{key:"C",get:function(){return _e}}]),r}(ll);function qh(c,s){var r=c._transactions,o;switch(s.method){case Ki.INVITE:if(o=r.ist[s.via_branch],o){switch(o.state){case _e.STATUS_PROCEEDING:o.transport.send(o.last_response);break;case _e.STATUS_ACCEPTED:break}return!0}break;case Ki.ACK:if(o=r.ist[s.via_branch],o){if(o.state===_e.STATUS_ACCEPTED)return!1;if(o.state===_e.STATUS_COMPLETED)return o.state=_e.STATUS_CONFIRMED,o.I=setTimeout(function(){o.timer_I()},ns.TIMER_I),!0}else return!1;break;case Ki.CANCEL:return o=r.ist[s.via_branch],o?(s.reply_sl(200),o.state!==_e.STATUS_PROCEEDING):(s.reply_sl(481),!0);default:if(o=r.nist[s.via_branch],o){switch(o.state){case _e.STATUS_TRYING:break;case _e.STATUS_PROCEEDING:case _e.STATUS_COMPLETED:o.transport.send(o.last_response);break}return!0}break}}var al={C:_e,NonInviteClientTransaction:Lh,InviteClientTransaction:$h,AckClientTransaction:Hh,NonInviteServerTransaction:Fh,InviteServerTransaction:jh,checkTransaction:qh};function Vh(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function oc(c,s){for(var r=0;r<s.length;r++){var o=s[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Bh(c,s,r){return s&&oc(c.prototype,s),r&&oc(c,r),c}var Gh=_t,ac=it,Wh=Uh,ha=al,Kh=new Gh("RequestSender"),da={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}},ul=function(){function c(s,r,o){Vh(this,c),this._ua=s,this._eventHandlers=o,this._method=r.method,this._request=r,this._auth=null,this._challenged=!1,this._staled=!1;for(var a in da)Object.prototype.hasOwnProperty.call(da,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=da[a]));s.status===s.C.STATUS_USER_CLOSED&&(this._method!==ac.BYE||this._method!==ac.ACK)&&this._eventHandlers.onTransportError()}return Bh(c,[{key:"send",value:function(){var r=this,o={onRequestTimeout:function(){r._eventHandlers.onRequestTimeout()},onTransportError:function(){r._eventHandlers.onTransportError()},onReceiveResponse:function(t){r._receiveResponse(t)}};switch(this._method){case"INVITE":this.clientTransaction=new ha.InviteClientTransaction(this._ua,this._ua.transport,this._request,o);break;case"ACK":this.clientTransaction=new ha.AckClientTransaction(this._ua,this._ua.transport,this._request,o);break;default:this.clientTransaction=new ha.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,o)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}},{key:"_receiveResponse",value:function(r){var o,a,t=r.status_code;if((t===401||t===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(r.status_code===401?(o=r.parseHeader("www-authenticate"),a="authorization"):(o=r.parseHeader("proxy-authenticate"),a="proxy-authorization"),!o){Kh.debug("".concat(r.status_code," with wrong or missing challenge, cannot authenticate")),this._eventHandlers.onReceiveResponse(r);return}if(!this._challenged||!this._staled&&o.stale===!0){if(this._auth||(this._auth=new Wh({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,o)){this._eventHandlers.onReceiveResponse(r);return}this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),o.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(a,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(r)}else this._eventHandlers.onReceiveResponse(r)}}]),c}();function Yh(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function uc(c,s){for(var r=0;r<s.length;r++){var o=s[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Jh(c,s,r){return s&&uc(c.prototype,s),r&&uc(c,r),c}var zh=_t,pa=bt(),hn=it,cc=vs,fc=ul,wi=new zh("Registrator"),Ll=10,Xh=function(){function c(s,r){Yh(this,c),this._reg_id=1,this._ua=s,this._transport=r,this._registrar=s.configuration.registrar_server,this._expires=s.configuration.register_expires,this._call_id=pa.createRandomToken(22),this._cseq=0,this._to_uri=s.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 Jh(c,[{key:"setExtraHeaders",value:function(r){Array.isArray(r)||(r=[]),this._extraHeaders=r.slice()}},{key:"setExtraContactParams",value:function(r){r instanceof Object||(r={}),this._extraContactParams="";for(var o in r)if(Object.prototype.hasOwnProperty.call(r,o)){var a=r[o];this._extraContactParams+=";".concat(o),a&&(this._extraContactParams+="=".concat(a))}}},{key:"register",value:function(){var r=this;if(this._registering){wi.debug("Register request in progress...");return}var o=this._extraHeaders.slice();o.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),o.push("Expires: ".concat(this._expires));var a=new cc.OutgoingRequest(hn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},o),t=new fc(this._ua,a,{onRequestTimeout:function(){r._registrationFailure(null,hn.causes.REQUEST_TIMEOUT)},onTransportError:function(){r._registrationFailure(null,hn.causes.CONNECTION_ERROR)},onAuthenticated:function(){r._cseq+=1},onReceiveResponse:function(d){if(d.cseq===r._cseq)switch(r._registrationTimer!==null&&(clearTimeout(r._registrationTimer),r._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(d.status_code):break;case/^2[0-9]{2}$/.test(d.status_code):{if(r._registering=!1,!d.hasHeader("Contact")){wi.debug("no Contact header in response to REGISTER, response ignored");break}var _=d.headers.Contact.reduce(function(y,A){return y.concat(A.parsed)},[]),h=_.find(function(y){return r._sipInstance===y.getParam("+sip.instance")&&r._reg_id===parseInt(y.getParam("reg-id"))});if(h||(h=_.find(function(y){return y.uri.user===r._ua.contact.uri.user})),!h){wi.debug("no Contact header pointing to us, response ignored");break}var g=h.getParam("expires");!g&&d.hasHeader("expires")&&(g=d.getHeader("expires")),g||(g=r._expires),g=Number(g),g<Ll&&(g=Ll);var T=g>64?g*1e3/2+Math.floor((g/2-32)*1e3*Math.random()):g*1e3-5e3;r._registrationTimer=setTimeout(function(){r._registrationTimer=null,r._ua.listeners("registrationExpiring").length===0?r.register():r._ua.emit("registrationExpiring")},T),h.hasParam("temp-gruu")&&(r._ua.contact.temp_gruu=h.getParam("temp-gruu").replace(/"/g,"")),h.hasParam("pub-gruu")&&(r._ua.contact.pub_gruu=h.getParam("pub-gruu").replace(/"/g,"")),r._registered||(r._registered=!0,r._ua.registered({response:d}));break}case/^423$/.test(d.status_code):{d.hasHeader("min-expires")?(r._expires=Number(d.getHeader("min-expires")),r._expires<Ll&&(r._expires=Ll),r.register()):(wi.debug("423 response received for REGISTER without Min-Expires"),r._registrationFailure(d,hn.causes.SIP_FAILURE_CODE));break}default:{var E=pa.sipErrorCause(d.status_code);r._registrationFailure(d,E)}}}});this._registering=!0,t.send()}},{key:"unregister",value:function(){var r=this,o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!this._registered){wi.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);var a=this._extraHeaders.slice();o.all?a.push("Contact: *".concat(this._extraContactParams)):a.push("Contact: ".concat(this._contact,";expires=0").concat(this._extraContactParams)),a.push("Expires: 0");var t=new cc.OutgoingRequest(hn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},a),n=new fc(this._ua,t,{onRequestTimeout:function(){r._unregistered(null,hn.causes.REQUEST_TIMEOUT)},onTransportError:function(){r._unregistered(null,hn.causes.CONNECTION_ERROR)},onAuthenticated:function(){r._cseq+=1},onReceiveResponse:function(_){switch(!0){case/^1[0-9]{2}$/.test(_.status_code):break;case/^2[0-9]{2}$/.test(_.status_code):r._unregistered(_);break;default:{var h=pa.sipErrorCause(_.status_code);r._unregistered(_,h)}}}});n.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(r,o){this._registering=!1,this._ua.registrationFailed({response:r||null,cause:o}),this._registered&&(this._registered=!1,this._ua.unregistered({response:r||null,cause:o}))}},{key:"_unregistered",value:function(r,o){this._registering=!1,this._registered=!1,this._ua.unregistered({response:r||null,cause:o||null})}},{key:"registered",get:function(){return this._registered}}]),c}();function Qh(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function _c(c,s){for(var r=0;r<s.length;r++){var o=s[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Zh(c,s,r){return s&&_c(c.prototype,s),r&&_c(c,r),c}var ma=it,$l=al,ed=ul,ga={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}},td=function(){function c(s,r,o){Qh(this,c),this._dialog=s,this._ua=s._ua,this._request=r,this._eventHandlers=o,this._reattempt=!1,this._reattemptTimer=null;for(var a in ga)Object.prototype.hasOwnProperty.call(ga,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=ga[a]))}return Zh(c,[{key:"send",value:function(){var r=this,o=new ed(this._ua,this._request,{onRequestTimeout:function(){r._eventHandlers.onRequestTimeout()},onTransportError:function(){r._eventHandlers.onTransportError()},onAuthenticated:function(n){r._eventHandlers.onAuthenticated(n)},onReceiveResponse:function(n){r._receiveResponse(n)}});if(o.send(),(this._request.method===ma.INVITE||this._request.method===ma.UPDATE&&this._request.body)&&o.clientTransaction.state!==$l.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;var a=function t(){(o.clientTransaction.state===$l.C.STATUS_ACCEPTED||o.clientTransaction.state===$l.C.STATUS_COMPLETED||o.clientTransaction.state===$l.C.STATUS_TERMINATED)&&(o.clientTransaction.removeListener("stateChanged",t),r._dialog.uac_pending_reply=!1)};o.clientTransaction.on("stateChanged",a)}}},{key:"_receiveResponse",value:function(r){var o=this;r.status_code===408||r.status_code===481?this._eventHandlers.onDialogError(r):r.method===ma.INVITE&&r.status_code===491?this._reattempt?r.status_code>=200&&r.status_code<300?this._eventHandlers.onSuccessResponse(r):r.status_code>=300&&this._eventHandlers.onErrorResponse(r):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(function(){o._dialog.isTerminated()||(o._reattempt=!0,o.send())},1e3)):r.status_code>=200&&r.status_code<300?this._eventHandlers.onSuccessResponse(r):r.status_code>=300&&this._eventHandlers.onErrorResponse(r)}},{key:"request",get:function(){return this._request}}]),c}();function sd(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function hc(c,s){for(var r=0;r<s.length;r++){var o=s[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function dc(c,s,r){return s&&hc(c.prototype,s),r&&hc(c,r),c}var nd=_t,pc=vs,xs=it,Oi=al,rd=td,Ta=bt(),va=new nd("Dialog"),Ms={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3},id=function(){dc(c,null,[{key:"C",get:function(){return Ms}}]);function c(s,r,o){var a=arguments.length>3&&arguments[3]!==void 0?arguments[3]:Ms.STATUS_CONFIRMED;if(sd(this,c),this._owner=s,this._ua=s._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!r.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};r instanceof pc.IncomingResponse&&(a=r.status_code<200?Ms.STATUS_EARLY:Ms.STATUS_CONFIRMED);var t=r.parseHeader("contact");o==="UAS"?(this._id={call_id:r.call_id,local_tag:r.to_tag,remote_tag:r.from_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._remote_seqnum=r.cseq,this._local_uri=r.parseHeader("to").uri,this._remote_uri=r.parseHeader("from").uri,this._remote_target=t.uri,this._route_set=r.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):o==="UAC"&&(this._id={call_id:r.call_id,local_tag:r.from_tag,remote_tag:r.to_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._local_seqnum=r.cseq,this._local_uri=r.parseHeader("from").uri,this._remote_uri=r.parseHeader("to").uri,this._remote_target=t.uri,this._route_set=r.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),va.debug("new ".concat(o," dialog created with status ").concat(this._state===Ms.STATUS_EARLY?"EARLY":"CONFIRMED"))}return dc(c,[{key:"isTerminated",value:function(){return this._status===Ms.STATUS_TERMINATED}},{key:"update",value:function(r,o){this._state=Ms.STATUS_CONFIRMED,va.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),o==="UAC"&&(this._route_set=r.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){va.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this),this._state=Ms.STATUS_TERMINATED}},{key:"sendRequest",value:function(r){var o=this,a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},t=Ta.cloneArray(a.extraHeaders),n=Ta.cloneObject(a.eventHandlers),d=a.body||null,_=this._createRequest(r,t,d);n.onAuthenticated=function(){o._local_seqnum+=1};var h=new rd(this,_,n);return h.send(),_}},{key:"receiveRequest",value:function(r){this._checkInDialogRequest(r)&&(r.method===xs.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:r.method===xs.INVITE&&(this._ack_seqnum=r.cseq),this._owner.receiveRequest(r))}},{key:"_createRequest",value:function(r,o,a){o=Ta.cloneArray(o),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));var t=r===xs.CANCEL||r===xs.ACK?this._local_seqnum:this._local_seqnum+=1,n=new pc.OutgoingRequest(r,this._remote_target,this._ua,{cseq:t,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},o,a);return n}},{key:"_checkInDialogRequest",value:function(r){var o=this;if(!this._remote_seqnum)this._remote_seqnum=r.cseq;else if(r.cseq<this._remote_seqnum)if(r.method===xs.ACK){if(this._ack_seqnum===null||r.cseq!==this._ack_seqnum)return!1}else return r.reply(500),!1;else r.cseq>this._remote_seqnum&&(this._remote_seqnum=r.cseq);if(r.method===xs.INVITE||r.method===xs.UPDATE&&r.body){if(this._uac_pending_reply===!0)r.reply(491);else if(this._uas_pending_reply===!0){var a=(Math.random()*10|0)+1;return r.reply(500,null,["Retry-After:".concat(a)]),!1}else{this._uas_pending_reply=!0;var t=function n(){(r.server_transaction.state===Oi.C.STATUS_ACCEPTED||r.server_transaction.state===Oi.C.STATUS_COMPLETED||r.server_transaction.state===Oi.C.STATUS_TERMINATED)&&(r.server_transaction.removeListener("stateChanged",n),o._uas_pending_reply=!1)};r.server_transaction.on("stateChanged",t)}r.hasHeader("contact")&&r.server_transaction.on("stateChanged",function(){r.server_transaction.state===Oi.C.STATUS_ACCEPTED&&(o._remote_target=r.parseHeader("contact").uri)})}else r.method===xs.NOTIFY&&r.hasHeader("contact")&&r.server_transaction.on("stateChanged",function(){r.server_transaction.state===Oi.C.STATUS_COMPLETED&&(o._remote_target=r.parseHeader("contact").uri)});return!0}},{key:"id",get:function(){return this._id}},{key:"local_seqnum",get:function(){return this._local_seqnum},set:function(r){this._local_seqnum=r}},{key:"owner",get:function(){return this._owner}},{key:"uac_pending_reply",get:function(){return this._uac_pending_reply},set:function(r){this._uac_pending_reply=r}},{key:"uas_pending_reply",get:function(){return this._uas_pending_reply}}]),c}(),wu={exports:{}};function go(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?go=function(r){return typeof r}:go=function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},go(c)}function ld(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function mc(c,s){for(var r=0;r<s.length;r++){var o=s[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function od(c,s,r){return s&&mc(c.prototype,s),r&&mc(c,r),c}function ad(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&au(c,s)}function au(c,s){return au=Object.setPrototypeOf||function(o,a){return o.__proto__=a,o},au(c,s)}function ud(c){var s=_d();return function(){var o=wo(c),a;if(s){var t=wo(this).constructor;a=Reflect.construct(o,arguments,t)}else a=o.apply(this,arguments);return cd(this,a)}}function cd(c,s){return s&&(go(s)==="object"||typeof s=="function")?s: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 _d(){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 wo(c){return wo=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)},wo(c)}var hd=ft.EventEmitter,dd=_t,pd=it,md=Bs,gc=bt(),gd=new dd("RTCSession:DTMF"),t_={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};wu.exports=function(c){ad(r,c);var s=ud(r);function r(o){var a;return ld(this,r),a=s.call(this),a._session=o,a._direction=null,a._tone=null,a._duration=null,a._request=null,a}return od(r,[{key:"send",value:function(a){var t=this,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(a===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 md.InvalidStateError(this._session.status);var d=gc.cloneArray(n.extraHeaders);if(this.eventHandlers=gc.cloneObject(n.eventHandlers),typeof a=="string")a=a.toUpperCase();else if(typeof a=="number")a=a.toString();else throw new TypeError("Invalid tone: ".concat(a));if(a.match(/^[0-9A-DR#*]$/))this._tone=a;else throw new TypeError("Invalid tone: ".concat(a));this._duration=n.duration,d.push("Content-Type: application/dtmf-relay");var _="Signal=".concat(this._tone,`\r
47
- `);_+="Duration=".concat(this._duration),this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(pd.INFO,{extraHeaders:d,eventHandlers:{onSuccessResponse:function(g){t.emit("succeeded",{originator:"remote",response:g})},onErrorResponse:function(g){t.eventHandlers.onFailed&&t.eventHandlers.onFailed(),t.emit("failed",{originator:"remote",response:g})},onRequestTimeout:function(){t._session.onRequestTimeout()},onTransportError:function(){t._session.onTransportError()},onDialogError:function(){t._session.onDialogError()}},body:_})}},{key:"init_incoming",value:function(a){var t=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,n=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=a,a.reply(200),a.body){var d=a.body.split(`
48
- `);d.length>=1&&t.test(d[0])&&(this._tone=d[0].replace(t,"$2")),d.length>=2&&n.test(d[1])&&(this._duration=parseInt(d[1].replace(n,"$2"),10))}this._duration||(this._duration=t_.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:a}):gd.debug("invalid INFO DTMF received, discarded")}},{key:"tone",get:function(){return this._tone}},{key:"duration",get:function(){return this._duration}}]),r}(hd);wu.exports.C=t_;var Td=wu.exports;function To(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?To=function(r){return typeof r}:To=function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},To(c)}function vd(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function Tc(c,s){for(var r=0;r<s.length;r++){var o=s[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Ed(c,s,r){return s&&Tc(c.prototype,s),r&&Tc(c,r),c}function Sd(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&uu(c,s)}function uu(c,s){return uu=Object.setPrototypeOf||function(o,a){return o.__proto__=a,o},uu(c,s)}function yd(c){var s=Rd();return function(){var o=Oo(c),a;if(s){var t=Oo(this).constructor;a=Reflect.construct(o,arguments,t)}else a=o.apply(this,arguments);return Ad(this,a)}}function Ad(c,s){return s&&(To(s)==="object"||typeof s=="function")?s:Cd(c)}function Cd(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 Oo(c){return Oo=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)},Oo(c)}var Id=ft.EventEmitter,bd=it,wd=Bs,Od=bt(),Dd=function(c){Sd(r,c);var s=yd(r);function r(o){var a;return vd(this,r),a=s.call(this),a._session=o,a._direction=null,a._contentType=null,a._body=null,a}return Ed(r,[{key:"send",value:function(a,t){var n=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(this._direction="outgoing",a===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 wd.InvalidStateError(this._session.status);this._contentType=a,this._body=t;var _=Od.cloneArray(d.extraHeaders);_.push("Content-Type: ".concat(a)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(bd.INFO,{extraHeaders:_,eventHandlers:{onSuccessResponse:function(g){n.emit("succeeded",{originator:"remote",response:g})},onErrorResponse:function(g){n.emit("failed",{originator:"remote",response:g})},onTransportError:function(){n._session.onTransportError()},onRequestTimeout:function(){n._session.onRequestTimeout()},onDialogError:function(){n._session.onDialogError()}},body:t})}},{key:"init_incoming",value:function(a){this._direction="incoming",this.request=a,a.reply(200),this._contentType=a.hasHeader("Content-Type")?a.getHeader("Content-Type").toLowerCase():void 0,this._body=a.body,this._session.newInfo({originator:"remote",info:this,request:a})}},{key:"contentType",get:function(){return this._contentType}},{key:"body",get:function(){return this._body}}]),r}(Id);function Nd(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function vc(c,s){for(var r=0;r<s.length;r++){var o=s[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Ud(c,s,r){return s&&vc(c.prototype,s),r&&vc(c,r),c}var Pd=_t,Ec=it,xd=new Pd("RTCSession:ReferNotifier"),Ea={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300},Md=function(){function c(s,r,o){Nd(this,c),this._session=s,this._id=r,this._expires=o||Ea.expires,this._active=!0,this.notify(100)}return Ud(c,[{key:"notify",value:function(r,o){if(xd.debug("notify()"),this._active!==!1){o=o||Ec.REASON_PHRASE[r]||"";var a;r>=200?a="terminated;reason=noresource":a="active;expires=".concat(this._expires),this._session.sendRequest(Ec.NOTIFY,{extraHeaders:["Event: ".concat(Ea.event_type,";id=").concat(this._id),"Subscription-State: ".concat(a),"Content-Type: ".concat(Ea.body_type)],body:"SIP/2.0 ".concat(r," ").concat(o),eventHandlers:{onErrorResponse:function(){this._active=!1}}})}}}]),c}();function vo(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?vo=function(r){return typeof r}:vo=function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},vo(c)}function kd(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function Sc(c,s){for(var r=0;r<s.length;r++){var o=s[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Ld(c,s,r){return s&&Sc(c.prototype,s),r&&Sc(c,r),c}function $d(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&cu(c,s)}function cu(c,s){return cu=Object.setPrototypeOf||function(o,a){return o.__proto__=a,o},cu(c,s)}function Hd(c){var s=qd();return function(){var o=Do(c),a;if(s){var t=Do(this).constructor;a=Reflect.construct(o,arguments,t)}else a=o.apply(this,arguments);return Fd(this,a)}}function Fd(c,s){return s&&(vo(s)==="object"||typeof s=="function")?s:jd(c)}function jd(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function qd(){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 Do(c){return Do=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)},Do(c)}var Vd=ft.EventEmitter,Bd=_t,Di=it,Gd=is(),yc=bt(),dn=new Bd("RTCSession:ReferSubscriber"),Wd=function(c){$d(r,c);var s=Hd(r);function r(o){var a;return kd(this,r),a=s.call(this),a._id=null,a._session=o,a}return Ld(r,[{key:"sendRefer",value:function(a){var t=this,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};dn.debug("sendRefer()");var d=yc.cloneArray(n.extraHeaders),_=yc.cloneObject(n.eventHandlers);for(var h in _)Object.prototype.hasOwnProperty.call(_,h)&&this.on(h,_[h]);var g=null;n.replaces&&(g=n.replaces._request.call_id,g+=";to-tag=".concat(n.replaces._to_tag),g+=";from-tag=".concat(n.replaces._from_tag),g=encodeURIComponent(g));var T="Refer-To: <".concat(a).concat(g?"?Replaces=".concat(g):"",">");if(d.push(T),!d.some(function(A){return A.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(Di.REFER,{extraHeaders:d,eventHandlers:{onSuccessResponse:function(C){t._requestSucceeded(C)},onErrorResponse:function(C){t._requestFailed(C,Di.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,Di.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,Di.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,Di.causes.DIALOG_ERROR)}}});this._id=y.cseq}},{key:"receiveNotify",value:function(a){if(dn.debug("receiveNotify()"),!!a.body){var t=Gd.parse(a.body.trim().split(`\r
49
- `,1)[0],"Status_Line");if(t===-1){dn.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(a.body,'"'));return}switch(!0){case/^100$/.test(t.status_code):this.emit("trying",{request:a,status_line:t});break;case/^1[0-9]{2}$/.test(t.status_code):this.emit("progress",{request:a,status_line:t});break;case/^2[0-9]{2}$/.test(t.status_code):this.emit("accepted",{request:a,status_line:t});break;default:this.emit("failed",{request:a,status_line:t});break}}}},{key:"_requestSucceeded",value:function(a){dn.debug("REFER succeeded"),dn.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:a})}},{key:"_requestFailed",value:function(a,t){dn.debug("REFER failed"),dn.debug('emit "requestFailed"'),this.emit("requestFailed",{response:a||null,cause:t})}},{key:"id",get:function(){return this._id}}]),r}(Vd);function Eo(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Eo=function(r){return typeof r}:Eo=function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},Eo(c)}function _s(c,s){var r;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(r=Kd(c))||s&&c&&typeof c.length=="number"){r&&(c=r);var o=0,a=function(){};return{s:a,n:function(){return o>=c.length?{done:!0}:{done:!1,value:c[o++]}},e:function(h){throw h},f:a}}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 t=!0,n=!1,d;return{s:function(){r=c[Symbol.iterator]()},n:function(){var h=r.next();return t=h.done,h},e:function(h){n=!0,d=h},f:function(){try{!t&&r.return!=null&&r.return()}finally{if(n)throw d}}}}function Kd(c,s){if(c){if(typeof c=="string")return Ac(c,s);var r=Object.prototype.toString.call(c).slice(8,-1);if(r==="Object"&&c.constructor&&(r=c.constructor.name),r==="Map"||r==="Set")return Array.from(c);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return Ac(c,s)}}function Ac(c,s){(s==null||s>c.length)&&(s=c.length);for(var r=0,o=new Array(s);r<s;r++)o[r]=c[r];return o}function Yd(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function Cc(c,s){for(var r=0;r<s.length;r++){var o=s[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Rc(c,s,r){return s&&Cc(c.prototype,s),r&&Cc(c,r),c}function Jd(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&fu(c,s)}function fu(c,s){return fu=Object.setPrototypeOf||function(o,a){return o.__proto__=a,o},fu(c,s)}function zd(c){var s=Zd();return function(){var o=No(c),a;if(s){var t=No(this).constructor;a=Reflect.construct(o,arguments,t)}else a=o.apply(this,arguments);return Xd(this,a)}}function Xd(c,s){return s&&(Eo(s)==="object"||typeof s=="function")?s:Qd(c)}function Qd(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Zd(){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 No(c){return No=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)},No(c)}var ep=ft.EventEmitter,Ic=Pt,tp=_t,ce=it,pn=Bs,bc=al,Ve=bt(),Ni=e_,sp=vs,Hl=id,np=ul,xt=Td,wc=Dd,rp=Md,ip=Wd,Oc=Gs(),K=new tp("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},Fl=["audio","video"],lp=function(c){Jd(r,c);var s=zd(r);Rc(r,null,[{key:"C",get:function(){return Q}}]);function r(o){var a;return Yd(this,r),K.debug("new"),a=s.call(this),a._id=null,a._ua=o,a._status=Q.STATUS_NULL,a._dialog=null,a._earlyDialogs={},a._contact=null,a._from_tag=null,a._to_tag=null,a._connection=null,a._connectionPromiseQueue=Promise.resolve(),a._request=null,a._is_canceled=!1,a._cancel_reason="",a._is_confirmed=!1,a._late_sdp=!1,a._rtcOfferConstraints=null,a._rtcAnswerConstraints=null,a._localMediaStream=null,a._localMediaStreamLocallyGenerated=!1,a._rtcReady=!0,a._iceReady=!1,a._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},a._direction=null,a._local_identity=null,a._remote_identity=null,a._start_time=null,a._end_time=null,a._tones=null,a._audioMuted=!1,a._videoMuted=!1,a._localHold=!1,a._remoteHold=!1,a._sessionTimers={enabled:a._ua.configuration.session_timers,refreshMethod:a._ua.configuration.session_timers_refresh_method,defaultExpires:ce.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},a._referSubscribers={},a._data={},a}return Rc(r,[{key:"isInProgress",value:function(){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}}},{key:"isEstablished",value:function(){switch(this._status){case Q.STATUS_ANSWERED:case Q.STATUS_WAITING_FOR_ACK:case Q.STATUS_CONFIRMED:return!0;default:return!1}}},{key:"isEnded",value:function(){switch(this._status){case Q.STATUS_CANCELED:case Q.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(a){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;K.debug("connect()");var d=a,_=Ve.cloneObject(t.eventHandlers),h=Ve.cloneArray(t.extraHeaders),g=Ve.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),T=t.mediaStream||null,E=Ve.cloneObject(t.pcConfig,{iceServers:[]}),y=t.rtcConstraints||null,A=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=A,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,a===void 0)throw new TypeError("Not enough arguments");if(this._status!==Q.STATUS_NULL)throw new pn.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new pn.NotSupportedError("WebRTC not supported");if(a=this._ua.normalizeTarget(a),!a)throw new TypeError("Invalid target: ".concat(d));this._sessionTimers.enabled&&Ve.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES);for(var C in _)Object.prototype.hasOwnProperty.call(_,C)&&this.on(C,_[C]);this._from_tag=Ve.newTag();var I=t.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 Oc("sip","anonymous","anonymous.invalid"),h.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),h.push("Privacy: id")):t.fromUserName&&(H.from_uri=new Oc("sip",t.fromUserName,this._ua.configuration.uri.host),h.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(H.from_display_name=t.fromDisplayName),h.push("Contact: ".concat(this._contact)),h.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&h.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher?";refresher=uac":"")),this._request=new sp.InitialOutgoingInviteRequest(a,this._ua,H,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,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(g,A,T)}},{key:"init_incoming",value:function(a,t){var n=this;K.debug("init_incoming()");var d,_=a.hasHeader("Content-Type")?a.getHeader("Content-Type").toLowerCase():void 0;if(a.body&&_!=="application/sdp"){a.reply(415);return}if(this._status=Q.STATUS_INVITE_RECEIVED,this._from_tag=a.from_tag,this._id=a.call_id+this._from_tag,this._request=a,this._contact=this._ua.contact.toString(),a.hasHeader("expires")&&(d=a.getHeader("expires")*1e3),a.to_tag=Ve.newTag(),!this._createDialog(a,"UAS",!0)){a.reply(500,"Missing Contact header field");return}a.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Q.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){a.reply(408),n._failed("local",null,ce.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),d&&(this._timers.expiresTimer=setTimeout(function(){n._status===Q.STATUS_WAITING_FOR_ANSWER&&(a.reply(487),n._failed("system",null,ce.causes.EXPIRES))},d)),this._direction="incoming",this._local_identity=a.to,this._remote_identity=a.from,t&&t(this),this._newRTCSession("remote",a),this._status!==Q.STATUS_TERMINATED&&(a.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))}},{key:"answer",value:function(){var a=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};K.debug("answer()");var n=this._request,d=Ve.cloneArray(t.extraHeaders),_=Ve.cloneObject(t.mediaConstraints),h=t.mediaStream||null,g=Ve.cloneObject(t.pcConfig,{iceServers:[]}),T=t.rtcConstraints||null,E=t.rtcAnswerConstraints||null,y=Ve.cloneObject(t.rtcOfferConstraints),A,C=!1,I=!1,H=!1,L=!1;if(this._rtcAnswerConstraints=E,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,this._direction!=="incoming")throw new pn.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==Q.STATUS_WAITING_FOR_ANSWER)throw new pn.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Ve.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES),this._status=Q.STATUS_ANSWERED,!this._createDialog(n,"UAS")){n.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),d.unshift("Contact: ".concat(this._contact));var ae=n.parseSDP();Array.isArray(ae.media)||(ae.media=[ae.media]);var N=_s(ae.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")&&(L=!0))}}catch(F){N.e(F)}finally{N.f()}if(h&&_.audio===!1){A=h.getAudioTracks();var ve=_s(A),M;try{for(ve.s();!(M=ve.n()).done;){var D=M.value;h.removeTrack(D)}}catch(F){ve.e(F)}finally{ve.f()}}if(h&&_.video===!1){A=h.getVideoTracks();var B=_s(A),V;try{for(B.s();!(V=B.n()).done;){var J=V.value;h.removeTrack(J)}}catch(F){B.e(F)}finally{B.f()}}!h&&_.audio===void 0&&(_.audio=H),!h&&_.video===void 0&&(_.video=L),!h&&!C&&!y.offerToReceiveAudio&&(_.audio=!1),!h&&!I&&!y.offerToReceiveVideo&&(_.video=!1),this._createRTCConnection(g,T),Promise.resolve().then(function(){if(h)return h;if(_.audio||_.video)return a._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(_).catch(function(F){throw a._status===Q.STATUS_TERMINATED?new Error("terminated"):(n.reply(480),a._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',F),a.emit("getusermediafailed",F),new Error("getUserMedia() failed"))})}).then(function(F){if(a._status===Q.STATUS_TERMINATED)throw new Error("terminated");a._localMediaStream=F,F&&F.getTracks().forEach(function(X){a._connection.addTrack(X,F)})}).then(function(){if(!a._late_sdp){var F={originator:"remote",type:"offer",sdp:n.body};K.debug('emit "sdp"'),a.emit("sdp",F);var X=new RTCSessionDescription({type:"offer",sdp:F.sdp});return a._connectionPromiseQueue=a._connectionPromiseQueue.then(function(){return a._connection.setRemoteDescription(X)}).catch(function(U){throw n.reply(488),a._failed("system",null,ce.causes.WEBRTC_ERROR),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',U),a.emit("peerconnection:setremotedescriptionfailed",U),new Error("peerconnection.setRemoteDescription() failed")}),a._connectionPromiseQueue}}).then(function(){if(a._status===Q.STATUS_TERMINATED)throw new Error("terminated");return a._connecting(n),a._late_sdp?a._createLocalDescription("offer",a._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):a._createLocalDescription("answer",E).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(F){if(a._status===Q.STATUS_TERMINATED)throw new Error("terminated");a._handleSessionTimersInIncomingRequest(n,d),n.reply(200,null,d,F,function(){a._status=Q.STATUS_WAITING_FOR_ACK,a._setInvite2xxTimer(n,F),a._setACKTimer(),a._accepted("local")},function(){a._failed("system",null,ce.causes.CONNECTION_ERROR)})}).catch(function(F){a._status!==Q.STATUS_TERMINATED&&K.warn(F)})}},{key:"terminate",value:function(){var a=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};K.debug("terminate()");var n=t.cause||ce.causes.BYE,d=Ve.cloneArray(t.extraHeaders),_=t.body,h,g=t.status_code,T=t.reason_phrase;if(this._status===Q.STATUS_TERMINATED)throw new pn.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"),g&&(g<200||g>=700))throw new TypeError("Invalid status_code: ".concat(g));g&&(T=T||ce.REASON_PHRASE[g]||"",h="SIP ;cause=".concat(g,' ;text="').concat(T,'"')),this._status===Q.STATUS_NULL||this._status===Q.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=h):this._status===Q.STATUS_1XX_RECEIVED&&this._request.cancel(h),this._status=Q.STATUS_CANCELED,this._failed("local",null,ce.causes.CANCELED);break;case Q.STATUS_WAITING_FOR_ANSWER:case Q.STATUS_ANSWERED:if(K.debug("rejecting session"),g=g||480,g<300||g>=700)throw new TypeError("Invalid status_code: ".concat(g));this._request.reply(g,T,d,_),this._failed("local",null,ce.causes.REJECTED);break;case Q.STATUS_WAITING_FOR_ACK:case Q.STATUS_CONFIRMED:if(K.debug("terminating session"),T=t.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===Q.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==bc.C.STATUS_TERMINATED){var E=this._dialog;this.receiveRequest=function(y){var A=y.method;A===ce.ACK&&(a.sendRequest(ce.BYE,{extraHeaders:d,body:_}),E.terminate())},this._request.server_transaction.on("stateChanged",function(){a._request.server_transaction.state===bc.C.STATUS_TERMINATED&&(a.sendRequest(ce.BYE,{extraHeaders:d,body:_}),E.terminate())}),this._ended("local",null,n),this._dialog=E,this._ua.newDialog(E)}else this.sendRequest(ce.BYE,{extraHeaders:d,body:_}),this._ended("local",null,n)}}},{key:"sendDTMF",value:function(a){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};K.debug("sendDTMF() | tones: %s",a);var n=0,d=t.duration||null,_=t.interToneGap||null,h=t.transportType||ce.DTMF_TRANSPORT.INFO;if(a===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 pn.InvalidStateError(this._status);if(h!==ce.DTMF_TRANSPORT.INFO&&h!==ce.DTMF_TRANSPORT.RFC2833)throw new TypeError("invalid transportType: ".concat(h));if(typeof a=="number"&&(a=a.toString()),!a||typeof a!="string"||!a.match(/^[0-9A-DR#*,]+$/i))throw new TypeError("Invalid tones: ".concat(a));if(d&&!Ve.isDecimal(d))throw new TypeError("Invalid tone duration: ".concat(d));if(d?d<xt.C.MIN_DURATION?(K.debug('"duration" value is lower than the minimum allowed, setting it to '.concat(xt.C.MIN_DURATION," milliseconds")),d=xt.C.MIN_DURATION):d>xt.C.MAX_DURATION?(K.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(xt.C.MAX_DURATION," milliseconds")),d=xt.C.MAX_DURATION):d=Math.abs(d):d=xt.C.DEFAULT_DURATION,t.duration=d,_&&!Ve.isDecimal(_))throw new TypeError("Invalid interToneGap: ".concat(_));if(_?_<xt.C.MIN_INTER_TONE_GAP?(K.debug('"interToneGap" value is lower than the minimum allowed, setting it to '.concat(xt.C.MIN_INTER_TONE_GAP," milliseconds")),_=xt.C.MIN_INTER_TONE_GAP):_=Math.abs(_):_=xt.C.DEFAULT_INTER_TONE_GAP,h===ce.DTMF_TRANSPORT.RFC2833){var g=this._getDTMFRTPSender();g&&(a=g.toneBuffer+a,g.insertDTMF(a,d,_));return}if(this._tones){this._tones+=a;return}this._tones=a,T.call(this);function T(){var E=this,y;if(this._status===Q.STATUS_TERMINATED||!this._tones||n>=this._tones.length){this._tones=null;return}var A=this._tones[n];if(n+=1,A===",")y=2e3;else{var C=new xt(this);t.eventHandlers={onFailed:function(){E._tones=null}},C.send(A,t),y=d+_}setTimeout(T.bind(this),y)}}},{key:"sendInfo",value:function(a,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(K.debug("sendInfo()"),this._status!==Q.STATUS_CONFIRMED&&this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_1XX_RECEIVED)throw new pn.InvalidStateError(this._status);var d=new wc(this);d.send(a,t,n)}},{key:"mute",value:function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!1};K.debug("mute()");var t=!1,n=!1;this._audioMuted===!1&&a.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&a.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(t===!0||n===!0)&&this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!0};K.debug("unmute()");var t=!1,n=!1;this._audioMuted===!0&&a.audio&&(t=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&a.video&&(n=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(t===!0||n===!0)&&this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var a=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;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");var d={succeeded:function(){n&&n()},failed:function(){a.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:d,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:d,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var a=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;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");var d={succeeded:function(){n&&n()},failed:function(){a.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:d,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:d,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var a=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;K.debug("renegotiate()");var d=t.rtcOfferConstraints||null;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;var _={succeeded:function(){n&&n()},failed:function(){a.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:_,rtcOfferConstraints:d,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:_,rtcOfferConstraints:d,extraHeaders:t.extraHeaders}),!0}},{key:"refer",value:function(a,t){var n=this;K.debug("refer()");var d=a;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;if(a=this._ua.normalizeTarget(a),!a)throw new TypeError("Invalid target: ".concat(d));var _=new ip(this);_.sendRefer(a,t);var h=_.id;return this._referSubscribers[h]=_,_.on("requestFailed",function(){delete n._referSubscribers[h]}),_.on("accepted",function(){delete n._referSubscribers[h]}),_.on("failed",function(){delete n._referSubscribers[h]}),_}},{key:"sendRequest",value:function(a,t){return K.debug("sendRequest()"),this._dialog.sendRequest(a,t)}},{key:"receiveRequest",value:function(a){var t=this;if(K.debug("receiveRequest()"),a.method===ce.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",a,ce.causes.CANCELED));else switch(a.method){case ce.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(!a.body){this.terminate({cause:ce.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:a.body};K.debug('emit "sdp"'),this.emit("sdp",n);var d=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(d)}).then(function(){t._is_confirmed||t._confirmed("remote",a)}).catch(function(h){t.terminate({cause:ce.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',h),t.emit("peerconnection:setremotedescriptionfailed",h)})}else this._is_confirmed||this._confirmed("remote",a);break;case ce.BYE:this._status===Q.STATUS_CONFIRMED||this._status===Q.STATUS_WAITING_FOR_ACK?(a.reply(200),this._ended("remote",a,ce.causes.BYE)):this._status===Q.STATUS_INVITE_RECEIVED||this._status===Q.STATUS_WAITING_FOR_ANSWER?(a.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",a,ce.causes.BYE)):a.reply(403,"Wrong Status");break;case ce.INVITE:this._status===Q.STATUS_CONFIRMED?a.hasHeader("replaces")?this._receiveReplaces(a):this._receiveReinvite(a):a.reply(403,"Wrong Status");break;case ce.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){var _=a.hasHeader("Content-Type")?a.getHeader("Content-Type").toLowerCase():void 0;_&&_.match(/^application\/dtmf-relay/i)?new xt(this).init_incoming(a):_!==void 0?new wc(this).init_incoming(a):a.reply(415)}else a.reply(403,"Wrong Status");break;case ce.UPDATE:this._status===Q.STATUS_CONFIRMED?this._receiveUpdate(a):a.reply(403,"Wrong Status");break;case ce.REFER:this._status===Q.STATUS_CONFIRMED?this._receiveRefer(a):a.reply(403,"Wrong Status");break;case ce.NOTIFY:this._status===Q.STATUS_CONFIRMED?this._receiveNotify(a):a.reply(403,"Wrong Status");break;default:a.reply(501)}}},{key:"onTransportError",value:function(){K.warn("onTransportError()"),this._status!==Q.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ce.causes.CONNECTION_ERROR,cause:ce.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){K.warn("onRequestTimeout()"),this._status!==Q.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:ce.causes.REQUEST_TIMEOUT,cause:ce.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){K.warn("onDialogError()"),this._status!==Q.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ce.causes.DIALOG_ERROR,cause:ce.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(a){K.debug("newDTMF()"),this.emit("newDTMF",a)}},{key:"newInfo",value:function(a){K.debug("newInfo()"),this.emit("newInfo",a)}},{key:"_isReadyToReOffer",value:function(){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)}},{key:"_close",value:function(){if(K.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(K.debug("close() | closing local MediaStream"),Ve.closeMediaStream(this._localMediaStream)),this._status!==Q.STATUS_TERMINATED){if(this._status=Q.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(d){K.warn("close() | error closing the RTCPeerConnection: %o",d)}for(var a in this._timers)Object.prototype.hasOwnProperty.call(this._timers,a)&&clearTimeout(this._timers[a]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(var t in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(a,t){var n=Ni.T1;function d(){this._status===Q.STATUS_WAITING_FOR_ACK&&(a.reply(200,null,["Contact: ".concat(this._contact)],t),n<Ni.T2&&(n=n*2,n>Ni.T2&&(n=Ni.T2)),this._timers.invite2xxTimer=setTimeout(d.bind(this),n))}this._timers.invite2xxTimer=setTimeout(d.bind(this),n)}},{key:"_setACKTimer",value:function(){var a=this;this._timers.ackTimer=setTimeout(function(){a._status===Q.STATUS_WAITING_FOR_ACK&&(K.debug("no ACK received, terminating the session"),clearTimeout(a._timers.invite2xxTimer),a.sendRequest(ce.BYE),a._ended("remote",null,ce.causes.NO_ACK))},Ni.TIMER_H)}},{key:"_createRTCConnection",value:function(a,t){var n=this;this._connection=new RTCPeerConnection(a,t),this._connection.addEventListener("iceconnectionstatechange",function(){var d=n._connection.iceConnectionState;d==="failed"&&n.terminate({cause:ce.causes.RTP_TIMEOUT,status_code:408,reason_phrase:ce.causes.RTP_TIMEOUT})}),K.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(a,t){var n=this;if(K.debug("createLocalDescription()"),a!=="offer"&&a!=="answer")throw new Error('createLocalDescription() | invalid type "'.concat(a,'"'));var d=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return a==="offer"?d.createOffer(t).catch(function(_){return K.warn('emit "peerconnection:createofferfailed" [error:%o]',_),n.emit("peerconnection:createofferfailed",_),Promise.reject(_)}):d.createAnswer(t).catch(function(_){return K.warn('emit "peerconnection:createanswerfailed" [error:%o]',_),n.emit("peerconnection:createanswerfailed",_),Promise.reject(_)})}).then(function(_){return d.setLocalDescription(_).catch(function(h){return n._rtcReady=!0,K.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',h),n.emit("peerconnection:setlocaldescriptionfailed",h),Promise.reject(h)})}).then(function(){var _=t&&t.iceRestart;if(d.iceGatheringState==="complete"&&!_||d.iceGatheringState==="gathering"&&n._iceReady){n._rtcReady=!0;var h={originator:"local",type:a,sdp:d.localDescription.sdp};return K.debug('emit "sdp"'),n.emit("sdp",h),Promise.resolve(h.sdp)}return new Promise(function(g){var T=!1,E,y;n._iceReady=!1;var A=function(){d.removeEventListener("icecandidate",E),d.removeEventListener("icegatheringstatechange",y),T=!0,n._rtcReady=!0,n._iceReady=!0;var I={originator:"local",type:a,sdp:d.localDescription.sdp};K.debug('emit "sdp"'),n.emit("sdp",I),g(I.sdp)};d.addEventListener("icecandidate",E=function(I){var H=I.candidate;H?n.emit("icecandidate",{candidate:H,ready:A}):T||A()}),d.addEventListener("icegatheringstatechange",y=function(){d.iceGatheringState==="complete"&&!T&&A()})})})}},{key:"_createDialog",value:function(a,t,n){var d=t==="UAS"?a.to_tag:a.from_tag,_=t==="UAS"?a.from_tag:a.to_tag,h=a.call_id+d+_,g=this._earlyDialogs[h];if(n)return g?!0:(g=new Hl(this,a,t,Hl.C.STATUS_EARLY),g.error?(K.debug(g.error),this._failed("remote",a,ce.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[h]=g,!0));if(this._from_tag=a.from_tag,this._to_tag=a.to_tag,g)return g.update(a,t),this._dialog=g,delete this._earlyDialogs[h],!0;var T=new Hl(this,a,t);return T.error?(K.debug(T.error),this._failed("remote",a,ce.causes.INTERNAL_ERROR),!1):(this._dialog=T,!0)}},{key:"_receiveReinvite",value:function(a){var t=this;K.debug("receiveReinvite()");var n=a.hasHeader("Content-Type")?a.getHeader("Content-Type").toLowerCase():void 0,d={request:a,callback:void 0,reject:h.bind(this)},_=!1;function h(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};_=!0;var E=T.status_code||403,y=T.reason_phrase||"",A=Ve.cloneArray(T.extraHeaders);if(this._status!==Q.STATUS_CONFIRMED)return!1;if(E<300||E>=700)throw new TypeError("Invalid status_code: ".concat(E));a.reply(E,y,A)}if(this.emit("reinvite",d),_)return;if(this._late_sdp=!1,!a.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._createLocalDescription("offer",t._rtcOfferConstraints)}).then(function(T){g.call(t,T)}).catch(function(){a.reply(500)});return}if(n!=="application/sdp"){K.debug("invalid Content-Type"),a.reply(415);return}this._processInDialogSdpOffer(a).then(function(T){t._status!==Q.STATUS_TERMINATED&&g.call(t,T)}).catch(function(T){K.warn(T)});function g(T){var E=this,y=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(a,y),this._late_sdp&&(T=this._mangleOffer(T)),a.reply(200,null,y,T,function(){E._status=Q.STATUS_WAITING_FOR_ACK,E._setInvite2xxTimer(a,T),E._setACKTimer()}),typeof d.callback=="function"&&d.callback()}}},{key:"_receiveUpdate",value:function(a){var t=this;K.debug("receiveUpdate()");var n=a.hasHeader("Content-Type")?a.getHeader("Content-Type").toLowerCase():void 0,d={request:a,callback:void 0,reject:h.bind(this)},_=!1;function h(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};_=!0;var E=T.status_code||403,y=T.reason_phrase||"",A=Ve.cloneArray(T.extraHeaders);if(this._status!==Q.STATUS_CONFIRMED)return!1;if(E<300||E>=700)throw new TypeError("Invalid status_code: ".concat(E));a.reply(E,y,A)}if(this.emit("update",d),_)return;if(!a.body){g.call(this,null);return}if(n!=="application/sdp"){K.debug("invalid Content-Type"),a.reply(415);return}this._processInDialogSdpOffer(a).then(function(T){t._status!==Q.STATUS_TERMINATED&&g.call(t,T)}).catch(function(T){K.warn(T)});function g(T){var E=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(a,E),a.reply(200,null,E,T),typeof d.callback=="function"&&d.callback()}}},{key:"_processInDialogSdpOffer",value:function(a){var t=this;K.debug("_processInDialogSdpOffer()");var n=a.parseSDP(),d=!1,_=_s(n.media),h;try{for(_.s();!(h=_.n()).done;){var g=h.value;if(Fl.indexOf(g.type)!==-1){var T=g.direction||n.direction||"sendrecv";if(T==="sendonly"||T==="inactive")d=!0;else{d=!1;break}}}}catch(A){_.e(A)}finally{_.f()}var E={originator:"remote",type:"offer",sdp:a.body};K.debug('emit "sdp"'),this.emit("sdp",E);var y=new RTCSessionDescription({type:"offer",sdp:E.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===Q.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(y).catch(function(A){throw a.reply(488),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',A),t.emit("peerconnection:setremotedescriptionfailed",A),A})}).then(function(){if(t._status===Q.STATUS_TERMINATED)throw new Error("terminated");t._remoteHold===!0&&d===!1?(t._remoteHold=!1,t._onunhold("remote")):t._remoteHold===!1&&d===!0&&(t._remoteHold=!0,t._onhold("remote"))}).then(function(){if(t._status===Q.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(A){throw a.reply(500),K.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',A),A})}).catch(function(A){K.warn("_processInDialogSdpOffer() failed [error: %o]",A)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(a){var t=this;if(K.debug("receiveRefer()"),!a.refer_to){K.debug("no Refer-To header field present in REFER"),a.reply(400);return}if(a.refer_to.uri.scheme!==ce.SIP){K.debug("Refer-To header field points to a non-SIP URI scheme"),a.reply(416);return}a.reply(202);var n=new rp(this,a.cseq);K.debug('emit "refer"'),this.emit("refer",{request:a,accept:function(g,T){d.call(t,g,T)},reject:function(){_.call(t)}});function d(h){var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(h=typeof h=="function"?h:null,this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;var T=new r(this._ua);if(T.on("progress",function(y){var A=y.response;n.notify(A.status_code,A.reason_phrase)}),T.on("accepted",function(y){var A=y.response;n.notify(A.status_code,A.reason_phrase)}),T.on("_failed",function(y){var A=y.message,C=y.cause;A?n.notify(A.status_code,A.reason_phrase):n.notify(487,C)}),a.refer_to.uri.hasHeader("replaces")){var E=decodeURIComponent(a.refer_to.uri.getHeader("replaces"));g.extraHeaders=Ve.cloneArray(g.extraHeaders),g.extraHeaders.push("Replaces: ".concat(E))}T.connect(a.refer_to.uri.toAor(),g,h)}function _(){n.notify(603)}}},{key:"_receiveNotify",value:function(a){switch(K.debug("receiveNotify()"),a.event||a.reply(400),a.event.event){case"refer":{var t,n;if(a.event.params&&a.event.params.id)t=a.event.params.id,n=this._referSubscribers[t];else if(Object.keys(this._referSubscribers).length===1)n=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{a.reply(400,"Missing event id parameter");return}if(!n){a.reply(481,"Subscription does not exist");return}n.receiveNotify(a),a.reply(200);break}default:a.reply(489)}}},{key:"_receiveReplaces",value:function(a){var t=this;K.debug("receiveReplaces()");function n(_){var h=this;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;var g=new r(this._ua);g.on("confirmed",function(){h.terminate()}),g.init_incoming(a,_)}function d(){K.debug("Replaced INVITE rejected by the user"),a.reply(486)}this.emit("replaces",{request:a,accept:function(h){n.call(t,h)},reject:function(){d.call(t)}})}},{key:"_sendInitialRequest",value:function(a,t,n){var d=this,_=new np(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(n)return n;if(a.audio||a.video)return d._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(a).catch(function(h){throw d._status===Q.STATUS_TERMINATED?new Error("terminated"):(d._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',h),d.emit("getusermediafailed",h),h)})}).then(function(h){if(d._status===Q.STATUS_TERMINATED)throw new Error("terminated");return d._localMediaStream=h,h&&h.getTracks().forEach(function(g){d._connection.addTrack(g,h)}),d._connecting(d._request),d._createLocalDescription("offer",t).catch(function(g){throw d._failed("local",null,ce.causes.WEBRTC_ERROR),g})}).then(function(h){if(d._is_canceled||d._status===Q.STATUS_TERMINATED)throw new Error("terminated");d._request.body=h,d._status=Q.STATUS_INVITE_SENT,K.debug('emit "sending" [request:%o]',d._request),d.emit("sending",{request:d._request}),_.send()}).catch(function(h){d._status!==Q.STATUS_TERMINATED&&K.warn(h)})}},{key:"_getDTMFRTPSender",value:function(){var a=this._connection.getSenders().find(function(t){return t.track&&t.track.kind==="audio"});if(!(a&&a.dtmf)){K.warn("sendDTMF() | no local audio track to send DTMF with");return}return a.dtmf}},{key:"_receiveInviteResponse",value:function(a){var t=this;if(K.debug("receiveInviteResponse()"),this._dialog&&a.status_code>=200&&a.status_code<=299)if(this._dialog.id.call_id===a.call_id&&this._dialog.id.local_tag===a.from_tag&&this._dialog.id.remote_tag===a.to_tag){this.sendRequest(ce.ACK);return}else{var n=new Hl(this,a,"UAC");if(n.error!==void 0){K.debug(n.error);return}this.sendRequest(ce.ACK),this.sendRequest(ce.BYE);return}if(this._is_canceled){a.status_code>=100&&a.status_code<200?this._request.cancel(this._cancel_reason):a.status_code>=200&&a.status_code<299&&this._acceptAndTerminate(a);return}if(!(this._status!==Q.STATUS_INVITE_SENT&&this._status!==Q.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(a.status_code):this._status=Q.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(a.status_code):{if(!a.to_tag){K.debug("1xx response received without to tag");break}if(a.hasHeader("contact")&&!this._createDialog(a,"UAC",!0))break;if(this._status=Q.STATUS_1XX_RECEIVED,!a.body){this._progress("remote",a);break}var d={originator:"remote",type:"answer",sdp:a.body};K.debug('emit "sdp"'),this.emit("sdp",d);var _=new RTCSessionDescription({type:"answer",sdp:d.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(_)}).then(function(){return t._progress("remote",a)}).catch(function(E){K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),t.emit("peerconnection:setremotedescriptionfailed",E)});break}case/^2[0-9]{2}$/.test(a.status_code):{if(this._status=Q.STATUS_CONFIRMED,!a.body){this._acceptAndTerminate(a,400,ce.causes.MISSING_SDP),this._failed("remote",a,ce.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(a,"UAC"))break;var h={originator:"remote",type:"answer",sdp:a.body};K.debug('emit "sdp"'),this.emit("sdp",h);var g=new RTCSessionDescription({type:"answer",sdp:h.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._connection.signalingState==="stable")return t._connection.createOffer(t._rtcOfferConstraints).then(function(E){return t._connection.setLocalDescription(E)}).catch(function(E){t._acceptAndTerminate(a,500,E.toString()),t._failed("local",a,ce.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(g).then(function(){t._handleSessionTimersInIncomingResponse(a),t._accepted("remote",a),t.sendRequest(ce.ACK),t._confirmed("local",null)}).catch(function(E){t._acceptAndTerminate(a,488,"Not Acceptable Here"),t._failed("remote",a,ce.causes.BAD_MEDIA_DESCRIPTION),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),t.emit("peerconnection:setremotedescriptionfailed",E)})});break}default:{var T=Ve.sipErrorCause(a.status_code);this._failed("remote",a,T)}}}},{key:"_sendReinvite",value:function(){var a=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};K.debug("sendReinvite()");var n=Ve.cloneArray(t.extraHeaders),d=Ve.cloneObject(t.eventHandlers),_=t.rtcOfferConstraints||this._rtcOfferConstraints||null,h=!1;n.push("Contact: ".concat(this._contact)),n.push("Content-Type: application/sdp"),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return a._createLocalDescription("offer",_)}).then(function(E){E=a._mangleOffer(E);var y={originator:"local",type:"offer",sdp:E};K.debug('emit "sdp"'),a.emit("sdp",y),a.sendRequest(ce.INVITE,{extraHeaders:n,body:E,eventHandlers:{onSuccessResponse:function(C){g.call(a,C),h=!0},onErrorResponse:function(C){T.call(a,C)},onTransportError:function(){a.onTransportError()},onRequestTimeout:function(){a.onRequestTimeout()},onDialogError:function(){a.onDialogError()}}})}).catch(function(){T()});function g(E){var y=this;if(this._status!==Q.STATUS_TERMINATED&&(this.sendRequest(ce.ACK),!h)){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};K.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),K.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 a=this,t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};K.debug("sendUpdate()");var n=Ve.cloneArray(t.extraHeaders),d=Ve.cloneObject(t.eventHandlers),_=t.rtcOfferConstraints||this._rtcOfferConstraints||null,h=t.sdpOffer||!1,g=!1;n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),h?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return a._createLocalDescription("offer",_)}).then(function(y){y=a._mangleOffer(y);var A={originator:"local",type:"offer",sdp:y};K.debug('emit "sdp"'),a.emit("sdp",A),a.sendRequest(ce.UPDATE,{extraHeaders:n,body:y,eventHandlers:{onSuccessResponse:function(I){T.call(a,I),g=!0},onErrorResponse:function(I){E.call(a,I)},onTransportError:function(){a.onTransportError()},onRequestTimeout:function(){a.onRequestTimeout()},onDialogError:function(){a.onDialogError()}}})}).catch(function(){E.call(a)})):this.sendRequest(ce.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(A){T.call(a,A)},onErrorResponse:function(A){E.call(a,A)},onTransportError:function(){a.onTransportError()},onRequestTimeout:function(){a.onRequestTimeout()},onDialogError:function(){a.onDialogError()}}});function T(y){var A=this;if(this._status!==Q.STATUS_TERMINATED&&!g)if(this._handleSessionTimersInIncomingResponse(y),h){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};K.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),K.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(a,t,n){K.debug("acceptAndTerminate()");var d=[];t&&(n=n||ce.REASON_PHRASE[t]||"",d.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(a,"UAC"))&&(this.sendRequest(ce.ACK),this.sendRequest(ce.BYE,{extraHeaders:d})),this._status=Q.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(a){if(!this._localHold&&!this._remoteHold)return a;if(a=Ic.parse(a),this._localHold&&!this._remoteHold){K.debug("mangleOffer() | me on hold, mangling offer");var t=_s(a.media),n;try{for(t.s();!(n=t.n()).done;){var d=n.value;Fl.indexOf(d.type)!==-1&&(d.direction?d.direction==="sendrecv"?d.direction="sendonly":d.direction==="recvonly"&&(d.direction="inactive"):d.direction="sendonly")}}catch(A){t.e(A)}finally{t.f()}}else if(this._localHold&&this._remoteHold){K.debug("mangleOffer() | both on hold, mangling offer");var _=_s(a.media),h;try{for(_.s();!(h=_.n()).done;){var g=h.value;Fl.indexOf(g.type)!==-1&&(g.direction="inactive")}}catch(A){_.e(A)}finally{_.f()}}else if(this._remoteHold){K.debug("mangleOffer() | remote on hold, mangling offer");var T=_s(a.media),E;try{for(T.s();!(E=T.n()).done;){var y=E.value;Fl.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 Ic.write(a)}},{key:"_setLocalMediaStatus",value:function(){var a=!0,t=!0;(this._localHold||this._remoteHold)&&(a=!1,t=!1),this._audioMuted&&(a=!1),this._videoMuted&&(t=!1),this._toggleMuteAudio(!a),this._toggleMuteVideo(!t)}},{key:"_handleSessionTimersInIncomingRequest",value:function(a,t){if(this._sessionTimers.enabled){var n;a.session_expires&&a.session_expires>=ce.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=a.session_expires,n=a.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uas"),t.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(n)),this._sessionTimers.refresher=n==="uas",this._runSessionTimer()}}},{key:"_handleSessionTimersInIncomingResponse",value:function(a){if(this._sessionTimers.enabled){var t;a.session_expires&&a.session_expires>=ce.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=a.session_expires,t=a.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher=t==="uac",this._runSessionTimer()}}},{key:"_runSessionTimer",value:function(){var a=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){a._status!==Q.STATUS_TERMINATED&&a._isReadyToReOffer()&&(K.debug("runSessionTimer() | sending session refresh request"),a._sessionTimers.refreshMethod===ce.UPDATE?a._sendUpdate():a._sendReinvite())},t*500):this._sessionTimers.timer=setTimeout(function(){a._status!==Q.STATUS_TERMINATED&&(K.warn("runSessionTimer() | timer expired, terminating the session"),a.terminate({cause:ce.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},t*1100)}},{key:"_toggleMuteAudio",value:function(a){var t=this._connection.getSenders().filter(function(h){return h.track&&h.track.kind==="audio"}),n=_s(t),d;try{for(n.s();!(d=n.n()).done;){var _=d.value;_.track.enabled=!a}}catch(h){n.e(h)}finally{n.f()}}},{key:"_toggleMuteVideo",value:function(a){var t=this._connection.getSenders().filter(function(h){return h.track&&h.track.kind==="video"}),n=_s(t),d;try{for(n.s();!(d=n.n()).done;){var _=d.value;_.track.enabled=!a}}catch(h){n.e(h)}finally{n.f()}}},{key:"_newRTCSession",value:function(a,t){K.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:a,session:this,request:t})}},{key:"_connecting",value:function(a){K.debug("session connecting"),K.debug('emit "connecting"'),this.emit("connecting",{request:a})}},{key:"_progress",value:function(a,t){K.debug("session progress"),K.debug('emit "progress"'),this.emit("progress",{originator:a,response:t||null})}},{key:"_accepted",value:function(a,t){K.debug("session accepted"),this._start_time=new Date,K.debug('emit "accepted"'),this.emit("accepted",{originator:a,response:t||null})}},{key:"_confirmed",value:function(a,t){K.debug("session confirmed"),this._is_confirmed=!0,K.debug('emit "confirmed"'),this.emit("confirmed",{originator:a,ack:t||null})}},{key:"_ended",value:function(a,t,n){K.debug("session ended"),this._end_time=new Date,this._close(),K.debug('emit "ended"'),this.emit("ended",{originator:a,message:t||null,cause:n})}},{key:"_failed",value:function(a,t,n){K.debug("session failed"),K.debug('emit "_failed"'),this.emit("_failed",{originator:a,message:t||null,cause:n}),this._close(),K.debug('emit "failed"'),this.emit("failed",{originator:a,message:t||null,cause:n})}},{key:"_onhold",value:function(a){K.debug("session onhold"),this._setLocalMediaStatus(),K.debug('emit "hold"'),this.emit("hold",{originator:a})}},{key:"_onunhold",value:function(a){K.debug("session onunhold"),this._setLocalMediaStatus(),K.debug('emit "unhold"'),this.emit("unhold",{originator:a})}},{key:"_onmute",value:function(a){var t=a.audio,n=a.video;K.debug("session onmute"),this._setLocalMediaStatus(),K.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(a){var t=a.audio,n=a.video;K.debug("session onunmute"),this._setLocalMediaStatus(),K.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}},{key:"C",get:function(){return Q}},{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(a){this._data=a}},{key:"status",get:function(){return this._status}}]),r}(ep);function So(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?So=function(r){return typeof r}:So=function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},So(c)}function op(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function Dc(c,s){for(var r=0;r<s.length;r++){var o=s[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function ap(c,s,r){return s&&Dc(c.prototype,s),r&&Dc(c,r),c}function up(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&_u(c,s)}function _u(c,s){return _u=Object.setPrototypeOf||function(o,a){return o.__proto__=a,o},_u(c,s)}function cp(c){var s=hp();return function(){var o=Uo(c),a;if(s){var t=Uo(this).constructor;a=Reflect.construct(o,arguments,t)}else a=o.apply(this,arguments);return fp(this,a)}}function fp(c,s){return s&&(So(s)==="object"||typeof s=="function")?s:_p(c)}function _p(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function hp(){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 Uo(c){return Uo=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)},Uo(c)}var dp=ft.EventEmitter,pp=_t,Sa=it,mp=vs,Ui=bt(),gp=ul,Nc=Bs,Tp=Gs(),jl=new pp("Message"),vp=function(c){up(r,c);var s=cp(r);function r(o){var a;return op(this,r),a=s.call(this),a._ua=o,a._request=null,a._closed=!1,a._direction=null,a._local_identity=null,a._remote_identity=null,a._is_replied=!1,a._data={},a}return ap(r,[{key:"send",value:function(a,t){var n=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},_=a;if(a===void 0||t===void 0)throw new TypeError("Not enough arguments");if(a=this._ua.normalizeTarget(a),!a)throw new TypeError("Invalid target: ".concat(_));var h=Ui.cloneArray(d.extraHeaders),g=Ui.cloneObject(d.eventHandlers),T=d.contentType||"text/plain",E={};d.fromUserName&&(E.from_uri=new Tp("sip",d.fromUserName,this._ua.configuration.uri.host),h.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]);h.push("Content-Type: ".concat(T)),this._request=new mp.OutgoingRequest(Sa.MESSAGE,a,this._ua,E,h),t&&(this._request.body=t);var A=new gp(this._ua,this._request,{onRequestTimeout:function(){n._onRequestTimeout()},onTransportError:function(){n._onTransportError()},onReceiveResponse:function(I){n._receiveResponse(I)}});this._newMessage("local",this._request),A.send()}},{key:"init_incoming",value:function(a){this._request=a,this._newMessage("remote",a),this._is_replied||(this._is_replied=!0,a.reply(200)),this._close()}},{key:"accept",value:function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=Ui.cloneArray(a.extraHeaders),n=a.body;if(this._direction!=="incoming")throw new Nc.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,t,n)}},{key:"reject",value:function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=a.status_code||480,n=a.reason_phrase,d=Ui.cloneArray(a.extraHeaders),_=a.body;if(this._direction!=="incoming")throw new Nc.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(t<300||t>=700)throw new TypeError("Invalid status_code: ".concat(t));this._is_replied=!0,this._request.reply(t,n,d,_)}},{key:"_receiveResponse",value:function(a){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(a.status_code):break;case/^2[0-9]{2}$/.test(a.status_code):this._succeeded("remote",a);break;default:{var t=Ui.sipErrorCause(a.status_code);this._failed("remote",a,t);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,Sa.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,Sa.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newMessage",value:function(a,t){a==="remote"?(this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from):a==="local"&&(this._direction="outgoing",this._local_identity=t.from,this._remote_identity=t.to),this._ua.newMessage(this,{originator:a,message:this,request:t})}},{key:"_failed",value:function(a,t,n){jl.debug("MESSAGE failed"),this._close(),jl.debug('emit "failed"'),this.emit("failed",{originator:a,response:t||null,cause:n})}},{key:"_succeeded",value:function(a,t){jl.debug("MESSAGE succeeded"),this._close(),jl.debug('emit "succeeded"'),this.emit("succeeded",{originator:a,response:t})}},{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}}]),r}(dp);function yo(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?yo=function(r){return typeof r}:yo=function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},yo(c)}function Ep(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function Uc(c,s){for(var r=0;r<s.length;r++){var o=s[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Sp(c,s,r){return s&&Uc(c.prototype,s),r&&Uc(c,r),c}function yp(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&hu(c,s)}function hu(c,s){return hu=Object.setPrototypeOf||function(o,a){return o.__proto__=a,o},hu(c,s)}function Ap(c){var s=Ip();return function(){var o=Po(c),a;if(s){var t=Po(this).constructor;a=Reflect.construct(o,arguments,t)}else a=o.apply(this,arguments);return Cp(this,a)}}function Cp(c,s){return s&&(yo(s)==="object"||typeof s=="function")?s:Rp(c)}function Rp(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Ip(){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 Po(c){return Po=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)},Po(c)}var bp=ft.EventEmitter,wp=_t,ya=it,Op=vs,Pi=bt(),Dp=ul,Pc=Bs,ql=new wp("Options"),Np=function(c){yp(r,c);var s=Ap(r);function r(o){var a;return Ep(this,r),a=s.call(this),a._ua=o,a._request=null,a._closed=!1,a._direction=null,a._local_identity=null,a._remote_identity=null,a._is_replied=!1,a._data={},a}return Sp(r,[{key:"send",value:function(a,t){var n=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},_=a;if(a===void 0)throw new TypeError("A target is required for OPTIONS");if(a=this._ua.normalizeTarget(a),!a)throw new TypeError("Invalid target: ".concat(_));var h=Pi.cloneArray(d.extraHeaders),g=Pi.cloneObject(d.eventHandlers),T=d.contentType||"application/sdp";for(var E in g)Object.prototype.hasOwnProperty.call(g,E)&&this.on(E,g[E]);h.push("Content-Type: ".concat(T)),this._request=new Op.OutgoingRequest(ya.OPTIONS,a,this._ua,null,h),t&&(this._request.body=t);var y=new Dp(this._ua,this._request,{onRequestTimeout:function(){n._onRequestTimeout()},onTransportError:function(){n._onTransportError()},onReceiveResponse:function(C){n._receiveResponse(C)}});this._newOptions("local",this._request),y.send()}},{key:"init_incoming",value:function(a){this._request=a,this._newOptions("remote",a),this._is_replied||(this._is_replied=!0,a.reply(200)),this._close()}},{key:"accept",value:function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=Pi.cloneArray(a.extraHeaders),n=a.body;if(this._direction!=="incoming")throw new Pc.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,t,n)}},{key:"reject",value:function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=a.status_code||480,n=a.reason_phrase,d=Pi.cloneArray(a.extraHeaders),_=a.body;if(this._direction!=="incoming")throw new Pc.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(t<300||t>=700)throw new TypeError("Invalid status_code: ".concat(t));this._is_replied=!0,this._request.reply(t,n,d,_)}},{key:"_receiveResponse",value:function(a){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(a.status_code):break;case/^2[0-9]{2}$/.test(a.status_code):this._succeeded("remote",a);break;default:{var t=Pi.sipErrorCause(a.status_code);this._failed("remote",a,t);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,ya.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,ya.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newOptions",value:function(a,t){a==="remote"?(this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from):a==="local"&&(this._direction="outgoing",this._local_identity=t.from,this._remote_identity=t.to),this._ua.newOptions(this,{originator:a,message:this,request:t})}},{key:"_failed",value:function(a,t,n){ql.debug("OPTIONS failed"),this._close(),ql.debug('emit "failed"'),this.emit("failed",{originator:a,response:t||null,cause:n})}},{key:"_succeeded",value:function(a,t){ql.debug("OPTIONS succeeded"),this._close(),ql.debug('emit "succeeded"'),this.emit("succeeded",{originator:a,response:t})}},{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}}]),r}(bp),Ou={},Up=_t,Aa=bt(),Pp=is(),xi=new Up("Socket");Ou.isSocket=function(c){if(Array.isArray(c))return!1;if(typeof c>"u")return xi.warn("undefined JsSIP.Socket instance"),!1;try{if(!Aa.isString(c.url))throw xi.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!Aa.isString(c.via_transport))throw xi.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(Pp.parse(c.sip_uri,"SIP_URI")===-1)throw xi.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(s){if(!Aa.isFunction(c[s]))throw xi.warn("missing or invalid JsSIP.Socket method: ".concat(s)),new Error("Missing or invalid JsSIP.Socket method: ".concat(s))})}catch{return!1}return!0};function xp(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function xc(c,s){for(var r=0;r<s.length;r++){var o=s[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Mp(c,s,r){return s&&xc(c.prototype,s),r&&xc(c,r),c}var kp=_t,Lp=Ou,Mc=it,Nt=new kp("Transport"),jt={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:Mc.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:Mc.CONNECTION_RECOVERY_MAX_INTERVAL}},$p=function(){function c(s){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:jt.recovery_options;xp(this,c),Nt.debug("new()"),this.status=jt.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=r,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(o){Nt.warn("cannot use TextDecoder: ".concat(o))}if(typeof s>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");s instanceof Array||(s=[s]),s.forEach(function(o){if(!Lp.isSocket(o.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(o.weight&&!Number(o.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:o.socket,weight:o.weight||0,status:jt.SOCKET_STATUS_READY})},this),this._getSocket()}return Mp(c,[{key:"connect",value:function(){if(Nt.debug("connect()"),this.isConnected()){Nt.debug("Transport is already connected");return}else if(this.isConnecting()){Nt.debug("Transport is connecting");return}this.close_requested=!1,this.status=jt.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(){Nt.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=jt.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(r){if(Nt.debug("send()"),!this.isConnected())return Nt.warn("unable to send message, transport is not connected"),!1;var o=r.toString();return Nt.debug(`sending message:
46
+ `),this.transport.send(p)}}]),i}(n_),Ph=function(c){Nu(i,c);var s=Uu(i);function i(){var l;return tl(this,i),l=s.call(this),l.headers={},l.status_code=null,l.reason_phrase=null,l}return i}(n_),Rs={OutgoingRequest:s_,InitialOutgoingInviteRequest:Nh,IncomingRequest:Uh,IncomingResponse:Ph};function xh(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function rc(c,s){for(var i=0;i<s.length;i++){var l=s[i];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(c,l.key,l)}}function Mh(c,s,i){return s&&rc(c.prototype,s),i&&rc(c,i),c}var kh=dt,ms=Nt(),Yt=new kh("DigestAuthentication"),Lh=function(){function c(s){xh(this,c),this._credentials=s,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 Mh(c,[{key:"get",value:function(i){switch(i){case"realm":return this._realm;case"ha1":return this._ha1;default:Yt.warn('get() | cannot get "%s" parameter',i);return}}},{key:"authenticate",value:function(i,l){var a=i.method,_=i.ruri,e=i.body,p=arguments.length>2&&arguments[2]!==void 0?arguments[2]:null;if(this._algorithm=l.algorithm,this._realm=l.realm,this._nonce=l.nonce,this._opaque=l.opaque,this._stale=l.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(l.qop)if(l.qop.indexOf("auth-int")>-1)this._qop="auth-int";else if(l.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=a,this._uri=_,this._cnonce=p||ms.createRandomToken(12),this._nc+=1;var g=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-g.length)+g,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=ms.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1;var n,v;return this._qop==="auth"?(n="".concat(this._method,":").concat(this._uri),v=ms.calculateMD5(n),Yt.debug('authenticate() | using qop=auth [a2:"%s"]',n),this._response=ms.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(v))):this._qop==="auth-int"?(n="".concat(this._method,":").concat(this._uri,":").concat(ms.calculateMD5(e||"")),v=ms.calculateMD5(n),Yt.debug('authenticate() | using qop=auth-int [a2:"%s"]',n),this._response=ms.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(v))):this._qop===null&&(n="".concat(this._method,":").concat(this._uri),v=ms.calculateMD5(n),Yt.debug('authenticate() | using qop=null [a2:"%s"]',n),this._response=ms.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(v))),Yt.debug("authenticate() | response generated"),!0}},{key:"toString",value:function(){var i=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return i.push("algorithm=".concat(this._algorithm)),i.push('username="'.concat(this._credentials.username,'"')),i.push('realm="'.concat(this._realm,'"')),i.push('nonce="'.concat(this._nonce,'"')),i.push('uri="'.concat(this._uri,'"')),i.push('response="'.concat(this._response,'"')),this._opaque&&i.push('opaque="'.concat(this._opaque,'"')),this._qop&&(i.push("qop=".concat(this._qop)),i.push('cnonce="'.concat(this._cnonce,'"')),i.push("nc=".concat(this._ncHex))),"Digest ".concat(i.join(", "))}}]),c}(),gs=500,$h=4e3,ic=5e3,r_={T1:gs,T2:$h,T4:ic,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*ic,TIMER_L:64*gs,TIMER_M:64*gs,PROVISIONAL_RESPONSE_INTERVAL:6e4};function Ia(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ia=function(i){return typeof i}:Ia=function(i){return i&&typeof Symbol=="function"&&i.constructor===Symbol&&i!==Symbol.prototype?"symbol":typeof i},Ia(c)}function sl(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function lc(c,s){for(var i=0;i<s.length;i++){var l=s[i];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(c,l.key,l)}}function nl(c,s,i){return s&&lc(c.prototype,s),i&&lc(c,i),c}function rl(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&fu(c,s)}function fu(c,s){return fu=Object.setPrototypeOf||function(l,a){return l.__proto__=a,l},fu(c,s)}function il(c){var s=Fh();return function(){var l=La(c),a;if(s){var _=La(this).constructor;a=Reflect.construct(l,arguments,_)}else a=l.apply(this,arguments);return Hh(this,a)}}function Hh(c,s){return s&&(Ia(s)==="object"||typeof s=="function")?s:Qs(c)}function Qs(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Fh(){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 La(c){return La=Object.setPrototypeOf?Object.getPrototypeOf:function(i){return i.__proto__||Object.getPrototypeOf(i)},La(c)}var ll=ht.EventEmitter,al=dt,Ki=ot,ac=Rs,as=r_,oc=new al("NonInviteClientTransaction"),Wl=new al("InviteClientTransaction"),jh=new al("AckClientTransaction"),uc=new al("NonInviteServerTransaction"),Kl=new al("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"},qh=function(c){rl(i,c);var s=il(i);function i(l,a,_,e){var p;sl(this,i),p=s.call(this),p.type=fe.NON_INVITE_CLIENT,p.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),p.ua=l,p.transport=a,p.request=_,p.eventHandlers=e;var g="SIP/2.0/".concat(a.via_transport);return g+=" ".concat(l.configuration.via_host,";branch=").concat(p.id),p.request.setHeader("via",g),p.ua.newTransaction(Qs(p)),p}return nl(i,[{key:"stateChanged",value:function(a){this.state=a,this.emit("stateChanged")}},{key:"send",value:function(){var a=this;this.stateChanged(fe.STATUS_TRYING),this.F=setTimeout(function(){a.timer_F()},as.TIMER_F),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){oc.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}},{key:"timer_F",value:function(){oc.debug("Timer F expired for transaction ".concat(this.id)),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}},{key:"timer_K",value:function(){this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"receiveResponse",value:function(a){var _=this,e=a.status_code;if(e<200)switch(this.state){case fe.STATUS_TRYING:case fe.STATUS_PROCEEDING:this.stateChanged(fe.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(a);break}else switch(this.state){case fe.STATUS_TRYING:case fe.STATUS_PROCEEDING:this.stateChanged(fe.STATUS_COMPLETED),clearTimeout(this.F),e===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(a),this.K=setTimeout(function(){_.timer_K()},as.TIMER_K);break;case fe.STATUS_COMPLETED:break}}},{key:"C",get:function(){return fe}}]),i}(ll),Vh=function(c){rl(i,c);var s=il(i);function i(l,a,_,e){var p;sl(this,i),p=s.call(this),p.type=fe.INVITE_CLIENT,p.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),p.ua=l,p.transport=a,p.request=_,p.eventHandlers=e,_.transaction=Qs(p);var g="SIP/2.0/".concat(a.via_transport);return g+=" ".concat(l.configuration.via_host,";branch=").concat(p.id),p.request.setHeader("via",g),p.ua.newTransaction(Qs(p)),p}return nl(i,[{key:"stateChanged",value:function(a){this.state=a,this.emit("stateChanged")}},{key:"send",value:function(){var a=this;this.stateChanged(fe.STATUS_CALLING),this.B=setTimeout(function(){a.timer_B()},as.TIMER_B),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==fe.STATUS_ACCEPTED&&(Wl.debug("transport error occurred, deleting transaction ".concat(this.id)),this.eventHandlers.onTransportError()),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_M",value:function(){Wl.debug("Timer M expired for transaction ".concat(this.id)),this.state===fe.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"timer_B",value:function(){Wl.debug("Timer B expired for transaction ".concat(this.id)),this.state===fe.STATUS_CALLING&&(this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}},{key:"timer_D",value:function(){Wl.debug("Timer D expired for transaction ".concat(this.id)),clearTimeout(this.B),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"sendACK",value:function(a){var _=this,e=new ac.OutgoingRequest(Ki.ACK,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});e.setHeader("from",this.request.getHeader("from")),e.setHeader("via",this.request.getHeader("via")),e.setHeader("to",a.getHeader("to")),this.D=setTimeout(function(){_.timer_D()},as.TIMER_D),this.transport.send(e)}},{key:"cancel",value:function(a){if(this.state===fe.STATUS_PROCEEDING){var _=new ac.OutgoingRequest(Ki.CANCEL,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});_.setHeader("from",this.request.getHeader("from")),_.setHeader("via",this.request.getHeader("via")),_.setHeader("to",this.request.getHeader("to")),a&&_.setHeader("reason",a),this.transport.send(_)}}},{key:"receiveResponse",value:function(a){var _=this,e=a.status_code;if(e>=100&&e<=199)switch(this.state){case fe.STATUS_CALLING:this.stateChanged(fe.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(a);break;case fe.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(a);break}else if(e>=200&&e<=299)switch(this.state){case fe.STATUS_CALLING:case fe.STATUS_PROCEEDING:this.stateChanged(fe.STATUS_ACCEPTED),this.M=setTimeout(function(){_.timer_M()},as.TIMER_M),this.eventHandlers.onReceiveResponse(a);break;case fe.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(a);break}else if(e>=300&&e<=699)switch(this.state){case fe.STATUS_CALLING:case fe.STATUS_PROCEEDING:this.stateChanged(fe.STATUS_COMPLETED),this.sendACK(a),this.eventHandlers.onReceiveResponse(a);break;case fe.STATUS_COMPLETED:this.sendACK(a);break}}},{key:"C",get:function(){return fe}}]),i}(ll),Bh=function(c){rl(i,c);var s=il(i);function i(l,a,_,e){var p;sl(this,i),p=s.call(this),p.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),p.transport=a,p.request=_,p.eventHandlers=e;var g="SIP/2.0/".concat(a.via_transport);return g+=" ".concat(l.configuration.via_host,";branch=").concat(p.id),p.request.setHeader("via",g),p}return nl(i,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){jh.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return fe}}]),i}(ll),Gh=function(c){rl(i,c);var s=il(i);function i(l,a,_){var e;return sl(this,i),e=s.call(this),e.type=fe.NON_INVITE_SERVER,e.id=_.via_branch,e.ua=l,e.transport=a,e.request=_,e.last_response="",_.server_transaction=Qs(e),e.state=fe.STATUS_TRYING,l.newTransaction(Qs(e)),e}return nl(i,[{key:"stateChanged",value:function(a){this.state=a,this.emit("stateChanged")}},{key:"timer_J",value:function(){uc.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,uc.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(a,_,e,p){var g=this;if(a===100)switch(this.state){case fe.STATUS_TRYING:this.stateChanged(fe.STATUS_PROCEEDING),this.transport.send(_)||this.onTransportError();break;case fe.STATUS_PROCEEDING:this.last_response=_,this.transport.send(_)?e&&e():(this.onTransportError(),p&&p());break}else if(a>=200&&a<=699)switch(this.state){case fe.STATUS_TRYING:case fe.STATUS_PROCEEDING:this.stateChanged(fe.STATUS_COMPLETED),this.last_response=_,this.J=setTimeout(function(){g.timer_J()},as.TIMER_J),this.transport.send(_)?e&&e():(this.onTransportError(),p&&p());break;case fe.STATUS_COMPLETED:break}}},{key:"C",get:function(){return fe}}]),i}(ll),Wh=function(c){rl(i,c);var s=il(i);function i(l,a,_){var e;return sl(this,i),e=s.call(this),e.type=fe.INVITE_SERVER,e.id=_.via_branch,e.ua=l,e.transport=a,e.request=_,e.last_response="",_.server_transaction=Qs(e),e.state=fe.STATUS_PROCEEDING,l.newTransaction(Qs(e)),e.resendProvisionalTimer=null,_.reply(100),e}return nl(i,[{key:"stateChanged",value:function(a){this.state=a,this.emit("stateChanged")}},{key:"timer_H",value:function(){Kl.debug("Timer H expired for transaction ".concat(this.id)),this.state===fe.STATUS_COMPLETED&&Kl.debug("ACK not received, dialog will be terminated"),this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){Kl.debug("Timer L expired for transaction ".concat(this.id)),this.state===fe.STATUS_ACCEPTED&&(this.stateChanged(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,Kl.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(fe.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"resend_provisional",value:function(){this.transport.send(this.last_response)||this.onTransportError()}},{key:"receiveResponse",value:function(a,_,e,p){var g=this;if(a>=100&&a<=199)switch(this.state){case fe.STATUS_PROCEEDING:this.transport.send(_)||this.onTransportError(),this.last_response=_;break}if(a>100&&a<=199&&this.state===fe.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(function(){g.resend_provisional()},as.PROVISIONAL_RESPONSE_INTERVAL));else if(a>=200&&a<=299)switch(this.state){case fe.STATUS_PROCEEDING:this.stateChanged(fe.STATUS_ACCEPTED),this.last_response=_,this.L=setTimeout(function(){g.timer_L()},as.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case fe.STATUS_ACCEPTED:this.transport.send(_)?e&&e():(this.onTransportError(),p&&p());break}else if(a>=300&&a<=699)switch(this.state){case fe.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(_)?(this.stateChanged(fe.STATUS_COMPLETED),this.H=setTimeout(function(){g.timer_H()},as.TIMER_H),e&&e()):(this.onTransportError(),p&&p());break}}},{key:"C",get:function(){return fe}}]),i}(ll);function Kh(c,s){var i=c._transactions,l;switch(s.method){case Ki.INVITE:if(l=i.ist[s.via_branch],l){switch(l.state){case fe.STATUS_PROCEEDING:l.transport.send(l.last_response);break;case fe.STATUS_ACCEPTED:break}return!0}break;case Ki.ACK:if(l=i.ist[s.via_branch],l){if(l.state===fe.STATUS_ACCEPTED)return!1;if(l.state===fe.STATUS_COMPLETED)return l.state=fe.STATUS_CONFIRMED,l.I=setTimeout(function(){l.timer_I()},as.TIMER_I),!0}else return!1;break;case Ki.CANCEL:return l=i.ist[s.via_branch],l?(s.reply_sl(200),l.state!==fe.STATUS_PROCEEDING):(s.reply_sl(481),!0);default:if(l=i.nist[s.via_branch],l){switch(l.state){case fe.STATUS_TRYING:break;case fe.STATUS_PROCEEDING:case fe.STATUS_COMPLETED:l.transport.send(l.last_response);break}return!0}break}}var ol={C:fe,NonInviteClientTransaction:qh,InviteClientTransaction:Vh,AckClientTransaction:Bh,NonInviteServerTransaction:Gh,InviteServerTransaction:Wh,checkTransaction:Kh};function Yh(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function cc(c,s){for(var i=0;i<s.length;i++){var l=s[i];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(c,l.key,l)}}function Jh(c,s,i){return s&&cc(c.prototype,s),i&&cc(c,i),c}var zh=dt,fc=ot,Xh=Lh,To=ol,Qh=new zh("RequestSender"),vo={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}},ul=function(){function c(s,i,l){Yh(this,c),this._ua=s,this._eventHandlers=l,this._method=i.method,this._request=i,this._auth=null,this._challenged=!1,this._staled=!1;for(var a in vo)Object.prototype.hasOwnProperty.call(vo,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=vo[a]));s.status===s.C.STATUS_USER_CLOSED&&(this._method!==fc.BYE||this._method!==fc.ACK)&&this._eventHandlers.onTransportError()}return Jh(c,[{key:"send",value:function(){var i=this,l={onRequestTimeout:function(){i._eventHandlers.onRequestTimeout()},onTransportError:function(){i._eventHandlers.onTransportError()},onReceiveResponse:function(_){i._receiveResponse(_)}};switch(this._method){case"INVITE":this.clientTransaction=new To.InviteClientTransaction(this._ua,this._ua.transport,this._request,l);break;case"ACK":this.clientTransaction=new To.AckClientTransaction(this._ua,this._ua.transport,this._request,l);break;default:this.clientTransaction=new To.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,l)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}},{key:"_receiveResponse",value:function(i){var l,a,_=i.status_code;if((_===401||_===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(i.status_code===401?(l=i.parseHeader("www-authenticate"),a="authorization"):(l=i.parseHeader("proxy-authenticate"),a="proxy-authorization"),!l){Qh.debug("".concat(i.status_code," with wrong or missing challenge, cannot authenticate")),this._eventHandlers.onReceiveResponse(i);return}if(!this._challenged||!this._staled&&l.stale===!0){if(this._auth||(this._auth=new Xh({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,l)){this._eventHandlers.onReceiveResponse(i);return}this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),l.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(a,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(i)}else this._eventHandlers.onReceiveResponse(i)}}]),c}();function Zh(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function _c(c,s){for(var i=0;i<s.length;i++){var l=s[i];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(c,l.key,l)}}function ed(c,s,i){return s&&_c(c.prototype,s),i&&_c(c,i),c}var td=dt,Eo=Nt(),yn=ot,hc=Rs,dc=ul,wi=new td("Registrator"),Yl=10,sd=function(){function c(s,i){Zh(this,c),this._reg_id=1,this._ua=s,this._transport=i,this._registrar=s.configuration.registrar_server,this._expires=s.configuration.register_expires,this._call_id=Eo.createRandomToken(22),this._cseq=0,this._to_uri=s.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 ed(c,[{key:"setExtraHeaders",value:function(i){Array.isArray(i)||(i=[]),this._extraHeaders=i.slice()}},{key:"setExtraContactParams",value:function(i){i instanceof Object||(i={}),this._extraContactParams="";for(var l in i)if(Object.prototype.hasOwnProperty.call(i,l)){var a=i[l];this._extraContactParams+=";".concat(l),a&&(this._extraContactParams+="=".concat(a))}}},{key:"register",value:function(){var i=this;if(this._registering){wi.debug("Register request in progress...");return}var l=this._extraHeaders.slice();l.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),l.push("Expires: ".concat(this._expires));var a=new hc.OutgoingRequest(yn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},l),_=new dc(this._ua,a,{onRequestTimeout:function(){i._registrationFailure(null,yn.causes.REQUEST_TIMEOUT)},onTransportError:function(){i._registrationFailure(null,yn.causes.CONNECTION_ERROR)},onAuthenticated:function(){i._cseq+=1},onReceiveResponse:function(p){if(p.cseq===i._cseq)switch(i._registrationTimer!==null&&(clearTimeout(i._registrationTimer),i._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(p.status_code):break;case/^2[0-9]{2}$/.test(p.status_code):{if(i._registering=!1,!p.hasHeader("Contact")){wi.debug("no Contact header in response to REGISTER, response ignored");break}var g=p.headers.Contact.reduce(function(C,A){return C.concat(A.parsed)},[]),n=g.find(function(C){return i._sipInstance===C.getParam("+sip.instance")&&i._reg_id===parseInt(C.getParam("reg-id"))});if(n||(n=g.find(function(C){return C.uri.user===i._ua.contact.uri.user})),!n){wi.debug("no Contact header pointing to us, response ignored");break}var v=n.getParam("expires");!v&&p.hasHeader("expires")&&(v=p.getHeader("expires")),v||(v=i._expires),v=Number(v),v<Yl&&(v=Yl);var S=v>64?v*1e3/2+Math.floor((v/2-32)*1e3*Math.random()):v*1e3-5e3;i._registrationTimer=setTimeout(function(){i._registrationTimer=null,i._ua.listeners("registrationExpiring").length===0?i.register():i._ua.emit("registrationExpiring")},S),n.hasParam("temp-gruu")&&(i._ua.contact.temp_gruu=n.getParam("temp-gruu").replace(/"/g,"")),n.hasParam("pub-gruu")&&(i._ua.contact.pub_gruu=n.getParam("pub-gruu").replace(/"/g,"")),i._registered||(i._registered=!0,i._ua.registered({response:p}));break}case/^423$/.test(p.status_code):{p.hasHeader("min-expires")?(i._expires=Number(p.getHeader("min-expires")),i._expires<Yl&&(i._expires=Yl),i.register()):(wi.debug("423 response received for REGISTER without Min-Expires"),i._registrationFailure(p,yn.causes.SIP_FAILURE_CODE));break}default:{var m=Eo.sipErrorCause(p.status_code);i._registrationFailure(p,m)}}}});this._registering=!0,_.send()}},{key:"unregister",value:function(){var i=this,l=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!this._registered){wi.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);var a=this._extraHeaders.slice();l.all?a.push("Contact: *".concat(this._extraContactParams)):a.push("Contact: ".concat(this._contact,";expires=0").concat(this._extraContactParams)),a.push("Expires: 0");var _=new hc.OutgoingRequest(yn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},a),e=new dc(this._ua,_,{onRequestTimeout:function(){i._unregistered(null,yn.causes.REQUEST_TIMEOUT)},onTransportError:function(){i._unregistered(null,yn.causes.CONNECTION_ERROR)},onAuthenticated:function(){i._cseq+=1},onReceiveResponse:function(g){switch(!0){case/^1[0-9]{2}$/.test(g.status_code):break;case/^2[0-9]{2}$/.test(g.status_code):i._unregistered(g);break;default:{var n=Eo.sipErrorCause(g.status_code);i._unregistered(g,n)}}}});e.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(i,l){this._registering=!1,this._ua.registrationFailed({response:i||null,cause:l}),this._registered&&(this._registered=!1,this._ua.unregistered({response:i||null,cause:l}))}},{key:"_unregistered",value:function(i,l){this._registering=!1,this._registered=!1,this._ua.unregistered({response:i||null,cause:l||null})}},{key:"registered",get:function(){return this._registered}}]),c}();function nd(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function pc(c,s){for(var i=0;i<s.length;i++){var l=s[i];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(c,l.key,l)}}function rd(c,s,i){return s&&pc(c.prototype,s),i&&pc(c,i),c}var So=ot,Jl=ol,id=ul,yo={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}},ld=function(){function c(s,i,l){nd(this,c),this._dialog=s,this._ua=s._ua,this._request=i,this._eventHandlers=l,this._reattempt=!1,this._reattemptTimer=null;for(var a in yo)Object.prototype.hasOwnProperty.call(yo,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=yo[a]))}return rd(c,[{key:"send",value:function(){var i=this,l=new id(this._ua,this._request,{onRequestTimeout:function(){i._eventHandlers.onRequestTimeout()},onTransportError:function(){i._eventHandlers.onTransportError()},onAuthenticated:function(e){i._eventHandlers.onAuthenticated(e)},onReceiveResponse:function(e){i._receiveResponse(e)}});if(l.send(),(this._request.method===So.INVITE||this._request.method===So.UPDATE&&this._request.body)&&l.clientTransaction.state!==Jl.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;var a=function _(){(l.clientTransaction.state===Jl.C.STATUS_ACCEPTED||l.clientTransaction.state===Jl.C.STATUS_COMPLETED||l.clientTransaction.state===Jl.C.STATUS_TERMINATED)&&(l.clientTransaction.removeListener("stateChanged",_),i._dialog.uac_pending_reply=!1)};l.clientTransaction.on("stateChanged",a)}}},{key:"_receiveResponse",value:function(i){var l=this;i.status_code===408||i.status_code===481?this._eventHandlers.onDialogError(i):i.method===So.INVITE&&i.status_code===491?this._reattempt?i.status_code>=200&&i.status_code<300?this._eventHandlers.onSuccessResponse(i):i.status_code>=300&&this._eventHandlers.onErrorResponse(i):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(function(){l._dialog.isTerminated()||(l._reattempt=!0,l.send())},1e3)):i.status_code>=200&&i.status_code<300?this._eventHandlers.onSuccessResponse(i):i.status_code>=300&&this._eventHandlers.onErrorResponse(i)}},{key:"request",get:function(){return this._request}}]),c}();function ad(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function mc(c,s){for(var i=0;i<s.length;i++){var l=s[i];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(c,l.key,l)}}function gc(c,s,i){return s&&mc(c.prototype,s),i&&mc(c,i),c}var od=dt,Tc=Rs,Bs=ot,Oi=ol,ud=ld,Ao=Nt(),Co=new od("Dialog"),Gs={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3},cd=function(){gc(c,null,[{key:"C",get:function(){return Gs}}]);function c(s,i,l){var a=arguments.length>3&&arguments[3]!==void 0?arguments[3]:Gs.STATUS_CONFIRMED;if(ad(this,c),this._owner=s,this._ua=s._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!i.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};i instanceof Tc.IncomingResponse&&(a=i.status_code<200?Gs.STATUS_EARLY:Gs.STATUS_CONFIRMED);var _=i.parseHeader("contact");l==="UAS"?(this._id={call_id:i.call_id,local_tag:i.to_tag,remote_tag:i.from_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._remote_seqnum=i.cseq,this._local_uri=i.parseHeader("to").uri,this._remote_uri=i.parseHeader("from").uri,this._remote_target=_.uri,this._route_set=i.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):l==="UAC"&&(this._id={call_id:i.call_id,local_tag:i.from_tag,remote_tag:i.to_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._local_seqnum=i.cseq,this._local_uri=i.parseHeader("from").uri,this._remote_uri=i.parseHeader("to").uri,this._remote_target=_.uri,this._route_set=i.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),Co.debug("new ".concat(l," dialog created with status ").concat(this._state===Gs.STATUS_EARLY?"EARLY":"CONFIRMED"))}return gc(c,[{key:"isTerminated",value:function(){return this._status===Gs.STATUS_TERMINATED}},{key:"update",value:function(i,l){this._state=Gs.STATUS_CONFIRMED,Co.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),l==="UAC"&&(this._route_set=i.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){Co.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this),this._state=Gs.STATUS_TERMINATED}},{key:"sendRequest",value:function(i){var l=this,a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},_=Ao.cloneArray(a.extraHeaders),e=Ao.cloneObject(a.eventHandlers),p=a.body||null,g=this._createRequest(i,_,p);e.onAuthenticated=function(){l._local_seqnum+=1};var n=new ud(this,g,e);return n.send(),g}},{key:"receiveRequest",value:function(i){this._checkInDialogRequest(i)&&(i.method===Bs.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:i.method===Bs.INVITE&&(this._ack_seqnum=i.cseq),this._owner.receiveRequest(i))}},{key:"_createRequest",value:function(i,l,a){l=Ao.cloneArray(l),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));var _=i===Bs.CANCEL||i===Bs.ACK?this._local_seqnum:this._local_seqnum+=1,e=new Tc.OutgoingRequest(i,this._remote_target,this._ua,{cseq:_,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},l,a);return e}},{key:"_checkInDialogRequest",value:function(i){var l=this;if(!this._remote_seqnum)this._remote_seqnum=i.cseq;else if(i.cseq<this._remote_seqnum)if(i.method===Bs.ACK){if(this._ack_seqnum===null||i.cseq!==this._ack_seqnum)return!1}else return i.reply(500),!1;else i.cseq>this._remote_seqnum&&(this._remote_seqnum=i.cseq);if(i.method===Bs.INVITE||i.method===Bs.UPDATE&&i.body){if(this._uac_pending_reply===!0)i.reply(491);else if(this._uas_pending_reply===!0){var a=(Math.random()*10|0)+1;return i.reply(500,null,["Retry-After:".concat(a)]),!1}else{this._uas_pending_reply=!0;var _=function e(){(i.server_transaction.state===Oi.C.STATUS_ACCEPTED||i.server_transaction.state===Oi.C.STATUS_COMPLETED||i.server_transaction.state===Oi.C.STATUS_TERMINATED)&&(i.server_transaction.removeListener("stateChanged",e),l._uas_pending_reply=!1)};i.server_transaction.on("stateChanged",_)}i.hasHeader("contact")&&i.server_transaction.on("stateChanged",function(){i.server_transaction.state===Oi.C.STATUS_ACCEPTED&&(l._remote_target=i.parseHeader("contact").uri)})}else i.method===Bs.NOTIFY&&i.hasHeader("contact")&&i.server_transaction.on("stateChanged",function(){i.server_transaction.state===Oi.C.STATUS_COMPLETED&&(l._remote_target=i.parseHeader("contact").uri)});return!0}},{key:"id",get:function(){return this._id}},{key:"local_seqnum",get:function(){return this._local_seqnum},set:function(i){this._local_seqnum=i}},{key:"owner",get:function(){return this._owner}},{key:"uac_pending_reply",get:function(){return this._uac_pending_reply},set:function(i){this._uac_pending_reply=i}},{key:"uas_pending_reply",get:function(){return this._uas_pending_reply}}]),c}(),Pu={exports:{}};function ba(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?ba=function(i){return typeof i}:ba=function(i){return i&&typeof Symbol=="function"&&i.constructor===Symbol&&i!==Symbol.prototype?"symbol":typeof i},ba(c)}function fd(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function vc(c,s){for(var i=0;i<s.length;i++){var l=s[i];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(c,l.key,l)}}function _d(c,s,i){return s&&vc(c.prototype,s),i&&vc(c,i),c}function hd(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&_u(c,s)}function _u(c,s){return _u=Object.setPrototypeOf||function(l,a){return l.__proto__=a,l},_u(c,s)}function dd(c){var s=gd();return function(){var l=$a(c),a;if(s){var _=$a(this).constructor;a=Reflect.construct(l,arguments,_)}else a=l.apply(this,arguments);return pd(this,a)}}function pd(c,s){return s&&(ba(s)==="object"||typeof s=="function")?s:md(c)}function md(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function gd(){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 $a(c){return $a=Object.setPrototypeOf?Object.getPrototypeOf:function(i){return i.__proto__||Object.getPrototypeOf(i)},$a(c)}var Td=ht.EventEmitter,vd=dt,Ed=ot,Sd=en,Ec=Nt(),yd=new vd("RTCSession:DTMF"),i_={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};Pu.exports=function(c){hd(i,c);var s=dd(i);function i(l){var a;return fd(this,i),a=s.call(this),a._session=l,a._direction=null,a._tone=null,a._duration=null,a._request=null,a}return _d(i,[{key:"send",value:function(a){var _=this,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(a===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 Sd.InvalidStateError(this._session.status);var p=Ec.cloneArray(e.extraHeaders);if(this.eventHandlers=Ec.cloneObject(e.eventHandlers),typeof a=="string")a=a.toUpperCase();else if(typeof a=="number")a=a.toString();else throw new TypeError("Invalid tone: ".concat(a));if(a.match(/^[0-9A-DR#*]$/))this._tone=a;else throw new TypeError("Invalid tone: ".concat(a));this._duration=e.duration,p.push("Content-Type: application/dtmf-relay");var g="Signal=".concat(this._tone,`\r
47
+ `);g+="Duration=".concat(this._duration),this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(Ed.INFO,{extraHeaders:p,eventHandlers:{onSuccessResponse:function(v){_.emit("succeeded",{originator:"remote",response:v})},onErrorResponse:function(v){_.eventHandlers.onFailed&&_.eventHandlers.onFailed(),_.emit("failed",{originator:"remote",response:v})},onRequestTimeout:function(){_._session.onRequestTimeout()},onTransportError:function(){_._session.onTransportError()},onDialogError:function(){_._session.onDialogError()}},body:g})}},{key:"init_incoming",value:function(a){var _=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,e=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=a,a.reply(200),a.body){var p=a.body.split(`
48
+ `);p.length>=1&&_.test(p[0])&&(this._tone=p[0].replace(_,"$2")),p.length>=2&&e.test(p[1])&&(this._duration=parseInt(p[1].replace(e,"$2"),10))}this._duration||(this._duration=i_.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:a}):yd.debug("invalid INFO DTMF received, discarded")}},{key:"tone",get:function(){return this._tone}},{key:"duration",get:function(){return this._duration}}]),i}(Td);Pu.exports.C=i_;var Ad=Pu.exports;function wa(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?wa=function(i){return typeof i}:wa=function(i){return i&&typeof Symbol=="function"&&i.constructor===Symbol&&i!==Symbol.prototype?"symbol":typeof i},wa(c)}function Cd(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function Sc(c,s){for(var i=0;i<s.length;i++){var l=s[i];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(c,l.key,l)}}function Rd(c,s,i){return s&&Sc(c.prototype,s),i&&Sc(c,i),c}function Id(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&hu(c,s)}function hu(c,s){return hu=Object.setPrototypeOf||function(l,a){return l.__proto__=a,l},hu(c,s)}function bd(c){var s=Dd();return function(){var l=Ha(c),a;if(s){var _=Ha(this).constructor;a=Reflect.construct(l,arguments,_)}else a=l.apply(this,arguments);return wd(this,a)}}function wd(c,s){return s&&(wa(s)==="object"||typeof s=="function")?s:Od(c)}function Od(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Dd(){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 Ha(c){return Ha=Object.setPrototypeOf?Object.getPrototypeOf:function(i){return i.__proto__||Object.getPrototypeOf(i)},Ha(c)}var Nd=ht.EventEmitter,Ud=ot,Pd=en,xd=Nt(),Md=function(c){Id(i,c);var s=bd(i);function i(l){var a;return Cd(this,i),a=s.call(this),a._session=l,a._direction=null,a._contentType=null,a._body=null,a}return Rd(i,[{key:"send",value:function(a,_){var e=this,p=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(this._direction="outgoing",a===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 Pd.InvalidStateError(this._session.status);this._contentType=a,this._body=_;var g=xd.cloneArray(p.extraHeaders);g.push("Content-Type: ".concat(a)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(Ud.INFO,{extraHeaders:g,eventHandlers:{onSuccessResponse:function(v){e.emit("succeeded",{originator:"remote",response:v})},onErrorResponse:function(v){e.emit("failed",{originator:"remote",response:v})},onTransportError:function(){e._session.onTransportError()},onRequestTimeout:function(){e._session.onRequestTimeout()},onDialogError:function(){e._session.onDialogError()}},body:_})}},{key:"init_incoming",value:function(a){this._direction="incoming",this.request=a,a.reply(200),this._contentType=a.hasHeader("Content-Type")?a.getHeader("Content-Type").toLowerCase():void 0,this._body=a.body,this._session.newInfo({originator:"remote",info:this,request:a})}},{key:"contentType",get:function(){return this._contentType}},{key:"body",get:function(){return this._body}}]),i}(Nd);function kd(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function yc(c,s){for(var i=0;i<s.length;i++){var l=s[i];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(c,l.key,l)}}function Ld(c,s,i){return s&&yc(c.prototype,s),i&&yc(c,i),c}var $d=dt,Ac=ot,Hd=new $d("RTCSession:ReferNotifier"),Ro={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300},Fd=function(){function c(s,i,l){kd(this,c),this._session=s,this._id=i,this._expires=l||Ro.expires,this._active=!0,this.notify(100)}return Ld(c,[{key:"notify",value:function(i,l){if(Hd.debug("notify()"),this._active!==!1){l=l||Ac.REASON_PHRASE[i]||"";var a;i>=200?a="terminated;reason=noresource":a="active;expires=".concat(this._expires),this._session.sendRequest(Ac.NOTIFY,{extraHeaders:["Event: ".concat(Ro.event_type,";id=").concat(this._id),"Subscription-State: ".concat(a),"Content-Type: ".concat(Ro.body_type)],body:"SIP/2.0 ".concat(i," ").concat(l),eventHandlers:{onErrorResponse:function(){this._active=!1}}})}}}]),c}();function Oa(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Oa=function(i){return typeof i}:Oa=function(i){return i&&typeof Symbol=="function"&&i.constructor===Symbol&&i!==Symbol.prototype?"symbol":typeof i},Oa(c)}function jd(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function Cc(c,s){for(var i=0;i<s.length;i++){var l=s[i];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(c,l.key,l)}}function qd(c,s,i){return s&&Cc(c.prototype,s),i&&Cc(c,i),c}function Vd(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&du(c,s)}function du(c,s){return du=Object.setPrototypeOf||function(l,a){return l.__proto__=a,l},du(c,s)}function Bd(c){var s=Kd();return function(){var l=Fa(c),a;if(s){var _=Fa(this).constructor;a=Reflect.construct(l,arguments,_)}else a=l.apply(this,arguments);return Gd(this,a)}}function Gd(c,s){return s&&(Oa(s)==="object"||typeof s=="function")?s:Wd(c)}function Wd(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Kd(){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 Fa(c){return Fa=Object.setPrototypeOf?Object.getPrototypeOf:function(i){return i.__proto__||Object.getPrototypeOf(i)},Fa(c)}var Yd=ht.EventEmitter,Jd=dt,Di=ot,zd=us(),Rc=Nt(),An=new Jd("RTCSession:ReferSubscriber"),Xd=function(c){Vd(i,c);var s=Bd(i);function i(l){var a;return jd(this,i),a=s.call(this),a._id=null,a._session=l,a}return qd(i,[{key:"sendRefer",value:function(a){var _=this,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};An.debug("sendRefer()");var p=Rc.cloneArray(e.extraHeaders),g=Rc.cloneObject(e.eventHandlers);for(var n in g)Object.prototype.hasOwnProperty.call(g,n)&&this.on(n,g[n]);var v=null;e.replaces&&(v=e.replaces._request.call_id,v+=";to-tag=".concat(e.replaces._to_tag),v+=";from-tag=".concat(e.replaces._from_tag),v=encodeURIComponent(v));var S="Refer-To: <".concat(a).concat(v?"?Replaces=".concat(v):"",">");if(p.push(S),!p.some(function(A){return A.toLowerCase().startsWith("referred-by:")})){var m="Referred-By: <".concat(this._session._ua._configuration.uri._scheme,":").concat(this._session._ua._configuration.uri._user,"@").concat(this._session._ua._configuration.uri._host,">");p.push(m)}p.push("Contact: ".concat(this._session.contact));var C=this._session.sendRequest(Di.REFER,{extraHeaders:p,eventHandlers:{onSuccessResponse:function(R){_._requestSucceeded(R)},onErrorResponse:function(R){_._requestFailed(R,Di.causes.REJECTED)},onTransportError:function(){_._requestFailed(null,Di.causes.CONNECTION_ERROR)},onRequestTimeout:function(){_._requestFailed(null,Di.causes.REQUEST_TIMEOUT)},onDialogError:function(){_._requestFailed(null,Di.causes.DIALOG_ERROR)}}});this._id=C.cseq}},{key:"receiveNotify",value:function(a){if(An.debug("receiveNotify()"),!!a.body){var _=zd.parse(a.body.trim().split(`\r
49
+ `,1)[0],"Status_Line");if(_===-1){An.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(a.body,'"'));return}switch(!0){case/^100$/.test(_.status_code):this.emit("trying",{request:a,status_line:_});break;case/^1[0-9]{2}$/.test(_.status_code):this.emit("progress",{request:a,status_line:_});break;case/^2[0-9]{2}$/.test(_.status_code):this.emit("accepted",{request:a,status_line:_});break;default:this.emit("failed",{request:a,status_line:_});break}}}},{key:"_requestSucceeded",value:function(a){An.debug("REFER succeeded"),An.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:a})}},{key:"_requestFailed",value:function(a,_){An.debug("REFER failed"),An.debug('emit "requestFailed"'),this.emit("requestFailed",{response:a||null,cause:_})}},{key:"id",get:function(){return this._id}}]),i}(Yd);function Da(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Da=function(i){return typeof i}:Da=function(i){return i&&typeof Symbol=="function"&&i.constructor===Symbol&&i!==Symbol.prototype?"symbol":typeof i},Da(c)}function Ts(c,s){var i;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(i=Qd(c))||s&&c&&typeof c.length=="number"){i&&(c=i);var l=0,a=function(){};return{s:a,n:function(){return l>=c.length?{done:!0}:{done:!1,value:c[l++]}},e:function(n){throw n},f:a}}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 _=!0,e=!1,p;return{s:function(){i=c[Symbol.iterator]()},n:function(){var n=i.next();return _=n.done,n},e:function(n){e=!0,p=n},f:function(){try{!_&&i.return!=null&&i.return()}finally{if(e)throw p}}}}function Qd(c,s){if(c){if(typeof c=="string")return Ic(c,s);var i=Object.prototype.toString.call(c).slice(8,-1);if(i==="Object"&&c.constructor&&(i=c.constructor.name),i==="Map"||i==="Set")return Array.from(c);if(i==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return Ic(c,s)}}function Ic(c,s){(s==null||s>c.length)&&(s=c.length);for(var i=0,l=new Array(s);i<s;i++)l[i]=c[i];return l}function Zd(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function bc(c,s){for(var i=0;i<s.length;i++){var l=s[i];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(c,l.key,l)}}function wc(c,s,i){return s&&bc(c.prototype,s),i&&bc(c,i),c}function ep(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&pu(c,s)}function pu(c,s){return pu=Object.setPrototypeOf||function(l,a){return l.__proto__=a,l},pu(c,s)}function tp(c){var s=rp();return function(){var l=ja(c),a;if(s){var _=ja(this).constructor;a=Reflect.construct(l,arguments,_)}else a=l.apply(this,arguments);return sp(this,a)}}function sp(c,s){return s&&(Da(s)==="object"||typeof s=="function")?s:np(c)}function np(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function rp(){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 ja(c){return ja=Object.setPrototypeOf?Object.getPrototypeOf:function(i){return i.__proto__||Object.getPrototypeOf(i)},ja(c)}var ip=ht.EventEmitter,Oc=kt,lp=dt,ue=ot,Cn=en,Dc=ol,Ye=Nt(),Ni=r_,ap=Rs,zl=cd,op=ul,Lt=Ad,Nc=Md,up=Fd,cp=Xd,Uc=tn(),J=new lp("RTCSession"),ee={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},Xl=["audio","video"],fp=function(c){ep(i,c);var s=tp(i);wc(i,null,[{key:"C",get:function(){return ee}}]);function i(l){var a;return Zd(this,i),J.debug("new"),a=s.call(this),a._id=null,a._ua=l,a._status=ee.STATUS_NULL,a._dialog=null,a._earlyDialogs={},a._contact=null,a._from_tag=null,a._to_tag=null,a._connection=null,a._connectionPromiseQueue=Promise.resolve(),a._request=null,a._is_canceled=!1,a._cancel_reason="",a._is_confirmed=!1,a._late_sdp=!1,a._rtcOfferConstraints=null,a._rtcAnswerConstraints=null,a._localMediaStream=null,a._localMediaStreamLocallyGenerated=!1,a._rtcReady=!0,a._iceReady=!1,a._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},a._direction=null,a._local_identity=null,a._remote_identity=null,a._start_time=null,a._end_time=null,a._tones=null,a._audioMuted=!1,a._videoMuted=!1,a._localHold=!1,a._remoteHold=!1,a._sessionTimers={enabled:a._ua.configuration.session_timers,refreshMethod:a._ua.configuration.session_timers_refresh_method,defaultExpires:ue.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},a._referSubscribers={},a._data={},a}return wc(i,[{key:"isInProgress",value:function(){switch(this._status){case ee.STATUS_NULL:case ee.STATUS_INVITE_SENT:case ee.STATUS_1XX_RECEIVED:case ee.STATUS_INVITE_RECEIVED:case ee.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}},{key:"isEstablished",value:function(){switch(this._status){case ee.STATUS_ANSWERED:case ee.STATUS_WAITING_FOR_ACK:case ee.STATUS_CONFIRMED:return!0;default:return!1}}},{key:"isEnded",value:function(){switch(this._status){case ee.STATUS_CANCELED:case ee.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(a){var _=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},e=arguments.length>2?arguments[2]:void 0;J.debug("connect()");var p=a,g=Ye.cloneObject(_.eventHandlers),n=Ye.cloneArray(_.extraHeaders),v=Ye.cloneObject(_.mediaConstraints,{audio:!0,video:!0}),S=_.mediaStream||null,m=Ye.cloneObject(_.pcConfig,{iceServers:[]}),C=_.rtcConstraints||null,A=_.rtcOfferConstraints||null;if(this._rtcOfferConstraints=A,this._rtcAnswerConstraints=_.rtcAnswerConstraints||null,this._data=_.data||this._data,a===void 0)throw new TypeError("Not enough arguments");if(this._status!==ee.STATUS_NULL)throw new Cn.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new Cn.NotSupportedError("WebRTC not supported");if(a=this._ua.normalizeTarget(a),!a)throw new TypeError("Invalid target: ".concat(p));this._sessionTimers.enabled&&Ye.isDecimal(_.sessionTimersExpires)&&(_.sessionTimersExpires>=ue.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=_.sessionTimersExpires:this._sessionTimers.defaultExpires=ue.SESSION_EXPIRES);for(var R in g)Object.prototype.hasOwnProperty.call(g,R)&&this.on(R,g[R]);this._from_tag=Ye.newTag();var I=_.anonymous||!1,V={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:I,outbound:!0}),I?(V.from_display_name="Anonymous",V.from_uri=new Uc("sip","anonymous","anonymous.invalid"),n.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),n.push("Privacy: id")):_.fromUserName&&(V.from_uri=new Uc("sip",_.fromUserName,this._ua.configuration.uri.host),n.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),_.fromDisplayName&&(V.from_display_name=_.fromDisplayName),n.push("Contact: ".concat(this._contact)),n.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&n.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher?";refresher=uac":"")),this._request=new ap.InitialOutgoingInviteRequest(a,this._ua,V,n),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(m,C),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,e&&e(this),this._newRTCSession("local",this._request),this._sendInitialRequest(v,A,S)}},{key:"init_incoming",value:function(a,_){var e=this;J.debug("init_incoming()");var p,g=a.hasHeader("Content-Type")?a.getHeader("Content-Type").toLowerCase():void 0;if(a.body&&g!=="application/sdp"){a.reply(415);return}if(this._status=ee.STATUS_INVITE_RECEIVED,this._from_tag=a.from_tag,this._id=a.call_id+this._from_tag,this._request=a,this._contact=this._ua.contact.toString(),a.hasHeader("expires")&&(p=a.getHeader("expires")*1e3),a.to_tag=Ye.newTag(),!this._createDialog(a,"UAS",!0)){a.reply(500,"Missing Contact header field");return}a.body?this._late_sdp=!1:this._late_sdp=!0,this._status=ee.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){a.reply(408),e._failed("local",null,ue.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),p&&(this._timers.expiresTimer=setTimeout(function(){e._status===ee.STATUS_WAITING_FOR_ANSWER&&(a.reply(487),e._failed("system",null,ue.causes.EXPIRES))},p)),this._direction="incoming",this._local_identity=a.to,this._remote_identity=a.from,_&&_(this),this._newRTCSession("remote",a),this._status!==ee.STATUS_TERMINATED&&(a.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))}},{key:"answer",value:function(){var a=this,_=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};J.debug("answer()");var e=this._request,p=Ye.cloneArray(_.extraHeaders),g=Ye.cloneObject(_.mediaConstraints),n=_.mediaStream||null,v=Ye.cloneObject(_.pcConfig,{iceServers:[]}),S=_.rtcConstraints||null,m=_.rtcAnswerConstraints||null,C=Ye.cloneObject(_.rtcOfferConstraints),A,R=!1,I=!1,V=!1,W=!1;if(this._rtcAnswerConstraints=m,this._rtcOfferConstraints=_.rtcOfferConstraints||null,this._data=_.data||this._data,this._direction!=="incoming")throw new Cn.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==ee.STATUS_WAITING_FOR_ANSWER)throw new Cn.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Ye.isDecimal(_.sessionTimersExpires)&&(_.sessionTimersExpires>=ue.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=_.sessionTimersExpires:this._sessionTimers.defaultExpires=ue.SESSION_EXPIRES),this._status=ee.STATUS_ANSWERED,!this._createDialog(e,"UAS")){e.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),p.unshift("Contact: ".concat(this._contact));var oe=e.parseSDP();Array.isArray(oe.media)||(oe.media=[oe.media]);var x=Ts(oe.media),$;try{for(x.s();!($=x.n()).done;){var Re=$.value;Re.type==="audio"&&(R=!0,(!Re.direction||Re.direction==="sendrecv")&&(V=!0)),Re.type==="video"&&(I=!0,(!Re.direction||Re.direction==="sendrecv")&&(W=!0))}}catch(B){x.e(B)}finally{x.f()}if(n&&g.audio===!1){A=n.getAudioTracks();var Ie=Ts(A),H;try{for(Ie.s();!(H=Ie.n()).done;){var D=H.value;n.removeTrack(D)}}catch(B){Ie.e(B)}finally{Ie.f()}}if(n&&g.video===!1){A=n.getVideoTracks();var L=Ts(A),q;try{for(L.s();!(q=L.n()).done;){var j=q.value;n.removeTrack(j)}}catch(B){L.e(B)}finally{L.f()}}!n&&g.audio===void 0&&(g.audio=V),!n&&g.video===void 0&&(g.video=W),!n&&!R&&!C.offerToReceiveAudio&&(g.audio=!1),!n&&!I&&!C.offerToReceiveVideo&&(g.video=!1),this._createRTCConnection(v,S),Promise.resolve().then(function(){if(n)return n;if(g.audio||g.video)return a._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(g).catch(function(B){throw a._status===ee.STATUS_TERMINATED?new Error("terminated"):(e.reply(480),a._failed("local",null,ue.causes.USER_DENIED_MEDIA_ACCESS),J.warn('emit "getusermediafailed" [error:%o]',B),a.emit("getusermediafailed",B),new Error("getUserMedia() failed"))})}).then(function(B){if(a._status===ee.STATUS_TERMINATED)throw new Error("terminated");a._localMediaStream=B,B&&B.getTracks().forEach(function(X){a._connection.addTrack(X,B)})}).then(function(){if(!a._late_sdp){var B={originator:"remote",type:"offer",sdp:e.body};J.debug('emit "sdp"'),a.emit("sdp",B);var X=new RTCSessionDescription({type:"offer",sdp:B.sdp});return a._connectionPromiseQueue=a._connectionPromiseQueue.then(function(){return a._connection.setRemoteDescription(X)}).catch(function(Q){throw e.reply(488),a._failed("system",null,ue.causes.WEBRTC_ERROR),J.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',Q),a.emit("peerconnection:setremotedescriptionfailed",Q),new Error("peerconnection.setRemoteDescription() failed")}),a._connectionPromiseQueue}}).then(function(){if(a._status===ee.STATUS_TERMINATED)throw new Error("terminated");return a._connecting(e),a._late_sdp?a._createLocalDescription("offer",a._rtcOfferConstraints).catch(function(){throw e.reply(500),new Error("_createLocalDescription() failed")}):a._createLocalDescription("answer",m).catch(function(){throw e.reply(500),new Error("_createLocalDescription() failed")})}).then(function(B){if(a._status===ee.STATUS_TERMINATED)throw new Error("terminated");a._handleSessionTimersInIncomingRequest(e,p),e.reply(200,null,p,B,function(){a._status=ee.STATUS_WAITING_FOR_ACK,a._setInvite2xxTimer(e,B),a._setACKTimer(),a._accepted("local")},function(){a._failed("system",null,ue.causes.CONNECTION_ERROR)})}).catch(function(B){a._status!==ee.STATUS_TERMINATED&&J.warn(B)})}},{key:"terminate",value:function(){var a=this,_=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};J.debug("terminate()");var e=_.cause||ue.causes.BYE,p=Ye.cloneArray(_.extraHeaders),g=_.body,n,v=_.status_code,S=_.reason_phrase;if(this._status===ee.STATUS_TERMINATED)throw new Cn.InvalidStateError(this._status);switch(this._status){case ee.STATUS_NULL:case ee.STATUS_INVITE_SENT:case ee.STATUS_1XX_RECEIVED:if(J.debug("canceling session"),v&&(v<200||v>=700))throw new TypeError("Invalid status_code: ".concat(v));v&&(S=S||ue.REASON_PHRASE[v]||"",n="SIP ;cause=".concat(v,' ;text="').concat(S,'"')),this._status===ee.STATUS_NULL||this._status===ee.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===ee.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=ee.STATUS_CANCELED,this._failed("local",null,ue.causes.CANCELED);break;case ee.STATUS_WAITING_FOR_ANSWER:case ee.STATUS_ANSWERED:if(J.debug("rejecting session"),v=v||480,v<300||v>=700)throw new TypeError("Invalid status_code: ".concat(v));this._request.reply(v,S,p,g),this._failed("local",null,ue.causes.REJECTED);break;case ee.STATUS_WAITING_FOR_ACK:case ee.STATUS_CONFIRMED:if(J.debug("terminating session"),S=_.reason_phrase||ue.REASON_PHRASE[v]||"",v&&(v<200||v>=700))throw new TypeError("Invalid status_code: ".concat(v));if(v&&p.push("Reason: SIP ;cause=".concat(v,'; text="').concat(S,'"')),this._status===ee.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Dc.C.STATUS_TERMINATED){var m=this._dialog;this.receiveRequest=function(C){var A=C.method;A===ue.ACK&&(a.sendRequest(ue.BYE,{extraHeaders:p,body:g}),m.terminate())},this._request.server_transaction.on("stateChanged",function(){a._request.server_transaction.state===Dc.C.STATUS_TERMINATED&&(a.sendRequest(ue.BYE,{extraHeaders:p,body:g}),m.terminate())}),this._ended("local",null,e),this._dialog=m,this._ua.newDialog(m)}else this.sendRequest(ue.BYE,{extraHeaders:p,body:g}),this._ended("local",null,e)}}},{key:"sendDTMF",value:function(a){var _=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};J.debug("sendDTMF() | tones: %s",a);var e=0,p=_.duration||null,g=_.interToneGap||null,n=_.transportType||ue.DTMF_TRANSPORT.INFO;if(a===void 0)throw new TypeError("Not enough arguments");if(this._status!==ee.STATUS_CONFIRMED&&this._status!==ee.STATUS_WAITING_FOR_ACK&&this._status!==ee.STATUS_1XX_RECEIVED)throw new Cn.InvalidStateError(this._status);if(n!==ue.DTMF_TRANSPORT.INFO&&n!==ue.DTMF_TRANSPORT.RFC2833)throw new TypeError("invalid transportType: ".concat(n));if(typeof a=="number"&&(a=a.toString()),!a||typeof a!="string"||!a.match(/^[0-9A-DR#*,]+$/i))throw new TypeError("Invalid tones: ".concat(a));if(p&&!Ye.isDecimal(p))throw new TypeError("Invalid tone duration: ".concat(p));if(p?p<Lt.C.MIN_DURATION?(J.debug('"duration" value is lower than the minimum allowed, setting it to '.concat(Lt.C.MIN_DURATION," milliseconds")),p=Lt.C.MIN_DURATION):p>Lt.C.MAX_DURATION?(J.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(Lt.C.MAX_DURATION," milliseconds")),p=Lt.C.MAX_DURATION):p=Math.abs(p):p=Lt.C.DEFAULT_DURATION,_.duration=p,g&&!Ye.isDecimal(g))throw new TypeError("Invalid interToneGap: ".concat(g));if(g?g<Lt.C.MIN_INTER_TONE_GAP?(J.debug('"interToneGap" value is lower than the minimum allowed, setting it to '.concat(Lt.C.MIN_INTER_TONE_GAP," milliseconds")),g=Lt.C.MIN_INTER_TONE_GAP):g=Math.abs(g):g=Lt.C.DEFAULT_INTER_TONE_GAP,n===ue.DTMF_TRANSPORT.RFC2833){var v=this._getDTMFRTPSender();v&&(a=v.toneBuffer+a,v.insertDTMF(a,p,g));return}if(this._tones){this._tones+=a;return}this._tones=a,S.call(this);function S(){var m=this,C;if(this._status===ee.STATUS_TERMINATED||!this._tones||e>=this._tones.length){this._tones=null;return}var A=this._tones[e];if(e+=1,A===",")C=2e3;else{var R=new Lt(this);_.eventHandlers={onFailed:function(){m._tones=null}},R.send(A,_),C=p+g}setTimeout(S.bind(this),C)}}},{key:"sendInfo",value:function(a,_){var e=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(J.debug("sendInfo()"),this._status!==ee.STATUS_CONFIRMED&&this._status!==ee.STATUS_WAITING_FOR_ACK&&this._status!==ee.STATUS_1XX_RECEIVED)throw new Cn.InvalidStateError(this._status);var p=new Nc(this);p.send(a,_,e)}},{key:"mute",value:function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!1};J.debug("mute()");var _=!1,e=!1;this._audioMuted===!1&&a.audio&&(_=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&a.video&&(e=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(_===!0||e===!0)&&this._onmute({audio:_,video:e})}},{key:"unmute",value:function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!0};J.debug("unmute()");var _=!1,e=!1;this._audioMuted===!0&&a.audio&&(_=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&a.video&&(e=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(_===!0||e===!0)&&this._onunmute({audio:_,video:e})}},{key:"hold",value:function(){var a=this,_=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;if(J.debug("hold()"),this._status!==ee.STATUS_WAITING_FOR_ACK&&this._status!==ee.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var p={succeeded:function(){e&&e()},failed:function(){a.terminate({cause:ue.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return _.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:p,extraHeaders:_.extraHeaders}):this._sendReinvite({eventHandlers:p,extraHeaders:_.extraHeaders}),!0}},{key:"unhold",value:function(){var a=this,_=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;if(J.debug("unhold()"),this._status!==ee.STATUS_WAITING_FOR_ACK&&this._status!==ee.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var p={succeeded:function(){e&&e()},failed:function(){a.terminate({cause:ue.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return _.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:p,extraHeaders:_.extraHeaders}):this._sendReinvite({eventHandlers:p,extraHeaders:_.extraHeaders}),!0}},{key:"renegotiate",value:function(){var a=this,_=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;J.debug("renegotiate()");var p=_.rtcOfferConstraints||null;if(this._status!==ee.STATUS_WAITING_FOR_ACK&&this._status!==ee.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;var g={succeeded:function(){e&&e()},failed:function(){a.terminate({cause:ue.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),_.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:g,rtcOfferConstraints:p,extraHeaders:_.extraHeaders}):this._sendReinvite({eventHandlers:g,rtcOfferConstraints:p,extraHeaders:_.extraHeaders}),!0}},{key:"refer",value:function(a,_){var e=this;J.debug("refer()");var p=a;if(this._status!==ee.STATUS_WAITING_FOR_ACK&&this._status!==ee.STATUS_CONFIRMED)return!1;if(a=this._ua.normalizeTarget(a),!a)throw new TypeError("Invalid target: ".concat(p));var g=new cp(this);g.sendRefer(a,_);var n=g.id;return this._referSubscribers[n]=g,g.on("requestFailed",function(){delete e._referSubscribers[n]}),g.on("accepted",function(){delete e._referSubscribers[n]}),g.on("failed",function(){delete e._referSubscribers[n]}),g}},{key:"sendRequest",value:function(a,_){return J.debug("sendRequest()"),this._dialog.sendRequest(a,_)}},{key:"receiveRequest",value:function(a){var _=this;if(J.debug("receiveRequest()"),a.method===ue.CANCEL)(this._status===ee.STATUS_WAITING_FOR_ANSWER||this._status===ee.STATUS_ANSWERED)&&(this._status=ee.STATUS_CANCELED,this._request.reply(487),this._failed("remote",a,ue.causes.CANCELED));else switch(a.method){case ue.ACK:if(this._status!==ee.STATUS_WAITING_FOR_ACK)return;if(this._status=ee.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!a.body){this.terminate({cause:ue.causes.MISSING_SDP,status_code:400});break}var e={originator:"remote",type:"answer",sdp:a.body};J.debug('emit "sdp"'),this.emit("sdp",e);var p=new RTCSessionDescription({type:"answer",sdp:e.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return _._connection.setRemoteDescription(p)}).then(function(){_._is_confirmed||_._confirmed("remote",a)}).catch(function(n){_.terminate({cause:ue.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),J.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),_.emit("peerconnection:setremotedescriptionfailed",n)})}else this._is_confirmed||this._confirmed("remote",a);break;case ue.BYE:this._status===ee.STATUS_CONFIRMED||this._status===ee.STATUS_WAITING_FOR_ACK?(a.reply(200),this._ended("remote",a,ue.causes.BYE)):this._status===ee.STATUS_INVITE_RECEIVED||this._status===ee.STATUS_WAITING_FOR_ANSWER?(a.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",a,ue.causes.BYE)):a.reply(403,"Wrong Status");break;case ue.INVITE:this._status===ee.STATUS_CONFIRMED?a.hasHeader("replaces")?this._receiveReplaces(a):this._receiveReinvite(a):a.reply(403,"Wrong Status");break;case ue.INFO:if(this._status===ee.STATUS_1XX_RECEIVED||this._status===ee.STATUS_WAITING_FOR_ANSWER||this._status===ee.STATUS_ANSWERED||this._status===ee.STATUS_WAITING_FOR_ACK||this._status===ee.STATUS_CONFIRMED){var g=a.hasHeader("Content-Type")?a.getHeader("Content-Type").toLowerCase():void 0;g&&g.match(/^application\/dtmf-relay/i)?new Lt(this).init_incoming(a):g!==void 0?new Nc(this).init_incoming(a):a.reply(415)}else a.reply(403,"Wrong Status");break;case ue.UPDATE:this._status===ee.STATUS_CONFIRMED?this._receiveUpdate(a):a.reply(403,"Wrong Status");break;case ue.REFER:this._status===ee.STATUS_CONFIRMED?this._receiveRefer(a):a.reply(403,"Wrong Status");break;case ue.NOTIFY:this._status===ee.STATUS_CONFIRMED?this._receiveNotify(a):a.reply(403,"Wrong Status");break;default:a.reply(501)}}},{key:"onTransportError",value:function(){J.warn("onTransportError()"),this._status!==ee.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ue.causes.CONNECTION_ERROR,cause:ue.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){J.warn("onRequestTimeout()"),this._status!==ee.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:ue.causes.REQUEST_TIMEOUT,cause:ue.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){J.warn("onDialogError()"),this._status!==ee.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ue.causes.DIALOG_ERROR,cause:ue.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(a){J.debug("newDTMF()"),this.emit("newDTMF",a)}},{key:"newInfo",value:function(a){J.debug("newInfo()"),this.emit("newInfo",a)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(J.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(J.debug("_isReadyToReOffer() | session not established yet"),!1):(J.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(J.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(J.debug("close() | closing local MediaStream"),Ye.closeMediaStream(this._localMediaStream)),this._status!==ee.STATUS_TERMINATED){if(this._status=ee.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(p){J.warn("close() | error closing the RTCPeerConnection: %o",p)}for(var a in this._timers)Object.prototype.hasOwnProperty.call(this._timers,a)&&clearTimeout(this._timers[a]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(var _ in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,_)&&(this._earlyDialogs[_].terminate(),delete this._earlyDialogs[_]);for(var e in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,e)&&delete this._referSubscribers[e];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(a,_){var e=Ni.T1;function p(){this._status===ee.STATUS_WAITING_FOR_ACK&&(a.reply(200,null,["Contact: ".concat(this._contact)],_),e<Ni.T2&&(e=e*2,e>Ni.T2&&(e=Ni.T2)),this._timers.invite2xxTimer=setTimeout(p.bind(this),e))}this._timers.invite2xxTimer=setTimeout(p.bind(this),e)}},{key:"_setACKTimer",value:function(){var a=this;this._timers.ackTimer=setTimeout(function(){a._status===ee.STATUS_WAITING_FOR_ACK&&(J.debug("no ACK received, terminating the session"),clearTimeout(a._timers.invite2xxTimer),a.sendRequest(ue.BYE),a._ended("remote",null,ue.causes.NO_ACK))},Ni.TIMER_H)}},{key:"_createRTCConnection",value:function(a,_){var e=this;this._connection=new RTCPeerConnection(a,_),this._connection.addEventListener("iceconnectionstatechange",function(){var p=e._connection.iceConnectionState;p==="failed"&&e.terminate({cause:ue.causes.RTP_TIMEOUT,status_code:408,reason_phrase:ue.causes.RTP_TIMEOUT})}),J.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(a,_){var e=this;if(J.debug("createLocalDescription()"),a!=="offer"&&a!=="answer")throw new Error('createLocalDescription() | invalid type "'.concat(a,'"'));var p=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return a==="offer"?p.createOffer(_).catch(function(g){return J.warn('emit "peerconnection:createofferfailed" [error:%o]',g),e.emit("peerconnection:createofferfailed",g),Promise.reject(g)}):p.createAnswer(_).catch(function(g){return J.warn('emit "peerconnection:createanswerfailed" [error:%o]',g),e.emit("peerconnection:createanswerfailed",g),Promise.reject(g)})}).then(function(g){return p.setLocalDescription(g).catch(function(n){return e._rtcReady=!0,J.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',n),e.emit("peerconnection:setlocaldescriptionfailed",n),Promise.reject(n)})}).then(function(){var g=_&&_.iceRestart;if(p.iceGatheringState==="complete"&&!g||p.iceGatheringState==="gathering"&&e._iceReady){e._rtcReady=!0;var n={originator:"local",type:a,sdp:p.localDescription.sdp};return J.debug('emit "sdp"'),e.emit("sdp",n),Promise.resolve(n.sdp)}return new Promise(function(v){var S=!1,m,C;e._iceReady=!1;var A=function(){p.removeEventListener("icecandidate",m),p.removeEventListener("icegatheringstatechange",C),S=!0,e._rtcReady=!0,e._iceReady=!0;var I={originator:"local",type:a,sdp:p.localDescription.sdp};J.debug('emit "sdp"'),e.emit("sdp",I),v(I.sdp)};p.addEventListener("icecandidate",m=function(I){var V=I.candidate;V?e.emit("icecandidate",{candidate:V,ready:A}):S||A()}),p.addEventListener("icegatheringstatechange",C=function(){p.iceGatheringState==="complete"&&!S&&A()})})})}},{key:"_createDialog",value:function(a,_,e){var p=_==="UAS"?a.to_tag:a.from_tag,g=_==="UAS"?a.from_tag:a.to_tag,n=a.call_id+p+g,v=this._earlyDialogs[n];if(e)return v?!0:(v=new zl(this,a,_,zl.C.STATUS_EARLY),v.error?(J.debug(v.error),this._failed("remote",a,ue.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[n]=v,!0));if(this._from_tag=a.from_tag,this._to_tag=a.to_tag,v)return v.update(a,_),this._dialog=v,delete this._earlyDialogs[n],!0;var S=new zl(this,a,_);return S.error?(J.debug(S.error),this._failed("remote",a,ue.causes.INTERNAL_ERROR),!1):(this._dialog=S,!0)}},{key:"_receiveReinvite",value:function(a){var _=this;J.debug("receiveReinvite()");var e=a.hasHeader("Content-Type")?a.getHeader("Content-Type").toLowerCase():void 0,p={request:a,callback:void 0,reject:n.bind(this)},g=!1;function n(){var S=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};g=!0;var m=S.status_code||403,C=S.reason_phrase||"",A=Ye.cloneArray(S.extraHeaders);if(this._status!==ee.STATUS_CONFIRMED)return!1;if(m<300||m>=700)throw new TypeError("Invalid status_code: ".concat(m));a.reply(m,C,A)}if(this.emit("reinvite",p),g)return;if(this._late_sdp=!1,!a.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return _._createLocalDescription("offer",_._rtcOfferConstraints)}).then(function(S){v.call(_,S)}).catch(function(){a.reply(500)});return}if(e!=="application/sdp"){J.debug("invalid Content-Type"),a.reply(415);return}this._processInDialogSdpOffer(a).then(function(S){_._status!==ee.STATUS_TERMINATED&&v.call(_,S)}).catch(function(S){J.warn(S)});function v(S){var m=this,C=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(a,C),this._late_sdp&&(S=this._mangleOffer(S)),a.reply(200,null,C,S,function(){m._status=ee.STATUS_WAITING_FOR_ACK,m._setInvite2xxTimer(a,S),m._setACKTimer()}),typeof p.callback=="function"&&p.callback()}}},{key:"_receiveUpdate",value:function(a){var _=this;J.debug("receiveUpdate()");var e=a.hasHeader("Content-Type")?a.getHeader("Content-Type").toLowerCase():void 0,p={request:a,callback:void 0,reject:n.bind(this)},g=!1;function n(){var S=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};g=!0;var m=S.status_code||403,C=S.reason_phrase||"",A=Ye.cloneArray(S.extraHeaders);if(this._status!==ee.STATUS_CONFIRMED)return!1;if(m<300||m>=700)throw new TypeError("Invalid status_code: ".concat(m));a.reply(m,C,A)}if(this.emit("update",p),g)return;if(!a.body){v.call(this,null);return}if(e!=="application/sdp"){J.debug("invalid Content-Type"),a.reply(415);return}this._processInDialogSdpOffer(a).then(function(S){_._status!==ee.STATUS_TERMINATED&&v.call(_,S)}).catch(function(S){J.warn(S)});function v(S){var m=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(a,m),a.reply(200,null,m,S),typeof p.callback=="function"&&p.callback()}}},{key:"_processInDialogSdpOffer",value:function(a){var _=this;J.debug("_processInDialogSdpOffer()");var e=a.parseSDP(),p=!1,g=Ts(e.media),n;try{for(g.s();!(n=g.n()).done;){var v=n.value;if(Xl.indexOf(v.type)!==-1){var S=v.direction||e.direction||"sendrecv";if(S==="sendonly"||S==="inactive")p=!0;else{p=!1;break}}}}catch(A){g.e(A)}finally{g.f()}var m={originator:"remote",type:"offer",sdp:a.body};J.debug('emit "sdp"'),this.emit("sdp",m);var C=new RTCSessionDescription({type:"offer",sdp:m.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(_._status===ee.STATUS_TERMINATED)throw new Error("terminated");return _._connection.setRemoteDescription(C).catch(function(A){throw a.reply(488),J.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',A),_.emit("peerconnection:setremotedescriptionfailed",A),A})}).then(function(){if(_._status===ee.STATUS_TERMINATED)throw new Error("terminated");_._remoteHold===!0&&p===!1?(_._remoteHold=!1,_._onunhold("remote")):_._remoteHold===!1&&p===!0&&(_._remoteHold=!0,_._onhold("remote"))}).then(function(){if(_._status===ee.STATUS_TERMINATED)throw new Error("terminated");return _._createLocalDescription("answer",_._rtcAnswerConstraints).catch(function(A){throw a.reply(500),J.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',A),A})}).catch(function(A){J.warn("_processInDialogSdpOffer() failed [error: %o]",A)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(a){var _=this;if(J.debug("receiveRefer()"),!a.refer_to){J.debug("no Refer-To header field present in REFER"),a.reply(400);return}if(a.refer_to.uri.scheme!==ue.SIP){J.debug("Refer-To header field points to a non-SIP URI scheme"),a.reply(416);return}a.reply(202);var e=new up(this,a.cseq);J.debug('emit "refer"'),this.emit("refer",{request:a,accept:function(v,S){p.call(_,v,S)},reject:function(){g.call(_)}});function p(n){var v=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(n=typeof n=="function"?n:null,this._status!==ee.STATUS_WAITING_FOR_ACK&&this._status!==ee.STATUS_CONFIRMED)return!1;var S=new i(this._ua);if(S.on("progress",function(C){var A=C.response;e.notify(A.status_code,A.reason_phrase)}),S.on("accepted",function(C){var A=C.response;e.notify(A.status_code,A.reason_phrase)}),S.on("_failed",function(C){var A=C.message,R=C.cause;A?e.notify(A.status_code,A.reason_phrase):e.notify(487,R)}),a.refer_to.uri.hasHeader("replaces")){var m=decodeURIComponent(a.refer_to.uri.getHeader("replaces"));v.extraHeaders=Ye.cloneArray(v.extraHeaders),v.extraHeaders.push("Replaces: ".concat(m))}S.connect(a.refer_to.uri.toAor(),v,n)}function g(){e.notify(603)}}},{key:"_receiveNotify",value:function(a){switch(J.debug("receiveNotify()"),a.event||a.reply(400),a.event.event){case"refer":{var _,e;if(a.event.params&&a.event.params.id)_=a.event.params.id,e=this._referSubscribers[_];else if(Object.keys(this._referSubscribers).length===1)e=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{a.reply(400,"Missing event id parameter");return}if(!e){a.reply(481,"Subscription does not exist");return}e.receiveNotify(a),a.reply(200);break}default:a.reply(489)}}},{key:"_receiveReplaces",value:function(a){var _=this;J.debug("receiveReplaces()");function e(g){var n=this;if(this._status!==ee.STATUS_WAITING_FOR_ACK&&this._status!==ee.STATUS_CONFIRMED)return!1;var v=new i(this._ua);v.on("confirmed",function(){n.terminate()}),v.init_incoming(a,g)}function p(){J.debug("Replaced INVITE rejected by the user"),a.reply(486)}this.emit("replaces",{request:a,accept:function(n){e.call(_,n)},reject:function(){p.call(_)}})}},{key:"_sendInitialRequest",value:function(a,_,e){var p=this,g=new op(this._ua,this._request,{onRequestTimeout:function(){p.onRequestTimeout()},onTransportError:function(){p.onTransportError()},onAuthenticated:function(v){p._request=v},onReceiveResponse:function(v){p._receiveInviteResponse(v)}});Promise.resolve().then(function(){if(e)return e;if(a.audio||a.video)return p._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(a).catch(function(n){throw p._status===ee.STATUS_TERMINATED?new Error("terminated"):(p._failed("local",null,ue.causes.USER_DENIED_MEDIA_ACCESS),J.warn('emit "getusermediafailed" [error:%o]',n),p.emit("getusermediafailed",n),n)})}).then(function(n){if(p._status===ee.STATUS_TERMINATED)throw new Error("terminated");return p._localMediaStream=n,n&&n.getTracks().forEach(function(v){p._connection.addTrack(v,n)}),p._connecting(p._request),p._createLocalDescription("offer",_).catch(function(v){throw p._failed("local",null,ue.causes.WEBRTC_ERROR),v})}).then(function(n){if(p._is_canceled||p._status===ee.STATUS_TERMINATED)throw new Error("terminated");p._request.body=n,p._status=ee.STATUS_INVITE_SENT,J.debug('emit "sending" [request:%o]',p._request),p.emit("sending",{request:p._request}),g.send()}).catch(function(n){p._status!==ee.STATUS_TERMINATED&&J.warn(n)})}},{key:"_getDTMFRTPSender",value:function(){var a=this._connection.getSenders().find(function(_){return _.track&&_.track.kind==="audio"});if(!(a&&a.dtmf)){J.warn("sendDTMF() | no local audio track to send DTMF with");return}return a.dtmf}},{key:"_receiveInviteResponse",value:function(a){var _=this;if(J.debug("receiveInviteResponse()"),this._dialog&&a.status_code>=200&&a.status_code<=299)if(this._dialog.id.call_id===a.call_id&&this._dialog.id.local_tag===a.from_tag&&this._dialog.id.remote_tag===a.to_tag){this.sendRequest(ue.ACK);return}else{var e=new zl(this,a,"UAC");if(e.error!==void 0){J.debug(e.error);return}this.sendRequest(ue.ACK),this.sendRequest(ue.BYE);return}if(this._is_canceled){a.status_code>=100&&a.status_code<200?this._request.cancel(this._cancel_reason):a.status_code>=200&&a.status_code<299&&this._acceptAndTerminate(a);return}if(!(this._status!==ee.STATUS_INVITE_SENT&&this._status!==ee.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(a.status_code):this._status=ee.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(a.status_code):{if(!a.to_tag){J.debug("1xx response received without to tag");break}if(a.hasHeader("contact")&&!this._createDialog(a,"UAC",!0))break;if(this._status=ee.STATUS_1XX_RECEIVED,!a.body){this._progress("remote",a);break}var p={originator:"remote",type:"answer",sdp:a.body};J.debug('emit "sdp"'),this.emit("sdp",p);var g=new RTCSessionDescription({type:"answer",sdp:p.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return _._connection.setRemoteDescription(g)}).then(function(){return _._progress("remote",a)}).catch(function(m){J.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',m),_.emit("peerconnection:setremotedescriptionfailed",m)});break}case/^2[0-9]{2}$/.test(a.status_code):{if(this._status=ee.STATUS_CONFIRMED,!a.body){this._acceptAndTerminate(a,400,ue.causes.MISSING_SDP),this._failed("remote",a,ue.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(a,"UAC"))break;var n={originator:"remote",type:"answer",sdp:a.body};J.debug('emit "sdp"'),this.emit("sdp",n);var v=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(_._connection.signalingState==="stable")return _._connection.createOffer(_._rtcOfferConstraints).then(function(m){return _._connection.setLocalDescription(m)}).catch(function(m){_._acceptAndTerminate(a,500,m.toString()),_._failed("local",a,ue.causes.WEBRTC_ERROR)})}).then(function(){_._connection.setRemoteDescription(v).then(function(){_._handleSessionTimersInIncomingResponse(a),_._accepted("remote",a),_.sendRequest(ue.ACK),_._confirmed("local",null)}).catch(function(m){_._acceptAndTerminate(a,488,"Not Acceptable Here"),_._failed("remote",a,ue.causes.BAD_MEDIA_DESCRIPTION),J.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',m),_.emit("peerconnection:setremotedescriptionfailed",m)})});break}default:{var S=Ye.sipErrorCause(a.status_code);this._failed("remote",a,S)}}}},{key:"_sendReinvite",value:function(){var a=this,_=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};J.debug("sendReinvite()");var e=Ye.cloneArray(_.extraHeaders),p=Ye.cloneObject(_.eventHandlers),g=_.rtcOfferConstraints||this._rtcOfferConstraints||null,n=!1;e.push("Contact: ".concat(this._contact)),e.push("Content-Type: application/sdp"),this._sessionTimers.running&&e.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return a._createLocalDescription("offer",g)}).then(function(m){m=a._mangleOffer(m);var C={originator:"local",type:"offer",sdp:m};J.debug('emit "sdp"'),a.emit("sdp",C),a.sendRequest(ue.INVITE,{extraHeaders:e,body:m,eventHandlers:{onSuccessResponse:function(R){v.call(a,R),n=!0},onErrorResponse:function(R){S.call(a,R)},onTransportError:function(){a.onTransportError()},onRequestTimeout:function(){a.onRequestTimeout()},onDialogError:function(){a.onDialogError()}}})}).catch(function(){S()});function v(m){var C=this;if(this._status!==ee.STATUS_TERMINATED&&(this.sendRequest(ue.ACK),!n)){if(this._handleSessionTimersInIncomingResponse(m),m.body){if(!m.hasHeader("Content-Type")||m.getHeader("Content-Type").toLowerCase()!=="application/sdp"){S.call(this);return}}else{S.call(this);return}var A={originator:"remote",type:"answer",sdp:m.body};J.debug('emit "sdp"'),this.emit("sdp",A);var R=new RTCSessionDescription({type:"answer",sdp:A.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return C._connection.setRemoteDescription(R)}).then(function(){p.succeeded&&p.succeeded(m)}).catch(function(I){S.call(C),J.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',I),C.emit("peerconnection:setremotedescriptionfailed",I)})}}function S(m){p.failed&&p.failed(m)}}},{key:"_sendUpdate",value:function(){var a=this,_=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};J.debug("sendUpdate()");var e=Ye.cloneArray(_.extraHeaders),p=Ye.cloneObject(_.eventHandlers),g=_.rtcOfferConstraints||this._rtcOfferConstraints||null,n=_.sdpOffer||!1,v=!1;e.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&e.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),n?(e.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return a._createLocalDescription("offer",g)}).then(function(C){C=a._mangleOffer(C);var A={originator:"local",type:"offer",sdp:C};J.debug('emit "sdp"'),a.emit("sdp",A),a.sendRequest(ue.UPDATE,{extraHeaders:e,body:C,eventHandlers:{onSuccessResponse:function(I){S.call(a,I),v=!0},onErrorResponse:function(I){m.call(a,I)},onTransportError:function(){a.onTransportError()},onRequestTimeout:function(){a.onRequestTimeout()},onDialogError:function(){a.onDialogError()}}})}).catch(function(){m.call(a)})):this.sendRequest(ue.UPDATE,{extraHeaders:e,eventHandlers:{onSuccessResponse:function(A){S.call(a,A)},onErrorResponse:function(A){m.call(a,A)},onTransportError:function(){a.onTransportError()},onRequestTimeout:function(){a.onRequestTimeout()},onDialogError:function(){a.onDialogError()}}});function S(C){var A=this;if(this._status!==ee.STATUS_TERMINATED&&!v)if(this._handleSessionTimersInIncomingResponse(C),n){if(C.body){if(!C.hasHeader("Content-Type")||C.getHeader("Content-Type").toLowerCase()!=="application/sdp"){m.call(this);return}}else{m.call(this);return}var R={originator:"remote",type:"answer",sdp:C.body};J.debug('emit "sdp"'),this.emit("sdp",R);var I=new RTCSessionDescription({type:"answer",sdp:R.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return A._connection.setRemoteDescription(I)}).then(function(){p.succeeded&&p.succeeded(C)}).catch(function(V){m.call(A),J.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',V),A.emit("peerconnection:setremotedescriptionfailed",V)})}else p.succeeded&&p.succeeded(C)}function m(C){p.failed&&p.failed(C)}}},{key:"_acceptAndTerminate",value:function(a,_,e){J.debug("acceptAndTerminate()");var p=[];_&&(e=e||ue.REASON_PHRASE[_]||"",p.push("Reason: SIP ;cause=".concat(_,'; text="').concat(e,'"'))),(this._dialog||this._createDialog(a,"UAC"))&&(this.sendRequest(ue.ACK),this.sendRequest(ue.BYE,{extraHeaders:p})),this._status=ee.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(a){if(!this._localHold&&!this._remoteHold)return a;if(a=Oc.parse(a),this._localHold&&!this._remoteHold){J.debug("mangleOffer() | me on hold, mangling offer");var _=Ts(a.media),e;try{for(_.s();!(e=_.n()).done;){var p=e.value;Xl.indexOf(p.type)!==-1&&(p.direction?p.direction==="sendrecv"?p.direction="sendonly":p.direction==="recvonly"&&(p.direction="inactive"):p.direction="sendonly")}}catch(A){_.e(A)}finally{_.f()}}else if(this._localHold&&this._remoteHold){J.debug("mangleOffer() | both on hold, mangling offer");var g=Ts(a.media),n;try{for(g.s();!(n=g.n()).done;){var v=n.value;Xl.indexOf(v.type)!==-1&&(v.direction="inactive")}}catch(A){g.e(A)}finally{g.f()}}else if(this._remoteHold){J.debug("mangleOffer() | remote on hold, mangling offer");var S=Ts(a.media),m;try{for(S.s();!(m=S.n()).done;){var C=m.value;Xl.indexOf(C.type)!==-1&&(C.direction?C.direction==="sendrecv"?C.direction="recvonly":C.direction==="recvonly"&&(C.direction="inactive"):C.direction="recvonly")}}catch(A){S.e(A)}finally{S.f()}}return Oc.write(a)}},{key:"_setLocalMediaStatus",value:function(){var a=!0,_=!0;(this._localHold||this._remoteHold)&&(a=!1,_=!1),this._audioMuted&&(a=!1),this._videoMuted&&(_=!1),this._toggleMuteAudio(!a),this._toggleMuteVideo(!_)}},{key:"_handleSessionTimersInIncomingRequest",value:function(a,_){if(this._sessionTimers.enabled){var e;a.session_expires&&a.session_expires>=ue.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=a.session_expires,e=a.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,e="uas"),_.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(e)),this._sessionTimers.refresher=e==="uas",this._runSessionTimer()}}},{key:"_handleSessionTimersInIncomingResponse",value:function(a){if(this._sessionTimers.enabled){var _;a.session_expires&&a.session_expires>=ue.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=a.session_expires,_=a.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,_="uac"),this._sessionTimers.refresher=_==="uac",this._runSessionTimer()}}},{key:"_runSessionTimer",value:function(){var a=this,_=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){a._status!==ee.STATUS_TERMINATED&&a._isReadyToReOffer()&&(J.debug("runSessionTimer() | sending session refresh request"),a._sessionTimers.refreshMethod===ue.UPDATE?a._sendUpdate():a._sendReinvite())},_*500):this._sessionTimers.timer=setTimeout(function(){a._status!==ee.STATUS_TERMINATED&&(J.warn("runSessionTimer() | timer expired, terminating the session"),a.terminate({cause:ue.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},_*1100)}},{key:"_toggleMuteAudio",value:function(a){var _=this._connection.getSenders().filter(function(n){return n.track&&n.track.kind==="audio"}),e=Ts(_),p;try{for(e.s();!(p=e.n()).done;){var g=p.value;g.track.enabled=!a}}catch(n){e.e(n)}finally{e.f()}}},{key:"_toggleMuteVideo",value:function(a){var _=this._connection.getSenders().filter(function(n){return n.track&&n.track.kind==="video"}),e=Ts(_),p;try{for(e.s();!(p=e.n()).done;){var g=p.value;g.track.enabled=!a}}catch(n){e.e(n)}finally{e.f()}}},{key:"_newRTCSession",value:function(a,_){J.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:a,session:this,request:_})}},{key:"_connecting",value:function(a){J.debug("session connecting"),J.debug('emit "connecting"'),this.emit("connecting",{request:a})}},{key:"_progress",value:function(a,_){J.debug("session progress"),J.debug('emit "progress"'),this.emit("progress",{originator:a,response:_||null})}},{key:"_accepted",value:function(a,_){J.debug("session accepted"),this._start_time=new Date,J.debug('emit "accepted"'),this.emit("accepted",{originator:a,response:_||null})}},{key:"_confirmed",value:function(a,_){J.debug("session confirmed"),this._is_confirmed=!0,J.debug('emit "confirmed"'),this.emit("confirmed",{originator:a,ack:_||null})}},{key:"_ended",value:function(a,_,e){J.debug("session ended"),this._end_time=new Date,this._close(),J.debug('emit "ended"'),this.emit("ended",{originator:a,message:_||null,cause:e})}},{key:"_failed",value:function(a,_,e){J.debug("session failed"),J.debug('emit "_failed"'),this.emit("_failed",{originator:a,message:_||null,cause:e}),this._close(),J.debug('emit "failed"'),this.emit("failed",{originator:a,message:_||null,cause:e})}},{key:"_onhold",value:function(a){J.debug("session onhold"),this._setLocalMediaStatus(),J.debug('emit "hold"'),this.emit("hold",{originator:a})}},{key:"_onunhold",value:function(a){J.debug("session onunhold"),this._setLocalMediaStatus(),J.debug('emit "unhold"'),this.emit("unhold",{originator:a})}},{key:"_onmute",value:function(a){var _=a.audio,e=a.video;J.debug("session onmute"),this._setLocalMediaStatus(),J.debug('emit "muted"'),this.emit("muted",{audio:_,video:e})}},{key:"_onunmute",value:function(a){var _=a.audio,e=a.video;J.debug("session onunmute"),this._setLocalMediaStatus(),J.debug('emit "unmuted"'),this.emit("unmuted",{audio:_,video:e})}},{key:"C",get:function(){return ee}},{key:"causes",get:function(){return ue.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(a){this._data=a}},{key:"status",get:function(){return this._status}}]),i}(ip);function Na(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Na=function(i){return typeof i}:Na=function(i){return i&&typeof Symbol=="function"&&i.constructor===Symbol&&i!==Symbol.prototype?"symbol":typeof i},Na(c)}function _p(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function Pc(c,s){for(var i=0;i<s.length;i++){var l=s[i];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(c,l.key,l)}}function hp(c,s,i){return s&&Pc(c.prototype,s),i&&Pc(c,i),c}function dp(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&mu(c,s)}function mu(c,s){return mu=Object.setPrototypeOf||function(l,a){return l.__proto__=a,l},mu(c,s)}function pp(c){var s=Tp();return function(){var l=qa(c),a;if(s){var _=qa(this).constructor;a=Reflect.construct(l,arguments,_)}else a=l.apply(this,arguments);return mp(this,a)}}function mp(c,s){return s&&(Na(s)==="object"||typeof s=="function")?s:gp(c)}function gp(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Tp(){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 qa(c){return qa=Object.setPrototypeOf?Object.getPrototypeOf:function(i){return i.__proto__||Object.getPrototypeOf(i)},qa(c)}var vp=ht.EventEmitter,Ep=dt,Io=ot,Sp=Rs,Ui=Nt(),yp=ul,xc=en,Ap=tn(),Ql=new Ep("Message"),Cp=function(c){dp(i,c);var s=pp(i);function i(l){var a;return _p(this,i),a=s.call(this),a._ua=l,a._request=null,a._closed=!1,a._direction=null,a._local_identity=null,a._remote_identity=null,a._is_replied=!1,a._data={},a}return hp(i,[{key:"send",value:function(a,_){var e=this,p=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},g=a;if(a===void 0||_===void 0)throw new TypeError("Not enough arguments");if(a=this._ua.normalizeTarget(a),!a)throw new TypeError("Invalid target: ".concat(g));var n=Ui.cloneArray(p.extraHeaders),v=Ui.cloneObject(p.eventHandlers),S=p.contentType||"text/plain",m={};p.fromUserName&&(m.from_uri=new Ap("sip",p.fromUserName,this._ua.configuration.uri.host),n.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),p.fromDisplayName&&(m.from_display_name=p.fromDisplayName);for(var C in v)Object.prototype.hasOwnProperty.call(v,C)&&this.on(C,v[C]);n.push("Content-Type: ".concat(S)),this._request=new Sp.OutgoingRequest(Io.MESSAGE,a,this._ua,m,n),_&&(this._request.body=_);var A=new yp(this._ua,this._request,{onRequestTimeout:function(){e._onRequestTimeout()},onTransportError:function(){e._onTransportError()},onReceiveResponse:function(I){e._receiveResponse(I)}});this._newMessage("local",this._request),A.send()}},{key:"init_incoming",value:function(a){this._request=a,this._newMessage("remote",a),this._is_replied||(this._is_replied=!0,a.reply(200)),this._close()}},{key:"accept",value:function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},_=Ui.cloneArray(a.extraHeaders),e=a.body;if(this._direction!=="incoming")throw new xc.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,_,e)}},{key:"reject",value:function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},_=a.status_code||480,e=a.reason_phrase,p=Ui.cloneArray(a.extraHeaders),g=a.body;if(this._direction!=="incoming")throw new xc.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(_<300||_>=700)throw new TypeError("Invalid status_code: ".concat(_));this._is_replied=!0,this._request.reply(_,e,p,g)}},{key:"_receiveResponse",value:function(a){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(a.status_code):break;case/^2[0-9]{2}$/.test(a.status_code):this._succeeded("remote",a);break;default:{var _=Ui.sipErrorCause(a.status_code);this._failed("remote",a,_);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:"_newMessage",value:function(a,_){a==="remote"?(this._direction="incoming",this._local_identity=_.to,this._remote_identity=_.from):a==="local"&&(this._direction="outgoing",this._local_identity=_.from,this._remote_identity=_.to),this._ua.newMessage(this,{originator:a,message:this,request:_})}},{key:"_failed",value:function(a,_,e){Ql.debug("MESSAGE failed"),this._close(),Ql.debug('emit "failed"'),this.emit("failed",{originator:a,response:_||null,cause:e})}},{key:"_succeeded",value:function(a,_){Ql.debug("MESSAGE succeeded"),this._close(),Ql.debug('emit "succeeded"'),this.emit("succeeded",{originator:a,response:_})}},{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}}]),i}(vp);function Ua(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ua=function(i){return typeof i}:Ua=function(i){return i&&typeof Symbol=="function"&&i.constructor===Symbol&&i!==Symbol.prototype?"symbol":typeof i},Ua(c)}function Rp(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function Mc(c,s){for(var i=0;i<s.length;i++){var l=s[i];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(c,l.key,l)}}function Ip(c,s,i){return s&&Mc(c.prototype,s),i&&Mc(c,i),c}function bp(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&gu(c,s)}function gu(c,s){return gu=Object.setPrototypeOf||function(l,a){return l.__proto__=a,l},gu(c,s)}function wp(c){var s=Np();return function(){var l=Va(c),a;if(s){var _=Va(this).constructor;a=Reflect.construct(l,arguments,_)}else a=l.apply(this,arguments);return Op(this,a)}}function Op(c,s){return s&&(Ua(s)==="object"||typeof s=="function")?s:Dp(c)}function Dp(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 Va(c){return Va=Object.setPrototypeOf?Object.getPrototypeOf:function(i){return i.__proto__||Object.getPrototypeOf(i)},Va(c)}var Up=ht.EventEmitter,Pp=dt,bo=ot,xp=Rs,Pi=Nt(),Mp=ul,kc=en,Zl=new Pp("Options"),kp=function(c){bp(i,c);var s=wp(i);function i(l){var a;return Rp(this,i),a=s.call(this),a._ua=l,a._request=null,a._closed=!1,a._direction=null,a._local_identity=null,a._remote_identity=null,a._is_replied=!1,a._data={},a}return Ip(i,[{key:"send",value:function(a,_){var e=this,p=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},g=a;if(a===void 0)throw new TypeError("A target is required for OPTIONS");if(a=this._ua.normalizeTarget(a),!a)throw new TypeError("Invalid target: ".concat(g));var n=Pi.cloneArray(p.extraHeaders),v=Pi.cloneObject(p.eventHandlers),S=p.contentType||"application/sdp";for(var m in v)Object.prototype.hasOwnProperty.call(v,m)&&this.on(m,v[m]);n.push("Content-Type: ".concat(S)),this._request=new xp.OutgoingRequest(bo.OPTIONS,a,this._ua,null,n),_&&(this._request.body=_);var C=new Mp(this._ua,this._request,{onRequestTimeout:function(){e._onRequestTimeout()},onTransportError:function(){e._onTransportError()},onReceiveResponse:function(R){e._receiveResponse(R)}});this._newOptions("local",this._request),C.send()}},{key:"init_incoming",value:function(a){this._request=a,this._newOptions("remote",a),this._is_replied||(this._is_replied=!0,a.reply(200)),this._close()}},{key:"accept",value:function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},_=Pi.cloneArray(a.extraHeaders),e=a.body;if(this._direction!=="incoming")throw new kc.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,_,e)}},{key:"reject",value:function(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},_=a.status_code||480,e=a.reason_phrase,p=Pi.cloneArray(a.extraHeaders),g=a.body;if(this._direction!=="incoming")throw new kc.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(_<300||_>=700)throw new TypeError("Invalid status_code: ".concat(_));this._is_replied=!0,this._request.reply(_,e,p,g)}},{key:"_receiveResponse",value:function(a){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(a.status_code):break;case/^2[0-9]{2}$/.test(a.status_code):this._succeeded("remote",a);break;default:{var _=Pi.sipErrorCause(a.status_code);this._failed("remote",a,_);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,bo.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,bo.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newOptions",value:function(a,_){a==="remote"?(this._direction="incoming",this._local_identity=_.to,this._remote_identity=_.from):a==="local"&&(this._direction="outgoing",this._local_identity=_.from,this._remote_identity=_.to),this._ua.newOptions(this,{originator:a,message:this,request:_})}},{key:"_failed",value:function(a,_,e){Zl.debug("OPTIONS failed"),this._close(),Zl.debug('emit "failed"'),this.emit("failed",{originator:a,response:_||null,cause:e})}},{key:"_succeeded",value:function(a,_){Zl.debug("OPTIONS succeeded"),this._close(),Zl.debug('emit "succeeded"'),this.emit("succeeded",{originator:a,response:_})}},{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}}]),i}(Up),xu={},Lp=dt,wo=Nt(),$p=us(),xi=new Lp("Socket");xu.isSocket=function(c){if(Array.isArray(c))return!1;if(typeof c>"u")return xi.warn("undefined JsSIP.Socket instance"),!1;try{if(!wo.isString(c.url))throw xi.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!wo.isString(c.via_transport))throw xi.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if($p.parse(c.sip_uri,"SIP_URI")===-1)throw xi.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(s){if(!wo.isFunction(c[s]))throw xi.warn("missing or invalid JsSIP.Socket method: ".concat(s)),new Error("Missing or invalid JsSIP.Socket method: ".concat(s))})}catch{return!1}return!0};function Hp(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function Lc(c,s){for(var i=0;i<s.length;i++){var l=s[i];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(c,l.key,l)}}function Fp(c,s,i){return s&&Lc(c.prototype,s),i&&Lc(c,i),c}var jp=dt,qp=xu,$c=ot,xt=new jp("Transport"),Ft={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:$c.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:$c.CONNECTION_RECOVERY_MAX_INTERVAL}},Vp=function(){function c(s){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Ft.recovery_options;Hp(this,c),xt.debug("new()"),this.status=Ft.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=i,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(l){xt.warn("cannot use TextDecoder: ".concat(l))}if(typeof s>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");s instanceof Array||(s=[s]),s.forEach(function(l){if(!qp.isSocket(l.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(l.weight&&!Number(l.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:l.socket,weight:l.weight||0,status:Ft.SOCKET_STATUS_READY})},this),this._getSocket()}return Fp(c,[{key:"connect",value:function(){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=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(){xt.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(i){if(xt.debug("send()"),!this.isConnected())return xt.warn("unable to send message, transport is not connected"),!1;var l=i.toString();return xt.debug(`sending message:
51
51
 
52
- `.concat(o,`
53
- `)),this.socket.send(o)}},{key:"isConnected",value:function(){return this.status===jt.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===jt.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var r=this;this.recover_attempts+=1;var o=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);o<this.recovery_options.min_interval?o=this.recovery_options.min_interval:o>this.recovery_options.max_interval&&(o=this.recovery_options.max_interval),Nt.debug("reconnection attempt: ".concat(this.recover_attempts,". next connection attempt in ").concat(o," seconds")),this.recovery_timer=setTimeout(function(){!r.close_requested&&!(r.isConnected()||r.isConnecting())&&(r._getSocket(),r.connect())},o*1e3)}},{key:"_getSocket",value:function(){var r=[];if(this.sockets.forEach(function(a){a.status!==jt.SOCKET_STATUS_ERROR&&(r.length===0?r.push(a):a.weight>r[0].weight?r=[a]:a.weight===r[0].weight&&r.push(a))}),r.length===0){this.sockets.forEach(function(a){a.status=jt.SOCKET_STATUS_READY}),this._getSocket();return}var o=Math.floor(Math.random()*r.length);this.socket=r[o].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=jt.STATUS_CONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(r,o,a){this.status=jt.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:r,code:o,reason:a}),!this.close_requested&&(this.sockets.forEach(function(t){this.socket===t.socket&&(t.status=jt.SOCKET_STATUS_ERROR)},this),this._reconnect(r))}},{key:"_onData",value:function(r){if(r===`\r
54
- `){Nt.debug("received message with CRLF Keep Alive response");return}else if(typeof r!="string"){try{this.textDecoder?r=this.textDecoder.decode(r):r=String.fromCharCode.apply(null,new Uint8Array(r))}catch{Nt.debug("received binary message failed to be converted into string, message discarded");return}Nt.debug(`received binary message:
52
+ `.concat(l,`
53
+ `)),this.socket.send(l)}},{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 i=this;this.recover_attempts+=1;var l=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);l<this.recovery_options.min_interval?l=this.recovery_options.min_interval:l>this.recovery_options.max_interval&&(l=this.recovery_options.max_interval),xt.debug("reconnection attempt: ".concat(this.recover_attempts,". next connection attempt in ").concat(l," seconds")),this.recovery_timer=setTimeout(function(){!i.close_requested&&!(i.isConnected()||i.isConnecting())&&(i._getSocket(),i.connect())},l*1e3)}},{key:"_getSocket",value:function(){var i=[];if(this.sockets.forEach(function(a){a.status!==Ft.SOCKET_STATUS_ERROR&&(i.length===0?i.push(a):a.weight>i[0].weight?i=[a]:a.weight===i[0].weight&&i.push(a))}),i.length===0){this.sockets.forEach(function(a){a.status=Ft.SOCKET_STATUS_READY}),this._getSocket();return}var l=Math.floor(Math.random()*i.length);this.socket=i[l].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(i,l,a){this.status=Ft.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:i,code:l,reason:a}),!this.close_requested&&(this.sockets.forEach(function(_){this.socket===_.socket&&(_.status=Ft.SOCKET_STATUS_ERROR)},this),this._reconnect(i))}},{key:"_onData",value:function(i){if(i===`\r
54
+ `){xt.debug("received message with CRLF Keep Alive response");return}else if(typeof i!="string"){try{this.textDecoder?i=this.textDecoder.decode(i):i=String.fromCharCode.apply(null,new Uint8Array(i))}catch{xt.debug("received binary message failed to be converted into string, message discarded");return}xt.debug(`received binary message:
55
55
 
56
- `.concat(r,`
57
- `))}else Nt.debug(`received text message:
56
+ `.concat(i,`
57
+ `))}else xt.debug(`received text message:
58
58
 
59
- `.concat(r,`
60
- `));this.ondata({transport:this,message:r})}},{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}(),s_={};function kc(c,s){var r;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(r=Hp(c))||s&&c&&typeof c.length=="number"){r&&(c=r);var o=0,a=function(){};return{s:a,n:function(){return o>=c.length?{done:!0}:{done:!1,value:c[o++]}},e:function(h){throw h},f:a}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
61
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var t=!0,n=!1,d;return{s:function(){r=c[Symbol.iterator]()},n:function(){var h=r.next();return t=h.done,h},e:function(h){n=!0,d=h},f:function(){try{!t&&r.return!=null&&r.return()}finally{if(n)throw d}}}}function Hp(c,s){if(c){if(typeof c=="string")return Lc(c,s);var r=Object.prototype.toString.call(c).slice(8,-1);if(r==="Object"&&c.constructor&&(r=c.constructor.name),r==="Map"||r==="Set")return Array.from(c);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return Lc(c,s)}}function Lc(c,s){(s==null||s>c.length)&&(s=c.length);for(var r=0,o=new Array(s);r<s;r++)o[r]=c[r];return o}var Fp=_t,du=is(),pu=vs,Vl=new Fp("Parser");s_.parseMessage=function(c,s){var r,o,a=c.indexOf(`\r
62
- `);if(a===-1){Vl.warn("parseMessage() | no CRLF found, not a SIP message");return}var t=c.substring(0,a),n=du.parse(t,"Request_Response");if(n===-1){Vl.warn('parseMessage() | error parsing first line of SIP message: "'.concat(t,'"'));return}else n.status_code?(r=new pu.IncomingResponse,r.status_code=n.status_code,r.reason_phrase=n.reason_phrase):(r=new pu.IncomingRequest(s),r.method=n.method,r.ruri=n.uri);r.data=c;for(var d=a+2;;){if(a=jp(c,d),a===-2){o=d+2;break}else if(a===-1){Vl.warn("parseMessage() | malformed message");return}if(n=qp(r,c,d,a),n!==!0){Vl.warn("parseMessage() |",n.error);return}d=a+2}if(r.hasHeader("content-length")){var _=r.getHeader("content-length");r.body=c.substr(o,_)}else r.body=c.substring(o);return r};function jp(c,s){var r=s,o=0,a=0;if(c.substring(r,r+2).match(/(^\r\n)/))return-2;for(;o===0;){if(a=c.indexOf(`\r
63
- `,r),a===-1)return a;!c.substring(a+2,a+4).match(/(^\r\n)/)&&c.charAt(a+2).match(/(^\s+)/)?r=a+2:o=a}return o}function qp(c,s,r,o){var a,t=s.indexOf(":",r),n=s.substring(r,t).trim(),d=s.substring(t+1,o).trim();switch(n.toLowerCase()){case"via":case"v":c.addHeader("via",d),c.getHeaders("via").length===1?(a=c.parseHeader("Via"),a&&(c.via=a,c.via_branch=a.branch)):a=0;break;case"from":case"f":c.setHeader("from",d),a=c.parseHeader("from"),a&&(c.from=a,c.from_tag=a.getParam("tag"));break;case"to":case"t":c.setHeader("to",d),a=c.parseHeader("to"),a&&(c.to=a,c.to_tag=a.getParam("tag"));break;case"record-route":if(a=du.parse(d,"Record_Route"),a===-1)a=void 0;else{var _=kc(a),h;try{for(_.s();!(h=_.n()).done;){var g=h.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(A){_.e(A)}finally{_.f()}}break;case"call-id":case"i":c.setHeader("call-id",d),a=c.parseHeader("call-id"),a&&(c.call_id=d);break;case"contact":case"m":if(a=du.parse(d,"Contact"),a===-1)a=void 0;else{var T=kc(a),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(A){T.e(A)}finally{T.f()}}break;case"content-length":case"l":c.setHeader("content-length",d),a=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",d),a=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",d),a=c.parseHeader("cseq"),a&&(c.cseq=a.value),c instanceof pu.IncomingResponse&&(c.method=a.method);break;case"max-forwards":c.setHeader("max-forwards",d),a=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",d),a=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",d),a=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",d),a=c.parseHeader("session-expires"),a&&(c.session_expires=a.expires,c.session_expires_refresher=a.refresher);break;case"refer-to":case"r":c.setHeader("refer-to",d),a=c.parseHeader("refer-to"),a&&(c.refer_to=a);break;case"replaces":c.setHeader("replaces",d),a=c.parseHeader("replaces"),a&&(c.replaces=a);break;case"event":case"o":c.setHeader("event",d),a=c.parseHeader("event"),a&&(c.event=a);break;default:c.addHeader(n,d),a=0}return a===void 0?{error:'error parsing header "'.concat(n,'"')}:!0}function Ao(c,s){var r;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(r=Vp(c))||s&&c&&typeof c.length=="number"){r&&(c=r);var o=0,a=function(){};return{s:a,n:function(){return o>=c.length?{done:!0}:{done:!1,value:c[o++]}},e:function(h){throw h},f:a}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
64
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var t=!0,n=!1,d;return{s:function(){r=c[Symbol.iterator]()},n:function(){var h=r.next();return t=h.done,h},e:function(h){n=!0,d=h},f:function(){try{!t&&r.return!=null&&r.return()}finally{if(n)throw d}}}}function Vp(c,s){if(c){if(typeof c=="string")return $c(c,s);var r=Object.prototype.toString.call(c).slice(8,-1);if(r==="Object"&&c.constructor&&(r=c.constructor.name),r==="Map"||r==="Set")return Array.from(c);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return $c(c,s)}}function $c(c,s){(s==null||s>c.length)&&(s=c.length);for(var r=0,o=new Array(s);r<s;r++)o[r]=c[r];return o}var Bp=_t,n_=it,Hc=vs,Du=bt(),Nu=new Bp("sanityCheck"),Gp=[tm],Wp=[Jp,zp,Xp,Qp],Kp=[Zp,em],He,ts,r_,Yp=function(c,s,r){He=c,ts=s,r_=r;var o=Ao(Gp),a;try{for(o.s();!(a=o.n()).done;){var t=a.value;if(t()===!1)return!1}}catch(E){o.e(E)}finally{o.f()}if(He instanceof Hc.IncomingRequest){var n=Ao(Wp),d;try{for(n.s();!(d=n.n()).done;){var _=d.value;if(_()===!1)return!1}}catch(E){n.e(E)}finally{n.f()}}else if(He instanceof Hc.IncomingResponse){var h=Ao(Kp),g;try{for(h.s();!(g=h.n()).done;){var T=g.value;if(T()===!1)return!1}}catch(E){h.e(E)}finally{h.f()}}return!0};function Jp(){if(He.s("to").uri.scheme!=="sip")return Qi(416),!1}function zp(){if(!He.to_tag&&He.call_id.substr(0,5)===ts.configuration.jssip_id)return Qi(482),!1}function Xp(){var c=Du.str_utf8_length(He.body),s=He.getHeader("content-length");if(c<s)return Qi(400),!1}function Qp(){var c=He.from_tag,s=He.call_id,r=He.cseq,o;if(!He.to_tag)if(He.method===n_.INVITE){if(ts._transactions.ist[He.via_branch])return!1;for(var a in ts._transactions.ist)if(Object.prototype.hasOwnProperty.call(ts._transactions.ist,a)&&(o=ts._transactions.ist[a],o.request.from_tag===c&&o.request.call_id===s&&o.request.cseq===r))return Qi(482),!1}else{if(ts._transactions.nist[He.via_branch])return!1;for(var t in ts._transactions.nist)if(Object.prototype.hasOwnProperty.call(ts._transactions.nist,t)&&(o=ts._transactions.nist[t],o.request.from_tag===c&&o.request.call_id===s&&o.request.cseq===r))return Qi(482),!1}}function Zp(){if(He.getHeaders("via").length>1)return Nu.debug("more than one Via header field present in the response, dropping the response"),!1}function em(){var c=Du.str_utf8_length(He.body),s=He.getHeader("content-length");if(c<s)return Nu.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}function tm(){for(var c=["from","to","call_id","cseq","via"],s=0,r=c;s<r.length;s++){var o=r[s];if(!He.hasHeader(o))return Nu.debug("missing mandatory header field : ".concat(o,", dropping the response")),!1}}function Qi(c){var s=He.getHeaders("via"),r,o="SIP/2.0 ".concat(c," ").concat(n_.REASON_PHRASE[c],`\r
65
- `),a=Ao(s),t;try{for(a.s();!(t=a.n()).done;){var n=t.value;o+="Via: ".concat(n,`\r
66
- `)}}catch(d){a.e(d)}finally{a.f()}r=He.getHeader("To"),He.to_tag||(r+=";tag=".concat(Du.newTag())),o+="To: ".concat(r,`\r
67
- `),o+="From: ".concat(He.getHeader("From"),`\r
68
- `),o+="Call-ID: ".concat(He.call_id,`\r
69
- `),o+="CSeq: ".concat(He.cseq," ").concat(He.method,`\r
70
- `),o+=`\r
71
- `,r_.send(o)}var Uu={};function Fc(c,s){var r;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(r=sm(c))||s&&c&&typeof c.length=="number"){r&&(c=r);var o=0,a=function(){};return{s:a,n:function(){return o>=c.length?{done:!0}:{done:!1,value:c[o++]}},e:function(h){throw h},f:a}}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 t=!0,n=!1,d;return{s:function(){r=c[Symbol.iterator]()},n:function(){var h=r.next();return t=h.done,h},e:function(h){n=!0,d=h},f:function(){try{!t&&r.return!=null&&r.return()}finally{if(n)throw d}}}}function sm(c,s){if(c){if(typeof c=="string")return jc(c,s);var r=Object.prototype.toString.call(c).slice(8,-1);if(r==="Object"&&c.constructor&&(r=c.constructor.name),r==="Map"||r==="Set")return Array.from(c);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return jc(c,s)}}function jc(c,s){(s==null||s>c.length)&&(s=c.length);for(var r=0,o=new Array(s);r<s;r++)o[r]=c[r];return o}var ar=bt(),En=it,Ca=is(),qc=Gs(),Ra=Ou,Ia=Bs;Uu.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(ar.createRandomToken(12),".invalid")};var Bl={mandatory:{sockets:function(s){var r=[];if(Ra.isSocket(s))r.push({socket:s});else if(Array.isArray(s)&&s.length){var o=Fc(s),a;try{for(o.s();!(a=o.n()).done;){var t=a.value;Object.prototype.hasOwnProperty.call(t,"socket")&&Ra.isSocket(t.socket)?r.push(t):Ra.isSocket(t)&&r.push({socket:t})}}catch(n){o.e(n)}finally{o.f()}}else return;return r},uri:function(s){/^sip:/i.test(s)||(s="".concat(En.SIP,":").concat(s));var r=qc.parse(s);if(r)return r.user?r:void 0}},optional:{authorization_user:function(s){if(Ca.parse('"'.concat(s,'"'),"quoted_string")!==-1)return s},authorization_jwt:function(s){if(typeof s=="string")return s},user_agent:function(s){if(typeof s=="string")return s},connection_recovery_max_interval:function(s){if(ar.isDecimal(s)){var r=Number(s);if(r>0)return r}},connection_recovery_min_interval:function(s){if(ar.isDecimal(s)){var r=Number(s);if(r>0)return r}},contact_uri:function(s){if(typeof s=="string"){var r=Ca.parse(s,"SIP_URI");if(r!==-1)return r}},display_name:function(s){return s},instance_id:function(s){if(/^uuid:/i.test(s)&&(s=s.substr(5)),Ca.parse(s,"uuid")!==-1)return s},no_answer_timeout:function(s){if(ar.isDecimal(s)){var r=Number(s);if(r>0)return r}},session_timers:function(s){if(typeof s=="boolean")return s},session_timers_refresh_method:function(s){if(typeof s=="string"&&(s=s.toUpperCase(),s===En.INVITE||s===En.UPDATE))return s},session_timers_force_refresher:function(s){if(typeof s=="boolean")return s},password:function(s){return String(s)},realm:function(s){return String(s)},ha1:function(s){return String(s)},register:function(s){if(typeof s=="boolean")return s},register_expires:function(s){if(ar.isDecimal(s)){var r=Number(s);if(r>0)return r}},registrar_server:function(s){/^sip:/i.test(s)||(s="".concat(En.SIP,":").concat(s));var r=qc.parse(s);if(r)return r.user?void 0:r},use_preloaded_route:function(s){if(typeof s=="boolean")return s},extra_headers:function(s){var r=[];if(Array.isArray(s)&&s.length){var o=Fc(s),a;try{for(o.s();!(a=o.n()).done;){var t=a.value;typeof t=="string"&&r.push(t)}}catch(n){o.e(n)}finally{o.f()}}else return;return r}}};Uu.load=function(c,s){for(var r in Bl.mandatory)if(s.hasOwnProperty(r)){var o=s[r],a=Bl.mandatory[r](o);if(a!==void 0)c[r]=a;else throw new Ia.ConfigurationError(r,o)}else throw new Ia.ConfigurationError(r);for(var t in Bl.optional)if(s.hasOwnProperty(t)){var n=s[t];if(ar.isEmpty(n))continue;var d=Bl.optional[t](n);if(d!==void 0)c[t]=d;else throw new Ia.ConfigurationError(t,n)}};function Co(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Co=function(r){return typeof r}:Co=function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},Co(c)}function nm(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function Vc(c,s){for(var r=0;r<s.length;r++){var o=s[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function Bc(c,s,r){return s&&Vc(c.prototype,s),r&&Vc(c,r),c}function rm(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&mu(c,s)}function mu(c,s){return mu=Object.setPrototypeOf||function(o,a){return o.__proto__=a,o},mu(c,s)}function im(c){var s=om();return function(){var o=xo(c),a;if(s){var t=xo(this).constructor;a=Reflect.construct(o,arguments,t)}else a=o.apply(this,arguments);return lm(this,a)}}function lm(c,s){return s&&(Co(s)==="object"||typeof s=="function")?s:i_(c)}function i_(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function om(){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 xo(c){return xo=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)},xo(c)}var am=ft.EventEmitter,um=_t,pt=it,cm=Xh,Gc=lp,Wc=vp,Kc=Np,ba=al,fm=$p,Gl=bt(),_m=Bs,hm=Gs(),dm=s_,wa=vs,pm=Yp,Oa=Uu,je=new um("UA"),Tt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},mm=function(c){rm(r,c);var s=im(r);Bc(r,null,[{key:"C",get:function(){return Tt}}]);function r(o){var a;if(nm(this,r),je.debug("new() [configuration:%o]",o),a=s.call(this),a._cache={credentials:{}},a._configuration=Object.assign({},Oa.settings),a._dynConfiguration={},a._dialogs={},a._applicants={},a._sessions={},a._transport=null,a._contact=null,a._status=Tt.STATUS_INIT,a._error=null,a._transactions={nist:{},nict:{},ist:{},ict:{}},a._data={},a._closeTimer=null,o===void 0)throw new TypeError("Not enough arguments");try{a._loadConfig(o)}catch(t){throw a._status=Tt.STATUS_NOT_READY,a._error=Tt.CONFIGURATION_ERROR,t}return a._registrator=new cm(i_(a)),a}return Bc(r,[{key:"start",value:function(){je.debug("start()"),this._status===Tt.STATUS_INIT?this._transport.connect():this._status===Tt.STATUS_USER_CLOSED?(je.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=Tt.STATUS_INIT,this._transport.connect()):this._status===Tt.STATUS_READY?je.debug("UA is in READY status, not restarted"):je.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}},{key:"register",value:function(){je.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}},{key:"unregister",value:function(a){je.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(a)}},{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(a,t){je.debug("call()");var n=new Gc(this);return n.connect(a,t),n}},{key:"sendMessage",value:function(a,t,n){je.debug("sendMessage()");var d=new Wc(this);return d.send(a,t,n),d}},{key:"sendOptions",value:function(a,t,n){je.debug("sendOptions()");var d=new Kc(this);return d.send(a,t,n),d}},{key:"terminateSessions",value:function(a){je.debug("terminateSessions()");for(var t in this._sessions)this._sessions[t].isEnded()||this._sessions[t].terminate(a)}},{key:"stop",value:function(){var a=this;if(je.debug("stop()"),this._dynConfiguration={},this._status===Tt.STATUS_USER_CLOSED){je.debug("UA already closed");return}this._registrator.close();var t=Object.keys(this._sessions).length;for(var n in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,n)){je.debug("closing session ".concat(n));try{this._sessions[n].terminate()}catch{}}for(var d in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,d))try{this._applicants[d].close()}catch{}this._status=Tt.STATUS_USER_CLOSED;var _=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(function(){a._closeTimer=null,a._transport.disconnect()},2e3)}},{key:"normalizeTarget",value:function(a){return Gl.normalizeTarget(a,this._configuration.hostport_params)}},{key:"get",value:function(a){switch(a){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:je.warn('get() | cannot get "%s" parameter in runtime',a);return}}},{key:"set",value:function(a,t){switch(a){case"authorization_user":{this._configuration.authorization_user=String(t);break}case"password":{this._configuration.password=String(t);break}case"realm":{this._configuration.realm=String(t);break}case"ha1":{this._configuration.ha1=String(t),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(t);break}case"display_name":{this._configuration.display_name=t;break}default:return je.warn('set() | cannot set "%s" parameter in runtime',a),!1}return!0}},{key:"newTransaction",value:function(a){this._transactions[a.type][a.id]=a,this.emit("newTransaction",{transaction:a})}},{key:"destroyTransaction",value:function(a){delete this._transactions[a.type][a.id],this.emit("transactionDestroyed",{transaction:a})}},{key:"newDialog",value:function(a){this._dialogs[a.id]=a}},{key:"destroyDialog",value:function(a){delete this._dialogs[a.id]}},{key:"newMessage",value:function(a,t){this._applicants[a]=a,this.emit("newMessage",t)}},{key:"newOptions",value:function(a,t){this._applicants[a]=a,this.emit("newOptions",t)}},{key:"destroyMessage",value:function(a){delete this._applicants[a]}},{key:"newRTCSession",value:function(a,t){this._sessions[a.id]=a,this.emit("newRTCSession",t)}},{key:"destroyRTCSession",value:function(a){delete this._sessions[a.id]}},{key:"registered",value:function(a){this.emit("registered",a)}},{key:"unregistered",value:function(a){this.emit("unregistered",a)}},{key:"registrationFailed",value:function(a){this.emit("registrationFailed",a)}},{key:"receiveRequest",value:function(a){var t=a.method;if(a.ruri.user!==this._configuration.uri.user&&a.ruri.user!==this._contact.uri.user){je.debug("Request-URI does not point to us"),a.method!==pt.ACK&&a.reply_sl(404);return}if(a.ruri.scheme===pt.SIPS){a.reply_sl(416);return}if(!ba.checkTransaction(this,a)){if(t===pt.INVITE?new ba.InviteServerTransaction(this,this._transport,a):t!==pt.ACK&&t!==pt.CANCEL&&new ba.NonInviteServerTransaction(this,this._transport,a),t===pt.OPTIONS){if(this.listeners("newOptions").length===0){a.reply(200);return}var n=new Kc(this);n.init_incoming(a)}else if(t===pt.MESSAGE){if(this.listeners("newMessage").length===0){a.reply(405);return}var d=new Wc(this);d.init_incoming(a)}else if(t===pt.INVITE&&!a.to_tag&&this.listeners("newRTCSession").length===0){a.reply(405);return}var _,h;if(a.to_tag)_=this._findDialog(a.call_id,a.from_tag,a.to_tag),_?_.receiveRequest(a):t===pt.NOTIFY?(h=this._findSession(a),h?h.receiveRequest(a):(je.debug("received NOTIFY request for a non existent subscription"),a.reply(481,"Subscription does not exist"))):t!==pt.ACK&&a.reply(481);else switch(t){case pt.INVITE:if(window.RTCPeerConnection)if(a.hasHeader("replaces")){var g=a.replaces;_=this._findDialog(g.call_id,g.from_tag,g.to_tag),_?(h=_.owner,h.isEnded()?a.reply(603):h.receiveRequest(a)):a.reply(481)}else h=new Gc(this),h.init_incoming(a);else je.warn("INVITE received but WebRTC is not supported"),a.reply(488);break;case pt.BYE:a.reply(481);break;case pt.CANCEL:h=this._findSession(a),h?h.receiveRequest(a):je.debug("received CANCEL request for a non existent session");break;case pt.ACK:break;case pt.NOTIFY:this.emit("sipEvent",{event:a.event,request:a}),a.reply(200);break;default:a.reply(405);break}}}},{key:"_findSession",value:function(a){var t=a.call_id,n=a.from_tag,d=a.to_tag,_=t+n,h=this._sessions[_],g=t+d,T=this._sessions[g];return h||T||null}},{key:"_findDialog",value:function(a,t,n){var d=a+t+n,_=this._dialogs[d];return _||(d=a+n+t,_=this._dialogs[d],_||null)}},{key:"_loadConfig",value:function(a){try{Oa.load(this._configuration,a)}catch(g){throw g}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=Gl.newUUID()),this._configuration.jssip_id=Gl.createRandomToken(5);var t=this._configuration.uri.clone();t.user=null,this._configuration.hostport_params=t.toString().replace(/^sip:/i,"");try{this._transport=new fm(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=gm.bind(this),this._transport.onconnect=Tm.bind(this),this._transport.ondisconnect=vm.bind(this),this._transport.ondata=Em.bind(this)}catch(g){throw je.warn(g),new _m.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 n=this._configuration.uri.clone();n.user=null,n.clearParams(),n.clearHeaders(),this._configuration.registrar_server=n}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new hm("sip",Gl.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 _ in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,_)&&(d.indexOf(_)!==-1?Object.defineProperty(this._configuration,_,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,_,{writable:!1,configurable:!1}));je.debug("configuration parameters after validation:");for(var h in this._configuration)if(Object.prototype.hasOwnProperty.call(Oa.settings,h))switch(h){case"uri":case"registrar_server":je.debug("- ".concat(h,": ").concat(this._configuration[h]));break;case"password":case"ha1":case"authorization_jwt":je.debug("- ".concat(h,": NOT SHOWN"));break;default:je.debug("- ".concat(h,": ").concat(JSON.stringify(this._configuration[h])))}}},{key:"C",get:function(){return Tt}},{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}}]),r}(am);function gm(c){this.emit("connecting",c)}function Tm(c){this._status!==Tt.STATUS_USER_CLOSED&&(this._status=Tt.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function vm(c){for(var s=["nict","ict","nist","ist"],r=0,o=s;r<o.length;r++){var a=o[r];for(var t in this._transactions[a])Object.prototype.hasOwnProperty.call(this._transactions[a],t)&&this._transactions[a][t].onTransportError()}this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==Tt.STATUS_USER_CLOSED&&(this._status=Tt.STATUS_NOT_READY,this._error=Tt.NETWORK_ERROR)}function Em(c){var s=c.transport,r=c.message;if(r=dm.parseMessage(r,this),!!r&&!(this._status===Tt.STATUS_USER_CLOSED&&r instanceof wa.IncomingRequest)&&pm(r,this,s)){if(r instanceof wa.IncomingRequest)r.transport=s,this.receiveRequest(r);else if(r instanceof wa.IncomingResponse){var o;switch(r.method){case pt.INVITE:o=this._transactions.ict[r.via_branch],o&&o.receiveResponse(r);break;case pt.ACK:break;default:o=this._transactions.nict[r.via_branch],o&&o.receiveResponse(r);break}}}}function Sm(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function Yc(c,s){for(var r=0;r<s.length;r++){var o=s[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(c,o.key,o)}}function ym(c,s,r){return s&&Yc(c.prototype,s),r&&Yc(c,r),c}var Am=_t,Cm=is(),Ot=new Am("WebSocketInterface"),Rm=function(){function c(s){Sm(this,c),Ot.debug('new() [url:"%s"]',s),this._url=s,this._sip_uri=null,this._via_transport=null,this._ws=null;var r=Cm.parse(s,"absoluteURI");if(r===-1)throw Ot.warn("invalid WebSocket URI: ".concat(s)),new TypeError("Invalid argument: ".concat(s));if(r.scheme!=="wss"&&r.scheme!=="ws")throw Ot.warn("invalid WebSocket URI scheme: ".concat(r.scheme)),new TypeError("Invalid argument: ".concat(s));this._sip_uri="sip:".concat(r.host).concat(r.port?":".concat(r.port):"",";transport=ws"),this._via_transport=r.scheme.toUpperCase()}return ym(c,[{key:"connect",value:function(){if(Ot.debug("connect()"),this.isConnected()){Ot.debug("WebSocket ".concat(this._url," is already connected"));return}else if(this.isConnecting()){Ot.debug("WebSocket ".concat(this._url," is connecting"));return}this._ws&&this.disconnect(),Ot.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(r){this._onError(r)}}},{key:"disconnect",value:function(){Ot.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(r){return Ot.debug("send()"),this.isConnected()?(this._ws.send(r),!0):(Ot.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(){Ot.debug("WebSocket ".concat(this._url," connected")),this.onconnect()}},{key:"_onClose",value:function(r){var o=r.wasClean,a=r.code,t=r.reason;Ot.debug("WebSocket ".concat(this._url," closed")),o===!1&&Ot.debug("WebSocket abrupt disconnection"),this.ondisconnect(!o,a,t)}},{key:"_onMessage",value:function(r){var o=r.data;Ot.debug("received WebSocket message"),this.ondata(o)}},{key:"_onError",value:function(r){Ot.warn("WebSocket ".concat(this._url," error: "),r)}},{key:"via_transport",get:function(){return this._via_transport},set:function(r){this._via_transport=r.toUpperCase()}},{key:"sip_uri",get:function(){return this._sip_uri}},{key:"url",get:function(){return this._url}}]),c}(),gu=Lo,Im=it,bm=Bs,wm=bt(),Om=mm,Dm=Gs(),Nm=Cu(),Um=is(),Pm=Rm,xm=dr("JsSIP");xm("version %s",gu.version);var Jc={C:Im,Exceptions:bm,Utils:wm,UA:Om,URI:Dm,NameAddrHeader:Nm,WebSocketInterface:Pm,Grammar:Um,debug:dr,get name(){return gu.title},get version(){return gu.version}};const ir=dr,lr="JsSIP";var at=class{constructor(s){s?(this._debug=ir.default(`${lr}:${s}`),this._warn=ir.default(`${lr}:WARN:${s}`),this._error=ir.default(`${lr}:ERROR:${s}`)):(this._debug=ir.default(lr),this._warn=ir.default(`${lr}:WARN`),this._error=ir.default(`${lr}: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 Pu=Xe(at),zc=Lo;var De={USER_AGENT:`${zc.title} ${zc.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 $=Xe(De);var et={},Da,Xc;function xu(){if(Xc)return Da;Xc=1;const c=Es(),s=ls();return Da=class l_{static parse(o){if(o=s.parse(o,"Name_Addr_Header"),o!==-1)return o}constructor(o,a,t){if(!o||!(o instanceof c))throw new TypeError('missing or invalid "uri" parameter');this._uri=o,this._parameters={},this.display_name=a;for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&this.setParam(n,t[n])}get uri(){return this._uri}get display_name(){return this._display_name}set display_name(o){this._display_name=o===0?"0":o}setParam(o,a){o&&(this._parameters[o.toLowerCase()]=typeof a>"u"||a===null?null:a.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 a=this._parameters[o];return delete this._parameters[o],a}}clearParams(){this._parameters={}}clone(){return new l_(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}_quote(o){return o.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}toString(){let o=this._display_name?`"${this._quote(this._display_name)}" `:"";o+=`<${this._uri.toString()}>`;for(const a in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,a)&&(o+=`;${a}`,this._parameters[a]!==null&&(o+=`=${this._parameters[a]}`));return o}},Da}var Na,Qc;function ls(){return Qc||(Qc=1,Na=function(){function c(r){return'"'+r.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 s={parse:function(r,o){var a={CRLF:h,DIGIT:g,ALPHA:T,HEXDIG:E,WSP:y,OCTET:A,DQUOTE:C,SP:I,HTAB:H,alphanum:L,reserved:ae,unreserved:N,mark:j,escaped:Se,LWS:ve,SWS:M,HCOLON:D,TEXT_UTF8_TRIM:B,TEXT_UTF8char:V,UTF8_NONASCII:J,UTF8_CONT:F,LHEX:X,token:U,token_nodot:P,separators:se,word:tt,STAR:ee,SLASH:W,EQUAL:G,LPAREN:re,RPAREN:ge,RAQUOT:be,LAQUOT:xe,COMMA:Ce,SEMI:le,COLON:ye,LDQUOT:st,RDQUOT:lt,comment:Ee,ctext:Ae,quoted_string:Ie,quoted_string_clean:Oe,qdtext:pe,quoted_pair:ue,SIP_URI_noparams:de,SIP_URI:we,uri_scheme:Ne,uri_scheme_sips:Qe,uri_scheme_sip:Le,userinfo:kt,user:ht,user_unreserved:Rn,password:In,hostport:Ws,host:Xt,hostname:os,domainlabel:Ks,toplabel:bn,IPv6reference:wn,IPv6address:Ys,h16:me,ls32:oe,IPv4address:ot,dec_octet:Gt,port:ys,uri_parameters:gr,uri_parameter:On,transport_param:Dn,user_param:Tr,method_param:vr,ttl_param:Er,maddr_param:Sr,lr_param:yr,other_param:Ar,pname:Cr,pvalue:Rr,paramchar:As,param_unreserved:Cs,headers:Ir,header:Js,hname:zs,hvalue:br,hnv_unreserved:Rs,Request_Response:Xs,Request_Line:hl,Request_URI:wr,absoluteURI:Nn,hier_part:Un,net_path:Or,abs_path:Qs,opaque_part:Zs,uric:Is,uric_no_slash:bs,path_segments:Dr,segment:en,param:ws,pchar:as,scheme:Os,authority:Nr,srvr:Ur,reg_name:Pr,query:xr,SIP_Version:Pn,INVITEm:xn,ACKm:Mr,OPTIONSm:kr,BYEm:Lr,CANCELm:$r,REGISTERm:Hr,SUBSCRIBEm:Fr,NOTIFYm:jr,REFERm:qr,Method:tn,Status_Line:sn,Status_Code:Vr,extension_code:Br,Reason_Phrase:Gr,Allow_Events:dl,Call_ID:Go,Contact:Wo,contact_param:Mn,name_addr:Lt,display_name:$t,contact_params:Ds,c_p_q:kn,c_p_expires:Wr,delta_seconds:Qt,qvalue:Zt,generic_param:Ge,gen_value:We,Content_Disposition:pl,disp_type:ml,disp_param:Ln,handling_param:$n,Content_Encoding:gl,Content_Length:Ko,Content_Type:Yo,media_type:Tl,m_type:Kr,discrete_type:Yr,composite_type:Jr,extension_token:nn,x_token:rn,m_subtype:zr,m_parameter:Hn,m_value:Fn,CSeq:vl,CSeq_value:El,Expires:Sl,Event:Jo,event_type:ln,From:on,from_param:Xr,tag_param:an,Max_Forwards:Qr,Min_Expires:zo,Name_Addr_Header:Xo,Proxy_Authenticate:Qo,challenge:Zr,other_challenge:jn,auth_param:Ns,digest_cln:es,realm:un,realm_value:ei,domain:ti,URI:cn,nonce:fn,nonce_value:si,opaque:ni,stale:ri,algorithm:ii,qop_options:li,qop_value:_n,Proxy_Require:qn,Record_Route:Zo,rec_route:Vn,Reason:Bn,reason_param:oi,reason_cause:Gn,Require:yl,Route:ea,route_param:Wn,Subscription_State:Kn,substate_value:Al,subexp_params:Yn,event_reason_value:Jn,Subject:Cl,Supported:ta,To:sa,to_param:ai,Via:ui,via_param:zn,via_params:Us,via_ttl:Xn,via_maddr:ci,via_received:fi,via_branch:_i,response_port:hi,rport:di,sent_protocol:pi,protocol_name:mi,transport:gi,sent_by:Ti,via_host:vi,via_port:Ei,ttl:Qn,WWW_Authenticate:Si,Session_Expires:na,s_e_expires:Rl,s_e_params:Zn,s_e_refresher:er,extension_header:Il,header_value:bl,message_body:wl,uuid_URI:ra,uuid:Ol,hex4:Ht,hex8:Ft,hex12:yi,Refer_To:Dl,Replaces:ia,call_id:Nl,replaces_param:tr,to_tag:sr,from_tag:Ai,early_flag:Ci};if(o!==void 0){if(a[o]===void 0)throw new Error("Invalid rule name: "+c(o)+".")}else o="CRLF";var t=0,n=0,d=[];function _(i){t<n||(t>n&&(n=t,d=[]),d.push(i))}function h(){var i;return r.substr(t,2)===`\r
73
- `?(i=`\r
74
- `,t+=2):(i=null,_('"\\r\\n"')),i}function g(){var i;return/^[0-9]/.test(r.charAt(t))?(i=r.charAt(t),t++):(i=null,_("[0-9]")),i}function T(){var i;return/^[a-zA-Z]/.test(r.charAt(t))?(i=r.charAt(t),t++):(i=null,_("[a-zA-Z]")),i}function E(){var i;return/^[0-9a-fA-F]/.test(r.charAt(t))?(i=r.charAt(t),t++):(i=null,_("[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(r.charAt(t))?(i=r.charAt(t),t++):(i=null,_("[\\0-\\xFF]")),i}function C(){var i;return/^["]/.test(r.charAt(t))?(i=r.charAt(t),t++):(i=null,_('["]')),i}function I(){var i;return r.charCodeAt(t)===32?(i=" ",t++):(i=null,_('" "')),i}function H(){var i;return r.charCodeAt(t)===9?(i=" ",t++):(i=null,_('"\\t"')),i}function L(){var i;return/^[a-zA-Z0-9]/.test(r.charAt(t))?(i=r.charAt(t),t++):(i=null,_("[a-zA-Z0-9]")),i}function ae(){var i;return r.charCodeAt(t)===59?(i=";",t++):(i=null,_('";"')),i===null&&(r.charCodeAt(t)===47?(i="/",t++):(i=null,_('"/"')),i===null&&(r.charCodeAt(t)===63?(i="?",t++):(i=null,_('"?"')),i===null&&(r.charCodeAt(t)===58?(i=":",t++):(i=null,_('":"')),i===null&&(r.charCodeAt(t)===64?(i="@",t++):(i=null,_('"@"')),i===null&&(r.charCodeAt(t)===38?(i="&",t++):(i=null,_('"&"')),i===null&&(r.charCodeAt(t)===61?(i="=",t++):(i=null,_('"="')),i===null&&(r.charCodeAt(t)===43?(i="+",t++):(i=null,_('"+"')),i===null&&(r.charCodeAt(t)===36?(i="$",t++):(i=null,_('"$"')),i===null&&(r.charCodeAt(t)===44?(i=",",t++):(i=null,_('","'))))))))))),i}function N(){var i;return i=L(),i===null&&(i=j()),i}function j(){var i;return r.charCodeAt(t)===45?(i="-",t++):(i=null,_('"-"')),i===null&&(r.charCodeAt(t)===95?(i="_",t++):(i=null,_('"_"')),i===null&&(r.charCodeAt(t)===46?(i=".",t++):(i=null,_('"."')),i===null&&(r.charCodeAt(t)===33?(i="!",t++):(i=null,_('"!"')),i===null&&(r.charCodeAt(t)===126?(i="~",t++):(i=null,_('"~"')),i===null&&(r.charCodeAt(t)===42?(i="*",t++):(i=null,_('"*"')),i===null&&(r.charCodeAt(t)===39?(i="'",t++):(i=null,_(`"'"`)),i===null&&(r.charCodeAt(t)===40?(i="(",t++):(i=null,_('"("')),i===null&&(r.charCodeAt(t)===41?(i=")",t++):(i=null,_('")"')))))))))),i}function Se(){var i,e,l,u,f;return u=t,f=t,r.charCodeAt(t)===37?(i="%",t++):(i=null,_('"%"')),i!==null?(e=E(),e!==null?(l=E(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p,m){return m.join("")}(u,i)),i===null&&(t=u),i}function ve(){var i,e,l,u,f,p;for(u=t,f=t,p=t,i=[],e=y();e!==null;)i.push(e),e=y();if(i!==null?(e=h(),e!==null?i=[i,e]:(i=null,t=p)):(i=null,t=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,t=f)}else i=null,t=f;return i!==null&&(i=function(m){return" "}()),i===null&&(t=u),i}function M(){var i;return i=ve(),i=i!==null?i:"",i}function D(){var i,e,l,u,f;for(u=t,f=t,i=[],e=I(),e===null&&(e=H());e!==null;)i.push(e),e=I(),e===null&&(e=H());return i!==null?(r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e!==null?(l=M(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p){return":"}()),i===null&&(t=u),i}function B(){var i,e,l,u,f,p,m;if(f=t,p=t,e=V(),e!==null)for(i=[];e!==null;)i.push(e),e=V();else i=null;if(i!==null){for(e=[],m=t,l=[],u=ve();u!==null;)l.push(u),u=ve();for(l!==null?(u=V(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);l!==null;){for(e.push(l),m=t,l=[],u=ve();u!==null;)l.push(u),u=ve();l!==null?(u=V(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m)}e!==null?i=[i,e]:(i=null,t=p)}else i=null,t=p;return i!==null&&(i=function(v){return r.substring(t,v)}(f)),i===null&&(t=f),i}function V(){var i;return/^[!-~]/.test(r.charAt(t))?(i=r.charAt(t),t++):(i=null,_("[!-~]")),i===null&&(i=J()),i}function J(){var i;return/^[\x80-\uFFFF]/.test(r.charAt(t))?(i=r.charAt(t),t++):(i=null,_("[\\x80-\\uFFFF]")),i}function F(){var i;return/^[\x80-\xBF]/.test(r.charAt(t))?(i=r.charAt(t),t++):(i=null,_("[\\x80-\\xBF]")),i}function X(){var i;return i=g(),i===null&&(/^[a-f]/.test(r.charAt(t))?(i=r.charAt(t),t++):(i=null,_("[a-f]"))),i}function U(){var i,e,l;if(l=t,e=L(),e===null&&(r.charCodeAt(t)===45?(e="-",t++):(e=null,_('"-"')),e===null&&(r.charCodeAt(t)===46?(e=".",t++):(e=null,_('"."')),e===null&&(r.charCodeAt(t)===33?(e="!",t++):(e=null,_('"!"')),e===null&&(r.charCodeAt(t)===37?(e="%",t++):(e=null,_('"%"')),e===null&&(r.charCodeAt(t)===42?(e="*",t++):(e=null,_('"*"')),e===null&&(r.charCodeAt(t)===95?(e="_",t++):(e=null,_('"_"')),e===null&&(r.charCodeAt(t)===43?(e="+",t++):(e=null,_('"+"')),e===null&&(r.charCodeAt(t)===96?(e="`",t++):(e=null,_('"`"')),e===null&&(r.charCodeAt(t)===39?(e="'",t++):(e=null,_(`"'"`)),e===null&&(r.charCodeAt(t)===126?(e="~",t++):(e=null,_('"~"')))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=L(),e===null&&(r.charCodeAt(t)===45?(e="-",t++):(e=null,_('"-"')),e===null&&(r.charCodeAt(t)===46?(e=".",t++):(e=null,_('"."')),e===null&&(r.charCodeAt(t)===33?(e="!",t++):(e=null,_('"!"')),e===null&&(r.charCodeAt(t)===37?(e="%",t++):(e=null,_('"%"')),e===null&&(r.charCodeAt(t)===42?(e="*",t++):(e=null,_('"*"')),e===null&&(r.charCodeAt(t)===95?(e="_",t++):(e=null,_('"_"')),e===null&&(r.charCodeAt(t)===43?(e="+",t++):(e=null,_('"+"')),e===null&&(r.charCodeAt(t)===96?(e="`",t++):(e=null,_('"`"')),e===null&&(r.charCodeAt(t)===39?(e="'",t++):(e=null,_(`"'"`)),e===null&&(r.charCodeAt(t)===126?(e="~",t++):(e=null,_('"~"'))))))))))));else i=null;return i!==null&&(i=function(u){return r.substring(t,u)}(l)),i===null&&(t=l),i}function P(){var i,e,l;if(l=t,e=L(),e===null&&(r.charCodeAt(t)===45?(e="-",t++):(e=null,_('"-"')),e===null&&(r.charCodeAt(t)===33?(e="!",t++):(e=null,_('"!"')),e===null&&(r.charCodeAt(t)===37?(e="%",t++):(e=null,_('"%"')),e===null&&(r.charCodeAt(t)===42?(e="*",t++):(e=null,_('"*"')),e===null&&(r.charCodeAt(t)===95?(e="_",t++):(e=null,_('"_"')),e===null&&(r.charCodeAt(t)===43?(e="+",t++):(e=null,_('"+"')),e===null&&(r.charCodeAt(t)===96?(e="`",t++):(e=null,_('"`"')),e===null&&(r.charCodeAt(t)===39?(e="'",t++):(e=null,_(`"'"`)),e===null&&(r.charCodeAt(t)===126?(e="~",t++):(e=null,_('"~"'))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=L(),e===null&&(r.charCodeAt(t)===45?(e="-",t++):(e=null,_('"-"')),e===null&&(r.charCodeAt(t)===33?(e="!",t++):(e=null,_('"!"')),e===null&&(r.charCodeAt(t)===37?(e="%",t++):(e=null,_('"%"')),e===null&&(r.charCodeAt(t)===42?(e="*",t++):(e=null,_('"*"')),e===null&&(r.charCodeAt(t)===95?(e="_",t++):(e=null,_('"_"')),e===null&&(r.charCodeAt(t)===43?(e="+",t++):(e=null,_('"+"')),e===null&&(r.charCodeAt(t)===96?(e="`",t++):(e=null,_('"`"')),e===null&&(r.charCodeAt(t)===39?(e="'",t++):(e=null,_(`"'"`)),e===null&&(r.charCodeAt(t)===126?(e="~",t++):(e=null,_('"~"')))))))))));else i=null;return i!==null&&(i=function(u){return r.substring(t,u)}(l)),i===null&&(t=l),i}function se(){var i;return r.charCodeAt(t)===40?(i="(",t++):(i=null,_('"("')),i===null&&(r.charCodeAt(t)===41?(i=")",t++):(i=null,_('")"')),i===null&&(r.charCodeAt(t)===60?(i="<",t++):(i=null,_('"<"')),i===null&&(r.charCodeAt(t)===62?(i=">",t++):(i=null,_('">"')),i===null&&(r.charCodeAt(t)===64?(i="@",t++):(i=null,_('"@"')),i===null&&(r.charCodeAt(t)===44?(i=",",t++):(i=null,_('","')),i===null&&(r.charCodeAt(t)===59?(i=";",t++):(i=null,_('";"')),i===null&&(r.charCodeAt(t)===58?(i=":",t++):(i=null,_('":"')),i===null&&(r.charCodeAt(t)===92?(i="\\",t++):(i=null,_('"\\\\"')),i===null&&(i=C(),i===null&&(r.charCodeAt(t)===47?(i="/",t++):(i=null,_('"/"')),i===null&&(r.charCodeAt(t)===91?(i="[",t++):(i=null,_('"["')),i===null&&(r.charCodeAt(t)===93?(i="]",t++):(i=null,_('"]"')),i===null&&(r.charCodeAt(t)===63?(i="?",t++):(i=null,_('"?"')),i===null&&(r.charCodeAt(t)===61?(i="=",t++):(i=null,_('"="')),i===null&&(r.charCodeAt(t)===123?(i="{",t++):(i=null,_('"{"')),i===null&&(r.charCodeAt(t)===125?(i="}",t++):(i=null,_('"}"')),i===null&&(i=I(),i===null&&(i=H())))))))))))))))))),i}function tt(){var i,e,l;if(l=t,e=L(),e===null&&(r.charCodeAt(t)===45?(e="-",t++):(e=null,_('"-"')),e===null&&(r.charCodeAt(t)===46?(e=".",t++):(e=null,_('"."')),e===null&&(r.charCodeAt(t)===33?(e="!",t++):(e=null,_('"!"')),e===null&&(r.charCodeAt(t)===37?(e="%",t++):(e=null,_('"%"')),e===null&&(r.charCodeAt(t)===42?(e="*",t++):(e=null,_('"*"')),e===null&&(r.charCodeAt(t)===95?(e="_",t++):(e=null,_('"_"')),e===null&&(r.charCodeAt(t)===43?(e="+",t++):(e=null,_('"+"')),e===null&&(r.charCodeAt(t)===96?(e="`",t++):(e=null,_('"`"')),e===null&&(r.charCodeAt(t)===39?(e="'",t++):(e=null,_(`"'"`)),e===null&&(r.charCodeAt(t)===126?(e="~",t++):(e=null,_('"~"')),e===null&&(r.charCodeAt(t)===40?(e="(",t++):(e=null,_('"("')),e===null&&(r.charCodeAt(t)===41?(e=")",t++):(e=null,_('")"')),e===null&&(r.charCodeAt(t)===60?(e="<",t++):(e=null,_('"<"')),e===null&&(r.charCodeAt(t)===62?(e=">",t++):(e=null,_('">"')),e===null&&(r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e===null&&(r.charCodeAt(t)===92?(e="\\",t++):(e=null,_('"\\\\"')),e===null&&(e=C(),e===null&&(r.charCodeAt(t)===47?(e="/",t++):(e=null,_('"/"')),e===null&&(r.charCodeAt(t)===91?(e="[",t++):(e=null,_('"["')),e===null&&(r.charCodeAt(t)===93?(e="]",t++):(e=null,_('"]"')),e===null&&(r.charCodeAt(t)===63?(e="?",t++):(e=null,_('"?"')),e===null&&(r.charCodeAt(t)===123?(e="{",t++):(e=null,_('"{"')),e===null&&(r.charCodeAt(t)===125?(e="}",t++):(e=null,_('"}"'))))))))))))))))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=L(),e===null&&(r.charCodeAt(t)===45?(e="-",t++):(e=null,_('"-"')),e===null&&(r.charCodeAt(t)===46?(e=".",t++):(e=null,_('"."')),e===null&&(r.charCodeAt(t)===33?(e="!",t++):(e=null,_('"!"')),e===null&&(r.charCodeAt(t)===37?(e="%",t++):(e=null,_('"%"')),e===null&&(r.charCodeAt(t)===42?(e="*",t++):(e=null,_('"*"')),e===null&&(r.charCodeAt(t)===95?(e="_",t++):(e=null,_('"_"')),e===null&&(r.charCodeAt(t)===43?(e="+",t++):(e=null,_('"+"')),e===null&&(r.charCodeAt(t)===96?(e="`",t++):(e=null,_('"`"')),e===null&&(r.charCodeAt(t)===39?(e="'",t++):(e=null,_(`"'"`)),e===null&&(r.charCodeAt(t)===126?(e="~",t++):(e=null,_('"~"')),e===null&&(r.charCodeAt(t)===40?(e="(",t++):(e=null,_('"("')),e===null&&(r.charCodeAt(t)===41?(e=")",t++):(e=null,_('")"')),e===null&&(r.charCodeAt(t)===60?(e="<",t++):(e=null,_('"<"')),e===null&&(r.charCodeAt(t)===62?(e=">",t++):(e=null,_('">"')),e===null&&(r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e===null&&(r.charCodeAt(t)===92?(e="\\",t++):(e=null,_('"\\\\"')),e===null&&(e=C(),e===null&&(r.charCodeAt(t)===47?(e="/",t++):(e=null,_('"/"')),e===null&&(r.charCodeAt(t)===91?(e="[",t++):(e=null,_('"["')),e===null&&(r.charCodeAt(t)===93?(e="]",t++):(e=null,_('"]"')),e===null&&(r.charCodeAt(t)===63?(e="?",t++):(e=null,_('"?"')),e===null&&(r.charCodeAt(t)===123?(e="{",t++):(e=null,_('"{"')),e===null&&(r.charCodeAt(t)===125?(e="}",t++):(e=null,_('"}"')))))))))))))))))))))))));else i=null;return i!==null&&(i=function(u){return r.substring(t,u)}(l)),i===null&&(t=l),i}function ee(){var i,e,l,u,f;return u=t,f=t,i=M(),i!==null?(r.charCodeAt(t)===42?(e="*",t++):(e=null,_('"*"')),e!==null?(l=M(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p){return"*"}()),i===null&&(t=u),i}function W(){var i,e,l,u,f;return u=t,f=t,i=M(),i!==null?(r.charCodeAt(t)===47?(e="/",t++):(e=null,_('"/"')),e!==null?(l=M(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p){return"/"}()),i===null&&(t=u),i}function G(){var i,e,l,u,f;return u=t,f=t,i=M(),i!==null?(r.charCodeAt(t)===61?(e="=",t++):(e=null,_('"="')),e!==null?(l=M(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p){return"="}()),i===null&&(t=u),i}function re(){var i,e,l,u,f;return u=t,f=t,i=M(),i!==null?(r.charCodeAt(t)===40?(e="(",t++):(e=null,_('"("')),e!==null?(l=M(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p){return"("}()),i===null&&(t=u),i}function ge(){var i,e,l,u,f;return u=t,f=t,i=M(),i!==null?(r.charCodeAt(t)===41?(e=")",t++):(e=null,_('")"')),e!==null?(l=M(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p){return")"}()),i===null&&(t=u),i}function be(){var i,e,l,u;return l=t,u=t,r.charCodeAt(t)===62?(i=">",t++):(i=null,_('">"')),i!==null?(e=M(),e!==null?i=[i,e]:(i=null,t=u)):(i=null,t=u),i!==null&&(i=function(f){return">"}()),i===null&&(t=l),i}function xe(){var i,e,l,u;return l=t,u=t,i=M(),i!==null?(r.charCodeAt(t)===60?(e="<",t++):(e=null,_('"<"')),e!==null?i=[i,e]:(i=null,t=u)):(i=null,t=u),i!==null&&(i=function(f){return"<"}()),i===null&&(t=l),i}function Ce(){var i,e,l,u,f;return u=t,f=t,i=M(),i!==null?(r.charCodeAt(t)===44?(e=",",t++):(e=null,_('","')),e!==null?(l=M(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p){return","}()),i===null&&(t=u),i}function le(){var i,e,l,u,f;return u=t,f=t,i=M(),i!==null?(r.charCodeAt(t)===59?(e=";",t++):(e=null,_('";"')),e!==null?(l=M(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p){return";"}()),i===null&&(t=u),i}function ye(){var i,e,l,u,f;return u=t,f=t,i=M(),i!==null?(r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e!==null?(l=M(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p){return":"}()),i===null&&(t=u),i}function st(){var i,e,l,u;return l=t,u=t,i=M(),i!==null?(e=C(),e!==null?i=[i,e]:(i=null,t=u)):(i=null,t=u),i!==null&&(i=function(f){return'"'}()),i===null&&(t=l),i}function lt(){var i,e,l,u;return l=t,u=t,i=C(),i!==null?(e=M(),e!==null?i=[i,e]:(i=null,t=u)):(i=null,t=u),i!==null&&(i=function(f){return'"'}()),i===null&&(t=l),i}function Ee(){var i,e,l,u;if(u=t,i=re(),i!==null){for(e=[],l=Ae(),l===null&&(l=ue(),l===null&&(l=Ee()));l!==null;)e.push(l),l=Ae(),l===null&&(l=ue(),l===null&&(l=Ee()));e!==null?(l=ge(),l!==null?i=[i,e,l]:(i=null,t=u)):(i=null,t=u)}else i=null,t=u;return i}function Ae(){var i;return/^[!-']/.test(r.charAt(t))?(i=r.charAt(t),t++):(i=null,_("[!-']")),i===null&&(/^[*-[]/.test(r.charAt(t))?(i=r.charAt(t),t++):(i=null,_("[*-[]")),i===null&&(/^[\]-~]/.test(r.charAt(t))?(i=r.charAt(t),t++):(i=null,_("[\\]-~]")),i===null&&(i=J(),i===null&&(i=ve())))),i}function Ie(){var i,e,l,u,f,p;if(f=t,p=t,i=M(),i!==null)if(e=C(),e!==null){for(l=[],u=pe(),u===null&&(u=ue());u!==null;)l.push(u),u=pe(),u===null&&(u=ue());l!==null?(u=C(),u!==null?i=[i,e,l,u]:(i=null,t=p)):(i=null,t=p)}else i=null,t=p;else i=null,t=p;return i!==null&&(i=function(m){return r.substring(t,m)}(f)),i===null&&(t=f),i}function Oe(){var i,e,l,u,f,p;if(f=t,p=t,i=M(),i!==null)if(e=C(),e!==null){for(l=[],u=pe(),u===null&&(u=ue());u!==null;)l.push(u),u=pe(),u===null&&(u=ue());l!==null?(u=C(),u!==null?i=[i,e,l,u]:(i=null,t=p)):(i=null,t=p)}else i=null,t=p;else i=null,t=p;return i!==null&&(i=function(m){var v=r.substring(t,m).trim();return v.substring(1,v.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(f)),i===null&&(t=f),i}function pe(){var i;return i=ve(),i===null&&(r.charCodeAt(t)===33?(i="!",t++):(i=null,_('"!"')),i===null&&(/^[#-[]/.test(r.charAt(t))?(i=r.charAt(t),t++):(i=null,_("[#-[]")),i===null&&(/^[\]-~]/.test(r.charAt(t))?(i=r.charAt(t),t++):(i=null,_("[\\]-~]")),i===null&&(i=J())))),i}function ue(){var i,e,l;return l=t,r.charCodeAt(t)===92?(i="\\",t++):(i=null,_('"\\\\"')),i!==null?(/^[\0-\t]/.test(r.charAt(t))?(e=r.charAt(t),t++):(e=null,_("[\\0-\\t]")),e===null&&(/^[\x0B-\f]/.test(r.charAt(t))?(e=r.charAt(t),t++):(e=null,_("[\\x0B-\\f]")),e===null&&(/^[\x0E-]/.test(r.charAt(t))?(e=r.charAt(t),t++):(e=null,_("[\\x0E-]")))),e!==null?i=[i,e]:(i=null,t=l)):(i=null,t=l),i}function de(){var i,e,l,u,f,p;return f=t,p=t,i=Ne(),i!==null?(r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e!==null?(l=kt(),l=l!==null?l:"",l!==null?(u=Ws(),u!==null?i=[i,e,l,u]:(i=null,t=p)):(i=null,t=p)):(i=null,t=p)):(i=null,t=p),i!==null&&(i=function(m){try{b.uri=new Pl(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&&(t=f),i}function we(){var i,e,l,u,f,p,m,v;return m=t,v=t,i=Ne(),i!==null?(r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e!==null?(l=kt(),l=l!==null?l:"",l!==null?(u=Ws(),u!==null?(f=gr(),f!==null?(p=Ir(),p=p!==null?p:"",p!==null?i=[i,e,l,u,f,p]:(i=null,t=v)):(i=null,t=v)):(i=null,t=v)):(i=null,t=v)):(i=null,t=v)):(i=null,t=v),i!==null&&(i=function(S){try{b.uri=new Pl(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,o==="SIP_URI"&&(b=b.uri)}catch{b=-1}}()),i===null&&(t=m),i}function Ne(){var i;return i=Qe(),i===null&&(i=Le()),i}function Qe(){var i,e;return e=t,r.substr(t,4).toLowerCase()==="sips"?(i=r.substr(t,4),t+=4):(i=null,_('"sips"')),i!==null&&(i=function(l,u){b.scheme=u.toLowerCase()}(e,i)),i===null&&(t=e),i}function Le(){var i,e;return e=t,r.substr(t,3).toLowerCase()==="sip"?(i=r.substr(t,3),t+=3):(i=null,_('"sip"')),i!==null&&(i=function(l,u){b.scheme=u.toLowerCase()}(e,i)),i===null&&(t=e),i}function kt(){var i,e,l,u,f,p;return u=t,f=t,i=ht(),i!==null?(p=t,r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e!==null?(l=In(),l!==null?e=[e,l]:(e=null,t=p)):(e=null,t=p),e=e!==null?e:"",e!==null?(r.charCodeAt(t)===64?(l="@",t++):(l=null,_('"@"')),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(m){b.user=decodeURIComponent(r.substring(t-1,m))}(u)),i===null&&(t=u),i}function ht(){var i,e;if(e=N(),e===null&&(e=Se(),e===null&&(e=Rn())),e!==null)for(i=[];e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(e=Rn()));else i=null;return i}function Rn(){var i;return r.charCodeAt(t)===38?(i="&",t++):(i=null,_('"&"')),i===null&&(r.charCodeAt(t)===61?(i="=",t++):(i=null,_('"="')),i===null&&(r.charCodeAt(t)===43?(i="+",t++):(i=null,_('"+"')),i===null&&(r.charCodeAt(t)===36?(i="$",t++):(i=null,_('"$"')),i===null&&(r.charCodeAt(t)===44?(i=",",t++):(i=null,_('","')),i===null&&(r.charCodeAt(t)===59?(i=";",t++):(i=null,_('";"')),i===null&&(r.charCodeAt(t)===63?(i="?",t++):(i=null,_('"?"')),i===null&&(r.charCodeAt(t)===47?(i="/",t++):(i=null,_('"/"'))))))))),i}function In(){var i,e,l;for(l=t,i=[],e=N(),e===null&&(e=Se(),e===null&&(r.charCodeAt(t)===38?(e="&",t++):(e=null,_('"&"')),e===null&&(r.charCodeAt(t)===61?(e="=",t++):(e=null,_('"="')),e===null&&(r.charCodeAt(t)===43?(e="+",t++):(e=null,_('"+"')),e===null&&(r.charCodeAt(t)===36?(e="$",t++):(e=null,_('"$"')),e===null&&(r.charCodeAt(t)===44?(e=",",t++):(e=null,_('","'))))))));e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(r.charCodeAt(t)===38?(e="&",t++):(e=null,_('"&"')),e===null&&(r.charCodeAt(t)===61?(e="=",t++):(e=null,_('"="')),e===null&&(r.charCodeAt(t)===43?(e="+",t++):(e=null,_('"+"')),e===null&&(r.charCodeAt(t)===36?(e="$",t++):(e=null,_('"$"')),e===null&&(r.charCodeAt(t)===44?(e=",",t++):(e=null,_('","'))))))));return i!==null&&(i=function(u){b.password=r.substring(t,u)}(l)),i===null&&(t=l),i}function Ws(){var i,e,l,u,f;return u=t,i=Xt(),i!==null?(f=t,r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e!==null?(l=ys(),l!==null?e=[e,l]:(e=null,t=f)):(e=null,t=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,t=u)):(i=null,t=u),i}function Xt(){var i,e;return e=t,i=os(),i===null&&(i=ot(),i===null&&(i=wn())),i!==null&&(i=function(l){return b.host=r.substring(t,l).toLowerCase(),b.host}(e)),i===null&&(t=e),i}function os(){var i,e,l,u,f,p;for(u=t,f=t,i=[],p=t,e=Ks(),e!==null?(r.charCodeAt(t)===46?(l=".",t++):(l=null,_('"."')),l!==null?e=[e,l]:(e=null,t=p)):(e=null,t=p);e!==null;)i.push(e),p=t,e=Ks(),e!==null?(r.charCodeAt(t)===46?(l=".",t++):(l=null,_('"."')),l!==null?e=[e,l]:(e=null,t=p)):(e=null,t=p);return i!==null?(e=bn(),e!==null?(r.charCodeAt(t)===46?(l=".",t++):(l=null,_('"."')),l=l!==null?l:"",l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(m){return b.host_type="domain",r.substring(t,m)}(u)),i===null&&(t=u),i}function Ks(){var i,e,l,u;if(u=t,i=L(),i!==null){for(e=[],l=L(),l===null&&(r.charCodeAt(t)===45?(l="-",t++):(l=null,_('"-"')),l===null&&(r.charCodeAt(t)===95?(l="_",t++):(l=null,_('"_"'))));l!==null;)e.push(l),l=L(),l===null&&(r.charCodeAt(t)===45?(l="-",t++):(l=null,_('"-"')),l===null&&(r.charCodeAt(t)===95?(l="_",t++):(l=null,_('"_"'))));e!==null?i=[i,e]:(i=null,t=u)}else i=null,t=u;return i}function bn(){var i,e,l,u;if(u=t,i=T(),i!==null){for(e=[],l=L(),l===null&&(r.charCodeAt(t)===45?(l="-",t++):(l=null,_('"-"')),l===null&&(r.charCodeAt(t)===95?(l="_",t++):(l=null,_('"_"'))));l!==null;)e.push(l),l=L(),l===null&&(r.charCodeAt(t)===45?(l="-",t++):(l=null,_('"-"')),l===null&&(r.charCodeAt(t)===95?(l="_",t++):(l=null,_('"_"'))));e!==null?i=[i,e]:(i=null,t=u)}else i=null,t=u;return i}function wn(){var i,e,l,u,f;return u=t,f=t,r.charCodeAt(t)===91?(i="[",t++):(i=null,_('"["')),i!==null?(e=Ys(),e!==null?(r.charCodeAt(t)===93?(l="]",t++):(l=null,_('"]"')),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p){return b.host_type="IPv6",r.substring(t,p)}(u)),i===null&&(t=u),i}function Ys(){var i,e,l,u,f,p,m,v,S,O,ie,Ue,wt,Ps,k,R;return Ps=t,k=t,i=me(),i!==null?(r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e!==null?(l=me(),l!==null?(r.charCodeAt(t)===58?(u=":",t++):(u=null,_('":"')),u!==null?(f=me(),f!==null?(r.charCodeAt(t)===58?(p=":",t++):(p=null,_('":"')),p!==null?(m=me(),m!==null?(r.charCodeAt(t)===58?(v=":",t++):(v=null,_('":"')),v!==null?(S=me(),S!==null?(r.charCodeAt(t)===58?(O=":",t++):(O=null,_('":"')),O!==null?(ie=me(),ie!==null?(r.charCodeAt(t)===58?(Ue=":",t++):(Ue=null,_('":"')),Ue!==null?(wt=oe(),wt!==null?i=[i,e,l,u,f,p,m,v,S,O,ie,Ue,wt]:(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k),i===null&&(k=t,r.substr(t,2)==="::"?(i="::",t+=2):(i=null,_('"::"')),i!==null?(e=me(),e!==null?(r.charCodeAt(t)===58?(l=":",t++):(l=null,_('":"')),l!==null?(u=me(),u!==null?(r.charCodeAt(t)===58?(f=":",t++):(f=null,_('":"')),f!==null?(p=me(),p!==null?(r.charCodeAt(t)===58?(m=":",t++):(m=null,_('":"')),m!==null?(v=me(),v!==null?(r.charCodeAt(t)===58?(S=":",t++):(S=null,_('":"')),S!==null?(O=me(),O!==null?(r.charCodeAt(t)===58?(ie=":",t++):(ie=null,_('":"')),ie!==null?(Ue=oe(),Ue!==null?i=[i,e,l,u,f,p,m,v,S,O,ie,Ue]:(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k),i===null&&(k=t,r.substr(t,2)==="::"?(i="::",t+=2):(i=null,_('"::"')),i!==null?(e=me(),e!==null?(r.charCodeAt(t)===58?(l=":",t++):(l=null,_('":"')),l!==null?(u=me(),u!==null?(r.charCodeAt(t)===58?(f=":",t++):(f=null,_('":"')),f!==null?(p=me(),p!==null?(r.charCodeAt(t)===58?(m=":",t++):(m=null,_('":"')),m!==null?(v=me(),v!==null?(r.charCodeAt(t)===58?(S=":",t++):(S=null,_('":"')),S!==null?(O=oe(),O!==null?i=[i,e,l,u,f,p,m,v,S,O]:(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k),i===null&&(k=t,r.substr(t,2)==="::"?(i="::",t+=2):(i=null,_('"::"')),i!==null?(e=me(),e!==null?(r.charCodeAt(t)===58?(l=":",t++):(l=null,_('":"')),l!==null?(u=me(),u!==null?(r.charCodeAt(t)===58?(f=":",t++):(f=null,_('":"')),f!==null?(p=me(),p!==null?(r.charCodeAt(t)===58?(m=":",t++):(m=null,_('":"')),m!==null?(v=oe(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k),i===null&&(k=t,r.substr(t,2)==="::"?(i="::",t+=2):(i=null,_('"::"')),i!==null?(e=me(),e!==null?(r.charCodeAt(t)===58?(l=":",t++):(l=null,_('":"')),l!==null?(u=me(),u!==null?(r.charCodeAt(t)===58?(f=":",t++):(f=null,_('":"')),f!==null?(p=oe(),p!==null?i=[i,e,l,u,f,p]:(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k),i===null&&(k=t,r.substr(t,2)==="::"?(i="::",t+=2):(i=null,_('"::"')),i!==null?(e=me(),e!==null?(r.charCodeAt(t)===58?(l=":",t++):(l=null,_('":"')),l!==null?(u=oe(),u!==null?i=[i,e,l,u]:(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k),i===null&&(k=t,r.substr(t,2)==="::"?(i="::",t+=2):(i=null,_('"::"')),i!==null?(e=oe(),e!==null?i=[i,e]:(i=null,t=k)):(i=null,t=k),i===null&&(k=t,r.substr(t,2)==="::"?(i="::",t+=2):(i=null,_('"::"')),i!==null?(e=me(),e!==null?i=[i,e]:(i=null,t=k)):(i=null,t=k),i===null&&(k=t,i=me(),i!==null?(r.substr(t,2)==="::"?(e="::",t+=2):(e=null,_('"::"')),e!==null?(l=me(),l!==null?(r.charCodeAt(t)===58?(u=":",t++):(u=null,_('":"')),u!==null?(f=me(),f!==null?(r.charCodeAt(t)===58?(p=":",t++):(p=null,_('":"')),p!==null?(m=me(),m!==null?(r.charCodeAt(t)===58?(v=":",t++):(v=null,_('":"')),v!==null?(S=me(),S!==null?(r.charCodeAt(t)===58?(O=":",t++):(O=null,_('":"')),O!==null?(ie=oe(),ie!==null?i=[i,e,l,u,f,p,m,v,S,O,ie]:(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k),i===null&&(k=t,i=me(),i!==null?(R=t,r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,t=R)):(e=null,t=R),e=e!==null?e:"",e!==null?(r.substr(t,2)==="::"?(l="::",t+=2):(l=null,_('"::"')),l!==null?(u=me(),u!==null?(r.charCodeAt(t)===58?(f=":",t++):(f=null,_('":"')),f!==null?(p=me(),p!==null?(r.charCodeAt(t)===58?(m=":",t++):(m=null,_('":"')),m!==null?(v=me(),v!==null?(r.charCodeAt(t)===58?(S=":",t++):(S=null,_('":"')),S!==null?(O=oe(),O!==null?i=[i,e,l,u,f,p,m,v,S,O]:(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k),i===null&&(k=t,i=me(),i!==null?(R=t,r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,t=R)):(e=null,t=R),e=e!==null?e:"",e!==null?(R=t,r.charCodeAt(t)===58?(l=":",t++):(l=null,_('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,t=R)):(l=null,t=R),l=l!==null?l:"",l!==null?(r.substr(t,2)==="::"?(u="::",t+=2):(u=null,_('"::"')),u!==null?(f=me(),f!==null?(r.charCodeAt(t)===58?(p=":",t++):(p=null,_('":"')),p!==null?(m=me(),m!==null?(r.charCodeAt(t)===58?(v=":",t++):(v=null,_('":"')),v!==null?(S=oe(),S!==null?i=[i,e,l,u,f,p,m,v,S]:(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k),i===null&&(k=t,i=me(),i!==null?(R=t,r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,t=R)):(e=null,t=R),e=e!==null?e:"",e!==null?(R=t,r.charCodeAt(t)===58?(l=":",t++):(l=null,_('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,t=R)):(l=null,t=R),l=l!==null?l:"",l!==null?(R=t,r.charCodeAt(t)===58?(u=":",t++):(u=null,_('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,t=R)):(u=null,t=R),u=u!==null?u:"",u!==null?(r.substr(t,2)==="::"?(f="::",t+=2):(f=null,_('"::"')),f!==null?(p=me(),p!==null?(r.charCodeAt(t)===58?(m=":",t++):(m=null,_('":"')),m!==null?(v=oe(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k),i===null&&(k=t,i=me(),i!==null?(R=t,r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,t=R)):(e=null,t=R),e=e!==null?e:"",e!==null?(R=t,r.charCodeAt(t)===58?(l=":",t++):(l=null,_('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,t=R)):(l=null,t=R),l=l!==null?l:"",l!==null?(R=t,r.charCodeAt(t)===58?(u=":",t++):(u=null,_('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,t=R)):(u=null,t=R),u=u!==null?u:"",u!==null?(R=t,r.charCodeAt(t)===58?(f=":",t++):(f=null,_('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,t=R)):(f=null,t=R),f=f!==null?f:"",f!==null?(r.substr(t,2)==="::"?(p="::",t+=2):(p=null,_('"::"')),p!==null?(m=oe(),m!==null?i=[i,e,l,u,f,p,m]:(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k),i===null&&(k=t,i=me(),i!==null?(R=t,r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,t=R)):(e=null,t=R),e=e!==null?e:"",e!==null?(R=t,r.charCodeAt(t)===58?(l=":",t++):(l=null,_('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,t=R)):(l=null,t=R),l=l!==null?l:"",l!==null?(R=t,r.charCodeAt(t)===58?(u=":",t++):(u=null,_('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,t=R)):(u=null,t=R),u=u!==null?u:"",u!==null?(R=t,r.charCodeAt(t)===58?(f=":",t++):(f=null,_('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,t=R)):(f=null,t=R),f=f!==null?f:"",f!==null?(R=t,r.charCodeAt(t)===58?(p=":",t++):(p=null,_('":"')),p!==null?(m=me(),m!==null?p=[p,m]:(p=null,t=R)):(p=null,t=R),p=p!==null?p:"",p!==null?(r.substr(t,2)==="::"?(m="::",t+=2):(m=null,_('"::"')),m!==null?(v=me(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k),i===null&&(k=t,i=me(),i!==null?(R=t,r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,t=R)):(e=null,t=R),e=e!==null?e:"",e!==null?(R=t,r.charCodeAt(t)===58?(l=":",t++):(l=null,_('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,t=R)):(l=null,t=R),l=l!==null?l:"",l!==null?(R=t,r.charCodeAt(t)===58?(u=":",t++):(u=null,_('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,t=R)):(u=null,t=R),u=u!==null?u:"",u!==null?(R=t,r.charCodeAt(t)===58?(f=":",t++):(f=null,_('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,t=R)):(f=null,t=R),f=f!==null?f:"",f!==null?(R=t,r.charCodeAt(t)===58?(p=":",t++):(p=null,_('":"')),p!==null?(m=me(),m!==null?p=[p,m]:(p=null,t=R)):(p=null,t=R),p=p!==null?p:"",p!==null?(R=t,r.charCodeAt(t)===58?(m=":",t++):(m=null,_('":"')),m!==null?(v=me(),v!==null?m=[m,v]:(m=null,t=R)):(m=null,t=R),m=m!==null?m:"",m!==null?(r.substr(t,2)==="::"?(v="::",t+=2):(v=null,_('"::"')),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k)):(i=null,t=k))))))))))))))),i!==null&&(i=function(Te){return b.host_type="IPv6",r.substring(t,Te)}(Ps)),i===null&&(t=Ps),i}function me(){var i,e,l,u,f;return f=t,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,t=f)):(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i}function oe(){var i,e,l,u;return u=t,i=me(),i!==null?(r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e!==null?(l=me(),l!==null?i=[i,e,l]:(i=null,t=u)):(i=null,t=u)):(i=null,t=u),i===null&&(i=ot()),i}function ot(){var i,e,l,u,f,p,m,v,S;return v=t,S=t,i=Gt(),i!==null?(r.charCodeAt(t)===46?(e=".",t++):(e=null,_('"."')),e!==null?(l=Gt(),l!==null?(r.charCodeAt(t)===46?(u=".",t++):(u=null,_('"."')),u!==null?(f=Gt(),f!==null?(r.charCodeAt(t)===46?(p=".",t++):(p=null,_('"."')),p!==null?(m=Gt(),m!==null?i=[i,e,l,u,f,p,m]:(i=null,t=S)):(i=null,t=S)):(i=null,t=S)):(i=null,t=S)):(i=null,t=S)):(i=null,t=S)):(i=null,t=S),i!==null&&(i=function(O){return b.host_type="IPv4",r.substring(t,O)}(v)),i===null&&(t=v),i}function Gt(){var i,e,l,u;return u=t,r.substr(t,2)==="25"?(i="25",t+=2):(i=null,_('"25"')),i!==null?(/^[0-5]/.test(r.charAt(t))?(e=r.charAt(t),t++):(e=null,_("[0-5]")),e!==null?i=[i,e]:(i=null,t=u)):(i=null,t=u),i===null&&(u=t,r.charCodeAt(t)===50?(i="2",t++):(i=null,_('"2"')),i!==null?(/^[0-4]/.test(r.charAt(t))?(e=r.charAt(t),t++):(e=null,_("[0-4]")),e!==null?(l=g(),l!==null?i=[i,e,l]:(i=null,t=u)):(i=null,t=u)):(i=null,t=u),i===null&&(u=t,r.charCodeAt(t)===49?(i="1",t++):(i=null,_('"1"')),i!==null?(e=g(),e!==null?(l=g(),l!==null?i=[i,e,l]:(i=null,t=u)):(i=null,t=u)):(i=null,t=u),i===null&&(u=t,/^[1-9]/.test(r.charAt(t))?(i=r.charAt(t),t++):(i=null,_("[1-9]")),i!==null?(e=g(),e!==null?i=[i,e]:(i=null,t=u)):(i=null,t=u),i===null&&(i=g())))),i}function ys(){var i,e,l,u,f,p,m;return p=t,m=t,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,t=m)):(i=null,t=m)):(i=null,t=m)):(i=null,t=m)):(i=null,t=m),i!==null&&(i=function(v,S){return S=parseInt(S.join("")),b.port=S,S}(p,i)),i===null&&(t=p),i}function gr(){var i,e,l,u;for(i=[],u=t,r.charCodeAt(t)===59?(e=";",t++):(e=null,_('";"')),e!==null?(l=On(),l!==null?e=[e,l]:(e=null,t=u)):(e=null,t=u);e!==null;)i.push(e),u=t,r.charCodeAt(t)===59?(e=";",t++):(e=null,_('";"')),e!==null?(l=On(),l!==null?e=[e,l]:(e=null,t=u)):(e=null,t=u);return i}function On(){var i;return i=Dn(),i===null&&(i=Tr(),i===null&&(i=vr(),i===null&&(i=Er(),i===null&&(i=Sr(),i===null&&(i=yr(),i===null&&(i=Ar())))))),i}function Dn(){var i,e,l,u;return l=t,u=t,r.substr(t,10).toLowerCase()==="transport="?(i=r.substr(t,10),t+=10):(i=null,_('"transport="')),i!==null?(r.substr(t,3).toLowerCase()==="udp"?(e=r.substr(t,3),t+=3):(e=null,_('"udp"')),e===null&&(r.substr(t,3).toLowerCase()==="tcp"?(e=r.substr(t,3),t+=3):(e=null,_('"tcp"')),e===null&&(r.substr(t,4).toLowerCase()==="sctp"?(e=r.substr(t,4),t+=4):(e=null,_('"sctp"')),e===null&&(r.substr(t,3).toLowerCase()==="tls"?(e=r.substr(t,3),t+=3):(e=null,_('"tls"')),e===null&&(e=U())))),e!==null?i=[i,e]:(i=null,t=u)):(i=null,t=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.transport=p.toLowerCase()}(l,i[1])),i===null&&(t=l),i}function Tr(){var i,e,l,u;return l=t,u=t,r.substr(t,5).toLowerCase()==="user="?(i=r.substr(t,5),t+=5):(i=null,_('"user="')),i!==null?(r.substr(t,5).toLowerCase()==="phone"?(e=r.substr(t,5),t+=5):(e=null,_('"phone"')),e===null&&(r.substr(t,2).toLowerCase()==="ip"?(e=r.substr(t,2),t+=2):(e=null,_('"ip"')),e===null&&(e=U())),e!==null?i=[i,e]:(i=null,t=u)):(i=null,t=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.user=p.toLowerCase()}(l,i[1])),i===null&&(t=l),i}function vr(){var i,e,l,u;return l=t,u=t,r.substr(t,7).toLowerCase()==="method="?(i=r.substr(t,7),t+=7):(i=null,_('"method="')),i!==null?(e=tn(),e!==null?i=[i,e]:(i=null,t=u)):(i=null,t=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.method=p}(l,i[1])),i===null&&(t=l),i}function Er(){var i,e,l,u;return l=t,u=t,r.substr(t,4).toLowerCase()==="ttl="?(i=r.substr(t,4),t+=4):(i=null,_('"ttl="')),i!==null?(e=Qn(),e!==null?i=[i,e]:(i=null,t=u)):(i=null,t=u),i!==null&&(i=function(f,p){b.params||(b.params={}),b.params.ttl=p}(l,i[1])),i===null&&(t=l),i}function Sr(){var i,e,l,u;return l=t,u=t,r.substr(t,6).toLowerCase()==="maddr="?(i=r.substr(t,6),t+=6):(i=null,_('"maddr="')),i!==null?(e=Xt(),e!==null?i=[i,e]:(i=null,t=u)):(i=null,t=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.maddr=p}(l,i[1])),i===null&&(t=l),i}function yr(){var i,e,l,u,f,p;return u=t,f=t,r.substr(t,2).toLowerCase()==="lr"?(i=r.substr(t,2),t+=2):(i=null,_('"lr"')),i!==null?(p=t,r.charCodeAt(t)===61?(e="=",t++):(e=null,_('"="')),e!==null?(l=U(),l!==null?e=[e,l]:(e=null,t=p)):(e=null,t=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(m){b.uri_params||(b.uri_params={}),b.uri_params.lr=void 0}()),i===null&&(t=u),i}function Ar(){var i,e,l,u,f,p;return u=t,f=t,i=Cr(),i!==null?(p=t,r.charCodeAt(t)===61?(e="=",t++):(e=null,_('"="')),e!==null?(l=Rr(),l!==null?e=[e,l]:(e=null,t=p)):(e=null,t=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,t=f)):(i=null,t=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&&(t=u),i}function Cr(){var i,e,l;if(l=t,e=As(),e!==null)for(i=[];e!==null;)i.push(e),e=As();else i=null;return i!==null&&(i=function(u,f){return f.join("")}(l,i)),i===null&&(t=l),i}function Rr(){var i,e,l;if(l=t,e=As(),e!==null)for(i=[];e!==null;)i.push(e),e=As();else i=null;return i!==null&&(i=function(u,f){return f.join("")}(l,i)),i===null&&(t=l),i}function As(){var i;return i=Cs(),i===null&&(i=N(),i===null&&(i=Se())),i}function Cs(){var i;return r.charCodeAt(t)===91?(i="[",t++):(i=null,_('"["')),i===null&&(r.charCodeAt(t)===93?(i="]",t++):(i=null,_('"]"')),i===null&&(r.charCodeAt(t)===47?(i="/",t++):(i=null,_('"/"')),i===null&&(r.charCodeAt(t)===58?(i=":",t++):(i=null,_('":"')),i===null&&(r.charCodeAt(t)===38?(i="&",t++):(i=null,_('"&"')),i===null&&(r.charCodeAt(t)===43?(i="+",t++):(i=null,_('"+"')),i===null&&(r.charCodeAt(t)===36?(i="$",t++):(i=null,_('"$"')))))))),i}function Ir(){var i,e,l,u,f,p,m;if(p=t,r.charCodeAt(t)===63?(i="?",t++):(i=null,_('"?"')),i!==null)if(e=Js(),e!==null){for(l=[],m=t,r.charCodeAt(t)===38?(u="&",t++):(u=null,_('"&"')),u!==null?(f=Js(),f!==null?u=[u,f]:(u=null,t=m)):(u=null,t=m);u!==null;)l.push(u),m=t,r.charCodeAt(t)===38?(u="&",t++):(u=null,_('"&"')),u!==null?(f=Js(),f!==null?u=[u,f]:(u=null,t=m)):(u=null,t=m);l!==null?i=[i,e,l]:(i=null,t=p)}else i=null,t=p;else i=null,t=p;return i}function Js(){var i,e,l,u,f;return u=t,f=t,i=zs(),i!==null?(r.charCodeAt(t)===61?(e="=",t++):(e=null,_('"="')),e!==null?(l=br(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=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&&(t=u),i}function zs(){var i,e;if(e=Rs(),e===null&&(e=N(),e===null&&(e=Se())),e!==null)for(i=[];e!==null;)i.push(e),e=Rs(),e===null&&(e=N(),e===null&&(e=Se()));else i=null;return i}function br(){var i,e;for(i=[],e=Rs(),e===null&&(e=N(),e===null&&(e=Se()));e!==null;)i.push(e),e=Rs(),e===null&&(e=N(),e===null&&(e=Se()));return i}function Rs(){var i;return r.charCodeAt(t)===91?(i="[",t++):(i=null,_('"["')),i===null&&(r.charCodeAt(t)===93?(i="]",t++):(i=null,_('"]"')),i===null&&(r.charCodeAt(t)===47?(i="/",t++):(i=null,_('"/"')),i===null&&(r.charCodeAt(t)===63?(i="?",t++):(i=null,_('"?"')),i===null&&(r.charCodeAt(t)===58?(i=":",t++):(i=null,_('":"')),i===null&&(r.charCodeAt(t)===43?(i="+",t++):(i=null,_('"+"')),i===null&&(r.charCodeAt(t)===36?(i="$",t++):(i=null,_('"$"')))))))),i}function Xs(){var i;return i=sn(),i===null&&(i=hl()),i}function hl(){var i,e,l,u,f,p;return p=t,i=tn(),i!==null?(e=I(),e!==null?(l=wr(),l!==null?(u=I(),u!==null?(f=Pn(),f!==null?i=[i,e,l,u,f]:(i=null,t=p)):(i=null,t=p)):(i=null,t=p)):(i=null,t=p)):(i=null,t=p),i}function wr(){var i;return i=we(),i===null&&(i=Nn()),i}function Nn(){var i,e,l,u;return u=t,i=Os(),i!==null?(r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e!==null?(l=Un(),l===null&&(l=Zs()),l!==null?i=[i,e,l]:(i=null,t=u)):(i=null,t=u)):(i=null,t=u),i}function Un(){var i,e,l,u,f;return u=t,i=Or(),i===null&&(i=Qs()),i!==null?(f=t,r.charCodeAt(t)===63?(e="?",t++):(e=null,_('"?"')),e!==null?(l=xr(),l!==null?e=[e,l]:(e=null,t=f)):(e=null,t=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,t=u)):(i=null,t=u),i}function Or(){var i,e,l,u;return u=t,r.substr(t,2)==="//"?(i="//",t+=2):(i=null,_('"//"')),i!==null?(e=Nr(),e!==null?(l=Qs(),l=l!==null?l:"",l!==null?i=[i,e,l]:(i=null,t=u)):(i=null,t=u)):(i=null,t=u),i}function Qs(){var i,e,l;return l=t,r.charCodeAt(t)===47?(i="/",t++):(i=null,_('"/"')),i!==null?(e=Dr(),e!==null?i=[i,e]:(i=null,t=l)):(i=null,t=l),i}function Zs(){var i,e,l,u;if(u=t,i=bs(),i!==null){for(e=[],l=Is();l!==null;)e.push(l),l=Is();e!==null?i=[i,e]:(i=null,t=u)}else i=null,t=u;return i}function Is(){var i;return i=ae(),i===null&&(i=N(),i===null&&(i=Se())),i}function bs(){var i;return i=N(),i===null&&(i=Se(),i===null&&(r.charCodeAt(t)===59?(i=";",t++):(i=null,_('";"')),i===null&&(r.charCodeAt(t)===63?(i="?",t++):(i=null,_('"?"')),i===null&&(r.charCodeAt(t)===58?(i=":",t++):(i=null,_('":"')),i===null&&(r.charCodeAt(t)===64?(i="@",t++):(i=null,_('"@"')),i===null&&(r.charCodeAt(t)===38?(i="&",t++):(i=null,_('"&"')),i===null&&(r.charCodeAt(t)===61?(i="=",t++):(i=null,_('"="')),i===null&&(r.charCodeAt(t)===43?(i="+",t++):(i=null,_('"+"')),i===null&&(r.charCodeAt(t)===36?(i="$",t++):(i=null,_('"$"')),i===null&&(r.charCodeAt(t)===44?(i=",",t++):(i=null,_('","')))))))))))),i}function Dr(){var i,e,l,u,f,p;if(f=t,i=en(),i!==null){for(e=[],p=t,r.charCodeAt(t)===47?(l="/",t++):(l=null,_('"/"')),l!==null?(u=en(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);l!==null;)e.push(l),p=t,r.charCodeAt(t)===47?(l="/",t++):(l=null,_('"/"')),l!==null?(u=en(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);e!==null?i=[i,e]:(i=null,t=f)}else i=null,t=f;return i}function en(){var i,e,l,u,f,p;for(f=t,i=[],e=as();e!==null;)i.push(e),e=as();if(i!==null){for(e=[],p=t,r.charCodeAt(t)===59?(l=";",t++):(l=null,_('";"')),l!==null?(u=ws(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);l!==null;)e.push(l),p=t,r.charCodeAt(t)===59?(l=";",t++):(l=null,_('";"')),l!==null?(u=ws(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);e!==null?i=[i,e]:(i=null,t=f)}else i=null,t=f;return i}function ws(){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&&(r.charCodeAt(t)===58?(i=":",t++):(i=null,_('":"')),i===null&&(r.charCodeAt(t)===64?(i="@",t++):(i=null,_('"@"')),i===null&&(r.charCodeAt(t)===38?(i="&",t++):(i=null,_('"&"')),i===null&&(r.charCodeAt(t)===61?(i="=",t++):(i=null,_('"="')),i===null&&(r.charCodeAt(t)===43?(i="+",t++):(i=null,_('"+"')),i===null&&(r.charCodeAt(t)===36?(i="$",t++):(i=null,_('"$"')),i===null&&(r.charCodeAt(t)===44?(i=",",t++):(i=null,_('","')))))))))),i}function Os(){var i,e,l,u,f;if(u=t,f=t,i=T(),i!==null){for(e=[],l=T(),l===null&&(l=g(),l===null&&(r.charCodeAt(t)===43?(l="+",t++):(l=null,_('"+"')),l===null&&(r.charCodeAt(t)===45?(l="-",t++):(l=null,_('"-"')),l===null&&(r.charCodeAt(t)===46?(l=".",t++):(l=null,_('"."'))))));l!==null;)e.push(l),l=T(),l===null&&(l=g(),l===null&&(r.charCodeAt(t)===43?(l="+",t++):(l=null,_('"+"')),l===null&&(r.charCodeAt(t)===45?(l="-",t++):(l=null,_('"-"')),l===null&&(r.charCodeAt(t)===46?(l=".",t++):(l=null,_('"."'))))));e!==null?i=[i,e]:(i=null,t=f)}else i=null,t=f;return i!==null&&(i=function(p){b.scheme=r.substring(t,p)}(u)),i===null&&(t=u),i}function Nr(){var i;return i=Ur(),i===null&&(i=Pr()),i}function Ur(){var i,e,l,u;return l=t,u=t,i=kt(),i!==null?(r.charCodeAt(t)===64?(e="@",t++):(e=null,_('"@"')),e!==null?i=[i,e]:(i=null,t=u)):(i=null,t=u),i=i!==null?i:"",i!==null?(e=Ws(),e!==null?i=[i,e]:(i=null,t=l)):(i=null,t=l),i=i!==null?i:"",i}function Pr(){var i,e;if(e=N(),e===null&&(e=Se(),e===null&&(r.charCodeAt(t)===36?(e="$",t++):(e=null,_('"$"')),e===null&&(r.charCodeAt(t)===44?(e=",",t++):(e=null,_('","')),e===null&&(r.charCodeAt(t)===59?(e=";",t++):(e=null,_('";"')),e===null&&(r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e===null&&(r.charCodeAt(t)===64?(e="@",t++):(e=null,_('"@"')),e===null&&(r.charCodeAt(t)===38?(e="&",t++):(e=null,_('"&"')),e===null&&(r.charCodeAt(t)===61?(e="=",t++):(e=null,_('"="')),e===null&&(r.charCodeAt(t)===43?(e="+",t++):(e=null,_('"+"'))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(r.charCodeAt(t)===36?(e="$",t++):(e=null,_('"$"')),e===null&&(r.charCodeAt(t)===44?(e=",",t++):(e=null,_('","')),e===null&&(r.charCodeAt(t)===59?(e=";",t++):(e=null,_('";"')),e===null&&(r.charCodeAt(t)===58?(e=":",t++):(e=null,_('":"')),e===null&&(r.charCodeAt(t)===64?(e="@",t++):(e=null,_('"@"')),e===null&&(r.charCodeAt(t)===38?(e="&",t++):(e=null,_('"&"')),e===null&&(r.charCodeAt(t)===61?(e="=",t++):(e=null,_('"="')),e===null&&(r.charCodeAt(t)===43?(e="+",t++):(e=null,_('"+"')))))))))));else i=null;return i}function xr(){var i,e;for(i=[],e=Is();e!==null;)i.push(e),e=Is();return i}function Pn(){var i,e,l,u,f,p,m,v;if(m=t,v=t,r.substr(t,3).toLowerCase()==="sip"?(i=r.substr(t,3),t+=3):(i=null,_('"SIP"')),i!==null)if(r.charCodeAt(t)===47?(e="/",t++):(e=null,_('"/"')),e!==null){if(u=g(),u!==null)for(l=[];u!==null;)l.push(u),u=g();else l=null;if(l!==null)if(r.charCodeAt(t)===46?(u=".",t++):(u=null,_('"."')),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,t=v)}else i=null,t=v;else i=null,t=v}else i=null,t=v;else i=null,t=v;return i!==null&&(i=function(S){b.sip_version=r.substring(t,S)}(m)),i===null&&(t=m),i}function xn(){var i;return r.substr(t,6)==="INVITE"?(i="INVITE",t+=6):(i=null,_('"INVITE"')),i}function Mr(){var i;return r.substr(t,3)==="ACK"?(i="ACK",t+=3):(i=null,_('"ACK"')),i}function kr(){var i;return r.substr(t,7)==="OPTIONS"?(i="OPTIONS",t+=7):(i=null,_('"OPTIONS"')),i}function Lr(){var i;return r.substr(t,3)==="BYE"?(i="BYE",t+=3):(i=null,_('"BYE"')),i}function $r(){var i;return r.substr(t,6)==="CANCEL"?(i="CANCEL",t+=6):(i=null,_('"CANCEL"')),i}function Hr(){var i;return r.substr(t,8)==="REGISTER"?(i="REGISTER",t+=8):(i=null,_('"REGISTER"')),i}function Fr(){var i;return r.substr(t,9)==="SUBSCRIBE"?(i="SUBSCRIBE",t+=9):(i=null,_('"SUBSCRIBE"')),i}function jr(){var i;return r.substr(t,6)==="NOTIFY"?(i="NOTIFY",t+=6):(i=null,_('"NOTIFY"')),i}function qr(){var i;return r.substr(t,5)==="REFER"?(i="REFER",t+=5):(i=null,_('"REFER"')),i}function tn(){var i,e;return e=t,i=xn(),i===null&&(i=Mr(),i===null&&(i=kr(),i===null&&(i=Lr(),i===null&&(i=$r(),i===null&&(i=Hr(),i===null&&(i=Fr(),i===null&&(i=jr(),i===null&&(i=qr(),i===null&&(i=U()))))))))),i!==null&&(i=function(l){return b.method=r.substring(t,l),b.method}(e)),i===null&&(t=e),i}function sn(){var i,e,l,u,f,p;return p=t,i=Pn(),i!==null?(e=I(),e!==null?(l=Vr(),l!==null?(u=I(),u!==null?(f=Gr(),f!==null?i=[i,e,l,u,f]:(i=null,t=p)):(i=null,t=p)):(i=null,t=p)):(i=null,t=p)):(i=null,t=p),i}function Vr(){var i,e;return e=t,i=Br(),i!==null&&(i=function(l,u){b.status_code=parseInt(u.join(""))}(e,i)),i===null&&(t=e),i}function Br(){var i,e,l,u;return u=t,i=g(),i!==null?(e=g(),e!==null?(l=g(),l!==null?i=[i,e,l]:(i=null,t=u)):(i=null,t=u)):(i=null,t=u),i}function Gr(){var i,e,l;for(l=t,i=[],e=ae(),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=ae(),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=r.substring(t,u)}(l)),i===null&&(t=l),i}function dl(){var i,e,l,u,f,p;if(f=t,i=ln(),i!==null){for(e=[],p=t,l=Ce(),l!==null?(u=ln(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);l!==null;)e.push(l),p=t,l=Ce(),l!==null?(u=ln(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);e!==null?i=[i,e]:(i=null,t=f)}else i=null,t=f;return i}function Go(){var i,e,l,u,f,p;return u=t,f=t,i=tt(),i!==null?(p=t,r.charCodeAt(t)===64?(e="@",t++):(e=null,_('"@"')),e!==null?(l=tt(),l!==null?e=[e,l]:(e=null,t=p)):(e=null,t=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(m){b=r.substring(t,m)}(u)),i===null&&(t=u),i}function Wo(){var i,e,l,u,f,p,m;if(f=t,i=ee(),i===null)if(p=t,i=Mn(),i!==null){for(e=[],m=t,l=Ce(),l!==null?(u=Mn(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);l!==null;)e.push(l),m=t,l=Ce(),l!==null?(u=Mn(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);e!==null?i=[i,e]:(i=null,t=p)}else i=null,t=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&&(t=f),i}function Mn(){var i,e,l,u,f,p,m;if(f=t,p=t,i=de(),i===null&&(i=Lt()),i!==null){for(e=[],m=t,l=le(),l!==null?(u=Ds(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);l!==null;)e.push(l),m=t,l=le(),l!==null?(u=Ds(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);e!==null?i=[i,e]:(i=null,t=p)}else i=null,t=p;return i!==null&&(i=function(v){var S;b.multi_header||(b.multi_header=[]);try{S=new us(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:t,offset:v,parsed:S})}(f)),i===null&&(t=f),i}function Lt(){var i,e,l,u,f;return f=t,i=$t(),i=i!==null?i:"",i!==null?(e=xe(),e!==null?(l=we(),l!==null?(u=be(),u!==null?i=[i,e,l,u]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i}function $t(){var i,e,l,u,f,p,m;if(f=t,p=t,i=U(),i!==null){for(e=[],m=t,l=ve(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);l!==null;)e.push(l),m=t,l=ve(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);e!==null?i=[i,e]:(i=null,t=p)}else i=null,t=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&&(t=f),i}function Ds(){var i;return i=kn(),i===null&&(i=Wr(),i===null&&(i=Ge())),i}function kn(){var i,e,l,u,f;return u=t,f=t,r.substr(t,1).toLowerCase()==="q"?(i=r.substr(t,1),t++):(i=null,_('"q"')),i!==null?(e=G(),e!==null?(l=Zt(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p,m){b.params||(b.params={}),b.params.q=m}(u,i[2])),i===null&&(t=u),i}function Wr(){var i,e,l,u,f;return u=t,f=t,r.substr(t,7).toLowerCase()==="expires"?(i=r.substr(t,7),t+=7):(i=null,_('"expires"')),i!==null?(e=G(),e!==null?(l=Qt(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p,m){b.params||(b.params={}),b.params.expires=m}(u,i[2])),i===null&&(t=u),i}function Qt(){var i,e,l;if(l=t,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&&(t=l),i}function Zt(){var i,e,l,u,f,p,m,v;return p=t,m=t,r.charCodeAt(t)===48?(i="0",t++):(i=null,_('"0"')),i!==null?(v=t,r.charCodeAt(t)===46?(e=".",t++):(e=null,_('"."')),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,t=v)):(e=null,t=v)):(e=null,t=v)):(e=null,t=v),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,t=m)):(i=null,t=m),i!==null&&(i=function(S){return parseFloat(r.substring(t,S))}(p)),i===null&&(t=p),i}function Ge(){var i,e,l,u,f,p;return u=t,f=t,i=U(),i!==null?(p=t,e=G(),e!==null?(l=We(),l!==null?e=[e,l]:(e=null,t=p)):(e=null,t=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,t=f)):(i=null,t=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&&(t=u),i}function We(){var i;return i=U(),i===null&&(i=Xt(),i===null&&(i=Ie())),i}function pl(){var i,e,l,u,f,p;if(f=t,i=ml(),i!==null){for(e=[],p=t,l=le(),l!==null?(u=Ln(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);l!==null;)e.push(l),p=t,l=le(),l!==null?(u=Ln(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);e!==null?i=[i,e]:(i=null,t=f)}else i=null,t=f;return i}function ml(){var i;return r.substr(t,6).toLowerCase()==="render"?(i=r.substr(t,6),t+=6):(i=null,_('"render"')),i===null&&(r.substr(t,7).toLowerCase()==="session"?(i=r.substr(t,7),t+=7):(i=null,_('"session"')),i===null&&(r.substr(t,4).toLowerCase()==="icon"?(i=r.substr(t,4),t+=4):(i=null,_('"icon"')),i===null&&(r.substr(t,5).toLowerCase()==="alert"?(i=r.substr(t,5),t+=5):(i=null,_('"alert"')),i===null&&(i=U())))),i}function Ln(){var i;return i=$n(),i===null&&(i=Ge()),i}function $n(){var i,e,l,u;return u=t,r.substr(t,8).toLowerCase()==="handling"?(i=r.substr(t,8),t+=8):(i=null,_('"handling"')),i!==null?(e=G(),e!==null?(r.substr(t,8).toLowerCase()==="optional"?(l=r.substr(t,8),t+=8):(l=null,_('"optional"')),l===null&&(r.substr(t,8).toLowerCase()==="required"?(l=r.substr(t,8),t+=8):(l=null,_('"required"')),l===null&&(l=U())),l!==null?i=[i,e,l]:(i=null,t=u)):(i=null,t=u)):(i=null,t=u),i}function gl(){var i,e,l,u,f,p;if(f=t,i=U(),i!==null){for(e=[],p=t,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);l!==null;)e.push(l),p=t,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);e!==null?i=[i,e]:(i=null,t=f)}else i=null,t=f;return i}function Ko(){var i,e,l;if(l=t,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&&(t=l),i}function Yo(){var i,e;return e=t,i=Tl(),i!==null&&(i=function(l){b=r.substring(t,l)}(e)),i===null&&(t=e),i}function Tl(){var i,e,l,u,f,p,m,v;if(m=t,i=Kr(),i!==null)if(e=W(),e!==null)if(l=zr(),l!==null){for(u=[],v=t,f=le(),f!==null?(p=Hn(),p!==null?f=[f,p]:(f=null,t=v)):(f=null,t=v);f!==null;)u.push(f),v=t,f=le(),f!==null?(p=Hn(),p!==null?f=[f,p]:(f=null,t=v)):(f=null,t=v);u!==null?i=[i,e,l,u]:(i=null,t=m)}else i=null,t=m;else i=null,t=m;else i=null,t=m;return i}function Kr(){var i;return i=Yr(),i===null&&(i=Jr()),i}function Yr(){var i;return r.substr(t,4).toLowerCase()==="text"?(i=r.substr(t,4),t+=4):(i=null,_('"text"')),i===null&&(r.substr(t,5).toLowerCase()==="image"?(i=r.substr(t,5),t+=5):(i=null,_('"image"')),i===null&&(r.substr(t,5).toLowerCase()==="audio"?(i=r.substr(t,5),t+=5):(i=null,_('"audio"')),i===null&&(r.substr(t,5).toLowerCase()==="video"?(i=r.substr(t,5),t+=5):(i=null,_('"video"')),i===null&&(r.substr(t,11).toLowerCase()==="application"?(i=r.substr(t,11),t+=11):(i=null,_('"application"')),i===null&&(i=nn()))))),i}function Jr(){var i;return r.substr(t,7).toLowerCase()==="message"?(i=r.substr(t,7),t+=7):(i=null,_('"message"')),i===null&&(r.substr(t,9).toLowerCase()==="multipart"?(i=r.substr(t,9),t+=9):(i=null,_('"multipart"')),i===null&&(i=nn())),i}function nn(){var i;return i=U(),i===null&&(i=rn()),i}function rn(){var i,e,l;return l=t,r.substr(t,2).toLowerCase()==="x-"?(i=r.substr(t,2),t+=2):(i=null,_('"x-"')),i!==null?(e=U(),e!==null?i=[i,e]:(i=null,t=l)):(i=null,t=l),i}function zr(){var i;return i=nn(),i===null&&(i=U()),i}function Hn(){var i,e,l,u;return u=t,i=U(),i!==null?(e=G(),e!==null?(l=Fn(),l!==null?i=[i,e,l]:(i=null,t=u)):(i=null,t=u)):(i=null,t=u),i}function Fn(){var i;return i=U(),i===null&&(i=Ie()),i}function vl(){var i,e,l,u;return u=t,i=El(),i!==null?(e=ve(),e!==null?(l=tn(),l!==null?i=[i,e,l]:(i=null,t=u)):(i=null,t=u)):(i=null,t=u),i}function El(){var i,e,l;if(l=t,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&&(t=l),i}function Sl(){var i,e;return e=t,i=Qt(),i!==null&&(i=function(l,u){b=u}(e,i)),i===null&&(t=e),i}function Jo(){var i,e,l,u,f,p,m;if(f=t,p=t,i=ln(),i!==null){for(e=[],m=t,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);l!==null;)e.push(l),m=t,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);e!==null?i=[i,e]:(i=null,t=p)}else i=null,t=p;return i!==null&&(i=function(v,S){b.event=S.join("").toLowerCase()}(f,i[0])),i===null&&(t=f),i}function ln(){var i,e,l,u,f,p;if(f=t,i=P(),i!==null){for(e=[],p=t,r.charCodeAt(t)===46?(l=".",t++):(l=null,_('"."')),l!==null?(u=P(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);l!==null;)e.push(l),p=t,r.charCodeAt(t)===46?(l=".",t++):(l=null,_('"."')),l!==null?(u=P(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);e!==null?i=[i,e]:(i=null,t=f)}else i=null,t=f;return i}function on(){var i,e,l,u,f,p,m;if(f=t,p=t,i=de(),i===null&&(i=Lt()),i!==null){for(e=[],m=t,l=le(),l!==null?(u=Xr(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);l!==null;)e.push(l),m=t,l=le(),l!==null?(u=Xr(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);e!==null?i=[i,e]:(i=null,t=p)}else i=null,t=p;return i!==null&&(i=function(v){var S=b.tag;try{b=new us(b.uri,b.display_name,b.params),S&&b.setParam("tag",S)}catch{b=-1}}()),i===null&&(t=f),i}function Xr(){var i;return i=an(),i===null&&(i=Ge()),i}function an(){var i,e,l,u,f;return u=t,f=t,r.substr(t,3).toLowerCase()==="tag"?(i=r.substr(t,3),t+=3):(i=null,_('"tag"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p,m){b.tag=m}(u,i[2])),i===null&&(t=u),i}function Qr(){var i,e,l;if(l=t,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&&(t=l),i}function zo(){var i,e;return e=t,i=Qt(),i!==null&&(i=function(l,u){b=u}(e,i)),i===null&&(t=e),i}function Xo(){var i,e,l,u,f,p,m,v,S,O;for(v=t,S=t,i=[],e=$t();e!==null;)i.push(e),e=$t();if(i!==null)if(e=xe(),e!==null)if(l=we(),l!==null)if(u=be(),u!==null){for(f=[],O=t,p=le(),p!==null?(m=Ge(),m!==null?p=[p,m]:(p=null,t=O)):(p=null,t=O);p!==null;)f.push(p),O=t,p=le(),p!==null?(m=Ge(),m!==null?p=[p,m]:(p=null,t=O)):(p=null,t=O);f!==null?i=[i,e,l,u,f]:(i=null,t=S)}else i=null,t=S;else i=null,t=S;else i=null,t=S;else i=null,t=S;return i!==null&&(i=function(ie){try{b=new us(b.uri,b.display_name,b.params)}catch{b=-1}}()),i===null&&(t=v),i}function Qo(){var i;return i=Zr(),i}function Zr(){var i,e,l,u,f,p,m,v;if(m=t,r.substr(t,6).toLowerCase()==="digest"?(i=r.substr(t,6),t+=6):(i=null,_('"Digest"')),i!==null)if(e=ve(),e!==null)if(l=es(),l!==null){for(u=[],v=t,f=Ce(),f!==null?(p=es(),p!==null?f=[f,p]:(f=null,t=v)):(f=null,t=v);f!==null;)u.push(f),v=t,f=Ce(),f!==null?(p=es(),p!==null?f=[f,p]:(f=null,t=v)):(f=null,t=v);u!==null?i=[i,e,l,u]:(i=null,t=m)}else i=null,t=m;else i=null,t=m;else i=null,t=m;return i===null&&(i=jn()),i}function jn(){var i,e,l,u,f,p,m,v;if(m=t,i=U(),i!==null)if(e=ve(),e!==null)if(l=Ns(),l!==null){for(u=[],v=t,f=Ce(),f!==null?(p=Ns(),p!==null?f=[f,p]:(f=null,t=v)):(f=null,t=v);f!==null;)u.push(f),v=t,f=Ce(),f!==null?(p=Ns(),p!==null?f=[f,p]:(f=null,t=v)):(f=null,t=v);u!==null?i=[i,e,l,u]:(i=null,t=m)}else i=null,t=m;else i=null,t=m;else i=null,t=m;return i}function Ns(){var i,e,l,u;return u=t,i=U(),i!==null?(e=G(),e!==null?(l=U(),l===null&&(l=Ie()),l!==null?i=[i,e,l]:(i=null,t=u)):(i=null,t=u)):(i=null,t=u),i}function es(){var i;return i=un(),i===null&&(i=ti(),i===null&&(i=fn(),i===null&&(i=ni(),i===null&&(i=ri(),i===null&&(i=ii(),i===null&&(i=li(),i===null&&(i=Ns()))))))),i}function un(){var i,e,l,u;return u=t,r.substr(t,5).toLowerCase()==="realm"?(i=r.substr(t,5),t+=5):(i=null,_('"realm"')),i!==null?(e=G(),e!==null?(l=ei(),l!==null?i=[i,e,l]:(i=null,t=u)):(i=null,t=u)):(i=null,t=u),i}function ei(){var i,e;return e=t,i=Oe(),i!==null&&(i=function(l,u){b.realm=u}(e,i)),i===null&&(t=e),i}function ti(){var i,e,l,u,f,p,m,v,S;if(v=t,r.substr(t,6).toLowerCase()==="domain"?(i=r.substr(t,6),t+=6):(i=null,_('"domain"')),i!==null)if(e=G(),e!==null)if(l=st(),l!==null)if(u=cn(),u!==null){if(f=[],S=t,m=I(),m!==null)for(p=[];m!==null;)p.push(m),m=I();else p=null;for(p!==null?(m=cn(),m!==null?p=[p,m]:(p=null,t=S)):(p=null,t=S);p!==null;){if(f.push(p),S=t,m=I(),m!==null)for(p=[];m!==null;)p.push(m),m=I();else p=null;p!==null?(m=cn(),m!==null?p=[p,m]:(p=null,t=S)):(p=null,t=S)}f!==null?(p=lt(),p!==null?i=[i,e,l,u,f,p]:(i=null,t=v)):(i=null,t=v)}else i=null,t=v;else i=null,t=v;else i=null,t=v;else i=null,t=v;return i}function cn(){var i;return i=Nn(),i===null&&(i=Qs()),i}function fn(){var i,e,l,u;return u=t,r.substr(t,5).toLowerCase()==="nonce"?(i=r.substr(t,5),t+=5):(i=null,_('"nonce"')),i!==null?(e=G(),e!==null?(l=si(),l!==null?i=[i,e,l]:(i=null,t=u)):(i=null,t=u)):(i=null,t=u),i}function si(){var i,e;return e=t,i=Oe(),i!==null&&(i=function(l,u){b.nonce=u}(e,i)),i===null&&(t=e),i}function ni(){var i,e,l,u,f;return u=t,f=t,r.substr(t,6).toLowerCase()==="opaque"?(i=r.substr(t,6),t+=6):(i=null,_('"opaque"')),i!==null?(e=G(),e!==null?(l=Oe(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p,m){b.opaque=m}(u,i[2])),i===null&&(t=u),i}function ri(){var i,e,l,u,f;return u=t,r.substr(t,5).toLowerCase()==="stale"?(i=r.substr(t,5),t+=5):(i=null,_('"stale"')),i!==null?(e=G(),e!==null?(f=t,r.substr(t,4).toLowerCase()==="true"?(l=r.substr(t,4),t+=4):(l=null,_('"true"')),l!==null&&(l=function(p){b.stale=!0}()),l===null&&(t=f),l===null&&(f=t,r.substr(t,5).toLowerCase()==="false"?(l=r.substr(t,5),t+=5):(l=null,_('"false"')),l!==null&&(l=function(p){b.stale=!1}()),l===null&&(t=f)),l!==null?i=[i,e,l]:(i=null,t=u)):(i=null,t=u)):(i=null,t=u),i}function ii(){var i,e,l,u,f;return u=t,f=t,r.substr(t,9).toLowerCase()==="algorithm"?(i=r.substr(t,9),t+=9):(i=null,_('"algorithm"')),i!==null?(e=G(),e!==null?(r.substr(t,3).toLowerCase()==="md5"?(l=r.substr(t,3),t+=3):(l=null,_('"MD5"')),l===null&&(r.substr(t,8).toLowerCase()==="md5-sess"?(l=r.substr(t,8),t+=8):(l=null,_('"MD5-sess"')),l===null&&(l=U())),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p,m){b.algorithm=m.toUpperCase()}(u,i[2])),i===null&&(t=u),i}function li(){var i,e,l,u,f,p,m,v,S,O;if(v=t,r.substr(t,3).toLowerCase()==="qop"?(i=r.substr(t,3),t+=3):(i=null,_('"qop"')),i!==null)if(e=G(),e!==null)if(l=st(),l!==null){if(S=t,u=_n(),u!==null){for(f=[],O=t,r.charCodeAt(t)===44?(p=",",t++):(p=null,_('","')),p!==null?(m=_n(),m!==null?p=[p,m]:(p=null,t=O)):(p=null,t=O);p!==null;)f.push(p),O=t,r.charCodeAt(t)===44?(p=",",t++):(p=null,_('","')),p!==null?(m=_n(),m!==null?p=[p,m]:(p=null,t=O)):(p=null,t=O);f!==null?u=[u,f]:(u=null,t=S)}else u=null,t=S;u!==null?(f=lt(),f!==null?i=[i,e,l,u,f]:(i=null,t=v)):(i=null,t=v)}else i=null,t=v;else i=null,t=v;else i=null,t=v;return i}function _n(){var i,e;return e=t,r.substr(t,8).toLowerCase()==="auth-int"?(i=r.substr(t,8),t+=8):(i=null,_('"auth-int"')),i===null&&(r.substr(t,4).toLowerCase()==="auth"?(i=r.substr(t,4),t+=4):(i=null,_('"auth"')),i===null&&(i=U())),i!==null&&(i=function(l,u){b.qop||(b.qop=[]),b.qop.push(u.toLowerCase())}(e,i)),i===null&&(t=e),i}function qn(){var i,e,l,u,f,p;if(f=t,i=U(),i!==null){for(e=[],p=t,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);l!==null;)e.push(l),p=t,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);e!==null?i=[i,e]:(i=null,t=f)}else i=null,t=f;return i}function Zo(){var i,e,l,u,f,p,m;if(f=t,p=t,i=Vn(),i!==null){for(e=[],m=t,l=Ce(),l!==null?(u=Vn(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);l!==null;)e.push(l),m=t,l=Ce(),l!==null?(u=Vn(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);e!==null?i=[i,e]:(i=null,t=p)}else i=null,t=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&&(t=f),i}function Vn(){var i,e,l,u,f,p,m;if(f=t,p=t,i=Lt(),i!==null){for(e=[],m=t,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);l!==null;)e.push(l),m=t,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);e!==null?i=[i,e]:(i=null,t=p)}else i=null,t=p;return i!==null&&(i=function(v){var S;b.multi_header||(b.multi_header=[]);try{S=new us(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:t,offset:v,parsed:S})}(f)),i===null&&(t=f),i}function Bn(){var i,e,l,u,f,p,m;if(f=t,p=t,r.substr(t,3).toLowerCase()==="sip"?(i=r.substr(t,3),t+=3):(i=null,_('"SIP"')),i===null&&(i=U()),i!==null){for(e=[],m=t,l=le(),l!==null?(u=oi(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);l!==null;)e.push(l),m=t,l=le(),l!==null?(u=oi(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);e!==null?i=[i,e]:(i=null,t=p)}else i=null,t=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&&(t=f),i}function oi(){var i;return i=Gn(),i===null&&(i=Ge()),i}function Gn(){var i,e,l,u,f,p;if(f=t,p=t,r.substr(t,5).toLowerCase()==="cause"?(i=r.substr(t,5),t+=5):(i=null,_('"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,t=p)}else i=null,t=p;else i=null,t=p;return i!==null&&(i=function(m,v){b.cause=parseInt(v.join(""))}(f,i[2])),i===null&&(t=f),i}function yl(){var i,e,l,u,f,p;if(f=t,i=U(),i!==null){for(e=[],p=t,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);l!==null;)e.push(l),p=t,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);e!==null?i=[i,e]:(i=null,t=f)}else i=null,t=f;return i}function ea(){var i,e,l,u,f,p;if(f=t,i=Wn(),i!==null){for(e=[],p=t,l=Ce(),l!==null?(u=Wn(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);l!==null;)e.push(l),p=t,l=Ce(),l!==null?(u=Wn(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);e!==null?i=[i,e]:(i=null,t=f)}else i=null,t=f;return i}function Wn(){var i,e,l,u,f,p;if(f=t,i=Lt(),i!==null){for(e=[],p=t,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);l!==null;)e.push(l),p=t,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);e!==null?i=[i,e]:(i=null,t=f)}else i=null,t=f;return i}function Kn(){var i,e,l,u,f,p;if(f=t,i=Al(),i!==null){for(e=[],p=t,l=le(),l!==null?(u=Yn(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);l!==null;)e.push(l),p=t,l=le(),l!==null?(u=Yn(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);e!==null?i=[i,e]:(i=null,t=f)}else i=null,t=f;return i}function Al(){var i,e;return e=t,r.substr(t,6).toLowerCase()==="active"?(i=r.substr(t,6),t+=6):(i=null,_('"active"')),i===null&&(r.substr(t,7).toLowerCase()==="pending"?(i=r.substr(t,7),t+=7):(i=null,_('"pending"')),i===null&&(r.substr(t,10).toLowerCase()==="terminated"?(i=r.substr(t,10),t+=10):(i=null,_('"terminated"')),i===null&&(i=U()))),i!==null&&(i=function(l){b.state=r.substring(t,l)}(e)),i===null&&(t=e),i}function Yn(){var i,e,l,u,f;return u=t,f=t,r.substr(t,6).toLowerCase()==="reason"?(i=r.substr(t,6),t+=6):(i=null,_('"reason"')),i!==null?(e=G(),e!==null?(l=Jn(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p,m){typeof m<"u"&&(b.reason=m)}(u,i[2])),i===null&&(t=u),i===null&&(u=t,f=t,r.substr(t,7).toLowerCase()==="expires"?(i=r.substr(t,7),t+=7):(i=null,_('"expires"')),i!==null?(e=G(),e!==null?(l=Qt(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p,m){typeof m<"u"&&(b.expires=m)}(u,i[2])),i===null&&(t=u),i===null&&(u=t,f=t,r.substr(t,11).toLowerCase()==="retry_after"?(i=r.substr(t,11),t+=11):(i=null,_('"retry_after"')),i!==null?(e=G(),e!==null?(l=Qt(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p,m){typeof m<"u"&&(b.retry_after=m)}(u,i[2])),i===null&&(t=u),i===null&&(i=Ge()))),i}function Jn(){var i;return r.substr(t,11).toLowerCase()==="deactivated"?(i=r.substr(t,11),t+=11):(i=null,_('"deactivated"')),i===null&&(r.substr(t,9).toLowerCase()==="probation"?(i=r.substr(t,9),t+=9):(i=null,_('"probation"')),i===null&&(r.substr(t,8).toLowerCase()==="rejected"?(i=r.substr(t,8),t+=8):(i=null,_('"rejected"')),i===null&&(r.substr(t,7).toLowerCase()==="timeout"?(i=r.substr(t,7),t+=7):(i=null,_('"timeout"')),i===null&&(r.substr(t,6).toLowerCase()==="giveup"?(i=r.substr(t,6),t+=6):(i=null,_('"giveup"')),i===null&&(r.substr(t,10).toLowerCase()==="noresource"?(i=r.substr(t,10),t+=10):(i=null,_('"noresource"')),i===null&&(r.substr(t,9).toLowerCase()==="invariant"?(i=r.substr(t,9),t+=9):(i=null,_('"invariant"')),i===null&&(i=U()))))))),i}function Cl(){var i;return i=B(),i=i!==null?i:"",i}function ta(){var i,e,l,u,f,p;if(f=t,i=U(),i!==null){for(e=[],p=t,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);l!==null;)e.push(l),p=t,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);e!==null?i=[i,e]:(i=null,t=f)}else i=null,t=f;return i=i!==null?i:"",i}function sa(){var i,e,l,u,f,p,m;if(f=t,p=t,i=de(),i===null&&(i=Lt()),i!==null){for(e=[],m=t,l=le(),l!==null?(u=ai(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);l!==null;)e.push(l),m=t,l=le(),l!==null?(u=ai(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);e!==null?i=[i,e]:(i=null,t=p)}else i=null,t=p;return i!==null&&(i=function(v){var S=b.tag;try{b=new us(b.uri,b.display_name,b.params),S&&b.setParam("tag",S)}catch{b=-1}}()),i===null&&(t=f),i}function ai(){var i;return i=an(),i===null&&(i=Ge()),i}function ui(){var i,e,l,u,f,p;if(f=t,i=zn(),i!==null){for(e=[],p=t,l=Ce(),l!==null?(u=zn(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);l!==null;)e.push(l),p=t,l=Ce(),l!==null?(u=zn(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);e!==null?i=[i,e]:(i=null,t=f)}else i=null,t=f;return i}function zn(){var i,e,l,u,f,p,m,v;if(m=t,i=pi(),i!==null)if(e=ve(),e!==null)if(l=Ti(),l!==null){for(u=[],v=t,f=le(),f!==null?(p=Us(),p!==null?f=[f,p]:(f=null,t=v)):(f=null,t=v);f!==null;)u.push(f),v=t,f=le(),f!==null?(p=Us(),p!==null?f=[f,p]:(f=null,t=v)):(f=null,t=v);u!==null?i=[i,e,l,u]:(i=null,t=m)}else i=null,t=m;else i=null,t=m;else i=null,t=m;return i}function Us(){var i;return i=Xn(),i===null&&(i=ci(),i===null&&(i=fi(),i===null&&(i=_i(),i===null&&(i=hi(),i===null&&(i=Ge()))))),i}function Xn(){var i,e,l,u,f;return u=t,f=t,r.substr(t,3).toLowerCase()==="ttl"?(i=r.substr(t,3),t+=3):(i=null,_('"ttl"')),i!==null?(e=G(),e!==null?(l=Qn(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p,m){b.ttl=m}(u,i[2])),i===null&&(t=u),i}function ci(){var i,e,l,u,f;return u=t,f=t,r.substr(t,5).toLowerCase()==="maddr"?(i=r.substr(t,5),t+=5):(i=null,_('"maddr"')),i!==null?(e=G(),e!==null?(l=Xt(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p,m){b.maddr=m}(u,i[2])),i===null&&(t=u),i}function fi(){var i,e,l,u,f;return u=t,f=t,r.substr(t,8).toLowerCase()==="received"?(i=r.substr(t,8),t+=8):(i=null,_('"received"')),i!==null?(e=G(),e!==null?(l=ot(),l===null&&(l=Ys()),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p,m){b.received=m}(u,i[2])),i===null&&(t=u),i}function _i(){var i,e,l,u,f;return u=t,f=t,r.substr(t,6).toLowerCase()==="branch"?(i=r.substr(t,6),t+=6):(i=null,_('"branch"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p,m){b.branch=m}(u,i[2])),i===null&&(t=u),i}function hi(){var i,e,l,u,f;return u=t,r.substr(t,5).toLowerCase()==="rport"?(i=r.substr(t,5),t+=5):(i=null,_('"rport"')),i!==null?(f=t,e=G(),e!==null?(l=di(),l!==null?e=[e,l]:(e=null,t=f)):(e=null,t=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,t=u)):(i=null,t=u),i}function di(){var i,e,l,u,f,p,m;return p=t,m=t,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,t=m)):(i=null,t=m)):(i=null,t=m)):(i=null,t=m)):(i=null,t=m),i!==null&&(i=function(v,S){b.rport=parseInt(S.join(""))}(p,i)),i===null&&(t=p),i}function pi(){var i,e,l,u,f,p;return p=t,i=mi(),i!==null?(e=W(),e!==null?(l=U(),l!==null?(u=W(),u!==null?(f=gi(),f!==null?i=[i,e,l,u,f]:(i=null,t=p)):(i=null,t=p)):(i=null,t=p)):(i=null,t=p)):(i=null,t=p),i}function mi(){var i,e;return e=t,r.substr(t,3).toLowerCase()==="sip"?(i=r.substr(t,3),t+=3):(i=null,_('"SIP"')),i===null&&(i=U()),i!==null&&(i=function(l,u){b.protocol=u}(e,i)),i===null&&(t=e),i}function gi(){var i,e;return e=t,r.substr(t,3).toLowerCase()==="udp"?(i=r.substr(t,3),t+=3):(i=null,_('"UDP"')),i===null&&(r.substr(t,3).toLowerCase()==="tcp"?(i=r.substr(t,3),t+=3):(i=null,_('"TCP"')),i===null&&(r.substr(t,3).toLowerCase()==="tls"?(i=r.substr(t,3),t+=3):(i=null,_('"TLS"')),i===null&&(r.substr(t,4).toLowerCase()==="sctp"?(i=r.substr(t,4),t+=4):(i=null,_('"SCTP"')),i===null&&(i=U())))),i!==null&&(i=function(l,u){b.transport=u}(e,i)),i===null&&(t=e),i}function Ti(){var i,e,l,u,f;return u=t,i=vi(),i!==null?(f=t,e=ye(),e!==null?(l=Ei(),l!==null?e=[e,l]:(e=null,t=f)):(e=null,t=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,t=u)):(i=null,t=u),i}function vi(){var i,e;return e=t,i=ot(),i===null&&(i=wn(),i===null&&(i=os())),i!==null&&(i=function(l){b.host=r.substring(t,l)}(e)),i===null&&(t=e),i}function Ei(){var i,e,l,u,f,p,m;return p=t,m=t,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,t=m)):(i=null,t=m)):(i=null,t=m)):(i=null,t=m)):(i=null,t=m),i!==null&&(i=function(v,S){b.port=parseInt(S.join(""))}(p,i)),i===null&&(t=p),i}function Qn(){var i,e,l,u,f;return u=t,f=t,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,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p,m){return parseInt(m.join(""))}(u,i)),i===null&&(t=u),i}function Si(){var i;return i=Zr(),i}function na(){var i,e,l,u,f,p;if(f=t,i=Rl(),i!==null){for(e=[],p=t,l=le(),l!==null?(u=Zn(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);l!==null;)e.push(l),p=t,l=le(),l!==null?(u=Zn(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);e!==null?i=[i,e]:(i=null,t=f)}else i=null,t=f;return i}function Rl(){var i,e;return e=t,i=Qt(),i!==null&&(i=function(l,u){b.expires=u}(e,i)),i===null&&(t=e),i}function Zn(){var i;return i=er(),i===null&&(i=Ge()),i}function er(){var i,e,l,u,f;return u=t,f=t,r.substr(t,9).toLowerCase()==="refresher"?(i=r.substr(t,9),t+=9):(i=null,_('"refresher"')),i!==null?(e=G(),e!==null?(r.substr(t,3).toLowerCase()==="uac"?(l=r.substr(t,3),t+=3):(l=null,_('"uac"')),l===null&&(r.substr(t,3).toLowerCase()==="uas"?(l=r.substr(t,3),t+=3):(l=null,_('"uas"'))),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p,m){b.refresher=m.toLowerCase()}(u,i[2])),i===null&&(t=u),i}function Il(){var i,e,l,u;return u=t,i=U(),i!==null?(e=D(),e!==null?(l=bl(),l!==null?i=[i,e,l]:(i=null,t=u)):(i=null,t=u)):(i=null,t=u),i}function bl(){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 wl(){var i,e;for(i=[],e=A();e!==null;)i.push(e),e=A();return i}function ra(){var i,e,l;return l=t,r.substr(t,5)==="uuid:"?(i="uuid:",t+=5):(i=null,_('"uuid:"')),i!==null?(e=Ol(),e!==null?i=[i,e]:(i=null,t=l)):(i=null,t=l),i}function Ol(){var i,e,l,u,f,p,m,v,S,O,ie;return O=t,ie=t,i=Ft(),i!==null?(r.charCodeAt(t)===45?(e="-",t++):(e=null,_('"-"')),e!==null?(l=Ht(),l!==null?(r.charCodeAt(t)===45?(u="-",t++):(u=null,_('"-"')),u!==null?(f=Ht(),f!==null?(r.charCodeAt(t)===45?(p="-",t++):(p=null,_('"-"')),p!==null?(m=Ht(),m!==null?(r.charCodeAt(t)===45?(v="-",t++):(v=null,_('"-"')),v!==null?(S=yi(),S!==null?i=[i,e,l,u,f,p,m,v,S]:(i=null,t=ie)):(i=null,t=ie)):(i=null,t=ie)):(i=null,t=ie)):(i=null,t=ie)):(i=null,t=ie)):(i=null,t=ie)):(i=null,t=ie)):(i=null,t=ie),i!==null&&(i=function(Ue,wt){b=r.substring(t+5,Ue)}(O,i[0])),i===null&&(t=O),i}function Ht(){var i,e,l,u,f;return f=t,i=E(),i!==null?(e=E(),e!==null?(l=E(),l!==null?(u=E(),u!==null?i=[i,e,l,u]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i}function Ft(){var i,e,l;return l=t,i=Ht(),i!==null?(e=Ht(),e!==null?i=[i,e]:(i=null,t=l)):(i=null,t=l),i}function yi(){var i,e,l,u;return u=t,i=Ht(),i!==null?(e=Ht(),e!==null?(l=Ht(),l!==null?i=[i,e,l]:(i=null,t=u)):(i=null,t=u)):(i=null,t=u),i}function Dl(){var i,e,l,u,f,p,m;if(f=t,p=t,i=de(),i===null&&(i=Lt()),i!==null){for(e=[],m=t,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);l!==null;)e.push(l),m=t,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,t=m)):(l=null,t=m);e!==null?i=[i,e]:(i=null,t=p)}else i=null,t=p;return i!==null&&(i=function(v){try{b=new us(b.uri,b.display_name,b.params)}catch{b=-1}}()),i===null&&(t=f),i}function ia(){var i,e,l,u,f,p;if(f=t,i=Nl(),i!==null){for(e=[],p=t,l=le(),l!==null?(u=tr(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);l!==null;)e.push(l),p=t,l=le(),l!==null?(u=tr(),u!==null?l=[l,u]:(l=null,t=p)):(l=null,t=p);e!==null?i=[i,e]:(i=null,t=f)}else i=null,t=f;return i}function Nl(){var i,e,l,u,f,p;return u=t,f=t,i=tt(),i!==null?(p=t,r.charCodeAt(t)===64?(e="@",t++):(e=null,_('"@"')),e!==null?(l=tt(),l!==null?e=[e,l]:(e=null,t=p)):(e=null,t=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(m){b.call_id=r.substring(t,m)}(u)),i===null&&(t=u),i}function tr(){var i;return i=sr(),i===null&&(i=Ai(),i===null&&(i=Ci(),i===null&&(i=Ge()))),i}function sr(){var i,e,l,u,f;return u=t,f=t,r.substr(t,6)==="to-tag"?(i="to-tag",t+=6):(i=null,_('"to-tag"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p,m){b.to_tag=m}(u,i[2])),i===null&&(t=u),i}function Ai(){var i,e,l,u,f;return u=t,f=t,r.substr(t,8)==="from-tag"?(i="from-tag",t+=8):(i=null,_('"from-tag"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,t=f)):(i=null,t=f)):(i=null,t=f),i!==null&&(i=function(p,m){b.from_tag=m}(u,i[2])),i===null&&(t=u),i}function Ci(){var i,e;return e=t,r.substr(t,10)==="early-only"?(i="early-only",t+=10):(i=null,_('"early-only"')),i!==null&&(i=function(l){b.early_only=!0}()),i===null&&(t=e),i}function Ul(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 la(){for(var i=1,e=1,l=!1,u=0;u<Math.max(t,n);u++){var f=r.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 Pl=Es(),us=xu(),b={},w=a[o]();if(w===null||t!==r.length){var Ri=Math.max(t,n),Ii=Ri<r.length?r.charAt(Ri):null,xl=la();return new this.SyntaxError(Ul(d),Ii,Ri,xl.line,xl.column),-1}return b},toSource:function(){return this._source}};return s.SyntaxError=function(r,o,a,t,n){function d(_,h){var g,T;switch(_.length){case 0:g="end of input";break;case 1:g=_[0];break;default:g=_.slice(0,_.length-1).join(", ")+" or "+_[_.length-1]}return T=h?c(h):"end of input","Expected "+g+" but "+T+" found."}this.name="SyntaxError",this.expected=r,this.found=o,this.message=d(r,o),this.offset=a,this.line=t,this.column=n},s.SyntaxError.prototype=Error.prototype,s}()),Na}var Ua,Zc;function Es(){if(Zc)return Ua;Zc=1;const c=De,s=yt(),r=ls();return Ua=class o_{static parse(a){if(a=r.parse(a,"SIP_URI"),a!==-1)return a}constructor(a,t,n,d,_={},h={}){if(!n)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=a||c.SIP,this._user=t,this._host=n,this._port=d;for(const g in _)Object.prototype.hasOwnProperty.call(_,g)&&this.setParam(g,_[g]);for(const g in h)Object.prototype.hasOwnProperty.call(h,g)&&this.setHeader(g,h[g])}get scheme(){return this._scheme}set scheme(a){this._scheme=a.toLowerCase()}get user(){return this._user}set user(a){this._user=a}get host(){return this._host}set host(a){this._host=a.toLowerCase()}get port(){return this._port}set port(a){this._port=a===0?a:parseInt(a,10)||null}setParam(a,t){a&&(this._parameters[a.toLowerCase()]=typeof t>"u"||t===null?null:t.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 t=this._parameters[a];return delete this._parameters[a],t}}clearParams(){this._parameters={}}setHeader(a,t){this._headers[s.headerize(a)]=Array.isArray(t)?t:[t]}getHeader(a){if(a)return this._headers[s.headerize(a)]}hasHeader(a){if(a)return this._headers.hasOwnProperty(s.headerize(a))&&!0||!1}deleteHeader(a){if(a=s.headerize(a),this._headers.hasOwnProperty(a)){const t=this._headers[a];return delete this._headers[a],t}}clearHeaders(){this._headers={}}clone(){return new o_(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}toString(){const a=[];let t=`${this._scheme}:`;this._user&&(t+=`${s.escapeUser(this._user)}@`),t+=this._host,(this._port||this._port===0)&&(t+=`:${this._port}`);for(const n in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,n)&&(t+=`;${n}`,this._parameters[n]!==null&&(t+=`=${this._parameters[n]}`));for(const n in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,n))for(const d of this._headers[n])a.push(`${n}=${d}`);return a.length>0&&(t+=`?${a.join("&")}`),t}toAor(a){let t=`${this._scheme}:`;return this._user&&(t+=`${s.escapeUser(this._user)}@`),t+=this._host,a&&(this._port||this._port===0)&&(t+=`:${this._port}`),t}},Ua}var ef;function yt(){if(ef)return et;ef=1;const c=De,s=Es(),r=ls();et.str_utf8_length=n=>unescape(encodeURIComponent(n)).length;const o=et.isFunction=n=>n!==void 0?Object.prototype.toString.call(n)==="[object Function]":!1;et.isString=n=>n!==void 0?Object.prototype.toString.call(n)==="[object String]":!1,et.isDecimal=n=>!isNaN(n)&&parseFloat(n)===parseInt(n,10),et.isEmpty=n=>n===null||n===""||n===void 0||Array.isArray(n)&&n.length===0||typeof n=="number"&&isNaN(n),et.hasMethods=function(n,...d){for(const _ of d)if(o(n[_]))return!1;return!0};const a=et.createRandomToken=(n,d=32)=>{let _,h,g="";for(_=0;_<n;_++)h=Math.random()*d|0,g+=h.toString(d);return g};et.newTag=()=>a(10),et.newUUID=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,d=>{const _=Math.random()*16|0;return(d==="x"?_:_&3|8).toString(16)}),et.hostType=n=>{if(n){if(n=r.parse(n,"host"),n!==-1)return n.host_type}else return};const t=et.escapeUser=n=>encodeURIComponent(decodeURIComponent(n)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/");return et.normalizeTarget=(n,d)=>{if(n){if(n instanceof s)return n;if(typeof n=="string"){const _=n.split("@");let h,g;switch(_.length){case 1:if(!d)return;h=n,g=d;break;case 2:h=_[0],g=_[1];break;default:h=_.slice(0,_.length-1).join("@"),g=_[_.length-1]}h=h.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(h)&&(h=h.replace(/[-.()]/g,"")),n=`${c.SIP}:${t(h)}@${g}`;let T;return(T=s.parse(n))?T:void 0}else return}else return},et.headerize=n=>{const d={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},_=n.toLowerCase().replace(/_/g,"-").split("-");let h="";const g=_.length;let T;for(T=0;T<g;T++)T!==0&&(h+="-"),h+=_[T].charAt(0).toUpperCase()+_[T].substring(1);return d[h]&&(h=d[h]),h},et.sipErrorCause=n=>{for(const d in c.SIP_ERROR_CAUSES)if(c.SIP_ERROR_CAUSES[d].indexOf(n)!==-1)return c.causes[d];return c.causes.SIP_FAILURE_CODE},et.getRandomTestNetIP=()=>{function n(d,_){return Math.floor(Math.random()*(_-d+1)+d)}return`192.0.2.${n(1,254)}`},et.calculateMD5=n=>{function d(Ee,Ae){return Ee<<Ae|Ee>>>32-Ae}function _(Ee,Ae){const Ie=Ee&2147483648,Oe=Ae&2147483648,pe=Ee&1073741824,ue=Ae&1073741824,de=(Ee&1073741823)+(Ae&1073741823);return pe&ue?de^2147483648^Ie^Oe:pe|ue?de&1073741824?de^3221225472^Ie^Oe:de^1073741824^Ie^Oe:de^Ie^Oe}function h(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,ue,de){return Ee=_(Ee,_(_(h(Ae,Ie,Oe),pe),de)),_(d(Ee,ue),Ae)}function A(Ee,Ae,Ie,Oe,pe,ue,de){return Ee=_(Ee,_(_(g(Ae,Ie,Oe),pe),de)),_(d(Ee,ue),Ae)}function C(Ee,Ae,Ie,Oe,pe,ue,de){return Ee=_(Ee,_(_(T(Ae,Ie,Oe),pe),de)),_(d(Ee,ue),Ae)}function I(Ee,Ae,Ie,Oe,pe,ue,de){return Ee=_(Ee,_(_(E(Ae,Ie,Oe),pe),de)),_(d(Ee,ue),Ae)}function H(Ee){let Ae;const Ie=Ee.length,Oe=Ie+8,ue=((Oe-Oe%64)/64+1)*16,de=new Array(ue-1);let we=0,Ne=0;for(;Ne<Ie;)Ae=(Ne-Ne%4)/4,we=Ne%4*8,de[Ae]=de[Ae]|Ee.charCodeAt(Ne)<<we,Ne++;return Ae=(Ne-Ne%4)/4,we=Ne%4*8,de[Ae]=de[Ae]|128<<we,de[ue-2]=Ie<<3,de[ue-1]=Ie>>>29,de}function L(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 ae(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,M,D,B,V,J,F;const X=7,U=12,P=17,se=22,tt=5,ee=9,W=14,G=20,re=4,ge=11,be=16,xe=23,Ce=6,le=10,ye=15,st=21;for(n=ae(n),N=H(n),B=1732584193,V=4023233417,J=2562383102,F=271733878,j=0;j<N.length;j+=16)Se=B,ve=V,M=J,D=F,B=y(B,V,J,F,N[j+0],X,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],X,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],X,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],X,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],tt,4129170786),F=A(F,B,V,J,N[j+6],ee,3225465664),J=A(J,F,B,V,N[j+11],W,643717713),V=A(V,J,F,B,N[j+0],G,3921069994),B=A(B,V,J,F,N[j+5],tt,3593408605),F=A(F,B,V,J,N[j+10],ee,38016083),J=A(J,F,B,V,N[j+15],W,3634488961),V=A(V,J,F,B,N[j+4],G,3889429448),B=A(B,V,J,F,N[j+9],tt,568446438),F=A(F,B,V,J,N[j+14],ee,3275163606),J=A(J,F,B,V,N[j+3],W,4107603335),V=A(V,J,F,B,N[j+8],G,1163531501),B=A(B,V,J,F,N[j+13],tt,2850285829),F=A(F,B,V,J,N[j+2],ee,4243563512),J=A(J,F,B,V,N[j+7],W,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],xe,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],xe,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],xe,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],xe,3299628645),B=I(B,V,J,F,N[j+0],Ce,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],st,4237533241),B=I(B,V,J,F,N[j+12],Ce,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],st,2240044497),B=I(B,V,J,F,N[j+8],Ce,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],st,1309151649),B=I(B,V,J,F,N[j+4],Ce,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],st,3951481745),B=_(B,Se),V=_(V,ve),J=_(J,M),F=_(F,D);return(L(B)+L(V)+L(J)+L(F)).toLowerCase()},et.closeMediaStream=n=>{if(n)try{let d;if(n.getTracks){d=n.getTracks();for(const _ of d)_.stop()}else{d=n.getAudioTracks();for(const _ of d)_.stop();d=n.getVideoTracks();for(const _ of d)_.stop()}}catch{(typeof n.stop=="function"||typeof n.stop=="object")&&n.stop()}},et.cloneArray=n=>n&&n.slice()||[],et.cloneObject=(n,d={})=>n&&Object.assign({},n)||d,et}const a_=Pt,Mm=at,St=De,rt=yt(),tf=xu(),km=ls(),Pa=new Mm("SIPMessage");class Vo{constructor(s,r,o,a,t,n){if(!s||!r||!o)return null;a=a||{},this.ua=o,this.headers={},this.method=s,this.ruri=r,this.body=n,this.extraHeaders=rt.cloneArray(t),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),a.route_set?this.setHeader("route",a.route_set):o.configuration.use_preloaded_route&&this.setHeader("route",`<${o.transport.sip_uri};lr>`),this.setHeader("via",""),this.setHeader("max-forwards",St.MAX_FORWARDS);const d=a.to_uri||r,_=a.to_tag?{tag:a.to_tag}:null,h=typeof a.to_display_name<"u"?a.to_display_name:null;this.to=new tf(d,h,_),this.setHeader("to",this.to.toString());const g=a.from_uri||o.configuration.uri,T={tag:a.from_tag||rt.newTag()};let E;typeof a.from_display_name<"u"?E=a.from_display_name:o.configuration.display_name?E=o.configuration.display_name:E=null,this.from=new tf(g,E,T),this.setHeader("from",this.from.toString());const y=a.call_id||o.configuration.jssip_id+rt.createRandomToken(15);this.call_id=y,this.setHeader("call-id",y);const A=a.cseq||Math.floor(Math.random()*1e4);this.cseq=A,this.setHeader("cseq",`${A} ${s}`)}setHeader(s,r){const o=new RegExp(`^\\s*${s}\\s*:`,"i");for(let a=0;a<this.extraHeaders.length;a++)o.test(this.extraHeaders[a])&&this.extraHeaders.splice(a,1);this.headers[rt.headerize(s)]=Array.isArray(r)?r:[r]}getHeader(s){const r=this.headers[rt.headerize(s)];if(r){if(r[0])return r[0]}else{const o=new RegExp(`^\\s*${s}\\s*:`,"i");for(const a of this.extraHeaders)if(o.test(a))return a.substring(a.indexOf(":")+1).trim()}}getHeaders(s){const r=this.headers[rt.headerize(s)],o=[];if(r){for(const a of r)o.push(a);return o}else{const a=new RegExp(`^\\s*${s}\\s*:`,"i");for(const t of this.extraHeaders)a.test(t)&&o.push(t.substring(t.indexOf(":")+1).trim());return o}}hasHeader(s){if(this.headers[rt.headerize(s)])return!0;{const r=new RegExp(`^\\s*${s}\\s*:`,"i");for(const o of this.extraHeaders)if(r.test(o))return!0}return!1}parseSDP(s){return!s&&this.sdp?this.sdp:(this.sdp=a_.parse(this.body||""),this.sdp)}toString(){let s=`${this.method} ${this.ruri} SIP/2.0\r
76
- `;for(const a in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,a))for(const t of this.headers[a])s+=`${a}: ${t}\r
59
+ `.concat(i,`
60
+ `));this.ondata({transport:this,message:i})}},{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}(),l_={};function Hc(c,s){var i;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(i=Bp(c))||s&&c&&typeof c.length=="number"){i&&(c=i);var l=0,a=function(){};return{s:a,n:function(){return l>=c.length?{done:!0}:{done:!1,value:c[l++]}},e:function(n){throw n},f:a}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
61
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var _=!0,e=!1,p;return{s:function(){i=c[Symbol.iterator]()},n:function(){var n=i.next();return _=n.done,n},e:function(n){e=!0,p=n},f:function(){try{!_&&i.return!=null&&i.return()}finally{if(e)throw p}}}}function Bp(c,s){if(c){if(typeof c=="string")return Fc(c,s);var i=Object.prototype.toString.call(c).slice(8,-1);if(i==="Object"&&c.constructor&&(i=c.constructor.name),i==="Map"||i==="Set")return Array.from(c);if(i==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return Fc(c,s)}}function Fc(c,s){(s==null||s>c.length)&&(s=c.length);for(var i=0,l=new Array(s);i<s;i++)l[i]=c[i];return l}var Gp=dt,Tu=us(),vu=Rs,ea=new Gp("Parser");l_.parseMessage=function(c,s){var i,l,a=c.indexOf(`\r
62
+ `);if(a===-1){ea.warn("parseMessage() | no CRLF found, not a SIP message");return}var _=c.substring(0,a),e=Tu.parse(_,"Request_Response");if(e===-1){ea.warn('parseMessage() | error parsing first line of SIP message: "'.concat(_,'"'));return}else e.status_code?(i=new vu.IncomingResponse,i.status_code=e.status_code,i.reason_phrase=e.reason_phrase):(i=new vu.IncomingRequest(s),i.method=e.method,i.ruri=e.uri);i.data=c;for(var p=a+2;;){if(a=Wp(c,p),a===-2){l=p+2;break}else if(a===-1){ea.warn("parseMessage() | malformed message");return}if(e=Kp(i,c,p,a),e!==!0){ea.warn("parseMessage() |",e.error);return}p=a+2}if(i.hasHeader("content-length")){var g=i.getHeader("content-length");i.body=c.substr(l,g)}else i.body=c.substring(l);return i};function Wp(c,s){var i=s,l=0,a=0;if(c.substring(i,i+2).match(/(^\r\n)/))return-2;for(;l===0;){if(a=c.indexOf(`\r
63
+ `,i),a===-1)return a;!c.substring(a+2,a+4).match(/(^\r\n)/)&&c.charAt(a+2).match(/(^\s+)/)?i=a+2:l=a}return l}function Kp(c,s,i,l){var a,_=s.indexOf(":",i),e=s.substring(i,_).trim(),p=s.substring(_+1,l).trim();switch(e.toLowerCase()){case"via":case"v":c.addHeader("via",p),c.getHeaders("via").length===1?(a=c.parseHeader("Via"),a&&(c.via=a,c.via_branch=a.branch)):a=0;break;case"from":case"f":c.setHeader("from",p),a=c.parseHeader("from"),a&&(c.from=a,c.from_tag=a.getParam("tag"));break;case"to":case"t":c.setHeader("to",p),a=c.parseHeader("to"),a&&(c.to=a,c.to_tag=a.getParam("tag"));break;case"record-route":if(a=Tu.parse(p,"Record_Route"),a===-1)a=void 0;else{var g=Hc(a),n;try{for(g.s();!(n=g.n()).done;){var v=n.value;c.addHeader("record-route",p.substring(v.possition,v.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=v.parsed}}catch(A){g.e(A)}finally{g.f()}}break;case"call-id":case"i":c.setHeader("call-id",p),a=c.parseHeader("call-id"),a&&(c.call_id=p);break;case"contact":case"m":if(a=Tu.parse(p,"Contact"),a===-1)a=void 0;else{var S=Hc(a),m;try{for(S.s();!(m=S.n()).done;){var C=m.value;c.addHeader("contact",p.substring(C.possition,C.offset)),c.headers.Contact[c.getHeaders("contact").length-1].parsed=C.parsed}}catch(A){S.e(A)}finally{S.f()}}break;case"content-length":case"l":c.setHeader("content-length",p),a=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",p),a=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",p),a=c.parseHeader("cseq"),a&&(c.cseq=a.value),c instanceof vu.IncomingResponse&&(c.method=a.method);break;case"max-forwards":c.setHeader("max-forwards",p),a=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",p),a=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",p),a=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",p),a=c.parseHeader("session-expires"),a&&(c.session_expires=a.expires,c.session_expires_refresher=a.refresher);break;case"refer-to":case"r":c.setHeader("refer-to",p),a=c.parseHeader("refer-to"),a&&(c.refer_to=a);break;case"replaces":c.setHeader("replaces",p),a=c.parseHeader("replaces"),a&&(c.replaces=a);break;case"event":case"o":c.setHeader("event",p),a=c.parseHeader("event"),a&&(c.event=a);break;default:c.addHeader(e,p),a=0}return a===void 0?{error:'error parsing header "'.concat(e,'"')}:!0}function Pa(c,s){var i;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(i=Yp(c))||s&&c&&typeof c.length=="number"){i&&(c=i);var l=0,a=function(){};return{s:a,n:function(){return l>=c.length?{done:!0}:{done:!1,value:c[l++]}},e:function(n){throw n},f:a}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
64
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var _=!0,e=!1,p;return{s:function(){i=c[Symbol.iterator]()},n:function(){var n=i.next();return _=n.done,n},e:function(n){e=!0,p=n},f:function(){try{!_&&i.return!=null&&i.return()}finally{if(e)throw p}}}}function Yp(c,s){if(c){if(typeof c=="string")return jc(c,s);var i=Object.prototype.toString.call(c).slice(8,-1);if(i==="Object"&&c.constructor&&(i=c.constructor.name),i==="Map"||i==="Set")return Array.from(c);if(i==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return jc(c,s)}}function jc(c,s){(s==null||s>c.length)&&(s=c.length);for(var i=0,l=new Array(s);i<s;i++)l[i]=c[i];return l}var Jp=dt,a_=ot,qc=Rs,Mu=Nt(),ku=new Jp("sanityCheck"),zp=[lm],Xp=[em,tm,sm,nm],Qp=[rm,im],Be,is,o_,Zp=function(c,s,i){Be=c,is=s,o_=i;var l=Pa(zp),a;try{for(l.s();!(a=l.n()).done;){var _=a.value;if(_()===!1)return!1}}catch(m){l.e(m)}finally{l.f()}if(Be instanceof qc.IncomingRequest){var e=Pa(Xp),p;try{for(e.s();!(p=e.n()).done;){var g=p.value;if(g()===!1)return!1}}catch(m){e.e(m)}finally{e.f()}}else if(Be instanceof qc.IncomingResponse){var n=Pa(Qp),v;try{for(n.s();!(v=n.n()).done;){var S=v.value;if(S()===!1)return!1}}catch(m){n.e(m)}finally{n.f()}}return!0};function em(){if(Be.s("to").uri.scheme!=="sip")return Qi(416),!1}function tm(){if(!Be.to_tag&&Be.call_id.substr(0,5)===is.configuration.jssip_id)return Qi(482),!1}function sm(){var c=Mu.str_utf8_length(Be.body),s=Be.getHeader("content-length");if(c<s)return Qi(400),!1}function nm(){var c=Be.from_tag,s=Be.call_id,i=Be.cseq,l;if(!Be.to_tag)if(Be.method===a_.INVITE){if(is._transactions.ist[Be.via_branch])return!1;for(var a in is._transactions.ist)if(Object.prototype.hasOwnProperty.call(is._transactions.ist,a)&&(l=is._transactions.ist[a],l.request.from_tag===c&&l.request.call_id===s&&l.request.cseq===i))return Qi(482),!1}else{if(is._transactions.nist[Be.via_branch])return!1;for(var _ in is._transactions.nist)if(Object.prototype.hasOwnProperty.call(is._transactions.nist,_)&&(l=is._transactions.nist[_],l.request.from_tag===c&&l.request.call_id===s&&l.request.cseq===i))return Qi(482),!1}}function rm(){if(Be.getHeaders("via").length>1)return ku.debug("more than one Via header field present in the response, dropping the response"),!1}function im(){var c=Mu.str_utf8_length(Be.body),s=Be.getHeader("content-length");if(c<s)return ku.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}function lm(){for(var c=["from","to","call_id","cseq","via"],s=0,i=c;s<i.length;s++){var l=i[s];if(!Be.hasHeader(l))return ku.debug("missing mandatory header field : ".concat(l,", dropping the response")),!1}}function Qi(c){var s=Be.getHeaders("via"),i,l="SIP/2.0 ".concat(c," ").concat(a_.REASON_PHRASE[c],`\r
65
+ `),a=Pa(s),_;try{for(a.s();!(_=a.n()).done;){var e=_.value;l+="Via: ".concat(e,`\r
66
+ `)}}catch(p){a.e(p)}finally{a.f()}i=Be.getHeader("To"),Be.to_tag||(i+=";tag=".concat(Mu.newTag())),l+="To: ".concat(i,`\r
67
+ `),l+="From: ".concat(Be.getHeader("From"),`\r
68
+ `),l+="Call-ID: ".concat(Be.call_id,`\r
69
+ `),l+="CSeq: ".concat(Be.cseq," ").concat(Be.method,`\r
70
+ `),l+=`\r
71
+ `,o_.send(l)}var Lu={};function Vc(c,s){var i;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(i=am(c))||s&&c&&typeof c.length=="number"){i&&(c=i);var l=0,a=function(){};return{s:a,n:function(){return l>=c.length?{done:!0}:{done:!1,value:c[l++]}},e:function(n){throw n},f:a}}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 _=!0,e=!1,p;return{s:function(){i=c[Symbol.iterator]()},n:function(){var n=i.next();return _=n.done,n},e:function(n){e=!0,p=n},f:function(){try{!_&&i.return!=null&&i.return()}finally{if(e)throw p}}}}function am(c,s){if(c){if(typeof c=="string")return Bc(c,s);var i=Object.prototype.toString.call(c).slice(8,-1);if(i==="Object"&&c.constructor&&(i=c.constructor.name),i==="Map"||i==="Set")return Array.from(c);if(i==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return Bc(c,s)}}function Bc(c,s){(s==null||s>c.length)&&(s=c.length);for(var i=0,l=new Array(s);i<s;i++)l[i]=c[i];return l}var nr=Nt(),On=ot,Oo=us(),Gc=tn(),Do=xu,No=en;Lu.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:On.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:On.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:On.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:"".concat(nr.createRandomToken(12),".invalid")};var ta={mandatory:{sockets:function(s){var i=[];if(Do.isSocket(s))i.push({socket:s});else if(Array.isArray(s)&&s.length){var l=Vc(s),a;try{for(l.s();!(a=l.n()).done;){var _=a.value;Object.prototype.hasOwnProperty.call(_,"socket")&&Do.isSocket(_.socket)?i.push(_):Do.isSocket(_)&&i.push({socket:_})}}catch(e){l.e(e)}finally{l.f()}}else return;return i},uri:function(s){/^sip:/i.test(s)||(s="".concat(On.SIP,":").concat(s));var i=Gc.parse(s);if(i)return i.user?i:void 0}},optional:{authorization_user:function(s){if(Oo.parse('"'.concat(s,'"'),"quoted_string")!==-1)return s},authorization_jwt:function(s){if(typeof s=="string")return s},user_agent:function(s){if(typeof s=="string")return s},connection_recovery_max_interval:function(s){if(nr.isDecimal(s)){var i=Number(s);if(i>0)return i}},connection_recovery_min_interval:function(s){if(nr.isDecimal(s)){var i=Number(s);if(i>0)return i}},contact_uri:function(s){if(typeof s=="string"){var i=Oo.parse(s,"SIP_URI");if(i!==-1)return i}},display_name:function(s){return s},instance_id:function(s){if(/^uuid:/i.test(s)&&(s=s.substr(5)),Oo.parse(s,"uuid")!==-1)return s},no_answer_timeout:function(s){if(nr.isDecimal(s)){var i=Number(s);if(i>0)return i}},session_timers:function(s){if(typeof s=="boolean")return s},session_timers_refresh_method:function(s){if(typeof s=="string"&&(s=s.toUpperCase(),s===On.INVITE||s===On.UPDATE))return s},session_timers_force_refresher:function(s){if(typeof s=="boolean")return s},password:function(s){return String(s)},realm:function(s){return String(s)},ha1:function(s){return String(s)},register:function(s){if(typeof s=="boolean")return s},register_expires:function(s){if(nr.isDecimal(s)){var i=Number(s);if(i>0)return i}},registrar_server:function(s){/^sip:/i.test(s)||(s="".concat(On.SIP,":").concat(s));var i=Gc.parse(s);if(i)return i.user?void 0:i},use_preloaded_route:function(s){if(typeof s=="boolean")return s},extra_headers:function(s){var i=[];if(Array.isArray(s)&&s.length){var l=Vc(s),a;try{for(l.s();!(a=l.n()).done;){var _=a.value;typeof _=="string"&&i.push(_)}}catch(e){l.e(e)}finally{l.f()}}else return;return i}}};Lu.load=function(c,s){for(var i in ta.mandatory)if(s.hasOwnProperty(i)){var l=s[i],a=ta.mandatory[i](l);if(a!==void 0)c[i]=a;else throw new No.ConfigurationError(i,l)}else throw new No.ConfigurationError(i);for(var _ in ta.optional)if(s.hasOwnProperty(_)){var e=s[_];if(nr.isEmpty(e))continue;var p=ta.optional[_](e);if(p!==void 0)c[_]=p;else throw new No.ConfigurationError(_,e)}};function xa(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?xa=function(i){return typeof i}:xa=function(i){return i&&typeof Symbol=="function"&&i.constructor===Symbol&&i!==Symbol.prototype?"symbol":typeof i},xa(c)}function om(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function Wc(c,s){for(var i=0;i<s.length;i++){var l=s[i];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(c,l.key,l)}}function Kc(c,s,i){return s&&Wc(c.prototype,s),i&&Wc(c,i),c}function um(c,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(s&&s.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),s&&Eu(c,s)}function Eu(c,s){return Eu=Object.setPrototypeOf||function(l,a){return l.__proto__=a,l},Eu(c,s)}function cm(c){var s=_m();return function(){var l=Ba(c),a;if(s){var _=Ba(this).constructor;a=Reflect.construct(l,arguments,_)}else a=l.apply(this,arguments);return fm(this,a)}}function fm(c,s){return s&&(xa(s)==="object"||typeof s=="function")?s:u_(c)}function u_(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function _m(){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 Ba(c){return Ba=Object.setPrototypeOf?Object.getPrototypeOf:function(i){return i.__proto__||Object.getPrototypeOf(i)},Ba(c)}var hm=ht.EventEmitter,dm=dt,gt=ot,pm=sd,Yc=fp,Jc=Cp,zc=kp,Uo=ol,mm=Vp,sa=Nt(),gm=en,Tm=tn(),vm=l_,Po=Rs,Em=Zp,xo=Lu,We=new dm("UA"),Et={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},Sm=function(c){um(i,c);var s=cm(i);Kc(i,null,[{key:"C",get:function(){return Et}}]);function i(l){var a;if(om(this,i),We.debug("new() [configuration:%o]",l),a=s.call(this),a._cache={credentials:{}},a._configuration=Object.assign({},xo.settings),a._dynConfiguration={},a._dialogs={},a._applicants={},a._sessions={},a._transport=null,a._contact=null,a._status=Et.STATUS_INIT,a._error=null,a._transactions={nist:{},nict:{},ist:{},ict:{}},a._data={},a._closeTimer=null,l===void 0)throw new TypeError("Not enough arguments");try{a._loadConfig(l)}catch(_){throw a._status=Et.STATUS_NOT_READY,a._error=Et.CONFIGURATION_ERROR,_}return a._registrator=new pm(u_(a)),a}return Kc(i,[{key:"start",value:function(){We.debug("start()"),this._status===Et.STATUS_INIT?this._transport.connect():this._status===Et.STATUS_USER_CLOSED?(We.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?We.debug("UA is in READY status, not restarted"):We.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}},{key:"register",value:function(){We.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}},{key:"unregister",value:function(a){We.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(a)}},{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(a,_){We.debug("call()");var e=new Yc(this);return e.connect(a,_),e}},{key:"sendMessage",value:function(a,_,e){We.debug("sendMessage()");var p=new Jc(this);return p.send(a,_,e),p}},{key:"sendOptions",value:function(a,_,e){We.debug("sendOptions()");var p=new zc(this);return p.send(a,_,e),p}},{key:"terminateSessions",value:function(a){We.debug("terminateSessions()");for(var _ in this._sessions)this._sessions[_].isEnded()||this._sessions[_].terminate(a)}},{key:"stop",value:function(){var a=this;if(We.debug("stop()"),this._dynConfiguration={},this._status===Et.STATUS_USER_CLOSED){We.debug("UA already closed");return}this._registrator.close();var _=Object.keys(this._sessions).length;for(var e in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,e)){We.debug("closing session ".concat(e));try{this._sessions[e].terminate()}catch{}}for(var p in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,p))try{this._applicants[p].close()}catch{}this._status=Et.STATUS_USER_CLOSED;var g=Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length;g===0&&_===0?this._transport.disconnect():this._closeTimer=setTimeout(function(){a._closeTimer=null,a._transport.disconnect()},2e3)}},{key:"normalizeTarget",value:function(a){return sa.normalizeTarget(a,this._configuration.hostport_params)}},{key:"get",value:function(a){switch(a){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:We.warn('get() | cannot get "%s" parameter in runtime',a);return}}},{key:"set",value:function(a,_){switch(a){case"authorization_user":{this._configuration.authorization_user=String(_);break}case"password":{this._configuration.password=String(_);break}case"realm":{this._configuration.realm=String(_);break}case"ha1":{this._configuration.ha1=String(_),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(_);break}case"display_name":{this._configuration.display_name=_;break}default:return We.warn('set() | cannot set "%s" parameter in runtime',a),!1}return!0}},{key:"newTransaction",value:function(a){this._transactions[a.type][a.id]=a,this.emit("newTransaction",{transaction:a})}},{key:"destroyTransaction",value:function(a){delete this._transactions[a.type][a.id],this.emit("transactionDestroyed",{transaction:a})}},{key:"newDialog",value:function(a){this._dialogs[a.id]=a}},{key:"destroyDialog",value:function(a){delete this._dialogs[a.id]}},{key:"newMessage",value:function(a,_){this._applicants[a]=a,this.emit("newMessage",_)}},{key:"newOptions",value:function(a,_){this._applicants[a]=a,this.emit("newOptions",_)}},{key:"destroyMessage",value:function(a){delete this._applicants[a]}},{key:"newRTCSession",value:function(a,_){this._sessions[a.id]=a,this.emit("newRTCSession",_)}},{key:"destroyRTCSession",value:function(a){delete this._sessions[a.id]}},{key:"registered",value:function(a){this.emit("registered",a)}},{key:"unregistered",value:function(a){this.emit("unregistered",a)}},{key:"registrationFailed",value:function(a){this.emit("registrationFailed",a)}},{key:"receiveRequest",value:function(a){var _=a.method;if(a.ruri.user!==this._configuration.uri.user&&a.ruri.user!==this._contact.uri.user){We.debug("Request-URI does not point to us"),a.method!==gt.ACK&&a.reply_sl(404);return}if(a.ruri.scheme===gt.SIPS){a.reply_sl(416);return}if(!Uo.checkTransaction(this,a)){if(_===gt.INVITE?new Uo.InviteServerTransaction(this,this._transport,a):_!==gt.ACK&&_!==gt.CANCEL&&new Uo.NonInviteServerTransaction(this,this._transport,a),_===gt.OPTIONS){if(this.listeners("newOptions").length===0){a.reply(200);return}var e=new zc(this);e.init_incoming(a)}else if(_===gt.MESSAGE){if(this.listeners("newMessage").length===0){a.reply(405);return}var p=new Jc(this);p.init_incoming(a)}else if(_===gt.INVITE&&!a.to_tag&&this.listeners("newRTCSession").length===0){a.reply(405);return}var g,n;if(a.to_tag)g=this._findDialog(a.call_id,a.from_tag,a.to_tag),g?g.receiveRequest(a):_===gt.NOTIFY?(n=this._findSession(a),n?n.receiveRequest(a):(We.debug("received NOTIFY request for a non existent subscription"),a.reply(481,"Subscription does not exist"))):_!==gt.ACK&&a.reply(481);else switch(_){case gt.INVITE:if(window.RTCPeerConnection)if(a.hasHeader("replaces")){var v=a.replaces;g=this._findDialog(v.call_id,v.from_tag,v.to_tag),g?(n=g.owner,n.isEnded()?a.reply(603):n.receiveRequest(a)):a.reply(481)}else n=new Yc(this),n.init_incoming(a);else We.warn("INVITE received but WebRTC is not supported"),a.reply(488);break;case gt.BYE:a.reply(481);break;case gt.CANCEL:n=this._findSession(a),n?n.receiveRequest(a):We.debug("received CANCEL request for a non existent session");break;case gt.ACK:break;case gt.NOTIFY:this.emit("sipEvent",{event:a.event,request:a}),a.reply(200);break;default:a.reply(405);break}}}},{key:"_findSession",value:function(a){var _=a.call_id,e=a.from_tag,p=a.to_tag,g=_+e,n=this._sessions[g],v=_+p,S=this._sessions[v];return n||S||null}},{key:"_findDialog",value:function(a,_,e){var p=a+_+e,g=this._dialogs[p];return g||(p=a+e+_,g=this._dialogs[p],g||null)}},{key:"_loadConfig",value:function(a){try{xo.load(this._configuration,a)}catch(v){throw v}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=sa.newUUID()),this._configuration.jssip_id=sa.createRandomToken(5);var _=this._configuration.uri.clone();_.user=null,this._configuration.hostport_params=_.toString().replace(/^sip:/i,"");try{this._transport=new mm(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=ym.bind(this),this._transport.onconnect=Am.bind(this),this._transport.ondisconnect=Cm.bind(this),this._transport.ondata=Rm.bind(this)}catch(v){throw We.warn(v),new gm.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 e=this._configuration.uri.clone();e.user=null,e.clearParams(),e.clearHeaders(),this._configuration.registrar_server=e}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new Tm("sip",sa.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 S=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},m=S.anonymous||null,C=S.outbound||null,A="<";return m?A+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":A+=this.pub_gruu||this.uri.toString(),C&&(m?!this.temp_gruu:!this.pub_gruu)&&(A+=";ob"),A+=">",A}};var p=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(var g in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,g)&&(p.indexOf(g)!==-1?Object.defineProperty(this._configuration,g,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,g,{writable:!1,configurable:!1}));We.debug("configuration parameters after validation:");for(var n in this._configuration)if(Object.prototype.hasOwnProperty.call(xo.settings,n))switch(n){case"uri":case"registrar_server":We.debug("- ".concat(n,": ").concat(this._configuration[n]));break;case"password":case"ha1":case"authorization_jwt":We.debug("- ".concat(n,": NOT SHOWN"));break;default:We.debug("- ".concat(n,": ").concat(JSON.stringify(this._configuration[n])))}}},{key:"C",get:function(){return Et}},{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}}]),i}(hm);function ym(c){this.emit("connecting",c)}function Am(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 Cm(c){for(var s=["nict","ict","nist","ist"],i=0,l=s;i<l.length;i++){var a=l[i];for(var _ in this._transactions[a])Object.prototype.hasOwnProperty.call(this._transactions[a],_)&&this._transactions[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 Rm(c){var s=c.transport,i=c.message;if(i=vm.parseMessage(i,this),!!i&&!(this._status===Et.STATUS_USER_CLOSED&&i instanceof Po.IncomingRequest)&&Em(i,this,s)){if(i instanceof Po.IncomingRequest)i.transport=s,this.receiveRequest(i);else if(i instanceof Po.IncomingResponse){var l;switch(i.method){case gt.INVITE:l=this._transactions.ict[i.via_branch],l&&l.receiveResponse(i);break;case gt.ACK:break;default:l=this._transactions.nict[i.via_branch],l&&l.receiveResponse(i);break}}}}function Im(c,s){if(!(c instanceof s))throw new TypeError("Cannot call a class as a function")}function Xc(c,s){for(var i=0;i<s.length;i++){var l=s[i];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(c,l.key,l)}}function bm(c,s,i){return s&&Xc(c.prototype,s),i&&Xc(c,i),c}var wm=dt,Om=us(),Ut=new wm("WebSocketInterface"),Dm=function(){function c(s){Im(this,c),Ut.debug('new() [url:"%s"]',s),this._url=s,this._sip_uri=null,this._via_transport=null,this._ws=null;var i=Om.parse(s,"absoluteURI");if(i===-1)throw Ut.warn("invalid WebSocket URI: ".concat(s)),new TypeError("Invalid argument: ".concat(s));if(i.scheme!=="wss"&&i.scheme!=="ws")throw Ut.warn("invalid WebSocket URI scheme: ".concat(i.scheme)),new TypeError("Invalid argument: ".concat(s));this._sip_uri="sip:".concat(i.host).concat(i.port?":".concat(i.port):"",";transport=ws"),this._via_transport=i.scheme.toUpperCase()}return bm(c,[{key:"connect",value:function(){if(Ut.debug("connect()"),this.isConnected()){Ut.debug("WebSocket ".concat(this._url," is already connected"));return}else if(this.isConnecting()){Ut.debug("WebSocket ".concat(this._url," is connecting"));return}this._ws&&this.disconnect(),Ut.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(i){this._onError(i)}}},{key:"disconnect",value:function(){Ut.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(i){return Ut.debug("send()"),this.isConnected()?(this._ws.send(i),!0):(Ut.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(){Ut.debug("WebSocket ".concat(this._url," connected")),this.onconnect()}},{key:"_onClose",value:function(i){var l=i.wasClean,a=i.code,_=i.reason;Ut.debug("WebSocket ".concat(this._url," closed")),l===!1&&Ut.debug("WebSocket abrupt disconnection"),this.ondisconnect(!l,a,_)}},{key:"_onMessage",value:function(i){var l=i.data;Ut.debug("received WebSocket message"),this.ondata(l)}},{key:"_onError",value:function(i){Ut.warn("WebSocket ".concat(this._url," error: "),i)}},{key:"via_transport",get:function(){return this._via_transport},set:function(i){this._via_transport=i.toUpperCase()}},{key:"sip_uri",get:function(){return this._sip_uri}},{key:"url",get:function(){return this._url}}]),c}(),Su=Ka,Nm=ot,Um=en,Pm=Nt(),xm=Sm,Mm=tn(),km=Ou(),Lm=us(),$m=Dm,Hm=ur("JsSIP");Hm("version %s",Su.version);var Qc={C:Nm,Exceptions:Um,Utils:Pm,UA:xm,URI:Mm,NameAddrHeader:km,WebSocketInterface:$m,Grammar:Lm,debug:ur,get name(){return Su.title},get version(){return Su.version}};const er=ur,tr="JsSIP";var ut=class{constructor(s){s?(this._debug=er.default(`${tr}:${s}`),this._warn=er.default(`${tr}:WARN:${s}`),this._error=er.default(`${tr}:ERROR:${s}`)):(this._debug=er.default(tr),this._warn=er.default(`${tr}:WARN`),this._error=er.default(`${tr}: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 Za=tt(ut),Zc=Ka;var Me={USER_AGENT:`${Zc.title} ${Zc.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 F=tt(Me);var rt={},ef={},Mo,tf;function $u(){if(tf)return Mo;tf=1;const c=Is(),s=Qt();return Mo=class c_{static parse(l){if(l=s.parse(l,"Name_Addr_Header"),l!==-1)return l}constructor(l,a,_){if(!l||!(l instanceof c))throw new TypeError('missing or invalid "uri" parameter');this._uri=l,this._parameters={},this.display_name=a;for(const e in _)Object.prototype.hasOwnProperty.call(_,e)&&this.setParam(e,_[e])}get uri(){return this._uri}get display_name(){return this._display_name}set display_name(l){this._display_name=l===0?"0":l}setParam(l,a){l&&(this._parameters[l.toLowerCase()]=typeof a>"u"||a===null?null:a.toString())}getParam(l){if(l)return this._parameters[l.toLowerCase()]}hasParam(l){if(l)return this._parameters.hasOwnProperty(l.toLowerCase())&&!0||!1}deleteParam(l){if(l=l.toLowerCase(),this._parameters.hasOwnProperty(l)){const a=this._parameters[l];return delete this._parameters[l],a}}clearParams(){this._parameters={}}clone(){return new c_(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}_quote(l){return l.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}toString(){let l=this._display_name?`"${this._quote(this._display_name)}" `:"";l+=`<${this._uri.toString()}>`;for(const a in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,a)&&(l+=`;${a}`,this._parameters[a]!==null&&(l+=`=${this._parameters[a]}`));return l}},Mo}var sf;function Qt(){if(sf)return ef;sf=1;function c(e){return'"'+e.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 s={parse:function(e,p){var g={CRLF:C,DIGIT:A,ALPHA:R,HEXDIG:I,WSP:V,OCTET:W,DQUOTE:oe,SP:x,HTAB:$,alphanum:Re,reserved:Ie,unreserved:H,mark:D,escaped:L,LWS:q,SWS:j,HCOLON:B,TEXT_UTF8_TRIM:X,TEXT_UTF8char:Q,UTF8_NONASCII:U,UTF8_CONT:se,LHEX:It,token:N,token_nodot:Y,separators:re,word:ae,STAR:Te,SLASH:De,EQUAL:Ce,LPAREN:Le,RPAREN:we,RAQUOT:Se,LAQUOT:it,COMMA:Ue,SEMI:le,COLON:Ae,LDQUOT:Oe,RDQUOT:Pe,comment:ve,ctext:he,quoted_string:pe,quoted_string_clean:Ne,qdtext:xe,quoted_pair:Ve,SIP_URI_noparams:He,SIP_URI:Ht,uri_scheme:ct,uri_scheme_sips:_r,uri_scheme_sip:Mn,userinfo:sn,user:nn,user_unreserved:cs,password:kn,hostport:ws,host:Os,hostname:rn,domainlabel:ln,toplabel:ge,IPv6reference:pt,IPv6address:fs,h16:de,ls32:bt,IPv4address:Ds,dec_octet:_s,port:hr,uri_parameters:dr,uri_parameter:Ln,transport_param:pr,user_param:mr,method_param:gr,ttl_param:Tr,maddr_param:vr,lr_param:Er,other_param:Ns,pname:Sr,pvalue:yr,paramchar:Zt,param_unreserved:Ar,headers:Cr,header:es,hname:hl,hvalue:Rr,hnv_unreserved:Us,Request_Response:Ir,Request_Line:br,Request_URI:wr,absoluteURI:Ps,hier_part:Or,net_path:xs,abs_path:an,opaque_part:Dr,uric:ts,uric_no_slash:$n,path_segments:Ms,segment:on,param:Hn,pchar:ks,scheme:Nr,authority:Ur,srvr:Fn,reg_name:Pr,query:xr,SIP_Version:jn,INVITEm:Mr,ACKm:kr,OPTIONSm:Lr,BYEm:$r,CANCELm:Hr,REGISTERm:Fr,SUBSCRIBEm:un,NOTIFYm:jr,REFERm:qr,Method:cn,Status_Line:Vr,Status_Code:dl,extension_code:pl,Reason_Phrase:ml,Allow_Events:qn,Call_ID:hs,Contact:Vn,contact_param:Ls,name_addr:ss,display_name:fn,contact_params:Bt,c_p_q:Br,c_p_expires:ze,delta_seconds:ns,qvalue:gl,generic_param:Xe,gen_value:Bn,Content_Disposition:Tl,disp_type:vl,disp_param:Gr,handling_param:El,Content_Encoding:Sl,Content_Length:yl,Content_Type:Al,media_type:Wr,m_type:_n,discrete_type:Kr,composite_type:Yr,extension_token:$s,x_token:Jr,m_subtype:Cl,m_parameter:Gn,m_value:Rl,CSeq:so,CSeq_value:Hs,Expires:no,Event:zr,event_type:ds,From:ro,from_param:Xr,tag_param:Qr,Max_Forwards:io,Min_Expires:Zr,Name_Addr_Header:Il,Proxy_Authenticate:hn,challenge:Fs,other_challenge:ei,auth_param:js,digest_cln:dn,realm:pn,realm_value:ti,domain:si,URI:mn,nonce:ni,nonce_value:ri,opaque:ii,stale:gn,algorithm:bl,qop_options:wl,qop_value:ps,Proxy_Require:lo,Record_Route:li,rec_route:Tn,Reason:ao,reason_param:ai,reason_cause:vn,Require:oo,Route:Ol,route_param:qs,Subscription_State:Dl,substate_value:Nl,subexp_params:oi,event_reason_value:Ul,Subject:ui,Supported:uo,To:Wn,to_param:En,Via:Pl,via_param:Sn,via_params:Kn,via_ttl:ci,via_maddr:fi,via_received:_i,via_branch:hi,response_port:di,rport:pi,sent_protocol:mi,protocol_name:gi,transport:Ti,sent_by:Yn,via_host:xl,via_port:Ml,ttl:Jn,WWW_Authenticate:vi,Session_Expires:kl,s_e_expires:Ll,s_e_params:zn,s_e_refresher:$l,extension_header:co,header_value:Ei,message_body:Gt,uuid_URI:Hl,uuid:Si,hex4:Wt,hex8:Fl,hex12:yi,Refer_To:Ai,Replaces:jl,call_id:Ci,replaces_param:Xn,to_tag:ql,from_tag:Vl,early_flag:Ri};if(p!==void 0){if(g[p]===void 0)throw new Error("Invalid rule name: "+c(p)+".")}else p="CRLF";var n=0,v=0,S=[];function m(t){n<v||(n>v&&(v=n,S=[]),S.push(t))}function C(){var t;return e.substr(n,2)===`\r
73
+ `?(t=`\r
74
+ `,n+=2):(t=null,m('"\\r\\n"')),t}function A(){var t;return/^[0-9]/.test(e.charAt(n))?(t=e.charAt(n),n++):(t=null,m("[0-9]")),t}function R(){var t;return/^[a-zA-Z]/.test(e.charAt(n))?(t=e.charAt(n),n++):(t=null,m("[a-zA-Z]")),t}function I(){var t;return/^[0-9a-fA-F]/.test(e.charAt(n))?(t=e.charAt(n),n++):(t=null,m("[0-9a-fA-F]")),t}function V(){var t;return t=x(),t===null&&(t=$()),t}function W(){var t;return/^[\0-\xFF]/.test(e.charAt(n))?(t=e.charAt(n),n++):(t=null,m("[\\0-\\xFF]")),t}function oe(){var t;return/^["]/.test(e.charAt(n))?(t=e.charAt(n),n++):(t=null,m('["]')),t}function x(){var t;return console.log("pos",n),console.log("input.charCodeAt(pos)",e.charAt(n)),e.charCodeAt(n)===32?(t=" ",n++):(t=null,m('" "')),t}function $(){var t;return e.charCodeAt(n)===9?(t=" ",n++):(t=null,m('"\\t"')),t}function Re(){var t;return/^[a-zA-Z0-9]/.test(e.charAt(n))?(t=e.charAt(n),n++):(t=null,m("[a-zA-Z0-9]")),t}function Ie(){var t;return e.charCodeAt(n)===59?(t=";",n++):(t=null,m('";"')),t===null&&(e.charCodeAt(n)===47?(t="/",n++):(t=null,m('"/"')),t===null&&(e.charCodeAt(n)===63?(t="?",n++):(t=null,m('"?"')),t===null&&(e.charCodeAt(n)===58?(t=":",n++):(t=null,m('":"')),t===null&&(e.charCodeAt(n)===64?(t="@",n++):(t=null,m('"@"')),t===null&&(e.charCodeAt(n)===38?(t="&",n++):(t=null,m('"&"')),t===null&&(e.charCodeAt(n)===61?(t="=",n++):(t=null,m('"="')),t===null&&(e.charCodeAt(n)===43?(t="+",n++):(t=null,m('"+"')),t===null&&(e.charCodeAt(n)===36?(t="$",n++):(t=null,m('"$"')),t===null&&(e.charCodeAt(n)===44?(t=",",n++):(t=null,m('","'))))))))))),t}function H(){var t;return t=Re(),t===null&&(t=D()),t}function D(){var t;return e.charCodeAt(n)===45?(t="-",n++):(t=null,m('"-"')),t===null&&(e.charCodeAt(n)===95?(t="_",n++):(t=null,m('"_"')),t===null&&(e.charCodeAt(n)===46?(t=".",n++):(t=null,m('"."')),t===null&&(e.charCodeAt(n)===33?(t="!",n++):(t=null,m('"!"')),t===null&&(e.charCodeAt(n)===126?(t="~",n++):(t=null,m('"~"')),t===null&&(e.charCodeAt(n)===42?(t="*",n++):(t=null,m('"*"')),t===null&&(e.charCodeAt(n)===39?(t="'",n++):(t=null,m(`"'"`)),t===null&&(e.charCodeAt(n)===40?(t="(",n++):(t=null,m('"("')),t===null&&(e.charCodeAt(n)===41?(t=")",n++):(t=null,m('")"')))))))))),t}function L(){var t,o,u,d,T;return d=n,T=n,e.charCodeAt(n)===37?(t="%",n++):(t=null,m('"%"')),t!==null?(o=I(),o!==null?(u=I(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E,y){return y.join("")}(d,t)),t===null&&(n=d),t}function q(){var t,o,u,d,T,E;for(d=n,T=n,E=n,t=[],o=V();o!==null;)t.push(o),o=V();if(t!==null?(o=C(),o!==null?t=[t,o]:(t=null,n=E)):(t=null,n=E),t=t!==null?t:"",t!==null){if(u=V(),u!==null)for(o=[];u!==null;)o.push(u),u=V();else o=null;o!==null?t=[t,o]:(t=null,n=T)}else t=null,n=T;return t!==null&&(t=function(y){return" "}()),t===null&&(n=d),t}function j(){var t;return t=q(),t=t!==null?t:"",t}function B(){var t,o,u,d,T;for(d=n,T=n,t=[],o=x(),o===null&&(o=$());o!==null;)t.push(o),o=x(),o===null&&(o=$());return t!==null?(e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o!==null?(u=j(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E){return":"}()),t===null&&(n=d),t}function X(){var t,o,u,d,T,E,y;if(T=n,E=n,o=Q(),o!==null)for(t=[];o!==null;)t.push(o),o=Q();else t=null;if(t!==null){for(o=[],y=n,u=[],d=q();d!==null;)u.push(d),d=q();for(u!==null?(d=Q(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);u!==null;){for(o.push(u),y=n,u=[],d=q();d!==null;)u.push(d),d=q();u!==null?(d=Q(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y)}o!==null?t=[t,o]:(t=null,n=E)}else t=null,n=E;return t!==null&&(t=function(O){return e.substring(n,O)}(T)),t===null&&(n=T),t}function Q(){var t;return/^[!-~]/.test(e.charAt(n))?(t=e.charAt(n),n++):(t=null,m("[!-~]")),t===null&&(t=U()),t}function U(){var t;return/^[\x80-\uFFFF]/.test(e.charAt(n))?(t=e.charAt(n),n++):(t=null,m("[\\x80-\\uFFFF]")),t}function se(){var t;return/^[\x80-\xBF]/.test(e.charAt(n))?(t=e.charAt(n),n++):(t=null,m("[\\x80-\\xBF]")),t}function It(){var t;return t=A(),t===null&&(/^[a-f]/.test(e.charAt(n))?(t=e.charAt(n),n++):(t=null,m("[a-f]"))),t}function N(){var t,o,u;if(u=n,o=Re(),o===null&&(e.charCodeAt(n)===45?(o="-",n++):(o=null,m('"-"')),o===null&&(e.charCodeAt(n)===46?(o=".",n++):(o=null,m('"."')),o===null&&(e.charCodeAt(n)===33?(o="!",n++):(o=null,m('"!"')),o===null&&(e.charCodeAt(n)===37?(o="%",n++):(o=null,m('"%"')),o===null&&(e.charCodeAt(n)===42?(o="*",n++):(o=null,m('"*"')),o===null&&(e.charCodeAt(n)===95?(o="_",n++):(o=null,m('"_"')),o===null&&(e.charCodeAt(n)===43?(o="+",n++):(o=null,m('"+"')),o===null&&(e.charCodeAt(n)===96?(o="`",n++):(o=null,m('"`"')),o===null&&(e.charCodeAt(n)===39?(o="'",n++):(o=null,m(`"'"`)),o===null&&(e.charCodeAt(n)===126?(o="~",n++):(o=null,m('"~"')))))))))))),o!==null)for(t=[];o!==null;)t.push(o),o=Re(),o===null&&(e.charCodeAt(n)===45?(o="-",n++):(o=null,m('"-"')),o===null&&(e.charCodeAt(n)===46?(o=".",n++):(o=null,m('"."')),o===null&&(e.charCodeAt(n)===33?(o="!",n++):(o=null,m('"!"')),o===null&&(e.charCodeAt(n)===37?(o="%",n++):(o=null,m('"%"')),o===null&&(e.charCodeAt(n)===42?(o="*",n++):(o=null,m('"*"')),o===null&&(e.charCodeAt(n)===95?(o="_",n++):(o=null,m('"_"')),o===null&&(e.charCodeAt(n)===43?(o="+",n++):(o=null,m('"+"')),o===null&&(e.charCodeAt(n)===96?(o="`",n++):(o=null,m('"`"')),o===null&&(e.charCodeAt(n)===39?(o="'",n++):(o=null,m(`"'"`)),o===null&&(e.charCodeAt(n)===126?(o="~",n++):(o=null,m('"~"'))))))))))));else t=null;return t!==null&&(t=function(d){return e.substring(n,d)}(u)),t===null&&(n=u),t}function Y(){var t,o,u;if(u=n,o=Re(),o===null&&(e.charCodeAt(n)===45?(o="-",n++):(o=null,m('"-"')),o===null&&(e.charCodeAt(n)===33?(o="!",n++):(o=null,m('"!"')),o===null&&(e.charCodeAt(n)===37?(o="%",n++):(o=null,m('"%"')),o===null&&(e.charCodeAt(n)===42?(o="*",n++):(o=null,m('"*"')),o===null&&(e.charCodeAt(n)===95?(o="_",n++):(o=null,m('"_"')),o===null&&(e.charCodeAt(n)===43?(o="+",n++):(o=null,m('"+"')),o===null&&(e.charCodeAt(n)===96?(o="`",n++):(o=null,m('"`"')),o===null&&(e.charCodeAt(n)===39?(o="'",n++):(o=null,m(`"'"`)),o===null&&(e.charCodeAt(n)===126?(o="~",n++):(o=null,m('"~"'))))))))))),o!==null)for(t=[];o!==null;)t.push(o),o=Re(),o===null&&(e.charCodeAt(n)===45?(o="-",n++):(o=null,m('"-"')),o===null&&(e.charCodeAt(n)===33?(o="!",n++):(o=null,m('"!"')),o===null&&(e.charCodeAt(n)===37?(o="%",n++):(o=null,m('"%"')),o===null&&(e.charCodeAt(n)===42?(o="*",n++):(o=null,m('"*"')),o===null&&(e.charCodeAt(n)===95?(o="_",n++):(o=null,m('"_"')),o===null&&(e.charCodeAt(n)===43?(o="+",n++):(o=null,m('"+"')),o===null&&(e.charCodeAt(n)===96?(o="`",n++):(o=null,m('"`"')),o===null&&(e.charCodeAt(n)===39?(o="'",n++):(o=null,m(`"'"`)),o===null&&(e.charCodeAt(n)===126?(o="~",n++):(o=null,m('"~"')))))))))));else t=null;return t!==null&&(t=function(d){return e.substring(n,d)}(u)),t===null&&(n=u),t}function re(){var t;return e.charCodeAt(n)===40?(t="(",n++):(t=null,m('"("')),t===null&&(e.charCodeAt(n)===41?(t=")",n++):(t=null,m('")"')),t===null&&(e.charCodeAt(n)===60?(t="<",n++):(t=null,m('"<"')),t===null&&(e.charCodeAt(n)===62?(t=">",n++):(t=null,m('">"')),t===null&&(e.charCodeAt(n)===64?(t="@",n++):(t=null,m('"@"')),t===null&&(e.charCodeAt(n)===44?(t=",",n++):(t=null,m('","')),t===null&&(e.charCodeAt(n)===59?(t=";",n++):(t=null,m('";"')),t===null&&(e.charCodeAt(n)===58?(t=":",n++):(t=null,m('":"')),t===null&&(e.charCodeAt(n)===92?(t="\\",n++):(t=null,m('"\\\\"')),t===null&&(t=oe(),t===null&&(e.charCodeAt(n)===47?(t="/",n++):(t=null,m('"/"')),t===null&&(e.charCodeAt(n)===91?(t="[",n++):(t=null,m('"["')),t===null&&(e.charCodeAt(n)===93?(t="]",n++):(t=null,m('"]"')),t===null&&(e.charCodeAt(n)===63?(t="?",n++):(t=null,m('"?"')),t===null&&(e.charCodeAt(n)===61?(t="=",n++):(t=null,m('"="')),t===null&&(e.charCodeAt(n)===123?(t="{",n++):(t=null,m('"{"')),t===null&&(e.charCodeAt(n)===125?(t="}",n++):(t=null,m('"}"')),t===null&&(t=x(),t===null&&(t=$())))))))))))))))))),t}function ae(){var t,o,u;if(u=n,o=Re(),o===null&&(e.charCodeAt(n)===45?(o="-",n++):(o=null,m('"-"')),o===null&&(e.charCodeAt(n)===46?(o=".",n++):(o=null,m('"."')),o===null&&(e.charCodeAt(n)===33?(o="!",n++):(o=null,m('"!"')),o===null&&(e.charCodeAt(n)===37?(o="%",n++):(o=null,m('"%"')),o===null&&(e.charCodeAt(n)===42?(o="*",n++):(o=null,m('"*"')),o===null&&(e.charCodeAt(n)===95?(o="_",n++):(o=null,m('"_"')),o===null&&(e.charCodeAt(n)===43?(o="+",n++):(o=null,m('"+"')),o===null&&(e.charCodeAt(n)===96?(o="`",n++):(o=null,m('"`"')),o===null&&(e.charCodeAt(n)===39?(o="'",n++):(o=null,m(`"'"`)),o===null&&(e.charCodeAt(n)===126?(o="~",n++):(o=null,m('"~"')),o===null&&(e.charCodeAt(n)===40?(o="(",n++):(o=null,m('"("')),o===null&&(e.charCodeAt(n)===41?(o=")",n++):(o=null,m('")"')),o===null&&(e.charCodeAt(n)===60?(o="<",n++):(o=null,m('"<"')),o===null&&(e.charCodeAt(n)===62?(o=">",n++):(o=null,m('">"')),o===null&&(e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o===null&&(e.charCodeAt(n)===92?(o="\\",n++):(o=null,m('"\\\\"')),o===null&&(o=oe(),o===null&&(e.charCodeAt(n)===47?(o="/",n++):(o=null,m('"/"')),o===null&&(e.charCodeAt(n)===91?(o="[",n++):(o=null,m('"["')),o===null&&(e.charCodeAt(n)===93?(o="]",n++):(o=null,m('"]"')),o===null&&(e.charCodeAt(n)===63?(o="?",n++):(o=null,m('"?"')),o===null&&(e.charCodeAt(n)===123?(o="{",n++):(o=null,m('"{"')),o===null&&(e.charCodeAt(n)===125?(o="}",n++):(o=null,m('"}"'))))))))))))))))))))))))),o!==null)for(t=[];o!==null;)t.push(o),o=Re(),o===null&&(e.charCodeAt(n)===45?(o="-",n++):(o=null,m('"-"')),o===null&&(e.charCodeAt(n)===46?(o=".",n++):(o=null,m('"."')),o===null&&(e.charCodeAt(n)===33?(o="!",n++):(o=null,m('"!"')),o===null&&(e.charCodeAt(n)===37?(o="%",n++):(o=null,m('"%"')),o===null&&(e.charCodeAt(n)===42?(o="*",n++):(o=null,m('"*"')),o===null&&(e.charCodeAt(n)===95?(o="_",n++):(o=null,m('"_"')),o===null&&(e.charCodeAt(n)===43?(o="+",n++):(o=null,m('"+"')),o===null&&(e.charCodeAt(n)===96?(o="`",n++):(o=null,m('"`"')),o===null&&(e.charCodeAt(n)===39?(o="'",n++):(o=null,m(`"'"`)),o===null&&(e.charCodeAt(n)===126?(o="~",n++):(o=null,m('"~"')),o===null&&(e.charCodeAt(n)===40?(o="(",n++):(o=null,m('"("')),o===null&&(e.charCodeAt(n)===41?(o=")",n++):(o=null,m('")"')),o===null&&(e.charCodeAt(n)===60?(o="<",n++):(o=null,m('"<"')),o===null&&(e.charCodeAt(n)===62?(o=">",n++):(o=null,m('">"')),o===null&&(e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o===null&&(e.charCodeAt(n)===92?(o="\\",n++):(o=null,m('"\\\\"')),o===null&&(o=oe(),o===null&&(e.charCodeAt(n)===47?(o="/",n++):(o=null,m('"/"')),o===null&&(e.charCodeAt(n)===91?(o="[",n++):(o=null,m('"["')),o===null&&(e.charCodeAt(n)===93?(o="]",n++):(o=null,m('"]"')),o===null&&(e.charCodeAt(n)===63?(o="?",n++):(o=null,m('"?"')),o===null&&(e.charCodeAt(n)===123?(o="{",n++):(o=null,m('"{"')),o===null&&(e.charCodeAt(n)===125?(o="}",n++):(o=null,m('"}"')))))))))))))))))))))))));else t=null;return t!==null&&(t=function(d){return e.substring(n,d)}(u)),t===null&&(n=u),t}function Te(){var t,o,u,d,T;return d=n,T=n,t=j(),t!==null?(e.charCodeAt(n)===42?(o="*",n++):(o=null,m('"*"')),o!==null?(u=j(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E){return"*"}()),t===null&&(n=d),t}function De(){var t,o,u,d,T;return d=n,T=n,t=j(),t!==null?(e.charCodeAt(n)===47?(o="/",n++):(o=null,m('"/"')),o!==null?(u=j(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E){return"/"}()),t===null&&(n=d),t}function Ce(){var t,o,u,d,T;return d=n,T=n,t=j(),t!==null?(e.charCodeAt(n)===61?(o="=",n++):(o=null,m('"="')),o!==null?(u=j(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E){return"="}()),t===null&&(n=d),t}function Le(){var t,o,u,d,T;return d=n,T=n,t=j(),t!==null?(e.charCodeAt(n)===40?(o="(",n++):(o=null,m('"("')),o!==null?(u=j(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E){return"("}()),t===null&&(n=d),t}function we(){var t,o,u,d,T;return d=n,T=n,t=j(),t!==null?(e.charCodeAt(n)===41?(o=")",n++):(o=null,m('")"')),o!==null?(u=j(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E){return")"}()),t===null&&(n=d),t}function Se(){var t,o,u,d;return u=n,d=n,e.charCodeAt(n)===62?(t=">",n++):(t=null,m('">"')),t!==null?(o=j(),o!==null?t=[t,o]:(t=null,n=d)):(t=null,n=d),t!==null&&(t=function(T){return">"}()),t===null&&(n=u),t}function it(){var t,o,u,d;return u=n,d=n,t=j(),t!==null?(e.charCodeAt(n)===60?(o="<",n++):(o=null,m('"<"')),o!==null?t=[t,o]:(t=null,n=d)):(t=null,n=d),t!==null&&(t=function(T){return"<"}()),t===null&&(n=u),t}function Ue(){var t,o,u,d,T;return d=n,T=n,t=j(),t!==null?(e.charCodeAt(n)===44?(o=",",n++):(o=null,m('","')),o!==null?(u=j(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E){return","}()),t===null&&(n=d),t}function le(){var t,o,u,d,T;return d=n,T=n,t=j(),t!==null?(e.charCodeAt(n)===59?(o=";",n++):(o=null,m('";"')),o!==null?(u=j(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E){return";"}()),t===null&&(n=d),t}function Ae(){var t,o,u,d,T;return d=n,T=n,t=j(),t!==null?(e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o!==null?(u=j(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E){return":"}()),t===null&&(n=d),t}function Oe(){var t,o,u,d;return u=n,d=n,t=j(),t!==null?(o=oe(),o!==null?t=[t,o]:(t=null,n=d)):(t=null,n=d),t!==null&&(t=function(T){return'"'}()),t===null&&(n=u),t}function Pe(){var t,o,u,d;return u=n,d=n,t=oe(),t!==null?(o=j(),o!==null?t=[t,o]:(t=null,n=d)):(t=null,n=d),t!==null&&(t=function(T){return'"'}()),t===null&&(n=u),t}function ve(){var t,o,u,d;if(d=n,t=Le(),t!==null){for(o=[],u=he(),u===null&&(u=Ve(),u===null&&(u=ve()));u!==null;)o.push(u),u=he(),u===null&&(u=Ve(),u===null&&(u=ve()));o!==null?(u=we(),u!==null?t=[t,o,u]:(t=null,n=d)):(t=null,n=d)}else t=null,n=d;return t}function he(){var t;return/^[!-']/.test(e.charAt(n))?(t=e.charAt(n),n++):(t=null,m("[!-']")),t===null&&(/^[*-[]/.test(e.charAt(n))?(t=e.charAt(n),n++):(t=null,m("[*-[]")),t===null&&(/^[\]-~]/.test(e.charAt(n))?(t=e.charAt(n),n++):(t=null,m("[\\]-~]")),t===null&&(t=U(),t===null&&(t=q())))),t}function pe(){var t,o,u,d,T,E;if(T=n,E=n,t=j(),t!==null)if(o=oe(),o!==null){for(u=[],d=xe(),d===null&&(d=Ve());d!==null;)u.push(d),d=xe(),d===null&&(d=Ve());u!==null?(d=oe(),d!==null?t=[t,o,u,d]:(t=null,n=E)):(t=null,n=E)}else t=null,n=E;else t=null,n=E;return t!==null&&(t=function(y){return e.substring(n,y)}(T)),t===null&&(n=T),t}function Ne(){var t,o,u,d,T,E;if(T=n,E=n,t=j(),t!==null)if(o=oe(),o!==null){for(u=[],d=xe(),d===null&&(d=Ve());d!==null;)u.push(d),d=xe(),d===null&&(d=Ve());u!==null?(d=oe(),d!==null?t=[t,o,u,d]:(t=null,n=E)):(t=null,n=E)}else t=null,n=E;else t=null,n=E;return t!==null&&(t=function(y){var O=e.substring(n,y).trim();return O.substring(1,O.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(T)),t===null&&(n=T),t}function xe(){var t;return t=q(),t===null&&(e.charCodeAt(n)===33?(t="!",n++):(t=null,m('"!"')),t===null&&(/^[#-[]/.test(e.charAt(n))?(t=e.charAt(n),n++):(t=null,m("[#-[]")),t===null&&(/^[\]-~]/.test(e.charAt(n))?(t=e.charAt(n),n++):(t=null,m("[\\]-~]")),t===null&&(t=U())))),t}function Ve(){var t,o,u;return u=n,e.charCodeAt(n)===92?(t="\\",n++):(t=null,m('"\\\\"')),t!==null?(/^[\0-\t]/.test(e.charAt(n))?(o=e.charAt(n),n++):(o=null,m("[\\0-\\t]")),o===null&&(/^[\x0B-\f]/.test(e.charAt(n))?(o=e.charAt(n),n++):(o=null,m("[\\x0B-\\f]")),o===null&&(/^[\x0E-]/.test(e.charAt(n))?(o=e.charAt(n),n++):(o=null,m("[\\x0E-]")))),o!==null?t=[t,o]:(t=null,n=u)):(t=null,n=u),t}function He(){var t,o,u,d,T,E;return T=n,E=n,t=ct(),t!==null?(e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o!==null?(u=sn(),u=u!==null?u:"",u!==null?(d=ws(),d!==null?t=[t,o,u,d]:(t=null,n=E)):(t=null,n=E)):(t=null,n=E)):(t=null,n=E),t!==null&&(t=function(y){try{w.uri=new Bl(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}}()),t===null&&(n=T),t}function Ht(){var t,o,u,d,T,E,y,O;return y=n,O=n,t=ct(),t!==null?(e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o!==null?(u=sn(),u=u!==null?u:"",u!==null?(d=ws(),d!==null?(T=dr(),T!==null?(E=Cr(),E=E!==null?E:"",E!==null?t=[t,o,u,d,T,E]:(t=null,n=O)):(t=null,n=O)):(t=null,n=O)):(t=null,n=O)):(t=null,n=O)):(t=null,n=O),t!==null&&(t=function(G){try{w.uri=new Bl(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,p==="SIP_URI"&&(w=w.uri)}catch{w=-1}}()),t===null&&(n=y),t}function ct(){var t;return t=_r(),t===null&&(t=Mn()),t}function _r(){var t,o;return o=n,e.substr(n,4).toLowerCase()==="sips"?(t=e.substr(n,4),n+=4):(t=null,m('"sips"')),t!==null&&(t=function(u,d){w.scheme=d.toLowerCase()}(o,t)),t===null&&(n=o),t}function Mn(){var t,o;return o=n,e.substr(n,3).toLowerCase()==="sip"?(t=e.substr(n,3),n+=3):(t=null,m('"sip"')),t!==null&&(t=function(u,d){w.scheme=d.toLowerCase()}(o,t)),t===null&&(n=o),t}function sn(){var t,o,u,d,T,E;return d=n,T=n,t=nn(),t!==null?(E=n,e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o!==null?(u=kn(),u!==null?o=[o,u]:(o=null,n=E)):(o=null,n=E),o=o!==null?o:"",o!==null?(e.charCodeAt(n)===64?(u="@",n++):(u=null,m('"@"')),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(y){w.user=decodeURIComponent(e.substring(n-1,y))}(d)),t===null&&(n=d),t}function nn(){var t,o;if(o=H(),o===null&&(o=L(),o===null&&(o=cs())),o!==null)for(t=[];o!==null;)t.push(o),o=H(),o===null&&(o=L(),o===null&&(o=cs()));else t=null;return t}function cs(){var t;return e.charCodeAt(n)===38?(t="&",n++):(t=null,m('"&"')),t===null&&(e.charCodeAt(n)===61?(t="=",n++):(t=null,m('"="')),t===null&&(e.charCodeAt(n)===43?(t="+",n++):(t=null,m('"+"')),t===null&&(e.charCodeAt(n)===36?(t="$",n++):(t=null,m('"$"')),t===null&&(e.charCodeAt(n)===44?(t=",",n++):(t=null,m('","')),t===null&&(e.charCodeAt(n)===59?(t=";",n++):(t=null,m('";"')),t===null&&(e.charCodeAt(n)===63?(t="?",n++):(t=null,m('"?"')),t===null&&(e.charCodeAt(n)===47?(t="/",n++):(t=null,m('"/"'))))))))),t}function kn(){var t,o,u;for(u=n,t=[],o=H(),o===null&&(o=L(),o===null&&(e.charCodeAt(n)===38?(o="&",n++):(o=null,m('"&"')),o===null&&(e.charCodeAt(n)===61?(o="=",n++):(o=null,m('"="')),o===null&&(e.charCodeAt(n)===43?(o="+",n++):(o=null,m('"+"')),o===null&&(e.charCodeAt(n)===36?(o="$",n++):(o=null,m('"$"')),o===null&&(e.charCodeAt(n)===44?(o=",",n++):(o=null,m('","'))))))));o!==null;)t.push(o),o=H(),o===null&&(o=L(),o===null&&(e.charCodeAt(n)===38?(o="&",n++):(o=null,m('"&"')),o===null&&(e.charCodeAt(n)===61?(o="=",n++):(o=null,m('"="')),o===null&&(e.charCodeAt(n)===43?(o="+",n++):(o=null,m('"+"')),o===null&&(e.charCodeAt(n)===36?(o="$",n++):(o=null,m('"$"')),o===null&&(e.charCodeAt(n)===44?(o=",",n++):(o=null,m('","'))))))));return t!==null&&(t=function(d){w.password=e.substring(n,d)}(u)),t===null&&(n=u),t}function ws(){var t,o,u,d,T;return d=n,t=Os(),t!==null?(T=n,e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o!==null?(u=hr(),u!==null?o=[o,u]:(o=null,n=T)):(o=null,n=T),o=o!==null?o:"",o!==null?t=[t,o]:(t=null,n=d)):(t=null,n=d),t}function Os(){var t,o;return o=n,t=rn(),t===null&&(t=Ds(),t===null&&(t=pt())),t!==null&&(t=function(u){return w.host=e.substring(n,u).toLowerCase(),w.host}(o)),t===null&&(n=o),t}function rn(){var t,o,u,d,T,E;for(d=n,T=n,t=[],E=n,o=ln(),o!==null?(e.charCodeAt(n)===46?(u=".",n++):(u=null,m('"."')),u!==null?o=[o,u]:(o=null,n=E)):(o=null,n=E);o!==null;)t.push(o),E=n,o=ln(),o!==null?(e.charCodeAt(n)===46?(u=".",n++):(u=null,m('"."')),u!==null?o=[o,u]:(o=null,n=E)):(o=null,n=E);return t!==null?(o=ge(),o!==null?(e.charCodeAt(n)===46?(u=".",n++):(u=null,m('"."')),u=u!==null?u:"",u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(y){return w.host_type="domain",e.substring(n,y)}(d)),t===null&&(n=d),t}function ln(){var t,o,u,d;if(d=n,t=Re(),t!==null){for(o=[],u=Re(),u===null&&(e.charCodeAt(n)===45?(u="-",n++):(u=null,m('"-"')),u===null&&(e.charCodeAt(n)===95?(u="_",n++):(u=null,m('"_"'))));u!==null;)o.push(u),u=Re(),u===null&&(e.charCodeAt(n)===45?(u="-",n++):(u=null,m('"-"')),u===null&&(e.charCodeAt(n)===95?(u="_",n++):(u=null,m('"_"'))));o!==null?t=[t,o]:(t=null,n=d)}else t=null,n=d;return t}function ge(){var t,o,u,d;if(d=n,t=R(),t!==null){for(o=[],u=Re(),u===null&&(e.charCodeAt(n)===45?(u="-",n++):(u=null,m('"-"')),u===null&&(e.charCodeAt(n)===95?(u="_",n++):(u=null,m('"_"'))));u!==null;)o.push(u),u=Re(),u===null&&(e.charCodeAt(n)===45?(u="-",n++):(u=null,m('"-"')),u===null&&(e.charCodeAt(n)===95?(u="_",n++):(u=null,m('"_"'))));o!==null?t=[t,o]:(t=null,n=d)}else t=null,n=d;return t}function pt(){var t,o,u,d,T;return d=n,T=n,e.charCodeAt(n)===91?(t="[",n++):(t=null,m('"["')),t!==null?(o=fs(),o!==null?(e.charCodeAt(n)===93?(u="]",n++):(u=null,m('"]"')),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E){return w.host_type="IPv6",e.substring(n,E)}(d)),t===null&&(n=d),t}function fs(){var t,o,u,d,T,E,y,O,G,ye,Fe,P,me,Ii,k,Ee;return Ii=n,k=n,t=de(),t!==null?(e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o!==null?(u=de(),u!==null?(e.charCodeAt(n)===58?(d=":",n++):(d=null,m('":"')),d!==null?(T=de(),T!==null?(e.charCodeAt(n)===58?(E=":",n++):(E=null,m('":"')),E!==null?(y=de(),y!==null?(e.charCodeAt(n)===58?(O=":",n++):(O=null,m('":"')),O!==null?(G=de(),G!==null?(e.charCodeAt(n)===58?(ye=":",n++):(ye=null,m('":"')),ye!==null?(Fe=de(),Fe!==null?(e.charCodeAt(n)===58?(P=":",n++):(P=null,m('":"')),P!==null?(me=bt(),me!==null?t=[t,o,u,d,T,E,y,O,G,ye,Fe,P,me]:(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k),t===null&&(k=n,e.substr(n,2)==="::"?(t="::",n+=2):(t=null,m('"::"')),t!==null?(o=de(),o!==null?(e.charCodeAt(n)===58?(u=":",n++):(u=null,m('":"')),u!==null?(d=de(),d!==null?(e.charCodeAt(n)===58?(T=":",n++):(T=null,m('":"')),T!==null?(E=de(),E!==null?(e.charCodeAt(n)===58?(y=":",n++):(y=null,m('":"')),y!==null?(O=de(),O!==null?(e.charCodeAt(n)===58?(G=":",n++):(G=null,m('":"')),G!==null?(ye=de(),ye!==null?(e.charCodeAt(n)===58?(Fe=":",n++):(Fe=null,m('":"')),Fe!==null?(P=bt(),P!==null?t=[t,o,u,d,T,E,y,O,G,ye,Fe,P]:(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k),t===null&&(k=n,e.substr(n,2)==="::"?(t="::",n+=2):(t=null,m('"::"')),t!==null?(o=de(),o!==null?(e.charCodeAt(n)===58?(u=":",n++):(u=null,m('":"')),u!==null?(d=de(),d!==null?(e.charCodeAt(n)===58?(T=":",n++):(T=null,m('":"')),T!==null?(E=de(),E!==null?(e.charCodeAt(n)===58?(y=":",n++):(y=null,m('":"')),y!==null?(O=de(),O!==null?(e.charCodeAt(n)===58?(G=":",n++):(G=null,m('":"')),G!==null?(ye=bt(),ye!==null?t=[t,o,u,d,T,E,y,O,G,ye]:(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k),t===null&&(k=n,e.substr(n,2)==="::"?(t="::",n+=2):(t=null,m('"::"')),t!==null?(o=de(),o!==null?(e.charCodeAt(n)===58?(u=":",n++):(u=null,m('":"')),u!==null?(d=de(),d!==null?(e.charCodeAt(n)===58?(T=":",n++):(T=null,m('":"')),T!==null?(E=de(),E!==null?(e.charCodeAt(n)===58?(y=":",n++):(y=null,m('":"')),y!==null?(O=bt(),O!==null?t=[t,o,u,d,T,E,y,O]:(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k),t===null&&(k=n,e.substr(n,2)==="::"?(t="::",n+=2):(t=null,m('"::"')),t!==null?(o=de(),o!==null?(e.charCodeAt(n)===58?(u=":",n++):(u=null,m('":"')),u!==null?(d=de(),d!==null?(e.charCodeAt(n)===58?(T=":",n++):(T=null,m('":"')),T!==null?(E=bt(),E!==null?t=[t,o,u,d,T,E]:(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k),t===null&&(k=n,e.substr(n,2)==="::"?(t="::",n+=2):(t=null,m('"::"')),t!==null?(o=de(),o!==null?(e.charCodeAt(n)===58?(u=":",n++):(u=null,m('":"')),u!==null?(d=bt(),d!==null?t=[t,o,u,d]:(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k),t===null&&(k=n,e.substr(n,2)==="::"?(t="::",n+=2):(t=null,m('"::"')),t!==null?(o=bt(),o!==null?t=[t,o]:(t=null,n=k)):(t=null,n=k),t===null&&(k=n,e.substr(n,2)==="::"?(t="::",n+=2):(t=null,m('"::"')),t!==null?(o=de(),o!==null?t=[t,o]:(t=null,n=k)):(t=null,n=k),t===null&&(k=n,t=de(),t!==null?(e.substr(n,2)==="::"?(o="::",n+=2):(o=null,m('"::"')),o!==null?(u=de(),u!==null?(e.charCodeAt(n)===58?(d=":",n++):(d=null,m('":"')),d!==null?(T=de(),T!==null?(e.charCodeAt(n)===58?(E=":",n++):(E=null,m('":"')),E!==null?(y=de(),y!==null?(e.charCodeAt(n)===58?(O=":",n++):(O=null,m('":"')),O!==null?(G=de(),G!==null?(e.charCodeAt(n)===58?(ye=":",n++):(ye=null,m('":"')),ye!==null?(Fe=bt(),Fe!==null?t=[t,o,u,d,T,E,y,O,G,ye,Fe]:(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k),t===null&&(k=n,t=de(),t!==null?(Ee=n,e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o!==null?(u=de(),u!==null?o=[o,u]:(o=null,n=Ee)):(o=null,n=Ee),o=o!==null?o:"",o!==null?(e.substr(n,2)==="::"?(u="::",n+=2):(u=null,m('"::"')),u!==null?(d=de(),d!==null?(e.charCodeAt(n)===58?(T=":",n++):(T=null,m('":"')),T!==null?(E=de(),E!==null?(e.charCodeAt(n)===58?(y=":",n++):(y=null,m('":"')),y!==null?(O=de(),O!==null?(e.charCodeAt(n)===58?(G=":",n++):(G=null,m('":"')),G!==null?(ye=bt(),ye!==null?t=[t,o,u,d,T,E,y,O,G,ye]:(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k),t===null&&(k=n,t=de(),t!==null?(Ee=n,e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o!==null?(u=de(),u!==null?o=[o,u]:(o=null,n=Ee)):(o=null,n=Ee),o=o!==null?o:"",o!==null?(Ee=n,e.charCodeAt(n)===58?(u=":",n++):(u=null,m('":"')),u!==null?(d=de(),d!==null?u=[u,d]:(u=null,n=Ee)):(u=null,n=Ee),u=u!==null?u:"",u!==null?(e.substr(n,2)==="::"?(d="::",n+=2):(d=null,m('"::"')),d!==null?(T=de(),T!==null?(e.charCodeAt(n)===58?(E=":",n++):(E=null,m('":"')),E!==null?(y=de(),y!==null?(e.charCodeAt(n)===58?(O=":",n++):(O=null,m('":"')),O!==null?(G=bt(),G!==null?t=[t,o,u,d,T,E,y,O,G]:(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k),t===null&&(k=n,t=de(),t!==null?(Ee=n,e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o!==null?(u=de(),u!==null?o=[o,u]:(o=null,n=Ee)):(o=null,n=Ee),o=o!==null?o:"",o!==null?(Ee=n,e.charCodeAt(n)===58?(u=":",n++):(u=null,m('":"')),u!==null?(d=de(),d!==null?u=[u,d]:(u=null,n=Ee)):(u=null,n=Ee),u=u!==null?u:"",u!==null?(Ee=n,e.charCodeAt(n)===58?(d=":",n++):(d=null,m('":"')),d!==null?(T=de(),T!==null?d=[d,T]:(d=null,n=Ee)):(d=null,n=Ee),d=d!==null?d:"",d!==null?(e.substr(n,2)==="::"?(T="::",n+=2):(T=null,m('"::"')),T!==null?(E=de(),E!==null?(e.charCodeAt(n)===58?(y=":",n++):(y=null,m('":"')),y!==null?(O=bt(),O!==null?t=[t,o,u,d,T,E,y,O]:(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k),t===null&&(k=n,t=de(),t!==null?(Ee=n,e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o!==null?(u=de(),u!==null?o=[o,u]:(o=null,n=Ee)):(o=null,n=Ee),o=o!==null?o:"",o!==null?(Ee=n,e.charCodeAt(n)===58?(u=":",n++):(u=null,m('":"')),u!==null?(d=de(),d!==null?u=[u,d]:(u=null,n=Ee)):(u=null,n=Ee),u=u!==null?u:"",u!==null?(Ee=n,e.charCodeAt(n)===58?(d=":",n++):(d=null,m('":"')),d!==null?(T=de(),T!==null?d=[d,T]:(d=null,n=Ee)):(d=null,n=Ee),d=d!==null?d:"",d!==null?(Ee=n,e.charCodeAt(n)===58?(T=":",n++):(T=null,m('":"')),T!==null?(E=de(),E!==null?T=[T,E]:(T=null,n=Ee)):(T=null,n=Ee),T=T!==null?T:"",T!==null?(e.substr(n,2)==="::"?(E="::",n+=2):(E=null,m('"::"')),E!==null?(y=bt(),y!==null?t=[t,o,u,d,T,E,y]:(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k),t===null&&(k=n,t=de(),t!==null?(Ee=n,e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o!==null?(u=de(),u!==null?o=[o,u]:(o=null,n=Ee)):(o=null,n=Ee),o=o!==null?o:"",o!==null?(Ee=n,e.charCodeAt(n)===58?(u=":",n++):(u=null,m('":"')),u!==null?(d=de(),d!==null?u=[u,d]:(u=null,n=Ee)):(u=null,n=Ee),u=u!==null?u:"",u!==null?(Ee=n,e.charCodeAt(n)===58?(d=":",n++):(d=null,m('":"')),d!==null?(T=de(),T!==null?d=[d,T]:(d=null,n=Ee)):(d=null,n=Ee),d=d!==null?d:"",d!==null?(Ee=n,e.charCodeAt(n)===58?(T=":",n++):(T=null,m('":"')),T!==null?(E=de(),E!==null?T=[T,E]:(T=null,n=Ee)):(T=null,n=Ee),T=T!==null?T:"",T!==null?(Ee=n,e.charCodeAt(n)===58?(E=":",n++):(E=null,m('":"')),E!==null?(y=de(),y!==null?E=[E,y]:(E=null,n=Ee)):(E=null,n=Ee),E=E!==null?E:"",E!==null?(e.substr(n,2)==="::"?(y="::",n+=2):(y=null,m('"::"')),y!==null?(O=de(),O!==null?t=[t,o,u,d,T,E,y,O]:(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k),t===null&&(k=n,t=de(),t!==null?(Ee=n,e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o!==null?(u=de(),u!==null?o=[o,u]:(o=null,n=Ee)):(o=null,n=Ee),o=o!==null?o:"",o!==null?(Ee=n,e.charCodeAt(n)===58?(u=":",n++):(u=null,m('":"')),u!==null?(d=de(),d!==null?u=[u,d]:(u=null,n=Ee)):(u=null,n=Ee),u=u!==null?u:"",u!==null?(Ee=n,e.charCodeAt(n)===58?(d=":",n++):(d=null,m('":"')),d!==null?(T=de(),T!==null?d=[d,T]:(d=null,n=Ee)):(d=null,n=Ee),d=d!==null?d:"",d!==null?(Ee=n,e.charCodeAt(n)===58?(T=":",n++):(T=null,m('":"')),T!==null?(E=de(),E!==null?T=[T,E]:(T=null,n=Ee)):(T=null,n=Ee),T=T!==null?T:"",T!==null?(Ee=n,e.charCodeAt(n)===58?(E=":",n++):(E=null,m('":"')),E!==null?(y=de(),y!==null?E=[E,y]:(E=null,n=Ee)):(E=null,n=Ee),E=E!==null?E:"",E!==null?(Ee=n,e.charCodeAt(n)===58?(y=":",n++):(y=null,m('":"')),y!==null?(O=de(),O!==null?y=[y,O]:(y=null,n=Ee)):(y=null,n=Ee),y=y!==null?y:"",y!==null?(e.substr(n,2)==="::"?(O="::",n+=2):(O=null,m('"::"')),O!==null?t=[t,o,u,d,T,E,y,O]:(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k)):(t=null,n=k))))))))))))))),t!==null&&(t=function(k_){return w.host_type="IPv6",e.substring(n,k_)}(Ii)),t===null&&(n=Ii),t}function de(){var t,o,u,d,T;return T=n,t=I(),t!==null?(o=I(),o=o!==null?o:"",o!==null?(u=I(),u=u!==null?u:"",u!==null?(d=I(),d=d!==null?d:"",d!==null?t=[t,o,u,d]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t}function bt(){var t,o,u,d;return d=n,t=de(),t!==null?(e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o!==null?(u=de(),u!==null?t=[t,o,u]:(t=null,n=d)):(t=null,n=d)):(t=null,n=d),t===null&&(t=Ds()),t}function Ds(){var t,o,u,d,T,E,y,O,G;return O=n,G=n,t=_s(),t!==null?(e.charCodeAt(n)===46?(o=".",n++):(o=null,m('"."')),o!==null?(u=_s(),u!==null?(e.charCodeAt(n)===46?(d=".",n++):(d=null,m('"."')),d!==null?(T=_s(),T!==null?(e.charCodeAt(n)===46?(E=".",n++):(E=null,m('"."')),E!==null?(y=_s(),y!==null?t=[t,o,u,d,T,E,y]:(t=null,n=G)):(t=null,n=G)):(t=null,n=G)):(t=null,n=G)):(t=null,n=G)):(t=null,n=G)):(t=null,n=G),t!==null&&(t=function(ye){return w.host_type="IPv4",e.substring(n,ye)}(O)),t===null&&(n=O),t}function _s(){var t,o,u,d;return d=n,e.substr(n,2)==="25"?(t="25",n+=2):(t=null,m('"25"')),t!==null?(/^[0-5]/.test(e.charAt(n))?(o=e.charAt(n),n++):(o=null,m("[0-5]")),o!==null?t=[t,o]:(t=null,n=d)):(t=null,n=d),t===null&&(d=n,e.charCodeAt(n)===50?(t="2",n++):(t=null,m('"2"')),t!==null?(/^[0-4]/.test(e.charAt(n))?(o=e.charAt(n),n++):(o=null,m("[0-4]")),o!==null?(u=A(),u!==null?t=[t,o,u]:(t=null,n=d)):(t=null,n=d)):(t=null,n=d),t===null&&(d=n,e.charCodeAt(n)===49?(t="1",n++):(t=null,m('"1"')),t!==null?(o=A(),o!==null?(u=A(),u!==null?t=[t,o,u]:(t=null,n=d)):(t=null,n=d)):(t=null,n=d),t===null&&(d=n,/^[1-9]/.test(e.charAt(n))?(t=e.charAt(n),n++):(t=null,m("[1-9]")),t!==null?(o=A(),o!==null?t=[t,o]:(t=null,n=d)):(t=null,n=d),t===null&&(t=A())))),t}function hr(){var t,o,u,d,T,E,y;return E=n,y=n,t=A(),t=t!==null?t:"",t!==null?(o=A(),o=o!==null?o:"",o!==null?(u=A(),u=u!==null?u:"",u!==null?(d=A(),d=d!==null?d:"",d!==null?(T=A(),T=T!==null?T:"",T!==null?t=[t,o,u,d,T]:(t=null,n=y)):(t=null,n=y)):(t=null,n=y)):(t=null,n=y)):(t=null,n=y),t!==null&&(t=function(O,G){return G=parseInt(G.join("")),w.port=G,G}(E,t)),t===null&&(n=E),t}function dr(){var t,o,u,d;for(t=[],d=n,e.charCodeAt(n)===59?(o=";",n++):(o=null,m('";"')),o!==null?(u=Ln(),u!==null?o=[o,u]:(o=null,n=d)):(o=null,n=d);o!==null;)t.push(o),d=n,e.charCodeAt(n)===59?(o=";",n++):(o=null,m('";"')),o!==null?(u=Ln(),u!==null?o=[o,u]:(o=null,n=d)):(o=null,n=d);return t}function Ln(){var t;return t=pr(),t===null&&(t=mr(),t===null&&(t=gr(),t===null&&(t=Tr(),t===null&&(t=vr(),t===null&&(t=Er(),t===null&&(t=Ns())))))),t}function pr(){var t,o,u,d;return u=n,d=n,e.substr(n,10).toLowerCase()==="transport="?(t=e.substr(n,10),n+=10):(t=null,m('"transport="')),t!==null?(e.substr(n,3).toLowerCase()==="udp"?(o=e.substr(n,3),n+=3):(o=null,m('"udp"')),o===null&&(e.substr(n,3).toLowerCase()==="tcp"?(o=e.substr(n,3),n+=3):(o=null,m('"tcp"')),o===null&&(e.substr(n,4).toLowerCase()==="sctp"?(o=e.substr(n,4),n+=4):(o=null,m('"sctp"')),o===null&&(e.substr(n,3).toLowerCase()==="tls"?(o=e.substr(n,3),n+=3):(o=null,m('"tls"')),o===null&&(o=N())))),o!==null?t=[t,o]:(t=null,n=d)):(t=null,n=d),t!==null&&(t=function(T,E){w.uri_params||(w.uri_params={}),w.uri_params.transport=E.toLowerCase()}(u,t[1])),t===null&&(n=u),t}function mr(){var t,o,u,d;return u=n,d=n,e.substr(n,5).toLowerCase()==="user="?(t=e.substr(n,5),n+=5):(t=null,m('"user="')),t!==null?(e.substr(n,5).toLowerCase()==="phone"?(o=e.substr(n,5),n+=5):(o=null,m('"phone"')),o===null&&(e.substr(n,2).toLowerCase()==="ip"?(o=e.substr(n,2),n+=2):(o=null,m('"ip"')),o===null&&(o=N())),o!==null?t=[t,o]:(t=null,n=d)):(t=null,n=d),t!==null&&(t=function(T,E){w.uri_params||(w.uri_params={}),w.uri_params.user=E.toLowerCase()}(u,t[1])),t===null&&(n=u),t}function gr(){var t,o,u,d;return u=n,d=n,e.substr(n,7).toLowerCase()==="method="?(t=e.substr(n,7),n+=7):(t=null,m('"method="')),t!==null?(o=cn(),o!==null?t=[t,o]:(t=null,n=d)):(t=null,n=d),t!==null&&(t=function(T,E){w.uri_params||(w.uri_params={}),w.uri_params.method=E}(u,t[1])),t===null&&(n=u),t}function Tr(){var t,o,u,d;return u=n,d=n,e.substr(n,4).toLowerCase()==="ttl="?(t=e.substr(n,4),n+=4):(t=null,m('"ttl="')),t!==null?(o=Jn(),o!==null?t=[t,o]:(t=null,n=d)):(t=null,n=d),t!==null&&(t=function(T,E){w.params||(w.params={}),w.params.ttl=E}(u,t[1])),t===null&&(n=u),t}function vr(){var t,o,u,d;return u=n,d=n,e.substr(n,6).toLowerCase()==="maddr="?(t=e.substr(n,6),n+=6):(t=null,m('"maddr="')),t!==null?(o=Os(),o!==null?t=[t,o]:(t=null,n=d)):(t=null,n=d),t!==null&&(t=function(T,E){w.uri_params||(w.uri_params={}),w.uri_params.maddr=E}(u,t[1])),t===null&&(n=u),t}function Er(){var t,o,u,d,T,E;return d=n,T=n,e.substr(n,2).toLowerCase()==="lr"?(t=e.substr(n,2),n+=2):(t=null,m('"lr"')),t!==null?(E=n,e.charCodeAt(n)===61?(o="=",n++):(o=null,m('"="')),o!==null?(u=N(),u!==null?o=[o,u]:(o=null,n=E)):(o=null,n=E),o=o!==null?o:"",o!==null?t=[t,o]:(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(y){w.uri_params||(w.uri_params={}),w.uri_params.lr=void 0}()),t===null&&(n=d),t}function Ns(){var t,o,u,d,T,E;return d=n,T=n,t=Sr(),t!==null?(E=n,e.charCodeAt(n)===61?(o="=",n++):(o=null,m('"="')),o!==null?(u=yr(),u!==null?o=[o,u]:(o=null,n=E)):(o=null,n=E),o=o!==null?o:"",o!==null?t=[t,o]:(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(y,O,G){w.uri_params||(w.uri_params={}),typeof G>"u"?G=void 0:G=G[1],w.uri_params[O.toLowerCase()]=G}(d,t[0],t[1])),t===null&&(n=d),t}function Sr(){var t,o,u;if(u=n,o=Zt(),o!==null)for(t=[];o!==null;)t.push(o),o=Zt();else t=null;return t!==null&&(t=function(d,T){return T.join("")}(u,t)),t===null&&(n=u),t}function yr(){var t,o,u;if(u=n,o=Zt(),o!==null)for(t=[];o!==null;)t.push(o),o=Zt();else t=null;return t!==null&&(t=function(d,T){return T.join("")}(u,t)),t===null&&(n=u),t}function Zt(){var t;return t=Ar(),t===null&&(t=H(),t===null&&(t=L())),t}function Ar(){var t;return e.charCodeAt(n)===91?(t="[",n++):(t=null,m('"["')),t===null&&(e.charCodeAt(n)===93?(t="]",n++):(t=null,m('"]"')),t===null&&(e.charCodeAt(n)===47?(t="/",n++):(t=null,m('"/"')),t===null&&(e.charCodeAt(n)===58?(t=":",n++):(t=null,m('":"')),t===null&&(e.charCodeAt(n)===38?(t="&",n++):(t=null,m('"&"')),t===null&&(e.charCodeAt(n)===43?(t="+",n++):(t=null,m('"+"')),t===null&&(e.charCodeAt(n)===36?(t="$",n++):(t=null,m('"$"')))))))),t}function Cr(){var t,o,u,d,T,E,y;if(E=n,e.charCodeAt(n)===63?(t="?",n++):(t=null,m('"?"')),t!==null)if(o=es(),o!==null){for(u=[],y=n,e.charCodeAt(n)===38?(d="&",n++):(d=null,m('"&"')),d!==null?(T=es(),T!==null?d=[d,T]:(d=null,n=y)):(d=null,n=y);d!==null;)u.push(d),y=n,e.charCodeAt(n)===38?(d="&",n++):(d=null,m('"&"')),d!==null?(T=es(),T!==null?d=[d,T]:(d=null,n=y)):(d=null,n=y);u!==null?t=[t,o,u]:(t=null,n=E)}else t=null,n=E;else t=null,n=E;return t}function es(){var t,o,u,d,T;return d=n,T=n,t=hl(),t!==null?(e.charCodeAt(n)===61?(o="=",n++):(o=null,m('"="')),o!==null?(u=Rr(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E,y,O){y=y.join("").toLowerCase(),O=O.join(""),w.uri_headers||(w.uri_headers={}),w.uri_headers[y]?w.uri_headers[y].push(O):w.uri_headers[y]=[O]}(d,t[0],t[2])),t===null&&(n=d),t}function hl(){var t,o;if(o=Us(),o===null&&(o=H(),o===null&&(o=L())),o!==null)for(t=[];o!==null;)t.push(o),o=Us(),o===null&&(o=H(),o===null&&(o=L()));else t=null;return t}function Rr(){var t,o;for(t=[],o=Us(),o===null&&(o=H(),o===null&&(o=L()));o!==null;)t.push(o),o=Us(),o===null&&(o=H(),o===null&&(o=L()));return t}function Us(){var t;return e.charCodeAt(n)===91?(t="[",n++):(t=null,m('"["')),t===null&&(e.charCodeAt(n)===93?(t="]",n++):(t=null,m('"]"')),t===null&&(e.charCodeAt(n)===47?(t="/",n++):(t=null,m('"/"')),t===null&&(e.charCodeAt(n)===63?(t="?",n++):(t=null,m('"?"')),t===null&&(e.charCodeAt(n)===58?(t=":",n++):(t=null,m('":"')),t===null&&(e.charCodeAt(n)===43?(t="+",n++):(t=null,m('"+"')),t===null&&(e.charCodeAt(n)===36?(t="$",n++):(t=null,m('"$"')))))))),t}function Ir(){var t;return t=Vr(),console.log("result0",t),t===null&&(t=br(),console.log("result0 2",t)),t}function br(){var t,o,u,d,T,E;return E=n,t=cn(),t!==null?(o=x(),console.log("parse_SP",o),o!==null?(u=wr(),console.log("parse_Request_URI",u),u!==null?(d=x(),console.log("parse_SP 2",d),d!==null?(T=jn(),T!==null?t=[t,o,u,d,T]:(t=null,n=E)):(t=null,n=E)):(t=null,n=E)):(t=null,n=E)):(t=null,n=E),t}function wr(){var t;return t=Ht(),t===null&&(t=Ps()),t}function Ps(){var t,o,u,d;return d=n,t=Nr(),t!==null?(e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o!==null?(u=Or(),u===null&&(u=Dr()),u!==null?t=[t,o,u]:(t=null,n=d)):(t=null,n=d)):(t=null,n=d),t}function Or(){var t,o,u,d,T;return d=n,t=xs(),t===null&&(t=an()),t!==null?(T=n,e.charCodeAt(n)===63?(o="?",n++):(o=null,m('"?"')),o!==null?(u=xr(),u!==null?o=[o,u]:(o=null,n=T)):(o=null,n=T),o=o!==null?o:"",o!==null?t=[t,o]:(t=null,n=d)):(t=null,n=d),t}function xs(){var t,o,u,d;return d=n,e.substr(n,2)==="//"?(t="//",n+=2):(t=null,m('"//"')),t!==null?(o=Ur(),o!==null?(u=an(),u=u!==null?u:"",u!==null?t=[t,o,u]:(t=null,n=d)):(t=null,n=d)):(t=null,n=d),t}function an(){var t,o,u;return u=n,e.charCodeAt(n)===47?(t="/",n++):(t=null,m('"/"')),t!==null?(o=Ms(),o!==null?t=[t,o]:(t=null,n=u)):(t=null,n=u),t}function Dr(){var t,o,u,d;if(d=n,t=$n(),t!==null){for(o=[],u=ts();u!==null;)o.push(u),u=ts();o!==null?t=[t,o]:(t=null,n=d)}else t=null,n=d;return t}function ts(){var t;return t=Ie(),t===null&&(t=H(),t===null&&(t=L())),t}function $n(){var t;return t=H(),t===null&&(t=L(),t===null&&(e.charCodeAt(n)===59?(t=";",n++):(t=null,m('";"')),t===null&&(e.charCodeAt(n)===63?(t="?",n++):(t=null,m('"?"')),t===null&&(e.charCodeAt(n)===58?(t=":",n++):(t=null,m('":"')),t===null&&(e.charCodeAt(n)===64?(t="@",n++):(t=null,m('"@"')),t===null&&(e.charCodeAt(n)===38?(t="&",n++):(t=null,m('"&"')),t===null&&(e.charCodeAt(n)===61?(t="=",n++):(t=null,m('"="')),t===null&&(e.charCodeAt(n)===43?(t="+",n++):(t=null,m('"+"')),t===null&&(e.charCodeAt(n)===36?(t="$",n++):(t=null,m('"$"')),t===null&&(e.charCodeAt(n)===44?(t=",",n++):(t=null,m('","')))))))))))),t}function Ms(){var t,o,u,d,T,E;if(T=n,t=on(),t!==null){for(o=[],E=n,e.charCodeAt(n)===47?(u="/",n++):(u=null,m('"/"')),u!==null?(d=on(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);u!==null;)o.push(u),E=n,e.charCodeAt(n)===47?(u="/",n++):(u=null,m('"/"')),u!==null?(d=on(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);o!==null?t=[t,o]:(t=null,n=T)}else t=null,n=T;return t}function on(){var t,o,u,d,T,E;for(T=n,t=[],o=ks();o!==null;)t.push(o),o=ks();if(t!==null){for(o=[],E=n,e.charCodeAt(n)===59?(u=";",n++):(u=null,m('";"')),u!==null?(d=Hn(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);u!==null;)o.push(u),E=n,e.charCodeAt(n)===59?(u=";",n++):(u=null,m('";"')),u!==null?(d=Hn(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);o!==null?t=[t,o]:(t=null,n=T)}else t=null,n=T;return t}function Hn(){var t,o;for(t=[],o=ks();o!==null;)t.push(o),o=ks();return t}function ks(){var t;return t=H(),t===null&&(t=L(),t===null&&(e.charCodeAt(n)===58?(t=":",n++):(t=null,m('":"')),t===null&&(e.charCodeAt(n)===64?(t="@",n++):(t=null,m('"@"')),t===null&&(e.charCodeAt(n)===38?(t="&",n++):(t=null,m('"&"')),t===null&&(e.charCodeAt(n)===61?(t="=",n++):(t=null,m('"="')),t===null&&(e.charCodeAt(n)===43?(t="+",n++):(t=null,m('"+"')),t===null&&(e.charCodeAt(n)===36?(t="$",n++):(t=null,m('"$"')),t===null&&(e.charCodeAt(n)===44?(t=",",n++):(t=null,m('","')))))))))),t}function Nr(){var t,o,u,d,T;if(d=n,T=n,t=R(),t!==null){for(o=[],u=R(),u===null&&(u=A(),u===null&&(e.charCodeAt(n)===43?(u="+",n++):(u=null,m('"+"')),u===null&&(e.charCodeAt(n)===45?(u="-",n++):(u=null,m('"-"')),u===null&&(e.charCodeAt(n)===46?(u=".",n++):(u=null,m('"."'))))));u!==null;)o.push(u),u=R(),u===null&&(u=A(),u===null&&(e.charCodeAt(n)===43?(u="+",n++):(u=null,m('"+"')),u===null&&(e.charCodeAt(n)===45?(u="-",n++):(u=null,m('"-"')),u===null&&(e.charCodeAt(n)===46?(u=".",n++):(u=null,m('"."'))))));o!==null?t=[t,o]:(t=null,n=T)}else t=null,n=T;return t!==null&&(t=function(E){w.scheme=e.substring(n,E)}(d)),t===null&&(n=d),t}function Ur(){var t;return t=Fn(),t===null&&(t=Pr()),t}function Fn(){var t,o,u,d;return u=n,d=n,t=sn(),t!==null?(e.charCodeAt(n)===64?(o="@",n++):(o=null,m('"@"')),o!==null?t=[t,o]:(t=null,n=d)):(t=null,n=d),t=t!==null?t:"",t!==null?(o=ws(),o!==null?t=[t,o]:(t=null,n=u)):(t=null,n=u),t=t!==null?t:"",t}function Pr(){var t,o;if(o=H(),o===null&&(o=L(),o===null&&(e.charCodeAt(n)===36?(o="$",n++):(o=null,m('"$"')),o===null&&(e.charCodeAt(n)===44?(o=",",n++):(o=null,m('","')),o===null&&(e.charCodeAt(n)===59?(o=";",n++):(o=null,m('";"')),o===null&&(e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o===null&&(e.charCodeAt(n)===64?(o="@",n++):(o=null,m('"@"')),o===null&&(e.charCodeAt(n)===38?(o="&",n++):(o=null,m('"&"')),o===null&&(e.charCodeAt(n)===61?(o="=",n++):(o=null,m('"="')),o===null&&(e.charCodeAt(n)===43?(o="+",n++):(o=null,m('"+"'))))))))))),o!==null)for(t=[];o!==null;)t.push(o),o=H(),o===null&&(o=L(),o===null&&(e.charCodeAt(n)===36?(o="$",n++):(o=null,m('"$"')),o===null&&(e.charCodeAt(n)===44?(o=",",n++):(o=null,m('","')),o===null&&(e.charCodeAt(n)===59?(o=";",n++):(o=null,m('";"')),o===null&&(e.charCodeAt(n)===58?(o=":",n++):(o=null,m('":"')),o===null&&(e.charCodeAt(n)===64?(o="@",n++):(o=null,m('"@"')),o===null&&(e.charCodeAt(n)===38?(o="&",n++):(o=null,m('"&"')),o===null&&(e.charCodeAt(n)===61?(o="=",n++):(o=null,m('"="')),o===null&&(e.charCodeAt(n)===43?(o="+",n++):(o=null,m('"+"')))))))))));else t=null;return t}function xr(){var t,o;for(t=[],o=ts();o!==null;)t.push(o),o=ts();return t}function jn(){var t,o,u,d,T,E,y,O;if(y=n,O=n,e.substr(n,3).toLowerCase()==="sip"?(t=e.substr(n,3),n+=3):(t=null,m('"SIP"')),t!==null)if(e.charCodeAt(n)===47?(o="/",n++):(o=null,m('"/"')),o!==null){if(d=A(),d!==null)for(u=[];d!==null;)u.push(d),d=A();else u=null;if(u!==null)if(e.charCodeAt(n)===46?(d=".",n++):(d=null,m('"."')),d!==null){if(E=A(),E!==null)for(T=[];E!==null;)T.push(E),E=A();else T=null;T!==null?t=[t,o,u,d,T]:(t=null,n=O)}else t=null,n=O;else t=null,n=O}else t=null,n=O;else t=null,n=O;return t!==null&&(t=function(G){w.sip_version=e.substring(n,G)}(y)),t===null&&(n=y),t}function Mr(){var t;return e.substr(n,6)==="INVITE"?(t="INVITE",n+=6):(t=null,m('"INVITE"')),t}function kr(){var t;return e.substr(n,3)==="ACK"?(t="ACK",n+=3):(t=null,m('"ACK"')),t}function Lr(){var t;return e.substr(n,7)==="OPTIONS"?(t="OPTIONS",n+=7):(t=null,m('"OPTIONS"')),t}function $r(){var t;return e.substr(n,3)==="BYE"?(t="BYE",n+=3):(t=null,m('"BYE"')),t}function Hr(){var t;return e.substr(n,6)==="CANCEL"?(t="CANCEL",n+=6):(t=null,m('"CANCEL"')),t}function Fr(){var t;return e.substr(n,8)==="REGISTER"?(t="REGISTER",n+=8):(t=null,m('"REGISTER"')),t}function un(){var t;return e.substr(n,9)==="SUBSCRIBE"?(t="SUBSCRIBE",n+=9):(t=null,m('"SUBSCRIBE"')),t}function jr(){var t;return e.substr(n,6)==="NOTIFY"?(t="NOTIFY",n+=6):(t=null,m('"NOTIFY"')),t}function qr(){var t;return e.substr(n,5)==="REFER"?(t="REFER",n+=5):(t=null,m('"REFER"')),t}function cn(){var t,o;return o=n,t=Mr(),t===null&&(t=kr(),t===null&&(t=Lr(),t===null&&(t=$r(),t===null&&(t=Hr(),t===null&&(t=Fr(),t===null&&(t=un(),t===null&&(t=jr(),t===null&&(t=qr(),t===null&&(t=N()))))))))),t!==null&&(t=function(u){return w.method=e.substring(n,u),w.method}(o)),t===null&&(n=o),t}function Vr(){var t,o,u,d,T,E;return E=n,t=jn(),t!==null?(o=x(),o!==null?(u=dl(),u!==null?(d=x(),d!==null?(T=ml(),T!==null?t=[t,o,u,d,T]:(t=null,n=E)):(t=null,n=E)):(t=null,n=E)):(t=null,n=E)):(t=null,n=E),t}function dl(){var t,o;return o=n,t=pl(),t!==null&&(t=function(u,d){w.status_code=parseInt(d.join(""))}(o,t)),t===null&&(n=o),t}function pl(){var t,o,u,d;return d=n,t=A(),t!==null?(o=A(),o!==null?(u=A(),u!==null?t=[t,o,u]:(t=null,n=d)):(t=null,n=d)):(t=null,n=d),t}function ml(){var t,o,u;for(u=n,t=[],o=Ie(),o===null&&(o=H(),o===null&&(o=L(),o===null&&(o=U(),o===null&&(o=se(),o===null&&(o=x(),o===null&&(o=$()))))));o!==null;)t.push(o),o=Ie(),o===null&&(o=H(),o===null&&(o=L(),o===null&&(o=U(),o===null&&(o=se(),o===null&&(o=x(),o===null&&(o=$()))))));return t!==null&&(t=function(d){w.reason_phrase=e.substring(n,d)}(u)),t===null&&(n=u),t}function qn(){var t,o,u,d,T,E;if(T=n,t=ds(),t!==null){for(o=[],E=n,u=Ue(),u!==null?(d=ds(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);u!==null;)o.push(u),E=n,u=Ue(),u!==null?(d=ds(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);o!==null?t=[t,o]:(t=null,n=T)}else t=null,n=T;return t}function hs(){var t,o,u,d,T,E;return d=n,T=n,t=ae(),t!==null?(E=n,e.charCodeAt(n)===64?(o="@",n++):(o=null,m('"@"')),o!==null?(u=ae(),u!==null?o=[o,u]:(o=null,n=E)):(o=null,n=E),o=o!==null?o:"",o!==null?t=[t,o]:(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(y){w=e.substring(n,y)}(d)),t===null&&(n=d),t}function Vn(){var t,o,u,d,T,E,y;if(T=n,t=Te(),t===null)if(E=n,t=Ls(),t!==null){for(o=[],y=n,u=Ue(),u!==null?(d=Ls(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);u!==null;)o.push(u),y=n,u=Ue(),u!==null?(d=Ls(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);o!==null?t=[t,o]:(t=null,n=E)}else t=null,n=E;return t!==null&&(t=function(O){var G,ye;for(ye=w.multi_header.length,G=0;G<ye;G++)if(w.multi_header[G].parsed===null){w=null;break}w!==null?w=w.multi_header:w=-1}()),t===null&&(n=T),t}function Ls(){var t,o,u,d,T,E,y;if(T=n,E=n,t=He(),t===null&&(t=ss()),t!==null){for(o=[],y=n,u=le(),u!==null?(d=Bt(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);u!==null;)o.push(u),y=n,u=le(),u!==null?(d=Bt(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);o!==null?t=[t,o]:(t=null,n=E)}else t=null,n=E;return t!==null&&(t=function(O){var G;w.multi_header||(w.multi_header=[]);try{G=new rs(w.uri,w.display_name,w.params),delete w.uri,delete w.display_name,delete w.params}catch{G=null}w.multi_header.push({possition:n,offset:O,parsed:G})}(T)),t===null&&(n=T),t}function ss(){var t,o,u,d,T;return T=n,t=fn(),t=t!==null?t:"",t!==null?(o=it(),o!==null?(u=Ht(),u!==null?(d=Se(),d!==null?t=[t,o,u,d]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t}function fn(){var t,o,u,d,T,E,y;if(T=n,E=n,t=N(),t!==null){for(o=[],y=n,u=q(),u!==null?(d=N(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);u!==null;)o.push(u),y=n,u=q(),u!==null?(d=N(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);o!==null?t=[t,o]:(t=null,n=E)}else t=null,n=E;return t===null&&(t=Ne()),t!==null&&(t=function(O,G){typeof G=="string"?w.display_name=G:w.display_name=G[1].reduce(function(ye,Fe){return ye+Fe[0]+Fe[1]},G[0])}(T,t)),t===null&&(n=T),t}function Bt(){var t;return t=Br(),t===null&&(t=ze(),t===null&&(t=Xe())),t}function Br(){var t,o,u,d,T;return d=n,T=n,e.substr(n,1).toLowerCase()==="q"?(t=e.substr(n,1),n++):(t=null,m('"q"')),t!==null?(o=Ce(),o!==null?(u=gl(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E,y){w.params||(w.params={}),w.params.q=y}(d,t[2])),t===null&&(n=d),t}function ze(){var t,o,u,d,T;return d=n,T=n,e.substr(n,7).toLowerCase()==="expires"?(t=e.substr(n,7),n+=7):(t=null,m('"expires"')),t!==null?(o=Ce(),o!==null?(u=ns(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E,y){w.params||(w.params={}),w.params.expires=y}(d,t[2])),t===null&&(n=d),t}function ns(){var t,o,u;if(u=n,o=A(),o!==null)for(t=[];o!==null;)t.push(o),o=A();else t=null;return t!==null&&(t=function(d,T){return parseInt(T.join(""))}(u,t)),t===null&&(n=u),t}function gl(){var t,o,u,d,T,E,y,O;return E=n,y=n,e.charCodeAt(n)===48?(t="0",n++):(t=null,m('"0"')),t!==null?(O=n,e.charCodeAt(n)===46?(o=".",n++):(o=null,m('"."')),o!==null?(u=A(),u=u!==null?u:"",u!==null?(d=A(),d=d!==null?d:"",d!==null?(T=A(),T=T!==null?T:"",T!==null?o=[o,u,d,T]:(o=null,n=O)):(o=null,n=O)):(o=null,n=O)):(o=null,n=O),o=o!==null?o:"",o!==null?t=[t,o]:(t=null,n=y)):(t=null,n=y),t!==null&&(t=function(G){return parseFloat(e.substring(n,G))}(E)),t===null&&(n=E),t}function Xe(){var t,o,u,d,T,E;return d=n,T=n,t=N(),t!==null?(E=n,o=Ce(),o!==null?(u=Bn(),u!==null?o=[o,u]:(o=null,n=E)):(o=null,n=E),o=o!==null?o:"",o!==null?t=[t,o]:(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(y,O,G){w.params||(w.params={}),typeof G>"u"?G=void 0:G=G[1],w.params[O.toLowerCase()]=G}(d,t[0],t[1])),t===null&&(n=d),t}function Bn(){var t;return t=N(),t===null&&(t=Os(),t===null&&(t=pe())),t}function Tl(){var t,o,u,d,T,E;if(T=n,t=vl(),t!==null){for(o=[],E=n,u=le(),u!==null?(d=Gr(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);u!==null;)o.push(u),E=n,u=le(),u!==null?(d=Gr(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);o!==null?t=[t,o]:(t=null,n=T)}else t=null,n=T;return t}function vl(){var t;return e.substr(n,6).toLowerCase()==="render"?(t=e.substr(n,6),n+=6):(t=null,m('"render"')),t===null&&(e.substr(n,7).toLowerCase()==="session"?(t=e.substr(n,7),n+=7):(t=null,m('"session"')),t===null&&(e.substr(n,4).toLowerCase()==="icon"?(t=e.substr(n,4),n+=4):(t=null,m('"icon"')),t===null&&(e.substr(n,5).toLowerCase()==="alert"?(t=e.substr(n,5),n+=5):(t=null,m('"alert"')),t===null&&(t=N())))),t}function Gr(){var t;return t=El(),t===null&&(t=Xe()),t}function El(){var t,o,u,d;return d=n,e.substr(n,8).toLowerCase()==="handling"?(t=e.substr(n,8),n+=8):(t=null,m('"handling"')),t!==null?(o=Ce(),o!==null?(e.substr(n,8).toLowerCase()==="optional"?(u=e.substr(n,8),n+=8):(u=null,m('"optional"')),u===null&&(e.substr(n,8).toLowerCase()==="required"?(u=e.substr(n,8),n+=8):(u=null,m('"required"')),u===null&&(u=N())),u!==null?t=[t,o,u]:(t=null,n=d)):(t=null,n=d)):(t=null,n=d),t}function Sl(){var t,o,u,d,T,E;if(T=n,t=N(),t!==null){for(o=[],E=n,u=Ue(),u!==null?(d=N(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);u!==null;)o.push(u),E=n,u=Ue(),u!==null?(d=N(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);o!==null?t=[t,o]:(t=null,n=T)}else t=null,n=T;return t}function yl(){var t,o,u;if(u=n,o=A(),o!==null)for(t=[];o!==null;)t.push(o),o=A();else t=null;return t!==null&&(t=function(d,T){w=parseInt(T.join(""))}(u,t)),t===null&&(n=u),t}function Al(){var t,o;return o=n,t=Wr(),t!==null&&(t=function(u){w=e.substring(n,u)}(o)),t===null&&(n=o),t}function Wr(){var t,o,u,d,T,E,y,O;if(y=n,t=_n(),t!==null)if(o=De(),o!==null)if(u=Cl(),u!==null){for(d=[],O=n,T=le(),T!==null?(E=Gn(),E!==null?T=[T,E]:(T=null,n=O)):(T=null,n=O);T!==null;)d.push(T),O=n,T=le(),T!==null?(E=Gn(),E!==null?T=[T,E]:(T=null,n=O)):(T=null,n=O);d!==null?t=[t,o,u,d]:(t=null,n=y)}else t=null,n=y;else t=null,n=y;else t=null,n=y;return t}function _n(){var t;return t=Kr(),t===null&&(t=Yr()),t}function Kr(){var t;return e.substr(n,4).toLowerCase()==="text"?(t=e.substr(n,4),n+=4):(t=null,m('"text"')),t===null&&(e.substr(n,5).toLowerCase()==="image"?(t=e.substr(n,5),n+=5):(t=null,m('"image"')),t===null&&(e.substr(n,5).toLowerCase()==="audio"?(t=e.substr(n,5),n+=5):(t=null,m('"audio"')),t===null&&(e.substr(n,5).toLowerCase()==="video"?(t=e.substr(n,5),n+=5):(t=null,m('"video"')),t===null&&(e.substr(n,11).toLowerCase()==="application"?(t=e.substr(n,11),n+=11):(t=null,m('"application"')),t===null&&(t=$s()))))),t}function Yr(){var t;return e.substr(n,7).toLowerCase()==="message"?(t=e.substr(n,7),n+=7):(t=null,m('"message"')),t===null&&(e.substr(n,9).toLowerCase()==="multipart"?(t=e.substr(n,9),n+=9):(t=null,m('"multipart"')),t===null&&(t=$s())),t}function $s(){var t;return t=N(),t===null&&(t=Jr()),t}function Jr(){var t,o,u;return u=n,e.substr(n,2).toLowerCase()==="x-"?(t=e.substr(n,2),n+=2):(t=null,m('"x-"')),t!==null?(o=N(),o!==null?t=[t,o]:(t=null,n=u)):(t=null,n=u),t}function Cl(){var t;return t=$s(),t===null&&(t=N()),t}function Gn(){var t,o,u,d;return d=n,t=N(),t!==null?(o=Ce(),o!==null?(u=Rl(),u!==null?t=[t,o,u]:(t=null,n=d)):(t=null,n=d)):(t=null,n=d),t}function Rl(){var t;return t=N(),t===null&&(t=pe()),t}function so(){var t,o,u,d;return d=n,t=Hs(),t!==null?(o=q(),o!==null?(u=cn(),u!==null?t=[t,o,u]:(t=null,n=d)):(t=null,n=d)):(t=null,n=d),t}function Hs(){var t,o,u;if(u=n,o=A(),o!==null)for(t=[];o!==null;)t.push(o),o=A();else t=null;return t!==null&&(t=function(d,T){w.value=parseInt(T.join(""))}(u,t)),t===null&&(n=u),t}function no(){var t,o;return o=n,t=ns(),t!==null&&(t=function(u,d){w=d}(o,t)),t===null&&(n=o),t}function zr(){var t,o,u,d,T,E,y;if(T=n,E=n,t=ds(),t!==null){for(o=[],y=n,u=le(),u!==null?(d=Xe(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);u!==null;)o.push(u),y=n,u=le(),u!==null?(d=Xe(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);o!==null?t=[t,o]:(t=null,n=E)}else t=null,n=E;return t!==null&&(t=function(O,G){w.event=G.join("").toLowerCase()}(T,t[0])),t===null&&(n=T),t}function ds(){var t,o,u,d,T,E;if(T=n,t=Y(),t!==null){for(o=[],E=n,e.charCodeAt(n)===46?(u=".",n++):(u=null,m('"."')),u!==null?(d=Y(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);u!==null;)o.push(u),E=n,e.charCodeAt(n)===46?(u=".",n++):(u=null,m('"."')),u!==null?(d=Y(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);o!==null?t=[t,o]:(t=null,n=T)}else t=null,n=T;return t}function ro(){var t,o,u,d,T,E,y;if(T=n,E=n,t=He(),t===null&&(t=ss()),t!==null){for(o=[],y=n,u=le(),u!==null?(d=Xr(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);u!==null;)o.push(u),y=n,u=le(),u!==null?(d=Xr(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);o!==null?t=[t,o]:(t=null,n=E)}else t=null,n=E;return t!==null&&(t=function(O){var G=w.tag;try{w=new rs(w.uri,w.display_name,w.params),G&&w.setParam("tag",G)}catch{w=-1}}()),t===null&&(n=T),t}function Xr(){var t;return t=Qr(),t===null&&(t=Xe()),t}function Qr(){var t,o,u,d,T;return d=n,T=n,e.substr(n,3).toLowerCase()==="tag"?(t=e.substr(n,3),n+=3):(t=null,m('"tag"')),t!==null?(o=Ce(),o!==null?(u=N(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E,y){w.tag=y}(d,t[2])),t===null&&(n=d),t}function io(){var t,o,u;if(u=n,o=A(),o!==null)for(t=[];o!==null;)t.push(o),o=A();else t=null;return t!==null&&(t=function(d,T){w=parseInt(T.join(""))}(u,t)),t===null&&(n=u),t}function Zr(){var t,o;return o=n,t=ns(),t!==null&&(t=function(u,d){w=d}(o,t)),t===null&&(n=o),t}function Il(){var t,o,u,d,T,E,y,O,G,ye;for(O=n,G=n,t=[],o=fn();o!==null;)t.push(o),o=fn();if(t!==null)if(o=it(),o!==null)if(u=Ht(),u!==null)if(d=Se(),d!==null){for(T=[],ye=n,E=le(),E!==null?(y=Xe(),y!==null?E=[E,y]:(E=null,n=ye)):(E=null,n=ye);E!==null;)T.push(E),ye=n,E=le(),E!==null?(y=Xe(),y!==null?E=[E,y]:(E=null,n=ye)):(E=null,n=ye);T!==null?t=[t,o,u,d,T]:(t=null,n=G)}else t=null,n=G;else t=null,n=G;else t=null,n=G;else t=null,n=G;return t!==null&&(t=function(Fe){try{w=new rs(w.uri,w.display_name,w.params)}catch{w=-1}}()),t===null&&(n=O),t}function hn(){var t;return t=Fs(),t}function Fs(){var t,o,u,d,T,E,y,O;if(y=n,e.substr(n,6).toLowerCase()==="digest"?(t=e.substr(n,6),n+=6):(t=null,m('"Digest"')),t!==null)if(o=q(),o!==null)if(u=dn(),u!==null){for(d=[],O=n,T=Ue(),T!==null?(E=dn(),E!==null?T=[T,E]:(T=null,n=O)):(T=null,n=O);T!==null;)d.push(T),O=n,T=Ue(),T!==null?(E=dn(),E!==null?T=[T,E]:(T=null,n=O)):(T=null,n=O);d!==null?t=[t,o,u,d]:(t=null,n=y)}else t=null,n=y;else t=null,n=y;else t=null,n=y;return t===null&&(t=ei()),t}function ei(){var t,o,u,d,T,E,y,O;if(y=n,t=N(),t!==null)if(o=q(),o!==null)if(u=js(),u!==null){for(d=[],O=n,T=Ue(),T!==null?(E=js(),E!==null?T=[T,E]:(T=null,n=O)):(T=null,n=O);T!==null;)d.push(T),O=n,T=Ue(),T!==null?(E=js(),E!==null?T=[T,E]:(T=null,n=O)):(T=null,n=O);d!==null?t=[t,o,u,d]:(t=null,n=y)}else t=null,n=y;else t=null,n=y;else t=null,n=y;return t}function js(){var t,o,u,d;return d=n,t=N(),t!==null?(o=Ce(),o!==null?(u=N(),u===null&&(u=pe()),u!==null?t=[t,o,u]:(t=null,n=d)):(t=null,n=d)):(t=null,n=d),t}function dn(){var t;return t=pn(),t===null&&(t=si(),t===null&&(t=ni(),t===null&&(t=ii(),t===null&&(t=gn(),t===null&&(t=bl(),t===null&&(t=wl(),t===null&&(t=js()))))))),t}function pn(){var t,o,u,d;return d=n,e.substr(n,5).toLowerCase()==="realm"?(t=e.substr(n,5),n+=5):(t=null,m('"realm"')),t!==null?(o=Ce(),o!==null?(u=ti(),u!==null?t=[t,o,u]:(t=null,n=d)):(t=null,n=d)):(t=null,n=d),t}function ti(){var t,o;return o=n,t=Ne(),t!==null&&(t=function(u,d){w.realm=d}(o,t)),t===null&&(n=o),t}function si(){var t,o,u,d,T,E,y,O,G;if(O=n,e.substr(n,6).toLowerCase()==="domain"?(t=e.substr(n,6),n+=6):(t=null,m('"domain"')),t!==null)if(o=Ce(),o!==null)if(u=Oe(),u!==null)if(d=mn(),d!==null){if(T=[],G=n,y=x(),y!==null)for(E=[];y!==null;)E.push(y),y=x();else E=null;for(E!==null?(y=mn(),y!==null?E=[E,y]:(E=null,n=G)):(E=null,n=G);E!==null;){if(T.push(E),G=n,y=x(),y!==null)for(E=[];y!==null;)E.push(y),y=x();else E=null;E!==null?(y=mn(),y!==null?E=[E,y]:(E=null,n=G)):(E=null,n=G)}T!==null?(E=Pe(),E!==null?t=[t,o,u,d,T,E]:(t=null,n=O)):(t=null,n=O)}else t=null,n=O;else t=null,n=O;else t=null,n=O;else t=null,n=O;return t}function mn(){var t;return t=Ps(),t===null&&(t=an()),t}function ni(){var t,o,u,d;return d=n,e.substr(n,5).toLowerCase()==="nonce"?(t=e.substr(n,5),n+=5):(t=null,m('"nonce"')),t!==null?(o=Ce(),o!==null?(u=ri(),u!==null?t=[t,o,u]:(t=null,n=d)):(t=null,n=d)):(t=null,n=d),t}function ri(){var t,o;return o=n,t=Ne(),t!==null&&(t=function(u,d){w.nonce=d}(o,t)),t===null&&(n=o),t}function ii(){var t,o,u,d,T;return d=n,T=n,e.substr(n,6).toLowerCase()==="opaque"?(t=e.substr(n,6),n+=6):(t=null,m('"opaque"')),t!==null?(o=Ce(),o!==null?(u=Ne(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E,y){w.opaque=y}(d,t[2])),t===null&&(n=d),t}function gn(){var t,o,u,d,T;return d=n,e.substr(n,5).toLowerCase()==="stale"?(t=e.substr(n,5),n+=5):(t=null,m('"stale"')),t!==null?(o=Ce(),o!==null?(T=n,e.substr(n,4).toLowerCase()==="true"?(u=e.substr(n,4),n+=4):(u=null,m('"true"')),u!==null&&(u=function(E){w.stale=!0}()),u===null&&(n=T),u===null&&(T=n,e.substr(n,5).toLowerCase()==="false"?(u=e.substr(n,5),n+=5):(u=null,m('"false"')),u!==null&&(u=function(E){w.stale=!1}()),u===null&&(n=T)),u!==null?t=[t,o,u]:(t=null,n=d)):(t=null,n=d)):(t=null,n=d),t}function bl(){var t,o,u,d,T;return d=n,T=n,e.substr(n,9).toLowerCase()==="algorithm"?(t=e.substr(n,9),n+=9):(t=null,m('"algorithm"')),t!==null?(o=Ce(),o!==null?(e.substr(n,3).toLowerCase()==="md5"?(u=e.substr(n,3),n+=3):(u=null,m('"MD5"')),u===null&&(e.substr(n,8).toLowerCase()==="md5-sess"?(u=e.substr(n,8),n+=8):(u=null,m('"MD5-sess"')),u===null&&(u=N())),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E,y){w.algorithm=y.toUpperCase()}(d,t[2])),t===null&&(n=d),t}function wl(){var t,o,u,d,T,E,y,O,G,ye;if(O=n,e.substr(n,3).toLowerCase()==="qop"?(t=e.substr(n,3),n+=3):(t=null,m('"qop"')),t!==null)if(o=Ce(),o!==null)if(u=Oe(),u!==null){if(G=n,d=ps(),d!==null){for(T=[],ye=n,e.charCodeAt(n)===44?(E=",",n++):(E=null,m('","')),E!==null?(y=ps(),y!==null?E=[E,y]:(E=null,n=ye)):(E=null,n=ye);E!==null;)T.push(E),ye=n,e.charCodeAt(n)===44?(E=",",n++):(E=null,m('","')),E!==null?(y=ps(),y!==null?E=[E,y]:(E=null,n=ye)):(E=null,n=ye);T!==null?d=[d,T]:(d=null,n=G)}else d=null,n=G;d!==null?(T=Pe(),T!==null?t=[t,o,u,d,T]:(t=null,n=O)):(t=null,n=O)}else t=null,n=O;else t=null,n=O;else t=null,n=O;return t}function ps(){var t,o;return o=n,e.substr(n,8).toLowerCase()==="auth-int"?(t=e.substr(n,8),n+=8):(t=null,m('"auth-int"')),t===null&&(e.substr(n,4).toLowerCase()==="auth"?(t=e.substr(n,4),n+=4):(t=null,m('"auth"')),t===null&&(t=N())),t!==null&&(t=function(u,d){w.qop||(w.qop=[]),w.qop.push(d.toLowerCase())}(o,t)),t===null&&(n=o),t}function lo(){var t,o,u,d,T,E;if(T=n,t=N(),t!==null){for(o=[],E=n,u=Ue(),u!==null?(d=N(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);u!==null;)o.push(u),E=n,u=Ue(),u!==null?(d=N(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);o!==null?t=[t,o]:(t=null,n=T)}else t=null,n=T;return t}function li(){var t,o,u,d,T,E,y;if(T=n,E=n,t=Tn(),t!==null){for(o=[],y=n,u=Ue(),u!==null?(d=Tn(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);u!==null;)o.push(u),y=n,u=Ue(),u!==null?(d=Tn(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);o!==null?t=[t,o]:(t=null,n=E)}else t=null,n=E;return t!==null&&(t=function(O){var G,ye;for(ye=w.multi_header.length,G=0;G<ye;G++)if(w.multi_header[G].parsed===null){w=null;break}w!==null?w=w.multi_header:w=-1}()),t===null&&(n=T),t}function Tn(){var t,o,u,d,T,E,y;if(T=n,E=n,t=ss(),t!==null){for(o=[],y=n,u=le(),u!==null?(d=Xe(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);u!==null;)o.push(u),y=n,u=le(),u!==null?(d=Xe(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);o!==null?t=[t,o]:(t=null,n=E)}else t=null,n=E;return t!==null&&(t=function(O){var G;w.multi_header||(w.multi_header=[]);try{G=new rs(w.uri,w.display_name,w.params),delete w.uri,delete w.display_name,delete w.params}catch{G=null}w.multi_header.push({possition:n,offset:O,parsed:G})}(T)),t===null&&(n=T),t}function ao(){var t,o,u,d,T,E,y;if(T=n,E=n,e.substr(n,3).toLowerCase()==="sip"?(t=e.substr(n,3),n+=3):(t=null,m('"SIP"')),t===null&&(t=N()),t!==null){for(o=[],y=n,u=le(),u!==null?(d=ai(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);u!==null;)o.push(u),y=n,u=le(),u!==null?(d=ai(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);o!==null?t=[t,o]:(t=null,n=E)}else t=null,n=E;return t!==null&&(t=function(O,G){if(w.protocol=G.toLowerCase(),w.params||(w.params={}),w.params.text&&w.params.text[0]==='"'){var ye=w.params.text;w.text=ye.substring(1,ye.length-1),delete w.params.text}}(T,t[0])),t===null&&(n=T),t}function ai(){var t;return t=vn(),t===null&&(t=Xe()),t}function vn(){var t,o,u,d,T,E;if(T=n,E=n,e.substr(n,5).toLowerCase()==="cause"?(t=e.substr(n,5),n+=5):(t=null,m('"cause"')),t!==null)if(o=Ce(),o!==null){if(d=A(),d!==null)for(u=[];d!==null;)u.push(d),d=A();else u=null;u!==null?t=[t,o,u]:(t=null,n=E)}else t=null,n=E;else t=null,n=E;return t!==null&&(t=function(y,O){w.cause=parseInt(O.join(""))}(T,t[2])),t===null&&(n=T),t}function oo(){var t,o,u,d,T,E;if(T=n,t=N(),t!==null){for(o=[],E=n,u=Ue(),u!==null?(d=N(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);u!==null;)o.push(u),E=n,u=Ue(),u!==null?(d=N(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);o!==null?t=[t,o]:(t=null,n=T)}else t=null,n=T;return t}function Ol(){var t,o,u,d,T,E;if(T=n,t=qs(),t!==null){for(o=[],E=n,u=Ue(),u!==null?(d=qs(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);u!==null;)o.push(u),E=n,u=Ue(),u!==null?(d=qs(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);o!==null?t=[t,o]:(t=null,n=T)}else t=null,n=T;return t}function qs(){var t,o,u,d,T,E;if(T=n,t=ss(),t!==null){for(o=[],E=n,u=le(),u!==null?(d=Xe(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);u!==null;)o.push(u),E=n,u=le(),u!==null?(d=Xe(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);o!==null?t=[t,o]:(t=null,n=T)}else t=null,n=T;return t}function Dl(){var t,o,u,d,T,E;if(T=n,t=Nl(),t!==null){for(o=[],E=n,u=le(),u!==null?(d=oi(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);u!==null;)o.push(u),E=n,u=le(),u!==null?(d=oi(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);o!==null?t=[t,o]:(t=null,n=T)}else t=null,n=T;return t}function Nl(){var t,o;return o=n,e.substr(n,6).toLowerCase()==="active"?(t=e.substr(n,6),n+=6):(t=null,m('"active"')),t===null&&(e.substr(n,7).toLowerCase()==="pending"?(t=e.substr(n,7),n+=7):(t=null,m('"pending"')),t===null&&(e.substr(n,10).toLowerCase()==="terminated"?(t=e.substr(n,10),n+=10):(t=null,m('"terminated"')),t===null&&(t=N()))),t!==null&&(t=function(u){w.state=e.substring(n,u)}(o)),t===null&&(n=o),t}function oi(){var t,o,u,d,T;return d=n,T=n,e.substr(n,6).toLowerCase()==="reason"?(t=e.substr(n,6),n+=6):(t=null,m('"reason"')),t!==null?(o=Ce(),o!==null?(u=Ul(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E,y){typeof y<"u"&&(w.reason=y)}(d,t[2])),t===null&&(n=d),t===null&&(d=n,T=n,e.substr(n,7).toLowerCase()==="expires"?(t=e.substr(n,7),n+=7):(t=null,m('"expires"')),t!==null?(o=Ce(),o!==null?(u=ns(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E,y){typeof y<"u"&&(w.expires=y)}(d,t[2])),t===null&&(n=d),t===null&&(d=n,T=n,e.substr(n,11).toLowerCase()==="retry_after"?(t=e.substr(n,11),n+=11):(t=null,m('"retry_after"')),t!==null?(o=Ce(),o!==null?(u=ns(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E,y){typeof y<"u"&&(w.retry_after=y)}(d,t[2])),t===null&&(n=d),t===null&&(t=Xe()))),t}function Ul(){var t;return e.substr(n,11).toLowerCase()==="deactivated"?(t=e.substr(n,11),n+=11):(t=null,m('"deactivated"')),t===null&&(e.substr(n,9).toLowerCase()==="probation"?(t=e.substr(n,9),n+=9):(t=null,m('"probation"')),t===null&&(e.substr(n,8).toLowerCase()==="rejected"?(t=e.substr(n,8),n+=8):(t=null,m('"rejected"')),t===null&&(e.substr(n,7).toLowerCase()==="timeout"?(t=e.substr(n,7),n+=7):(t=null,m('"timeout"')),t===null&&(e.substr(n,6).toLowerCase()==="giveup"?(t=e.substr(n,6),n+=6):(t=null,m('"giveup"')),t===null&&(e.substr(n,10).toLowerCase()==="noresource"?(t=e.substr(n,10),n+=10):(t=null,m('"noresource"')),t===null&&(e.substr(n,9).toLowerCase()==="invariant"?(t=e.substr(n,9),n+=9):(t=null,m('"invariant"')),t===null&&(t=N()))))))),t}function ui(){var t;return t=X(),t=t!==null?t:"",t}function uo(){var t,o,u,d,T,E;if(T=n,t=N(),t!==null){for(o=[],E=n,u=Ue(),u!==null?(d=N(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);u!==null;)o.push(u),E=n,u=Ue(),u!==null?(d=N(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);o!==null?t=[t,o]:(t=null,n=T)}else t=null,n=T;return t=t!==null?t:"",t}function Wn(){var t,o,u,d,T,E,y;if(T=n,E=n,t=He(),t===null&&(t=ss()),t!==null){for(o=[],y=n,u=le(),u!==null?(d=En(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);u!==null;)o.push(u),y=n,u=le(),u!==null?(d=En(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);o!==null?t=[t,o]:(t=null,n=E)}else t=null,n=E;return t!==null&&(t=function(O){var G=w.tag;try{w=new rs(w.uri,w.display_name,w.params),G&&w.setParam("tag",G)}catch{w=-1}}()),t===null&&(n=T),t}function En(){var t;return t=Qr(),t===null&&(t=Xe()),t}function Pl(){var t,o,u,d,T,E;if(T=n,t=Sn(),t!==null){for(o=[],E=n,u=Ue(),u!==null?(d=Sn(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);u!==null;)o.push(u),E=n,u=Ue(),u!==null?(d=Sn(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);o!==null?t=[t,o]:(t=null,n=T)}else t=null,n=T;return t}function Sn(){var t,o,u,d,T,E,y,O;if(y=n,t=mi(),t!==null)if(o=q(),o!==null)if(u=Yn(),u!==null){for(d=[],O=n,T=le(),T!==null?(E=Kn(),E!==null?T=[T,E]:(T=null,n=O)):(T=null,n=O);T!==null;)d.push(T),O=n,T=le(),T!==null?(E=Kn(),E!==null?T=[T,E]:(T=null,n=O)):(T=null,n=O);d!==null?t=[t,o,u,d]:(t=null,n=y)}else t=null,n=y;else t=null,n=y;else t=null,n=y;return t}function Kn(){var t;return t=ci(),t===null&&(t=fi(),t===null&&(t=_i(),t===null&&(t=hi(),t===null&&(t=di(),t===null&&(t=Xe()))))),t}function ci(){var t,o,u,d,T;return d=n,T=n,e.substr(n,3).toLowerCase()==="ttl"?(t=e.substr(n,3),n+=3):(t=null,m('"ttl"')),t!==null?(o=Ce(),o!==null?(u=Jn(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E,y){w.ttl=y}(d,t[2])),t===null&&(n=d),t}function fi(){var t,o,u,d,T;return d=n,T=n,e.substr(n,5).toLowerCase()==="maddr"?(t=e.substr(n,5),n+=5):(t=null,m('"maddr"')),t!==null?(o=Ce(),o!==null?(u=Os(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E,y){w.maddr=y}(d,t[2])),t===null&&(n=d),t}function _i(){var t,o,u,d,T;return d=n,T=n,e.substr(n,8).toLowerCase()==="received"?(t=e.substr(n,8),n+=8):(t=null,m('"received"')),t!==null?(o=Ce(),o!==null?(u=Ds(),u===null&&(u=fs()),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E,y){w.received=y}(d,t[2])),t===null&&(n=d),t}function hi(){var t,o,u,d,T;return d=n,T=n,e.substr(n,6).toLowerCase()==="branch"?(t=e.substr(n,6),n+=6):(t=null,m('"branch"')),t!==null?(o=Ce(),o!==null?(u=N(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E,y){w.branch=y}(d,t[2])),t===null&&(n=d),t}function di(){var t,o,u,d,T;return d=n,e.substr(n,5).toLowerCase()==="rport"?(t=e.substr(n,5),n+=5):(t=null,m('"rport"')),t!==null?(T=n,o=Ce(),o!==null?(u=pi(),u!==null?o=[o,u]:(o=null,n=T)):(o=null,n=T),o=o!==null?o:"",o!==null?t=[t,o]:(t=null,n=d)):(t=null,n=d),t}function pi(){var t,o,u,d,T,E,y;return E=n,y=n,t=A(),t=t!==null?t:"",t!==null?(o=A(),o=o!==null?o:"",o!==null?(u=A(),u=u!==null?u:"",u!==null?(d=A(),d=d!==null?d:"",d!==null?(T=A(),T=T!==null?T:"",T!==null?t=[t,o,u,d,T]:(t=null,n=y)):(t=null,n=y)):(t=null,n=y)):(t=null,n=y)):(t=null,n=y),t!==null&&(t=function(O,G){w.rport=parseInt(G.join(""))}(E,t)),t===null&&(n=E),t}function mi(){var t,o,u,d,T,E;return E=n,t=gi(),t!==null?(o=De(),o!==null?(u=N(),u!==null?(d=De(),d!==null?(T=Ti(),T!==null?t=[t,o,u,d,T]:(t=null,n=E)):(t=null,n=E)):(t=null,n=E)):(t=null,n=E)):(t=null,n=E),t}function gi(){var t,o;return o=n,e.substr(n,3).toLowerCase()==="sip"?(t=e.substr(n,3),n+=3):(t=null,m('"SIP"')),t===null&&(t=N()),t!==null&&(t=function(u,d){w.protocol=d}(o,t)),t===null&&(n=o),t}function Ti(){var t,o;return o=n,e.substr(n,3).toLowerCase()==="udp"?(t=e.substr(n,3),n+=3):(t=null,m('"UDP"')),t===null&&(e.substr(n,3).toLowerCase()==="tcp"?(t=e.substr(n,3),n+=3):(t=null,m('"TCP"')),t===null&&(e.substr(n,3).toLowerCase()==="tls"?(t=e.substr(n,3),n+=3):(t=null,m('"TLS"')),t===null&&(e.substr(n,4).toLowerCase()==="sctp"?(t=e.substr(n,4),n+=4):(t=null,m('"SCTP"')),t===null&&(t=N())))),t!==null&&(t=function(u,d){w.transport=d}(o,t)),t===null&&(n=o),t}function Yn(){var t,o,u,d,T;return d=n,t=xl(),t!==null?(T=n,o=Ae(),o!==null?(u=Ml(),u!==null?o=[o,u]:(o=null,n=T)):(o=null,n=T),o=o!==null?o:"",o!==null?t=[t,o]:(t=null,n=d)):(t=null,n=d),t}function xl(){var t,o;return o=n,t=Ds(),t===null&&(t=pt(),t===null&&(t=rn())),t!==null&&(t=function(u){w.host=e.substring(n,u)}(o)),t===null&&(n=o),t}function Ml(){var t,o,u,d,T,E,y;return E=n,y=n,t=A(),t=t!==null?t:"",t!==null?(o=A(),o=o!==null?o:"",o!==null?(u=A(),u=u!==null?u:"",u!==null?(d=A(),d=d!==null?d:"",d!==null?(T=A(),T=T!==null?T:"",T!==null?t=[t,o,u,d,T]:(t=null,n=y)):(t=null,n=y)):(t=null,n=y)):(t=null,n=y)):(t=null,n=y),t!==null&&(t=function(O,G){w.port=parseInt(G.join(""))}(E,t)),t===null&&(n=E),t}function Jn(){var t,o,u,d,T;return d=n,T=n,t=A(),t!==null?(o=A(),o=o!==null?o:"",o!==null?(u=A(),u=u!==null?u:"",u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E,y){return parseInt(y.join(""))}(d,t)),t===null&&(n=d),t}function vi(){var t;return t=Fs(),t}function kl(){var t,o,u,d,T,E;if(T=n,t=Ll(),t!==null){for(o=[],E=n,u=le(),u!==null?(d=zn(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);u!==null;)o.push(u),E=n,u=le(),u!==null?(d=zn(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);o!==null?t=[t,o]:(t=null,n=T)}else t=null,n=T;return t}function Ll(){var t,o;return o=n,t=ns(),t!==null&&(t=function(u,d){w.expires=d}(o,t)),t===null&&(n=o),t}function zn(){var t;return t=$l(),t===null&&(t=Xe()),t}function $l(){var t,o,u,d,T;return d=n,T=n,e.substr(n,9).toLowerCase()==="refresher"?(t=e.substr(n,9),n+=9):(t=null,m('"refresher"')),t!==null?(o=Ce(),o!==null?(e.substr(n,3).toLowerCase()==="uac"?(u=e.substr(n,3),n+=3):(u=null,m('"uac"')),u===null&&(e.substr(n,3).toLowerCase()==="uas"?(u=e.substr(n,3),n+=3):(u=null,m('"uas"'))),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E,y){w.refresher=y.toLowerCase()}(d,t[2])),t===null&&(n=d),t}function co(){var t,o,u,d;return d=n,t=N(),t!==null?(o=B(),o!==null?(u=Ei(),u!==null?t=[t,o,u]:(t=null,n=d)):(t=null,n=d)):(t=null,n=d),t}function Ei(){var t,o;for(t=[],o=Q(),o===null&&(o=se(),o===null&&(o=q()));o!==null;)t.push(o),o=Q(),o===null&&(o=se(),o===null&&(o=q()));return t}function Gt(){var t,o;for(t=[],o=W();o!==null;)t.push(o),o=W();return t}function Hl(){var t,o,u;return u=n,e.substr(n,5)==="uuid:"?(t="uuid:",n+=5):(t=null,m('"uuid:"')),t!==null?(o=Si(),o!==null?t=[t,o]:(t=null,n=u)):(t=null,n=u),t}function Si(){var t,o,u,d,T,E,y,O,G,ye,Fe;return ye=n,Fe=n,t=Fl(),t!==null?(e.charCodeAt(n)===45?(o="-",n++):(o=null,m('"-"')),o!==null?(u=Wt(),u!==null?(e.charCodeAt(n)===45?(d="-",n++):(d=null,m('"-"')),d!==null?(T=Wt(),T!==null?(e.charCodeAt(n)===45?(E="-",n++):(E=null,m('"-"')),E!==null?(y=Wt(),y!==null?(e.charCodeAt(n)===45?(O="-",n++):(O=null,m('"-"')),O!==null?(G=yi(),G!==null?t=[t,o,u,d,T,E,y,O,G]:(t=null,n=Fe)):(t=null,n=Fe)):(t=null,n=Fe)):(t=null,n=Fe)):(t=null,n=Fe)):(t=null,n=Fe)):(t=null,n=Fe)):(t=null,n=Fe)):(t=null,n=Fe),t!==null&&(t=function(P,me){w=e.substring(n+5,P)}(ye,t[0])),t===null&&(n=ye),t}function Wt(){var t,o,u,d,T;return T=n,t=I(),t!==null?(o=I(),o!==null?(u=I(),u!==null?(d=I(),d!==null?t=[t,o,u,d]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t}function Fl(){var t,o,u;return u=n,t=Wt(),t!==null?(o=Wt(),o!==null?t=[t,o]:(t=null,n=u)):(t=null,n=u),t}function yi(){var t,o,u,d;return d=n,t=Wt(),t!==null?(o=Wt(),o!==null?(u=Wt(),u!==null?t=[t,o,u]:(t=null,n=d)):(t=null,n=d)):(t=null,n=d),t}function Ai(){var t,o,u,d,T,E,y;if(T=n,E=n,t=He(),t===null&&(t=ss()),t!==null){for(o=[],y=n,u=le(),u!==null?(d=Xe(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);u!==null;)o.push(u),y=n,u=le(),u!==null?(d=Xe(),d!==null?u=[u,d]:(u=null,n=y)):(u=null,n=y);o!==null?t=[t,o]:(t=null,n=E)}else t=null,n=E;return t!==null&&(t=function(O){try{w=new rs(w.uri,w.display_name,w.params)}catch{w=-1}}()),t===null&&(n=T),t}function jl(){var t,o,u,d,T,E;if(T=n,t=Ci(),t!==null){for(o=[],E=n,u=le(),u!==null?(d=Xn(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);u!==null;)o.push(u),E=n,u=le(),u!==null?(d=Xn(),d!==null?u=[u,d]:(u=null,n=E)):(u=null,n=E);o!==null?t=[t,o]:(t=null,n=T)}else t=null,n=T;return t}function Ci(){var t,o,u,d,T,E;return d=n,T=n,t=ae(),t!==null?(E=n,e.charCodeAt(n)===64?(o="@",n++):(o=null,m('"@"')),o!==null?(u=ae(),u!==null?o=[o,u]:(o=null,n=E)):(o=null,n=E),o=o!==null?o:"",o!==null?t=[t,o]:(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(y){w.call_id=e.substring(n,y)}(d)),t===null&&(n=d),t}function Xn(){var t;return t=ql(),t===null&&(t=Vl(),t===null&&(t=Ri(),t===null&&(t=Xe()))),t}function ql(){var t,o,u,d,T;return d=n,T=n,e.substr(n,6)==="to-tag"?(t="to-tag",n+=6):(t=null,m('"to-tag"')),t!==null?(o=Ce(),o!==null?(u=N(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E,y){w.to_tag=y}(d,t[2])),t===null&&(n=d),t}function Vl(){var t,o,u,d,T;return d=n,T=n,e.substr(n,8)==="from-tag"?(t="from-tag",n+=8):(t=null,m('"from-tag"')),t!==null?(o=Ce(),o!==null?(u=N(),u!==null?t=[t,o,u]:(t=null,n=T)):(t=null,n=T)):(t=null,n=T),t!==null&&(t=function(E,y){w.from_tag=y}(d,t[2])),t===null&&(n=d),t}function Ri(){var t,o;return o=n,e.substr(n,10)==="early-only"?(t="early-only",n+=10):(t=null,m('"early-only"')),t!==null&&(t=function(u){w.early_only=!0}()),t===null&&(n=o),t}function Vs(t){t.sort();for(var o=null,u=[],d=0;d<t.length;d++)t[d]!==o&&(u.push(t[d]),o=t[d]);return u}function b(){for(var t=1,o=1,u=!1,d=0;d<Math.max(n,v);d++){var T=e.charAt(d);T===`
75
+ `?(u||t++,o=1,u=!1):T==="\r"||T==="\u2028"||T==="\u2029"?(t++,o=1,u=!0):(o++,u=!1)}return{line:t,column:o}}var Bl=Is(),rs=$u(),w={},Gl=g[p]();if(Gl===null||n!==e.length){var r=Math.max(n,v),f=r<e.length?e.charAt(r):null,h=b();return new this.SyntaxError(Vs(S),f,r,h.line,h.column),-1}return w},toSource:function(){return this._source}};s.SyntaxError=function(e,p,g,n,v){function S(m,C){var A,R;switch(m.length){case 0:A="end of input";break;case 1:A=m[0];break;default:A=m.slice(0,m.length-1).join(", ")+" or "+m[m.length-1]}return R=C?c(C):"end of input","Expected "+A+" but "+R+" found."}this.name="SyntaxError",this.expected=e,this.found=p,this.message=S(e,p),this.offset=g,this.line=n,this.column=v},s.SyntaxError.prototype=Error.prototype;const i='INVITE sip:ds881ehp@6ke7klp2hppe.invalid;transport=ws;+sip.ice;reg-id=1;+sip.instance="<urn:uuid:378e5fc1-d7b5-42a9-8bf3-2b796aa0c67e>" SIP/2.0',l="INVITE sip:gsfjq6nt@6itebkeio2hf.invalid;transport=ws SIP/2.0",a=s.parse(i,"Request_Response");console.log("newRes",a),console.log("#############################################");const _=s.parse(l,"Request_Response");return console.log("oldRes",_),ef}var ko,nf;function Is(){if(nf)return ko;nf=1;const c=Me,s=Ct(),i=Qt();return ko=class f_{static parse(a){if(a=i.parse(a,"SIP_URI"),a!==-1)return a}constructor(a,_,e,p,g={},n={}){if(!e)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=a||c.SIP,this._user=_,this._host=e,this._port=p;for(const v in g)Object.prototype.hasOwnProperty.call(g,v)&&this.setParam(v,g[v]);for(const v in n)Object.prototype.hasOwnProperty.call(n,v)&&this.setHeader(v,n[v])}get scheme(){return this._scheme}set scheme(a){this._scheme=a.toLowerCase()}get user(){return this._user}set user(a){this._user=a}get host(){return this._host}set host(a){this._host=a.toLowerCase()}get port(){return this._port}set port(a){this._port=a===0?a:parseInt(a,10)||null}setParam(a,_){a&&(this._parameters[a.toLowerCase()]=typeof _>"u"||_===null?null:_.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 _=this._parameters[a];return delete this._parameters[a],_}}clearParams(){this._parameters={}}setHeader(a,_){this._headers[s.headerize(a)]=Array.isArray(_)?_:[_]}getHeader(a){if(a)return this._headers[s.headerize(a)]}hasHeader(a){if(a)return this._headers.hasOwnProperty(s.headerize(a))&&!0||!1}deleteHeader(a){if(a=s.headerize(a),this._headers.hasOwnProperty(a)){const _=this._headers[a];return delete this._headers[a],_}}clearHeaders(){this._headers={}}clone(){return new f_(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}toString(){const a=[];let _=`${this._scheme}:`;this._user&&(_+=`${s.escapeUser(this._user)}@`),_+=this._host,(this._port||this._port===0)&&(_+=`:${this._port}`);for(const e in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,e)&&(_+=`;${e}`,this._parameters[e]!==null&&(_+=`=${this._parameters[e]}`));for(const e in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,e))for(const p of this._headers[e])a.push(`${e}=${p}`);return a.length>0&&(_+=`?${a.join("&")}`),_}toAor(a){let _=`${this._scheme}:`;return this._user&&(_+=`${s.escapeUser(this._user)}@`),_+=this._host,a&&(this._port||this._port===0)&&(_+=`:${this._port}`),_}},ko}var rf;function Ct(){if(rf)return rt;rf=1;const c=Me,s=Is(),i=Qt();rt.str_utf8_length=e=>unescape(encodeURIComponent(e)).length;const l=rt.isFunction=e=>e!==void 0?Object.prototype.toString.call(e)==="[object Function]":!1;rt.isString=e=>e!==void 0?Object.prototype.toString.call(e)==="[object String]":!1,rt.isDecimal=e=>!isNaN(e)&&parseFloat(e)===parseInt(e,10),rt.isEmpty=e=>e===null||e===""||e===void 0||Array.isArray(e)&&e.length===0||typeof e=="number"&&isNaN(e),rt.hasMethods=function(e,...p){for(const g of p)if(l(e[g]))return!1;return!0};const a=rt.createRandomToken=(e,p=32)=>{let g,n,v="";for(g=0;g<e;g++)n=Math.random()*p|0,v+=n.toString(p);return v};rt.newTag=()=>a(10),rt.newUUID=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,p=>{const g=Math.random()*16|0;return(p==="x"?g:g&3|8).toString(16)}),rt.hostType=e=>{if(e){if(e=i.parse(e,"host"),e!==-1)return e.host_type}else return};const _=rt.escapeUser=e=>encodeURIComponent(decodeURIComponent(e)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/");return rt.normalizeTarget=(e,p)=>{if(e){if(e instanceof s)return e;if(typeof e=="string"){const g=e.split("@");let n,v;switch(g.length){case 1:if(!p)return;n=e,v=p;break;case 2:n=g[0],v=g[1];break;default:n=g.slice(0,g.length-1).join("@"),v=g[g.length-1]}n=n.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(n)&&(n=n.replace(/[-.()]/g,"")),e=`${c.SIP}:${_(n)}@${v}`;let S;return(S=s.parse(e))?S:void 0}else return}else return},rt.headerize=e=>{const p={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},g=e.toLowerCase().replace(/_/g,"-").split("-");let n="";const v=g.length;let S;for(S=0;S<v;S++)S!==0&&(n+="-"),n+=g[S].charAt(0).toUpperCase()+g[S].substring(1);return p[n]&&(n=p[n]),n},rt.sipErrorCause=e=>{for(const p in c.SIP_ERROR_CAUSES)if(c.SIP_ERROR_CAUSES[p].indexOf(e)!==-1)return c.causes[p];return c.causes.SIP_FAILURE_CODE},rt.getRandomTestNetIP=()=>{function e(p,g){return Math.floor(Math.random()*(g-p+1)+p)}return`192.0.2.${e(1,254)}`},rt.calculateMD5=e=>{function p(le,Ae){return le<<Ae|le>>>32-Ae}function g(le,Ae){const Oe=le&2147483648,Pe=Ae&2147483648,ve=le&1073741824,he=Ae&1073741824,pe=(le&1073741823)+(Ae&1073741823);return ve&he?pe^2147483648^Oe^Pe:ve|he?pe&1073741824?pe^3221225472^Oe^Pe:pe^1073741824^Oe^Pe:pe^Oe^Pe}function n(le,Ae,Oe){return le&Ae|~le&Oe}function v(le,Ae,Oe){return le&Oe|Ae&~Oe}function S(le,Ae,Oe){return le^Ae^Oe}function m(le,Ae,Oe){return Ae^(le|~Oe)}function C(le,Ae,Oe,Pe,ve,he,pe){return le=g(le,g(g(n(Ae,Oe,Pe),ve),pe)),g(p(le,he),Ae)}function A(le,Ae,Oe,Pe,ve,he,pe){return le=g(le,g(g(v(Ae,Oe,Pe),ve),pe)),g(p(le,he),Ae)}function R(le,Ae,Oe,Pe,ve,he,pe){return le=g(le,g(g(S(Ae,Oe,Pe),ve),pe)),g(p(le,he),Ae)}function I(le,Ae,Oe,Pe,ve,he,pe){return le=g(le,g(g(m(Ae,Oe,Pe),ve),pe)),g(p(le,he),Ae)}function V(le){let Ae;const Oe=le.length,Pe=Oe+8,he=((Pe-Pe%64)/64+1)*16,pe=new Array(he-1);let Ne=0,xe=0;for(;xe<Oe;)Ae=(xe-xe%4)/4,Ne=xe%4*8,pe[Ae]=pe[Ae]|le.charCodeAt(xe)<<Ne,xe++;return Ae=(xe-xe%4)/4,Ne=xe%4*8,pe[Ae]=pe[Ae]|128<<Ne,pe[he-2]=Oe<<3,pe[he-1]=Oe>>>29,pe}function W(le){let Ae="",Oe="",Pe,ve;for(ve=0;ve<=3;ve++)Pe=le>>>ve*8&255,Oe=`0${Pe.toString(16)}`,Ae=Ae+Oe.substr(Oe.length-2,2);return Ae}function oe(le){let Ae="";for(let Oe=0;Oe<le.length;Oe++){const Pe=le.charCodeAt(Oe);Pe<128?Ae+=String.fromCharCode(Pe):Pe>127&&Pe<2048?(Ae+=String.fromCharCode(Pe>>6|192),Ae+=String.fromCharCode(Pe&63|128)):(Ae+=String.fromCharCode(Pe>>12|224),Ae+=String.fromCharCode(Pe>>6&63|128),Ae+=String.fromCharCode(Pe&63|128))}return Ae}let x=[],$,Re,Ie,H,D,L,q,j,B;const X=7,Q=12,U=17,se=22,It=5,N=9,Y=14,re=20,ae=4,Te=11,De=16,Ce=23,Le=6,we=10,Se=15,it=21;for(e=oe(e),x=V(e),L=1732584193,q=4023233417,j=2562383102,B=271733878,$=0;$<x.length;$+=16)Re=L,Ie=q,H=j,D=B,L=C(L,q,j,B,x[$+0],X,3614090360),B=C(B,L,q,j,x[$+1],Q,3905402710),j=C(j,B,L,q,x[$+2],U,606105819),q=C(q,j,B,L,x[$+3],se,3250441966),L=C(L,q,j,B,x[$+4],X,4118548399),B=C(B,L,q,j,x[$+5],Q,1200080426),j=C(j,B,L,q,x[$+6],U,2821735955),q=C(q,j,B,L,x[$+7],se,4249261313),L=C(L,q,j,B,x[$+8],X,1770035416),B=C(B,L,q,j,x[$+9],Q,2336552879),j=C(j,B,L,q,x[$+10],U,4294925233),q=C(q,j,B,L,x[$+11],se,2304563134),L=C(L,q,j,B,x[$+12],X,1804603682),B=C(B,L,q,j,x[$+13],Q,4254626195),j=C(j,B,L,q,x[$+14],U,2792965006),q=C(q,j,B,L,x[$+15],se,1236535329),L=A(L,q,j,B,x[$+1],It,4129170786),B=A(B,L,q,j,x[$+6],N,3225465664),j=A(j,B,L,q,x[$+11],Y,643717713),q=A(q,j,B,L,x[$+0],re,3921069994),L=A(L,q,j,B,x[$+5],It,3593408605),B=A(B,L,q,j,x[$+10],N,38016083),j=A(j,B,L,q,x[$+15],Y,3634488961),q=A(q,j,B,L,x[$+4],re,3889429448),L=A(L,q,j,B,x[$+9],It,568446438),B=A(B,L,q,j,x[$+14],N,3275163606),j=A(j,B,L,q,x[$+3],Y,4107603335),q=A(q,j,B,L,x[$+8],re,1163531501),L=A(L,q,j,B,x[$+13],It,2850285829),B=A(B,L,q,j,x[$+2],N,4243563512),j=A(j,B,L,q,x[$+7],Y,1735328473),q=A(q,j,B,L,x[$+12],re,2368359562),L=R(L,q,j,B,x[$+5],ae,4294588738),B=R(B,L,q,j,x[$+8],Te,2272392833),j=R(j,B,L,q,x[$+11],De,1839030562),q=R(q,j,B,L,x[$+14],Ce,4259657740),L=R(L,q,j,B,x[$+1],ae,2763975236),B=R(B,L,q,j,x[$+4],Te,1272893353),j=R(j,B,L,q,x[$+7],De,4139469664),q=R(q,j,B,L,x[$+10],Ce,3200236656),L=R(L,q,j,B,x[$+13],ae,681279174),B=R(B,L,q,j,x[$+0],Te,3936430074),j=R(j,B,L,q,x[$+3],De,3572445317),q=R(q,j,B,L,x[$+6],Ce,76029189),L=R(L,q,j,B,x[$+9],ae,3654602809),B=R(B,L,q,j,x[$+12],Te,3873151461),j=R(j,B,L,q,x[$+15],De,530742520),q=R(q,j,B,L,x[$+2],Ce,3299628645),L=I(L,q,j,B,x[$+0],Le,4096336452),B=I(B,L,q,j,x[$+7],we,1126891415),j=I(j,B,L,q,x[$+14],Se,2878612391),q=I(q,j,B,L,x[$+5],it,4237533241),L=I(L,q,j,B,x[$+12],Le,1700485571),B=I(B,L,q,j,x[$+3],we,2399980690),j=I(j,B,L,q,x[$+10],Se,4293915773),q=I(q,j,B,L,x[$+1],it,2240044497),L=I(L,q,j,B,x[$+8],Le,1873313359),B=I(B,L,q,j,x[$+15],we,4264355552),j=I(j,B,L,q,x[$+6],Se,2734768916),q=I(q,j,B,L,x[$+13],it,1309151649),L=I(L,q,j,B,x[$+4],Le,4149444226),B=I(B,L,q,j,x[$+11],we,3174756917),j=I(j,B,L,q,x[$+2],Se,718787259),q=I(q,j,B,L,x[$+9],it,3951481745),L=g(L,Re),q=g(q,Ie),j=g(j,H),B=g(B,D);return(W(L)+W(q)+W(j)+W(B)).toLowerCase()},rt.closeMediaStream=e=>{if(e)try{let p;if(e.getTracks){p=e.getTracks();for(const g of p)g.stop()}else{p=e.getAudioTracks();for(const g of p)g.stop();p=e.getVideoTracks();for(const g of p)g.stop()}}catch{(typeof e.stop=="function"||typeof e.stop=="object")&&e.stop()}},rt.cloneArray=e=>e&&e.slice()||[],rt.cloneObject=(e,p={})=>e&&Object.assign({},e)||p,rt}const __=kt,Fm=ut,At=Me,at=Ct(),lf=$u(),jm=Qt(),Lo=new Fm("SIPMessage");class eo{constructor(s,i,l,a,_,e){if(!s||!i||!l)return null;a=a||{},this.ua=l,this.headers={},this.method=s,this.ruri=i,this.body=e,this.extraHeaders=at.cloneArray(_),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),a.route_set?this.setHeader("route",a.route_set):l.configuration.use_preloaded_route&&this.setHeader("route",`<${l.transport.sip_uri};lr>`),this.setHeader("via",""),this.setHeader("max-forwards",At.MAX_FORWARDS);const p=a.to_uri||i,g=a.to_tag?{tag:a.to_tag}:null,n=typeof a.to_display_name<"u"?a.to_display_name:null;this.to=new lf(p,n,g),this.setHeader("to",this.to.toString());const v=a.from_uri||l.configuration.uri,S={tag:a.from_tag||at.newTag()};let m;typeof a.from_display_name<"u"?m=a.from_display_name:l.configuration.display_name?m=l.configuration.display_name:m=null,this.from=new lf(v,m,S),this.setHeader("from",this.from.toString());const C=a.call_id||l.configuration.jssip_id+at.createRandomToken(15);this.call_id=C,this.setHeader("call-id",C);const A=a.cseq||Math.floor(Math.random()*1e4);this.cseq=A,this.setHeader("cseq",`${A} ${s}`)}setHeader(s,i){const l=new RegExp(`^\\s*${s}\\s*:`,"i");for(let a=0;a<this.extraHeaders.length;a++)l.test(this.extraHeaders[a])&&this.extraHeaders.splice(a,1);this.headers[at.headerize(s)]=Array.isArray(i)?i:[i]}getHeader(s){const i=this.headers[at.headerize(s)];if(i){if(i[0])return i[0]}else{const l=new RegExp(`^\\s*${s}\\s*:`,"i");for(const a of this.extraHeaders)if(l.test(a))return a.substring(a.indexOf(":")+1).trim()}}getHeaders(s){const i=this.headers[at.headerize(s)],l=[];if(i){for(const a of i)l.push(a);return l}else{const a=new RegExp(`^\\s*${s}\\s*:`,"i");for(const _ of this.extraHeaders)a.test(_)&&l.push(_.substring(_.indexOf(":")+1).trim());return l}}hasHeader(s){if(this.headers[at.headerize(s)])return!0;{const i=new RegExp(`^\\s*${s}\\s*:`,"i");for(const l of this.extraHeaders)if(i.test(l))return!0}return!1}parseSDP(s){return!s&&this.sdp?this.sdp:(this.sdp=__.parse(this.body||""),this.sdp)}toString(){let s=`${this.method} ${this.ruri} SIP/2.0\r
76
+ `;for(const a in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,a))for(const _ of this.headers[a])s+=`${a}: ${_}\r
77
77
  `;for(const a of this.extraHeaders)s+=`${a.trim()}\r
78
- `;const r=[];switch(this.method){case St.REGISTER:r.push("path","gruu");break;case St.INVITE:this.ua.configuration.session_timers&&r.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&r.push("gruu"),r.push("ice","replaces");break;case St.UPDATE:this.ua.configuration.session_timers&&r.push("timer"),r.push("ice");break}r.push("outbound");const o=this.ua.configuration.user_agent||St.USER_AGENT;if(s+=`Allow: ${St.ALLOWED_METHODS}\r
79
- `,s+=`Supported: ${r}\r
80
- `,s+=`User-Agent: ${o}\r
81
- `,this.body){const a=rt.str_utf8_length(this.body);s+=`Content-Length: ${a}\r
78
+ `;const i=[];switch(this.method){case At.REGISTER:i.push("path","gruu");break;case At.INVITE:this.ua.configuration.session_timers&&i.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&i.push("gruu"),i.push("ice","replaces");break;case At.UPDATE:this.ua.configuration.session_timers&&i.push("timer"),i.push("ice");break}i.push("outbound");const l=this.ua.configuration.user_agent||At.USER_AGENT;if(s+=`Allow: ${At.ALLOWED_METHODS}\r
79
+ `,s+=`Supported: ${i}\r
80
+ `,s+=`User-Agent: ${l}\r
81
+ `,this.body){const a=at.str_utf8_length(this.body);s+=`Content-Length: ${a}\r
82
82
  \r
83
83
  `,s+=this.body}else s+=`Content-Length: 0\r
84
84
  \r
85
- `;return s}clone(){const s=new Vo(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(r){s.headers[r]=this.headers[r].slice()},this),s.body=this.body,s.extraHeaders=rt.cloneArray(this.extraHeaders),s.to=this.to,s.from=this.from,s.call_id=this.call_id,s.cseq=this.cseq,s}}class Mu extends Vo{constructor(s,r,o,a,t){super(St.INVITE,s,r,o,a,t),this.transaction=null}cancel(s){this.transaction.cancel(s)}clone(){const s=new Mu(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(r){s.headers[r]=this.headers[r].slice()},this),s.body=this.body,s.extraHeaders=rt.cloneArray(this.extraHeaders),s.to=this.to,s.from=this.from,s.call_id=this.call_id,s.cseq=this.cseq,s.transaction=this.transaction,s}}class u_{constructor(){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}addHeader(s,r){const o={raw:r};s=rt.headerize(s),this.headers[s]?this.headers[s].push(o):this.headers[s]=[o]}getHeader(s){const r=this.headers[rt.headerize(s)];if(r){if(r[0])return r[0].raw}else return}getHeaders(s){const r=this.headers[rt.headerize(s)],o=[];if(!r)return[];for(const a of r)o.push(a.raw);return o}hasHeader(s){return!!this.headers[rt.headerize(s)]}parseHeader(s,r=0){if(s=rt.headerize(s),this.headers[s]){if(r>=this.headers[s].length){Pa.debug(`not so many "${s}" headers present`);return}}else{Pa.debug(`header "${s}" not present`);return}const o=this.headers[s][r],a=o.raw;if(o.parsed)return o.parsed;const t=km.parse(a,s.replace(/-/g,"_"));if(t===-1){this.headers[s].splice(r,1),Pa.debug(`error parsing "${s}" header field with value "${a}"`);return}else return o.parsed=t,t}s(s,r){return this.parseHeader(s,r)}setHeader(s,r){const o={raw:r};this.headers[rt.headerize(s)]=[o]}parseSDP(s){return!s&&this.sdp?this.sdp:(this.sdp=a_.parse(this.body||""),this.sdp)}toString(){return this.data}}class Lm extends u_{constructor(s){super(),this.ua=s,this.headers={},this.ruri=null,this.transport=null,this.server_transaction=null}reply(s,r,o,a,t,n){const d=[];let _=this.getHeader("To");if(s=s||null,r=r||null,!s||s<100||s>699)throw new TypeError(`Invalid status_code: ${s}`);if(r&&typeof r!="string"&&!(r instanceof String))throw new TypeError(`Invalid reason_phrase: ${r}`);r=r||St.REASON_PHRASE[s]||"",o=rt.cloneArray(o),this.ua.configuration.extra_headers&&(o=o.concat(this.ua.configuration.extra_headers));let h=`SIP/2.0 ${s} ${r}\r
86
- `;if(this.method===St.INVITE&&s>100&&s<=200){const T=this.getHeaders("record-route");for(const E of T)h+=`Record-Route: ${E}\r
87
- `}const g=this.getHeaders("via");for(const T of g)h+=`Via: ${T}\r
88
- `;!this.to_tag&&s>100?_+=`;tag=${rt.newTag()}`:this.to_tag&&!this.s("to").hasParam("tag")&&(_+=`;tag=${this.to_tag}`),h+=`To: ${_}\r
89
- `,h+=`From: ${this.getHeader("From")}\r
90
- `,h+=`Call-ID: ${this.call_id}\r
91
- `,h+=`CSeq: ${this.cseq} ${this.method}\r
92
- `;for(const T of o)h+=`${T.trim()}\r
93
- `;switch(this.method){case St.INVITE:this.ua.configuration.session_timers&&d.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&d.push("gruu"),d.push("ice","replaces");break;case St.UPDATE:this.ua.configuration.session_timers&&d.push("timer"),a&&d.push("ice"),d.push("replaces")}if(d.push("outbound"),this.method===St.OPTIONS?(h+=`Allow: ${St.ALLOWED_METHODS}\r
94
- `,h+=`Accept: ${St.ACCEPTED_BODY_TYPES}\r
95
- `):s===405?h+=`Allow: ${St.ALLOWED_METHODS}\r
96
- `:s===415&&(h+=`Accept: ${St.ACCEPTED_BODY_TYPES}\r
97
- `),h+=`Supported: ${d}\r
98
- `,a){const T=rt.str_utf8_length(a);h+=`Content-Type: application/sdp\r
99
- `,h+=`Content-Length: ${T}\r
85
+ `;return s}clone(){const s=new eo(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(i){s.headers[i]=this.headers[i].slice()},this),s.body=this.body,s.extraHeaders=at.cloneArray(this.extraHeaders),s.to=this.to,s.from=this.from,s.call_id=this.call_id,s.cseq=this.cseq,s}}class Hu extends eo{constructor(s,i,l,a,_){super(At.INVITE,s,i,l,a,_),this.transaction=null}cancel(s){this.transaction.cancel(s)}clone(){const s=new Hu(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(i){s.headers[i]=this.headers[i].slice()},this),s.body=this.body,s.extraHeaders=at.cloneArray(this.extraHeaders),s.to=this.to,s.from=this.from,s.call_id=this.call_id,s.cseq=this.cseq,s.transaction=this.transaction,s}}class h_{constructor(){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}addHeader(s,i){const l={raw:i};s=at.headerize(s),this.headers[s]?this.headers[s].push(l):this.headers[s]=[l]}getHeader(s){const i=this.headers[at.headerize(s)];if(i){if(i[0])return i[0].raw}else return}getHeaders(s){const i=this.headers[at.headerize(s)],l=[];if(!i)return[];for(const a of i)l.push(a.raw);return l}hasHeader(s){return!!this.headers[at.headerize(s)]}parseHeader(s,i=0){if(s=at.headerize(s),this.headers[s]){if(i>=this.headers[s].length){Lo.debug(`not so many "${s}" headers present`);return}}else{Lo.debug(`header "${s}" not present`);return}const l=this.headers[s][i],a=l.raw;if(l.parsed)return l.parsed;const _=jm.parse(a,s.replace(/-/g,"_"));if(_===-1){this.headers[s].splice(i,1),Lo.debug(`error parsing "${s}" header field with value "${a}"`);return}else return l.parsed=_,_}s(s,i){return this.parseHeader(s,i)}setHeader(s,i){const l={raw:i};this.headers[at.headerize(s)]=[l]}parseSDP(s){return!s&&this.sdp?this.sdp:(this.sdp=__.parse(this.body||""),this.sdp)}toString(){return this.data}}class qm extends h_{constructor(s){super(),this.ua=s,this.headers={},this.ruri=null,this.transport=null,this.server_transaction=null}reply(s,i,l,a,_,e){const p=[];let g=this.getHeader("To");if(s=s||null,i=i||null,!s||s<100||s>699)throw new TypeError(`Invalid status_code: ${s}`);if(i&&typeof i!="string"&&!(i instanceof String))throw new TypeError(`Invalid reason_phrase: ${i}`);i=i||At.REASON_PHRASE[s]||"",l=at.cloneArray(l),this.ua.configuration.extra_headers&&(l=l.concat(this.ua.configuration.extra_headers));let n=`SIP/2.0 ${s} ${i}\r
86
+ `;if(this.method===At.INVITE&&s>100&&s<=200){const S=this.getHeaders("record-route");for(const m of S)n+=`Record-Route: ${m}\r
87
+ `}const v=this.getHeaders("via");for(const S of v)n+=`Via: ${S}\r
88
+ `;!this.to_tag&&s>100?g+=`;tag=${at.newTag()}`:this.to_tag&&!this.s("to").hasParam("tag")&&(g+=`;tag=${this.to_tag}`),n+=`To: ${g}\r
89
+ `,n+=`From: ${this.getHeader("From")}\r
90
+ `,n+=`Call-ID: ${this.call_id}\r
91
+ `,n+=`CSeq: ${this.cseq} ${this.method}\r
92
+ `;for(const S of l)n+=`${S.trim()}\r
93
+ `;switch(this.method){case At.INVITE:this.ua.configuration.session_timers&&p.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&p.push("gruu"),p.push("ice","replaces");break;case At.UPDATE:this.ua.configuration.session_timers&&p.push("timer"),a&&p.push("ice"),p.push("replaces")}if(p.push("outbound"),this.method===At.OPTIONS?(n+=`Allow: ${At.ALLOWED_METHODS}\r
94
+ `,n+=`Accept: ${At.ACCEPTED_BODY_TYPES}\r
95
+ `):s===405?n+=`Allow: ${At.ALLOWED_METHODS}\r
96
+ `:s===415&&(n+=`Accept: ${At.ACCEPTED_BODY_TYPES}\r
97
+ `),n+=`Supported: ${p}\r
98
+ `,a){const S=at.str_utf8_length(a);n+=`Content-Type: application/sdp\r
99
+ `,n+=`Content-Length: ${S}\r
100
100
  \r
101
- `,h+=a}else h+=`Content-Length: 0\r
101
+ `,n+=a}else n+=`Content-Length: 0\r
102
102
  \r
103
- `;this.server_transaction.receiveResponse(s,h,t,n)}reply_sl(s=null,r=null){const o=this.getHeaders("via");if(!s||s<100||s>699)throw new TypeError(`Invalid status_code: ${s}`);if(r&&typeof r!="string"&&!(r instanceof String))throw new TypeError(`Invalid reason_phrase: ${r}`);r=r||St.REASON_PHRASE[s]||"";let a=`SIP/2.0 ${s} ${r}\r
104
- `;for(const n of o)a+=`Via: ${n}\r
105
- `;let t=this.getHeader("To");if(!this.to_tag&&s>100?t+=`;tag=${rt.newTag()}`:this.to_tag&&!this.s("to").hasParam("tag")&&(t+=`;tag=${this.to_tag}`),a+=`To: ${t}\r
103
+ `;this.server_transaction.receiveResponse(s,n,_,e)}reply_sl(s=null,i=null){const l=this.getHeaders("via");if(!s||s<100||s>699)throw new TypeError(`Invalid status_code: ${s}`);if(i&&typeof i!="string"&&!(i instanceof String))throw new TypeError(`Invalid reason_phrase: ${i}`);i=i||At.REASON_PHRASE[s]||"";let a=`SIP/2.0 ${s} ${i}\r
104
+ `;for(const e of l)a+=`Via: ${e}\r
105
+ `;let _=this.getHeader("To");if(!this.to_tag&&s>100?_+=`;tag=${at.newTag()}`:this.to_tag&&!this.s("to").hasParam("tag")&&(_+=`;tag=${this.to_tag}`),a+=`To: ${_}\r
106
106
  `,a+=`From: ${this.getHeader("From")}\r
107
107
  `,a+=`Call-ID: ${this.call_id}\r
108
108
  `,a+=`CSeq: ${this.cseq} ${this.method}\r
109
- `,this.ua.configuration.extra_headers)for(const n of this.ua.configuration.extra_headers)a+=`${n.trim()}\r
109
+ `,this.ua.configuration.extra_headers)for(const e of this.ua.configuration.extra_headers)a+=`${e.trim()}\r
110
110
  `;a+=`Content-Length: 0\r
111
111
  \r
112
- `,this.transport.send(a)}}class $m extends u_{constructor(){super(),this.headers={},this.status_code=null,this.reason_phrase=null}}var It={OutgoingRequest:Vo,InitialOutgoingInviteRequest:Mu,IncomingRequest:Lm,IncomingResponse:$m};const Wl=Xe(It),Hm=at,hs=yt(),Yt=new Hm("DigestAuthentication");var c_=class{constructor(s){this._credentials=s,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(s){switch(s){case"realm":return this._realm;case"ha1":return this._ha1;default:Yt.warn('get() | cannot get "%s" parameter',s);return}}authenticate({method:s,ruri:r,body:o},a,t=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=s,this._uri=r,this._cnonce=t||hs.createRandomToken(12),this._nc+=1;const n=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-n.length)+n,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=hs.calculateMD5(`${this._credentials.username}:${this._realm}:${this._credentials.password}`):this._ha1=this._credentials.ha1;let d,_;return this._qop==="auth"?(d=`${this._method}:${this._uri}`,_=hs.calculateMD5(d),Yt.debug('authenticate() | using qop=auth [a2:"%s"]',d),this._response=hs.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${_}`)):this._qop==="auth-int"?(d=`${this._method}:${this._uri}:${hs.calculateMD5(o||"")}`,_=hs.calculateMD5(d),Yt.debug('authenticate() | using qop=auth-int [a2:"%s"]',d),this._response=hs.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${_}`)):this._qop===null&&(d=`${this._method}:${this._uri}`,_=hs.calculateMD5(d),Yt.debug('authenticate() | using qop=null [a2:"%s"]',d),this._response=hs.calculateMD5(`${this._ha1}:${this._nonce}:${_}`)),Yt.debug("authenticate() | response generated"),!0}toString(){const s=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return s.push(`algorithm=${this._algorithm}`),s.push(`username="${this._credentials.username}"`),s.push(`realm="${this._realm}"`),s.push(`nonce="${this._nonce}"`),s.push(`uri="${this._uri}"`),s.push(`response="${this._response}"`),this._opaque&&s.push(`opaque="${this._opaque}"`),this._qop&&(s.push(`qop=${this._qop}`),s.push(`cnonce="${this._cnonce}"`),s.push(`nc=${this._ncHex}`)),`Digest ${s.join(", ")}`}};const Fm=Xe(c_),ds=500,jm=4e3,sf=5e3;var ku={T1:ds,T2:jm,T4:sf,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*sf,TIMER_L:64*ds,TIMER_M:64*ds,PROVISIONAL_RESPONSE_INTERVAL:6e4};const Mi=Xe(ku),cl=ft.EventEmitter,fl=at,Yi=De,nf=It,rs=ku,rf=new fl("NonInviteClientTransaction"),Kl=new fl("InviteClientTransaction"),qm=new fl("AckClientTransaction"),lf=new fl("NonInviteServerTransaction"),Yl=new fl("InviteServerTransaction"),he={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 Vm extends cl{constructor(s,r,o,a){super(),this.type=he.NON_INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=s,this.transport=r,this.request=o,this.eventHandlers=a;let t=`SIP/2.0/${r.via_transport}`;t+=` ${s.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",t),this.ua.newTransaction(this)}get C(){return he}stateChanged(s){this.state=s,this.emit("stateChanged")}send(){this.stateChanged(he.STATUS_TRYING),this.F=setTimeout(()=>{this.timer_F()},rs.TIMER_F),this.transport.send(this.request)||this.onTransportError()}onTransportError(){rf.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}timer_F(){rf.debug(`Timer F expired for transaction ${this.id}`),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}timer_K(){this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}receiveResponse(s){const r=s.status_code;if(r<200)switch(this.state){case he.STATUS_TRYING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(s);break}else switch(this.state){case he.STATUS_TRYING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_COMPLETED),clearTimeout(this.F),r===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(s),this.K=setTimeout(()=>{this.timer_K()},rs.TIMER_K);break;case he.STATUS_COMPLETED:break}}}class Bm extends cl{constructor(s,r,o,a){super(),this.type=he.INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=s,this.transport=r,this.request=o,this.eventHandlers=a,o.transaction=this;let t=`SIP/2.0/${r.via_transport}`;t+=` ${s.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",t),this.ua.newTransaction(this)}get C(){return he}stateChanged(s){this.state=s,this.emit("stateChanged")}send(){this.stateChanged(he.STATUS_CALLING),this.B=setTimeout(()=>{this.timer_B()},rs.TIMER_B),this.transport.send(this.request)||this.onTransportError()}onTransportError(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==he.STATUS_ACCEPTED&&(Kl.debug(`transport error occurred, deleting transaction ${this.id}`),this.eventHandlers.onTransportError()),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_M(){Kl.debug(`Timer M expired for transaction ${this.id}`),this.state===he.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}timer_B(){Kl.debug(`Timer B expired for transaction ${this.id}`),this.state===he.STATUS_CALLING&&(this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}timer_D(){Kl.debug(`Timer D expired for transaction ${this.id}`),clearTimeout(this.B),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}sendACK(s){const r=new nf.OutgoingRequest(Yi.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",s.getHeader("to")),this.D=setTimeout(()=>{this.timer_D()},rs.TIMER_D),this.transport.send(r)}cancel(s){if(this.state!==he.STATUS_PROCEEDING)return;const r=new nf.OutgoingRequest(Yi.CANCEL,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",this.request.getHeader("to")),s&&r.setHeader("reason",s),this.transport.send(r)}receiveResponse(s){const r=s.status_code;if(r>=100&&r<=199)switch(this.state){case he.STATUS_CALLING:this.stateChanged(he.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(s);break;case he.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(s);break}else if(r>=200&&r<=299)switch(this.state){case he.STATUS_CALLING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_ACCEPTED),this.M=setTimeout(()=>{this.timer_M()},rs.TIMER_M),this.eventHandlers.onReceiveResponse(s);break;case he.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(s);break}else if(r>=300&&r<=699)switch(this.state){case he.STATUS_CALLING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_COMPLETED),this.sendACK(s),this.eventHandlers.onReceiveResponse(s);break;case he.STATUS_COMPLETED:this.sendACK(s);break}}}class Gm extends cl{constructor(s,r,o,a){super(),this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.transport=r,this.request=o,this.eventHandlers=a;let t=`SIP/2.0/${r.via_transport}`;t+=` ${s.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",t)}get C(){return he}send(){this.transport.send(this.request)||this.onTransportError()}onTransportError(){qm.debug(`transport error occurred for transaction ${this.id}`),this.eventHandlers.onTransportError()}}class Wm extends cl{constructor(s,r,o){super(),this.type=he.NON_INVITE_SERVER,this.id=o.via_branch,this.ua=s,this.transport=r,this.request=o,this.last_response="",o.server_transaction=this,this.state=he.STATUS_TRYING,s.newTransaction(this)}get C(){return he}stateChanged(s){this.state=s,this.emit("stateChanged")}timer_J(){lf.debug(`Timer J expired for transaction ${this.id}`),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}onTransportError(){this.transportError||(this.transportError=!0,lf.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.J),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}receiveResponse(s,r,o,a){if(s===100)switch(this.state){case he.STATUS_TRYING:this.stateChanged(he.STATUS_PROCEEDING),this.transport.send(r)||this.onTransportError();break;case he.STATUS_PROCEEDING:this.last_response=r,this.transport.send(r)?o&&o():(this.onTransportError(),a&&a());break}else if(s>=200&&s<=699)switch(this.state){case he.STATUS_TRYING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_COMPLETED),this.last_response=r,this.J=setTimeout(()=>{this.timer_J()},rs.TIMER_J),this.transport.send(r)?o&&o():(this.onTransportError(),a&&a());break;case he.STATUS_COMPLETED:break}}}class Km extends cl{constructor(s,r,o){super(),this.type=he.INVITE_SERVER,this.id=o.via_branch,this.ua=s,this.transport=r,this.request=o,this.last_response="",o.server_transaction=this,this.state=he.STATUS_PROCEEDING,s.newTransaction(this),this.resendProvisionalTimer=null,o.reply(100)}get C(){return he}stateChanged(s){this.state=s,this.emit("stateChanged")}timer_H(){Yl.debug(`Timer H expired for transaction ${this.id}`),this.state===he.STATUS_COMPLETED&&Yl.debug("ACK not received, dialog will be terminated"),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_I(){this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_L(){Yl.debug(`Timer L expired for transaction ${this.id}`),this.state===he.STATUS_ACCEPTED&&(this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}onTransportError(){this.transportError||(this.transportError=!0,Yl.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(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}resend_provisional(){this.transport.send(this.last_response)||this.onTransportError()}receiveResponse(s,r,o,a){if(s>=100&&s<=199)switch(this.state){case he.STATUS_PROCEEDING:this.transport.send(r)||this.onTransportError(),this.last_response=r;break}if(s>100&&s<=199&&this.state===he.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(()=>{this.resend_provisional()},rs.PROVISIONAL_RESPONSE_INTERVAL));else if(s>=200&&s<=299)switch(this.state){case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_ACCEPTED),this.last_response=r,this.L=setTimeout(()=>{this.timer_L()},rs.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case he.STATUS_ACCEPTED:this.transport.send(r)?o&&o():(this.onTransportError(),a&&a());break}else if(s>=300&&s<=699)switch(this.state){case he.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(r)?(this.stateChanged(he.STATUS_COMPLETED),this.H=setTimeout(()=>{this.timer_H()},rs.TIMER_H),o&&o()):(this.onTransportError(),a&&a());break}}}function Ym({_transactions:c},s){let r;switch(s.method){case Yi.INVITE:if(r=c.ist[s.via_branch],r){switch(r.state){case he.STATUS_PROCEEDING:r.transport.send(r.last_response);break;case he.STATUS_ACCEPTED:break}return!0}break;case Yi.ACK:if(r=c.ist[s.via_branch],r){if(r.state===he.STATUS_ACCEPTED)return!1;if(r.state===he.STATUS_COMPLETED)return r.state=he.STATUS_CONFIRMED,r.I=setTimeout(()=>{r.timer_I()},rs.TIMER_I),!0}else return!1;break;case Yi.CANCEL:return r=c.ist[s.via_branch],r?(s.reply_sl(200),r.state!==he.STATUS_PROCEEDING):(s.reply_sl(481),!0);default:if(r=c.nist[s.via_branch],r){switch(r.state){case he.STATUS_TRYING:break;case he.STATUS_PROCEEDING:case he.STATUS_COMPLETED:r.transport.send(r.last_response);break}return!0}break}}var pr={C:he,NonInviteClientTransaction:Vm,InviteClientTransaction:Bm,AckClientTransaction:Gm,NonInviteServerTransaction:Wm,InviteServerTransaction:Km,checkTransaction:Ym};const Bt=Xe(pr),Jm=at,of=De,zm=c_,xa=pr,Xm=new Jm("RequestSender"),Ma={onRequestTimeout:()=>{},onTransportError:()=>{},onReceiveResponse:()=>{},onAuthenticated:()=>{}};var mr=class{constructor(s,r,o){this._ua=s,this._eventHandlers=o,this._method=r.method,this._request=r,this._auth=null,this._challenged=!1,this._staled=!1;for(const a in Ma)Object.prototype.hasOwnProperty.call(Ma,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=Ma[a]));s.status===s.C.STATUS_USER_CLOSED&&(this._method!==of.BYE||this._method!==of.ACK)&&this._eventHandlers.onTransportError()}send(){const s={onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onReceiveResponse:r=>{this._receiveResponse(r)}};switch(this._method){case"INVITE":this.clientTransaction=new xa.InviteClientTransaction(this._ua,this._ua.transport,this._request,s);break;case"ACK":this.clientTransaction=new xa.AckClientTransaction(this._ua,this._ua.transport,this._request,s);break;default:this.clientTransaction=new xa.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,s)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}_receiveResponse(s){let r,o;const a=s.status_code;if((a===401||a===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(s.status_code===401?(r=s.parseHeader("www-authenticate"),o="authorization"):(r=s.parseHeader("proxy-authenticate"),o="proxy-authorization"),!r){Xm.debug(`${s.status_code} with wrong or missing challenge, cannot authenticate`),this._eventHandlers.onReceiveResponse(s);return}if(!this._challenged||!this._staled&&r.stale===!0){if(this._auth||(this._auth=new zm({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,r)){this._eventHandlers.onReceiveResponse(s);return}this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),r.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(o,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(s)}else this._eventHandlers.onReceiveResponse(s)}};const Mo=Xe(mr),Qm=at,ka=yt(),mn=De,af=It,uf=mr,ki=new Qm("Registrator"),Jl=10;var Zm=class{constructor(s,r){this._reg_id=1,this._ua=s,this._transport=r,this._registrar=s.configuration.registrar_server,this._expires=s.configuration.register_expires,this._call_id=ka.createRandomToken(22),this._cseq=0,this._to_uri=s.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(s){Array.isArray(s)||(s=[]),this._extraHeaders=s.slice()}setExtraContactParams(s){s instanceof Object||(s={}),this._extraContactParams="";for(const r in s)if(Object.prototype.hasOwnProperty.call(s,r)){const o=s[r];this._extraContactParams+=`;${r}`,o&&(this._extraContactParams+=`=${o}`)}}register(){if(this._registering){ki.debug("Register request in progress...");return}const s=this._extraHeaders.slice();s.push(`Contact: ${this._contact};expires=${this._expires}${this._extraContactParams}`),s.push(`Expires: ${this._expires}`);const r=new af.OutgoingRequest(mn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},s),o=new uf(this._ua,r,{onRequestTimeout:()=>{this._registrationFailure(null,mn.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,mn.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:a=>{if(a.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(a.status_code):break;case/^2[0-9]{2}$/.test(a.status_code):{if(this._registering=!1,!a.hasHeader("Contact")){ki.debug("no Contact header in response to REGISTER, response ignored");break}const t=a.headers.Contact.reduce((h,g)=>h.concat(g.parsed),[]);let n=t.find(h=>this._sipInstance===h.getParam("+sip.instance")&&this._reg_id===parseInt(h.getParam("reg-id")));if(n||(n=t.find(h=>h.uri.user===this._ua.contact.uri.user)),!n){ki.debug("no Contact header pointing to us, response ignored");break}let d=n.getParam("expires");!d&&a.hasHeader("expires")&&(d=a.getHeader("expires")),d||(d=this._expires),d=Number(d),d<Jl&&(d=Jl);const _=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")},_),n.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=n.getParam("temp-gruu").replace(/"/g,"")),n.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=n.getParam("pub-gruu").replace(/"/g,"")),this._registered||(this._registered=!0,this._ua.registered({response:a}));break}case/^423$/.test(a.status_code):{a.hasHeader("min-expires")?(this._expires=Number(a.getHeader("min-expires")),this._expires<Jl&&(this._expires=Jl),this.register()):(ki.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(a,mn.causes.SIP_FAILURE_CODE));break}default:{const t=ka.sipErrorCause(a.status_code);this._registrationFailure(a,t)}}}});this._registering=!0,o.send()}unregister(s={}){if(!this._registered){ki.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const r=this._extraHeaders.slice();s.all?r.push(`Contact: *${this._extraContactParams}`):r.push(`Contact: ${this._contact};expires=0${this._extraContactParams}`),r.push("Expires: 0");const o=new af.OutgoingRequest(mn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},r);new uf(this._ua,o,{onRequestTimeout:()=>{this._unregistered(null,mn.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,mn.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:t=>{switch(!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):this._unregistered(t);break;default:{const n=ka.sipErrorCause(t.status_code);this._unregistered(t,n)}}}}).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(s,r){this._registering=!1,this._ua.registrationFailed({response:s||null,cause:r}),this._registered&&(this._registered=!1,this._ua.unregistered({response:s||null,cause:r}))}_unregistered(s,r){this._registering=!1,this._registered=!1,this._ua.unregistered({response:s||null,cause:r||null})}};class eg extends Error{constructor(s,r){super(),this.code=1,this.name="CONFIGURATION_ERROR",this.parameter=s,this.value=r,this.message=this.value?`Invalid value ${JSON.stringify(this.value)} for parameter "${this.parameter}"`:`Missing parameter: ${this.parameter}`}}class tg extends Error{constructor(s){super(),this.code=2,this.name="INVALID_STATE_ERROR",this.status=s,this.message=`Invalid status: ${s}`}}class sg extends Error{constructor(s){super(),this.code=3,this.name="NOT_SUPPORTED_ERROR",this.message=s}}class ng extends Error{constructor(s){super(),this.code=4,this.name="NOT_READY_ERROR",this.message=s}}var Ss={ConfigurationError:eg,InvalidStateError:tg,NotSupportedError:sg,NotReadyError:ng};const Fs=Xe(Ss),La=De,zl=pr,rg=mr,$a={onRequestTimeout:()=>{},onTransportError:()=>{},onSuccessResponse:()=>{},onErrorResponse:()=>{},onAuthenticated:()=>{},onDialogError:()=>{}};var f_=class{constructor(s,r,o){this._dialog=s,this._ua=s._ua,this._request=r,this._eventHandlers=o,this._reattempt=!1,this._reattemptTimer=null;for(const a in $a)Object.prototype.hasOwnProperty.call($a,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=$a[a]))}get request(){return this._request}send(){const s=new rg(this._ua,this._request,{onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onAuthenticated:r=>{this._eventHandlers.onAuthenticated(r)},onReceiveResponse:r=>{this._receiveResponse(r)}});if(s.send(),(this._request.method===La.INVITE||this._request.method===La.UPDATE&&this._request.body)&&s.clientTransaction.state!==zl.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;const r=()=>{(s.clientTransaction.state===zl.C.STATUS_ACCEPTED||s.clientTransaction.state===zl.C.STATUS_COMPLETED||s.clientTransaction.state===zl.C.STATUS_TERMINATED)&&(s.clientTransaction.removeListener("stateChanged",r),this._dialog.uac_pending_reply=!1)};s.clientTransaction.on("stateChanged",r)}}_receiveResponse(s){s.status_code===408||s.status_code===481?this._eventHandlers.onDialogError(s):s.method===La.INVITE&&s.status_code===491?this._reattempt?s.status_code>=200&&s.status_code<300?this._eventHandlers.onSuccessResponse(s):s.status_code>=300&&this._eventHandlers.onErrorResponse(s):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(()=>{this._dialog.isTerminated()||(this._reattempt=!0,this.send())},1e3)):s.status_code>=200&&s.status_code<300?this._eventHandlers.onSuccessResponse(s):s.status_code>=300&&this._eventHandlers.onErrorResponse(s)}};const ig=Xe(f_),lg=at,cf=It,ks=De,Li=pr,og=f_,Ha=yt(),Fa=new lg("Dialog"),Ls={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};var __=class{static get C(){return Ls}constructor(s,r,o,a=Ls.STATUS_CONFIRMED){if(this._owner=s,this._ua=s._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!r.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};r instanceof cf.IncomingResponse&&(a=r.status_code<200?Ls.STATUS_EARLY:Ls.STATUS_CONFIRMED);const t=r.parseHeader("contact");o==="UAS"?(this._id={call_id:r.call_id,local_tag:r.to_tag,remote_tag:r.from_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._remote_seqnum=r.cseq,this._local_uri=r.parseHeader("to").uri,this._remote_uri=r.parseHeader("from").uri,this._remote_target=t.uri,this._route_set=r.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):o==="UAC"&&(this._id={call_id:r.call_id,local_tag:r.from_tag,remote_tag:r.to_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._local_seqnum=r.cseq,this._local_uri=r.parseHeader("from").uri,this._remote_uri=r.parseHeader("to").uri,this._remote_target=t.uri,this._route_set=r.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),Fa.debug(`new ${o} dialog created with status ${this._state===Ls.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(s){this._local_seqnum=s}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(s){this._uac_pending_reply=s}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===Ls.STATUS_TERMINATED}update(s,r){this._state=Ls.STATUS_CONFIRMED,Fa.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),r==="UAC"&&(this._route_set=s.getHeaders("record-route").reverse())}terminate(){Fa.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Ls.STATUS_TERMINATED}sendRequest(s,r={}){const o=Ha.cloneArray(r.extraHeaders),a=Ha.cloneObject(r.eventHandlers),t=r.body||null,n=this._createRequest(s,o,t);return a.onAuthenticated=()=>{this._local_seqnum+=1},new og(this,n,a).send(),n}receiveRequest(s){this._checkInDialogRequest(s)&&(s.method===ks.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:s.method===ks.INVITE&&(this._ack_seqnum=s.cseq),this._owner.receiveRequest(s))}_createRequest(s,r,o){r=Ha.cloneArray(r),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const a=s===ks.CANCEL||s===ks.ACK?this._local_seqnum:this._local_seqnum+=1;return new cf.OutgoingRequest(s,this._remote_target,this._ua,{cseq:a,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},r,o)}_checkInDialogRequest(s){if(!this._remote_seqnum)this._remote_seqnum=s.cseq;else if(s.cseq<this._remote_seqnum)if(s.method===ks.ACK){if(this._ack_seqnum===null||s.cseq!==this._ack_seqnum)return!1}else return s.reply(500),!1;else s.cseq>this._remote_seqnum&&(this._remote_seqnum=s.cseq);if(s.method===ks.INVITE||s.method===ks.UPDATE&&s.body){if(this._uac_pending_reply===!0)s.reply(491);else if(this._uas_pending_reply===!0){const r=(Math.random()*10|0)+1;return s.reply(500,null,[`Retry-After:${r}`]),!1}else{this._uas_pending_reply=!0;const r=()=>{(s.server_transaction.state===Li.C.STATUS_ACCEPTED||s.server_transaction.state===Li.C.STATUS_COMPLETED||s.server_transaction.state===Li.C.STATUS_TERMINATED)&&(s.server_transaction.removeListener("stateChanged",r),this._uas_pending_reply=!1)};s.server_transaction.on("stateChanged",r)}s.hasHeader("contact")&&s.server_transaction.on("stateChanged",()=>{s.server_transaction.state===Li.C.STATUS_ACCEPTED&&(this._remote_target=s.parseHeader("contact").uri)})}else s.method===ks.NOTIFY&&s.hasHeader("contact")&&s.server_transaction.on("stateChanged",()=>{s.server_transaction.state===Li.C.STATUS_COMPLETED&&(this._remote_target=s.parseHeader("contact").uri)});return!0}};const Xl=Xe(__);var Lu={exports:{}};const ag=ft.EventEmitter,ug=at,cg=De,fg=Ss,ff=yt(),_g=new ug("RTCSession:DTMF"),h_={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};Lu.exports=class extends ag{constructor(s){super(),this._session=s,this._direction=null,this._tone=null,this._duration=null,this._request=null}get tone(){return this._tone}get duration(){return this._duration}send(s,r={}){if(s===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 fg.InvalidStateError(this._session.status);const o=ff.cloneArray(r.extraHeaders);if(this.eventHandlers=ff.cloneObject(r.eventHandlers),typeof s=="string")s=s.toUpperCase();else if(typeof s=="number")s=s.toString();else throw new TypeError(`Invalid tone: ${s}`);if(s.match(/^[0-9A-DR#*]$/))this._tone=s;else throw new TypeError(`Invalid tone: ${s}`);this._duration=r.duration,o.push("Content-Type: application/dtmf-relay");let a=`Signal=${this._tone}\r
113
- `;a+=`Duration=${this._duration}`,this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(cg.INFO,{extraHeaders:o,eventHandlers:{onSuccessResponse:t=>{this.emit("succeeded",{originator:"remote",response:t})},onErrorResponse:t=>{this.eventHandlers.onFailed&&this.eventHandlers.onFailed(),this.emit("failed",{originator:"remote",response:t})},onRequestTimeout:()=>{this._session.onRequestTimeout()},onTransportError:()=>{this._session.onTransportError()},onDialogError:()=>{this._session.onDialogError()}},body:a})}init_incoming(s){const r=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,o=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=s,s.reply(200),s.body){const a=s.body.split(`
114
- `);a.length>=1&&r.test(a[0])&&(this._tone=a[0].replace(r,"$2")),a.length>=2&&o.test(a[1])&&(this._duration=parseInt(a[1].replace(o,"$2"),10))}this._duration||(this._duration=h_.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:s}):_g.debug("invalid INFO DTMF received, discarded")}};Lu.exports.C=h_;var d_=Lu.exports;const hg=Xe(d_),dg=ft.EventEmitter,pg=De,mg=Ss,gg=yt();var p_=class extends dg{constructor(s){super(),this._session=s,this._direction=null,this._contentType=null,this._body=null}get contentType(){return this._contentType}get body(){return this._body}send(s,r,o={}){if(this._direction="outgoing",s===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 mg.InvalidStateError(this._session.status);this._contentType=s,this._body=r;const a=gg.cloneArray(o.extraHeaders);a.push(`Content-Type: ${s}`),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(pg.INFO,{extraHeaders:a,eventHandlers:{onSuccessResponse:t=>{this.emit("succeeded",{originator:"remote",response:t})},onErrorResponse:t=>{this.emit("failed",{originator:"remote",response:t})},onTransportError:()=>{this._session.onTransportError()},onRequestTimeout:()=>{this._session.onRequestTimeout()},onDialogError:()=>{this._session.onDialogError()}},body:r})}init_incoming(s){this._direction="incoming",this.request=s,s.reply(200),this._contentType=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0,this._body=s.body,this._session.newInfo({originator:"remote",info:this,request:s})}};const Tu=Xe(p_),Tg=at,_f=De,vg=new Tg("RTCSession:ReferNotifier"),ja={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300};var m_=class{constructor(s,r,o){this._session=s,this._id=r,this._expires=o||ja.expires,this._active=!0,this.notify(100)}notify(s,r){if(vg.debug("notify()"),this._active===!1)return;r=r||_f.REASON_PHRASE[s]||"";let o;s>=200?o="terminated;reason=noresource":o=`active;expires=${this._expires}`,this._session.sendRequest(_f.NOTIFY,{extraHeaders:[`Event: ${ja.event_type};id=${this._id}`,`Subscription-State: ${o}`,`Content-Type: ${ja.body_type}`],body:`SIP/2.0 ${s} ${r}`,eventHandlers:{onErrorResponse(){this._active=!1}}})}};const Eg=Xe(m_),Sg=ft.EventEmitter,yg=at,$i=De,Ag=ls(),hf=yt(),gn=new yg("RTCSession:ReferSubscriber");var g_=class extends Sg{constructor(s){super(),this._id=null,this._session=s}get id(){return this._id}sendRefer(s,r={}){gn.debug("sendRefer()");const o=hf.cloneArray(r.extraHeaders),a=hf.cloneObject(r.eventHandlers);for(const _ in a)Object.prototype.hasOwnProperty.call(a,_)&&this.on(_,a[_]);let t=null;r.replaces&&(t=r.replaces._request.call_id,t+=`;to-tag=${r.replaces._to_tag}`,t+=`;from-tag=${r.replaces._from_tag}`,t=encodeURIComponent(t));const n=`Refer-To: <${s}${t?`?Replaces=${t}`:""}>`;if(o.push(n),!o.some(_=>_.toLowerCase().startsWith("referred-by:"))){const _=`Referred-By: <${this._session._ua._configuration.uri._scheme}:${this._session._ua._configuration.uri._user}@${this._session._ua._configuration.uri._host}>`;o.push(_)}o.push(`Contact: ${this._session.contact}`);const d=this._session.sendRequest($i.REFER,{extraHeaders:o,eventHandlers:{onSuccessResponse:_=>{this._requestSucceeded(_)},onErrorResponse:_=>{this._requestFailed(_,$i.causes.REJECTED)},onTransportError:()=>{this._requestFailed(null,$i.causes.CONNECTION_ERROR)},onRequestTimeout:()=>{this._requestFailed(null,$i.causes.REQUEST_TIMEOUT)},onDialogError:()=>{this._requestFailed(null,$i.causes.DIALOG_ERROR)}}});this._id=d.cseq}receiveNotify(s){if(gn.debug("receiveNotify()"),!s.body)return;const r=Ag.parse(s.body.trim().split(`\r
115
- `,1)[0],"Status_Line");if(r===-1){gn.debug(`receiveNotify() | error parsing NOTIFY body: "${s.body}"`);return}switch(!0){case/^100$/.test(r.status_code):this.emit("trying",{request:s,status_line:r});break;case/^1[0-9]{2}$/.test(r.status_code):this.emit("progress",{request:s,status_line:r});break;case/^2[0-9]{2}$/.test(r.status_code):this.emit("accepted",{request:s,status_line:r});break;default:this.emit("failed",{request:s,status_line:r});break}}_requestSucceeded(s){gn.debug("REFER succeeded"),gn.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:s})}_requestFailed(s,r){gn.debug("REFER failed"),gn.debug('emit "requestFailed"'),this.emit("requestFailed",{response:s||null,cause:r})}};const Cg=Xe(g_),Rg=ft.EventEmitter,df=Pt,Ig=at,fe=De,Tn=Ss,pf=pr,Be=yt(),Hi=ku,bg=It,Ql=__,wg=mr,Mt=d_,mf=p_,Og=m_,Dg=g_,gf=Es(),Y=new Ig("RTCSession"),Z={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},Zl=["audio","video"];var T_=class vu extends Rg{static get C(){return Z}constructor(s){Y.debug("new"),super(),this._id=null,this._ua=s,this._status=Z.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:fe.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._referSubscribers={},this._data={}}get C(){return Z}get causes(){return fe.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(s){this._data=s}get status(){return this._status}isInProgress(){switch(this._status){case Z.STATUS_NULL:case Z.STATUS_INVITE_SENT:case Z.STATUS_1XX_RECEIVED:case Z.STATUS_INVITE_RECEIVED:case Z.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case Z.STATUS_ANSWERED:case Z.STATUS_WAITING_FOR_ACK:case Z.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case Z.STATUS_CANCELED:case Z.STATUS_TERMINATED:return!0;default:return!1}}isMuted(){return{audio:this._audioMuted,video:this._videoMuted}}isOnHold(){return{local:this._localHold,remote:this._remoteHold}}connect(s,r={},o){Y.debug("connect()");const a=s,t=Be.cloneObject(r.eventHandlers),n=Be.cloneArray(r.extraHeaders),d=Be.cloneObject(r.mediaConstraints,{audio:!0,video:!0}),_=r.mediaStream||null,h=Be.cloneObject(r.pcConfig,{iceServers:[]}),g=r.rtcConstraints||null,T=r.rtcOfferConstraints||null;if(this._rtcOfferConstraints=T,this._rtcAnswerConstraints=r.rtcAnswerConstraints||null,this._data=r.data||this._data,s===void 0)throw new TypeError("Not enough arguments");if(this._status!==Z.STATUS_NULL)throw new Tn.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new Tn.NotSupportedError("WebRTC not supported");if(s=this._ua.normalizeTarget(s),!s)throw new TypeError(`Invalid target: ${a}`);this._sessionTimers.enabled&&Be.isDecimal(r.sessionTimersExpires)&&(r.sessionTimersExpires>=fe.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=r.sessionTimersExpires:this._sessionTimers.defaultExpires=fe.SESSION_EXPIRES);for(const A in t)Object.prototype.hasOwnProperty.call(t,A)&&this.on(A,t[A]);this._from_tag=Be.newTag();const E=r.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 gf("sip","anonymous","anonymous.invalid"),n.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),n.push("Privacy: id")):r.fromUserName&&(y.from_uri=new gf("sip",r.fromUserName,this._ua.configuration.uri.host),n.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),r.fromDisplayName&&(y.from_display_name=r.fromDisplayName),n.push(`Contact: ${this._contact}`),n.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&n.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new bg.InitialOutgoingInviteRequest(s,this._ua,y,n),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(h,g),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,o&&o(this),this._newRTCSession("local",this._request),this._sendInitialRequest(d,T,_)}init_incoming(s,r){Y.debug("init_incoming()");let o;const a=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0;if(s.body&&a!=="application/sdp"){s.reply(415);return}if(this._status=Z.STATUS_INVITE_RECEIVED,this._from_tag=s.from_tag,this._id=s.call_id+this._from_tag,this._request=s,this._contact=this._ua.contact.toString(),s.hasHeader("expires")&&(o=s.getHeader("expires")*1e3),s.to_tag=Be.newTag(),!this._createDialog(s,"UAS",!0)){s.reply(500,"Missing Contact header field");return}s.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Z.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{s.reply(408),this._failed("local",null,fe.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),o&&(this._timers.expiresTimer=setTimeout(()=>{this._status===Z.STATUS_WAITING_FOR_ANSWER&&(s.reply(487),this._failed("system",null,fe.causes.EXPIRES))},o)),this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from,r&&r(this),this._newRTCSession("remote",s),this._status!==Z.STATUS_TERMINATED&&(s.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(s={}){Y.debug("answer()");const r=this._request,o=Be.cloneArray(s.extraHeaders),a=Be.cloneObject(s.mediaConstraints),t=s.mediaStream||null,n=Be.cloneObject(s.pcConfig,{iceServers:[]}),d=s.rtcConstraints||null,_=s.rtcAnswerConstraints||null,h=Be.cloneObject(s.rtcOfferConstraints);let g,T=!1,E=!1,y=!1,A=!1;if(this._rtcAnswerConstraints=_,this._rtcOfferConstraints=s.rtcOfferConstraints||null,this._data=s.data||this._data,this._direction!=="incoming")throw new Tn.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==Z.STATUS_WAITING_FOR_ANSWER)throw new Tn.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Be.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=fe.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=fe.SESSION_EXPIRES),this._status=Z.STATUS_ANSWERED,!this._createDialog(r,"UAS")){r.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),o.unshift(`Contact: ${this._contact}`);const C=r.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(t&&a.audio===!1){g=t.getAudioTracks();for(const I of g)t.removeTrack(I)}if(t&&a.video===!1){g=t.getVideoTracks();for(const I of g)t.removeTrack(I)}!t&&a.audio===void 0&&(a.audio=y),!t&&a.video===void 0&&(a.video=A),!t&&!T&&!h.offerToReceiveAudio&&(a.audio=!1),!t&&!E&&!h.offerToReceiveVideo&&(a.video=!1),this._createRTCConnection(n,d),Promise.resolve().then(()=>{if(t)return t;if(a.audio||a.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(a).catch(I=>{throw this._status===Z.STATUS_TERMINATED?new Error("terminated"):(r.reply(480),this._failed("local",null,fe.causes.USER_DENIED_MEDIA_ACCESS),Y.warn('emit "getusermediafailed" [error:%o]',I),this.emit("getusermediafailed",I),new Error("getUserMedia() failed"))})}).then(I=>{if(this._status===Z.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:r.body};Y.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(L=>{throw r.reply(488),this._failed("system",null,fe.causes.WEBRTC_ERROR),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',L),this.emit("peerconnection:setremotedescriptionfailed",L),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(r),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw r.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",_).catch(()=>{throw r.reply(500),new Error("_createLocalDescription() failed")})}).then(I=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(r,o),r.reply(200,null,o,I,()=>{this._status=Z.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(r,I),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,fe.causes.CONNECTION_ERROR)})}).catch(I=>{this._status!==Z.STATUS_TERMINATED&&Y.warn(I)})}terminate(s={}){Y.debug("terminate()");const r=s.cause||fe.causes.BYE,o=Be.cloneArray(s.extraHeaders),a=s.body;let t,n=s.status_code,d=s.reason_phrase;if(this._status===Z.STATUS_TERMINATED)throw new Tn.InvalidStateError(this._status);switch(this._status){case Z.STATUS_NULL:case Z.STATUS_INVITE_SENT:case Z.STATUS_1XX_RECEIVED:if(Y.debug("canceling session"),n&&(n<200||n>=700))throw new TypeError(`Invalid status_code: ${n}`);n&&(d=d||fe.REASON_PHRASE[n]||"",t=`SIP ;cause=${n} ;text="${d}"`),this._status===Z.STATUS_NULL||this._status===Z.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=t):this._status===Z.STATUS_1XX_RECEIVED&&this._request.cancel(t),this._status=Z.STATUS_CANCELED,this._failed("local",null,fe.causes.CANCELED);break;case Z.STATUS_WAITING_FOR_ANSWER:case Z.STATUS_ANSWERED:if(Y.debug("rejecting session"),n=n||480,n<300||n>=700)throw new TypeError(`Invalid status_code: ${n}`);this._request.reply(n,d,o,a),this._failed("local",null,fe.causes.REJECTED);break;case Z.STATUS_WAITING_FOR_ACK:case Z.STATUS_CONFIRMED:if(Y.debug("terminating session"),d=s.reason_phrase||fe.REASON_PHRASE[n]||"",n&&(n<200||n>=700))throw new TypeError(`Invalid status_code: ${n}`);if(n&&o.push(`Reason: SIP ;cause=${n}; text="${d}"`),this._status===Z.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==pf.C.STATUS_TERMINATED){const _=this._dialog;this.receiveRequest=({method:h})=>{h===fe.ACK&&(this.sendRequest(fe.BYE,{extraHeaders:o,body:a}),_.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===pf.C.STATUS_TERMINATED&&(this.sendRequest(fe.BYE,{extraHeaders:o,body:a}),_.terminate())}),this._ended("local",null,r),this._dialog=_,this._ua.newDialog(_)}else this.sendRequest(fe.BYE,{extraHeaders:o,body:a}),this._ended("local",null,r)}}sendDTMF(s,r={}){Y.debug("sendDTMF() | tones: %s",s);let o=0,a=r.duration||null,t=r.interToneGap||null;const n=r.transportType||fe.DTMF_TRANSPORT.INFO;if(s===void 0)throw new TypeError("Not enough arguments");if(this._status!==Z.STATUS_CONFIRMED&&this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_1XX_RECEIVED)throw new Tn.InvalidStateError(this._status);if(n!==fe.DTMF_TRANSPORT.INFO&&n!==fe.DTMF_TRANSPORT.RFC2833)throw new TypeError(`invalid transportType: ${n}`);if(typeof s=="number"&&(s=s.toString()),!s||typeof s!="string"||!s.match(/^[0-9A-DR#*,]+$/i))throw new TypeError(`Invalid tones: ${s}`);if(a&&!Be.isDecimal(a))throw new TypeError(`Invalid tone duration: ${a}`);if(a?a<Mt.C.MIN_DURATION?(Y.debug(`"duration" value is lower than the minimum allowed, setting it to ${Mt.C.MIN_DURATION} milliseconds`),a=Mt.C.MIN_DURATION):a>Mt.C.MAX_DURATION?(Y.debug(`"duration" value is greater than the maximum allowed, setting it to ${Mt.C.MAX_DURATION} milliseconds`),a=Mt.C.MAX_DURATION):a=Math.abs(a):a=Mt.C.DEFAULT_DURATION,r.duration=a,t&&!Be.isDecimal(t))throw new TypeError(`Invalid interToneGap: ${t}`);if(t?t<Mt.C.MIN_INTER_TONE_GAP?(Y.debug(`"interToneGap" value is lower than the minimum allowed, setting it to ${Mt.C.MIN_INTER_TONE_GAP} milliseconds`),t=Mt.C.MIN_INTER_TONE_GAP):t=Math.abs(t):t=Mt.C.DEFAULT_INTER_TONE_GAP,n===fe.DTMF_TRANSPORT.RFC2833){const _=this._getDTMFRTPSender();_&&(s=_.toneBuffer+s,_.insertDTMF(s,a,t));return}if(this._tones){this._tones+=s;return}this._tones=s,d.call(this);function d(){let _;if(this._status===Z.STATUS_TERMINATED||!this._tones||o>=this._tones.length){this._tones=null;return}const h=this._tones[o];if(o+=1,h===",")_=2e3;else{const g=new Mt(this);r.eventHandlers={onFailed:()=>{this._tones=null}},g.send(h,r),_=a+t}setTimeout(d.bind(this),_)}}sendInfo(s,r,o={}){if(Y.debug("sendInfo()"),this._status!==Z.STATUS_CONFIRMED&&this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_1XX_RECEIVED)throw new Tn.InvalidStateError(this._status);new mf(this).send(s,r,o)}mute(s={audio:!0,video:!1}){Y.debug("mute()");let r=!1,o=!1;this._audioMuted===!1&&s.audio&&(r=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&s.video&&(o=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(r===!0||o===!0)&&this._onmute({audio:r,video:o})}unmute(s={audio:!0,video:!0}){Y.debug("unmute()");let r=!1,o=!1;this._audioMuted===!0&&s.audio&&(r=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&s.video&&(o=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(r===!0||o===!0)&&this._onunmute({audio:r,video:o})}hold(s={},r){if(Y.debug("hold()"),this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");const o={succeeded:()=>{r&&r()},failed:()=>{this.terminate({cause:fe.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:o,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:o,extraHeaders:s.extraHeaders}),!0}unhold(s={},r){if(Y.debug("unhold()"),this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");const o={succeeded:()=>{r&&r()},failed:()=>{this.terminate({cause:fe.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:o,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:o,extraHeaders:s.extraHeaders}),!0}renegotiate(s={},r){Y.debug("renegotiate()");const o=s.rtcOfferConstraints||null;if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const a={succeeded:()=>{r&&r()},failed:()=>{this.terminate({cause:fe.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,rtcOfferConstraints:o,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:a,rtcOfferConstraints:o,extraHeaders:s.extraHeaders}),!0}refer(s,r){Y.debug("refer()");const o=s;if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;if(s=this._ua.normalizeTarget(s),!s)throw new TypeError(`Invalid target: ${o}`);const a=new Dg(this);a.sendRefer(s,r);const t=a.id;return this._referSubscribers[t]=a,a.on("requestFailed",()=>{delete this._referSubscribers[t]}),a.on("accepted",()=>{delete this._referSubscribers[t]}),a.on("failed",()=>{delete this._referSubscribers[t]}),a}sendRequest(s,r){return Y.debug("sendRequest()"),this._dialog.sendRequest(s,r)}receiveRequest(s){if(Y.debug("receiveRequest()"),s.method===fe.CANCEL)(this._status===Z.STATUS_WAITING_FOR_ANSWER||this._status===Z.STATUS_ANSWERED)&&(this._status=Z.STATUS_CANCELED,this._request.reply(487),this._failed("remote",s,fe.causes.CANCELED));else switch(s.method){case fe.ACK:if(this._status!==Z.STATUS_WAITING_FOR_ACK)return;if(this._status=Z.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!s.body){this.terminate({cause:fe.causes.MISSING_SDP,status_code:400});break}const r={originator:"remote",type:"answer",sdp:s.body};Y.debug('emit "sdp"'),this.emit("sdp",r);const o=new RTCSessionDescription({type:"answer",sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(o)).then(()=>{this._is_confirmed||this._confirmed("remote",s)}).catch(a=>{this.terminate({cause:fe.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})}else this._is_confirmed||this._confirmed("remote",s);break;case fe.BYE:this._status===Z.STATUS_CONFIRMED||this._status===Z.STATUS_WAITING_FOR_ACK?(s.reply(200),this._ended("remote",s,fe.causes.BYE)):this._status===Z.STATUS_INVITE_RECEIVED||this._status===Z.STATUS_WAITING_FOR_ANSWER?(s.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",s,fe.causes.BYE)):s.reply(403,"Wrong Status");break;case fe.INVITE:this._status===Z.STATUS_CONFIRMED?s.hasHeader("replaces")?this._receiveReplaces(s):this._receiveReinvite(s):s.reply(403,"Wrong Status");break;case fe.INFO:if(this._status===Z.STATUS_1XX_RECEIVED||this._status===Z.STATUS_WAITING_FOR_ANSWER||this._status===Z.STATUS_ANSWERED||this._status===Z.STATUS_WAITING_FOR_ACK||this._status===Z.STATUS_CONFIRMED){const r=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0;r&&r.match(/^application\/dtmf-relay/i)?new Mt(this).init_incoming(s):r!==void 0?new mf(this).init_incoming(s):s.reply(415)}else s.reply(403,"Wrong Status");break;case fe.UPDATE:this._status===Z.STATUS_CONFIRMED?this._receiveUpdate(s):s.reply(403,"Wrong Status");break;case fe.REFER:this._status===Z.STATUS_CONFIRMED?this._receiveRefer(s):s.reply(403,"Wrong Status");break;case fe.NOTIFY:this._status===Z.STATUS_CONFIRMED?this._receiveNotify(s):s.reply(403,"Wrong Status");break;default:s.reply(501)}}onTransportError(){Y.warn("onTransportError()"),this._status!==Z.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:fe.causes.CONNECTION_ERROR,cause:fe.causes.CONNECTION_ERROR})}onRequestTimeout(){Y.warn("onRequestTimeout()"),this._status!==Z.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:fe.causes.REQUEST_TIMEOUT,cause:fe.causes.REQUEST_TIMEOUT})}onDialogError(){Y.warn("onDialogError()"),this._status!==Z.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:fe.causes.DIALOG_ERROR,cause:fe.causes.DIALOG_ERROR})}newDTMF(s){Y.debug("newDTMF()"),this.emit("newDTMF",s)}newInfo(s){Y.debug("newInfo()"),this.emit("newInfo",s)}_isReadyToReOffer(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(Y.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(Y.debug("_isReadyToReOffer() | session not established yet"),!1):(Y.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}_close(){if(Y.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(Y.debug("close() | closing local MediaStream"),Be.closeMediaStream(this._localMediaStream)),this._status!==Z.STATUS_TERMINATED){if(this._status=Z.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(s){Y.warn("close() | error closing the RTCPeerConnection: %o",s)}for(const s in this._timers)Object.prototype.hasOwnProperty.call(this._timers,s)&&clearTimeout(this._timers[s]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const s in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,s)&&(this._earlyDialogs[s].terminate(),delete this._earlyDialogs[s]);for(const s in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,s)&&delete this._referSubscribers[s];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(s,r){let o=Hi.T1;function a(){this._status===Z.STATUS_WAITING_FOR_ACK&&(s.reply(200,null,[`Contact: ${this._contact}`],r),o<Hi.T2&&(o=o*2,o>Hi.T2&&(o=Hi.T2)),this._timers.invite2xxTimer=setTimeout(a.bind(this),o))}this._timers.invite2xxTimer=setTimeout(a.bind(this),o)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===Z.STATUS_WAITING_FOR_ACK&&(Y.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(fe.BYE),this._ended("remote",null,fe.causes.NO_ACK))},Hi.TIMER_H)}_createRTCConnection(s,r){this._connection=new RTCPeerConnection(s,r),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:fe.causes.RTP_TIMEOUT,status_code:408,reason_phrase:fe.causes.RTP_TIMEOUT})}),Y.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(s,r){if(Y.debug("createLocalDescription()"),s!=="offer"&&s!=="answer")throw new Error(`createLocalDescription() | invalid type "${s}"`);const o=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>s==="offer"?o.createOffer(r).catch(a=>(Y.warn('emit "peerconnection:createofferfailed" [error:%o]',a),this.emit("peerconnection:createofferfailed",a),Promise.reject(a))):o.createAnswer(r).catch(a=>(Y.warn('emit "peerconnection:createanswerfailed" [error:%o]',a),this.emit("peerconnection:createanswerfailed",a),Promise.reject(a)))).then(a=>o.setLocalDescription(a).catch(t=>(this._rtcReady=!0,Y.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',t),this.emit("peerconnection:setlocaldescriptionfailed",t),Promise.reject(t)))).then(()=>{const a=r&&r.iceRestart;if(o.iceGatheringState==="complete"&&!a||o.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const t={originator:"local",type:s,sdp:o.localDescription.sdp};return Y.debug('emit "sdp"'),this.emit("sdp",t),Promise.resolve(t.sdp)}return new Promise(t=>{let n=!1,d,_;this._iceReady=!1;const h=()=>{o.removeEventListener("icecandidate",d),o.removeEventListener("icegatheringstatechange",_),n=!0,this._rtcReady=!0,this._iceReady=!0;const g={originator:"local",type:s,sdp:o.localDescription.sdp};Y.debug('emit "sdp"'),this.emit("sdp",g),t(g.sdp)};o.addEventListener("icecandidate",d=g=>{const T=g.candidate;T?this.emit("icecandidate",{candidate:T,ready:h}):n||h()}),o.addEventListener("icegatheringstatechange",_=()=>{o.iceGatheringState==="complete"&&!n&&h()})})})}_createDialog(s,r,o){const a=r==="UAS"?s.to_tag:s.from_tag,t=r==="UAS"?s.from_tag:s.to_tag,n=s.call_id+a+t;let d=this._earlyDialogs[n];if(o)return d?!0:(d=new Ql(this,s,r,Ql.C.STATUS_EARLY),d.error?(Y.debug(d.error),this._failed("remote",s,fe.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[n]=d,!0));{if(this._from_tag=s.from_tag,this._to_tag=s.to_tag,d)return d.update(s,r),this._dialog=d,delete this._earlyDialogs[n],!0;const _=new Ql(this,s,r);return _.error?(Y.debug(_.error),this._failed("remote",s,fe.causes.INTERNAL_ERROR),!1):(this._dialog=_,!0)}}_receiveReinvite(s){Y.debug("receiveReinvite()");const r=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0,o={request:s,callback:void 0,reject:t.bind(this)};let a=!1;function t(d={}){a=!0;const _=d.status_code||403,h=d.reason_phrase||"",g=Be.cloneArray(d.extraHeaders);if(this._status!==Z.STATUS_CONFIRMED)return!1;if(_<300||_>=700)throw new TypeError(`Invalid status_code: ${_}`);s.reply(_,h,g)}if(this.emit("reinvite",o),a)return;if(this._late_sdp=!1,!s.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=>{n.call(this,d)}).catch(()=>{s.reply(500)});return}if(r!=="application/sdp"){Y.debug("invalid Content-Type"),s.reply(415);return}this._processInDialogSdpOffer(s).then(d=>{this._status!==Z.STATUS_TERMINATED&&n.call(this,d)}).catch(d=>{Y.warn(d)});function n(d){const _=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(s,_),this._late_sdp&&(d=this._mangleOffer(d)),s.reply(200,null,_,d,()=>{this._status=Z.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(s,d),this._setACKTimer()}),typeof o.callback=="function"&&o.callback()}}_receiveUpdate(s){Y.debug("receiveUpdate()");const r=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0,o={request:s,callback:void 0,reject:t.bind(this)};let a=!1;function t(d={}){a=!0;const _=d.status_code||403,h=d.reason_phrase||"",g=Be.cloneArray(d.extraHeaders);if(this._status!==Z.STATUS_CONFIRMED)return!1;if(_<300||_>=700)throw new TypeError(`Invalid status_code: ${_}`);s.reply(_,h,g)}if(this.emit("update",o),a)return;if(!s.body){n.call(this,null);return}if(r!=="application/sdp"){Y.debug("invalid Content-Type"),s.reply(415);return}this._processInDialogSdpOffer(s).then(d=>{this._status!==Z.STATUS_TERMINATED&&n.call(this,d)}).catch(d=>{Y.warn(d)});function n(d){const _=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(s,_),s.reply(200,null,_,d),typeof o.callback=="function"&&o.callback()}}_processInDialogSdpOffer(s){Y.debug("_processInDialogSdpOffer()");const r=s.parseSDP();let o=!1;for(const n of r.media){if(Zl.indexOf(n.type)===-1)continue;const d=n.direction||r.direction||"sendrecv";if(d==="sendonly"||d==="inactive")o=!0;else{o=!1;break}}const a={originator:"remote",type:"offer",sdp:s.body};Y.debug('emit "sdp"'),this.emit("sdp",a);const t=new RTCSessionDescription({type:"offer",sdp:a.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(t).catch(n=>{throw s.reply(488),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),this.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&o===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&o===!0&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(n=>{throw s.reply(500),Y.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',n),n})}).catch(n=>{Y.warn("_processInDialogSdpOffer() failed [error: %o]",n)}),this._connectionPromiseQueue}_receiveRefer(s){if(Y.debug("receiveRefer()"),!s.refer_to){Y.debug("no Refer-To header field present in REFER"),s.reply(400);return}if(s.refer_to.uri.scheme!==fe.SIP){Y.debug("Refer-To header field points to a non-SIP URI scheme"),s.reply(416);return}s.reply(202);const r=new Og(this,s.cseq);Y.debug('emit "refer"'),this.emit("refer",{request:s,accept:(t,n)=>{o.call(this,t,n)},reject:()=>{a.call(this)}});function o(t,n={}){if(t=typeof t=="function"?t:null,this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;const d=new vu(this._ua);if(d.on("progress",({response:_})=>{r.notify(_.status_code,_.reason_phrase)}),d.on("accepted",({response:_})=>{r.notify(_.status_code,_.reason_phrase)}),d.on("_failed",({message:_,cause:h})=>{_?r.notify(_.status_code,_.reason_phrase):r.notify(487,h)}),s.refer_to.uri.hasHeader("replaces")){const _=decodeURIComponent(s.refer_to.uri.getHeader("replaces"));n.extraHeaders=Be.cloneArray(n.extraHeaders),n.extraHeaders.push(`Replaces: ${_}`)}d.connect(s.refer_to.uri.toAor(),n,t)}function a(){r.notify(603)}}_receiveNotify(s){switch(Y.debug("receiveNotify()"),s.event||s.reply(400),s.event.event){case"refer":{let r,o;if(s.event.params&&s.event.params.id)r=s.event.params.id,o=this._referSubscribers[r];else if(Object.keys(this._referSubscribers).length===1)o=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{s.reply(400,"Missing event id parameter");return}if(!o){s.reply(481,"Subscription does not exist");return}o.receiveNotify(s),s.reply(200);break}default:s.reply(489)}}_receiveReplaces(s){Y.debug("receiveReplaces()");function r(a){if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;const t=new vu(this._ua);t.on("confirmed",()=>{this.terminate()}),t.init_incoming(s,a)}function o(){Y.debug("Replaced INVITE rejected by the user"),s.reply(486)}this.emit("replaces",{request:s,accept:a=>{r.call(this,a)},reject:()=>{o.call(this)}})}_sendInitialRequest(s,r,o){const a=new wg(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:t=>{this._request=t},onReceiveResponse:t=>{this._receiveInviteResponse(t)}});Promise.resolve().then(()=>{if(o)return o;if(s.audio||s.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(s).catch(t=>{throw this._status===Z.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,fe.causes.USER_DENIED_MEDIA_ACCESS),Y.warn('emit "getusermediafailed" [error:%o]',t),this.emit("getusermediafailed",t),t)})}).then(t=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=t,t&&t.getTracks().forEach(n=>{this._connection.addTrack(n,t)}),this._connecting(this._request),this._createLocalDescription("offer",r).catch(n=>{throw this._failed("local",null,fe.causes.WEBRTC_ERROR),n})}).then(t=>{if(this._is_canceled||this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._request.body=t,this._status=Z.STATUS_INVITE_SENT,Y.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),a.send()}).catch(t=>{this._status!==Z.STATUS_TERMINATED&&Y.warn(t)})}_getDTMFRTPSender(){const s=this._connection.getSenders().find(r=>r.track&&r.track.kind==="audio");if(!(s&&s.dtmf)){Y.warn("sendDTMF() | no local audio track to send DTMF with");return}return s.dtmf}_receiveInviteResponse(s){if(Y.debug("receiveInviteResponse()"),this._dialog&&s.status_code>=200&&s.status_code<=299)if(this._dialog.id.call_id===s.call_id&&this._dialog.id.local_tag===s.from_tag&&this._dialog.id.remote_tag===s.to_tag){this.sendRequest(fe.ACK);return}else{const r=new Ql(this,s,"UAC");if(r.error!==void 0){Y.debug(r.error);return}this.sendRequest(fe.ACK),this.sendRequest(fe.BYE);return}if(this._is_canceled){s.status_code>=100&&s.status_code<200?this._request.cancel(this._cancel_reason):s.status_code>=200&&s.status_code<299&&this._acceptAndTerminate(s);return}if(!(this._status!==Z.STATUS_INVITE_SENT&&this._status!==Z.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(s.status_code):this._status=Z.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(s.status_code):{if(!s.to_tag){Y.debug("1xx response received without to tag");break}if(s.hasHeader("contact")&&!this._createDialog(s,"UAC",!0))break;if(this._status=Z.STATUS_1XX_RECEIVED,!s.body){this._progress("remote",s);break}const r={originator:"remote",type:"answer",sdp:s.body};Y.debug('emit "sdp"'),this.emit("sdp",r);const o=new RTCSessionDescription({type:"answer",sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(o)).then(()=>this._progress("remote",s)).catch(a=>{Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)});break}case/^2[0-9]{2}$/.test(s.status_code):{if(this._status=Z.STATUS_CONFIRMED,!s.body){this._acceptAndTerminate(s,400,fe.causes.MISSING_SDP),this._failed("remote",s,fe.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(s,"UAC"))break;const r={originator:"remote",type:"answer",sdp:s.body};Y.debug('emit "sdp"'),this.emit("sdp",r);const o=new RTCSessionDescription({type:"answer",sdp:r.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(s,500,a.toString()),this._failed("local",s,fe.causes.WEBRTC_ERROR)})}).then(()=>{this._connection.setRemoteDescription(o).then(()=>{this._handleSessionTimersInIncomingResponse(s),this._accepted("remote",s),this.sendRequest(fe.ACK),this._confirmed("local",null)}).catch(a=>{this._acceptAndTerminate(s,488,"Not Acceptable Here"),this._failed("remote",s,fe.causes.BAD_MEDIA_DESCRIPTION),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})});break}default:{const r=Be.sipErrorCause(s.status_code);this._failed("remote",s,r)}}}_sendReinvite(s={}){Y.debug("sendReinvite()");const r=Be.cloneArray(s.extraHeaders),o=Be.cloneObject(s.eventHandlers),a=s.rtcOfferConstraints||this._rtcOfferConstraints||null;let t=!1;r.push(`Contact: ${this._contact}`),r.push("Content-Type: application/sdp"),this._sessionTimers.running&&r.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",a)).then(_=>{_=this._mangleOffer(_);const h={originator:"local",type:"offer",sdp:_};Y.debug('emit "sdp"'),this.emit("sdp",h),this.sendRequest(fe.INVITE,{extraHeaders:r,body:_,eventHandlers:{onSuccessResponse:g=>{n.call(this,g),t=!0},onErrorResponse:g=>{d.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{d()});function n(_){if(this._status===Z.STATUS_TERMINATED||(this.sendRequest(fe.ACK),t))return;if(this._handleSessionTimersInIncomingResponse(_),_.body){if(!_.hasHeader("Content-Type")||_.getHeader("Content-Type").toLowerCase()!=="application/sdp"){d.call(this);return}}else{d.call(this);return}const h={originator:"remote",type:"answer",sdp:_.body};Y.debug('emit "sdp"'),this.emit("sdp",h);const g=new RTCSessionDescription({type:"answer",sdp:h.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(g)).then(()=>{o.succeeded&&o.succeeded(_)}).catch(T=>{d.call(this),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function d(_){o.failed&&o.failed(_)}}_sendUpdate(s={}){Y.debug("sendUpdate()");const r=Be.cloneArray(s.extraHeaders),o=Be.cloneObject(s.eventHandlers),a=s.rtcOfferConstraints||this._rtcOfferConstraints||null,t=s.sdpOffer||!1;let n=!1;r.push(`Contact: ${this._contact}`),this._sessionTimers.running&&r.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),t?(r.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",a)).then(h=>{h=this._mangleOffer(h);const g={originator:"local",type:"offer",sdp:h};Y.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(fe.UPDATE,{extraHeaders:r,body:h,eventHandlers:{onSuccessResponse:T=>{d.call(this,T),n=!0},onErrorResponse:T=>{_.call(this,T)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{_.call(this)})):this.sendRequest(fe.UPDATE,{extraHeaders:r,eventHandlers:{onSuccessResponse:h=>{d.call(this,h)},onErrorResponse:h=>{_.call(this,h)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function d(h){if(this._status!==Z.STATUS_TERMINATED&&!n)if(this._handleSessionTimersInIncomingResponse(h),t){if(h.body){if(!h.hasHeader("Content-Type")||h.getHeader("Content-Type").toLowerCase()!=="application/sdp"){_.call(this);return}}else{_.call(this);return}const g={originator:"remote",type:"answer",sdp:h.body};Y.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(()=>{o.succeeded&&o.succeeded(h)}).catch(E=>{_.call(this),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),this.emit("peerconnection:setremotedescriptionfailed",E)})}else o.succeeded&&o.succeeded(h)}function _(h){o.failed&&o.failed(h)}}_acceptAndTerminate(s,r,o){Y.debug("acceptAndTerminate()");const a=[];r&&(o=o||fe.REASON_PHRASE[r]||"",a.push(`Reason: SIP ;cause=${r}; text="${o}"`)),(this._dialog||this._createDialog(s,"UAC"))&&(this.sendRequest(fe.ACK),this.sendRequest(fe.BYE,{extraHeaders:a})),this._status=Z.STATUS_TERMINATED}_mangleOffer(s){if(!this._localHold&&!this._remoteHold)return s;if(s=df.parse(s),this._localHold&&!this._remoteHold){Y.debug("mangleOffer() | me on hold, mangling offer");for(const r of s.media)Zl.indexOf(r.type)!==-1&&(r.direction?r.direction==="sendrecv"?r.direction="sendonly":r.direction==="recvonly"&&(r.direction="inactive"):r.direction="sendonly")}else if(this._localHold&&this._remoteHold){Y.debug("mangleOffer() | both on hold, mangling offer");for(const r of s.media)Zl.indexOf(r.type)!==-1&&(r.direction="inactive")}else if(this._remoteHold){Y.debug("mangleOffer() | remote on hold, mangling offer");for(const r of s.media)Zl.indexOf(r.type)!==-1&&(r.direction?r.direction==="sendrecv"?r.direction="recvonly":r.direction==="recvonly"&&(r.direction="inactive"):r.direction="recvonly")}return df.write(s)}_setLocalMediaStatus(){let s=!0,r=!0;(this._localHold||this._remoteHold)&&(s=!1,r=!1),this._audioMuted&&(s=!1),this._videoMuted&&(r=!1),this._toggleMuteAudio(!s),this._toggleMuteVideo(!r)}_handleSessionTimersInIncomingRequest(s,r){if(!this._sessionTimers.enabled)return;let o;s.session_expires&&s.session_expires>=fe.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=s.session_expires,o=s.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,o="uas"),r.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${o}`),this._sessionTimers.refresher=o==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(s){if(!this._sessionTimers.enabled)return;let r;s.session_expires&&s.session_expires>=fe.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=s.session_expires,r=s.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,r="uac"),this._sessionTimers.refresher=r==="uac",this._runSessionTimer()}_runSessionTimer(){const s=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(()=>{this._status!==Z.STATUS_TERMINATED&&this._isReadyToReOffer()&&(Y.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===fe.UPDATE?this._sendUpdate():this._sendReinvite())},s*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==Z.STATUS_TERMINATED&&(Y.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:fe.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},s*1100)}_toggleMuteAudio(s){const r=this._connection.getSenders().filter(o=>o.track&&o.track.kind==="audio");for(const o of r)o.track.enabled=!s}_toggleMuteVideo(s){const r=this._connection.getSenders().filter(o=>o.track&&o.track.kind==="video");for(const o of r)o.track.enabled=!s}_newRTCSession(s,r){Y.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:s,session:this,request:r})}_connecting(s){Y.debug("session connecting"),Y.debug('emit "connecting"'),this.emit("connecting",{request:s})}_progress(s,r){Y.debug("session progress"),Y.debug('emit "progress"'),this.emit("progress",{originator:s,response:r||null})}_accepted(s,r){Y.debug("session accepted"),this._start_time=new Date,Y.debug('emit "accepted"'),this.emit("accepted",{originator:s,response:r||null})}_confirmed(s,r){Y.debug("session confirmed"),this._is_confirmed=!0,Y.debug('emit "confirmed"'),this.emit("confirmed",{originator:s,ack:r||null})}_ended(s,r,o){Y.debug("session ended"),this._end_time=new Date,this._close(),Y.debug('emit "ended"'),this.emit("ended",{originator:s,message:r||null,cause:o})}_failed(s,r,o){Y.debug("session failed"),Y.debug('emit "_failed"'),this.emit("_failed",{originator:s,message:r||null,cause:o}),this._close(),Y.debug('emit "failed"'),this.emit("failed",{originator:s,message:r||null,cause:o})}_onhold(s){Y.debug("session onhold"),this._setLocalMediaStatus(),Y.debug('emit "hold"'),this.emit("hold",{originator:s})}_onunhold(s){Y.debug("session onunhold"),this._setLocalMediaStatus(),Y.debug('emit "unhold"'),this.emit("unhold",{originator:s})}_onmute({audio:s,video:r}){Y.debug("session onmute"),this._setLocalMediaStatus(),Y.debug('emit "muted"'),this.emit("muted",{audio:s,video:r})}_onunmute({audio:s,video:r}){Y.debug("session onunmute"),this._setLocalMediaStatus(),Y.debug('emit "unmuted"'),this.emit("unmuted",{audio:s,video:r})}};const Ng=Xe(T_),Ug=ft.EventEmitter,Pg=at,qa=De,xg=It,Fi=yt(),Mg=mr,Tf=Ss,kg=Es(),eo=new Pg("Message");var Lg=class extends Ug{constructor(s){super(),this._ua=s,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(s,r,o={}){const a=s;if(s===void 0||r===void 0)throw new TypeError("Not enough arguments");if(s=this._ua.normalizeTarget(s),!s)throw new TypeError(`Invalid target: ${a}`);const t=Fi.cloneArray(o.extraHeaders),n=Fi.cloneObject(o.eventHandlers),d=o.contentType||"text/plain",_={};o.fromUserName&&(_.from_uri=new kg("sip",o.fromUserName,this._ua.configuration.uri.host),t.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),o.fromDisplayName&&(_.from_display_name=o.fromDisplayName);for(const g in n)Object.prototype.hasOwnProperty.call(n,g)&&this.on(g,n[g]);t.push(`Content-Type: ${d}`),this._request=new xg.OutgoingRequest(qa.MESSAGE,s,this._ua,_,t),r&&(this._request.body=r);const h=new Mg(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:g=>{this._receiveResponse(g)}});this._newMessage("local",this._request),h.send()}init_incoming(s){this._request=s,this._newMessage("remote",s),this._is_replied||(this._is_replied=!0,s.reply(200)),this._close()}accept(s={}){const r=Fi.cloneArray(s.extraHeaders),o=s.body;if(this._direction!=="incoming")throw new Tf.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,r,o)}reject(s={}){const r=s.status_code||480,o=s.reason_phrase,a=Fi.cloneArray(s.extraHeaders),t=s.body;if(this._direction!=="incoming")throw new Tf.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(r<300||r>=700)throw new TypeError(`Invalid status_code: ${r}`);this._is_replied=!0,this._request.reply(r,o,a,t)}_receiveResponse(s){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(s.status_code):break;case/^2[0-9]{2}$/.test(s.status_code):this._succeeded("remote",s);break;default:{const r=Fi.sipErrorCause(s.status_code);this._failed("remote",s,r);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,qa.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,qa.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newMessage(s,r){s==="remote"?(this._direction="incoming",this._local_identity=r.to,this._remote_identity=r.from):s==="local"&&(this._direction="outgoing",this._local_identity=r.from,this._remote_identity=r.to),this._ua.newMessage(this,{originator:s,message:this,request:r})}_failed(s,r,o){eo.debug("MESSAGE failed"),this._close(),eo.debug('emit "failed"'),this.emit("failed",{originator:s,response:r||null,cause:o})}_succeeded(s,r){eo.debug("MESSAGE succeeded"),this._close(),eo.debug('emit "succeeded"'),this.emit("succeeded",{originator:s,response:r})}};const $g=ft.EventEmitter,Hg=at,Va=De,Fg=It,ji=yt(),jg=mr,vf=Ss,to=new Hg("Options");var qg=class extends $g{constructor(s){super(),this._ua=s,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(s,r,o={}){const a=s;if(s===void 0)throw new TypeError("A target is required for OPTIONS");if(s=this._ua.normalizeTarget(s),!s)throw new TypeError(`Invalid target: ${a}`);const t=ji.cloneArray(o.extraHeaders),n=ji.cloneObject(o.eventHandlers),d=o.contentType||"application/sdp";for(const h in n)Object.prototype.hasOwnProperty.call(n,h)&&this.on(h,n[h]);t.push(`Content-Type: ${d}`),this._request=new Fg.OutgoingRequest(Va.OPTIONS,s,this._ua,null,t),r&&(this._request.body=r);const _=new jg(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:h=>{this._receiveResponse(h)}});this._newOptions("local",this._request),_.send()}init_incoming(s){this._request=s,this._newOptions("remote",s),this._is_replied||(this._is_replied=!0,s.reply(200)),this._close()}accept(s={}){const r=ji.cloneArray(s.extraHeaders),o=s.body;if(this._direction!=="incoming")throw new vf.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,r,o)}reject(s={}){const r=s.status_code||480,o=s.reason_phrase,a=ji.cloneArray(s.extraHeaders),t=s.body;if(this._direction!=="incoming")throw new vf.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(r<300||r>=700)throw new TypeError(`Invalid status_code: ${r}`);this._is_replied=!0,this._request.reply(r,o,a,t)}_receiveResponse(s){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(s.status_code):break;case/^2[0-9]{2}$/.test(s.status_code):this._succeeded("remote",s);break;default:{const r=ji.sipErrorCause(s.status_code);this._failed("remote",s,r);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,Va.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,Va.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newOptions(s,r){s==="remote"?(this._direction="incoming",this._local_identity=r.to,this._remote_identity=r.from):s==="local"&&(this._direction="outgoing",this._local_identity=r.from,this._remote_identity=r.to),this._ua.newOptions(this,{originator:s,message:this,request:r})}_failed(s,r,o){to.debug("OPTIONS failed"),this._close(),to.debug('emit "failed"'),this.emit("failed",{originator:s,response:r||null,cause:o})}_succeeded(s,r){to.debug("OPTIONS succeeded"),this._close(),to.debug('emit "succeeded"'),this.emit("succeeded",{originator:s,response:r})}},$u={};const Vg=at,Ba=yt(),Bg=ls(),qi=new Vg("Socket");$u.isSocket=c=>{if(Array.isArray(c))return!1;if(typeof c>"u")return qi.warn("undefined JsSIP.Socket instance"),!1;try{if(!Ba.isString(c.url))throw qi.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!Ba.isString(c.via_transport))throw qi.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(Bg.parse(c.sip_uri,"SIP_URI")===-1)throw qi.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(s=>{if(!Ba.isFunction(c[s]))throw qi.warn(`missing or invalid JsSIP.Socket method: ${s}`),new Error(`Missing or invalid JsSIP.Socket method: ${s}`)})}catch{return!1}return!0};const Gg=at,Wg=$u,Ef=De,Ut=new Gg("Transport"),qt={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:Ef.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:Ef.CONNECTION_RECOVERY_MAX_INTERVAL}};var v_=class{constructor(s,r=qt.recovery_options){Ut.debug("new()"),this.status=qt.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=r,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(o){Ut.warn(`cannot use TextDecoder: ${o}`)}if(typeof s>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");s instanceof Array||(s=[s]),s.forEach(function(o){if(!Wg.isSocket(o.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(o.weight&&!Number(o.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:o.socket,weight:o.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(Ut.debug("connect()"),this.isConnected()){Ut.debug("Transport is already connected");return}else if(this.isConnecting()){Ut.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(){Ut.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(s){if(Ut.debug("send()"),!this.isConnected())return Ut.warn("unable to send message, transport is not connected"),!1;const r=s.toString();return Ut.debug(`sending message:
112
+ `,this.transport.send(a)}}class Vm extends h_{constructor(){super(),this.headers={},this.status_code=null,this.reason_phrase=null}}var Dt={OutgoingRequest:eo,InitialOutgoingInviteRequest:Hu,IncomingRequest:qm,IncomingResponse:Vm};const Dn=tt(Dt),Bm=ut,vs=Ct(),Jt=new Bm("DigestAuthentication");var d_=class{constructor(s){this._credentials=s,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(s){switch(s){case"realm":return this._realm;case"ha1":return this._ha1;default:Jt.warn('get() | cannot get "%s" parameter',s);return}}authenticate({method:s,ruri:i,body:l},a,_=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 Jt.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return Jt.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return Jt.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return Jt.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return Jt.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 Jt.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;else this._qop=null;this._method=s,this._uri=i,this._cnonce=_||vs.createRandomToken(12),this._nc+=1;const e=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-e.length)+e,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=vs.calculateMD5(`${this._credentials.username}:${this._realm}:${this._credentials.password}`):this._ha1=this._credentials.ha1;let p,g;return this._qop==="auth"?(p=`${this._method}:${this._uri}`,g=vs.calculateMD5(p),Jt.debug('authenticate() | using qop=auth [a2:"%s"]',p),this._response=vs.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${g}`)):this._qop==="auth-int"?(p=`${this._method}:${this._uri}:${vs.calculateMD5(l||"")}`,g=vs.calculateMD5(p),Jt.debug('authenticate() | using qop=auth-int [a2:"%s"]',p),this._response=vs.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${g}`)):this._qop===null&&(p=`${this._method}:${this._uri}`,g=vs.calculateMD5(p),Jt.debug('authenticate() | using qop=null [a2:"%s"]',p),this._response=vs.calculateMD5(`${this._ha1}:${this._nonce}:${g}`)),Jt.debug("authenticate() | response generated"),!0}toString(){const s=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return s.push(`algorithm=${this._algorithm}`),s.push(`username="${this._credentials.username}"`),s.push(`realm="${this._realm}"`),s.push(`nonce="${this._nonce}"`),s.push(`uri="${this._uri}"`),s.push(`response="${this._response}"`),this._opaque&&s.push(`opaque="${this._opaque}"`),this._qop&&(s.push(`qop=${this._qop}`),s.push(`cnonce="${this._cnonce}"`),s.push(`nc=${this._ncHex}`)),`Digest ${s.join(", ")}`}};const Gm=tt(d_),Es=500,Wm=4e3,af=5e3;var Fu={T1:Es,T2:Wm,T4:af,TIMER_B:64*Es,TIMER_D:0*Es,TIMER_F:64*Es,TIMER_H:64*Es,TIMER_I:0*Es,TIMER_J:0*Es,TIMER_K:0*af,TIMER_L:64*Es,TIMER_M:64*Es,PROVISIONAL_RESPONSE_INTERVAL:6e4};const Mi=tt(Fu),cl=ht.EventEmitter,fl=ut,Yi=Me,of=Dt,os=Fu,uf=new fl("NonInviteClientTransaction"),na=new fl("InviteClientTransaction"),Km=new fl("AckClientTransaction"),cf=new fl("NonInviteServerTransaction"),ra=new fl("InviteServerTransaction"),_e={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 Ym extends cl{constructor(s,i,l,a){super(),this.type=_e.NON_INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=s,this.transport=i,this.request=l,this.eventHandlers=a;let _=`SIP/2.0/${i.via_transport}`;_+=` ${s.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",_),this.ua.newTransaction(this)}get C(){return _e}stateChanged(s){this.state=s,this.emit("stateChanged")}send(){this.stateChanged(_e.STATUS_TRYING),this.F=setTimeout(()=>{this.timer_F()},os.TIMER_F),this.transport.send(this.request)||this.onTransportError()}onTransportError(){uf.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}timer_F(){uf.debug(`Timer F expired for transaction ${this.id}`),this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}timer_K(){this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this)}receiveResponse(s){const i=s.status_code;if(i<200)switch(this.state){case _e.STATUS_TRYING:case _e.STATUS_PROCEEDING:this.stateChanged(_e.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(s);break}else switch(this.state){case _e.STATUS_TRYING:case _e.STATUS_PROCEEDING:this.stateChanged(_e.STATUS_COMPLETED),clearTimeout(this.F),i===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(s),this.K=setTimeout(()=>{this.timer_K()},os.TIMER_K);break;case _e.STATUS_COMPLETED:break}}}class Jm extends cl{constructor(s,i,l,a){super(),this.type=_e.INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=s,this.transport=i,this.request=l,this.eventHandlers=a,l.transaction=this;let _=`SIP/2.0/${i.via_transport}`;_+=` ${s.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",_),this.ua.newTransaction(this)}get C(){return _e}stateChanged(s){this.state=s,this.emit("stateChanged")}send(){this.stateChanged(_e.STATUS_CALLING),this.B=setTimeout(()=>{this.timer_B()},os.TIMER_B),this.transport.send(this.request)||this.onTransportError()}onTransportError(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==_e.STATUS_ACCEPTED&&(na.debug(`transport error occurred, deleting transaction ${this.id}`),this.eventHandlers.onTransportError()),this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_M(){na.debug(`Timer M expired for transaction ${this.id}`),this.state===_e.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this))}timer_B(){na.debug(`Timer B expired for transaction ${this.id}`),this.state===_e.STATUS_CALLING&&(this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}timer_D(){na.debug(`Timer D expired for transaction ${this.id}`),clearTimeout(this.B),this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this)}sendACK(s){const i=new of.OutgoingRequest(Yi.ACK,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});i.setHeader("from",this.request.getHeader("from")),i.setHeader("via",this.request.getHeader("via")),i.setHeader("to",s.getHeader("to")),this.D=setTimeout(()=>{this.timer_D()},os.TIMER_D),this.transport.send(i)}cancel(s){if(this.state!==_e.STATUS_PROCEEDING)return;const i=new of.OutgoingRequest(Yi.CANCEL,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});i.setHeader("from",this.request.getHeader("from")),i.setHeader("via",this.request.getHeader("via")),i.setHeader("to",this.request.getHeader("to")),s&&i.setHeader("reason",s),this.transport.send(i)}receiveResponse(s){const i=s.status_code;if(i>=100&&i<=199)switch(this.state){case _e.STATUS_CALLING:this.stateChanged(_e.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(s);break;case _e.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(s);break}else if(i>=200&&i<=299)switch(this.state){case _e.STATUS_CALLING:case _e.STATUS_PROCEEDING:this.stateChanged(_e.STATUS_ACCEPTED),this.M=setTimeout(()=>{this.timer_M()},os.TIMER_M),this.eventHandlers.onReceiveResponse(s);break;case _e.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(s);break}else if(i>=300&&i<=699)switch(this.state){case _e.STATUS_CALLING:case _e.STATUS_PROCEEDING:this.stateChanged(_e.STATUS_COMPLETED),this.sendACK(s),this.eventHandlers.onReceiveResponse(s);break;case _e.STATUS_COMPLETED:this.sendACK(s);break}}}class zm extends cl{constructor(s,i,l,a){super(),this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.transport=i,this.request=l,this.eventHandlers=a;let _=`SIP/2.0/${i.via_transport}`;_+=` ${s.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",_)}get C(){return _e}send(){this.transport.send(this.request)||this.onTransportError()}onTransportError(){Km.debug(`transport error occurred for transaction ${this.id}`),this.eventHandlers.onTransportError()}}class Xm extends cl{constructor(s,i,l){super(),this.type=_e.NON_INVITE_SERVER,this.id=l.via_branch,this.ua=s,this.transport=i,this.request=l,this.last_response="",l.server_transaction=this,this.state=_e.STATUS_TRYING,s.newTransaction(this)}get C(){return _e}stateChanged(s){this.state=s,this.emit("stateChanged")}timer_J(){cf.debug(`Timer J expired for transaction ${this.id}`),this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this)}onTransportError(){this.transportError||(this.transportError=!0,cf.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.J),this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this))}receiveResponse(s,i,l,a){if(s===100)switch(this.state){case _e.STATUS_TRYING:this.stateChanged(_e.STATUS_PROCEEDING),this.transport.send(i)||this.onTransportError();break;case _e.STATUS_PROCEEDING:this.last_response=i,this.transport.send(i)?l&&l():(this.onTransportError(),a&&a());break}else if(s>=200&&s<=699)switch(this.state){case _e.STATUS_TRYING:case _e.STATUS_PROCEEDING:this.stateChanged(_e.STATUS_COMPLETED),this.last_response=i,this.J=setTimeout(()=>{this.timer_J()},os.TIMER_J),this.transport.send(i)?l&&l():(this.onTransportError(),a&&a());break;case _e.STATUS_COMPLETED:break}}}class Qm extends cl{constructor(s,i,l){super(),this.type=_e.INVITE_SERVER,this.id=l.via_branch,this.ua=s,this.transport=i,this.request=l,this.last_response="",l.server_transaction=this,this.state=_e.STATUS_PROCEEDING,s.newTransaction(this),this.resendProvisionalTimer=null,l.reply(100)}get C(){return _e}stateChanged(s){this.state=s,this.emit("stateChanged")}timer_H(){ra.debug(`Timer H expired for transaction ${this.id}`),this.state===_e.STATUS_COMPLETED&&ra.debug("ACK not received, dialog will be terminated"),this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_I(){this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_L(){ra.debug(`Timer L expired for transaction ${this.id}`),this.state===_e.STATUS_ACCEPTED&&(this.stateChanged(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this))}onTransportError(){this.transportError||(this.transportError=!0,ra.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(_e.STATUS_TERMINATED),this.ua.destroyTransaction(this))}resend_provisional(){this.transport.send(this.last_response)||this.onTransportError()}receiveResponse(s,i,l,a){if(s>=100&&s<=199)switch(this.state){case _e.STATUS_PROCEEDING:this.transport.send(i)||this.onTransportError(),this.last_response=i;break}if(s>100&&s<=199&&this.state===_e.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(()=>{this.resend_provisional()},os.PROVISIONAL_RESPONSE_INTERVAL));else if(s>=200&&s<=299)switch(this.state){case _e.STATUS_PROCEEDING:this.stateChanged(_e.STATUS_ACCEPTED),this.last_response=i,this.L=setTimeout(()=>{this.timer_L()},os.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case _e.STATUS_ACCEPTED:this.transport.send(i)?l&&l():(this.onTransportError(),a&&a());break}else if(s>=300&&s<=699)switch(this.state){case _e.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(i)?(this.stateChanged(_e.STATUS_COMPLETED),this.H=setTimeout(()=>{this.timer_H()},os.TIMER_H),l&&l()):(this.onTransportError(),a&&a());break}}}function Zm({_transactions:c},s){let i;switch(s.method){case Yi.INVITE:if(i=c.ist[s.via_branch],i){switch(i.state){case _e.STATUS_PROCEEDING:i.transport.send(i.last_response);break;case _e.STATUS_ACCEPTED:break}return!0}break;case Yi.ACK:if(i=c.ist[s.via_branch],i){if(i.state===_e.STATUS_ACCEPTED)return!1;if(i.state===_e.STATUS_COMPLETED)return i.state=_e.STATUS_CONFIRMED,i.I=setTimeout(()=>{i.timer_I()},os.TIMER_I),!0}else return!1;break;case Yi.CANCEL:return i=c.ist[s.via_branch],i?(s.reply_sl(200),i.state!==_e.STATUS_PROCEEDING):(s.reply_sl(481),!0);default:if(i=c.nist[s.via_branch],i){switch(i.state){case _e.STATUS_TRYING:break;case _e.STATUS_PROCEEDING:case _e.STATUS_COMPLETED:i.transport.send(i.last_response);break}return!0}break}}var cr={C:_e,NonInviteClientTransaction:Ym,InviteClientTransaction:Jm,AckClientTransaction:zm,NonInviteServerTransaction:Xm,InviteServerTransaction:Qm,checkTransaction:Zm};const Vt=tt(cr),eg=ut,ff=Me,tg=d_,$o=cr,sg=new eg("RequestSender"),Ho={onRequestTimeout:()=>{},onTransportError:()=>{},onReceiveResponse:()=>{},onAuthenticated:()=>{}};var fr=class{constructor(s,i,l){this._ua=s,this._eventHandlers=l,this._method=i.method,this._request=i,this._auth=null,this._challenged=!1,this._staled=!1;for(const a in Ho)Object.prototype.hasOwnProperty.call(Ho,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=Ho[a]));s.status===s.C.STATUS_USER_CLOSED&&(this._method!==ff.BYE||this._method!==ff.ACK)&&this._eventHandlers.onTransportError()}send(){const s={onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onReceiveResponse:i=>{this._receiveResponse(i)}};switch(this._method){case"INVITE":this.clientTransaction=new $o.InviteClientTransaction(this._ua,this._ua.transport,this._request,s);break;case"ACK":this.clientTransaction=new $o.AckClientTransaction(this._ua,this._ua.transport,this._request,s);break;default:this.clientTransaction=new $o.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,s)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}_receiveResponse(s){let i,l;const a=s.status_code;if((a===401||a===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(s.status_code===401?(i=s.parseHeader("www-authenticate"),l="authorization"):(i=s.parseHeader("proxy-authenticate"),l="proxy-authorization"),!i){sg.debug(`${s.status_code} with wrong or missing challenge, cannot authenticate`),this._eventHandlers.onReceiveResponse(s);return}if(!this._challenged||!this._staled&&i.stale===!0){if(this._auth||(this._auth=new tg({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,i)){this._eventHandlers.onReceiveResponse(s);return}this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),i.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(l,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(s)}else this._eventHandlers.onReceiveResponse(s)}};const Ga=tt(fr),ng=ut,Fo=Ct(),Rn=Me,_f=Dt,hf=fr,ki=new ng("Registrator"),ia=10;var rg=class{constructor(s,i){this._reg_id=1,this._ua=s,this._transport=i,this._registrar=s.configuration.registrar_server,this._expires=s.configuration.register_expires,this._call_id=Fo.createRandomToken(22),this._cseq=0,this._to_uri=s.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString(),this._extraContactParams+=";+sip.ice",this._extraHeaders=[],this._sipInstance=`"<urn:uuid:${this._ua.configuration.instance_id}>"`,this._extraContactParams+=`;reg-id=${this._reg_id}`,this._extraContactParams+=`;+sip.instance=${this._sipInstance}`}get registered(){return this._registered}setExtraHeaders(s){Array.isArray(s)||(s=[]),this._extraHeaders=s.slice()}setExtraContactParams(s){s instanceof Object||(s={}),this._extraContactParams="";for(const i in s)if(Object.prototype.hasOwnProperty.call(s,i)){const l=s[i];this._extraContactParams+=`;${i}`,l&&(this._extraContactParams+=`=${l}`)}}register(){if(this._registering){ki.debug("Register request in progress...");return}const s=this._extraHeaders.slice();s.push(`Contact: ${this._contact};expires=${this._expires}${this._extraContactParams}`),s.push(`Expires: ${this._expires}`);const i=new _f.OutgoingRequest(Rn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},s),l=new hf(this._ua,i,{onRequestTimeout:()=>{this._registrationFailure(null,Rn.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,Rn.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:a=>{if(a.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(a.status_code):break;case/^2[0-9]{2}$/.test(a.status_code):{if(this._registering=!1,!a.hasHeader("Contact")){ki.debug("no Contact header in response to REGISTER, response ignored");break}const _=a.headers.Contact.reduce((n,v)=>n.concat(v.parsed),[]);let e=_.find(n=>this._sipInstance===n.getParam("+sip.instance")&&this._reg_id===parseInt(n.getParam("reg-id")));if(e||(e=_.find(n=>n.uri.user===this._ua.contact.uri.user)),!e){ki.debug("no Contact header pointing to us, response ignored");break}let p=e.getParam("expires");!p&&a.hasHeader("expires")&&(p=a.getHeader("expires")),p||(p=this._expires),p=Number(p),p<ia&&(p=ia);const g=p>64?p*1e3/2+Math.floor((p/2-32)*1e3*Math.random()):p*1e3-5e3;this._registrationTimer=setTimeout(()=>{this._registrationTimer=null,this._ua.listeners("registrationExpiring").length===0?this.register():this._ua.emit("registrationExpiring")},g),e.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=e.getParam("temp-gruu").replace(/"/g,"")),e.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=e.getParam("pub-gruu").replace(/"/g,"")),this._registered||(this._registered=!0,this._ua.registered({response:a}));break}case/^423$/.test(a.status_code):{a.hasHeader("min-expires")?(this._expires=Number(a.getHeader("min-expires")),this._expires<ia&&(this._expires=ia),this.register()):(ki.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(a,Rn.causes.SIP_FAILURE_CODE));break}default:{const _=Fo.sipErrorCause(a.status_code);this._registrationFailure(a,_)}}}});this._registering=!0,l.send()}unregister(s={}){if(!this._registered){ki.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const i=this._extraHeaders.slice();s.all?i.push(`Contact: *${this._extraContactParams}`):i.push(`Contact: ${this._contact};expires=0${this._extraContactParams}`),i.push("Expires: 0");const l=new _f.OutgoingRequest(Rn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},i);new hf(this._ua,l,{onRequestTimeout:()=>{this._unregistered(null,Rn.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,Rn.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:_=>{switch(!0){case/^1[0-9]{2}$/.test(_.status_code):break;case/^2[0-9]{2}$/.test(_.status_code):this._unregistered(_);break;default:{const e=Fo.sipErrorCause(_.status_code);this._unregistered(_,e)}}}}).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(s,i){this._registering=!1,this._ua.registrationFailed({response:s||null,cause:i}),this._registered&&(this._registered=!1,this._ua.unregistered({response:s||null,cause:i}))}_unregistered(s,i){this._registering=!1,this._registered=!1,this._ua.unregistered({response:s||null,cause:i||null})}};class ig extends Error{constructor(s,i){super(),this.code=1,this.name="CONFIGURATION_ERROR",this.parameter=s,this.value=i,this.message=this.value?`Invalid value ${JSON.stringify(this.value)} for parameter "${this.parameter}"`:`Missing parameter: ${this.parameter}`}}class lg extends Error{constructor(s){super(),this.code=2,this.name="INVALID_STATE_ERROR",this.status=s,this.message=`Invalid status: ${s}`}}class ag extends Error{constructor(s){super(),this.code=3,this.name="NOT_SUPPORTED_ERROR",this.message=s}}class og extends Error{constructor(s){super(),this.code=4,this.name="NOT_READY_ERROR",this.message=s}}var bs={ConfigurationError:ig,InvalidStateError:lg,NotSupportedError:ag,NotReadyError:og};const zs=tt(bs),jo=Me,la=cr,ug=fr,qo={onRequestTimeout:()=>{},onTransportError:()=>{},onSuccessResponse:()=>{},onErrorResponse:()=>{},onAuthenticated:()=>{},onDialogError:()=>{}};var p_=class{constructor(s,i,l){this._dialog=s,this._ua=s._ua,this._request=i,this._eventHandlers=l,this._reattempt=!1,this._reattemptTimer=null;for(const a in qo)Object.prototype.hasOwnProperty.call(qo,a)&&(this._eventHandlers[a]||(this._eventHandlers[a]=qo[a]))}get request(){return this._request}send(){const s=new ug(this._ua,this._request,{onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onAuthenticated:i=>{this._eventHandlers.onAuthenticated(i)},onReceiveResponse:i=>{this._receiveResponse(i)}});if(s.send(),(this._request.method===jo.INVITE||this._request.method===jo.UPDATE&&this._request.body)&&s.clientTransaction.state!==la.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;const i=()=>{(s.clientTransaction.state===la.C.STATUS_ACCEPTED||s.clientTransaction.state===la.C.STATUS_COMPLETED||s.clientTransaction.state===la.C.STATUS_TERMINATED)&&(s.clientTransaction.removeListener("stateChanged",i),this._dialog.uac_pending_reply=!1)};s.clientTransaction.on("stateChanged",i)}}_receiveResponse(s){s.status_code===408||s.status_code===481?this._eventHandlers.onDialogError(s):s.method===jo.INVITE&&s.status_code===491?this._reattempt?s.status_code>=200&&s.status_code<300?this._eventHandlers.onSuccessResponse(s):s.status_code>=300&&this._eventHandlers.onErrorResponse(s):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(()=>{this._dialog.isTerminated()||(this._reattempt=!0,this.send())},1e3)):s.status_code>=200&&s.status_code<300?this._eventHandlers.onSuccessResponse(s):s.status_code>=300&&this._eventHandlers.onErrorResponse(s)}};const cg=tt(p_),fg=ut,df=Dt,Ws=Me,Li=cr,_g=p_,Vo=Ct(),Bo=new fg("Dialog"),Ks={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};var m_=class{static get C(){return Ks}constructor(s,i,l,a=Ks.STATUS_CONFIRMED){if(this._owner=s,this._ua=s._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!i.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};i instanceof df.IncomingResponse&&(a=i.status_code<200?Ks.STATUS_EARLY:Ks.STATUS_CONFIRMED);const _=i.parseHeader("contact");l==="UAS"?(this._id={call_id:i.call_id,local_tag:i.to_tag,remote_tag:i.from_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._remote_seqnum=i.cseq,this._local_uri=i.parseHeader("to").uri,this._remote_uri=i.parseHeader("from").uri,this._remote_target=_.uri,this._route_set=i.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):l==="UAC"&&(this._id={call_id:i.call_id,local_tag:i.from_tag,remote_tag:i.to_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._local_seqnum=i.cseq,this._local_uri=i.parseHeader("from").uri,this._remote_uri=i.parseHeader("to").uri,this._remote_target=_.uri,this._route_set=i.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),Bo.debug(`new ${l} dialog created with status ${this._state===Ks.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(s){this._local_seqnum=s}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(s){this._uac_pending_reply=s}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===Ks.STATUS_TERMINATED}update(s,i){this._state=Ks.STATUS_CONFIRMED,Bo.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),i==="UAC"&&(this._route_set=s.getHeaders("record-route").reverse())}terminate(){Bo.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Ks.STATUS_TERMINATED}sendRequest(s,i={}){const l=Vo.cloneArray(i.extraHeaders),a=Vo.cloneObject(i.eventHandlers),_=i.body||null,e=this._createRequest(s,l,_);return a.onAuthenticated=()=>{this._local_seqnum+=1},new _g(this,e,a).send(),e}receiveRequest(s){this._checkInDialogRequest(s)&&(s.method===Ws.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:s.method===Ws.INVITE&&(this._ack_seqnum=s.cseq),this._owner.receiveRequest(s))}_createRequest(s,i,l){i=Vo.cloneArray(i),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const a=s===Ws.CANCEL||s===Ws.ACK?this._local_seqnum:this._local_seqnum+=1;return new df.OutgoingRequest(s,this._remote_target,this._ua,{cseq:a,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},i,l)}_checkInDialogRequest(s){if(!this._remote_seqnum)this._remote_seqnum=s.cseq;else if(s.cseq<this._remote_seqnum)if(s.method===Ws.ACK){if(this._ack_seqnum===null||s.cseq!==this._ack_seqnum)return!1}else return s.reply(500),!1;else s.cseq>this._remote_seqnum&&(this._remote_seqnum=s.cseq);if(s.method===Ws.INVITE||s.method===Ws.UPDATE&&s.body){if(this._uac_pending_reply===!0)s.reply(491);else if(this._uas_pending_reply===!0){const i=(Math.random()*10|0)+1;return s.reply(500,null,[`Retry-After:${i}`]),!1}else{this._uas_pending_reply=!0;const i=()=>{(s.server_transaction.state===Li.C.STATUS_ACCEPTED||s.server_transaction.state===Li.C.STATUS_COMPLETED||s.server_transaction.state===Li.C.STATUS_TERMINATED)&&(s.server_transaction.removeListener("stateChanged",i),this._uas_pending_reply=!1)};s.server_transaction.on("stateChanged",i)}s.hasHeader("contact")&&s.server_transaction.on("stateChanged",()=>{s.server_transaction.state===Li.C.STATUS_ACCEPTED&&(this._remote_target=s.parseHeader("contact").uri)})}else s.method===Ws.NOTIFY&&s.hasHeader("contact")&&s.server_transaction.on("stateChanged",()=>{s.server_transaction.state===Li.C.STATUS_COMPLETED&&(this._remote_target=s.parseHeader("contact").uri)});return!0}};const aa=tt(m_);var ju={exports:{}};const hg=ht.EventEmitter,dg=ut,pg=Me,mg=bs,pf=Ct(),gg=new dg("RTCSession:DTMF"),g_={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};ju.exports=class extends hg{constructor(s){super(),this._session=s,this._direction=null,this._tone=null,this._duration=null,this._request=null}get tone(){return this._tone}get duration(){return this._duration}send(s,i={}){if(s===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 mg.InvalidStateError(this._session.status);const l=pf.cloneArray(i.extraHeaders);if(this.eventHandlers=pf.cloneObject(i.eventHandlers),typeof s=="string")s=s.toUpperCase();else if(typeof s=="number")s=s.toString();else throw new TypeError(`Invalid tone: ${s}`);if(s.match(/^[0-9A-DR#*]$/))this._tone=s;else throw new TypeError(`Invalid tone: ${s}`);this._duration=i.duration,l.push("Content-Type: application/dtmf-relay");let a=`Signal=${this._tone}\r
113
+ `;a+=`Duration=${this._duration}`,this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(pg.INFO,{extraHeaders:l,eventHandlers:{onSuccessResponse:_=>{this.emit("succeeded",{originator:"remote",response:_})},onErrorResponse:_=>{this.eventHandlers.onFailed&&this.eventHandlers.onFailed(),this.emit("failed",{originator:"remote",response:_})},onRequestTimeout:()=>{this._session.onRequestTimeout()},onTransportError:()=>{this._session.onTransportError()},onDialogError:()=>{this._session.onDialogError()}},body:a})}init_incoming(s){const i=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,l=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=s,s.reply(200),s.body){const a=s.body.split(`
114
+ `);a.length>=1&&i.test(a[0])&&(this._tone=a[0].replace(i,"$2")),a.length>=2&&l.test(a[1])&&(this._duration=parseInt(a[1].replace(l,"$2"),10))}this._duration||(this._duration=g_.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:s}):gg.debug("invalid INFO DTMF received, discarded")}};ju.exports.C=g_;var T_=ju.exports;const Tg=tt(T_),vg=ht.EventEmitter,Eg=Me,Sg=bs,yg=Ct();var v_=class extends vg{constructor(s){super(),this._session=s,this._direction=null,this._contentType=null,this._body=null}get contentType(){return this._contentType}get body(){return this._body}send(s,i,l={}){if(this._direction="outgoing",s===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 Sg.InvalidStateError(this._session.status);this._contentType=s,this._body=i;const a=yg.cloneArray(l.extraHeaders);a.push(`Content-Type: ${s}`),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(Eg.INFO,{extraHeaders:a,eventHandlers:{onSuccessResponse:_=>{this.emit("succeeded",{originator:"remote",response:_})},onErrorResponse:_=>{this.emit("failed",{originator:"remote",response:_})},onTransportError:()=>{this._session.onTransportError()},onRequestTimeout:()=>{this._session.onRequestTimeout()},onDialogError:()=>{this._session.onDialogError()}},body:i})}init_incoming(s){this._direction="incoming",this.request=s,s.reply(200),this._contentType=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0,this._body=s.body,this._session.newInfo({originator:"remote",info:this,request:s})}};const yu=tt(v_),Ag=ut,mf=Me,Cg=new Ag("RTCSession:ReferNotifier"),Go={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300};var E_=class{constructor(s,i,l){this._session=s,this._id=i,this._expires=l||Go.expires,this._active=!0,this.notify(100)}notify(s,i){if(Cg.debug("notify()"),this._active===!1)return;i=i||mf.REASON_PHRASE[s]||"";let l;s>=200?l="terminated;reason=noresource":l=`active;expires=${this._expires}`,this._session.sendRequest(mf.NOTIFY,{extraHeaders:[`Event: ${Go.event_type};id=${this._id}`,`Subscription-State: ${l}`,`Content-Type: ${Go.body_type}`],body:`SIP/2.0 ${s} ${i}`,eventHandlers:{onErrorResponse(){this._active=!1}}})}};const Rg=tt(E_),Ig=ht.EventEmitter,bg=ut,$i=Me,wg=Qt(),gf=Ct(),In=new bg("RTCSession:ReferSubscriber");var S_=class extends Ig{constructor(s){super(),this._id=null,this._session=s}get id(){return this._id}sendRefer(s,i={}){In.debug("sendRefer()");const l=gf.cloneArray(i.extraHeaders),a=gf.cloneObject(i.eventHandlers);for(const g in a)Object.prototype.hasOwnProperty.call(a,g)&&this.on(g,a[g]);let _=null;i.replaces&&(_=i.replaces._request.call_id,_+=`;to-tag=${i.replaces._to_tag}`,_+=`;from-tag=${i.replaces._from_tag}`,_=encodeURIComponent(_));const e=`Refer-To: <${s}${_?`?Replaces=${_}`:""}>`;if(l.push(e),!l.some(g=>g.toLowerCase().startsWith("referred-by:"))){const g=`Referred-By: <${this._session._ua._configuration.uri._scheme}:${this._session._ua._configuration.uri._user}@${this._session._ua._configuration.uri._host}>`;l.push(g)}l.push(`Contact: ${this._session.contact}`);const p=this._session.sendRequest($i.REFER,{extraHeaders:l,eventHandlers:{onSuccessResponse:g=>{this._requestSucceeded(g)},onErrorResponse:g=>{this._requestFailed(g,$i.causes.REJECTED)},onTransportError:()=>{this._requestFailed(null,$i.causes.CONNECTION_ERROR)},onRequestTimeout:()=>{this._requestFailed(null,$i.causes.REQUEST_TIMEOUT)},onDialogError:()=>{this._requestFailed(null,$i.causes.DIALOG_ERROR)}}});this._id=p.cseq}receiveNotify(s){if(In.debug("receiveNotify()"),!s.body)return;const i=wg.parse(s.body.trim().split(`\r
115
+ `,1)[0],"Status_Line");if(i===-1){In.debug(`receiveNotify() | error parsing NOTIFY body: "${s.body}"`);return}switch(!0){case/^100$/.test(i.status_code):this.emit("trying",{request:s,status_line:i});break;case/^1[0-9]{2}$/.test(i.status_code):this.emit("progress",{request:s,status_line:i});break;case/^2[0-9]{2}$/.test(i.status_code):this.emit("accepted",{request:s,status_line:i});break;default:this.emit("failed",{request:s,status_line:i});break}}_requestSucceeded(s){In.debug("REFER succeeded"),In.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:s})}_requestFailed(s,i){In.debug("REFER failed"),In.debug('emit "requestFailed"'),this.emit("requestFailed",{response:s||null,cause:i})}};const Og=tt(S_),Dg=ht.EventEmitter,Tf=kt,Ng=ut,ce=Me,bn=bs,vf=cr,Je=Ct(),Hi=Fu,Ug=Dt,oa=m_,Pg=fr,$t=T_,Ef=v_,xg=E_,Mg=S_,Sf=Is(),z=new Ng("RTCSession"),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},ua=["audio","video"];var y_=class Au extends Dg{static get C(){return te}constructor(s){z.debug("new"),super(),this._id=null,this._ua=s,this._status=te.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:ce.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._referSubscribers={},this._data={}}get C(){return te}get causes(){return ce.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(s){this._data=s}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}}connect(s,i={},l){z.debug("connect()");const a=s,_=Je.cloneObject(i.eventHandlers),e=Je.cloneArray(i.extraHeaders),p=Je.cloneObject(i.mediaConstraints,{audio:!0,video:!0}),g=i.mediaStream||null,n=Je.cloneObject(i.pcConfig,{iceServers:[]}),v=i.rtcConstraints||null,S=i.rtcOfferConstraints||null;if(this._rtcOfferConstraints=S,this._rtcAnswerConstraints=i.rtcAnswerConstraints||null,this._data=i.data||this._data,s===void 0)throw new TypeError("Not enough arguments");if(this._status!==te.STATUS_NULL)throw new bn.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new bn.NotSupportedError("WebRTC not supported");if(s=this._ua.normalizeTarget(s),!s)throw new TypeError(`Invalid target: ${a}`);this._sessionTimers.enabled&&Je.isDecimal(i.sessionTimersExpires)&&(i.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=i.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES);for(const A in _)Object.prototype.hasOwnProperty.call(_,A)&&this.on(A,_[A]);this._from_tag=Je.newTag();const m=i.anonymous||!1,C={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:m,outbound:!0}),m?(C.from_display_name="Anonymous",C.from_uri=new Sf("sip","anonymous","anonymous.invalid"),e.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),e.push("Privacy: id")):i.fromUserName&&(C.from_uri=new Sf("sip",i.fromUserName,this._ua.configuration.uri.host),e.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),i.fromDisplayName&&(C.from_display_name=i.fromDisplayName),e.push(`Contact: ${this._contact}`),e.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&e.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new Ug.InitialOutgoingInviteRequest(s,this._ua,C,e),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(n,v),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,l&&l(this),this._newRTCSession("local",this._request),this._sendInitialRequest(p,S,g)}init_incoming(s,i){z.debug("init_incoming()");let l;const a=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0;if(s.body&&a!=="application/sdp"){s.reply(415);return}if(this._status=te.STATUS_INVITE_RECEIVED,this._from_tag=s.from_tag,this._id=s.call_id+this._from_tag,this._request=s,this._contact=this._ua.contact.toString(),s.hasHeader("expires")&&(l=s.getHeader("expires")*1e3),s.to_tag=Je.newTag(),!this._createDialog(s,"UAS",!0)){s.reply(500,"Missing Contact header field");return}s.body?this._late_sdp=!1:this._late_sdp=!0,this._status=te.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{s.reply(408),this._failed("local",null,ce.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),l&&(this._timers.expiresTimer=setTimeout(()=>{this._status===te.STATUS_WAITING_FOR_ANSWER&&(s.reply(487),this._failed("system",null,ce.causes.EXPIRES))},l)),this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from,i&&i(this),this._newRTCSession("remote",s),this._status!==te.STATUS_TERMINATED&&(s.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(s={}){z.debug("answer()");const i=this._request,l=Je.cloneArray(s.extraHeaders),a=Je.cloneObject(s.mediaConstraints),_=s.mediaStream||null,e=Je.cloneObject(s.pcConfig,{iceServers:[]}),p=s.rtcConstraints||null,g=s.rtcAnswerConstraints||null,n=Je.cloneObject(s.rtcOfferConstraints);let v,S=!1,m=!1,C=!1,A=!1;if(this._rtcAnswerConstraints=g,this._rtcOfferConstraints=s.rtcOfferConstraints||null,this._data=s.data||this._data,this._direction!=="incoming")throw new bn.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==te.STATUS_WAITING_FOR_ANSWER)throw new bn.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Je.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES),this._status=te.STATUS_ANSWERED,!this._createDialog(i,"UAS")){i.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),l.unshift(`Contact: ${this._contact}`);const R=i.parseSDP();Array.isArray(R.media)||(R.media=[R.media]);for(const I of R.media)I.type==="audio"&&(S=!0,(!I.direction||I.direction==="sendrecv")&&(C=!0)),I.type==="video"&&(m=!0,(!I.direction||I.direction==="sendrecv")&&(A=!0));if(_&&a.audio===!1){v=_.getAudioTracks();for(const I of v)_.removeTrack(I)}if(_&&a.video===!1){v=_.getVideoTracks();for(const I of v)_.removeTrack(I)}!_&&a.audio===void 0&&(a.audio=C),!_&&a.video===void 0&&(a.video=A),!_&&!S&&!n.offerToReceiveAudio&&(a.audio=!1),!_&&!m&&!n.offerToReceiveVideo&&(a.video=!1),this._createRTCConnection(e,p),Promise.resolve().then(()=>{if(_)return _;if(a.audio||a.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(a).catch(I=>{throw this._status===te.STATUS_TERMINATED?new Error("terminated"):(i.reply(480),this._failed("local",null,ce.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(V=>{this._connection.addTrack(V,I)})}).then(()=>{if(this._late_sdp)return;const I={originator:"remote",type:"offer",sdp:i.body};z.debug('emit "sdp"'),this.emit("sdp",I);const V=new RTCSessionDescription({type:"offer",sdp:I.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(V)).catch(W=>{throw i.reply(488),this._failed("system",null,ce.causes.WEBRTC_ERROR),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',W),this.emit("peerconnection:setremotedescriptionfailed",W),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(i),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw i.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",g).catch(()=>{throw i.reply(500),new Error("_createLocalDescription() failed")})}).then(I=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(i,l),i.reply(200,null,l,I,()=>{this._status=te.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(i,I),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,ce.causes.CONNECTION_ERROR)})}).catch(I=>{this._status!==te.STATUS_TERMINATED&&z.warn(I)})}terminate(s={}){z.debug("terminate()");const i=s.cause||ce.causes.BYE,l=Je.cloneArray(s.extraHeaders),a=s.body;let _,e=s.status_code,p=s.reason_phrase;if(this._status===te.STATUS_TERMINATED)throw new bn.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"),e&&(e<200||e>=700))throw new TypeError(`Invalid status_code: ${e}`);e&&(p=p||ce.REASON_PHRASE[e]||"",_=`SIP ;cause=${e} ;text="${p}"`),this._status===te.STATUS_NULL||this._status===te.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=_):this._status===te.STATUS_1XX_RECEIVED&&this._request.cancel(_),this._status=te.STATUS_CANCELED,this._failed("local",null,ce.causes.CANCELED);break;case te.STATUS_WAITING_FOR_ANSWER:case te.STATUS_ANSWERED:if(z.debug("rejecting session"),e=e||480,e<300||e>=700)throw new TypeError(`Invalid status_code: ${e}`);this._request.reply(e,p,l,a),this._failed("local",null,ce.causes.REJECTED);break;case te.STATUS_WAITING_FOR_ACK:case te.STATUS_CONFIRMED:if(z.debug("terminating session"),p=s.reason_phrase||ce.REASON_PHRASE[e]||"",e&&(e<200||e>=700))throw new TypeError(`Invalid status_code: ${e}`);if(e&&l.push(`Reason: SIP ;cause=${e}; text="${p}"`),this._status===te.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==vf.C.STATUS_TERMINATED){const g=this._dialog;this.receiveRequest=({method:n})=>{n===ce.ACK&&(this.sendRequest(ce.BYE,{extraHeaders:l,body:a}),g.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===vf.C.STATUS_TERMINATED&&(this.sendRequest(ce.BYE,{extraHeaders:l,body:a}),g.terminate())}),this._ended("local",null,i),this._dialog=g,this._ua.newDialog(g)}else this.sendRequest(ce.BYE,{extraHeaders:l,body:a}),this._ended("local",null,i)}}sendDTMF(s,i={}){z.debug("sendDTMF() | tones: %s",s);let l=0,a=i.duration||null,_=i.interToneGap||null;const e=i.transportType||ce.DTMF_TRANSPORT.INFO;if(s===void 0)throw new TypeError("Not enough arguments");if(this._status!==te.STATUS_CONFIRMED&&this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_1XX_RECEIVED)throw new bn.InvalidStateError(this._status);if(e!==ce.DTMF_TRANSPORT.INFO&&e!==ce.DTMF_TRANSPORT.RFC2833)throw new TypeError(`invalid transportType: ${e}`);if(typeof s=="number"&&(s=s.toString()),!s||typeof s!="string"||!s.match(/^[0-9A-DR#*,]+$/i))throw new TypeError(`Invalid tones: ${s}`);if(a&&!Je.isDecimal(a))throw new TypeError(`Invalid tone duration: ${a}`);if(a?a<$t.C.MIN_DURATION?(z.debug(`"duration" value is lower than the minimum allowed, setting it to ${$t.C.MIN_DURATION} milliseconds`),a=$t.C.MIN_DURATION):a>$t.C.MAX_DURATION?(z.debug(`"duration" value is greater than the maximum allowed, setting it to ${$t.C.MAX_DURATION} milliseconds`),a=$t.C.MAX_DURATION):a=Math.abs(a):a=$t.C.DEFAULT_DURATION,i.duration=a,_&&!Je.isDecimal(_))throw new TypeError(`Invalid interToneGap: ${_}`);if(_?_<$t.C.MIN_INTER_TONE_GAP?(z.debug(`"interToneGap" value is lower than the minimum allowed, setting it to ${$t.C.MIN_INTER_TONE_GAP} milliseconds`),_=$t.C.MIN_INTER_TONE_GAP):_=Math.abs(_):_=$t.C.DEFAULT_INTER_TONE_GAP,e===ce.DTMF_TRANSPORT.RFC2833){const g=this._getDTMFRTPSender();g&&(s=g.toneBuffer+s,g.insertDTMF(s,a,_));return}if(this._tones){this._tones+=s;return}this._tones=s,p.call(this);function p(){let g;if(this._status===te.STATUS_TERMINATED||!this._tones||l>=this._tones.length){this._tones=null;return}const n=this._tones[l];if(l+=1,n===",")g=2e3;else{const v=new $t(this);i.eventHandlers={onFailed:()=>{this._tones=null}},v.send(n,i),g=a+_}setTimeout(p.bind(this),g)}}sendInfo(s,i,l={}){if(z.debug("sendInfo()"),this._status!==te.STATUS_CONFIRMED&&this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_1XX_RECEIVED)throw new bn.InvalidStateError(this._status);new Ef(this).send(s,i,l)}mute(s={audio:!0,video:!1}){z.debug("mute()");let i=!1,l=!1;this._audioMuted===!1&&s.audio&&(i=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&s.video&&(l=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(i===!0||l===!0)&&this._onmute({audio:i,video:l})}unmute(s={audio:!0,video:!0}){z.debug("unmute()");let i=!1,l=!1;this._audioMuted===!0&&s.audio&&(i=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&s.video&&(l=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(i===!0||l===!0)&&this._onunmute({audio:i,video:l})}hold(s={},i){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 l={succeeded:()=>{i&&i()},failed:()=>{this.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:l,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:l,extraHeaders:s.extraHeaders}),!0}unhold(s={},i){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 l={succeeded:()=>{i&&i()},failed:()=>{this.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:l,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:l,extraHeaders:s.extraHeaders}),!0}renegotiate(s={},i){z.debug("renegotiate()");const l=s.rtcOfferConstraints||null;if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const a={succeeded:()=>{i&&i()},failed:()=>{this.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,rtcOfferConstraints:l,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:a,rtcOfferConstraints:l,extraHeaders:s.extraHeaders}),!0}refer(s,i){z.debug("refer()");const l=s;if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;if(s=this._ua.normalizeTarget(s),!s)throw new TypeError(`Invalid target: ${l}`);const a=new Mg(this);a.sendRefer(s,i);const _=a.id;return this._referSubscribers[_]=a,a.on("requestFailed",()=>{delete this._referSubscribers[_]}),a.on("accepted",()=>{delete this._referSubscribers[_]}),a.on("failed",()=>{delete this._referSubscribers[_]}),a}sendRequest(s,i){return z.debug("sendRequest()"),this._dialog.sendRequest(s,i)}receiveRequest(s){if(z.debug("receiveRequest()"),s.method===ce.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",s,ce.causes.CANCELED));else switch(s.method){case ce.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(!s.body){this.terminate({cause:ce.causes.MISSING_SDP,status_code:400});break}const i={originator:"remote",type:"answer",sdp:s.body};z.debug('emit "sdp"'),this.emit("sdp",i);const l=new RTCSessionDescription({type:"answer",sdp:i.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(l)).then(()=>{this._is_confirmed||this._confirmed("remote",s)}).catch(a=>{this.terminate({cause:ce.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})}else this._is_confirmed||this._confirmed("remote",s);break;case ce.BYE:this._status===te.STATUS_CONFIRMED||this._status===te.STATUS_WAITING_FOR_ACK?(s.reply(200),this._ended("remote",s,ce.causes.BYE)):this._status===te.STATUS_INVITE_RECEIVED||this._status===te.STATUS_WAITING_FOR_ANSWER?(s.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",s,ce.causes.BYE)):s.reply(403,"Wrong Status");break;case ce.INVITE:this._status===te.STATUS_CONFIRMED?s.hasHeader("replaces")?this._receiveReplaces(s):this._receiveReinvite(s):s.reply(403,"Wrong Status");break;case ce.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 i=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0;i&&i.match(/^application\/dtmf-relay/i)?new $t(this).init_incoming(s):i!==void 0?new Ef(this).init_incoming(s):s.reply(415)}else s.reply(403,"Wrong Status");break;case ce.UPDATE:this._status===te.STATUS_CONFIRMED?this._receiveUpdate(s):s.reply(403,"Wrong Status");break;case ce.REFER:this._status===te.STATUS_CONFIRMED?this._receiveRefer(s):s.reply(403,"Wrong Status");break;case ce.NOTIFY:this._status===te.STATUS_CONFIRMED?this._receiveNotify(s):s.reply(403,"Wrong Status");break;default:s.reply(501)}}onTransportError(){z.warn("onTransportError()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ce.causes.CONNECTION_ERROR,cause:ce.causes.CONNECTION_ERROR})}onRequestTimeout(){z.warn("onRequestTimeout()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:ce.causes.REQUEST_TIMEOUT,cause:ce.causes.REQUEST_TIMEOUT})}onDialogError(){z.warn("onDialogError()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:ce.causes.DIALOG_ERROR,cause:ce.causes.DIALOG_ERROR})}newDTMF(s){z.debug("newDTMF()"),this.emit("newDTMF",s)}newInfo(s){z.debug("newInfo()"),this.emit("newInfo",s)}_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"),Je.closeMediaStream(this._localMediaStream)),this._status!==te.STATUS_TERMINATED){if(this._status=te.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(s){z.warn("close() | error closing the RTCPeerConnection: %o",s)}for(const s in this._timers)Object.prototype.hasOwnProperty.call(this._timers,s)&&clearTimeout(this._timers[s]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const s in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,s)&&(this._earlyDialogs[s].terminate(),delete this._earlyDialogs[s]);for(const s in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,s)&&delete this._referSubscribers[s];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(s,i){let l=Hi.T1;function a(){this._status===te.STATUS_WAITING_FOR_ACK&&(s.reply(200,null,[`Contact: ${this._contact}`],i),l<Hi.T2&&(l=l*2,l>Hi.T2&&(l=Hi.T2)),this._timers.invite2xxTimer=setTimeout(a.bind(this),l))}this._timers.invite2xxTimer=setTimeout(a.bind(this),l)}_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(ce.BYE),this._ended("remote",null,ce.causes.NO_ACK))},Hi.TIMER_H)}_createRTCConnection(s,i){this._connection=new RTCPeerConnection(s,i),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:ce.causes.RTP_TIMEOUT,status_code:408,reason_phrase:ce.causes.RTP_TIMEOUT})}),z.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(s,i){if(z.debug("createLocalDescription()"),s!=="offer"&&s!=="answer")throw new Error(`createLocalDescription() | invalid type "${s}"`);const l=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>s==="offer"?l.createOffer(i).catch(a=>(z.warn('emit "peerconnection:createofferfailed" [error:%o]',a),this.emit("peerconnection:createofferfailed",a),Promise.reject(a))):l.createAnswer(i).catch(a=>(z.warn('emit "peerconnection:createanswerfailed" [error:%o]',a),this.emit("peerconnection:createanswerfailed",a),Promise.reject(a)))).then(a=>l.setLocalDescription(a).catch(_=>(this._rtcReady=!0,z.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',_),this.emit("peerconnection:setlocaldescriptionfailed",_),Promise.reject(_)))).then(()=>{const a=i&&i.iceRestart;if(l.iceGatheringState==="complete"&&!a||l.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const _={originator:"local",type:s,sdp:l.localDescription.sdp};return z.debug('emit "sdp"'),this.emit("sdp",_),Promise.resolve(_.sdp)}return new Promise(_=>{let e=!1,p,g;this._iceReady=!1;const n=()=>{l.removeEventListener("icecandidate",p),l.removeEventListener("icegatheringstatechange",g),e=!0,this._rtcReady=!0,this._iceReady=!0;const v={originator:"local",type:s,sdp:l.localDescription.sdp};z.debug('emit "sdp"'),this.emit("sdp",v),_(v.sdp)};l.addEventListener("icecandidate",p=v=>{const S=v.candidate;S?this.emit("icecandidate",{candidate:S,ready:n}):e||n()}),l.addEventListener("icegatheringstatechange",g=()=>{l.iceGatheringState==="complete"&&!e&&n()})})})}_createDialog(s,i,l){const a=i==="UAS"?s.to_tag:s.from_tag,_=i==="UAS"?s.from_tag:s.to_tag,e=s.call_id+a+_;let p=this._earlyDialogs[e];if(l)return p?!0:(p=new oa(this,s,i,oa.C.STATUS_EARLY),p.error?(z.debug(p.error),this._failed("remote",s,ce.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[e]=p,!0));{if(this._from_tag=s.from_tag,this._to_tag=s.to_tag,p)return p.update(s,i),this._dialog=p,delete this._earlyDialogs[e],!0;const g=new oa(this,s,i);return g.error?(z.debug(g.error),this._failed("remote",s,ce.causes.INTERNAL_ERROR),!1):(this._dialog=g,!0)}}_receiveReinvite(s){z.debug("receiveReinvite()");const i=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0,l={request:s,callback:void 0,reject:_.bind(this)};let a=!1;function _(p={}){a=!0;const g=p.status_code||403,n=p.reason_phrase||"",v=Je.cloneArray(p.extraHeaders);if(this._status!==te.STATUS_CONFIRMED)return!1;if(g<300||g>=700)throw new TypeError(`Invalid status_code: ${g}`);s.reply(g,n,v)}if(this.emit("reinvite",l),a)return;if(this._late_sdp=!1,!s.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(p=>{e.call(this,p)}).catch(()=>{s.reply(500)});return}if(i!=="application/sdp"){z.debug("invalid Content-Type"),s.reply(415);return}this._processInDialogSdpOffer(s).then(p=>{this._status!==te.STATUS_TERMINATED&&e.call(this,p)}).catch(p=>{z.warn(p)});function e(p){const g=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(s,g),this._late_sdp&&(p=this._mangleOffer(p)),s.reply(200,null,g,p,()=>{this._status=te.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(s,p),this._setACKTimer()}),typeof l.callback=="function"&&l.callback()}}_receiveUpdate(s){z.debug("receiveUpdate()");const i=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0,l={request:s,callback:void 0,reject:_.bind(this)};let a=!1;function _(p={}){a=!0;const g=p.status_code||403,n=p.reason_phrase||"",v=Je.cloneArray(p.extraHeaders);if(this._status!==te.STATUS_CONFIRMED)return!1;if(g<300||g>=700)throw new TypeError(`Invalid status_code: ${g}`);s.reply(g,n,v)}if(this.emit("update",l),a)return;if(!s.body){e.call(this,null);return}if(i!=="application/sdp"){z.debug("invalid Content-Type"),s.reply(415);return}this._processInDialogSdpOffer(s).then(p=>{this._status!==te.STATUS_TERMINATED&&e.call(this,p)}).catch(p=>{z.warn(p)});function e(p){const g=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(s,g),s.reply(200,null,g,p),typeof l.callback=="function"&&l.callback()}}_processInDialogSdpOffer(s){z.debug("_processInDialogSdpOffer()");const i=s.parseSDP();let l=!1;for(const e of i.media){if(ua.indexOf(e.type)===-1)continue;const p=e.direction||i.direction||"sendrecv";if(p==="sendonly"||p==="inactive")l=!0;else{l=!1;break}}const a={originator:"remote",type:"offer",sdp:s.body};z.debug('emit "sdp"'),this.emit("sdp",a);const _=new RTCSessionDescription({type:"offer",sdp:a.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(_).catch(e=>{throw s.reply(488),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),this.emit("peerconnection:setremotedescriptionfailed",e),e})}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&l===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&l===!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(e=>{throw s.reply(500),z.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',e),e})}).catch(e=>{z.warn("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}_receiveRefer(s){if(z.debug("receiveRefer()"),!s.refer_to){z.debug("no Refer-To header field present in REFER"),s.reply(400);return}if(s.refer_to.uri.scheme!==ce.SIP){z.debug("Refer-To header field points to a non-SIP URI scheme"),s.reply(416);return}s.reply(202);const i=new xg(this,s.cseq);z.debug('emit "refer"'),this.emit("refer",{request:s,accept:(_,e)=>{l.call(this,_,e)},reject:()=>{a.call(this)}});function l(_,e={}){if(_=typeof _=="function"?_:null,this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;const p=new Au(this._ua);if(p.on("progress",({response:g})=>{i.notify(g.status_code,g.reason_phrase)}),p.on("accepted",({response:g})=>{i.notify(g.status_code,g.reason_phrase)}),p.on("_failed",({message:g,cause:n})=>{g?i.notify(g.status_code,g.reason_phrase):i.notify(487,n)}),s.refer_to.uri.hasHeader("replaces")){const g=decodeURIComponent(s.refer_to.uri.getHeader("replaces"));e.extraHeaders=Je.cloneArray(e.extraHeaders),e.extraHeaders.push(`Replaces: ${g}`)}p.connect(s.refer_to.uri.toAor(),e,_)}function a(){i.notify(603)}}_receiveNotify(s){switch(z.debug("receiveNotify()"),s.event||s.reply(400),s.event.event){case"refer":{let i,l;if(s.event.params&&s.event.params.id)i=s.event.params.id,l=this._referSubscribers[i];else if(Object.keys(this._referSubscribers).length===1)l=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{s.reply(400,"Missing event id parameter");return}if(!l){s.reply(481,"Subscription does not exist");return}l.receiveNotify(s),s.reply(200);break}default:s.reply(489)}}_receiveReplaces(s){z.debug("receiveReplaces()");function i(a){if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;const _=new Au(this._ua);_.on("confirmed",()=>{this.terminate()}),_.init_incoming(s,a)}function l(){z.debug("Replaced INVITE rejected by the user"),s.reply(486)}this.emit("replaces",{request:s,accept:a=>{i.call(this,a)},reject:()=>{l.call(this)}})}_sendInitialRequest(s,i,l){const a=new Pg(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:_=>{this._request=_},onReceiveResponse:_=>{this._receiveInviteResponse(_)}});Promise.resolve().then(()=>{if(l)return l;if(s.audio||s.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(s).catch(_=>{throw this._status===te.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),z.warn('emit "getusermediafailed" [error:%o]',_),this.emit("getusermediafailed",_),_)})}).then(_=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=_,_&&_.getTracks().forEach(e=>{this._connection.addTrack(e,_)}),this._connecting(this._request),this._createLocalDescription("offer",i).catch(e=>{throw this._failed("local",null,ce.causes.WEBRTC_ERROR),e})}).then(_=>{if(this._is_canceled||this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._request.body=_,this._status=te.STATUS_INVITE_SENT,z.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),a.send()}).catch(_=>{this._status!==te.STATUS_TERMINATED&&z.warn(_)})}_getDTMFRTPSender(){const s=this._connection.getSenders().find(i=>i.track&&i.track.kind==="audio");if(!(s&&s.dtmf)){z.warn("sendDTMF() | no local audio track to send DTMF with");return}return s.dtmf}_receiveInviteResponse(s){if(z.debug("receiveInviteResponse()"),this._dialog&&s.status_code>=200&&s.status_code<=299)if(this._dialog.id.call_id===s.call_id&&this._dialog.id.local_tag===s.from_tag&&this._dialog.id.remote_tag===s.to_tag){this.sendRequest(ce.ACK);return}else{const i=new oa(this,s,"UAC");if(i.error!==void 0){z.debug(i.error);return}this.sendRequest(ce.ACK),this.sendRequest(ce.BYE);return}if(this._is_canceled){s.status_code>=100&&s.status_code<200?this._request.cancel(this._cancel_reason):s.status_code>=200&&s.status_code<299&&this._acceptAndTerminate(s);return}if(!(this._status!==te.STATUS_INVITE_SENT&&this._status!==te.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(s.status_code):this._status=te.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(s.status_code):{if(!s.to_tag){z.debug("1xx response received without to tag");break}if(s.hasHeader("contact")&&!this._createDialog(s,"UAC",!0))break;if(this._status=te.STATUS_1XX_RECEIVED,!s.body){this._progress("remote",s);break}const i={originator:"remote",type:"answer",sdp:s.body};z.debug('emit "sdp"'),this.emit("sdp",i);const l=new RTCSessionDescription({type:"answer",sdp:i.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(l)).then(()=>this._progress("remote",s)).catch(a=>{z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)});break}case/^2[0-9]{2}$/.test(s.status_code):{if(this._status=te.STATUS_CONFIRMED,!s.body){this._acceptAndTerminate(s,400,ce.causes.MISSING_SDP),this._failed("remote",s,ce.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(s,"UAC"))break;const i={originator:"remote",type:"answer",sdp:s.body};z.debug('emit "sdp"'),this.emit("sdp",i);const l=new RTCSessionDescription({type:"answer",sdp:i.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(s,500,a.toString()),this._failed("local",s,ce.causes.WEBRTC_ERROR)})}).then(()=>{this._connection.setRemoteDescription(l).then(()=>{this._handleSessionTimersInIncomingResponse(s),this._accepted("remote",s),this.sendRequest(ce.ACK),this._confirmed("local",null)}).catch(a=>{this._acceptAndTerminate(s,488,"Not Acceptable Here"),this._failed("remote",s,ce.causes.BAD_MEDIA_DESCRIPTION),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})});break}default:{const i=Je.sipErrorCause(s.status_code);this._failed("remote",s,i)}}}_sendReinvite(s={}){z.debug("sendReinvite()");const i=Je.cloneArray(s.extraHeaders),l=Je.cloneObject(s.eventHandlers),a=s.rtcOfferConstraints||this._rtcOfferConstraints||null;let _=!1;i.push(`Contact: ${this._contact}`),i.push("Content-Type: application/sdp"),this._sessionTimers.running&&i.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",a)).then(g=>{g=this._mangleOffer(g);const n={originator:"local",type:"offer",sdp:g};z.debug('emit "sdp"'),this.emit("sdp",n),this.sendRequest(ce.INVITE,{extraHeaders:i,body:g,eventHandlers:{onSuccessResponse:v=>{e.call(this,v),_=!0},onErrorResponse:v=>{p.call(this,v)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{p()});function e(g){if(this._status===te.STATUS_TERMINATED||(this.sendRequest(ce.ACK),_))return;if(this._handleSessionTimersInIncomingResponse(g),g.body){if(!g.hasHeader("Content-Type")||g.getHeader("Content-Type").toLowerCase()!=="application/sdp"){p.call(this);return}}else{p.call(this);return}const n={originator:"remote",type:"answer",sdp:g.body};z.debug('emit "sdp"'),this.emit("sdp",n);const v=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(v)).then(()=>{l.succeeded&&l.succeeded(g)}).catch(S=>{p.call(this),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',S),this.emit("peerconnection:setremotedescriptionfailed",S)})}function p(g){l.failed&&l.failed(g)}}_sendUpdate(s={}){z.debug("sendUpdate()");const i=Je.cloneArray(s.extraHeaders),l=Je.cloneObject(s.eventHandlers),a=s.rtcOfferConstraints||this._rtcOfferConstraints||null,_=s.sdpOffer||!1;let e=!1;i.push(`Contact: ${this._contact}`),this._sessionTimers.running&&i.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),_?(i.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",a)).then(n=>{n=this._mangleOffer(n);const v={originator:"local",type:"offer",sdp:n};z.debug('emit "sdp"'),this.emit("sdp",v),this.sendRequest(ce.UPDATE,{extraHeaders:i,body:n,eventHandlers:{onSuccessResponse:S=>{p.call(this,S),e=!0},onErrorResponse:S=>{g.call(this,S)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{g.call(this)})):this.sendRequest(ce.UPDATE,{extraHeaders:i,eventHandlers:{onSuccessResponse:n=>{p.call(this,n)},onErrorResponse:n=>{g.call(this,n)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function p(n){if(this._status!==te.STATUS_TERMINATED&&!e)if(this._handleSessionTimersInIncomingResponse(n),_){if(n.body){if(!n.hasHeader("Content-Type")||n.getHeader("Content-Type").toLowerCase()!=="application/sdp"){g.call(this);return}}else{g.call(this);return}const v={originator:"remote",type:"answer",sdp:n.body};z.debug('emit "sdp"'),this.emit("sdp",v);const S=new RTCSessionDescription({type:"answer",sdp:v.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(S)).then(()=>{l.succeeded&&l.succeeded(n)}).catch(m=>{g.call(this),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',m),this.emit("peerconnection:setremotedescriptionfailed",m)})}else l.succeeded&&l.succeeded(n)}function g(n){l.failed&&l.failed(n)}}_acceptAndTerminate(s,i,l){z.debug("acceptAndTerminate()");const a=[];i&&(l=l||ce.REASON_PHRASE[i]||"",a.push(`Reason: SIP ;cause=${i}; text="${l}"`)),(this._dialog||this._createDialog(s,"UAC"))&&(this.sendRequest(ce.ACK),this.sendRequest(ce.BYE,{extraHeaders:a})),this._status=te.STATUS_TERMINATED}_mangleOffer(s){if(!this._localHold&&!this._remoteHold)return s;if(s=Tf.parse(s),this._localHold&&!this._remoteHold){z.debug("mangleOffer() | me on hold, mangling offer");for(const i of s.media)ua.indexOf(i.type)!==-1&&(i.direction?i.direction==="sendrecv"?i.direction="sendonly":i.direction==="recvonly"&&(i.direction="inactive"):i.direction="sendonly")}else if(this._localHold&&this._remoteHold){z.debug("mangleOffer() | both on hold, mangling offer");for(const i of s.media)ua.indexOf(i.type)!==-1&&(i.direction="inactive")}else if(this._remoteHold){z.debug("mangleOffer() | remote on hold, mangling offer");for(const i of s.media)ua.indexOf(i.type)!==-1&&(i.direction?i.direction==="sendrecv"?i.direction="recvonly":i.direction==="recvonly"&&(i.direction="inactive"):i.direction="recvonly")}return Tf.write(s)}_setLocalMediaStatus(){let s=!0,i=!0;(this._localHold||this._remoteHold)&&(s=!1,i=!1),this._audioMuted&&(s=!1),this._videoMuted&&(i=!1),this._toggleMuteAudio(!s),this._toggleMuteVideo(!i)}_handleSessionTimersInIncomingRequest(s,i){if(!this._sessionTimers.enabled)return;let l;s.session_expires&&s.session_expires>=ce.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=s.session_expires,l=s.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,l="uas"),i.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${l}`),this._sessionTimers.refresher=l==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(s){if(!this._sessionTimers.enabled)return;let i;s.session_expires&&s.session_expires>=ce.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=s.session_expires,i=s.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,i="uac"),this._sessionTimers.refresher=i==="uac",this._runSessionTimer()}_runSessionTimer(){const s=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===ce.UPDATE?this._sendUpdate():this._sendReinvite())},s*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==te.STATUS_TERMINATED&&(z.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:ce.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},s*1100)}_toggleMuteAudio(s){const i=this._connection.getSenders().filter(l=>l.track&&l.track.kind==="audio");for(const l of i)l.track.enabled=!s}_toggleMuteVideo(s){const i=this._connection.getSenders().filter(l=>l.track&&l.track.kind==="video");for(const l of i)l.track.enabled=!s}_newRTCSession(s,i){z.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:s,session:this,request:i})}_connecting(s){z.debug("session connecting"),z.debug('emit "connecting"'),this.emit("connecting",{request:s})}_progress(s,i){z.debug("session progress"),z.debug('emit "progress"'),this.emit("progress",{originator:s,response:i||null})}_accepted(s,i){z.debug("session accepted"),this._start_time=new Date,z.debug('emit "accepted"'),this.emit("accepted",{originator:s,response:i||null})}_confirmed(s,i){z.debug("session confirmed"),this._is_confirmed=!0,z.debug('emit "confirmed"'),this.emit("confirmed",{originator:s,ack:i||null})}_ended(s,i,l){z.debug("session ended"),this._end_time=new Date,this._close(),z.debug('emit "ended"'),this.emit("ended",{originator:s,message:i||null,cause:l})}_failed(s,i,l){z.debug("session failed"),z.debug('emit "_failed"'),this.emit("_failed",{originator:s,message:i||null,cause:l}),this._close(),z.debug('emit "failed"'),this.emit("failed",{originator:s,message:i||null,cause:l})}_onhold(s){z.debug("session onhold"),this._setLocalMediaStatus(),z.debug('emit "hold"'),this.emit("hold",{originator:s})}_onunhold(s){z.debug("session onunhold"),this._setLocalMediaStatus(),z.debug('emit "unhold"'),this.emit("unhold",{originator:s})}_onmute({audio:s,video:i}){z.debug("session onmute"),this._setLocalMediaStatus(),z.debug('emit "muted"'),this.emit("muted",{audio:s,video:i})}_onunmute({audio:s,video:i}){z.debug("session onunmute"),this._setLocalMediaStatus(),z.debug('emit "unmuted"'),this.emit("unmuted",{audio:s,video:i})}};const kg=tt(y_),Lg=ht.EventEmitter,$g=ut,Wo=Me,Hg=Dt,Fi=Ct(),Fg=fr,yf=bs,jg=Is(),ca=new $g("Message");var qg=class extends Lg{constructor(s){super(),this._ua=s,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(s,i,l={}){const a=s;if(s===void 0||i===void 0)throw new TypeError("Not enough arguments");if(s=this._ua.normalizeTarget(s),!s)throw new TypeError(`Invalid target: ${a}`);const _=Fi.cloneArray(l.extraHeaders),e=Fi.cloneObject(l.eventHandlers),p=l.contentType||"text/plain",g={};l.fromUserName&&(g.from_uri=new jg("sip",l.fromUserName,this._ua.configuration.uri.host),_.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),l.fromDisplayName&&(g.from_display_name=l.fromDisplayName);for(const v in e)Object.prototype.hasOwnProperty.call(e,v)&&this.on(v,e[v]);_.push(`Content-Type: ${p}`),this._request=new Hg.OutgoingRequest(Wo.MESSAGE,s,this._ua,g,_),i&&(this._request.body=i);const n=new Fg(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:v=>{this._receiveResponse(v)}});this._newMessage("local",this._request),n.send()}init_incoming(s){this._request=s,this._newMessage("remote",s),this._is_replied||(this._is_replied=!0,s.reply(200)),this._close()}accept(s={}){const i=Fi.cloneArray(s.extraHeaders),l=s.body;if(this._direction!=="incoming")throw new yf.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,i,l)}reject(s={}){const i=s.status_code||480,l=s.reason_phrase,a=Fi.cloneArray(s.extraHeaders),_=s.body;if(this._direction!=="incoming")throw new yf.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(i<300||i>=700)throw new TypeError(`Invalid status_code: ${i}`);this._is_replied=!0,this._request.reply(i,l,a,_)}_receiveResponse(s){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(s.status_code):break;case/^2[0-9]{2}$/.test(s.status_code):this._succeeded("remote",s);break;default:{const i=Fi.sipErrorCause(s.status_code);this._failed("remote",s,i);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,Wo.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,Wo.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newMessage(s,i){s==="remote"?(this._direction="incoming",this._local_identity=i.to,this._remote_identity=i.from):s==="local"&&(this._direction="outgoing",this._local_identity=i.from,this._remote_identity=i.to),this._ua.newMessage(this,{originator:s,message:this,request:i})}_failed(s,i,l){ca.debug("MESSAGE failed"),this._close(),ca.debug('emit "failed"'),this.emit("failed",{originator:s,response:i||null,cause:l})}_succeeded(s,i){ca.debug("MESSAGE succeeded"),this._close(),ca.debug('emit "succeeded"'),this.emit("succeeded",{originator:s,response:i})}};const Vg=ht.EventEmitter,Bg=ut,Ko=Me,Gg=Dt,ji=Ct(),Wg=fr,Af=bs,fa=new Bg("Options");var Kg=class extends Vg{constructor(s){super(),this._ua=s,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(s,i,l={}){const a=s;if(s===void 0)throw new TypeError("A target is required for OPTIONS");if(s=this._ua.normalizeTarget(s),!s)throw new TypeError(`Invalid target: ${a}`);const _=ji.cloneArray(l.extraHeaders),e=ji.cloneObject(l.eventHandlers),p=l.contentType||"application/sdp";for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&this.on(n,e[n]);_.push(`Content-Type: ${p}`),this._request=new Gg.OutgoingRequest(Ko.OPTIONS,s,this._ua,null,_),i&&(this._request.body=i);const g=new Wg(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:n=>{this._receiveResponse(n)}});this._newOptions("local",this._request),g.send()}init_incoming(s){this._request=s,this._newOptions("remote",s),this._is_replied||(this._is_replied=!0,s.reply(200)),this._close()}accept(s={}){const i=ji.cloneArray(s.extraHeaders),l=s.body;if(this._direction!=="incoming")throw new Af.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,i,l)}reject(s={}){const i=s.status_code||480,l=s.reason_phrase,a=ji.cloneArray(s.extraHeaders),_=s.body;if(this._direction!=="incoming")throw new Af.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(i<300||i>=700)throw new TypeError(`Invalid status_code: ${i}`);this._is_replied=!0,this._request.reply(i,l,a,_)}_receiveResponse(s){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(s.status_code):break;case/^2[0-9]{2}$/.test(s.status_code):this._succeeded("remote",s);break;default:{const i=ji.sipErrorCause(s.status_code);this._failed("remote",s,i);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,Ko.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,Ko.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newOptions(s,i){s==="remote"?(this._direction="incoming",this._local_identity=i.to,this._remote_identity=i.from):s==="local"&&(this._direction="outgoing",this._local_identity=i.from,this._remote_identity=i.to),this._ua.newOptions(this,{originator:s,message:this,request:i})}_failed(s,i,l){fa.debug("OPTIONS failed"),this._close(),fa.debug('emit "failed"'),this.emit("failed",{originator:s,response:i||null,cause:l})}_succeeded(s,i){fa.debug("OPTIONS succeeded"),this._close(),fa.debug('emit "succeeded"'),this.emit("succeeded",{originator:s,response:i})}},qu={};const Yg=ut,Yo=Ct(),Jg=Qt(),qi=new Yg("Socket");qu.isSocket=c=>{if(Array.isArray(c))return!1;if(typeof c>"u")return qi.warn("undefined JsSIP.Socket instance"),!1;try{if(!Yo.isString(c.url))throw qi.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!Yo.isString(c.via_transport))throw qi.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(Jg.parse(c.sip_uri,"SIP_URI")===-1)throw qi.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(s=>{if(!Yo.isFunction(c[s]))throw qi.warn(`missing or invalid JsSIP.Socket method: ${s}`),new Error(`Missing or invalid JsSIP.Socket method: ${s}`)})}catch{return!1}return!0};const zg=ut,Xg=qu,Cf=Me,Mt=new zg("Transport"),jt={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:Cf.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:Cf.CONNECTION_RECOVERY_MAX_INTERVAL}};var A_=class{constructor(s,i=jt.recovery_options){Mt.debug("new()"),this.status=jt.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=i,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(l){Mt.warn(`cannot use TextDecoder: ${l}`)}if(typeof s>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");s instanceof Array||(s=[s]),s.forEach(function(l){if(!Xg.isSocket(l.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(l.weight&&!Number(l.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:l.socket,weight:l.weight||0,status:jt.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(Mt.debug("connect()"),this.isConnected()){Mt.debug("Transport is already connected");return}else if(this.isConnecting()){Mt.debug("Transport is connecting");return}this.close_requested=!1,this.status=jt.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(){Mt.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=jt.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(s){if(Mt.debug("send()"),!this.isConnected())return Mt.warn("unable to send message, transport is not connected"),!1;const i=s.toString();return Mt.debug(`sending message:
116
116
 
117
- ${r}
118
- `),this.socket.send(r)}isConnected(){return this.status===qt.STATUS_CONNECTED}isConnecting(){return this.status===qt.STATUS_CONNECTING}_reconnect(){this.recover_attempts+=1;let s=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);s<this.recovery_options.min_interval?s=this.recovery_options.min_interval:s>this.recovery_options.max_interval&&(s=this.recovery_options.max_interval),Ut.debug(`reconnection attempt: ${this.recover_attempts}. next connection attempt in ${s} seconds`),this.recovery_timer=setTimeout(()=>{!this.close_requested&&!(this.isConnected()||this.isConnecting())&&(this._getSocket(),this.connect())},s*1e3)}_getSocket(){let s=[];if(this.sockets.forEach(o=>{o.status!==qt.SOCKET_STATUS_ERROR&&(s.length===0?s.push(o):o.weight>s[0].weight?s=[o]:o.weight===s[0].weight&&s.push(o))}),s.length===0){this.sockets.forEach(o=>{o.status=qt.SOCKET_STATUS_READY}),this._getSocket();return}const r=Math.floor(Math.random()*s.length);this.socket=s[r].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(s,r,o){this.status=qt.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:s,code:r,reason:o}),!this.close_requested&&(this.sockets.forEach(function(a){this.socket===a.socket&&(a.status=qt.SOCKET_STATUS_ERROR)},this),this._reconnect(s))}_onData(s){if(s===`\r
119
- `){Ut.debug("received message with CRLF Keep Alive response");return}else if(typeof s!="string"){try{this.textDecoder?s=this.textDecoder.decode(s):s=String.fromCharCode.apply(null,new Uint8Array(s))}catch{Ut.debug("received binary message failed to be converted into string, message discarded");return}Ut.debug(`received binary message:
117
+ ${i}
118
+ `),this.socket.send(i)}isConnected(){return this.status===jt.STATUS_CONNECTED}isConnecting(){return this.status===jt.STATUS_CONNECTING}_reconnect(){this.recover_attempts+=1;let s=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);s<this.recovery_options.min_interval?s=this.recovery_options.min_interval:s>this.recovery_options.max_interval&&(s=this.recovery_options.max_interval),Mt.debug(`reconnection attempt: ${this.recover_attempts}. next connection attempt in ${s} seconds`),this.recovery_timer=setTimeout(()=>{!this.close_requested&&!(this.isConnected()||this.isConnecting())&&(this._getSocket(),this.connect())},s*1e3)}_getSocket(){let s=[];if(this.sockets.forEach(l=>{l.status!==jt.SOCKET_STATUS_ERROR&&(s.length===0?s.push(l):l.weight>s[0].weight?s=[l]:l.weight===s[0].weight&&s.push(l))}),s.length===0){this.sockets.forEach(l=>{l.status=jt.SOCKET_STATUS_READY}),this._getSocket();return}const i=Math.floor(Math.random()*s.length);this.socket=s[i].socket}_onConnect(){this.recover_attempts=0,this.status=jt.STATUS_CONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}_onDisconnect(s,i,l){this.status=jt.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:s,code:i,reason:l}),!this.close_requested&&(this.sockets.forEach(function(a){this.socket===a.socket&&(a.status=jt.SOCKET_STATUS_ERROR)},this),this._reconnect(s))}_onData(s){if(s===`\r
119
+ `){Mt.debug("received message with CRLF Keep Alive response");return}else if(typeof s!="string"){try{this.textDecoder?s=this.textDecoder.decode(s):s=String.fromCharCode.apply(null,new Uint8Array(s))}catch{Mt.debug("received binary message failed to be converted into string, message discarded");return}Mt.debug(`received binary message:
120
120
 
121
121
  ${s}
122
- `)}else Ut.debug(`received text message:
122
+ `)}else Mt.debug(`received text message:
123
123
 
124
124
  ${s}
125
- `);this.ondata({transport:this,message:s})}};const Kg=Xe(v_);var Hu={};const Yg=at,Eu=ls(),Su=It,so=new Yg("Parser");Hu.parseMessage=(c,s)=>{let r,o,a=c.indexOf(`\r
126
- `);if(a===-1){so.warn("parseMessage() | no CRLF found, not a SIP message");return}const t=c.substring(0,a);let n=Eu.parse(t,"Request_Response");if(n===-1){so.warn(`parseMessage() | error parsing first line of SIP message: "${t}"`);return}else n.status_code?(r=new Su.IncomingResponse,r.status_code=n.status_code,r.reason_phrase=n.reason_phrase):(r=new Su.IncomingRequest(s),r.method=n.method,r.ruri=n.uri);r.data=c;let d=a+2;for(;;){if(a=Jg(c,d),a===-2){o=d+2;break}else if(a===-1){so.warn("parseMessage() | malformed message");return}if(n=zg(r,c,d,a),n!==!0){so.warn("parseMessage() |",n.error);return}d=a+2}if(r.hasHeader("content-length")){const _=r.getHeader("content-length");r.body=c.substr(o,_)}else r.body=c.substring(o);return r};function Jg(c,s){let r=s,o=0,a=0;if(c.substring(r,r+2).match(/(^\r\n)/))return-2;for(;o===0;){if(a=c.indexOf(`\r
127
- `,r),a===-1)return a;!c.substring(a+2,a+4).match(/(^\r\n)/)&&c.charAt(a+2).match(/(^\s+)/)?r=a+2:o=a}return o}function zg(c,s,r,o){let a;const t=s.indexOf(":",r),n=s.substring(r,t).trim(),d=s.substring(t+1,o).trim();switch(n.toLowerCase()){case"via":case"v":c.addHeader("via",d),c.getHeaders("via").length===1?(a=c.parseHeader("Via"),a&&(c.via=a,c.via_branch=a.branch)):a=0;break;case"from":case"f":c.setHeader("from",d),a=c.parseHeader("from"),a&&(c.from=a,c.from_tag=a.getParam("tag"));break;case"to":case"t":c.setHeader("to",d),a=c.parseHeader("to"),a&&(c.to=a,c.to_tag=a.getParam("tag"));break;case"record-route":if(a=Eu.parse(d,"Record_Route"),a===-1)a=void 0;else for(const _ of a)c.addHeader("record-route",d.substring(_.possition,_.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=_.parsed;break;case"call-id":case"i":c.setHeader("call-id",d),a=c.parseHeader("call-id"),a&&(c.call_id=d);break;case"contact":case"m":if(a=Eu.parse(d,"Contact"),a===-1)a=void 0;else for(const _ of a)c.addHeader("contact",d.substring(_.possition,_.offset)),c.headers.Contact[c.getHeaders("contact").length-1].parsed=_.parsed;break;case"content-length":case"l":c.setHeader("content-length",d),a=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",d),a=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",d),a=c.parseHeader("cseq"),a&&(c.cseq=a.value),c instanceof Su.IncomingResponse&&(c.method=a.method);break;case"max-forwards":c.setHeader("max-forwards",d),a=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",d),a=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",d),a=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",d),a=c.parseHeader("session-expires"),a&&(c.session_expires=a.expires,c.session_expires_refresher=a.refresher);break;case"refer-to":case"r":c.setHeader("refer-to",d),a=c.parseHeader("refer-to"),a&&(c.refer_to=a);break;case"replaces":c.setHeader("replaces",d),a=c.parseHeader("replaces"),a&&(c.replaces=a);break;case"event":case"o":c.setHeader("event",d),a=c.parseHeader("event"),a&&(c.event=a);break;default:c.addHeader(n,d),a=0}return a===void 0?{error:`error parsing header "${n}"`}:!0}const Xg=at,E_=De,Sf=It,Fu=yt(),ju=new Xg("sanityCheck"),Qg=[oT],Zg=[tT,sT,nT,rT],eT=[iT,lT];let Fe,ss,S_;var y_=(c,s,r)=>{Fe=c,ss=s,S_=r;for(const o of Qg)if(o()===!1)return!1;if(Fe instanceof Sf.IncomingRequest){for(const o of Zg)if(o()===!1)return!1}else if(Fe instanceof Sf.IncomingResponse){for(const o of eT)if(o()===!1)return!1}return!0};function tT(){if(Fe.s("to").uri.scheme!=="sip")return Zi(416),!1}function sT(){if(!Fe.to_tag&&Fe.call_id.substr(0,5)===ss.configuration.jssip_id)return Zi(482),!1}function nT(){const c=Fu.str_utf8_length(Fe.body),s=Fe.getHeader("content-length");if(c<s)return Zi(400),!1}function rT(){const c=Fe.from_tag,s=Fe.call_id,r=Fe.cseq;let o;if(!Fe.to_tag)if(Fe.method===E_.INVITE){if(ss._transactions.ist[Fe.via_branch])return!1;for(const a in ss._transactions.ist)if(Object.prototype.hasOwnProperty.call(ss._transactions.ist,a)&&(o=ss._transactions.ist[a],o.request.from_tag===c&&o.request.call_id===s&&o.request.cseq===r))return Zi(482),!1}else{if(ss._transactions.nist[Fe.via_branch])return!1;for(const a in ss._transactions.nist)if(Object.prototype.hasOwnProperty.call(ss._transactions.nist,a)&&(o=ss._transactions.nist[a],o.request.from_tag===c&&o.request.call_id===s&&o.request.cseq===r))return Zi(482),!1}}function iT(){if(Fe.getHeaders("via").length>1)return ju.debug("more than one Via header field present in the response, dropping the response"),!1}function lT(){const c=Fu.str_utf8_length(Fe.body),s=Fe.getHeader("content-length");if(c<s)return ju.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}function oT(){const c=["from","to","call_id","cseq","via"];for(const s of c)if(!Fe.hasHeader(s))return ju.debug(`missing mandatory header field : ${s}, dropping the response`),!1}function Zi(c){const s=Fe.getHeaders("via");let r,o=`SIP/2.0 ${c} ${E_.REASON_PHRASE[c]}\r
128
- `;for(const a of s)o+=`Via: ${a}\r
129
- `;r=Fe.getHeader("To"),Fe.to_tag||(r+=`;tag=${Fu.newTag()}`),o+=`To: ${r}\r
130
- `,o+=`From: ${Fe.getHeader("From")}\r
131
- `,o+=`Call-ID: ${Fe.call_id}\r
132
- `,o+=`CSeq: ${Fe.cseq} ${Fe.method}\r
133
- `,o+=`\r
134
- `,S_.send(o)}const aT=Xe(y_);var el={};const ur=yt(),Sn=De,Ga=ls(),yf=Es(),Wa=$u,Ka=Ss;el.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:Sn.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:Sn.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:Sn.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:`${ur.createRandomToken(12)}.invalid`};const no={mandatory:{sockets(c){const s=[];if(Wa.isSocket(c))s.push({socket:c});else if(Array.isArray(c)&&c.length)for(const r of c)Object.prototype.hasOwnProperty.call(r,"socket")&&Wa.isSocket(r.socket)?s.push(r):Wa.isSocket(r)&&s.push({socket:r});else return;return s},uri(c){/^sip:/i.test(c)||(c=`${Sn.SIP}:${c}`);const s=yf.parse(c);if(s)return s.user?s:void 0}},optional:{authorization_user(c){if(Ga.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(ur.isDecimal(c)){const s=Number(c);if(s>0)return s}},connection_recovery_min_interval(c){if(ur.isDecimal(c)){const s=Number(c);if(s>0)return s}},contact_uri(c){if(typeof c=="string"){const s=Ga.parse(c,"SIP_URI");if(s!==-1)return s}},display_name(c){return c},instance_id(c){if(/^uuid:/i.test(c)&&(c=c.substr(5)),Ga.parse(c,"uuid")!==-1)return c},no_answer_timeout(c){if(ur.isDecimal(c)){const s=Number(c);if(s>0)return s}},session_timers(c){if(typeof c=="boolean")return c},session_timers_refresh_method(c){if(typeof c=="string"&&(c=c.toUpperCase(),c===Sn.INVITE||c===Sn.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(ur.isDecimal(c)){const s=Number(c);if(s>0)return s}},registrar_server(c){/^sip:/i.test(c)||(c=`${Sn.SIP}:${c}`);const s=yf.parse(c);if(s)return s.user?void 0:s},use_preloaded_route(c){if(typeof c=="boolean")return c},extra_headers(c){const s=[];if(Array.isArray(c)&&c.length)for(const r of c)typeof r=="string"&&s.push(r);else return;return s}}};el.load=(c,s)=>{for(const r in no.mandatory)if(s.hasOwnProperty(r)){const o=s[r],a=no.mandatory[r](o);if(a!==void 0)c[r]=a;else throw new Ka.ConfigurationError(r,o)}else throw new Ka.ConfigurationError(r);for(const r in no.optional)if(s.hasOwnProperty(r)){const o=s[r];if(ur.isEmpty(o))continue;const a=no.optional[r](o);if(a!==void 0)c[r]=a;else throw new Ka.ConfigurationError(r,o)}};const uT=ft.EventEmitter,cT=at,mt=De,fT=Zm,Af=T_,Cf=Lg,Rf=qg,Ya=pr,_T=v_,ro=yt(),hT=Ss,dT=Es(),pT=Hu,Ja=It,mT=y_,za=el,qe=new cT("UA"),vt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};var A_=class extends uT{static get C(){return vt}constructor(s){if(qe.debug("new() [configuration:%o]",s),super(),this._cache={credentials:{}},this._configuration=Object.assign({},za.settings),this._dynConfiguration={},this._dialogs={},this._applicants={},this._sessions={},this._transport=null,this._contact=null,this._status=vt.STATUS_INIT,this._error=null,this._transactions={nist:{},nict:{},ist:{},ict:{}},this._data={},this._closeTimer=null,s===void 0)throw new TypeError("Not enough arguments");try{this._loadConfig(s)}catch(r){throw this._status=vt.STATUS_NOT_READY,this._error=vt.CONFIGURATION_ERROR,r}this._registrator=new fT(this)}get C(){return vt}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===vt.STATUS_INIT?this._transport.connect():this._status===vt.STATUS_USER_CLOSED?(qe.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=vt.STATUS_INIT,this._transport.connect()):this._status===vt.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(s){qe.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(s)}registrator(){return this._registrator}isRegistered(){return this._registrator.registered}isConnected(){return this._transport.isConnected()}call(s,r){qe.debug("call()");const o=new Af(this);return o.connect(s,r),o}sendMessage(s,r,o){qe.debug("sendMessage()");const a=new Cf(this);return a.send(s,r,o),a}sendOptions(s,r,o){qe.debug("sendOptions()");const a=new Rf(this);return a.send(s,r,o),a}terminateSessions(s){qe.debug("terminateSessions()");for(const r in this._sessions)this._sessions[r].isEnded()||this._sessions[r].terminate(s)}stop(){if(qe.debug("stop()"),this._dynConfiguration={},this._status===vt.STATUS_USER_CLOSED){qe.debug("UA already closed");return}this._registrator.close();const s=Object.keys(this._sessions).length;for(const o in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,o)){qe.debug(`closing session ${o}`);try{this._sessions[o].terminate()}catch{}}for(const o in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,o))try{this._applicants[o].close()}catch{}this._status=vt.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&&s===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}normalizeTarget(s){return ro.normalizeTarget(s,this._configuration.hostport_params)}get(s){switch(s){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',s);return}}set(s,r){switch(s){case"authorization_user":{this._configuration.authorization_user=String(r);break}case"password":{this._configuration.password=String(r);break}case"realm":{this._configuration.realm=String(r);break}case"ha1":{this._configuration.ha1=String(r),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(r);break}case"display_name":{this._configuration.display_name=r;break}default:return qe.warn('set() | cannot set "%s" parameter in runtime',s),!1}return!0}newTransaction(s){this._transactions[s.type][s.id]=s,this.emit("newTransaction",{transaction:s})}destroyTransaction(s){delete this._transactions[s.type][s.id],this.emit("transactionDestroyed",{transaction:s})}newDialog(s){this._dialogs[s.id]=s}destroyDialog(s){delete this._dialogs[s.id]}newMessage(s,r){this._applicants[s]=s,this.emit("newMessage",r)}newOptions(s,r){this._applicants[s]=s,this.emit("newOptions",r)}destroyMessage(s){delete this._applicants[s]}newRTCSession(s,r){this._sessions[s.id]=s,this.emit("newRTCSession",r)}destroyRTCSession(s){delete this._sessions[s.id]}registered(s){this.emit("registered",s)}unregistered(s){this.emit("unregistered",s)}registrationFailed(s){this.emit("registrationFailed",s)}receiveRequest(s){const r=s.method;if(s.ruri.user!==this._configuration.uri.user&&s.ruri.user!==this._contact.uri.user){qe.debug("Request-URI does not point to us"),s.method!==mt.ACK&&s.reply_sl(404);return}if(s.ruri.scheme===mt.SIPS){s.reply_sl(416);return}if(Ya.checkTransaction(this,s))return;if(r===mt.INVITE?new Ya.InviteServerTransaction(this,this._transport,s):r!==mt.ACK&&r!==mt.CANCEL&&new Ya.NonInviteServerTransaction(this,this._transport,s),r===mt.OPTIONS){if(this.listeners("newOptions").length===0){s.reply(200);return}new Rf(this).init_incoming(s)}else if(r===mt.MESSAGE){if(this.listeners("newMessage").length===0){s.reply(405);return}new Cf(this).init_incoming(s)}else if(r===mt.INVITE&&!s.to_tag&&this.listeners("newRTCSession").length===0){s.reply(405);return}let o,a;if(s.to_tag)o=this._findDialog(s.call_id,s.from_tag,s.to_tag),o?o.receiveRequest(s):r===mt.NOTIFY?(a=this._findSession(s),a?a.receiveRequest(s):(qe.debug("received NOTIFY request for a non existent subscription"),s.reply(481,"Subscription does not exist"))):r!==mt.ACK&&s.reply(481);else switch(r){case mt.INVITE:if(window.RTCPeerConnection)if(s.hasHeader("replaces")){const t=s.replaces;o=this._findDialog(t.call_id,t.from_tag,t.to_tag),o?(a=o.owner,a.isEnded()?s.reply(603):a.receiveRequest(s)):s.reply(481)}else a=new Af(this),a.init_incoming(s);else qe.warn("INVITE received but WebRTC is not supported"),s.reply(488);break;case mt.BYE:s.reply(481);break;case mt.CANCEL:a=this._findSession(s),a?a.receiveRequest(s):qe.debug("received CANCEL request for a non existent session");break;case mt.ACK:break;case mt.NOTIFY:this.emit("sipEvent",{event:s.event,request:s}),s.reply(200);break;default:s.reply(405);break}}_findSession({call_id:s,from_tag:r,to_tag:o}){const a=s+r,t=this._sessions[a],n=s+o,d=this._sessions[n];return t||d||null}_findDialog(s,r,o){let a=s+r+o,t=this._dialogs[a];return t||(a=s+o+r,t=this._dialogs[a],t||null)}_loadConfig(s){try{za.load(this._configuration,s)}catch(a){throw a}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=ro.newUUID()),this._configuration.jssip_id=ro.createRandomToken(5);const r=this._configuration.uri.clone();r.user=null,this._configuration.hostport_params=r.toString().replace(/^sip:/i,"");try{this._transport=new _T(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=gT.bind(this),this._transport.onconnect=TT.bind(this),this._transport.ondisconnect=vT.bind(this),this._transport.ondata=ET.bind(this)}catch(a){throw qe.warn(a),new hT.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 a=this._configuration.uri.clone();a.user=null,a.clearParams(),a.clearHeaders(),this._configuration.registrar_server=a}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new dT("sip",ro.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(a={}){const t=a.anonymous||null,n=a.outbound||null;let d="<";return t?d+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":d+=this.pub_gruu||this.uri.toString(),n&&(t?!this.temp_gruu:!this.pub_gruu)&&(d+=";ob"),d+=">",d}};const o=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const a in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,a)&&(o.indexOf(a)!==-1?Object.defineProperty(this._configuration,a,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,a,{writable:!1,configurable:!1}));qe.debug("configuration parameters after validation:");for(const a in this._configuration)if(Object.prototype.hasOwnProperty.call(za.settings,a))switch(a){case"uri":case"registrar_server":qe.debug(`- ${a}: ${this._configuration[a]}`);break;case"password":case"ha1":case"authorization_jwt":qe.debug(`- ${a}: NOT SHOWN`);break;default:qe.debug(`- ${a}: ${JSON.stringify(this._configuration[a])}`)}}};function gT(c){this.emit("connecting",c)}function TT(c){this._status!==vt.STATUS_USER_CLOSED&&(this._status=vt.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function vT(c){const s=["nict","ict","nist","ist"];for(const r of s)for(const o in this._transactions[r])Object.prototype.hasOwnProperty.call(this._transactions[r],o)&&this._transactions[r][o].onTransportError();this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==vt.STATUS_USER_CLOSED&&(this._status=vt.STATUS_NOT_READY,this._error=vt.NETWORK_ERROR)}function ET(c){console.log("onTransportData",c);const s=c.transport;let r=c.message;if(r=pT.parseMessage(r,this),!!r&&!(this._status===vt.STATUS_USER_CLOSED&&r instanceof Ja.IncomingRequest)&&mT(r,this,s)){if(r instanceof Ja.IncomingRequest)r.transport=s,this.receiveRequest(r);else if(r instanceof Ja.IncomingResponse){let o;switch(r.method){case mt.INVITE:o=this._transactions.ict[r.via_branch],o&&o.receiveResponse(r);break;case mt.ACK:break;default:o=this._transactions.nict[r.via_branch],o&&o.receiveResponse(r);break}}}}const ST=Xe(A_);var dt=[];for(var Xa=0;Xa<256;++Xa)dt.push((Xa+256).toString(16).slice(1));function yT(c,s=0){return(dt[c[s+0]]+dt[c[s+1]]+dt[c[s+2]]+dt[c[s+3]]+"-"+dt[c[s+4]]+dt[c[s+5]]+"-"+dt[c[s+6]]+dt[c[s+7]]+"-"+dt[c[s+8]]+dt[c[s+9]]+"-"+dt[c[s+10]]+dt[c[s+11]]+dt[c[s+12]]+dt[c[s+13]]+dt[c[s+14]]+dt[c[s+15]]).toLowerCase()}var io,AT=new Uint8Array(16);function CT(){if(!io&&(io=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!io))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return io(AT)}var RT=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const If={randomUUID:RT};function bf(c,s,r){if(If.randomUUID&&!s&&!c)return If.randomUUID();c=c||{};var o=c.random||(c.rng||CT)();if(o[6]=o[6]&15|64,o[8]=o[8]&63|128,s){r=r||0;for(var a=0;a<16;++a)s[r+a]=o[a];return s}return yT(o)}var Me=yt();const ms=Xe(Me),Qa=new Pu("Dialog"),$s={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};class lo{static get C(){return $s}constructor(s,r,o,a=$s.STATUS_CONFIRMED){if(this._owner=s,this._ua=s._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,r instanceof It.IncomingResponse&&(a=r.status_code<200?$s.STATUS_EARLY:$s.STATUS_CONFIRMED),o==="UAS"){this._id={call_id:r.call_id,local_tag:r.to_tag,remote_tag:r.from_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._remote_seqnum=r.cseq,this._local_uri=r.parseHeader("to").uri,this._remote_uri=r.parseHeader("from").uri;let t=r.getHeaders("to")[0].split(";")[0];t=t.match(/<([^>]*)>/)[1],this._remote_target=t,this._route_set=r.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum}else if(o==="UAC"){this._id={call_id:r.call_id,local_tag:r.from_tag,remote_tag:r.to_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._local_seqnum=r.cseq,this._local_uri=r.parseHeader("from").uri,this._remote_uri=r.parseHeader("to").uri;let t=r.getHeaders("to")[0].split(";")[0];t=t.match(/<([^>]*)>/)[1],this._remote_target=t,this._route_set=r.getHeaders("record-route").reverse(),this._ack_seqnum=null}this._ua.newDialog(this),Qa.debug(`new ${o} dialog created with status ${this._state===$s.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(s){this._local_seqnum=s}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(s){this._uac_pending_reply=s}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===$s.STATUS_TERMINATED}update(s,r){this._state=$s.STATUS_CONFIRMED,Qa.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),r==="UAC"&&(this._route_set=s.getHeaders("record-route").reverse())}terminate(){Qa.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=$s.STATUS_TERMINATED}sendRequest(s,r={}){const o=ms.cloneArray(r.extraHeaders),a=ms.cloneObject(r.eventHandlers),t=r.body||null,n=this._createRequest(s,o,t);return a.onAuthenticated=()=>{this._local_seqnum+=1},new ig(this,n,a).send(),n}receiveRequest(s){this._checkInDialogRequest(s)&&(s.method===$.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:s.method===$.INVITE&&(this._ack_seqnum=s.cseq),this._owner.receiveRequest(s))}_createRequest(s,r,o){r=ms.cloneArray(r),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const a=s===$.CANCEL||s===$.ACK?this._local_seqnum:this._local_seqnum+=1;return new It.OutgoingRequest(s,this._remote_target,this._ua,{cseq:a,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},r,o)}_checkInDialogRequest(s){if(!this._remote_seqnum)this._remote_seqnum=s.cseq;else if(s.cseq<this._remote_seqnum)if(s.method===$.ACK){if(this._ack_seqnum===null||s.cseq!==this._ack_seqnum)return!1}else return s.reply(500),!1;else s.cseq>this._remote_seqnum&&(this._remote_seqnum=s.cseq);if(s.method===$.INVITE||s.method===$.UPDATE&&s.body){if(this._uac_pending_reply===!0)s.reply(491);else if(this._uas_pending_reply===!0){const r=(Math.random()*10|0)+1;return s.reply(500,null,[`Retry-After:${r}`]),!1}else{this._uas_pending_reply=!0;const r=()=>{(s.server_transaction.state===Bt.C.STATUS_ACCEPTED||s.server_transaction.state===Bt.C.STATUS_COMPLETED||s.server_transaction.state===Bt.C.STATUS_TERMINATED)&&(s.server_transaction.removeListener("stateChanged",r),this._uas_pending_reply=!1)};s.server_transaction.on("stateChanged",r)}s.hasHeader("contact")&&s.server_transaction.on("stateChanged",()=>{s.server_transaction.state===Bt.C.STATUS_ACCEPTED&&(this._remote_target=s.parseHeader("contact").uri)})}else s.method===$.NOTIFY&&s.hasHeader("contact")&&s.server_transaction.on("stateChanged",()=>{s.server_transaction.state===Bt.C.STATUS_COMPLETED&&(this._remote_target=s.parseHeader("contact").uri)});return!0}}class IT{constructor(s,r){Wt(this,"plugin",null);Wt(this,"rtcpPeer",null);Wt(this,"handleId",0);Wt(this,"info",null);Wt(this,"joinResult",null);Wt(this,"state",{});Wt(this,"stream",null);Wt(this,"loaded",!1);Wt(this,"aTracks",[]);Wt(this,"vTracks",[]);this.info=s,this.plugin=r,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(s){var r;this.state={...this.state,...s||{}},(r=this.plugin)==null||r.session.emit("member:update",this.memberInfo)}updateMemberStateFromMessage(s){var t,n,d,_;const r=(n=(t=s==null?void 0:s.plugindata)==null?void 0:t.data)==null?void 0:n.newStatePublisher,a=((_=(d=s==null?void 0:s.plugindata)==null?void 0:d.data)==null?void 0:_.publisher_state).find(h=>h.id===r);this.updateMemberState(a==null?void 0:a.state)}hangup(){this.rtcpPeer&&(this.rtcpPeer.close(),this.rtcpPeer=null),this.stream&&this.stream.getTracks().forEach(s=>{s.stop()})}}var bT=Es();const _r=Xe(bT),z=new Pu("JanusSession"),wT="/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},oo=["audio","video"];class ko extends ft.EventEmitter{static get C(){return te}constructor(s){z.debug("new"),super(),console.log("constructor call"),this._id=null,this._ua=s,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:$.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"}];const r=bf().replace(/-/g,"").slice(0,12);this.opaque_id=`videoroomtest-${r}`,this._data={}}get C(){return te}get causes(){return $.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(s){this._data=s}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}}connect(s,r,o={},a){z.debug("connect()"),this.display_name=r;const t=s,n=Me.cloneObject(o.eventHandlers),d=Me.cloneArray(o.extraHeaders),_=Me.cloneObject(o.mediaConstraints,{audio:!0,video:!0}),h=o.mediaStream||null,g=Me.cloneObject(o.pcConfig,{iceServers:[]}),T=o.rtcConstraints||null,E=o.rtcOfferConstraints||null;if(this._rtcOfferConstraints=E,this._rtcAnswerConstraints=o.rtcAnswerConstraints||null,this._data=o.data||this._data,s===void 0)throw new TypeError("Not enough arguments");if(this._status!==te.STATUS_NULL)throw new Fs.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new Fs.NotSupportedError("WebRTC not supported");if(console.log("target",s),s=this._ua.normalizeTarget(s),console.log("normalizeTarget target",s),this.room_id=s.user,!s)throw new TypeError(`Invalid target: ${t}`);this._sessionTimers.enabled&&Me.isDecimal(o.sessionTimersExpires)&&(o.sessionTimersExpires>=$.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=o.sessionTimersExpires:this._sessionTimers.defaultExpires=$.SESSION_EXPIRES);for(const C in n)Object.prototype.hasOwnProperty.call(n,C)&&this.on(C,n[C]);this._from_tag=Me.newTag();const y=o.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 _r("sip","anonymous","anonymous.invalid"),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),d.push("Privacy: id")):o.fromUserName&&(A.from_uri=new _r("sip",o.fromUserName,this._ua.configuration.uri.host),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),o.fromDisplayName&&(A.from_display_name=o.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 It.InitialOutgoingInviteRequest(s,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,console.log("this._remote_identity",this._remote_identity),a&&a(this),this._newJanusSession("local",this._request),this._sendInitialRequest(_,E,h)}init_incoming(s,r){z.debug("init_incoming()");let o;const a=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0;if(s.body&&a!=="application/sdp"){s.reply(415);return}if(this._status=te.STATUS_INVITE_RECEIVED,this._from_tag=s.from_tag,this._id=s.call_id+this._from_tag,this._request=s,this._contact=this._ua.contact.toString(),s.hasHeader("expires")&&(o=s.getHeader("expires")*1e3),s.to_tag=Me.newTag(),!this._createDialog(s,"UAS",!0)){s.reply(500,"Missing Contact header field");return}s.body?this._late_sdp=!1:this._late_sdp=!0,this._status=te.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{s.reply(408),this._failed("local",null,$.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),o&&(this._timers.expiresTimer=setTimeout(()=>{this._status===te.STATUS_WAITING_FOR_ANSWER&&(s.reply(487),this._failed("system",null,$.causes.EXPIRES))},o)),this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from,r&&r(this),this._newJanusSession("remote",s),this._status!==te.STATUS_TERMINATED&&(s.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(s={}){z.debug("answer()");const r=this._request,o=Me.cloneArray(s.extraHeaders),a=Me.cloneObject(s.mediaConstraints),t=s.mediaStream||null,n=Me.cloneObject(s.pcConfig,{iceServers:[]}),d=s.rtcConstraints||null,_=s.rtcAnswerConstraints||null,h=Me.cloneObject(s.rtcOfferConstraints);let g,T=!1,E=!1,y=!1,A=!1;if(this._rtcAnswerConstraints=_,this._rtcOfferConstraints=s.rtcOfferConstraints||null,this._data=s.data||this._data,this._direction!=="incoming")throw new Fs.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==te.STATUS_WAITING_FOR_ANSWER)throw new Fs.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Me.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=$.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=$.SESSION_EXPIRES),this._status=te.STATUS_ANSWERED,!this._createDialog(r,"UAS")){r.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),o.unshift(`Contact: ${this._contact}`);const C=r.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(t&&a.audio===!1){g=t.getAudioTracks();for(const I of g)t.removeTrack(I)}if(t&&a.video===!1){g=t.getVideoTracks();for(const I of g)t.removeTrack(I)}!t&&a.audio===void 0&&(a.audio=y),!t&&a.video===void 0&&(a.video=A),!t&&!T&&!h.offerToReceiveAudio&&(a.audio=!1),!t&&!E&&!h.offerToReceiveVideo&&(a.video=!1),this._createRTCConnection(n,d),Promise.resolve().then(()=>{if(t)return t;if(a.audio||a.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(a).catch(I=>{throw this._status===te.STATUS_TERMINATED?new Error("terminated"):(r.reply(480),this._failed("local",null,$.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:r.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(L=>{throw r.reply(488),this._failed("system",null,$.causes.WEBRTC_ERROR),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',L),this.emit("peerconnection:setremotedescriptionfailed",L),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(r),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw r.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",_).catch(()=>{throw r.reply(500),new Error("_createLocalDescription() failed")})}).then(I=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(r,o),r.reply(200,null,o,I,()=>{this._status=te.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(r,I),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,$.causes.CONNECTION_ERROR)})}).catch(I=>{this._status!==te.STATUS_TERMINATED&&z.warn(I)})}terminate(s={}){z.debug("terminate()");const r=s.cause||$.causes.BYE,o=Me.cloneArray(s.extraHeaders),a=s.body;let t,n=s.status_code,d=s.reason_phrase;if(this._status===te.STATUS_TERMINATED)throw new Fs.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"),n&&(n<200||n>=700))throw new TypeError(`Invalid status_code: ${n}`);n&&(d=d||$.REASON_PHRASE[n]||"",t=`SIP ;cause=${n} ;text="${d}"`),this._status===te.STATUS_NULL||this._status===te.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=t):this._status===te.STATUS_1XX_RECEIVED&&this._request.cancel(t),this._status=te.STATUS_CANCELED,this._failed("local",null,$.causes.CANCELED);break;case te.STATUS_WAITING_FOR_ANSWER:case te.STATUS_ANSWERED:if(z.debug("rejecting session"),n=n||480,n<300||n>=700)throw new TypeError(`Invalid status_code: ${n}`);this._request.reply(n,d,o,a),this._failed("local",null,$.causes.REJECTED);break;case te.STATUS_WAITING_FOR_ACK:case te.STATUS_CONFIRMED:if(z.debug("terminating session"),d=s.reason_phrase||$.REASON_PHRASE[n]||"",n&&(n<200||n>=700))throw new TypeError(`Invalid status_code: ${n}`);if(n&&o.push(`Reason: SIP ;cause=${n}; text="${d}"`),this._status===te.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Bt.C.STATUS_TERMINATED){const _=this._dialog;this.receiveRequest=({method:h})=>{h===$.ACK&&(this.sendRequest($.BYE,{extraHeaders:o,body:a}),_.terminate(),this.closeSession())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Bt.C.STATUS_TERMINATED&&(this.sendRequest($.BYE,{extraHeaders:o,body:a}),_.terminate(),this.closeSession())}),this._ended("local",null,r),this._dialog=_,console.log("SET DIALOG terminate"),this._ua.newDialog(_)}else{const _={request:"leave"},h=["Content-Type: application/json","PTYPE: Leave"];this.sendRequest($.BYE,{extraHeaders:h,body:JSON.stringify(_)}),this.closeSession(),this._ended("local",null,r)}}}sendInfo(s,r,o={}){if(z.debug("sendInfo()"),this._status!==te.STATUS_CONFIRMED&&this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_1XX_RECEIVED)throw new Fs.InvalidStateError(this._status);new Tu(this).send(s,r,o)}mute(s={audio:!0,video:!1}){z.debug("mute()");let r=!1,o=!1;this._audioMuted===!1&&s.audio&&(r=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&s.video&&(o=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(r===!0||o===!0)&&this._onmute({audio:r,video:o})}unmute(s={audio:!0,video:!0}){z.debug("unmute()");let r=!1,o=!1;this._audioMuted===!0&&s.audio&&(r=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&s.video&&(o=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(r===!0||o===!0)&&this._onunmute({audio:r,video:o})}hold(s={},r){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 o={succeeded:()=>{r&&r()},failed:()=>{this.terminate({cause:$.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:o,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:o,extraHeaders:s.extraHeaders}),!0}unhold(s={},r){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 o={succeeded:()=>{r&&r()},failed:()=>{this.terminate({cause:$.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:o,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:o,extraHeaders:s.extraHeaders}),!0}renegotiate(s={},r){z.debug("renegotiate()");const o=s.rtcOfferConstraints||null;if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const a={succeeded:()=>{r&&r()},failed:()=>{this.terminate({cause:$.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,rtcOfferConstraints:o,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:a,rtcOfferConstraints:o,extraHeaders:s.extraHeaders}),!0}refer(s,r){z.debug("refer()");const o=s;if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;if(s=this._ua.normalizeTarget(s),!s)throw new TypeError(`Invalid target: ${o}`);const a=new Cg(this);a.sendRefer(s,r);const t=a.id;return this._referSubscribers[t]=a,a.on("requestFailed",()=>{delete this._referSubscribers[t]}),a.on("accepted",()=>{delete this._referSubscribers[t]}),a.on("failed",()=>{delete this._referSubscribers[t]}),a}sendRequest(s,r){return z.debug("sendRequest()"),this._dialog.sendRequest(s,r)}receiveNotify(s){z.debug("receiveRequest()")}receiveRequest(s){if(z.debug("receiveRequest()"),s.method===$.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",s,$.causes.CANCELED));else switch(s.method){case $.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(!s.body){this.terminate({cause:$.causes.MISSING_SDP,status_code:400});break}const r={originator:"remote",type:"answer",sdp:s.body};z.debug('emit "sdp"'),this.emit("sdp",r);const o=new RTCSessionDescription({type:"answer",sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(o)).then(()=>{this._is_confirmed||this._confirmed("remote",s)}).catch(a=>{this.terminate({cause:$.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})}else this._is_confirmed||this._confirmed("remote",s);break;case $.BYE:this._status===te.STATUS_CONFIRMED||this._status===te.STATUS_WAITING_FOR_ACK?(s.reply(200),this._ended("remote",s,$.causes.BYE)):this._status===te.STATUS_INVITE_RECEIVED||this._status===te.STATUS_WAITING_FOR_ANSWER?(s.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",s,$.causes.BYE)):s.reply(403,"Wrong Status");break;case $.INVITE:this._status===te.STATUS_CONFIRMED?s.hasHeader("replaces")?this._receiveReplaces(s):this._receiveReinvite(s):s.reply(403,"Wrong Status");break;case $.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 r=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0;r&&r.match(/^application\/dtmf-relay/i)?new hg(this).init_incoming(s):r!==void 0?new Tu(this).init_incoming(s):s.reply(415)}else s.reply(403,"Wrong Status");break;case $.UPDATE:this._status===te.STATUS_CONFIRMED?this._receiveUpdate(s):s.reply(403,"Wrong Status");break;case $.REFER:this._status===te.STATUS_CONFIRMED?this._receiveRefer(s):s.reply(403,"Wrong Status");break;case $.NOTIFY:this._status===te.STATUS_CONFIRMED?this._receiveNotify(s):s.reply(403,"Wrong Status");break;default:s.reply(501)}}onTransportError(){z.warn("onTransportError()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:$.causes.CONNECTION_ERROR,cause:$.causes.CONNECTION_ERROR})}onRequestTimeout(){z.warn("onRequestTimeout()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:$.causes.REQUEST_TIMEOUT,cause:$.causes.REQUEST_TIMEOUT})}onDialogError(){z.warn("onDialogError()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:$.causes.DIALOG_ERROR,cause:$.causes.DIALOG_ERROR})}newDTMF(s){z.debug("newDTMF()"),this.emit("newDTMF",s)}newInfo(s){z.debug("newInfo()"),this.emit("newInfo",s)}_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"),Me.closeMediaStream(this._localMediaStream)),this._status!==te.STATUS_TERMINATED){if(this._status=te.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(s){z.warn("close() | error closing the RTCPeerConnection: %o",s)}for(const s in this._timers)Object.prototype.hasOwnProperty.call(this._timers,s)&&clearTimeout(this._timers[s]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const s in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,s)&&(this._earlyDialogs[s].terminate(),delete this._earlyDialogs[s]);for(const s in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,s)&&delete this._referSubscribers[s];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(s,r){let o=Mi.T1;function a(){this._status===te.STATUS_WAITING_FOR_ACK&&(s.reply(200,null,[`Contact: ${this._contact}`],r),o<Mi.T2&&(o=o*2,o>Mi.T2&&(o=Mi.T2)),this._timers.invite2xxTimer=setTimeout(a.bind(this),o))}this._timers.invite2xxTimer=setTimeout(a.bind(this),o)}_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($.BYE),this._ended("remote",null,$.causes.NO_ACK))},Mi.TIMER_H)}_createRTCConnection(s,r){this.stunServers,this._connection=new RTCPeerConnection(s,r),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:$.causes.RTP_TIMEOUT,status_code:408,reason_phrase:$.causes.RTP_TIMEOUT})});let o;const a=t=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||t.candidate&&(this._candidates.push(t.candidate),clearTimeout(o),o=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=a,z.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(s,r){if(z.debug("createLocalDescription()"),s!=="offer"&&s!=="answer")throw new Error(`createLocalDescription() | invalid type "${s}"`);const o=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>s==="offer"?o.createOffer(r).catch(a=>(z.warn('emit "peerconnection:createofferfailed" [error:%o]',a),this.emit("peerconnection:createofferfailed",a),Promise.reject(a))):o.createAnswer(r).catch(a=>(z.warn('emit "peerconnection:createanswerfailed" [error:%o]',a),this.emit("peerconnection:createanswerfailed",a),Promise.reject(a)))).then(a=>o.setLocalDescription(a).catch(t=>(this._rtcReady=!0,z.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',t),this.emit("peerconnection:setlocaldescriptionfailed",t),Promise.reject(t)))).then(()=>{const a=r&&r.iceRestart;if(o.iceGatheringState==="complete"&&!a||o.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const t={originator:"local",type:s,sdp:o.localDescription.sdp};return z.debug('emit "sdp"'),this.emit("sdp",t),Promise.resolve(t.sdp)}return new Promise(t=>{let n=!1,d,_;this._iceReady=!1;const h=()=>{o.removeEventListener("icecandidate",d),o.removeEventListener("icegatheringstatechange",_),n=!0,this._rtcReady=!0,this._iceReady=!0;const g={originator:"local",type:s,sdp:o.localDescription.sdp};z.debug('emit "sdp"'),this.emit("sdp",g),t(g.sdp)};o.addEventListener("icecandidate",d=g=>{const T=g.candidate;T?this.emit("icecandidate",{candidate:T,ready:h}):n||h()}),o.addEventListener("icegatheringstatechange",_=()=>{o.iceGatheringState==="complete"&&!n&&h()})})})}_createDialog(s,r,o){console.log("_createDialog",s);const a=r==="UAS"?s.to_tag:s.from_tag,t=r==="UAS"?s.from_tag:s.to_tag,n=s.call_id+a+t;console.log("remote_tag",t);let d=this._earlyDialogs[n];if(o)return d?!0:(d=new lo(this,s,r,lo.C.STATUS_EARLY),console.log("SET DIALOG early"),d.error?(console.log("early_dialog error",d.error),z.debug(d.error),this._failed("remote",s,$.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[n]=d,!0));{if(this._from_tag=s.from_tag,this._to_tag=s.to_tag,d)return d.update(s,r),console.log("SET DIALOG 1"),this._dialog=d,delete this._earlyDialogs[n],!0;const _=new lo(this,s,r);return _.error?(console.log("dialog.error",_.error),z.debug(_.error),this._failed("remote",s,$.causes.INTERNAL_ERROR),!1):(console.log("AAA SET DIALOG 2"),this._dialog=_,!0)}}_receiveReinvite(s){z.debug("receiveReinvite()");const r=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0,o={request:s,callback:void 0,reject:t.bind(this)};let a=!1;function t(d={}){a=!0;const _=d.status_code||403,h=d.reason_phrase||"",g=Me.cloneArray(d.extraHeaders);if(this._status!==te.STATUS_CONFIRMED)return!1;if(_<300||_>=700)throw new TypeError(`Invalid status_code: ${_}`);s.reply(_,h,g)}if(this.emit("reinvite",o),a)return;if(this._late_sdp=!1,!s.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=>{n.call(this,d)}).catch(()=>{s.reply(500)});return}if(r!=="application/sdp"){z.debug("invalid Content-Type"),s.reply(415);return}this._processInDialogSdpOffer(s).then(d=>{this._status!==te.STATUS_TERMINATED&&n.call(this,d)}).catch(d=>{z.warn(d)});function n(d){const _=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(s,_),this._late_sdp&&(d=this._mangleOffer(d)),s.reply(200,null,_,d,()=>{this._status=te.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(s,d),this._setACKTimer()}),typeof o.callback=="function"&&o.callback()}}_receiveUpdate(s){z.debug("receiveUpdate()");const r=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0,o={request:s,callback:void 0,reject:t.bind(this)};let a=!1;function t(d={}){a=!0;const _=d.status_code||403,h=d.reason_phrase||"",g=Me.cloneArray(d.extraHeaders);if(this._status!==te.STATUS_CONFIRMED)return!1;if(_<300||_>=700)throw new TypeError(`Invalid status_code: ${_}`);s.reply(_,h,g)}if(this.emit("update",o),a)return;if(!s.body){n.call(this,null);return}if(r!=="application/sdp"){z.debug("invalid Content-Type"),s.reply(415);return}this._processInDialogSdpOffer(s).then(d=>{this._status!==te.STATUS_TERMINATED&&n.call(this,d)}).catch(d=>{z.warn(d)});function n(d){const _=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(s,_),s.reply(200,null,_,d),typeof o.callback=="function"&&o.callback()}}_processInDialogSdpOffer(s){z.debug("_processInDialogSdpOffer()");const r=s.parseSDP();let o=!1;for(const n of r.media){if(oo.indexOf(n.type)===-1)continue;const d=n.direction||r.direction||"sendrecv";if(d==="sendonly"||d==="inactive")o=!0;else{o=!1;break}}const a={originator:"remote",type:"offer",sdp:s.body};z.debug('emit "sdp"'),this.emit("sdp",a);const t=new RTCSessionDescription({type:"offer",sdp:a.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(t).catch(n=>{throw s.reply(488),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),this.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&o===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&o===!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(n=>{throw s.reply(500),z.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',n),n})}).catch(n=>{z.warn("_processInDialogSdpOffer() failed [error: %o]",n)}),this._connectionPromiseQueue}_receiveRefer(s){if(z.debug("receiveRefer()"),!s.refer_to){z.debug("no Refer-To header field present in REFER"),s.reply(400);return}if(s.refer_to.uri.scheme!==$.SIP){z.debug("Refer-To header field points to a non-SIP URI scheme"),s.reply(416);return}s.reply(202);const r=new Eg(this,s.cseq);z.debug('emit "refer"'),this.emit("refer",{request:s,accept:(t,n)=>{o.call(this,t,n)},reject:()=>{a.call(this)}});function o(t,n={}){if(t=typeof t=="function"?t:null,this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;const d=new ko(this._ua);if(d.on("progress",({response:_})=>{r.notify(_.status_code,_.reason_phrase)}),d.on("accepted",({response:_})=>{r.notify(_.status_code,_.reason_phrase)}),d.on("_failed",({message:_,cause:h})=>{_?r.notify(_.status_code,_.reason_phrase):r.notify(487,h)}),s.refer_to.uri.hasHeader("replaces")){const _=decodeURIComponent(s.refer_to.uri.getHeader("replaces"));n.extraHeaders=Me.cloneArray(n.extraHeaders),n.extraHeaders.push(`Replaces: ${_}`)}d.connect(s.refer_to.uri.toAor(),n,t)}function a(){r.notify(603)}}_receiveNotify(s){switch(z.debug("receiveNotify()"),s.event||s.reply(400),s.event.event){case"refer":{let r,o;if(s.event.params&&s.event.params.id)r=s.event.params.id,o=this._referSubscribers[r];else if(Object.keys(this._referSubscribers).length===1)o=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{s.reply(400,"Missing event id parameter");return}if(!o){s.reply(481,"Subscription does not exist");return}o.receiveNotify(s),s.reply(200);break}default:s.reply(489)}}_receiveReplaces(s){z.debug("receiveReplaces()");function r(a){if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;const t=new ko(this._ua);t.on("confirmed",()=>{this.terminate()}),t.init_incoming(s,a)}function o(){z.debug("Replaced INVITE rejected by the user"),s.reply(486)}this.emit("replaces",{request:s,accept:a=>{r.call(this,a)},reject:()=>{o.call(this)}})}_getNextTransactionId(){return(this.lastTransaction+1).toString()}_sendInitialRequest(s,r,o){this.ackSent=!1,this.publisherSubscribeSent=!1;const a=new Mo(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:t=>{this._request=t},onReceiveResponse:t=>{this._receiveInviteResponse(t)}});Promise.resolve().then(()=>{if(o)return o;if(s.audio||s.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(s).catch(t=>{throw this._status===te.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,$.causes.USER_DENIED_MEDIA_ACCESS),z.warn('emit "getusermediafailed" [error:%o]',t),this.emit("getusermediafailed",t),t)})}).then(t=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=t,t&&t.getTracks().forEach(n=>{this._connection.addTrack(n,t)}),this._connecting(this._request),this._createLocalDescription("offer",r).catch(n=>{throw this._failed("local",null,$.causes.WEBRTC_ERROR),n})}).then(t=>{if(this._is_canceled||this._status===te.STATUS_TERMINATED)throw new Error("terminated");const n={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaque_id},d=JSON.stringify(n);this._request.body=d,this._status=te.STATUS_INVITE_SENT,z.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),a.send()}).catch(t=>{this._status!==te.STATUS_TERMINATED&&z.warn(t)})}requestAudioAndVideoPermissions(){return this.loadStream()}async loadStream(){const s={audio:!0,video:!0};try{this.stream=await navigator.mediaDevices.getUserMedia(s)}catch{try{s.video=!1,this.stream=await navigator.mediaDevices.getUserMedia(s)}catch{s.audio=!1,s.video=!1,this.stream=await navigator.mediaDevices.getUserMedia(s)}}return{stream:this.stream,options:s}}addTracks(s){s.forEach(r=>{this._connection.addTrack(r)})}getRecordFileName(){return wT+this.room_id+btoa(unescape(encodeURIComponent(this.displayName)))+Date.now()}async processIceCandidates(){for(let s=0;s<this.iceCandidates.length;s++)await this._connection.addIceCandidate(this.iceCandidates[s]);this.iceCandidates=[]}async _sendConfigureMessage(s){const r={offerToReceiveAudio:!1,offerToReceiveVideo:!1},o=await this._connection.createOffer(r);await this._connection.setLocalDescription(o);const a=this._candidates.map(_=>({janus:"trickle",candidate:_,handle_id:this.handle_id,session_id:this.session_id})),n={configure:{janus:"message",body:{request:"configure",record:!0,filename:this.getRecordFileName(),...s},jsep:o,handle_id:this.handle_id,session_id:this.session_id},trickles:[...a]},d=["Content-Type: application/json","PTYPE: Ice"];this.sendRequest($.INFO,{extraHeaders:d,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async _=>{this.isConfigureSent=!0;const g=_.data.split(`\r
135
- `),T=g[g.length-1],E=JSON.parse(T);await this._connection.setRemoteDescription(E.jsep),this._candidates=[]}}})}_sendMemberStartMessage(s,r){const o={janus:"message",body:{request:"start",room:this.room_id},handle_id:s.handleId,session_id:this.session_id,jsep:r},a=["Content-Type: application/json","PTYPE: Configure"];this.sendRequest($.INFO,{extraHeaders:a,body:JSON.stringify(o),eventHandlers:{onSuccessResponse:async t=>{t.status_code===200&&await s.rtcpPeer.setLocalDescription(r)}}})}_sendTrickleMessage(s){const o={trickles:[...s.map(t=>({janus:"trickle",candidate:t,handle_id:this.handle_id,session_id:this.session_id}))]},a=["PTYPE: Trickle"];this.sendRequest($.INFO,{extraHeaders:a,body:JSON.stringify(o),eventHandlers:{onSuccessResponse:async t=>{console.log("_sendTrickleMessage",t)}}})}async _answerAttachedStream(s,r){let o=null;const a=async _=>{if(!s.rtcpPeer||s.loaded)return;{s.loaded=!0;const y={audio:!0,video:!0};await new Promise(A=>{setTimeout(A,100)}),o=await s.rtcpPeer.createAnswer(y),this._sendMemberStartMessage(s,o)}const h=_.streams[0].getAudioTracks(),g=_.streams[0].getVideoTracks(),T=[];h[0]&&T.push(h[0]),g[0]&&T.push(g[0]);const E=new MediaStream(T);s.stream=E,this._ua.emit("memberJoin",s.memberInfo)};let t,n=[];const d=_=>{s.rtcpPeer.signalingState!=="stable"&&s.rtcpPeer.signalingState!=="have-local-offer"||(n.push(_.candidate||null),clearTimeout(t),t=setTimeout(()=>{this._sendTrickleMessage(n)},500))};s.rtcpPeer=new RTCPeerConnection,s.rtcpPeer.ontrack=a,s.rtcpPeer.onicecandidate=d,s.rtcpPeer.sender=r.sender,await s.rtcpPeer.setRemoteDescription(r.jsep)}_sendJoinMemberRequest(s){const r={janus:"message",body:{request:"join",room:this.room_id,feed:s.info.id,ptype:"subscriber"},handle_id:s.handleId,session_id:this.session_id},o=["PTYPE: Subscriber"];this.sendRequest($.SUBSCRIBE,{extraHeaders:o,body:JSON.stringify(r),eventHandlers:{onSuccessResponse:async a=>{var t,n;if(a.status_code===200){const d=JSON.parse(a.body);(n=(t=d==null?void 0:d.plugindata)==null?void 0:t.data)!=null&&n.id&&await this._answerAttachedStream(s,d)}}}})}_attachMember(s){const r={janus:"attach",opaque_id:this.opaque_id,plugin:"janus.plugin.videoroom",session_id:this.session_id},o=["PTYPE: Subscriber"];this.sendRequest($.INFO,{extraHeaders:o,body:JSON.stringify(r),eventHandlers:{onSuccessResponse:async a=>{if(a.status_code===200){const n=JSON.parse(a.body).data.id;s.handleId=n,this._sendJoinMemberRequest(s)}}}})}_detachMember(s){const r={janus:"detach",handle_id:s.handleId,session_id:this.session_id},o=["PTYPE: Subscriber"];this.sendRequest($.INFO,{extraHeaders:o,body:JSON.stringify(r)}),this._ua.emit("memberHangup",s.memberInfo)}receivePublishers(s){var o,a,t,n,d,_,h,g;const r={...this.memberList};(a=(o=s==null?void 0:s.plugindata)==null?void 0:o.data)==null||a.publishers.forEach(T=>{delete r[T.id],!this.memberList[T.id]&&!this.myFeedList.includes(T.id)&&T.clientID!==this.client_id&&(this.memberList[T.id]=new IT(T,this),this._attachMember(this.memberList[T.id]))}),((n=(t=s==null?void 0:s.plugindata)==null?void 0:t.data)==null?void 0:n.videoroom)==="synced"&&Object.keys(r).forEach(T=>{r[T].hangup(),delete this.memberList[T]}),this.publishers=(_=(d=s==null?void 0:s.plugindata)==null?void 0:d.data)==null?void 0:_.publishers,this.private_id=(g=(h=s==null?void 0:s.plugindata)==null?void 0:h.data)==null?void 0:g.private_id}receiveUnpublished(s){const r=this.memberList[s];r&&(r.hangup(),this._detachMember(r),delete this.memberList[s])}closeSession(){this.stream&&this.stream.getTracks().forEach(r=>{r.stop()}),Object.values(this.memberList).forEach(r=>{r.hangup(),this._detachMember(r)})}_receiveInviteResponse(s){if(z.debug("receiveInviteResponse()"),console.log("_receiveInviteResponse response",s),console.log("dialog",this._dialog),this._dialog&&s.status_code>=200&&s.status_code<=299&&!this.ackSent)if(console.log("IF 1 dialog"),this._dialog.id.call_id===s.call_id&&this._dialog.id.local_tag===s.from_tag&&this._dialog.id.remote_tag===s.to_tag){this.ackSent=!0,this.sendRequest($.ACK);return}else{const r=new lo(this,s,"UAC");if(r.error!==void 0){z.debug(r.error);return}this.sendRequest($.ACK),this.sendRequest($.BYE);return}if(this.ackSent&&!this.publisherSubscribeSent){const r=JSON.parse(s.body);this.requestAudioAndVideoPermissions().then(()=>{this.session_id=r.session_id,this.handle_id=r.data.id,this.client_id=bf();const o={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},a=["PTYPE: Publisher"];this.sendRequest($.SUBSCRIBE,{extraHeaders:a,body:JSON.stringify(o),eventHandlers:{onSuccessResponse:async t=>{var n,d;if(t.status_code===200){if(this.subscribeSent=!0,t.body)try{const _=JSON.parse(t.body)||{};(d=(n=_.plugindata)==null?void 0:n.data)!=null&&d.publishers&&this.receivePublishers(_)}catch(_){console.error(_)}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.publisherSubscribeSent=!0})}if(this._is_canceled){s.status_code>=100&&s.status_code<200?this._request.cancel(this._cancel_reason):s.status_code>=200&&s.status_code<299&&this._acceptAndTerminate(s);return}if(!(this._status!==te.STATUS_INVITE_SENT&&this._status!==te.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(s.status_code):this._status=te.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(s.status_code):{if(!s.to_tag){z.debug("1xx response received without to tag");break}if(s.hasHeader("contact")&&!this._createDialog(s,"UAC",!0))break;if(this._status=te.STATUS_1XX_RECEIVED,!s.body){this._progress("remote",s);break}const r={originator:"remote",type:"answer",sdp:s.body};z.debug('emit "sdp"'),this.emit("sdp",r);const o=new RTCSessionDescription({type:"answer",sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(o)).then(()=>this._progress("remote",s)).catch(a=>{z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)});break}case/^2[0-9]{2}$/.test(s.status_code):{if(this._status=te.STATUS_CONFIRMED,!s.body){this._acceptAndTerminate(s,400,$.causes.MISSING_SDP),this._failed("remote",s,$.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(s,"UAC"))break;break}default:{const r=Me.sipErrorCause(s.status_code);this._failed("remote",s,r)}}}_sendReinvite(s={}){z.debug("sendReinvite()");const r=Me.cloneArray(s.extraHeaders),o=Me.cloneObject(s.eventHandlers),a=s.rtcOfferConstraints||this._rtcOfferConstraints||null;let t=!1;r.push(`Contact: ${this._contact}`),r.push("Content-Type: application/sdp"),this._sessionTimers.running&&r.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",a)).then(_=>{_=this._mangleOffer(_);const h={originator:"local",type:"offer",sdp:_};z.debug('emit "sdp"'),this.emit("sdp",h),this.sendRequest($.INVITE,{extraHeaders:r,body:_,eventHandlers:{onSuccessResponse:g=>{n.call(this,g),t=!0},onErrorResponse:g=>{d.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{d()});function n(_){if(this._status===te.STATUS_TERMINATED||(this.sendRequest($.ACK),t))return;if(this._handleSessionTimersInIncomingResponse(_),_.body){if(!_.hasHeader("Content-Type")||_.getHeader("Content-Type").toLowerCase()!=="application/sdp"){d.call(this);return}}else{d.call(this);return}const h={originator:"remote",type:"answer",sdp:_.body};z.debug('emit "sdp"'),this.emit("sdp",h);const g=new RTCSessionDescription({type:"answer",sdp:h.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(g)).then(()=>{o.succeeded&&o.succeeded(_)}).catch(T=>{d.call(this),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function d(_){o.failed&&o.failed(_)}}_sendUpdate(s={}){z.debug("sendUpdate()");const r=Me.cloneArray(s.extraHeaders),o=Me.cloneObject(s.eventHandlers),a=s.rtcOfferConstraints||this._rtcOfferConstraints||null,t=s.sdpOffer||!1;let n=!1;r.push(`Contact: ${this._contact}`),this._sessionTimers.running&&r.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),t?(r.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",a)).then(h=>{h=this._mangleOffer(h);const g={originator:"local",type:"offer",sdp:h};z.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest($.UPDATE,{extraHeaders:r,body:h,eventHandlers:{onSuccessResponse:T=>{d.call(this,T),n=!0},onErrorResponse:T=>{_.call(this,T)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{_.call(this)})):this.sendRequest($.UPDATE,{extraHeaders:r,eventHandlers:{onSuccessResponse:h=>{d.call(this,h)},onErrorResponse:h=>{_.call(this,h)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function d(h){if(this._status!==te.STATUS_TERMINATED&&!n)if(this._handleSessionTimersInIncomingResponse(h),t){if(h.body){if(!h.hasHeader("Content-Type")||h.getHeader("Content-Type").toLowerCase()!=="application/sdp"){_.call(this);return}}else{_.call(this);return}const g={originator:"remote",type:"answer",sdp:h.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(()=>{o.succeeded&&o.succeeded(h)}).catch(E=>{_.call(this),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),this.emit("peerconnection:setremotedescriptionfailed",E)})}else o.succeeded&&o.succeeded(h)}function _(h){o.failed&&o.failed(h)}}_acceptAndTerminate(s,r,o){z.debug("acceptAndTerminate()");const a=[];r&&(o=o||$.REASON_PHRASE[r]||"",a.push(`Reason: SIP ;cause=${r}; text="${o}"`)),(this._dialog||this._createDialog(s,"UAC"))&&(this.sendRequest($.ACK),this.sendRequest($.BYE,{extraHeaders:a})),this._status=te.STATUS_TERMINATED}_mangleOffer(s){if(!this._localHold&&!this._remoteHold)return s;if(s=Pt.parse(s),this._localHold&&!this._remoteHold){z.debug("mangleOffer() | me on hold, mangling offer");for(const r of s.media)oo.indexOf(r.type)!==-1&&(r.direction?r.direction==="sendrecv"?r.direction="sendonly":r.direction==="recvonly"&&(r.direction="inactive"):r.direction="sendonly")}else if(this._localHold&&this._remoteHold){z.debug("mangleOffer() | both on hold, mangling offer");for(const r of s.media)oo.indexOf(r.type)!==-1&&(r.direction="inactive")}else if(this._remoteHold){z.debug("mangleOffer() | remote on hold, mangling offer");for(const r of s.media)oo.indexOf(r.type)!==-1&&(r.direction?r.direction==="sendrecv"?r.direction="recvonly":r.direction==="recvonly"&&(r.direction="inactive"):r.direction="recvonly")}return Pt.write(s)}_setLocalMediaStatus(){let s=!0,r=!0;(this._localHold||this._remoteHold)&&(s=!1,r=!1),this._audioMuted&&(s=!1),this._videoMuted&&(r=!1),this._toggleMuteAudio(!s),this._toggleMuteVideo(!r)}_handleSessionTimersInIncomingRequest(s,r){if(!this._sessionTimers.enabled)return;let o;s.session_expires&&s.session_expires>=$.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=s.session_expires,o=s.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,o="uas"),r.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${o}`),this._sessionTimers.refresher=o==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(s){if(!this._sessionTimers.enabled)return;let r;s.session_expires&&s.session_expires>=$.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=s.session_expires,r=s.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,r="uac"),this._sessionTimers.refresher=r==="uac",this._runSessionTimer()}_runSessionTimer(){const s=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===$.UPDATE?this._sendUpdate():this._sendReinvite())},s*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==te.STATUS_TERMINATED&&(z.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:$.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},s*1100)}_toggleMuteAudio(s){const r=this._connection.getSenders().filter(o=>o.track&&o.track.kind==="audio");for(const o of r)o.track.enabled=!s}_toggleMuteVideo(s){const r=this._connection.getSenders().filter(o=>o.track&&o.track.kind==="video");for(const o of r)o.track.enabled=!s}_newJanusSession(s,r){z.debug("newRTCSession()"),this._ua.newJanusSession(this,{originator:s,session:this,request:r})}_connecting(s){z.debug("session connecting"),z.debug('emit "connecting"'),this.emit("connecting",{request:s})}_progress(s,r){z.debug("session progress"),z.debug('emit "progress"'),this.emit("progress",{originator:s,response:r||null})}_accepted(s,r){z.debug("session accepted"),this._start_time=new Date,z.debug('emit "accepted"'),this.emit("accepted",{originator:s,response:r||null})}_confirmed(s,r){z.debug("session confirmed"),this._is_confirmed=!0,z.debug('emit "confirmed"'),this.emit("confirmed",{originator:s,ack:r||null})}_ended(s,r,o){z.debug("session ended"),this._end_time=new Date,this._close(),z.debug('emit "ended"'),this.emit("ended",{originator:s,message:r||null,cause:o})}_failed(s,r,o){z.debug("session failed"),z.debug('emit "_failed"'),this.emit("_failed",{originator:s,message:r||null,cause:o}),this._close(),z.debug('emit "failed"'),this.emit("failed",{originator:s,message:r||null,cause:o})}_onhold(s){z.debug("session onhold"),this._setLocalMediaStatus(),z.debug('emit "hold"'),this.emit("hold",{originator:s})}_onunhold(s){z.debug("session onunhold"),this._setLocalMediaStatus(),z.debug('emit "unhold"'),this.emit("unhold",{originator:s})}_onmute({audio:s,video:r}){z.debug("session onmute"),this._setLocalMediaStatus(),z.debug('emit "muted"'),this.emit("muted",{audio:s,video:r})}_onunmute({audio:s,video:r}){z.debug("session onunmute"),this._setLocalMediaStatus(),z.debug('emit "unmuted"'),this.emit("unmuted",{audio:s,video:r})}}class or{constructor(s){if(this.headers={},s.length>0){let r=!1;const o=s.split(`\r
136
- `),a=o.shift().split(/\s/);this.protocol=a[0],this.ident=a[1],this.code=a.length>3?parseInt(a[2]):0,this.method=a.length>3?a[3]:a[2],this.body="";for(const t of o){if(t==`-------${this.ident}$`)break;if(t===""){r=!0;continue}if(t&&r)this.body+=`${t}\r
137
- `;else{const n=t.split(": ");this.addHeader(n[0],n[1].trim())}}}else this.ident=Me.createRandomToken(12),this.protocol="MSRP"}addHeader(s,r){this.headers[s]=r}getHeader(s){return this.headers[s]}toString(){let s=`${this.protocol} ${this.ident} ${this.code} ${this.method}`.replaceAll(/null\s|undefined\s/ig,"")+`\r
138
- `;for(const r in this.headers)s+=`${r}: ${this.headers[r]}\r
125
+ `);this.ondata({transport:this,message:s})}};const Qg=tt(A_);var C_={};const Zg=ut,Cu=Qt(),Ru=Dt,_a=new Zg("Parser");C_.parseMessage=(c,s)=>{let i,l,a=c.indexOf(`\r
126
+ `);if(a===-1){_a.warn("parseMessage() | no CRLF found, not a SIP message");return}const _=c.substring(0,a);let e=Cu.parse(_,"Request_Response");if(e===-1){_a.warn(`parseMessage() | error parsing first line of SIP message: "${_}"`);return}else e.status_code?(i=new Ru.IncomingResponse,i.status_code=e.status_code,i.reason_phrase=e.reason_phrase):(i=new Ru.IncomingRequest(s),i.method=e.method,i.ruri=e.uri);i.data=c;let p=a+2;for(;;){if(a=eT(c,p),a===-2){l=p+2;break}else if(a===-1){_a.warn("parseMessage() | malformed message");return}if(e=tT(i,c,p,a),e!==!0){_a.warn("parseMessage() |",e.error);return}p=a+2}if(i.hasHeader("content-length")){const g=i.getHeader("content-length");i.body=c.substr(l,g)}else i.body=c.substring(l);return i};function eT(c,s){let i=s,l=0,a=0;if(c.substring(i,i+2).match(/(^\r\n)/))return-2;for(;l===0;){if(a=c.indexOf(`\r
127
+ `,i),a===-1)return a;!c.substring(a+2,a+4).match(/(^\r\n)/)&&c.charAt(a+2).match(/(^\s+)/)?i=a+2:l=a}return l}function tT(c,s,i,l){let a;const _=s.indexOf(":",i),e=s.substring(i,_).trim(),p=s.substring(_+1,l).trim();switch(e.toLowerCase()){case"via":case"v":c.addHeader("via",p),c.getHeaders("via").length===1?(a=c.parseHeader("Via"),a&&(c.via=a,c.via_branch=a.branch)):a=0;break;case"from":case"f":c.setHeader("from",p),a=c.parseHeader("from"),a&&(c.from=a,c.from_tag=a.getParam("tag"));break;case"to":case"t":c.setHeader("to",p),a=c.parseHeader("to"),a&&(c.to=a,c.to_tag=a.getParam("tag"));break;case"record-route":if(a=Cu.parse(p,"Record_Route"),a===-1)a=void 0;else for(const g of a)c.addHeader("record-route",p.substring(g.possition,g.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=g.parsed;break;case"call-id":case"i":c.setHeader("call-id",p),a=c.parseHeader("call-id"),a&&(c.call_id=p);break;case"contact":case"m":if(a=Cu.parse(p,"Contact"),a===-1)a=void 0;else for(const g of a)c.addHeader("contact",p.substring(g.possition,g.offset)),c.headers.Contact[c.getHeaders("contact").length-1].parsed=g.parsed;break;case"content-length":case"l":c.setHeader("content-length",p),a=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",p),a=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",p),a=c.parseHeader("cseq"),a&&(c.cseq=a.value),c instanceof Ru.IncomingResponse&&(c.method=a.method);break;case"max-forwards":c.setHeader("max-forwards",p),a=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",p),a=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",p),a=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",p),a=c.parseHeader("session-expires"),a&&(c.session_expires=a.expires,c.session_expires_refresher=a.refresher);break;case"refer-to":case"r":c.setHeader("refer-to",p),a=c.parseHeader("refer-to"),a&&(c.refer_to=a);break;case"replaces":c.setHeader("replaces",p),a=c.parseHeader("replaces"),a&&(c.replaces=a);break;case"event":case"o":c.setHeader("event",p),a=c.parseHeader("event"),a&&(c.event=a);break;default:c.addHeader(e,p),a=0}return a===void 0?{error:`error parsing header "${e}"`}:!0}const sT=ut,R_=Me,Rf=Dt,Vu=Ct(),Bu=new sT("sanityCheck"),nT=[_T],rT=[lT,aT,oT,uT],iT=[cT,fT];let Ge,ls,I_;var b_=(c,s,i)=>{Ge=c,ls=s,I_=i;for(const l of nT)if(l()===!1)return!1;if(Ge instanceof Rf.IncomingRequest){for(const l of rT)if(l()===!1)return!1}else if(Ge instanceof Rf.IncomingResponse){for(const l of iT)if(l()===!1)return!1}return!0};function lT(){if(Ge.s("to").uri.scheme!=="sip")return Zi(416),!1}function aT(){if(!Ge.to_tag&&Ge.call_id.substr(0,5)===ls.configuration.jssip_id)return Zi(482),!1}function oT(){const c=Vu.str_utf8_length(Ge.body),s=Ge.getHeader("content-length");if(c<s)return Zi(400),!1}function uT(){const c=Ge.from_tag,s=Ge.call_id,i=Ge.cseq;let l;if(!Ge.to_tag)if(Ge.method===R_.INVITE){if(ls._transactions.ist[Ge.via_branch])return!1;for(const a in ls._transactions.ist)if(Object.prototype.hasOwnProperty.call(ls._transactions.ist,a)&&(l=ls._transactions.ist[a],l.request.from_tag===c&&l.request.call_id===s&&l.request.cseq===i))return Zi(482),!1}else{if(ls._transactions.nist[Ge.via_branch])return!1;for(const a in ls._transactions.nist)if(Object.prototype.hasOwnProperty.call(ls._transactions.nist,a)&&(l=ls._transactions.nist[a],l.request.from_tag===c&&l.request.call_id===s&&l.request.cseq===i))return Zi(482),!1}}function cT(){if(Ge.getHeaders("via").length>1)return Bu.debug("more than one Via header field present in the response, dropping the response"),!1}function fT(){const c=Vu.str_utf8_length(Ge.body),s=Ge.getHeader("content-length");if(c<s)return Bu.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}function _T(){const c=["from","to","call_id","cseq","via"];for(const s of c)if(!Ge.hasHeader(s))return Bu.debug(`missing mandatory header field : ${s}, dropping the response`),!1}function Zi(c){const s=Ge.getHeaders("via");let i,l=`SIP/2.0 ${c} ${R_.REASON_PHRASE[c]}\r
128
+ `;for(const a of s)l+=`Via: ${a}\r
129
+ `;i=Ge.getHeader("To"),Ge.to_tag||(i+=`;tag=${Vu.newTag()}`),l+=`To: ${i}\r
130
+ `,l+=`From: ${Ge.getHeader("From")}\r
131
+ `,l+=`Call-ID: ${Ge.call_id}\r
132
+ `,l+=`CSeq: ${Ge.cseq} ${Ge.method}\r
133
+ `,l+=`\r
134
+ `,I_.send(l)}const hT=tt(b_);var el={};const rr=Ct(),Nn=Me,Jo=Qt(),If=Is(),zo=qu,Xo=bs;el.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:Nn.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:Nn.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:Nn.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:`${rr.createRandomToken(12)}.invalid`};const ha={mandatory:{sockets(c){const s=[];if(zo.isSocket(c))s.push({socket:c});else if(Array.isArray(c)&&c.length)for(const i of c)Object.prototype.hasOwnProperty.call(i,"socket")&&zo.isSocket(i.socket)?s.push(i):zo.isSocket(i)&&s.push({socket:i});else return;return s},uri(c){/^sip:/i.test(c)||(c=`${Nn.SIP}:${c}`);const s=If.parse(c);if(s)return s.user?s:void 0}},optional:{authorization_user(c){if(Jo.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(rr.isDecimal(c)){const s=Number(c);if(s>0)return s}},connection_recovery_min_interval(c){if(rr.isDecimal(c)){const s=Number(c);if(s>0)return s}},contact_uri(c){if(typeof c=="string"){const s=Jo.parse(c,"SIP_URI");if(s!==-1)return s}},display_name(c){return c},instance_id(c){if(/^uuid:/i.test(c)&&(c=c.substr(5)),Jo.parse(c,"uuid")!==-1)return c},no_answer_timeout(c){if(rr.isDecimal(c)){const s=Number(c);if(s>0)return s}},session_timers(c){if(typeof c=="boolean")return c},session_timers_refresh_method(c){if(typeof c=="string"&&(c=c.toUpperCase(),c===Nn.INVITE||c===Nn.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(rr.isDecimal(c)){const s=Number(c);if(s>0)return s}},registrar_server(c){/^sip:/i.test(c)||(c=`${Nn.SIP}:${c}`);const s=If.parse(c);if(s)return s.user?void 0:s},use_preloaded_route(c){if(typeof c=="boolean")return c},extra_headers(c){const s=[];if(Array.isArray(c)&&c.length)for(const i of c)typeof i=="string"&&s.push(i);else return;return s}}};el.load=(c,s)=>{for(const i in ha.mandatory)if(s.hasOwnProperty(i)){const l=s[i],a=ha.mandatory[i](l);if(a!==void 0)c[i]=a;else throw new Xo.ConfigurationError(i,l)}else throw new Xo.ConfigurationError(i);for(const i in ha.optional)if(s.hasOwnProperty(i)){const l=s[i];if(rr.isEmpty(l))continue;const a=ha.optional[i](l);if(a!==void 0)c[i]=a;else throw new Xo.ConfigurationError(i,l)}};const dT=ht.EventEmitter,pT=ut,Tt=Me,mT=rg,bf=y_,wf=qg,Of=Kg,Qo=cr,gT=A_,da=Ct(),TT=bs,vT=Is(),ET=C_,Zo=Dt,ST=b_,eu=el,Ke=new pT("UA"),St={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};var w_=class extends dT{static get C(){return St}constructor(s){if(Ke.debug("new() [configuration:%o]",s),super(),this._cache={credentials:{}},this._configuration=Object.assign({},eu.settings),this._dynConfiguration={},this._dialogs={},this._applicants={},this._sessions={},this._transport=null,this._contact=null,this._status=St.STATUS_INIT,this._error=null,this._transactions={nist:{},nict:{},ist:{},ict:{}},this._data={},this._closeTimer=null,s===void 0)throw new TypeError("Not enough arguments");try{this._loadConfig(s)}catch(i){throw this._status=St.STATUS_NOT_READY,this._error=St.CONFIGURATION_ERROR,i}this._registrator=new mT(this)}get C(){return St}get status(){return this._status}get contact(){return this._contact}get configuration(){return this._configuration}get transport(){return this._transport}start(){Ke.debug("start()"),this._status===St.STATUS_INIT?this._transport.connect():this._status===St.STATUS_USER_CLOSED?(Ke.debug("restarting UA"),this._closeTimer!==null&&(clearTimeout(this._closeTimer),this._closeTimer=null,this._transport.disconnect()),this._status=St.STATUS_INIT,this._transport.connect()):this._status===St.STATUS_READY?Ke.debug("UA is in READY status, not restarted"):Ke.debug("ERROR: connection is down, Auto-Recovery system is trying to reconnect"),this._dynConfiguration.register=this._configuration.register}register(){Ke.debug("register()"),this._dynConfiguration.register=!0,this._registrator.register()}unregister(s){Ke.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(s)}registrator(){return this._registrator}isRegistered(){return this._registrator.registered}isConnected(){return this._transport.isConnected()}call(s,i){Ke.debug("call()");const l=new bf(this);return l.connect(s,i),l}sendMessage(s,i,l){Ke.debug("sendMessage()");const a=new wf(this);return a.send(s,i,l),a}sendOptions(s,i,l){Ke.debug("sendOptions()");const a=new Of(this);return a.send(s,i,l),a}terminateSessions(s){Ke.debug("terminateSessions()");for(const i in this._sessions)this._sessions[i].isEnded()||this._sessions[i].terminate(s)}stop(){if(Ke.debug("stop()"),this._dynConfiguration={},this._status===St.STATUS_USER_CLOSED){Ke.debug("UA already closed");return}this._registrator.close();const s=Object.keys(this._sessions).length;for(const l in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,l)){Ke.debug(`closing session ${l}`);try{this._sessions[l].terminate()}catch{}}for(const l in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,l))try{this._applicants[l].close()}catch{}this._status=St.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&&s===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}normalizeTarget(s){return da.normalizeTarget(s,this._configuration.hostport_params)}get(s){switch(s){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:Ke.warn('get() | cannot get "%s" parameter in runtime',s);return}}set(s,i){switch(s){case"authorization_user":{this._configuration.authorization_user=String(i);break}case"password":{this._configuration.password=String(i);break}case"realm":{this._configuration.realm=String(i);break}case"ha1":{this._configuration.ha1=String(i),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(i);break}case"display_name":{this._configuration.display_name=i;break}default:return Ke.warn('set() | cannot set "%s" parameter in runtime',s),!1}return!0}newTransaction(s){this._transactions[s.type][s.id]=s,this.emit("newTransaction",{transaction:s})}destroyTransaction(s){delete this._transactions[s.type][s.id],this.emit("transactionDestroyed",{transaction:s})}newDialog(s){this._dialogs[s.id]=s}destroyDialog(s){delete this._dialogs[s.id]}newMessage(s,i){this._applicants[s]=s,this.emit("newMessage",i)}newOptions(s,i){this._applicants[s]=s,this.emit("newOptions",i)}destroyMessage(s){delete this._applicants[s]}newRTCSession(s,i){this._sessions[s.id]=s,this.emit("newRTCSession",i)}destroyRTCSession(s){delete this._sessions[s.id]}registered(s){this.emit("registered",s)}unregistered(s){this.emit("unregistered",s)}registrationFailed(s){this.emit("registrationFailed",s)}receiveRequest(s){const i=s.method;if(s.ruri.user!==this._configuration.uri.user&&s.ruri.user!==this._contact.uri.user){Ke.debug("Request-URI does not point to us"),s.method!==Tt.ACK&&s.reply_sl(404);return}if(s.ruri.scheme===Tt.SIPS){s.reply_sl(416);return}if(Qo.checkTransaction(this,s))return;if(i===Tt.INVITE?new Qo.InviteServerTransaction(this,this._transport,s):i!==Tt.ACK&&i!==Tt.CANCEL&&new Qo.NonInviteServerTransaction(this,this._transport,s),i===Tt.OPTIONS){if(this.listeners("newOptions").length===0){s.reply(200);return}new Of(this).init_incoming(s)}else if(i===Tt.MESSAGE){if(this.listeners("newMessage").length===0){s.reply(405);return}new wf(this).init_incoming(s)}else if(i===Tt.INVITE&&!s.to_tag&&this.listeners("newRTCSession").length===0){s.reply(405);return}let l,a;if(s.to_tag)l=this._findDialog(s.call_id,s.from_tag,s.to_tag),l?l.receiveRequest(s):i===Tt.NOTIFY?(a=this._findSession(s),a?a.receiveRequest(s):(Ke.debug("received NOTIFY request for a non existent subscription"),s.reply(481,"Subscription does not exist"))):i!==Tt.ACK&&s.reply(481);else switch(i){case Tt.INVITE:if(window.RTCPeerConnection)if(s.hasHeader("replaces")){const _=s.replaces;l=this._findDialog(_.call_id,_.from_tag,_.to_tag),l?(a=l.owner,a.isEnded()?s.reply(603):a.receiveRequest(s)):s.reply(481)}else a=new bf(this),a.init_incoming(s);else Ke.warn("INVITE received but WebRTC is not supported"),s.reply(488);break;case Tt.BYE:s.reply(481);break;case Tt.CANCEL:a=this._findSession(s),a?a.receiveRequest(s):Ke.debug("received CANCEL request for a non existent session");break;case Tt.ACK:break;case Tt.NOTIFY:this.emit("sipEvent",{event:s.event,request:s}),s.reply(200);break;default:s.reply(405);break}}_findSession({call_id:s,from_tag:i,to_tag:l}){const a=s+i,_=this._sessions[a],e=s+l,p=this._sessions[e];return _||p||null}_findDialog(s,i,l){let a=s+i+l,_=this._dialogs[a];return _||(a=s+l+i,_=this._dialogs[a],_||null)}_loadConfig(s){try{eu.load(this._configuration,s)}catch(a){throw a}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=da.newUUID()),this._configuration.jssip_id=da.createRandomToken(5);const i=this._configuration.uri.clone();i.user=null,this._configuration.hostport_params=i.toString().replace(/^sip:/i,"");try{this._transport=new gT(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=yT.bind(this),this._transport.onconnect=AT.bind(this),this._transport.ondisconnect=CT.bind(this),this._transport.ondata=RT.bind(this)}catch(a){throw Ke.warn(a),new TT.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 a=this._configuration.uri.clone();a.user=null,a.clearParams(),a.clearHeaders(),this._configuration.registrar_server=a}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new vT("sip",da.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(a={}){const _=a.anonymous||null,e=a.outbound||null;let p="<";return _?p+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":p+=this.pub_gruu||this.uri.toString(),e&&(_?!this.temp_gruu:!this.pub_gruu)&&(p+=";ob"),p+=">",p}};const l=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const a in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,a)&&(l.indexOf(a)!==-1?Object.defineProperty(this._configuration,a,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,a,{writable:!1,configurable:!1}));Ke.debug("configuration parameters after validation:");for(const a in this._configuration)if(Object.prototype.hasOwnProperty.call(eu.settings,a))switch(a){case"uri":case"registrar_server":Ke.debug(`- ${a}: ${this._configuration[a]}`);break;case"password":case"ha1":case"authorization_jwt":Ke.debug(`- ${a}: NOT SHOWN`);break;default:Ke.debug(`- ${a}: ${JSON.stringify(this._configuration[a])}`)}}};function yT(c){this.emit("connecting",c)}function AT(c){this._status!==St.STATUS_USER_CLOSED&&(this._status=St.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function CT(c){const s=["nict","ict","nist","ist"];for(const i of s)for(const l in this._transactions[i])Object.prototype.hasOwnProperty.call(this._transactions[i],l)&&this._transactions[i][l].onTransportError();this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==St.STATUS_USER_CLOSED&&(this._status=St.STATUS_NOT_READY,this._error=St.NETWORK_ERROR)}function RT(c){console.log("onTransportData",c);const s=c.transport;let i=c.message;if(i=ET.parseMessage(i,this),!!i&&!(this._status===St.STATUS_USER_CLOSED&&i instanceof Zo.IncomingRequest)&&ST(i,this,s)){if(i instanceof Zo.IncomingRequest)i.transport=s,this.receiveRequest(i);else if(i instanceof Zo.IncomingResponse){let l;switch(i.method){case Tt.INVITE:l=this._transactions.ict[i.via_branch],l&&l.receiveResponse(i);break;case Tt.ACK:break;default:l=this._transactions.nict[i.via_branch],l&&l.receiveResponse(i);break}}}}const IT=tt(w_);var mt=[];for(var tu=0;tu<256;++tu)mt.push((tu+256).toString(16).slice(1));function bT(c,s=0){return(mt[c[s+0]]+mt[c[s+1]]+mt[c[s+2]]+mt[c[s+3]]+"-"+mt[c[s+4]]+mt[c[s+5]]+"-"+mt[c[s+6]]+mt[c[s+7]]+"-"+mt[c[s+8]]+mt[c[s+9]]+"-"+mt[c[s+10]]+mt[c[s+11]]+mt[c[s+12]]+mt[c[s+13]]+mt[c[s+14]]+mt[c[s+15]]).toLowerCase()}var pa,wT=new Uint8Array(16);function OT(){if(!pa&&(pa=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!pa))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return pa(wT)}var DT=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Df={randomUUID:DT};function Nf(c,s,i){if(Df.randomUUID&&!s&&!c)return Df.randomUUID();c=c||{};var l=c.random||(c.rng||OT)();if(l[6]=l[6]&15|64,l[8]=l[8]&63|128,s){i=i||0;for(var a=0;a<16;++a)s[i+a]=l[a];return s}return bT(l)}var $e=Ct();const ys=tt($e),su=new Za("Dialog"),Ys={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};class ma{static get C(){return Ys}constructor(s,i,l,a=Ys.STATUS_CONFIRMED){if(this._owner=s,this._ua=s._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,i instanceof Dt.IncomingResponse&&(a=i.status_code<200?Ys.STATUS_EARLY:Ys.STATUS_CONFIRMED),l==="UAS"){this._id={call_id:i.call_id,local_tag:i.to_tag,remote_tag:i.from_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._remote_seqnum=i.cseq,this._local_uri=i.parseHeader("to").uri,this._remote_uri=i.parseHeader("from").uri;let _=i.getHeaders("to")[0].split(";")[0];_=_.match(/<([^>]*)>/)[1],this._remote_target=_,this._route_set=i.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum}else if(l==="UAC"){this._id={call_id:i.call_id,local_tag:i.from_tag,remote_tag:i.to_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=a,this._local_seqnum=i.cseq,this._local_uri=i.parseHeader("from").uri,this._remote_uri=i.parseHeader("to").uri;let _=i.getHeaders("to")[0].split(";")[0];_=_.match(/<([^>]*)>/)[1],this._remote_target=_,this._route_set=i.getHeaders("record-route").reverse(),this._ack_seqnum=null}this._ua.newDialog(this),su.debug(`new ${l} dialog created with status ${this._state===Ys.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(s){this._local_seqnum=s}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(s){this._uac_pending_reply=s}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===Ys.STATUS_TERMINATED}update(s,i){this._state=Ys.STATUS_CONFIRMED,su.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),i==="UAC"&&(this._route_set=s.getHeaders("record-route").reverse())}terminate(){su.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Ys.STATUS_TERMINATED}sendRequest(s,i={}){const l=ys.cloneArray(i.extraHeaders),a=ys.cloneObject(i.eventHandlers),_=i.body||null,e=this._createRequest(s,l,_);return a.onAuthenticated=()=>{this._local_seqnum+=1},new cg(this,e,a).send(),e}receiveRequest(s){this._checkInDialogRequest(s)&&(s.method===F.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:s.method===F.INVITE&&(this._ack_seqnum=s.cseq),this._owner.receiveRequest(s))}_createRequest(s,i,l){i=ys.cloneArray(i),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const a=s===F.CANCEL||s===F.ACK?this._local_seqnum:this._local_seqnum+=1;return new Dt.OutgoingRequest(s,this._remote_target,this._ua,{cseq:a,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},i,l)}_checkInDialogRequest(s){if(!this._remote_seqnum)this._remote_seqnum=s.cseq;else if(s.cseq<this._remote_seqnum)if(s.method===F.ACK){if(this._ack_seqnum===null||s.cseq!==this._ack_seqnum)return!1}else return s.reply(500),!1;else s.cseq>this._remote_seqnum&&(this._remote_seqnum=s.cseq);if(s.method===F.INVITE||s.method===F.UPDATE&&s.body){if(this._uac_pending_reply===!0)s.reply(491);else if(this._uas_pending_reply===!0){const i=(Math.random()*10|0)+1;return s.reply(500,null,[`Retry-After:${i}`]),!1}else{this._uas_pending_reply=!0;const i=()=>{(s.server_transaction.state===Vt.C.STATUS_ACCEPTED||s.server_transaction.state===Vt.C.STATUS_COMPLETED||s.server_transaction.state===Vt.C.STATUS_TERMINATED)&&(s.server_transaction.removeListener("stateChanged",i),this._uas_pending_reply=!1)};s.server_transaction.on("stateChanged",i)}s.hasHeader("contact")&&s.server_transaction.on("stateChanged",()=>{s.server_transaction.state===Vt.C.STATUS_ACCEPTED&&(this._remote_target=s.parseHeader("contact").uri)})}else s.method===F.NOTIFY&&s.hasHeader("contact")&&s.server_transaction.on("stateChanged",()=>{s.server_transaction.state===Vt.C.STATUS_COMPLETED&&(this._remote_target=s.parseHeader("contact").uri)});return!0}}class NT{constructor(s,i){Kt(this,"plugin",null);Kt(this,"rtcpPeer",null);Kt(this,"handleId",0);Kt(this,"info",null);Kt(this,"joinResult",null);Kt(this,"state",{});Kt(this,"stream",null);Kt(this,"loaded",!1);Kt(this,"aTracks",[]);Kt(this,"vTracks",[]);this.info=s,this.plugin=i,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(s){var i;this.state={...this.state,...s||{}},(i=this.plugin)==null||i.session.emit("member:update",this.memberInfo)}updateMemberStateFromMessage(s){var _,e,p,g;const i=(e=(_=s==null?void 0:s.plugindata)==null?void 0:_.data)==null?void 0:e.newStatePublisher,a=((g=(p=s==null?void 0:s.plugindata)==null?void 0:p.data)==null?void 0:g.publisher_state).find(n=>n.id===i);this.updateMemberState(a==null?void 0:a.state)}hangup(){this.rtcpPeer&&(this.rtcpPeer.close(),this.rtcpPeer=null),this.stream&&this.stream.getTracks().forEach(s=>{s.stop()})}}var UT=Is();const ar=tt(UT),Z=new Za("JanusSession"),PT="/opt/recordings/",ne={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},ga=["audio","video"];class Wa extends ht.EventEmitter{static get C(){return ne}constructor(s){Z.debug("new"),super(),console.log("constructor call"),this._id=null,this._ua=s,this._status=ne.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:F.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"}];const i=Nf().replace(/-/g,"").slice(0,12);this.opaque_id=`videoroomtest-${i}`,this._data={}}get C(){return ne}get causes(){return F.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(s){this._data=s}get status(){return this._status}isInProgress(){switch(this._status){case ne.STATUS_NULL:case ne.STATUS_INVITE_SENT:case ne.STATUS_1XX_RECEIVED:case ne.STATUS_INVITE_RECEIVED:case ne.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case ne.STATUS_ANSWERED:case ne.STATUS_WAITING_FOR_ACK:case ne.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case ne.STATUS_CANCELED:case ne.STATUS_TERMINATED:return!0;default:return!1}}isMuted(){return{audio:this._audioMuted,video:this._videoMuted}}isOnHold(){return{local:this._localHold,remote:this._remoteHold}}connect(s,i,l={},a){Z.debug("connect()"),this.display_name=i;const _=s,e=$e.cloneObject(l.eventHandlers),p=$e.cloneArray(l.extraHeaders),g=$e.cloneObject(l.mediaConstraints,{audio:!0,video:!0}),n=l.mediaStream||null,v=$e.cloneObject(l.pcConfig,{iceServers:[]}),S=l.rtcConstraints||null,m=l.rtcOfferConstraints||null;if(this._rtcOfferConstraints=m,this._rtcAnswerConstraints=l.rtcAnswerConstraints||null,this._data=l.data||this._data,s===void 0)throw new TypeError("Not enough arguments");if(this._status!==ne.STATUS_NULL)throw new zs.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new zs.NotSupportedError("WebRTC not supported");if(console.log("target",s),s=this._ua.normalizeTarget(s),console.log("normalizeTarget target",s),this.room_id=s.user,!s)throw new TypeError(`Invalid target: ${_}`);this._sessionTimers.enabled&&$e.isDecimal(l.sessionTimersExpires)&&(l.sessionTimersExpires>=F.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=l.sessionTimersExpires:this._sessionTimers.defaultExpires=F.SESSION_EXPIRES);for(const R in e)Object.prototype.hasOwnProperty.call(e,R)&&this.on(R,e[R]);this._from_tag=$e.newTag();const C=l.anonymous||!1,A={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:C,outbound:!0}),C?(A.from_display_name="Anonymous",A.from_uri=new ar("sip","anonymous","anonymous.invalid"),p.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),p.push("Privacy: id")):l.fromUserName&&(A.from_uri=new ar("sip",l.fromUserName,this._ua.configuration.uri.host),p.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),l.fromDisplayName&&(A.from_display_name=l.fromDisplayName),p.push(`Contact: ${this._contact}`),p.push("Content-Type: application/json"),this._sessionTimers.enabled&&p.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new Dt.InitialOutgoingInviteRequest(s,this._ua,A,p),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(v,S),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,console.log("this._remote_identity",this._remote_identity),a&&a(this),this._newJanusSession("local",this._request),this._sendInitialRequest(g,m,n)}init_incoming(s,i){Z.debug("init_incoming()");let l;const a=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0;if(s.body&&a!=="application/sdp"){s.reply(415);return}if(this._status=ne.STATUS_INVITE_RECEIVED,this._from_tag=s.from_tag,this._id=s.call_id+this._from_tag,this._request=s,this._contact=this._ua.contact.toString(),s.hasHeader("expires")&&(l=s.getHeader("expires")*1e3),s.to_tag=$e.newTag(),!this._createDialog(s,"UAS",!0)){s.reply(500,"Missing Contact header field");return}s.body?this._late_sdp=!1:this._late_sdp=!0,this._status=ne.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{s.reply(408),this._failed("local",null,F.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),l&&(this._timers.expiresTimer=setTimeout(()=>{this._status===ne.STATUS_WAITING_FOR_ANSWER&&(s.reply(487),this._failed("system",null,F.causes.EXPIRES))},l)),this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from,i&&i(this),this._newJanusSession("remote",s),this._status!==ne.STATUS_TERMINATED&&(s.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(s={}){Z.debug("answer()");const i=this._request,l=$e.cloneArray(s.extraHeaders),a=$e.cloneObject(s.mediaConstraints),_=s.mediaStream||null,e=$e.cloneObject(s.pcConfig,{iceServers:[]}),p=s.rtcConstraints||null,g=s.rtcAnswerConstraints||null,n=$e.cloneObject(s.rtcOfferConstraints);let v,S=!1,m=!1,C=!1,A=!1;if(this._rtcAnswerConstraints=g,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!==ne.STATUS_WAITING_FOR_ANSWER)throw new zs.InvalidStateError(this._status);if(this._sessionTimers.enabled&&$e.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=F.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=F.SESSION_EXPIRES),this._status=ne.STATUS_ANSWERED,!this._createDialog(i,"UAS")){i.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),l.unshift(`Contact: ${this._contact}`);const R=i.parseSDP();Array.isArray(R.media)||(R.media=[R.media]);for(const I of R.media)I.type==="audio"&&(S=!0,(!I.direction||I.direction==="sendrecv")&&(C=!0)),I.type==="video"&&(m=!0,(!I.direction||I.direction==="sendrecv")&&(A=!0));if(_&&a.audio===!1){v=_.getAudioTracks();for(const I of v)_.removeTrack(I)}if(_&&a.video===!1){v=_.getVideoTracks();for(const I of v)_.removeTrack(I)}!_&&a.audio===void 0&&(a.audio=C),!_&&a.video===void 0&&(a.video=A),!_&&!S&&!n.offerToReceiveAudio&&(a.audio=!1),!_&&!m&&!n.offerToReceiveVideo&&(a.video=!1),this._createRTCConnection(e,p),Promise.resolve().then(()=>{if(_)return _;if(a.audio||a.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(a).catch(I=>{throw this._status===ne.STATUS_TERMINATED?new Error("terminated"):(i.reply(480),this._failed("local",null,F.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===ne.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=I,I&&I.getTracks().forEach(V=>{this._connection.addTrack(V,I)})}).then(()=>{if(this._late_sdp)return;const I={originator:"remote",type:"offer",sdp:i.body};Z.debug('emit "sdp"'),this.emit("sdp",I);const V=new RTCSessionDescription({type:"offer",sdp:I.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(V)).catch(W=>{throw i.reply(488),this._failed("system",null,F.causes.WEBRTC_ERROR),Z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',W),this.emit("peerconnection:setremotedescriptionfailed",W),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===ne.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(i),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw i.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",g).catch(()=>{throw i.reply(500),new Error("_createLocalDescription() failed")})}).then(I=>{if(this._status===ne.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(i,l),i.reply(200,null,l,I,()=>{this._status=ne.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(i,I),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,F.causes.CONNECTION_ERROR)})}).catch(I=>{this._status!==ne.STATUS_TERMINATED&&Z.warn(I)})}terminate(s={}){Z.debug("terminate()");const i=s.cause||F.causes.BYE,l=$e.cloneArray(s.extraHeaders),a=s.body;let _,e=s.status_code,p=s.reason_phrase;if(this._status===ne.STATUS_TERMINATED)throw new zs.InvalidStateError(this._status);switch(this._status){case ne.STATUS_NULL:case ne.STATUS_INVITE_SENT:case ne.STATUS_1XX_RECEIVED:if(Z.debug("canceling session"),e&&(e<200||e>=700))throw new TypeError(`Invalid status_code: ${e}`);e&&(p=p||F.REASON_PHRASE[e]||"",_=`SIP ;cause=${e} ;text="${p}"`),this._status===ne.STATUS_NULL||this._status===ne.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=_):this._status===ne.STATUS_1XX_RECEIVED&&this._request.cancel(_),this._status=ne.STATUS_CANCELED,this._failed("local",null,F.causes.CANCELED);break;case ne.STATUS_WAITING_FOR_ANSWER:case ne.STATUS_ANSWERED:if(Z.debug("rejecting session"),e=e||480,e<300||e>=700)throw new TypeError(`Invalid status_code: ${e}`);this._request.reply(e,p,l,a),this._failed("local",null,F.causes.REJECTED);break;case ne.STATUS_WAITING_FOR_ACK:case ne.STATUS_CONFIRMED:if(Z.debug("terminating session"),p=s.reason_phrase||F.REASON_PHRASE[e]||"",e&&(e<200||e>=700))throw new TypeError(`Invalid status_code: ${e}`);if(e&&l.push(`Reason: SIP ;cause=${e}; text="${p}"`),this._status===ne.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Vt.C.STATUS_TERMINATED){const g=this._dialog;this.receiveRequest=({method:n})=>{n===F.ACK&&(this.sendRequest(F.BYE,{extraHeaders:l,body:a}),g.terminate(),this.closeSession())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Vt.C.STATUS_TERMINATED&&(this.sendRequest(F.BYE,{extraHeaders:l,body:a}),g.terminate(),this.closeSession())}),this._ended("local",null,i),this._dialog=g,console.log("SET DIALOG terminate"),this._ua.newDialog(g)}else{const g={janus:"leave"},n=["Content-Type: application/json","PTYPE: Leave"];this.sendRequest(F.BYE,{extraHeaders:n,body:JSON.stringify(g)}),this.closeSession(),this._ended("local",null,i)}}}sendInfo(s,i,l={}){if(Z.debug("sendInfo()"),this._status!==ne.STATUS_CONFIRMED&&this._status!==ne.STATUS_WAITING_FOR_ACK&&this._status!==ne.STATUS_1XX_RECEIVED)throw new zs.InvalidStateError(this._status);new yu(this).send(s,i,l)}mute(s={audio:!0,video:!1}){Z.debug("mute()");let i=!1,l=!1;this._audioMuted===!1&&s.audio&&(i=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&s.video&&(l=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(i===!0||l===!0)&&this._onmute({audio:i,video:l})}unmute(s={audio:!0,video:!0}){Z.debug("unmute()");let i=!1,l=!1;this._audioMuted===!0&&s.audio&&(i=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&s.video&&(l=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(i===!0||l===!0)&&this._onunmute({audio:i,video:l})}hold(s={},i){if(Z.debug("hold()"),this._status!==ne.STATUS_WAITING_FOR_ACK&&this._status!==ne.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");const l={succeeded:()=>{i&&i()},failed:()=>{this.terminate({cause:F.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:l,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:l,extraHeaders:s.extraHeaders}),!0}unhold(s={},i){if(Z.debug("unhold()"),this._status!==ne.STATUS_WAITING_FOR_ACK&&this._status!==ne.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");const l={succeeded:()=>{i&&i()},failed:()=>{this.terminate({cause:F.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:l,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:l,extraHeaders:s.extraHeaders}),!0}renegotiate(s={},i){Z.debug("renegotiate()");const l=s.rtcOfferConstraints||null;if(this._status!==ne.STATUS_WAITING_FOR_ACK&&this._status!==ne.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const a={succeeded:()=>{i&&i()},failed:()=>{this.terminate({cause:F.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,rtcOfferConstraints:l,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:a,rtcOfferConstraints:l,extraHeaders:s.extraHeaders}),!0}refer(s,i){Z.debug("refer()");const l=s;if(this._status!==ne.STATUS_WAITING_FOR_ACK&&this._status!==ne.STATUS_CONFIRMED)return!1;if(s=this._ua.normalizeTarget(s),!s)throw new TypeError(`Invalid target: ${l}`);const a=new Og(this);a.sendRefer(s,i);const _=a.id;return this._referSubscribers[_]=a,a.on("requestFailed",()=>{delete this._referSubscribers[_]}),a.on("accepted",()=>{delete this._referSubscribers[_]}),a.on("failed",()=>{delete this._referSubscribers[_]}),a}sendRequest(s,i){return Z.debug("sendRequest()"),this._dialog.sendRequest(s,i)}receiveNotify(s){Z.debug("receiveRequest()")}receiveRequest(s){if(Z.debug("receiveRequest()"),s.method===F.CANCEL)(this._status===ne.STATUS_WAITING_FOR_ANSWER||this._status===ne.STATUS_ANSWERED)&&(this._status=ne.STATUS_CANCELED,this._request.reply(487),this._failed("remote",s,F.causes.CANCELED));else switch(s.method){case F.ACK:if(this._status!==ne.STATUS_WAITING_FOR_ACK)return;if(this._status=ne.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!s.body){this.terminate({cause:F.causes.MISSING_SDP,status_code:400});break}const i={originator:"remote",type:"answer",sdp:s.body};Z.debug('emit "sdp"'),this.emit("sdp",i);const l=new RTCSessionDescription({type:"answer",sdp:i.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(l)).then(()=>{this._is_confirmed||this._confirmed("remote",s)}).catch(a=>{this.terminate({cause:F.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),Z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})}else this._is_confirmed||this._confirmed("remote",s);break;case F.BYE:this._status===ne.STATUS_CONFIRMED||this._status===ne.STATUS_WAITING_FOR_ACK?(s.reply(200),this._ended("remote",s,F.causes.BYE)):this._status===ne.STATUS_INVITE_RECEIVED||this._status===ne.STATUS_WAITING_FOR_ANSWER?(s.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",s,F.causes.BYE)):s.reply(403,"Wrong Status");break;case F.INVITE:this._status===ne.STATUS_CONFIRMED?s.hasHeader("replaces")?this._receiveReplaces(s):this._receiveReinvite(s):s.reply(403,"Wrong Status");break;case F.INFO:if(this._status===ne.STATUS_1XX_RECEIVED||this._status===ne.STATUS_WAITING_FOR_ANSWER||this._status===ne.STATUS_ANSWERED||this._status===ne.STATUS_WAITING_FOR_ACK||this._status===ne.STATUS_CONFIRMED){const i=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0;i&&i.match(/^application\/dtmf-relay/i)?new Tg(this).init_incoming(s):i!==void 0?new yu(this).init_incoming(s):s.reply(415)}else s.reply(403,"Wrong Status");break;case F.UPDATE:this._status===ne.STATUS_CONFIRMED?this._receiveUpdate(s):s.reply(403,"Wrong Status");break;case F.REFER:this._status===ne.STATUS_CONFIRMED?this._receiveRefer(s):s.reply(403,"Wrong Status");break;case F.NOTIFY:this._status===ne.STATUS_CONFIRMED?this._receiveNotify(s):s.reply(403,"Wrong Status");break;default:s.reply(501)}}onTransportError(){Z.warn("onTransportError()"),this._status!==ne.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:F.causes.CONNECTION_ERROR,cause:F.causes.CONNECTION_ERROR})}onRequestTimeout(){Z.warn("onRequestTimeout()"),this._status!==ne.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:F.causes.REQUEST_TIMEOUT,cause:F.causes.REQUEST_TIMEOUT})}onDialogError(){Z.warn("onDialogError()"),this._status!==ne.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:F.causes.DIALOG_ERROR,cause:F.causes.DIALOG_ERROR})}newDTMF(s){Z.debug("newDTMF()"),this.emit("newDTMF",s)}newInfo(s){Z.debug("newInfo()"),this.emit("newInfo",s)}_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"),$e.closeMediaStream(this._localMediaStream)),this._status!==ne.STATUS_TERMINATED){if(this._status=ne.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(s){Z.warn("close() | error closing the RTCPeerConnection: %o",s)}for(const s in this._timers)Object.prototype.hasOwnProperty.call(this._timers,s)&&clearTimeout(this._timers[s]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const s in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,s)&&(this._earlyDialogs[s].terminate(),delete this._earlyDialogs[s]);for(const s in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,s)&&delete this._referSubscribers[s];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(s,i){let l=Mi.T1;function a(){this._status===ne.STATUS_WAITING_FOR_ACK&&(s.reply(200,null,[`Contact: ${this._contact}`],i),l<Mi.T2&&(l=l*2,l>Mi.T2&&(l=Mi.T2)),this._timers.invite2xxTimer=setTimeout(a.bind(this),l))}this._timers.invite2xxTimer=setTimeout(a.bind(this),l)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===ne.STATUS_WAITING_FOR_ACK&&(Z.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(F.BYE),this._ended("remote",null,F.causes.NO_ACK))},Mi.TIMER_H)}_createRTCConnection(s,i){this.stunServers,this._connection=new RTCPeerConnection(s,i),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:F.causes.RTP_TIMEOUT,status_code:408,reason_phrase:F.causes.RTP_TIMEOUT})});let l;const a=_=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||_.candidate&&(this._candidates.push(_.candidate),clearTimeout(l),l=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=a,Z.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(s,i){if(Z.debug("createLocalDescription()"),s!=="offer"&&s!=="answer")throw new Error(`createLocalDescription() | invalid type "${s}"`);const l=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>s==="offer"?l.createOffer(i).catch(a=>(Z.warn('emit "peerconnection:createofferfailed" [error:%o]',a),this.emit("peerconnection:createofferfailed",a),Promise.reject(a))):l.createAnswer(i).catch(a=>(Z.warn('emit "peerconnection:createanswerfailed" [error:%o]',a),this.emit("peerconnection:createanswerfailed",a),Promise.reject(a)))).then(a=>l.setLocalDescription(a).catch(_=>(this._rtcReady=!0,Z.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',_),this.emit("peerconnection:setlocaldescriptionfailed",_),Promise.reject(_)))).then(()=>{const a=i&&i.iceRestart;if(l.iceGatheringState==="complete"&&!a||l.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const _={originator:"local",type:s,sdp:l.localDescription.sdp};return Z.debug('emit "sdp"'),this.emit("sdp",_),Promise.resolve(_.sdp)}return new Promise(_=>{let e=!1,p,g;this._iceReady=!1;const n=()=>{l.removeEventListener("icecandidate",p),l.removeEventListener("icegatheringstatechange",g),e=!0,this._rtcReady=!0,this._iceReady=!0;const v={originator:"local",type:s,sdp:l.localDescription.sdp};Z.debug('emit "sdp"'),this.emit("sdp",v),_(v.sdp)};l.addEventListener("icecandidate",p=v=>{const S=v.candidate;S?this.emit("icecandidate",{candidate:S,ready:n}):e||n()}),l.addEventListener("icegatheringstatechange",g=()=>{l.iceGatheringState==="complete"&&!e&&n()})})})}_createDialog(s,i,l){console.log("_createDialog",s);const a=i==="UAS"?s.to_tag:s.from_tag,_=i==="UAS"?s.from_tag:s.to_tag,e=s.call_id+a+_;console.log("remote_tag",_);let p=this._earlyDialogs[e];if(l)return p?!0:(p=new ma(this,s,i,ma.C.STATUS_EARLY),console.log("SET DIALOG early"),p.error?(console.log("early_dialog error",p.error),Z.debug(p.error),this._failed("remote",s,F.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[e]=p,!0));{if(this._from_tag=s.from_tag,this._to_tag=s.to_tag,p)return p.update(s,i),console.log("SET DIALOG 1"),this._dialog=p,delete this._earlyDialogs[e],!0;const g=new ma(this,s,i);return g.error?(console.log("dialog.error",g.error),Z.debug(g.error),this._failed("remote",s,F.causes.INTERNAL_ERROR),!1):(console.log("AAA SET DIALOG 2"),this._dialog=g,!0)}}_receiveReinvite(s){Z.debug("receiveReinvite()");const i=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0,l={request:s,callback:void 0,reject:_.bind(this)};let a=!1;function _(p={}){a=!0;const g=p.status_code||403,n=p.reason_phrase||"",v=$e.cloneArray(p.extraHeaders);if(this._status!==ne.STATUS_CONFIRMED)return!1;if(g<300||g>=700)throw new TypeError(`Invalid status_code: ${g}`);s.reply(g,n,v)}if(this.emit("reinvite",l),a)return;if(this._late_sdp=!1,!s.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(p=>{e.call(this,p)}).catch(()=>{s.reply(500)});return}if(i!=="application/sdp"){Z.debug("invalid Content-Type"),s.reply(415);return}this._processInDialogSdpOffer(s).then(p=>{this._status!==ne.STATUS_TERMINATED&&e.call(this,p)}).catch(p=>{Z.warn(p)});function e(p){const g=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(s,g),this._late_sdp&&(p=this._mangleOffer(p)),s.reply(200,null,g,p,()=>{this._status=ne.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(s,p),this._setACKTimer()}),typeof l.callback=="function"&&l.callback()}}_receiveUpdate(s){Z.debug("receiveUpdate()");const i=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0,l={request:s,callback:void 0,reject:_.bind(this)};let a=!1;function _(p={}){a=!0;const g=p.status_code||403,n=p.reason_phrase||"",v=$e.cloneArray(p.extraHeaders);if(this._status!==ne.STATUS_CONFIRMED)return!1;if(g<300||g>=700)throw new TypeError(`Invalid status_code: ${g}`);s.reply(g,n,v)}if(this.emit("update",l),a)return;if(!s.body){e.call(this,null);return}if(i!=="application/sdp"){Z.debug("invalid Content-Type"),s.reply(415);return}this._processInDialogSdpOffer(s).then(p=>{this._status!==ne.STATUS_TERMINATED&&e.call(this,p)}).catch(p=>{Z.warn(p)});function e(p){const g=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(s,g),s.reply(200,null,g,p),typeof l.callback=="function"&&l.callback()}}_processInDialogSdpOffer(s){Z.debug("_processInDialogSdpOffer()");const i=s.parseSDP();let l=!1;for(const e of i.media){if(ga.indexOf(e.type)===-1)continue;const p=e.direction||i.direction||"sendrecv";if(p==="sendonly"||p==="inactive")l=!0;else{l=!1;break}}const a={originator:"remote",type:"offer",sdp:s.body};Z.debug('emit "sdp"'),this.emit("sdp",a);const _=new RTCSessionDescription({type:"offer",sdp:a.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===ne.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(_).catch(e=>{throw s.reply(488),Z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),this.emit("peerconnection:setremotedescriptionfailed",e),e})}).then(()=>{if(this._status===ne.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&l===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&l===!0&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===ne.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(e=>{throw s.reply(500),Z.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',e),e})}).catch(e=>{Z.warn("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}_receiveRefer(s){if(Z.debug("receiveRefer()"),!s.refer_to){Z.debug("no Refer-To header field present in REFER"),s.reply(400);return}if(s.refer_to.uri.scheme!==F.SIP){Z.debug("Refer-To header field points to a non-SIP URI scheme"),s.reply(416);return}s.reply(202);const i=new Rg(this,s.cseq);Z.debug('emit "refer"'),this.emit("refer",{request:s,accept:(_,e)=>{l.call(this,_,e)},reject:()=>{a.call(this)}});function l(_,e={}){if(_=typeof _=="function"?_:null,this._status!==ne.STATUS_WAITING_FOR_ACK&&this._status!==ne.STATUS_CONFIRMED)return!1;const p=new Wa(this._ua);if(p.on("progress",({response:g})=>{i.notify(g.status_code,g.reason_phrase)}),p.on("accepted",({response:g})=>{i.notify(g.status_code,g.reason_phrase)}),p.on("_failed",({message:g,cause:n})=>{g?i.notify(g.status_code,g.reason_phrase):i.notify(487,n)}),s.refer_to.uri.hasHeader("replaces")){const g=decodeURIComponent(s.refer_to.uri.getHeader("replaces"));e.extraHeaders=$e.cloneArray(e.extraHeaders),e.extraHeaders.push(`Replaces: ${g}`)}p.connect(s.refer_to.uri.toAor(),e,_)}function a(){i.notify(603)}}_receiveNotify(s){switch(Z.debug("receiveNotify()"),s.event||s.reply(400),s.event.event){case"refer":{let i,l;if(s.event.params&&s.event.params.id)i=s.event.params.id,l=this._referSubscribers[i];else if(Object.keys(this._referSubscribers).length===1)l=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{s.reply(400,"Missing event id parameter");return}if(!l){s.reply(481,"Subscription does not exist");return}l.receiveNotify(s),s.reply(200);break}default:s.reply(489)}}_receiveReplaces(s){Z.debug("receiveReplaces()");function i(a){if(this._status!==ne.STATUS_WAITING_FOR_ACK&&this._status!==ne.STATUS_CONFIRMED)return!1;const _=new Wa(this._ua);_.on("confirmed",()=>{this.terminate()}),_.init_incoming(s,a)}function l(){Z.debug("Replaced INVITE rejected by the user"),s.reply(486)}this.emit("replaces",{request:s,accept:a=>{i.call(this,a)},reject:()=>{l.call(this)}})}_getNextTransactionId(){return(this.lastTransaction+1).toString()}_sendInitialRequest(s,i,l){this.ackSent=!1,this.publisherSubscribeSent=!1;const a=new Ga(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:_=>{this._request=_},onReceiveResponse:_=>{this._receiveInviteResponse(_)}});Promise.resolve().then(()=>{if(l)return l;if(s.audio||s.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(s).catch(_=>{throw this._status===ne.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,F.causes.USER_DENIED_MEDIA_ACCESS),Z.warn('emit "getusermediafailed" [error:%o]',_),this.emit("getusermediafailed",_),_)})}).then(_=>{if(this._status===ne.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=_,_&&_.getTracks().forEach(e=>{this._connection.addTrack(e,_)}),this._connecting(this._request),this._createLocalDescription("offer",i).catch(e=>{throw this._failed("local",null,F.causes.WEBRTC_ERROR),e})}).then(_=>{if(this._is_canceled||this._status===ne.STATUS_TERMINATED)throw new Error("terminated");const e={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaque_id},p=JSON.stringify(e);this._request.body=p,this._status=ne.STATUS_INVITE_SENT,Z.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),a.send()}).catch(_=>{this._status!==ne.STATUS_TERMINATED&&Z.warn(_)})}requestAudioAndVideoPermissions(){return this.loadStream()}async loadStream(){const s={audio:!0,video:!0};try{this.stream=await navigator.mediaDevices.getUserMedia(s)}catch{try{s.video=!1,this.stream=await navigator.mediaDevices.getUserMedia(s)}catch{s.audio=!1,s.video=!1,this.stream=await navigator.mediaDevices.getUserMedia(s)}}return{stream:this.stream,options:s}}addTracks(s){s.forEach(i=>{this._connection.addTrack(i)})}getRecordFileName(){return PT+this.room_id+btoa(unescape(encodeURIComponent(this.displayName)))+Date.now()}async processIceCandidates(){for(let s=0;s<this.iceCandidates.length;s++)await this._connection.addIceCandidate(this.iceCandidates[s]);this.iceCandidates=[]}async _sendConfigureMessage(s){const i={offerToReceiveAudio:!1,offerToReceiveVideo:!1},l=await this._connection.createOffer(i);await this._connection.setLocalDescription(l);const a=this._candidates.map(g=>({janus:"trickle",candidate:g,handle_id:this.handle_id,session_id:this.session_id})),e={configure:{janus:"message",body:{request:"configure",record:!0,filename:this.getRecordFileName(),...s},jsep:l,handle_id:this.handle_id,session_id:this.session_id},trickles:[...a]},p=["Content-Type: application/json","PTYPE: Ice"];this.sendRequest(F.INFO,{extraHeaders:p,body:JSON.stringify(e),eventHandlers:{onSuccessResponse:async g=>{this.isConfigureSent=!0;const v=g.data.split(`\r
135
+ `),S=v[v.length-1],m=JSON.parse(S);await this._connection.setRemoteDescription(m.jsep),this._candidates=[]}}})}_sendMemberStartMessage(s,i){const l={janus:"message",body:{request:"start",room:this.room_id},handle_id:s.handleId,session_id:this.session_id,jsep:i},a=["Content-Type: application/json","PTYPE: Configure"];this.sendRequest(F.INFO,{extraHeaders:a,body:JSON.stringify(l),eventHandlers:{onSuccessResponse:async _=>{_.status_code===200&&await s.rtcpPeer.setLocalDescription(i)}}})}_sendTrickleMessage(s){const l={trickles:[...s.map(_=>({janus:"trickle",candidate:_,handle_id:this.handle_id,session_id:this.session_id}))]},a=["PTYPE: Trickle"];this.sendRequest(F.INFO,{extraHeaders:a,body:JSON.stringify(l),eventHandlers:{onSuccessResponse:async _=>{console.log("_sendTrickleMessage",_)}}})}async _answerAttachedStream(s,i){let l=null;const a=async g=>{if(!s.rtcpPeer||s.loaded)return;{s.loaded=!0;const C={audio:!0,video:!0};await new Promise(A=>{setTimeout(A,100)}),l=await s.rtcpPeer.createAnswer(C),this._sendMemberStartMessage(s,l)}const n=g.streams[0].getAudioTracks(),v=g.streams[0].getVideoTracks(),S=[];n[0]&&S.push(n[0]),v[0]&&S.push(v[0]);const m=new MediaStream(S);s.stream=m,this._ua.emit("memberJoin",s.memberInfo)};let _,e=[];const p=g=>{s.rtcpPeer.signalingState!=="stable"&&s.rtcpPeer.signalingState!=="have-local-offer"||(e.push(g.candidate||null),clearTimeout(_),_=setTimeout(()=>{this._sendTrickleMessage(e)},500))};s.rtcpPeer=new RTCPeerConnection,s.rtcpPeer.ontrack=a,s.rtcpPeer.onicecandidate=p,s.rtcpPeer.sender=i.sender,await s.rtcpPeer.setRemoteDescription(i.jsep)}_sendJoinMemberRequest(s){const i={janus:"message",body:{request:"join",room:this.room_id,feed:s.info.id,ptype:"subscriber"},handle_id:s.handleId,session_id:this.session_id},l=["PTYPE: Subscriber"];this.sendRequest(F.SUBSCRIBE,{extraHeaders:l,body:JSON.stringify(i),eventHandlers:{onSuccessResponse:async a=>{var _,e;if(a.status_code===200){const p=JSON.parse(a.body);(e=(_=p==null?void 0:p.plugindata)==null?void 0:_.data)!=null&&e.id&&await this._answerAttachedStream(s,p)}}}})}_attachMember(s){const i={janus:"attach",opaque_id:this.opaque_id,plugin:"janus.plugin.videoroom",session_id:this.session_id},l=["PTYPE: Subscriber"];this.sendRequest(F.INFO,{extraHeaders:l,body:JSON.stringify(i),eventHandlers:{onSuccessResponse:async a=>{if(a.status_code===200){const e=JSON.parse(a.body).data.id;s.handleId=e,this._sendJoinMemberRequest(s)}}}})}_detachMember(s){const i={janus:"detach",handle_id:s.handleId,session_id:this.session_id},l=["PTYPE: Subscriber"];this.sendRequest(F.INFO,{extraHeaders:l,body:JSON.stringify(i)}),this._ua.emit("memberHangup",s.memberInfo)}receivePublishers(s){var l,a,_,e,p,g,n,v;const i={...this.memberList};(a=(l=s==null?void 0:s.plugindata)==null?void 0:l.data)==null||a.publishers.forEach(S=>{delete i[S.id],!this.memberList[S.id]&&!this.myFeedList.includes(S.id)&&S.clientID!==this.client_id&&(this.memberList[S.id]=new NT(S,this),this._attachMember(this.memberList[S.id]))}),((e=(_=s==null?void 0:s.plugindata)==null?void 0:_.data)==null?void 0:e.videoroom)==="synced"&&Object.keys(i).forEach(S=>{i[S].hangup(),delete this.memberList[S]}),this.publishers=(g=(p=s==null?void 0:s.plugindata)==null?void 0:p.data)==null?void 0:g.publishers,this.private_id=(v=(n=s==null?void 0:s.plugindata)==null?void 0:n.data)==null?void 0:v.private_id}receiveUnpublished(s){const i=this.memberList[s];i&&(i.hangup(),this._detachMember(i),delete this.memberList[s])}closeSession(){this.stream&&this.stream.getTracks().forEach(i=>{i.stop()}),Object.values(this.memberList).forEach(i=>{i.hangup(),this._detachMember(i)})}_receiveInviteResponse(s){if(Z.debug("receiveInviteResponse()"),console.log("_receiveInviteResponse response",s),console.log("dialog",this._dialog),this._dialog&&s.status_code>=200&&s.status_code<=299&&!this.ackSent)if(console.log("IF 1 dialog"),this._dialog.id.call_id===s.call_id&&this._dialog.id.local_tag===s.from_tag&&this._dialog.id.remote_tag===s.to_tag){this.ackSent=!0,this.sendRequest(F.ACK);return}else{const i=new ma(this,s,"UAC");if(i.error!==void 0){Z.debug(i.error);return}this.sendRequest(F.ACK),this.sendRequest(F.BYE);return}if(this.ackSent&&!this.publisherSubscribeSent){const i=JSON.parse(s.body);this.requestAudioAndVideoPermissions().then(()=>{this.session_id=i.session_id,this.handle_id=i.data.id,this.client_id=Nf();const l={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},a=["PTYPE: Publisher"];this.sendRequest(F.SUBSCRIBE,{extraHeaders:a,body:JSON.stringify(l),eventHandlers:{onSuccessResponse:async _=>{var e,p;if(_.status_code===200){if(this.subscribeSent=!0,_.body)try{const g=JSON.parse(_.body)||{};(p=(e=g.plugindata)==null?void 0:e.data)!=null&&p.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.publisherSubscribeSent=!0})}if(this._is_canceled){s.status_code>=100&&s.status_code<200?this._request.cancel(this._cancel_reason):s.status_code>=200&&s.status_code<299&&this._acceptAndTerminate(s);return}if(!(this._status!==ne.STATUS_INVITE_SENT&&this._status!==ne.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(s.status_code):this._status=ne.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(s.status_code):{if(!s.to_tag){Z.debug("1xx response received without to tag");break}if(s.hasHeader("contact")&&!this._createDialog(s,"UAC",!0))break;if(this._status=ne.STATUS_1XX_RECEIVED,!s.body){this._progress("remote",s);break}const i={originator:"remote",type:"answer",sdp:s.body};Z.debug('emit "sdp"'),this.emit("sdp",i);const l=new RTCSessionDescription({type:"answer",sdp:i.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(l)).then(()=>this._progress("remote",s)).catch(a=>{Z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)});break}case/^2[0-9]{2}$/.test(s.status_code):{if(this._status=ne.STATUS_CONFIRMED,!s.body){this._acceptAndTerminate(s,400,F.causes.MISSING_SDP),this._failed("remote",s,F.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(s,"UAC"))break;break}default:{const i=$e.sipErrorCause(s.status_code);this._failed("remote",s,i)}}}_sendReinvite(s={}){Z.debug("sendReinvite()");const i=$e.cloneArray(s.extraHeaders),l=$e.cloneObject(s.eventHandlers),a=s.rtcOfferConstraints||this._rtcOfferConstraints||null;let _=!1;i.push(`Contact: ${this._contact}`),i.push("Content-Type: application/sdp"),this._sessionTimers.running&&i.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",a)).then(g=>{g=this._mangleOffer(g);const n={originator:"local",type:"offer",sdp:g};Z.debug('emit "sdp"'),this.emit("sdp",n),this.sendRequest(F.INVITE,{extraHeaders:i,body:g,eventHandlers:{onSuccessResponse:v=>{e.call(this,v),_=!0},onErrorResponse:v=>{p.call(this,v)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{p()});function e(g){if(this._status===ne.STATUS_TERMINATED||(this.sendRequest(F.ACK),_))return;if(this._handleSessionTimersInIncomingResponse(g),g.body){if(!g.hasHeader("Content-Type")||g.getHeader("Content-Type").toLowerCase()!=="application/sdp"){p.call(this);return}}else{p.call(this);return}const n={originator:"remote",type:"answer",sdp:g.body};Z.debug('emit "sdp"'),this.emit("sdp",n);const v=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(v)).then(()=>{l.succeeded&&l.succeeded(g)}).catch(S=>{p.call(this),Z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',S),this.emit("peerconnection:setremotedescriptionfailed",S)})}function p(g){l.failed&&l.failed(g)}}_sendUpdate(s={}){Z.debug("sendUpdate()");const i=$e.cloneArray(s.extraHeaders),l=$e.cloneObject(s.eventHandlers),a=s.rtcOfferConstraints||this._rtcOfferConstraints||null,_=s.sdpOffer||!1;let e=!1;i.push(`Contact: ${this._contact}`),this._sessionTimers.running&&i.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),_?(i.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",a)).then(n=>{n=this._mangleOffer(n);const v={originator:"local",type:"offer",sdp:n};Z.debug('emit "sdp"'),this.emit("sdp",v),this.sendRequest(F.UPDATE,{extraHeaders:i,body:n,eventHandlers:{onSuccessResponse:S=>{p.call(this,S),e=!0},onErrorResponse:S=>{g.call(this,S)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{g.call(this)})):this.sendRequest(F.UPDATE,{extraHeaders:i,eventHandlers:{onSuccessResponse:n=>{p.call(this,n)},onErrorResponse:n=>{g.call(this,n)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function p(n){if(this._status!==ne.STATUS_TERMINATED&&!e)if(this._handleSessionTimersInIncomingResponse(n),_){if(n.body){if(!n.hasHeader("Content-Type")||n.getHeader("Content-Type").toLowerCase()!=="application/sdp"){g.call(this);return}}else{g.call(this);return}const v={originator:"remote",type:"answer",sdp:n.body};Z.debug('emit "sdp"'),this.emit("sdp",v);const S=new RTCSessionDescription({type:"answer",sdp:v.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(S)).then(()=>{l.succeeded&&l.succeeded(n)}).catch(m=>{g.call(this),Z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',m),this.emit("peerconnection:setremotedescriptionfailed",m)})}else l.succeeded&&l.succeeded(n)}function g(n){l.failed&&l.failed(n)}}_acceptAndTerminate(s,i,l){Z.debug("acceptAndTerminate()");const a=[];i&&(l=l||F.REASON_PHRASE[i]||"",a.push(`Reason: SIP ;cause=${i}; text="${l}"`)),(this._dialog||this._createDialog(s,"UAC"))&&(this.sendRequest(F.ACK),this.sendRequest(F.BYE,{extraHeaders:a})),this._status=ne.STATUS_TERMINATED}_mangleOffer(s){if(!this._localHold&&!this._remoteHold)return s;if(s=kt.parse(s),this._localHold&&!this._remoteHold){Z.debug("mangleOffer() | me on hold, mangling offer");for(const i of s.media)ga.indexOf(i.type)!==-1&&(i.direction?i.direction==="sendrecv"?i.direction="sendonly":i.direction==="recvonly"&&(i.direction="inactive"):i.direction="sendonly")}else if(this._localHold&&this._remoteHold){Z.debug("mangleOffer() | both on hold, mangling offer");for(const i of s.media)ga.indexOf(i.type)!==-1&&(i.direction="inactive")}else if(this._remoteHold){Z.debug("mangleOffer() | remote on hold, mangling offer");for(const i of s.media)ga.indexOf(i.type)!==-1&&(i.direction?i.direction==="sendrecv"?i.direction="recvonly":i.direction==="recvonly"&&(i.direction="inactive"):i.direction="recvonly")}return kt.write(s)}_setLocalMediaStatus(){let s=!0,i=!0;(this._localHold||this._remoteHold)&&(s=!1,i=!1),this._audioMuted&&(s=!1),this._videoMuted&&(i=!1),this._toggleMuteAudio(!s),this._toggleMuteVideo(!i)}_handleSessionTimersInIncomingRequest(s,i){if(!this._sessionTimers.enabled)return;let l;s.session_expires&&s.session_expires>=F.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=s.session_expires,l=s.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,l="uas"),i.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${l}`),this._sessionTimers.refresher=l==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(s){if(!this._sessionTimers.enabled)return;let i;s.session_expires&&s.session_expires>=F.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=s.session_expires,i=s.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,i="uac"),this._sessionTimers.refresher=i==="uac",this._runSessionTimer()}_runSessionTimer(){const s=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(()=>{this._status!==ne.STATUS_TERMINATED&&this._isReadyToReOffer()&&(Z.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===F.UPDATE?this._sendUpdate():this._sendReinvite())},s*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==ne.STATUS_TERMINATED&&(Z.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:F.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},s*1100)}_toggleMuteAudio(s){const i=this._connection.getSenders().filter(l=>l.track&&l.track.kind==="audio");for(const l of i)l.track.enabled=!s}_toggleMuteVideo(s){const i=this._connection.getSenders().filter(l=>l.track&&l.track.kind==="video");for(const l of i)l.track.enabled=!s}_newJanusSession(s,i){Z.debug("newRTCSession()"),this._ua.newJanusSession(this,{originator:s,session:this,request:i})}_connecting(s){Z.debug("session connecting"),Z.debug('emit "connecting"'),this.emit("connecting",{request:s})}_progress(s,i){Z.debug("session progress"),Z.debug('emit "progress"'),this.emit("progress",{originator:s,response:i||null})}_accepted(s,i){Z.debug("session accepted"),this._start_time=new Date,Z.debug('emit "accepted"'),this.emit("accepted",{originator:s,response:i||null})}_confirmed(s,i){Z.debug("session confirmed"),this._is_confirmed=!0,Z.debug('emit "confirmed"'),this.emit("confirmed",{originator:s,ack:i||null})}_ended(s,i,l){Z.debug("session ended"),this._end_time=new Date,this._close(),Z.debug('emit "ended"'),this.emit("ended",{originator:s,message:i||null,cause:l})}_failed(s,i,l){Z.debug("session failed"),Z.debug('emit "_failed"'),this.emit("_failed",{originator:s,message:i||null,cause:l}),this._close(),Z.debug('emit "failed"'),this.emit("failed",{originator:s,message:i||null,cause:l})}_onhold(s){Z.debug("session onhold"),this._setLocalMediaStatus(),Z.debug('emit "hold"'),this.emit("hold",{originator:s})}_onunhold(s){Z.debug("session onunhold"),this._setLocalMediaStatus(),Z.debug('emit "unhold"'),this.emit("unhold",{originator:s})}_onmute({audio:s,video:i}){Z.debug("session onmute"),this._setLocalMediaStatus(),Z.debug('emit "muted"'),this.emit("muted",{audio:s,video:i})}_onunmute({audio:s,video:i}){Z.debug("session onunmute"),this._setLocalMediaStatus(),Z.debug('emit "unmuted"'),this.emit("unmuted",{audio:s,video:i})}}class sr{constructor(s){if(this.headers={},s.length>0){let i=!1;const l=s.split(`\r
136
+ `),a=l.shift().split(/\s/);this.protocol=a[0],this.ident=a[1],this.code=a.length>3?parseInt(a[2]):0,this.method=a.length>3?a[3]:a[2],this.body="";for(const _ of l){if(_==`-------${this.ident}$`)break;if(_===""){i=!0;continue}if(_&&i)this.body+=`${_}\r
137
+ `;else{const e=_.split(": ");this.addHeader(e[0],e[1].trim())}}}else this.ident=$e.createRandomToken(12),this.protocol="MSRP"}addHeader(s,i){this.headers[s]=i}getHeader(s){return this.headers[s]}toString(){let s=`${this.protocol} ${this.ident} ${this.code} ${this.method}`.replaceAll(/null\s|undefined\s/ig,"")+`\r
138
+ `;for(const i in this.headers)s+=`${i}: ${this.headers[i]}\r
139
139
  `;return this.body&&(s+=`\r
140
140
  ${this.body}\r
141
141
  `),s+=`-------${this.ident}$\r
142
- `,s}}const Re={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 Za extends ft.EventEmitter{constructor(s){super(),this._id=null,this.my_ip="127.0.0.1",this._ua=s,this.auth_id=Me.createRandomToken(10),this._status=Re.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:s._configuration.authorization_user,ha1:s._configuration.ha1,realm:s._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:$.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._msrpKeepAliveTimer=null}static get C(){return Re}get direction(){return this._direction}get connection(){return this._connection}get id(){return this._id}connect(s=""){s!==""&&(this._direction="outgoing"),this.target=s,this._connection=new WebSocket(`wss://${this._ua._configuration.realm}`,"msrp"),this._connection.binaryType="arraybuffer",this._connection.onopen=r=>{console.log("open",r),this.onopen()},this._connection.onclose=r=>{console.log("close",r),this.onclose()},this._connection.onmessage=r=>{console.log("msg",r),this.onmessage(r)},this._connection.onerror=r=>{console.log("error",r),this.onerror()}}_sendKeepAlive(){const s=new or("");s.method="SEND",s.addHeader("To-Path",`${this.my_addr[1]}`),s.addHeader("From-Path",`${this.my_addr[0]}`),s.addHeader("Message-ID",Me.createRandomToken(10)),this._connection.send(s.toString())}answer(){if(!this._createDialog(this._request,"UAS")){this._request.reply(500,"Error creating dialog");return}this._status=Re.STATUS_ANSWERED,clearTimeout(this._timers.userNoAnswerTimer),this.connect()}acceptParty(s){this._request.parseSDP(!0),this._request.reply(200,"OK",[],`v=0
142
+ `,s}}const be={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 nu extends ht.EventEmitter{constructor(s){super(),this._id=null,this.my_ip="127.0.0.1",this._ua=s,this.auth_id=$e.createRandomToken(10),this._status=be.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:s._configuration.authorization_user,ha1:s._configuration.ha1,realm:s._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:F.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._msrpKeepAliveTimer=null}static get C(){return be}get direction(){return this._direction}get connection(){return this._connection}get id(){return this._id}connect(s=""){s!==""&&(this._direction="outgoing"),this.target=s,this._connection=new WebSocket(`wss://${this._ua._configuration.realm}`,"msrp"),this._connection.binaryType="arraybuffer",this._connection.onopen=i=>{console.log("open",i),this.onopen()},this._connection.onclose=i=>{console.log("close",i),this.onclose()},this._connection.onmessage=i=>{console.log("msg",i),this.onmessage(i)},this._connection.onerror=i=>{console.log("error",i),this.onerror()}}_sendKeepAlive(){const s=new sr("");s.method="SEND",s.addHeader("To-Path",`${this.my_addr[1]}`),s.addHeader("From-Path",`${this.my_addr[0]}`),s.addHeader("Message-ID",$e.createRandomToken(10)),this._connection.send(s.toString())}answer(){if(!this._createDialog(this._request,"UAS")){this._request.reply(500,"Error creating dialog");return}this._status=be.STATUS_ANSWERED,clearTimeout(this._timers.userNoAnswerTimer),this.connect()}acceptParty(s){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
146
146
  m=message 2856 TCP/TLS/MSRP *
147
147
  a=accept-types:text/plain text/html
148
148
  a=path: ${s.getHeader("Use-Path")} msrp://${this._ua._configuration.authorization_user}.${this._ua._configuration.realm}:2856/${this.auth_id};ws
149
- `)}inviteParty(s){const r={},o=[];r.to_uri=new _r("sip",this.target,this._ua._configuration.realm),r.from_uri=new _r("sip",this._ua._configuration.uri.user,this._ua._configuration.uri.host),o.push(`Contact: ${this._ua.contact.toString({outbound:!0})}`),o.push("Content-Type: application/sdp"),this._request=new It.InitialOutgoingInviteRequest(new _r("sip",this.target,this._ua._configuration.realm).clone(),this._ua,r,o,`v=0
149
+ `)}inviteParty(s){const i={},l=[];i.to_uri=new ar("sip",this.target,this._ua._configuration.realm),i.from_uri=new ar("sip",this._ua._configuration.uri.user,this._ua._configuration.uri.host),l.push(`Contact: ${this._ua.contact.toString({outbound:!0})}`),l.push("Content-Type: application/sdp"),this._request=new Dt.InitialOutgoingInviteRequest(new ar("sip",this.target,this._ua._configuration.realm).clone(),this._ua,i,l,`v=0
150
150
  o=- 4232740119537112802 2 IN IP4 ${this.my_ip}
151
151
  c=IN IP4 ${this.my_ip}
152
152
  t=0 0
153
153
  m=message 2856 TCP/TLS/MSRP *
154
154
  a=accept-types:text/plain text/html
155
155
  a=path:${s.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,console.log("dialog be",this._dialog),new Mo(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout(),console.log("to")},onTransportError:t=>{this.onTransportError(),console.log(t)},onAuthenticated:t=>{this._request=t},onReceiveResponse:t=>{this._receiveInviteResponse(t),console.log("dialog af",this._dialog),t.status_code===200&&(t.parseSDP(!0),this._status=Re.STATUS_CONFIRMED,this.target_addr=t.sdp.media[0].invalid[1].value.replaceAll("path:","").split(" ").reverse(),this.status="active",this.emit("active"),this.emit("confirmed"))}}).send(),this._status=Re.STATUS_INVITE_SENT}terminate(s={}){console.log("terminate",this);const r=s.cause||$.causes.BYE,o=Me.cloneArray(s.extraHeaders),a=s.body;let t,n=s.status_code,d=s.reason_phrase;if(this._status===Re.STATUS_TERMINATED)throw new Fs.InvalidStateError(this._status);switch(this.status="terminated",this._status){case Re.STATUS_NULL:case Re.STATUS_INVITE_SENT:case Re.STATUS_1XX_RECEIVED:if(n&&(n<200||n>=700))throw new TypeError(`Invalid status_code: ${n}`);n&&(d=d||$.REASON_PHRASE[n]||"",t=`SIP ;cause=${n} ;text="${d}"`),this._status===Re.STATUS_NULL||this._status===Re.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=t):this._status===Re.STATUS_1XX_RECEIVED&&this._request.cancel(t),this._status=Re.STATUS_CANCELED,console.log("failed 1"),this._failed("local",null,$.causes.CANCELED);break;case Re.STATUS_WAITING_FOR_ANSWER:case Re.STATUS_ANSWERED:if(n=n||480,console.log("REPLY 480"),n<300||n>=700)throw new TypeError(`Invalid status_code: ${n}`);this._request.reply(n,d,o,a),console.log("failed 2"),this._failed("local",null,$.causes.REJECTED);break;case Re.STATUS_WAITING_FOR_ACK:case Re.STATUS_CONFIRMED:if(d=s.reason_phrase||$.REASON_PHRASE[n]||"",n&&(n<200||n>=700))throw new TypeError(`Invalid status_code: ${n}`);if(n&&o.push(`Reason: SIP ;cause=${n}; text="${d}"`),this._status===Re.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Bt.C.STATUS_TERMINATED){const _=this._dialog;this.receiveRequest=({method:h})=>{h===$.ACK&&(this.sendRequest($.BYE,{extraHeaders:o,body:a}),_.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Bt.C.STATUS_TERMINATED&&(this.sendRequest($.BYE,{extraHeaders:o,body:a}),_.terminate())}),this._ended("local",null,r),this._dialog=_,this._ua.newDialog(_)}else console.log("here it is"),this.sendRequest($.BYE,{extraHeaders:o,body:a}),this._ended("local",null,r)}}sendRequest(s,r){return this._dialog.sendRequest(s,r)}authenticate(s){this.status="auth";let r=new or("");r.method="AUTH",r.addHeader("To-Path",`msrp://${this._ua._configuration.realm}:2856;ws`),r.addHeader("From-Path",`msrp://${this.credentials.username}.${this.credentials.realm}:2856/${this.auth_id};ws`),s&&r.addHeader("Authorization",s.toString());let o=r.toString();console.log(o);let a=[];for(var t=0;t<o.length;t++)a.push(o.charCodeAt(t).toString(16));console.log(a),this._connection.send(r.toString())}onmessage(s){console.log("onmessage",s);const r=new or(s.data);if(this.status==="auth"&&r.code===401){const o=this.parseAuth(r.getHeader("WWW-Authenticate")),a=new Fm(this.credentials);a.authenticate({method:"AUTH",ruri:`msrp://${this._ua._configuration.realm}:2856;ws`,body:null},o,Me.createRandomToken(12)),this.authenticate(a)}this.status==="auth"&&r.code===200&&this._direction==="outgoing"?(this.my_addr.push(r.getHeader("To-Path")),this.my_addr.push(r.getHeader("Use-Path")),this.status="active",this.inviteParty(r)):this.status==="auth"&&r.code===200&&this._direction==="incoming"?(this.my_addr.push(r.getHeader("To-Path")),this.my_addr.push(r.getHeader("Use-Path")),this.status="active",this.acceptParty(r),this.emit("confirmed")):r.method==="SEND"&&(this._sendOk(r),this._sendReport(r),r.direction="incoming",this.emit("newMessage",r),this._msgHistory.push(r),this.emit("msgHistoryUpdate",this._msgHistory),console.log("======================================================================")),r.code===480&&this._close()}onclose(){console.log("close")}onopen(){const s=new RTCPeerConnection({iceServers:[]});s.createDataChannel(""),s.createOffer().then(s.setLocalDescription.bind(s)),s.onicecandidate=r=>{if(!r||!r.candidate||!r.candidate.candidate)return;const o=/([0-9]{1,3}(\.[0-9]{1,3}){3})/,a=r.candidate.candidate.match(o);this.my_ip=a&&a[1],s.onicecandidate=()=>{},this.authenticate(null)}}onerror(s){console.log(s)}_receiveInviteResponse(s){if(console.log("resp0000000000000",s),this._dialog&&s.status_code>=200&&s.status_code<=299)if(console.log("200000000000000"),this._dialog.id.call_id===s.call_id&&this._dialog.id.local_tag===s.from_tag&&this._dialog.id.remote_tag===s.to_tag){this.sendRequest($.ACK);return}else{const r=new Xl(this,s,"UAC");if(r.error!==void 0){console.log(r.error);return}this.sendRequest($.ACK),this.sendRequest($.BYE);return}if(this._is_canceled){s.status_code>=100&&s.status_code<200?this._request.cancel(this._cancel_reason):s.status_code>=200&&s.status_code<299&&this._acceptAndTerminate(s);return}if(!(this._status!==Re.STATUS_INVITE_SENT&&this._status!==Re.STATUS_1XX_RECEIVED))switch(console.log("start Switch"),!0){case/^100$/.test(s.status_code):this._status=Re.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(s.status_code):{if(!s.to_tag){console.log("1xx response received without to tag");break}if(s.hasHeader("contact")&&!this._createDialog(s,"UAC",!0))break;if(this._status=Re.STATUS_1XX_RECEIVED,!s.body){this._progress("remote",s);break}const r={originator:"remote",type:"answer",sdp:s.body};console.log('emit "sdp"'),this.emit("sdp",r);const o=new RTCSessionDescription({type:"answer",sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(o)).then(()=>this._progress("remote",s)).catch(a=>{console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)});break}case/^2[0-9]{2}$/.test(s.status_code):{if(console.log("maybe here???"),this._status=Re.STATUS_CONFIRMED,!s.body){this._acceptAndTerminate(s,400,$.causes.MISSING_SDP),console.log("failed 3"),this._failed("remote",s,$.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(s,"UAC"))break;const r={originator:"remote",type:"answer",sdp:s.body};console.log('emit "sdp"'),this.emit("sdp",r),new RTCSessionDescription({type:"answer",sdp:r.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(s,500,o.toString()),console.log("failed 4"),this._failed("local",s,$.causes.WEBRTC_ERROR)})}).then(()=>{this._handleSessionTimersInIncomingResponse(s),this._accepted("remote",s),this.sendRequest($.ACK),this._confirmed("local",null)});break}default:{const r=Me.sipErrorCause(s.status_code);console.log("failed 5"),this._failed("remote",s,r)}}}sendMSRP(s){const r=new or("");r.method="SEND",r.addHeader("To-Path",`${this.my_addr[1]} ${this.target_addr[1]} ${this.target_addr[0]}`),r.addHeader("From-Path",`${this.my_addr[0]}`),r.addHeader("Message-ID",Me.createRandomToken(10)),r.addHeader("Byte-Range","1-25/25"),r.addHeader("Content-Type","text/plain"),r.addHeader("Success-Report","yes"),r.addHeader("Failure-Report","yes"),r.body=s;let o=r.toString();console.log(o);let a=[];for(var t=0;t<o.length;t++)a.push(o.charCodeAt(t).toString(16));console.log(a),this._connection.send(r.toString()),r.direction="outgoing",this.emit("newMessage",r),this._msgHistory.push(r),this.emit("msgHistoryUpdate",this._msgHistory)}_sendOk(s){let r=s.ident,o=s.getHeader("Message-ID"),a=new or("");a.method="200 OK",a.addHeader("To-Path",`${this.my_addr[1]}`),a.addHeader("From-Path",`${this.my_addr[0]}`),a.addHeader("Message-ID",o),a.ident=r;let t=a.toString();console.log(t);let n=[];for(var d=0;d<t.length;d++)n.push(t.charCodeAt(d).toString(16));console.log(n),this._connection.send(a.toString())}_sendReport(s){let r=s.ident,o=s.getHeader("Message-ID"),a=new or("");a.method="REPORT",a.addHeader("To-Path",`${s.getHeader("From-Path")}`),a.addHeader("From-Path",`${this.my_addr[0]}`),a.addHeader("Message-ID",o),a.addHeader("Byte-Range","1-25/25"),a.addHeader("Status","000 200 OK"),a.ident=r;let t=a.toString();console.log(t);let n=[];for(var d=0;d<t.length;d++)n.push(t.charCodeAt(d).toString(16));console.log(n),this._connection.send(a.toString())}parseAuth(s){const r={},o=s.replace("Digest","").split(",");for(const a of o){const t=a.trim().split("=");r[t[0]]=t[1].match('^"(.+)"$')[1]}return r}init_incoming(s,r){let o;const a=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0;if(s.body&&a!=="application/sdp"){s.reply(415);return}if(this._status=Re.STATUS_INVITE_RECEIVED,this._from_tag=s.from_tag,this._id=s.call_id+this._from_tag,this._request=s,this._contact=this._ua.contact.toString(),s.hasHeader("expires")&&(o=s.getHeader("expires")*1e3),s.to_tag=Me.newTag(),!this._createDialog(s,"UAS",!0)){s.reply(500,"Missing Contact header field");return}s.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Re.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{s.reply(408),console.log("failed 6"),this._failed("local",null,$.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),o&&(this._timers.expiresTimer=setTimeout(()=>{this._status===Re.STATUS_WAITING_FOR_ANSWER&&(s.reply(487),console.log("failed 7"),this._failed("system",null,$.causes.EXPIRES))},o)),this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from,r&&r(this),s.parseSDP(!0),this.target_addr=s.sdp.media[0].invalid[1].value.replaceAll("path:","").split(" ").reverse(),this._newMSRPSession("remote",s),this._status!==Re.STATUS_TERMINATED&&(s.reply(180,null,[`Contact: ${this._ua._contact}`]),this._progress("local",null))}_failed(s,r,o){this.emit("_failed",{originator:s,message:r||null,cause:o}),this._close(),this.emit("failed",{originator:s,message:r||null,cause:o})}_close(){if(console.log("CLOSE SESSION"),this._status!==Re.STATUS_TERMINATED){if(this._status=Re.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(s){console.log("close() | error closing the RTCPeerConnection: %o",s)}for(const s in this._timers)Object.prototype.hasOwnProperty.call(this._timers,s)&&clearTimeout(this._timers[s]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const s in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,s)&&(this._earlyDialogs[s].terminate(),delete this._earlyDialogs[s]);for(const s in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,s)&&delete this._referSubscribers[s];this._ua.destroyMSRPSession(this)}}_createDialog(s,r,o){const a=r==="UAS"?s.to_tag:s.from_tag,t=r==="UAS"?s.from_tag:s.to_tag,n=s.call_id+a+t;let d=this._earlyDialogs[n];if(o)return d?!0:(d=new Xl(this,s,r,Xl.C.STATUS_EARLY),d.error?(console.log("failed 8"),this._failed("remote",s,$.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[n]=d,!0));{if(this._from_tag=s.from_tag,this._to_tag=s.to_tag,d)return d.update(s,r),this._dialog=d,delete this._earlyDialogs[n],!0;const _=new Xl(this,s,r);return _.error?(console.log("failed 9"),this._failed("remote",s,$.causes.INTERNAL_ERROR),!1):(this._dialog=_,!0)}}_newMSRPSession(s,r){this._ua.newMSRPSession(this,{originator:s,session:this,request:r})}_progress(s,r){this.emit("progress",{originator:s,response:r||null})}isEnded(){switch(this._status){case Re.STATUS_CANCELED:case Re.STATUS_TERMINATED:return!0;default:return!1}}_accepted(s,r){console.log("session accepted"),this._start_time=new Date,console.log('emit "accepted"'),this.emit("accepted",{originator:s,response:r||null})}_confirmed(s,r){console.log("session confirmed"),this._is_confirmed=!0,console.log('emit "confirmed"'),this.emit("confirmed",{originator:s,ack:r||null})}_ended(s,r,o){console.log("session ended"),this._end_time=new Date,this._close(),console.log('emit "ended"'),this.emit("ended",{originator:s,message:r||null,cause:o})}_handleSessionTimersInIncomingResponse(s){if(!this._sessionTimers.enabled)return;let r;s.session_expires&&s.session_expires>=$.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=s.session_expires,r=s.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,r="uac"),this._sessionTimers.refresher=r==="uac",this._runSessionTimer()}receiveRequest(s){if(console.log("receiveRequest()"),s.method===$.CANCEL)(this._status===Re.STATUS_WAITING_FOR_ANSWER||this._status===Re.STATUS_ANSWERED)&&(this._status=Re.STATUS_CANCELED,this._request.reply(487),console.log("failed 10"),this._failed("remote",s,$.causes.CANCELED));else switch(s.method){case $.ACK:if(this._status!==Re.STATUS_WAITING_FOR_ACK)return;if(this._status=Re.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!s.body){this.terminate({cause:$.causes.MISSING_SDP,status_code:400});break}const r={originator:"remote",type:"answer",sdp:s.body};console.log('emit "sdp"'),this.emit("sdp",r);const o=new RTCSessionDescription({type:"answer",sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(o)).then(()=>{this._is_confirmed||this._confirmed("remote",s)}).catch(a=>{this.terminate({cause:$.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})}else this._is_confirmed||this._confirmed("remote",s);break;case $.BYE:this._status===Re.STATUS_CONFIRMED||this._status===Re.STATUS_WAITING_FOR_ACK?(s.reply(200),this._ended("remote",s,$.causes.BYE)):this._status===Re.STATUS_INVITE_RECEIVED||this._status===Re.STATUS_WAITING_FOR_ANSWER?(s.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",s,$.causes.BYE)):s.reply(403,"Wrong Status");break;case $.INVITE:this._status===Re.STATUS_CONFIRMED?s.hasHeader("replaces")?this._receiveReplaces(s):this._receiveReinvite(s):s.reply(403,"Wrong Status");break;case $.INFO:this._status===Re.STATUS_1XX_RECEIVED||this._status===Re.STATUS_WAITING_FOR_ANSWER||this._status===Re.STATUS_ANSWERED||this._status===Re.STATUS_WAITING_FOR_ACK||this._status===Re.STATUS_CONFIRMED?(s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0)!==void 0?new Tu(this).init_incoming(s):s.reply(415):s.reply(403,"Wrong Status");break;case $.UPDATE:this._status===Re.STATUS_CONFIRMED?this._receiveUpdate(s):s.reply(403,"Wrong Status");break;case $.REFER:this._status===Re.STATUS_CONFIRMED?this._receiveRefer(s):s.reply(403,"Wrong Status");break;case $.NOTIFY:this._status===Re.STATUS_CONFIRMED?this._receiveNotify(s):s.reply(403,"Wrong Status");break;default:s.reply(501)}}onTransportError(){console.log("onTransportError()"),this._status!==Re.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:$.causes.CONNECTION_ERROR,cause:$.causes.CONNECTION_ERROR})}onRequestTimeout(){console.log("onRequestTimeout()"),this._status!==Re.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:$.causes.REQUEST_TIMEOUT,cause:$.causes.REQUEST_TIMEOUT})}onDialogError(){console.log("onDialogError()"),this._status!==Re.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:$.causes.DIALOG_ERROR,cause:$.causes.DIALOG_ERROR})}}const Vi=new Pu("Registrator"),ao=10;class OT{constructor(s,r){this._reg_id=1,this._ua=s,this._transport=r,this._registrar=s.configuration.registrar_server,this._expires=s.configuration.register_expires,this._call_id=ms.createRandomToken(22),this._cseq=0,this._to_uri=s.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString();const o=this._contact.indexOf(">");if(o!==-1){const a=this._contact.slice(0,o)+this._contact.slice(o+1,this._contact.length);this._contact=a}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(s){Array.isArray(s)||(s=[]),this._extraHeaders=s.slice()}setExtraContactParams(s){s instanceof Object||(s={}),this._extraContactParams="";for(const r in s)if(Object.prototype.hasOwnProperty.call(s,r)){const o=s[r];this._extraContactParams+=`;${r}`,o&&(this._extraContactParams+=`=${o}`)}}setExtraContactUriParams(s){s instanceof Object||(s={}),this._extraContactParams="";for(const r in s)if(Object.prototype.hasOwnProperty.call(s,r)){const o=s[r];this._extraContactParams+=`;${r}`,o&&(this._extraContactParams+=`=${o}`)}}register(){if(this._registering){Vi.debug("Register request in progress...");return}const s=this._extraHeaders.slice();s.push(`Contact: ${this._contact}${this._extraContactParams}>;expires=${this._expires}`),s.push(`Expires: ${this._expires}`);const r=new It.OutgoingRequest($.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},s),o=new Mo(this._ua,r,{onRequestTimeout:()=>{this._registrationFailure(null,$.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,$.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:a=>{if(a.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(a.status_code):break;case/^2[0-9]{2}$/.test(a.status_code):{if(this._registering=!1,!a.hasHeader("Contact")){Vi.debug("no Contact header in response to REGISTER, response ignored");break}const t=a.headers.Contact.reduce((h,g)=>h.concat(g.parsed),[]);let n=t.find(h=>this._sipInstance===h.getParam("+sip.instance")&&this._reg_id===parseInt(h.getParam("reg-id")));if(n||(n=t.find(h=>h.uri.user===this._ua.contact.uri.user)),!n){Vi.debug("no Contact header pointing to us, response ignored");break}let d=n.getParam("expires");!d&&a.hasHeader("expires")&&(d=a.getHeader("expires")),d||(d=this._expires),d=Number(d),d<ao&&(d=ao);const _=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")},_),n.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=n.getParam("temp-gruu").replace(/"/g,"")),n.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=n.getParam("pub-gruu").replace(/"/g,"")),this._registered||(this._registered=!0,this._ua.registered({response:a}));break}case/^423$/.test(a.status_code):{a.hasHeader("min-expires")?(this._expires=Number(a.getHeader("min-expires")),this._expires<ao&&(this._expires=ao),this.register()):(Vi.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(a,$.causes.SIP_FAILURE_CODE));break}default:{const t=ms.sipErrorCause(a.status_code);this._registrationFailure(a,t)}}}});this._registering=!0,o.send()}unregister(s={}){if(!this._registered){Vi.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const r=this._extraHeaders.slice();s.all?r.push(`Contact: *${this._extraContactParams}`):r.push(`Contact: ${this._contact}${this._extraContactParams}>;expires=0`),r.push("Expires: 0");const o=new It.OutgoingRequest($.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},r);new Mo(this._ua,o,{onRequestTimeout:()=>{this._unregistered(null,$.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,$.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:t=>{switch(!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):this._unregistered(t);break;default:{const n=ms.sipErrorCause(t.status_code);this._unregistered(t,n)}}}}).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(s,r){this._registering=!1,this._ua.registrationFailed({response:s||null,cause:r}),this._registered&&(this._registered=!1,this._ua.unregistered({response:s||null,cause:r}))}_unregistered(s,r){this._registering=!1,this._registered=!1,this._ua.unregistered({response:s||null,cause:r||null})}}const ut=console,js={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},DT=ST;class NT extends DT{constructor(s){super(s),this._msrp_sessions=[],this._transactions={nist:{},nict:{},ist:{},ict:{}},this._janus_sessions=[],this._registrator=new OT(this)}call(s,r){return super.call(s,r)}joinVideoCall(s,r,o){ut.debug("call()");const a=new ko(this);return a.connect(s,r,o),a}_loadConfig(s){try{el.load(this._configuration,s)}catch(a){throw a}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=ms.newUUID()),this._configuration.jssip_id=ms.createRandomToken(5);const r=this._configuration.uri.clone();r.user=null,this._configuration.hostport_params=r.toString().replace(/^sip:/i,"");try{this._transport=new Kg(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=UT.bind(this),this._transport.onconnect=PT.bind(this),this._transport.ondisconnect=xT.bind(this),this._transport.ondata=MT.bind(this)}catch(a){throw ut.warn(a),new Fs.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 a=this._configuration.uri.clone();a.user=null,a.clearParams(),a.clearHeaders(),this._configuration.registrar_server=a}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new _r("sip",ms.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(a={}){const t=a.anonymous||null,n=a.outbound||null;let d="<";return t?d+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":d+=this.pub_gruu||this.uri.toString(),n&&(t?!this.temp_gruu:!this.pub_gruu)&&(d+=";ob"),d+=">",d}};const o=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const a in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,a)&&(o.indexOf(a)!==-1?Object.defineProperty(this._configuration,a,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,a,{writable:!1,configurable:!1}));ut.debug("configuration parameters after validation:");for(const a in this._configuration)if(Object.prototype.hasOwnProperty.call(el.settings,a))switch(a){case"uri":case"registrar_server":ut.debug(`- ${a}: ${this._configuration[a]}`);break;case"password":case"ha1":case"authorization_jwt":ut.debug(`- ${a}: NOT SHOWN`);break;default:ut.debug(`- ${a}: ${JSON.stringify(this._configuration[a])}`)}}newMSRPSession(s,r){s.on("msgHistoryUpdate",o=>{console.log(o)}),this._msrp_sessions[s.id]=s,this.emit("newMSRPSession",r)}newJanusSession(s,r){this._janus_sessions[s.id]=s,this.emit("newJanusSession",r)}destroyMSRPSession(s){delete this._msrp_sessions[s.id]}destroyJanusSession(s){delete this._janus_sessions[s.id]}receiveRequest(s){var t,n,d,_;const r=s.method;if(console.log("-----------"),s.ruri.user!==this._configuration.uri.user&&s.ruri.user!==this._contact.uri.user){ut.debug("Request-URI does not point to us"),s.method!==De.ACK&&s.reply_sl(404);return}if(s.ruri.scheme===De.SIPS){s.reply_sl(416);return}if(Bt.checkTransaction(this,s))return;if(r===De.INVITE?new Bt.InviteServerTransaction(this,this._transport,s):r!==De.ACK&&r!==De.CANCEL&&new Bt.NonInviteServerTransaction(this,this._transport,s),r===De.OPTIONS){if(this.listeners("newOptions").length===0){s.reply(200);return}new Jc.Options(this).init_incoming(s)}else if(r===De.MESSAGE){if(this.listeners("newMessage").length===0){s.reply(405);return}new Jc.Message(this).init_incoming(s)}else if(r===De.INVITE&&!s.to_tag&&this.listeners("newRTCSession").length===0){s.reply(405);return}let o,a;if(s.to_tag)if(o=this._findDialog(s.call_id,s.from_tag,s.to_tag),o)o.receiveRequest(s);else if(r===De.NOTIFY)if(a=this._findSession(s),a)a.receiveRequest(s);else{if(s.body)try{const h=JSON.parse(s.body)||{};(n=(t=h.plugindata)==null?void 0:t.data)!=null&&n.publishers&&Object.values(this._janus_sessions)[0].receivePublishers(h),(_=(d=h.plugindata)==null?void 0:d.data)!=null&&_.unpublished&&Object.values(this._janus_sessions)[0].receiveUnpublished(h.plugindata.data.unpublished)}catch(h){console.error(h)}s.reply(200)}else r!==De.ACK&&s.reply(481);else switch(r){case De.INVITE:if(window.RTCPeerConnection)if(s.hasHeader("replaces")){const h=s.replaces;o=this._findDialog(h.call_id,h.from_tag,h.to_tag),o?(a=o.owner,a.isEnded()?s.reply(603):a.receiveRequest(s)):s.reply(481)}else s.body.search(/MSRP/ig)>-1?(a=new Za(this),a.init_incoming(s)):s.body.search(/JANUS/ig)>-1||(a=new Ng(this),a.init_incoming(s));else ut.warn("INVITE received but WebRTC is not supported"),s.reply(488);break;case De.BYE:s.reply(481);break;case De.CANCEL:a=this._findSession(s),a?a.receiveRequest(s):ut.debug("received CANCEL request for a non existent session");break;case De.ACK:break;case De.NOTIFY:this.emit("sipEvent",{event:s.event,request:s}),s.reply(200);break;default:s.reply(405);break}}startMSRP(s,r){ut.debug("startMSRP()",r);const o=new Za(this);return o.connect(s),o}startJanus(s,r){ut.debug("startJanus()",r);const o=new Za(this);return o.connect(s),o}terminateMSRPSessions(s){ut.debug("terminateSessions()");for(const r in this._msrp_sessions)this._msrp_sessions[r].isEnded()||this._msrp_sessions[r].terminate(s)}terminateJanusSessions(s){ut.debug("terminateSessions()");for(const r in this._janus_sessions)this._janus_sessions[r].isEnded()||this._janus_sessions[r].terminate(s)}stop(){if(ut.debug("stop()"),this._dynConfiguration={},this._status===js.STATUS_USER_CLOSED){ut.debug("UA already closed");return}this._registrator.close();const s=Object.keys(this._sessions).length;for(const o in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,o)){ut.debug(`closing session ${o}`);try{this._sessions[o].terminate()}catch(a){console.error(a)}}for(const o in this._msrp_sessions)if(Object.prototype.hasOwnProperty.call(this._msrp_sessions,o)){ut.debug(`closing session ${o}`);try{this._msrp_sessions[o].terminate()}catch(a){console.error(a)}}for(const o in this._janus_sessions)if(Object.prototype.hasOwnProperty.call(this._janus_sessions,o)){ut.debug(`closing session ${o}`);try{this._janus_sessions[o].terminate()}catch(a){console.error(a)}}for(const o in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,o))try{this._applicants[o].close()}catch(a){console.error(a)}this._status=js.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&&s===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}}function UT(c){this.emit("connecting",c)}function PT(c){this._status!==js.STATUS_USER_CLOSED&&(this._status=js.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function xT(c){const s=["nict","ict","nist","ist"];for(const r of s)for(const o in this._transactions[r])Object.prototype.hasOwnProperty.call(this._transactions[r],o)&&this._transactions[r][o].onTransportError();this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==js.STATUS_USER_CLOSED&&(this._status=js.STATUS_NOT_READY,this._error=js.NETWORK_ERROR)}function MT(c){console.log("onTransportData",c);const s=c.transport;let r=c.message;if(r=Hu.parseMessage(r,this),!r){console.log("if 1 return");return}if(this._status===js.STATUS_USER_CLOSED&&r instanceof Wl.IncomingRequest){console.log("if 2 return");return}if(!aT(r,this,s)){console.log("if 3 return");return}if(console.log("onTransportData message",r),console.log("onTransportData instanceof",r instanceof Wl.IncomingRequest),r instanceof Wl.IncomingRequest)r.transport=s,console.log("onTransportData receiveRequest"),this.receiveRequest(r);else if(r instanceof Wl.IncomingResponse){let o;switch(r.method){case De.INVITE:o=this._transactions.ict[r.via_branch],o&&o.receiveResponse(r);break;case De.ACK:break;default:o=this._transactions.nict[r.via_branch],o&&o.receiveResponse(r);break}}}const kT=["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"],LT=["_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","status","start_time","_remote_identity","target_addr"];function wf(c){const s={};return kT.forEach(r=>{c[r]!==void 0&&(s[r]=c[r])}),s.localHold=c._localHold,s}function Of(c){const s={};return LT.forEach(r=>{c[r]!==void 0&&(s[r]=c[r])}),s}function Df(c,s){const r=new AudioContext,o=r.createMediaStreamSource(c),a=r.createMediaStreamDestination(),t=r.createGain();return o.connect(t),t.connect(a),t.gain.value=s,a.stream}function $T(c,s,r,o){const a=document.createElement("audio");a.id=s._id,a.className="audioTag",a.srcObject=c,C_()||(a.setSinkId(r),a.volume=o),a.play(),s.audioTag=a}function HT(c){if(c&&typeof c.log=="function"&&typeof c.warn=="function"&&typeof c.error=="function")return!0}function C_(){return/Mobi|Android|iPhone/i.test(navigator.userAgent)}const FT=at,jT=ls(),Dt=new FT("WebSocketInterface");var qT=class{constructor(s){Dt.debug('new() [url:"%s"]',s),this._url=s,this._sip_uri=null,this._via_transport=null,this._ws=null;const r=jT.parse(s,"absoluteURI");if(r===-1)throw Dt.warn(`invalid WebSocket URI: ${s}`),new TypeError(`Invalid argument: ${s}`);if(r.scheme!=="wss"&&r.scheme!=="ws")throw Dt.warn(`invalid WebSocket URI scheme: ${r.scheme}`),new TypeError(`Invalid argument: ${s}`);this._sip_uri=`sip:${r.host}${r.port?`:${r.port}`:""};transport=ws`,this._via_transport=r.scheme.toUpperCase()}get via_transport(){return this._via_transport}set via_transport(s){this._via_transport=s.toUpperCase()}get sip_uri(){return this._sip_uri}get url(){return this._url}connect(){if(Dt.debug("connect()"),this.isConnected()){Dt.debug(`WebSocket ${this._url} is already connected`);return}else if(this.isConnecting()){Dt.debug(`WebSocket ${this._url} is connecting`);return}this._ws&&this.disconnect(),Dt.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(s){this._onError(s)}}disconnect(){Dt.debug("disconnect()"),this._ws&&(this._ws.onopen=()=>{},this._ws.onclose=()=>{},this._ws.onmessage=()=>{},this._ws.onerror=()=>{},this._ws.close(),this._ws=null)}send(s){return Dt.debug("send()"),this.isConnected()?(this._ws.send(s),!0):(Dt.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(){Dt.debug(`WebSocket ${this._url} connected`),this.onconnect()}_onClose({wasClean:s,code:r,reason:o}){Dt.debug(`WebSocket ${this._url} closed`),s===!1&&Dt.debug("WebSocket abrupt disconnection"),this.ondisconnect(!s,r,o)}_onMessage({data:s}){Dt.debug("received WebSocket message"),this.ondata(s)}_onError(s){Dt.warn(`WebSocket ${this._url} error: `,s)}};const yu=Lo,VT=De,BT=Ss,GT=yt(),WT=A_,KT=Es(),YT=xu(),JT=ls(),zT=qT,XT=dr("JsSIP");XT("version %s",yu.version);var QT={C:VT,Exceptions:BT,Utils:GT,UA:WT,URI:KT,NameAddrHeader:YT,WebSocketInterface:zT,Grammar:JT,debug:dr,get name(){return yu.title},get version(){return yu.version}};const ZT=Xe(QT);function eu(c){return c<10?`0${c}`:`${c}`}function ev(c){let s=c.hours||0,r=c.minutes||0,o=c.seconds||0;o++,o===60&&(o=0,r++,r===60&&(r=0,s++));const a=`${eu(s)}:${eu(r)}:${eu(o)}`;return{seconds:o,minutes:r,hours:s,formatted:a}}var At={};At.forEach=async(c,s,r)=>{const o=[];for(let a=0;a<c.length;a++)if(a in c){const t=Promise.resolve(c[a]).then(n=>s.call(r||globalThis,n,a,c));o.push(t)}await Promise.all(o)};At.forEachSeries=async(c,s,r)=>{for(let o=0;o<c.length;o++)o in c&&await s.call(r||globalThis,await c[o],o,c)};At.map=async(c,s,r)=>{const o=[];for(let a=0;a<c.length;a++)a in c&&(o[a]=Promise.resolve(c[a]).then(t=>s.call(r||globalThis,t,a,c)));return Promise.all(o)};At.mapSeries=async(c,s,r)=>{const o=[];for(let a=0;a<c.length;a++)a in c&&(o[a]=await s.call(r||globalThis,await c[a],a,c));return o};At.find=(c,s,r)=>new Promise((o,a)=>{if(c.length===0)return o();let t=1;for(let n=0;n<c.length;n++){const d=_=>{_?o(c[n]):t===c.length&&o(),t++};Promise.resolve(c[n]).then(_=>s.call(r||globalThis,_,n,c)).then(d).catch(a)}});At.findSeries=async(c,s,r)=>{for(let o=0;o<c.length;o++)if(await s.call(r||globalThis,await c[o],o,c))return c[o]};At.findIndex=(c,s,r)=>new Promise((o,a)=>{if(c.length===0)return o(-1);let t=1;for(let n=0;n<c.length;n++){const d=_=>{_?o(n):t===c.length&&o(-1),t++};Promise.resolve(c[n]).then(_=>s.call(r||globalThis,_,n,c)).then(d).catch(a)}});At.findIndexSeries=async(c,s,r)=>{for(let o=0;o<c.length;o++)if(await s.call(r||globalThis,await c[o],o,c))return o};At.some=(c,s,r)=>new Promise((o,a)=>{if(c.length===0)return o(!1);let t=1;for(let n=0;n<c.length;n++){if(!(n in c)){t++;continue}const d=_=>{_?o(!0):t===c.length&&o(!1),t++};Promise.resolve(c[n]).then(_=>s.call(r||globalThis,_,n,c)).then(d).catch(a)}});At.someSeries=async(c,s,r)=>{for(let o=0;o<c.length;o++)if(o in c&&await s.call(r||globalThis,await c[o],o,c))return!0;return!1};At.every=(c,s,r)=>new Promise((o,a)=>{if(c.length===0)return o(!0);let t=1;for(let n=0;n<c.length;n++){if(!(n in c)){t++;continue}const d=_=>{_?t===c.length&&o(!0):o(!1),t++};Promise.resolve(c[n]).then(_=>s.call(r||globalThis,_,n,c)).then(d).catch(a)}});At.everySeries=async(c,s,r)=>{for(let o=0;o<c.length;o++)if(o in c&&!await s.call(r||globalThis,await c[o],o,c))return!1;return!0};At.filter=(c,s,r)=>new Promise(async(o,a)=>{const t=[];for(let d=0;d<c.length;d++)d in c&&(t[d]=Promise.resolve(c[d]).then(_=>s.call(r||globalThis,_,d,c)).catch(a));const n=[];for(let d=0;d<t.length;d++)await t[d]&&n.push(await c[d]);o(n)});At.filterSeries=async(c,s,r)=>{const o=[];for(let a=0;a<c.length;a++)a in c&&await s.call(r||globalThis,await c[a],a,c)&&o.push(await c[a]);return o};At.reduce=async(c,s,r)=>{if(c.length===0&&r===void 0)throw TypeError("Reduce of empty array with no initial value");let o,a;for(r!==void 0?(a=r,o=0):(a=c[0],o=1),o;o<c.length;o++)o in c&&(a=await s(await a,await c[o],o,c));return a};var R_={};(function(c){const s=At;Object.keys(s).forEach(r=>{const o=r.charAt(0).toUpperCase()+r.slice(1);c[`async${o}`]=async function(...a){return s[r](this,...a)}})})(R_);const tv=At,sv=R_;var nv=Object.assign(tv,{instanceMethods:sv});const yn=new AudioContext,zt={NEW_CALL:"new_call",CALL_CONFIRMED:"confirmed",CALL_FAILED:"failed",CALL_PROGRESS:"progress",CALL_ENDED:"ended"};var rv={exports:{}};(function(c){var s=function(r){var o=Object.prototype,a=o.hasOwnProperty,t=Object.defineProperty||function(ee,W,G){ee[W]=G.value},n,d=typeof Symbol=="function"?Symbol:{},_=d.iterator||"@@iterator",h=d.asyncIterator||"@@asyncIterator",g=d.toStringTag||"@@toStringTag";function T(ee,W,G){return Object.defineProperty(ee,W,{value:G,enumerable:!0,configurable:!0,writable:!0}),ee[W]}try{T({},"")}catch{T=function(W,G,re){return W[G]=re}}function E(ee,W,G,re){var ge=W&&W.prototype instanceof ae?W:ae,be=Object.create(ge.prototype),xe=new P(re||[]);return t(be,"_invoke",{value:J(ee,G,xe)}),be}r.wrap=E;function y(ee,W,G){try{return{type:"normal",arg:ee.call(W,G)}}catch(re){return{type:"throw",arg:re}}}var A="suspendedStart",C="suspendedYield",I="executing",H="completed",L={};function ae(){}function N(){}function j(){}var Se={};T(Se,_,function(){return this});var ve=Object.getPrototypeOf,M=ve&&ve(ve(se([])));M&&M!==o&&a.call(M,_)&&(Se=M);var D=j.prototype=ae.prototype=Object.create(Se);N.prototype=j,t(D,"constructor",{value:j,configurable:!0}),t(j,"constructor",{value:N,configurable:!0}),N.displayName=T(j,g,"GeneratorFunction");function B(ee){["next","throw","return"].forEach(function(W){T(ee,W,function(G){return this._invoke(W,G)})})}r.isGeneratorFunction=function(ee){var W=typeof ee=="function"&&ee.constructor;return W?W===N||(W.displayName||W.name)==="GeneratorFunction":!1},r.mark=function(ee){return Object.setPrototypeOf?Object.setPrototypeOf(ee,j):(ee.__proto__=j,T(ee,g,"GeneratorFunction")),ee.prototype=Object.create(D),ee},r.awrap=function(ee){return{__await:ee}};function V(ee,W){function G(be,xe,Ce,le){var ye=y(ee[be],ee,xe);if(ye.type==="throw")le(ye.arg);else{var st=ye.arg,lt=st.value;return lt&&typeof lt=="object"&&a.call(lt,"__await")?W.resolve(lt.__await).then(function(Ee){G("next",Ee,Ce,le)},function(Ee){G("throw",Ee,Ce,le)}):W.resolve(lt).then(function(Ee){st.value=Ee,Ce(st)},function(Ee){return G("throw",Ee,Ce,le)})}}var re;function ge(be,xe){function Ce(){return new W(function(le,ye){G(be,xe,le,ye)})}return re=re?re.then(Ce,Ce):Ce()}t(this,"_invoke",{value:ge})}B(V.prototype),T(V.prototype,h,function(){return this}),r.AsyncIterator=V,r.async=function(ee,W,G,re,ge){ge===void 0&&(ge=Promise);var be=new V(E(ee,W,G,re),ge);return r.isGeneratorFunction(W)?be:be.next().then(function(xe){return xe.done?xe.value:be.next()})};function J(ee,W,G){var re=A;return function(be,xe){if(re===I)throw new Error("Generator is already running");if(re===H){if(be==="throw")throw xe;return tt()}for(G.method=be,G.arg=xe;;){var Ce=G.delegate;if(Ce){var le=F(Ce,G);if(le){if(le===L)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,W,G);if(ye.type==="normal"){if(re=G.done?H:C,ye.arg===L)continue;return{value:ye.arg,done:G.done}}else ye.type==="throw"&&(re=H,G.method="throw",G.arg=ye.arg)}}}function F(ee,W){var G=W.method,re=ee.iterator[G];if(re===n)return W.delegate=null,G==="throw"&&ee.iterator.return&&(W.method="return",W.arg=n,F(ee,W),W.method==="throw")||G!=="return"&&(W.method="throw",W.arg=new TypeError("The iterator does not provide a '"+G+"' method")),L;var ge=y(re,ee.iterator,W.arg);if(ge.type==="throw")return W.method="throw",W.arg=ge.arg,W.delegate=null,L;var be=ge.arg;if(!be)return W.method="throw",W.arg=new TypeError("iterator result is not an object"),W.delegate=null,L;if(be.done)W[ee.resultName]=be.value,W.next=ee.nextLoc,W.method!=="return"&&(W.method="next",W.arg=n);else return be;return W.delegate=null,L}B(D),T(D,g,"Generator"),T(D,_,function(){return this}),T(D,"toString",function(){return"[object Generator]"});function X(ee){var W={tryLoc:ee[0]};1 in ee&&(W.catchLoc=ee[1]),2 in ee&&(W.finallyLoc=ee[2],W.afterLoc=ee[3]),this.tryEntries.push(W)}function U(ee){var W=ee.completion||{};W.type="normal",delete W.arg,ee.completion=W}function P(ee){this.tryEntries=[{tryLoc:"root"}],ee.forEach(X,this),this.reset(!0)}r.keys=function(ee){var W=Object(ee),G=[];for(var re in W)G.push(re);return G.reverse(),function ge(){for(;G.length;){var be=G.pop();if(be in W)return ge.value=be,ge.done=!1,ge}return ge.done=!0,ge}};function se(ee){if(ee){var W=ee[_];if(W)return W.call(ee);if(typeof ee.next=="function")return ee;if(!isNaN(ee.length)){var G=-1,re=function ge(){for(;++G<ee.length;)if(a.call(ee,G))return ge.value=ee[G],ge.done=!1,ge;return ge.value=n,ge.done=!0,ge};return re.next=re}}return{next:tt}}r.values=se;function tt(){return{value:n,done:!0}}return P.prototype={constructor:P,reset:function(ee){if(this.prev=0,this.next=0,this.sent=this._sent=n,this.done=!1,this.delegate=null,this.method="next",this.arg=n,this.tryEntries.forEach(U),!ee)for(var W in this)W.charAt(0)==="t"&&a.call(this,W)&&!isNaN(+W.slice(1))&&(this[W]=n)},stop:function(){this.done=!0;var ee=this.tryEntries[0],W=ee.completion;if(W.type==="throw")throw W.arg;return this.rval},dispatchException:function(ee){if(this.done)throw ee;var W=this;function G(le,ye){return be.type="throw",be.arg=ee,W.next=le,ye&&(W.method="next",W.arg=n),!!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 xe=a.call(ge,"catchLoc"),Ce=a.call(ge,"finallyLoc");if(xe&&Ce){if(this.prev<ge.catchLoc)return G(ge.catchLoc,!0);if(this.prev<ge.finallyLoc)return G(ge.finallyLoc)}else if(xe){if(this.prev<ge.catchLoc)return G(ge.catchLoc,!0)}else if(Ce){if(this.prev<ge.finallyLoc)return G(ge.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(ee,W){for(var G=this.tryEntries.length-1;G>=0;--G){var re=this.tryEntries[G];if(re.tryLoc<=this.prev&&a.call(re,"finallyLoc")&&this.prev<re.finallyLoc){var ge=re;break}}ge&&(ee==="break"||ee==="continue")&&ge.tryLoc<=W&&W<=ge.finallyLoc&&(ge=null);var be=ge?ge.completion:{};return be.type=ee,be.arg=W,ge?(this.method="next",this.next=ge.finallyLoc,L):this.complete(be)},complete:function(ee,W){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"&&W&&(this.next=W),L},finish:function(ee){for(var W=this.tryEntries.length-1;W>=0;--W){var G=this.tryEntries[W];if(G.finallyLoc===ee)return this.complete(G.completion,G.afterLoc),U(G),L}},catch:function(ee){for(var W=this.tryEntries.length-1;W>=0;--W){var G=this.tryEntries[W];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,W,G){return this.delegate={iterator:se(ee),resultName:W,nextLoc:G},this.method==="next"&&(this.arg=n),L}},r}(c.exports);try{regeneratorRuntime=s}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=s:Function("r","regeneratorRuntime = r")(s)}})(rv);var I_={exports:{}};(function(c){(function(s,r){c.exports?c.exports=r():s.log=r()})(x_,function(){var s=function(){},r="undefined",o=typeof window!==r&&typeof window.navigator!==r&&/Trident\/|MSIE /.test(window.navigator.userAgent),a=["trace","debug","info","warn","error"];function t(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 n(){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===r?!1:C==="trace"&&o?n:console[C]!==void 0?t(console,C):console.log!==void 0?t(console,"log"):s}function _(C,I){for(var H=0;H<a.length;H++){var L=a[H];this[L]=H<C?s:this.methodFactory(L,C,I)}this.log=this.debug}function h(C,I,H){return function(){typeof console!==r&&(_.call(this,I,H),this[C].apply(this,arguments))}}function g(C,I,H){return d(C)||h.apply(this,arguments)}function T(C,I,H){var L=this,ae;I=I??"WARN";var N="loglevel";typeof C=="string"?N+=":"+C:typeof C=="symbol"&&(N=void 0);function j(D){var B=(a[D]||"silent").toUpperCase();if(!(typeof window===r||!N)){try{window.localStorage[N]=B;return}catch{}try{window.document.cookie=encodeURIComponent(N)+"="+B+";"}catch{}}}function Se(){var D;if(!(typeof window===r||!N)){try{D=window.localStorage[N]}catch{}if(typeof D===r)try{var B=window.document.cookie,V=B.indexOf(encodeURIComponent(N)+"=");V!==-1&&(D=/^([^;]+)/.exec(B.slice(V))[1])}catch{}return L.levels[D]===void 0&&(D=void 0),D}}function ve(){if(!(typeof window===r||!N)){try{window.localStorage.removeItem(N);return}catch{}try{window.document.cookie=encodeURIComponent(N)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}L.name=C,L.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},L.methodFactory=H||g,L.getLevel=function(){return ae},L.setLevel=function(D,B){if(typeof D=="string"&&L.levels[D.toUpperCase()]!==void 0&&(D=L.levels[D.toUpperCase()]),typeof D=="number"&&D>=0&&D<=L.levels.SILENT){if(ae=D,B!==!1&&j(D),_.call(L,D,C),typeof console===r&&D<L.levels.SILENT)return"No console available for logging"}else throw"log.setLevel() called with invalid level: "+D},L.setDefaultLevel=function(D){I=D,Se()||L.setLevel(D,!1)},L.resetLevel=function(){L.setLevel(I,!1),ve()},L.enableAll=function(D){L.setLevel(L.levels.TRACE,D)},L.disableAll=function(D){L.setLevel(L.levels.SILENT,D)};var M=Se();M==null&&(M=I),L.setLevel(M,!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!==r?window.log:void 0;return E.noConflict=function(){return typeof window!==r&&window.log===E&&(window.log=A),E},E.getLoggers=function(){return y},E.default=E,E})})(I_);var Rt=I_.exports;const gs=()=>`${new Date().toISOString()} | metrics`,Ts=(c,s,r)=>`${c} | ${s} | ${r}`;Rt.setDefaultLevel(Rt.levels.TRACE);const iv=c=>{Rt.info(Ts(gs(),"log ",`set log level to ${c?"verbose":"info"}`)),Rt.setLevel(c?Rt.levels.TRACE:Rt.levels.INFO)},lv=c=>{const s=[...Object.keys(Rt.levels)];s.includes(c)?(Rt.info(Ts(gs(),"log ",`update log level to ${c.toLowerCase()}`)),Rt.setLevel(c)):Rt.warn(Ts(gs(),"log ","Incorrect log level please choose one of "),s)},Pe=(c,s,r)=>{r?Rt.debug(Ts(gs(),c,s),r):Rt.debug(Ts(gs(),c,s))},tu=(c,s)=>{Rt.info(Ts(gs(),c,s))},An=(c,s)=>{Rt.info(Ts(gs(),c,s))},Ro=(c,s)=>{Rt.warn(Ts(gs(),c,s))},cr=(c,s)=>{Rt.error(Ts(gs(),c,s))};function ov(c){return Math.floor(Math.random()*c).toString()}function Nf(c,s){let r=s;return c.forEach(o=>{r=r.replace(o,"")}),r}function av(c,s){let r="";for(let o=0;o<s;o+=1)r+=c[ov(c.length)];return r}function uv({length:c=20,useLetters:s=!0,useNumbers:r=!0,includeSymbols:o=[],excludeSymbols:a=[]}={}){let t="abcdefghijklmnopqrstuvwxyz",n="0123456789",d=[],_=[],h=[];return s&&(a.length&&(t=Nf(a,t)),_=t.split("")),r&&(a.length&&(n=Nf(a,n)),h=n.split("")),d=[..._,...h,...o],av(d,c)}var cv=uv;const Ji=Xe(cv),fv=()=>"WebRTCMetrics",_v=()=>"5.0.3",$e={INBOUND:"inbound",OUTBOUND:"outbound"},ps={IDLE:"idle",RUNNING:"running",MUTED:"muted"},Bi={NEW:"new",CHECKING:"checking",CONNECTED:"connected",COMPLETED:"completed",DISCONNECTED:"disconnected",FAILED:"failed",CLOSED:"closed"},hv=()=>({...{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:[]}}),b_={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},w_={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},O_={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},D_={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},dv=c=>{const s={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 r={...c,audio:{},video:{},data:{...c.data},network:{...c.network},experimental:{...c.experimental}};return Object.keys(c.audio).forEach(o=>{r.audio[o]={...c.audio[o]}}),Object.keys(c.video).forEach(o=>{r.video[o]={...c.video[o]}}),r}return{...s,audio:{},video:{},data:{...s.data},network:{...s.network},experimental:{...s.experimental}}},pv={refreshEvery:2e3,startAfter:0,stopAfter:-1,verbose:!1,pname:`p-${Ji()}`,cid:`c-${Ji()}`,uid:`u-${Ji()}`,record:!1,ticket:!0},Jt={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"},Gi={ETHERNET:0,CELLULAR_5G:2,WIFI:3,CELLULAR_4G:5,CELLULAR:10},su={ETHERNET:"ethernet",CELLULAR_4G:"cellular",WIFI:"wifi"},ne={AUDIO:"audio",VIDEO:"video",NETWORK:"network",DATA:"data"},nu="config ",mv=(c,s={},r)=>{const o={...r,...s};return s.pname||Ro(nu,`Argument [String] 'cfg.pname' for the peerConnection name or id is missing - use generated '${r.pname}'`),s.cid||Ro(nu,`Argument [String] 'cfg.cid' for the call name or id is missing - use generated '${r.cid}'`),s.uid||Ro(nu,`Argument [String] 'cfg.uid' for the user name or id is missing - use generated '${r.uid}'`),o.pc=c,o},gv=(c={})=>{const s={...pv,...c};return s.name=fv(),s.version=_v(),s},_l=(c,s,r,o=!1,a)=>{let t=c.map(n=>{if(!r)return n[s];if(!a)return n[s][r];const d=n[s][a];return d?d[r]:null});return t=t.filter(n=>o?Number.isFinite(n)&&n>0:Number.isFinite(n)),t.length===0?[]:t},Vs=c=>c.reduce((s,r)=>s+r,0)/c.length,Tv=()=>`probe-${Ji()}`,vv=()=>`coltr-${Ji()}`,Uf=c=>new Promise(s=>setTimeout(s,c)),Au=(c,s,r)=>{s?c.call(s,r):c(r)},Ke=(c,s,r,o)=>{const a=_l(c,s,r,!0,o);if(a.length===0)return null;const t=a.reduce((h,g)=>h+g,0)/a.length;return t===0?null:a.map(h=>Math.abs(t-h)).reduce((h,g)=>h+g,0)/a.length*100/t},ze=(c,s,r,o=!1,a)=>{const t=_l(c,s,r,o,a);return t.length===0?null:t.reduce((n,d)=>n+d,0)/t.length},vn=(c,s,r)=>_l(c,s,r).reduce((a,t)=>a+t,0),Ye=(c,s,r,o)=>{const a=_l(c,s,r,!0,o);return a.length===0?null:Math.min(...a)},Je=(c,s,r,o)=>{const a=_l(c,s,r,!1,o);return a.length===0?null:Math.max(...a)},gt=(c,s,r,o)=>{const a=c.slice().pop();if(!a)return null;if(!r)return a[s];if(!o)return a[s][r];const t=a[s][o];return t?t[r]:null},Ev=c=>c.slice().pop(),ct=(c,s,r)=>{if(!s)return null;const o={};let a=s[x.AUDIO][c];a||(a=r===$e.INBOUND?{...b_}:{...w_}),o[x.AUDIO]=a;let t=s[x.VIDEO][c];return t||(t=r===$e.INBOUND?{...O_}:{...D_}),o[x.VIDEO]=t,o},Wi="exporter ",Sv="2.0",Pf=(c,s,r)=>{if(!c||c.length===0)return 0;const o=c[c.length-1];if(!o)return 0;const a=o[s][r];if(a){const t=a.total_rtt_ms_out,n=a.total_rtt_measure_out;return!n||!t?ze(c,s,"delta_rtt_ms_out",!1,r):Number(t/n)}return null},yv=(c,s)=>{if(!c||c.length===0)return 0;const r=c[c.length-1];if(!r)return 0;const o=r[s].total_rtt_connectivity_ms,a=r[s].total_rtt_connectivity_measure;return!a||!o?ze(c,s,"delta_rtt_connectivity_ms"):Number(o/a)},Av=c=>gt(c,"network","local_candidate_type")!=="relay"?`direct/${gt(c,"network","local_candidate_protocol")}`:`turn/${gt(c,"network","local_candidate_relay_protocol")}`,Cv=c=>{const s=gt(c,"network","remote_candidate_type"),r=gt(c,"network","remote_candidate_protocol");return s!=="relay"?`direct/${r}`:`turn/${r}`};class Rv{constructor(s){this._start=null,this._end=null,this._cfg=s,this._referenceReport=null,this._reports=[],this._events=[]}start(){tu(Wi,"start() - start exporter...");const s=new Date;return this._start=s.toJSON(),s}stop(){tu(Wi,"stop() - stop exporter...");const s=new Date;return this._end=s.toJSON(),s}saveReferenceReport(s){this._referenceReport=s}getReferenceReport(){return this._referenceReport}addReport(s){this._cfg.ticket&&(Pe(Wi,`addReport() - add report to exporter at ${s.timestamp}`),this._reports.push(s))}addCustomEvent(s){this._events.push(s)}reset(){tu(Wi,"resetReports() - reset reports"),this._reports=[],this._referenceReport=null,this._start=null,this._end=null}get ticket(){Pe(Wi,"ticket() - generate ticket");const s=gt(this._reports,"audio","total_packets_lost_in"),r=gt(this._reports,"audio","total_packets_in"),o=gt(this._reports,"video","total_packets_lost_in"),a=gt(this._reports,"video","total_packets_in"),t={},n=Ev(this._reports);return n&&(Object.keys(n[x.AUDIO]).forEach(d=>{const _=n[x.AUDIO][d];if(t[_.ssrc]={type:x.AUDIO,direction:_.direction},_.direction===$e.INBOUND){const h={avg:ze(this._reports,x.AUDIO,"delta_jitter_ms_in",!1,d),min:Ye(this._reports,x.AUDIO,"delta_jitter_ms_in",d),max:Je(this._reports,x.AUDIO,"delta_jitter_ms_in",d),volatility:Ke(this._reports,x.AUDIO,"delta_jitter_ms_in",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:ze(this._reports,x.AUDIO,"delta_kbs_in",!1,d),min:Ye(this._reports,x.AUDIO,"delta_kbs_in",d),max:Je(this._reports,x.AUDIO,"delta_kbs_in",d),volatility:Ke(this._reports,x.AUDIO,"delta_kbs_in",d),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:ze(this._reports,x.AUDIO,"delta_KBytes_in",!1,d),min:Ye(this._reports,x.AUDIO,"delta_KBytes_in",d),max:Je(this._reports,x.AUDIO,"delta_KBytes_in",d),volatility:Ke(this._reports,x.AUDIO,"delta_KBytes_in",d),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},E={emodel:{avg:ze(this._reports,x.AUDIO,"mos_emodel_in",!1,d),min:Ye(this._reports,x.AUDIO,"mos_emodel_in",d),max:Je(this._reports,x.AUDIO,"mos_emodel_in",d),volatility:Ke(this._reports,x.AUDIO,"mos_emodel_in",d)},effective:{avg:ze(this._reports,x.AUDIO,"mos_in",!1,d),min:Ye(this._reports,x.AUDIO,"mos_in",d),max:Je(this._reports,x.AUDIO,"mos_in",d),volatility:Ke(this._reports,x.AUDIO,"mos_in",d)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}},y=gt(this._reports,x.AUDIO,"total_packets_lost_in",d),A=gt(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"}};t[d].jitter=h,t[d].mos=E,t[d].traffic=T,t[d].bitrate=g,t[d].loss=C}else{const h={avg:ze(this._reports,x.AUDIO,"delta_jitter_ms_out",!1,d),min:Ye(this._reports,x.AUDIO,"delta_jitter_ms_out",d),max:Je(this._reports,x.AUDIO,"delta_jitter_ms_out",d),volatility:Ke(this._reports,x.AUDIO,"delta_jitter_ms_out",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:ze(this._reports,x.AUDIO,"delta_kbs_out",!1,d),min:Ye(this._reports,x.AUDIO,"delta_kbs_out",d),max:Je(this._reports,x.AUDIO,"delta_kbs_out",d),volatility:Ke(this._reports,x.AUDIO,"delta_kbs_out",d),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:ze(this._reports,x.AUDIO,"delta_KBytes_out",!1,d),min:Ye(this._reports,x.AUDIO,"delta_KBytes_out",d),max:Je(this._reports,x.AUDIO,"delta_KBytes_out",d),volatility:Ke(this._reports,x.AUDIO,"delta_KBytes_out",d),_unit:{avg:"KB",min:"KB",max:"KB",bitrate:"kbs",volatility:"percent"}},E={avg:Pf(this._reports,x.AUDIO,d),min:Ye(this._reports,x.AUDIO,"delta_rtt_ms_out",d),max:Je(this._reports,x.AUDIO,"delta_rtt_ms_out",d),volatility:Ke(this._reports,x.AUDIO,"delta_rtt_ms_out",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},y=gt(this._reports,x.AUDIO,"total_packets_lost_out",d),A=gt(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:ze(this._reports,x.AUDIO,"mos_emodel_out",!1,d),min:Ye(this._reports,x.AUDIO,"mos_emodel_out",d),max:Je(this._reports,x.AUDIO,"mos_emodel_out",d),volatility:Ke(this._reports,x.AUDIO,"mos_emodel_out",d)},effective:{avg:ze(this._reports,x.AUDIO,"mos_out",!1,d),min:Ye(this._reports,x.AUDIO,"mos_out",d),max:Je(this._reports,x.AUDIO,"mos_out",d),volatility:Ke(this._reports,x.AUDIO,"mos_out",d)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}};t[d].jitter=h,t[d].rtt=E,t[d].traffic=T,t[d].bitrate=g,t[d].loss=C,t[d].mos=I}}),Object.keys(n[x.VIDEO]).forEach(d=>{const _=n[x.VIDEO][d];if(t[d]={type:x.VIDEO,direction:_.direction},_.direction===$e.INBOUND){const h={avg:ze(this._reports,x.VIDEO,"delta_jitter_ms_in",!1,d),min:Ye(this._reports,x.VIDEO,"delta_jitter_ms_in",d),max:Je(this._reports,x.VIDEO,"delta_jitter_ms_in",d),volatility:Ke(this._reports,x.VIDEO,"delta_jitter_ms_in",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:ze(this._reports,x.VIDEO,"delta_kbs_in",!1,d),min:Ye(this._reports,x.VIDEO,"delta_kbs_in",d),max:Je(this._reports,x.VIDEO,"delta_kbs_in",d),volatility:Ke(this._reports,x.VIDEO,"delta_kbs_in",d),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:ze(this._reports,x.VIDEO,"delta_KBytes_in",!1,d),min:Ye(this._reports,x.VIDEO,"delta_KBytes_in",d),max:Je(this._reports,x.VIDEO,"delta_KBytes_in",d),volatility:Ke(this._reports,x.VIDEO,"delta_KBytes_in",d),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},E=gt(this._reports,x.VIDEO,"total_packets_lost_in",d),y=gt(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"}};t[d].jitter=h,t[d].traffic=T,t[d].bitrate=g,t[d].loss=A}else{const h={avg:ze(this._reports,x.VIDEO,"delta_jitter_ms_out",!1,d),min:Ye(this._reports,x.VIDEO,"delta_jitter_ms_out",d),max:Je(this._reports,x.VIDEO,"delta_jitter_ms_out",d),volatility:Ke(this._reports,x.VIDEO,"delta_jitter_ms_out",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},g={avg:ze(this._reports,x.VIDEO,"delta_kbs_out",!1,d),min:Ye(this._reports,x.VIDEO,"delta_kbs_out",d),max:Je(this._reports,x.VIDEO,"delta_kbs_out",d),volatility:Ke(this._reports,x.VIDEO,"delta_kbs_out",d),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},T={avg:ze(this._reports,x.VIDEO,"delta_KBytes_out",!1,d),min:Ye(this._reports,x.VIDEO,"delta_KBytes_out",d),max:Je(this._reports,x.VIDEO,"delta_KBytes_out",d),volatility:Ke(this._reports,x.VIDEO,"delta_KBytes_out",d),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},E={avg:Pf(this._reports,x.VIDEO,d),min:Ye(this._reports,x.VIDEO,"delta_rtt_ms_out",d),max:Je(this._reports,x.VIDEO,"delta_rtt_ms_out",d),volatility:Ke(this._reports,x.VIDEO,"delta_rtt_ms_out",d),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},y=gt(this._reports,x.VIDEO,"total_packets_lost_out",d),A=gt(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"}};t[d].jitter=h,t[d].rtt=E,t[d].traffic=T,t[d].bitrate=g,t[d].loss=C}})),{version:Sv,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:t,data:{rtt:{avg:yv(this._reports,"data"),min:Ye(this._reports,"data","delta_rtt_connectivity_ms"),max:Je(this._reports,"data","delta_rtt_connectivity_ms"),volatility:Ke(this._reports,"data","delta_rtt_connectivity_ms"),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},packetsLost:{audio:{in:{avg:Math.round((s/(s+r)*100||0)*100)/100}},video:{in:{avg:Math.round((o/(o+a)*100||0)*100)/100}},unit:{avg:"percent"}},bitrate:{in:{avg:ze(this._reports,"data","delta_kbs_in"),min:Ye(this._reports,"data","delta_kbs_in"),max:Je(this._reports,"data","delta_kbs_in"),volatility:Ke(this._reports,"data","delta_kbs_in")},out:{avg:ze(this._reports,"data","delta_kbs_out"),min:Ye(this._reports,"data","delta_kbs_out"),max:Je(this._reports,"data","delta_kbs_out"),volatility:Ke(this._reports,"data","delta_kbs_out")},unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},traffic:{in:{avg:ze(this._reports,"data","delta_KBytes_in"),min:Ye(this._reports,"data","delta_KBytes_in"),max:Je(this._reports,"data","delta_KBytes_in"),volatility:Ke(this._reports,"data","delta_KBytes_in")},out:{avg:ze(this._reports,"data","delta_KBytes_out"),min:Ye(this._reports,"data","delta_KBytes_out"),max:Je(this._reports,"data","delta_KBytes_out"),volatility:Ke(this._reports,"data","delta_KBytes_out")},unit:{avg:"KBytes",min:"KBytes",max:"KBytes",volatility:"percent"}},network:{localConnection:Av(this._reports),remoteConnection:Cv(this._reports)}}}}updateConfig(s){this._cfg=s}getLastReport(){return this._reports.slice().pop()||null}getBeforeLastReport(){const s=this._reports.slice();return s.pop(),s.pop()||null}getReportsNumber(){return this._reports.length}}const Hs="extractor ",xf=(c,s,r,o)=>{let a=!1;const t=o[s].total_rtt_ms_out,n=o[s].total_rtt_measure_out,d=r?r[s].total_rtt_ms_out:0,_=r?r[s].total_rtt_measure_out:0,h={rtt:null,totalRTT:t,totalRTTMeasurements:n};if(c[q.TIMESTAMP]===o[s].timestamp_out||!Object.prototype.hasOwnProperty.call(c,q.ROUND_TRIP_TIME)||Object.prototype.hasOwnProperty.call(c,q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS)&&(a=!0,Number(c[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])===0||Number(c[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-_===n))return h;const g=1e3*Number(c[q.ROUND_TRIP_TIME]);let T=t+g,E=n+1;return a&&(T=1e3*Number(c[q.TOTAL_ROUND_TRIP_TIME])-d,E=Number(c[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-_),{rtt:g,totalRTT:T,totalRTTMeasurements:E}},Iv=(c,s,r,o)=>{if(!Object.prototype.hasOwnProperty.call(c,q.CURRENT_ROUND_TRIP_TIME))return{rtt:null,totalRTT:o[s].total_rtt_connectivity_ms,totalRTTMeasurements:o[s].total_rtt_connectivity_measure};const a=1e3*Number(c[q.CURRENT_ROUND_TRIP_TIME]);let t=o[s].total_rtt_connectivity_ms+a,n=o[s].total_rtt_connectivity_measure+1;return Object.prototype.hasOwnProperty.call(c,q.TOTAL_ROUND_TRIP_TIME)&&(t=1e3*Number(c[q.TOTAL_ROUND_TRIP_TIME])-(r?r[s].total_rtt_connectivity_ms:0)),Object.prototype.hasOwnProperty.call(c,q.RESPONSES_RECEIVED)&&(n=Number(c[q.RESPONSES_RECEIVED])-(r?r[s].total_rtt_connectivity_measure:0)),{rtt:a,totalRTT:t,totalRTTMeasurements:n}},uo=(c,s,r)=>c[q.TIMESTAMP]===r[s].timestamp_out||!Object.prototype.hasOwnProperty.call(c,q.JITTER)?null:1e3*(Number(c[q.JITTER])||0),bv=(c,s)=>{if(!Object.prototype.hasOwnProperty.call(c,q.FRAMES_DECODED)||!Object.prototype.hasOwnProperty.call(c,q.TOTAL_DECODE_TIME))return{delta_ms_decode_frame:s[x.VIDEO].delta_ms_decode_frame_in,frames_decoded:s[x.VIDEO].total_frames_decoded_in,total_decode_time:s[x.VIDEO].total_time_decoded_in};const r=c[q.FRAMES_DECODED],o=c[q.TOTAL_DECODE_TIME],a=o-s[x.VIDEO].total_time_decoded_in,t=r-s[x.VIDEO].total_frames_decoded_in;return{delta_ms_decode_frame:t>0?a*1e3/t:0,frames_decoded:r,total_decode_time:o}},wv=(c,s)=>{if(!Object.prototype.hasOwnProperty.call(c,q.FRAMES_ENCODED)||!Object.prototype.hasOwnProperty.call(c,q.TOTAL_ENCODE_TIME))return{delta_ms_encode_frame:s[x.VIDEO].delta_ms_encode_frame_out,frames_encoded:s[x.VIDEO].total_frames_encoded_out,total_encode_time:s[x.VIDEO].total_time_encoded_out};const r=c[q.FRAMES_ENCODED],o=c[q.TOTAL_ENCODE_TIME],a=o-s[x.VIDEO].total_time_encoded_out,t=r-s[x.VIDEO].total_frames_encoded_out;return{delta_ms_encode_frame:t>0&&a?a*1e3/t:0,frames_encoded:r,total_encode_time:o}},Mf=(c,s,r,o)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PACKETS_SENT)||!Object.prototype.hasOwnProperty.call(c,q.BYTES_SENT))return{packetsSent:r[s].total_packets_out,packetsLost:r[s].total_packets_lost_out,bytesSent:r[s].total_KBytes_out};const a=Number(c[q.PACKETS_SENT])||0-(o?o[s].total_packets_out:0),t=a-r[s].total_packets_out,n=Number(c[q.BYTES_SENT])/1024-(o?o[s].total_KBytes_out:0),d=n-r[s].total_KBytes_out,_=c[q.TIMESTAMP]||Date.now(),h=o?o.timestamp:null;let g=r.timestamp;!g&&h&&(g=h);const T=g?_-g:0,E=T>0?d*.008*1024/T*1e3:0;return{packetsSent:a,deltaPacketsSent:t,KBytesSent:n,deltaKBytesSent:d,kbsSent:E}},kf=(c,s,r,o)=>{let a=r[s].total_packets_lost_out,t=0,n=0;return Object.prototype.hasOwnProperty.call(c,q.PACKETS_LOST)&&(a=Number(c[q.PACKETS_LOST])||0-(o?o[s].total_packets_lost_out:0),t=a-r[s].total_packets_lost_out),Object.prototype.hasOwnProperty.call(c,q.FRACTION_LOST)&&(n=Number(100*c[q.FRACTION_LOST])),{packetsLost:a,deltaPacketsLost:t,fractionLost:n}},Lf=(c,s,r,o)=>{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:r[s].percent_packets_lost_in,packetsReceived:r[s].total_packets_in,packetsLost:r[s].total_packets_lost_in,bytesReceived:r[s].total_KBytes_in};const a=Number(c[q.PACKETS_RECEIVED])||0-(o?o[s].total_packets_in:0),t=Number(c[q.PACKETS_LOST])||0-(o?o[s].total_packets_lost_in:0),n=t-r[s].total_packets_lost_in,d=a-r[s].total_packets_in,_=a!==r[s].total_packets_in?n*100/(n+d):0,h=Number(c[q.BYTES_RECEIVED])/1024-(o?o[s].total_KBytes_in:0),g=h-r[s].total_KBytes_in,T=c[q.TIMESTAMP]||Date.now(),E=o?o.timestamp:null;let y=r.timestamp;!y&&E&&(y=E);const A=y?T-y:0,C=A>0?g*.008*1024/A*1e3:0;return{percentPacketsLost:_,packetsReceived:a,deltaPacketsReceived:d,packetsLost:t,deltaPacketsLost:n,KBytesReceived:h,deltaKBytesReceived:g,kbsReceived:C}},Ov=c=>c[q.CANDIDATE_TYPE]!=="relay"?"":c[q.RELAY_PROTOCOL]||"",Dv=c=>{if(!Object.prototype.hasOwnProperty.call(c,q.NETWORK_TYPE))return Gi.WIFI;switch(c[q.NETWORK_TYPE]){case su.ETHERNET:return Gi.ETHERNET;case su.CELLULAR_4G:return Gi.CELLULAR_4G;case su.WIFI:return Gi.WIFI;default:return Gi.CELLULAR}},$f=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]},Nv=c=>{const s=Object.prototype.hasOwnProperty.call(c,q.QUALITY_LIMITATION_REASON)?c[q.QUALITY_LIMITATION_REASON]:null,r=Object.prototype.hasOwnProperty.call(c,q.QUALITY_LIMITATION_RESOLUTION_CHANGES)?c[q.QUALITY_LIMITATION_RESOLUTION_CHANGES]:null,o=Object.prototype.hasOwnProperty.call(c,q.QUALITY_LIMITATION_DURATIONS)?c[q.QUALITY_LIMITATION_DURATIONS]:null;return o&&Object.keys(o).forEach(a=>{o[a]>1e3&&(o[a]=Number(o[a]/1e3))}),{reason:s,durations:o,resolutionChanges:r}},Uv=(c,s,r)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PLI)||!Object.prototype.hasOwnProperty.call(c,q.NACK))return{pliCount:s.total_pli_sent_in,nackCount:s.total_nack_sent_in,deltaPliCount:0,deltaNackCount:0};const o=(c[q.PLI]||0)-(r?r[x.VIDEO].total_pli_sent_in:0),a=(c[q.NACK]||0)-(r?r[x.VIDEO].total_nack_sent_in:0);return{pliCount:o,nackCount:a,deltaPliCount:o-s[x.VIDEO].total_pli_sent_in,deltaNackCount:a-s[x.VIDEO].total_nack_sent_in}},Pv=(c,s,r)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PLI)||!Object.prototype.hasOwnProperty.call(c,q.NACK))return{pliCount:s.total_pli_received_out,nackCount:s.total_nack_received_out,deltaPliCount:0,deltaNackCount:0};const o=(c[q.PLI]||0)-(r?r[x.VIDEO].total_pli_received_out:0),a=(c[q.NACK]||0)-(r?r[x.VIDEO].total_nack_received_out:0);return{pliCount:o,nackCount:a,deltaPliCount:o-s[x.VIDEO].total_pli_received_out,deltaNackCount:a-s[x.VIDEO].total_nack_received_out}},xv=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}),Mv=c=>({clock_rate:c[q.CLOCK_RATE]||null,mime_type:c[q.MIME_TYPE]||null}),kv=(c,s,r)=>{const o=(c[q.BYTES_RECEIVED]||0)/1024-(r?r.data.total_KBytes_in:0),a=(c[q.BYTES_SENT]||0)/1024-(r?r.data.total_KBytes_out:0),t=c[q.TIMESTAMP]||Date.now(),n=o-s.data.total_KBytes_in,d=a-s.data.total_KBytes_out,_=r?r.timestamp:null;let h=s.timestamp;!h&&_&&(h=_);const g=h?t-h:0,T=g>0?n*.008*1024/g*1e3:0,E=g>0?d*.008*1024/g*1e3:0;return{total_KBytes_received:o,total_KBytes_sent:a,delta_KBytes_received:n,delta_KBytes_sent:d,kbs_speed_received:T,kbs_speed_sent:E}},Lv=c=>{const s=c[q.AVAILABLE_INCOMING_BITRATE]/1024||0,r=c[q.AVAILABLE_OUTGOING_BITRATE]/1024||0;return{kbs_incoming_bandwidth:s,kbs_outgoing_bandwidth:r}},$v=(c,s,r,o)=>{if(!c)return[];switch(c[q.TYPE]){case Jt.CANDIDATE_PAIR:let a=!1;if(c[q.NOMINATED]&&c[q.STATE]===x.SUCCEEDED&&(a=!0,Pe(Hs,`analyze() - got stats ${c[q.TYPE]} for ${r}`,c),q.SELECTED in c&&!c[q.SELECTED]&&(a=!1)),a){const n=c[q.LOCAL_CANDIDATE_ID],d=c[q.REMOTE_CANDIDATE_ID],_=kv(c,s,o),h=Lv(c),g=Iv(c,"data",o,s);return[{type:ne.NETWORK,value:{local_candidate_id:n}},{type:ne.NETWORK,value:{remote_candidate_id:d}},{type:ne.DATA,value:{total_KBytes_in:_.total_KBytes_received}},{type:ne.DATA,value:{total_KBytes_out:_.total_KBytes_sent}},{type:ne.DATA,value:{delta_KBytes_in:_.delta_KBytes_received}},{type:ne.DATA,value:{delta_KBytes_out:_.delta_KBytes_sent}},{type:ne.DATA,value:{delta_kbs_in:_.kbs_speed_received}},{type:ne.DATA,value:{delta_kbs_out:_.kbs_speed_sent}},{type:ne.DATA,value:{delta_kbs_bandwidth_in:h.kbs_incoming_bandwidth}},{type:ne.DATA,value:{delta_kbs_bandwidth_out:h.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 Jt.LOCAL_CANDIDATE:if(c[q.ID]===s.network.local_candidate_id)return[{type:ne.NETWORK,value:{infrastructure:Dv(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:Ov(c)}}];break;case Jt.REMOTE_CANDIDATE:if(c[q.ID]===s.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 Jt.INBOUND_RTP:{Pe(Hs,`analyze() - got stats ${c[q.TYPE]} for ${r}`,c);const n=c[q.SSRC],d=ct(n,s,$e.INBOUND);d&&(d.timestamp=s.timestamp);const _=ct(n,o,$e.INBOUND);if(_&&(_.timestamp=o.timestamp),c[q.MEDIA_TYPE]===x.AUDIO){const h=Lf(c,x.AUDIO,d,_),g=uo(c,x.AUDIO,d),T=c[q.CODEC_ID]||"";return[{ssrc:n,type:ne.AUDIO,value:{codec_id_in:T}},{ssrc:n,type:ne.AUDIO,value:{total_packets_in:h.packetsReceived}},{ssrc:n,type:ne.AUDIO,value:{delta_packets_in:h.deltaPacketsReceived}},{ssrc:n,type:ne.AUDIO,value:{total_packets_lost_in:h.packetsLost}},{ssrc:n,type:ne.AUDIO,value:{delta_packets_lost_in:h.deltaPacketsLost}},{ssrc:n,type:ne.AUDIO,value:{percent_packets_lost_in:h.percentPacketsLost}},{ssrc:n,type:ne.AUDIO,value:{total_KBytes_in:h.KBytesReceived}},{ssrc:n,type:ne.AUDIO,value:{delta_KBytes_in:h.deltaKBytesReceived}},{ssrc:n,type:ne.AUDIO,value:{delta_kbs_in:h.kbsReceived}},{ssrc:n,type:ne.AUDIO,value:{delta_jitter_ms_in:g}}]}if(c[q.MEDIA_TYPE]===x.VIDEO){const h=bv(c,d),g=Lf(c,x.VIDEO,d,_),T=uo(c,x.VIDEO,d),E=c[q.DECODER_IMPLEMENTATION]||null,y=c[q.CODEC_ID]||null,A=$f(c),C=Uv(c,d,_);return[{ssrc:n,type:ne.VIDEO,value:{codec_id_in:y}},{ssrc:n,type:ne.VIDEO,value:{total_packets_in:g.packetsReceived}},{ssrc:n,type:ne.VIDEO,value:{delta_packets_in:g.deltaPacketsReceived}},{ssrc:n,type:ne.VIDEO,value:{total_packets_lost_in:g.packetsLost}},{ssrc:n,type:ne.VIDEO,value:{delta_packets_lost_in:g.deltaPacketsLost}},{ssrc:n,type:ne.VIDEO,value:{percent_packets_lost_in:g.percentPacketsLost}},{ssrc:n,type:ne.VIDEO,value:{total_KBytes_in:g.KBytesReceived}},{ssrc:n,type:ne.VIDEO,value:{delta_KBytes_in:g.deltaKBytesReceived}},{ssrc:n,type:ne.VIDEO,value:{delta_kbs_in:g.kbsReceived}},{ssrc:n,type:ne.VIDEO,value:{delta_jitter_ms_in:T}},{ssrc:n,type:ne.VIDEO,value:{decoder_in:E}},{ssrc:n,type:ne.VIDEO,value:{delta_ms_decode_frame_in:h.delta_ms_decode_frame}},{ssrc:n,type:ne.VIDEO,value:{total_frames_decoded_in:h.frames_decoded}},{ssrc:n,type:ne.VIDEO,value:{total_time_decoded_in:h.total_decode_time}},{ssrc:n,type:ne.VIDEO,value:{total_nack_sent_in:C.nackCount}},{ssrc:n,type:ne.VIDEO,value:{delta_nack_sent_in:C.deltaNackCount}},{ssrc:n,type:ne.VIDEO,value:{total_pli_sent_in:C.pliCount}},{ssrc:n,type:ne.VIDEO,value:{delta_pli_sent_in:C.deltaPliCount}},{ssrc:n,type:ne.VIDEO,value:{size_in:A}}]}break}case Jt.OUTBOUND_RTP:{Pe(Hs,`analyze() - got stats ${c[q.TYPE]} for ${r}`,c);const n=c[q.SSRC],d=ct(n,s,$e.OUTBOUND);d&&(d.timestamp=s.timestamp);const _=ct(n,o,$e.OUTBOUND);if(_&&(_.timestamp=o.timestamp),c[q.MEDIA_TYPE]===x.AUDIO){const h=c[q.CODEC_ID]||null,g=Mf(c,x.AUDIO,d,_);return[{ssrc:n,type:ne.AUDIO,value:{codec_id_out:h}},{ssrc:n,type:ne.AUDIO,value:{total_packets_out:g.packetsSent}},{ssrc:n,type:ne.AUDIO,value:{delta_packets_out:g.deltaPacketsSent}},{ssrc:n,type:ne.AUDIO,value:{total_KBytes_out:g.KBytesSent}},{ssrc:n,type:ne.AUDIO,value:{delta_KBytes_out:g.deltaKBytesSent}},{ssrc:n,type:ne.AUDIO,value:{delta_kbs_out:g.kbsSent}}]}if(c[q.MEDIA_TYPE]===x.VIDEO){const h=c[q.ENCODER_IMPLEMENTATION]||null,g=c[q.CODEC_ID]||null,T=wv(c,d),E=$f(c),y=Nv(c),A=Pv(c,d,_),C=Mf(c,x.VIDEO,d,_);return[{ssrc:n,type:ne.VIDEO,value:{codec_id_out:g}},{ssrc:n,type:ne.VIDEO,value:{total_packets_out:C.packetsSent}},{ssrc:n,type:ne.VIDEO,value:{delta_packets_out:C.deltaPacketsSent}},{ssrc:n,type:ne.VIDEO,value:{total_KBytes_out:C.KBytesSent}},{ssrc:n,type:ne.VIDEO,value:{delta_KBytes_out:C.deltaKBytesSent}},{ssrc:n,type:ne.VIDEO,value:{delta_kbs_out:C.kbsSent}},{ssrc:n,type:ne.VIDEO,value:{encoder_out:h}},{ssrc:n,type:ne.VIDEO,value:{delta_ms_encode_frame_out:T.delta_ms_encode_frame}},{ssrc:n,type:ne.VIDEO,value:{total_frames_encoded_out:T.frames_encoded}},{ssrc:n,type:ne.VIDEO,value:{total_time_encoded_out:T.total_encode_time}},{ssrc:n,type:ne.VIDEO,value:{total_nack_received_out:A.nackCount}},{ssrc:n,type:ne.VIDEO,value:{delta_nack_received_out:A.deltaNackCount}},{ssrc:n,type:ne.VIDEO,value:{total_pli_received_out:A.pliCount}},{ssrc:n,type:ne.VIDEO,value:{delta_pli_received_out:A.deltaPliCount}},{ssrc:n,type:ne.VIDEO,value:{size_out:E}},{ssrc:n,type:ne.VIDEO,value:{limitation_out:y}}]}break}case Jt.MEDIA_SOURCE:{Pe(Hs,`analyze() - got stats ${c[q.TYPE]} for ${r}`,c);break}case Jt.TRACK:{Pe(Hs,`analyze() - got stats ${c[q.TYPE]} for ${r}`,c);break}case Jt.CODEC:const t=[];return Object.keys(s[x.AUDIO]).forEach(n=>{const d=s[x.AUDIO][n];if(d.codec_id_in===c[q.ID]||d.codec_id_out===c[q.ID]){Pe(Hs,`analyze() - got stats ${c[q.TYPE]} for ${r}`,c);const _=xv(c);c[q.ID]===d.codec_id_in?t.push({ssrc:d.ssrc,type:ne.AUDIO,value:{codec_in:_}}):t.push({ssrc:d.ssrc,type:ne.AUDIO,value:{codec_out:_}})}}),Object.keys(s[x.VIDEO]).forEach(n=>{const d=s[x.VIDEO][n];if(d.codec_id_in===c[q.ID]||d.codec_id_out===c[q.ID]){Pe(Hs,`analyze() - got stats ${c[q.TYPE]} for ${r}`,c);const _=Mv(c);c[q.ID]===d.codec_id_in?t.push({ssrc:d.ssrc,type:ne.VIDEO,value:{codec_in:_}}):t.push({ssrc:d.ssrc,type:ne.VIDEO,value:{codec_out:_}})}}),t;case Jt.REMOTE_INBOUND_RTP:{Pe(Hs,`analyze() - got stats ${c[q.TYPE]} for ${r}`,c);const n=c[q.SSRC],d=ct(n,s,$e.OUTBOUND),_=ct(n,o,$e.OUTBOUND);if(c[q.KIND]===x.AUDIO){const h=xf(c,x.AUDIO,_,d),g=uo(c,x.AUDIO,d),T=kf(c,x.AUDIO,d,_);return[{ssrc:n,type:ne.AUDIO,value:{delta_rtt_ms_out:h.rtt}},{ssrc:n,type:ne.AUDIO,value:{total_rtt_ms_out:h.totalRTT}},{ssrc:n,type:ne.AUDIO,value:{total_rtt_measure_out:h.totalRTTMeasurements}},{ssrc:n,type:ne.AUDIO,value:{delta_jitter_ms_out:g}},{ssrc:n,type:ne.AUDIO,value:{timestamp_out:c[q.TIMESTAMP]}},{ssrc:n,type:ne.AUDIO,value:{total_packets_lost_out:T.packetsLost}},{ssrc:n,type:ne.AUDIO,value:{delta_packets_lost_out:T.deltaPacketsLost}},{ssrc:n,type:ne.AUDIO,value:{percent_packets_lost_out:T.fractionLost}}]}if(c[q.KIND]===x.VIDEO){const h=xf(c,x.VIDEO,_,d),g=uo(c,x.VIDEO,d),T=kf(c,x.VIDEO,d,_);return[{ssrc:n,type:ne.VIDEO,value:{delta_rtt_ms_out:h.rtt}},{ssrc:n,type:ne.VIDEO,value:{total_rtt_ms_out:h.totalRTT}},{ssrc:n,type:ne.VIDEO,value:{total_rtt_measure_out:h.totalRTTMeasurements}},{ssrc:n,type:ne.VIDEO,value:{delta_jitter_ms_out:g}},{ssrc:n,type:ne.VIDEO,value:{timestamp_out:c[q.TIMESTAMP]}},{ssrc:n,type:ne.VIDEO,value:{total_packets_lost_out:T.packetsLost}},{ssrc:n,type:ne.VIDEO,value:{delta_packets_lost_out:T.deltaPacketsLost}},{ssrc:n,type:ne.VIDEO,value:{percent_packets_lost_out:T.fractionLost}}]}break}}return[]},Bo=c=>c<0?1:c>100?4.5:1+.035*c+7/1e6*c*(c-60)*(100-c),Hv=(c,s=x.AUDIO,r,o,a)=>{const t=ct(a,c,$e.INBOUND),n=ct(a,r,$e.INBOUND),d=ct(a,o,$e.INBOUND),_=[],h=[],g=t[s].percent_packets_lost_in,T=t[s].delta_jitter_ms_in,E=n&&n[s].delta_jitter_ms_in||null,y=d&&d[s].delta_jitter_ms_in||null,A=c.data.delta_rtt_connectivity_ms,C=r&&r.data.delta_rtt_connectivity_ms||null,I=o&&o.data.delta_rtt_connectivity_ms||null;A&&_.push(A),C&&_.push(C),I&&_.push(I),T&&h.push(T),r&&E&&h.push(E),o&&y&&h.push(y);const H=_.length>0?Vs(_):100,L=h.length>0?Vs(h):10,ae=93.2-g,N=.18*ae*ae-27.9*ae+1126.62,j=(H+L)/2,Se=j-177.3<0?0:1,ve=.024*j+.11*(j-177.3)*Se,M=N-ve;return Bo(M)},Fv=(c,s=x.AUDIO,r,o,a)=>{const t=ct(a,c,$e.OUTBOUND),n=ct(a,r,$e.OUTBOUND),d=ct(a,o,$e.OUTBOUND),_=[],h=[],g=t[s].percent_packets_lost_out,T=t[s].delta_rtt_ms_out,E=n&&n[s].delta_rtt_ms_out||null,y=d&&d[s].delta_rtt_ms_out||null,A=t[s].delta_jitter_ms_out,C=n&&n[s].delta_jitter_ms_out||null,I=d&&d[s].delta_jitter_ms_out||null,H=c.data.delta_rtt_connectivity_ms,L=r&&r.data.delta_rtt_connectivity_ms||null,ae=o&&o.data.delta_rtt_connectivity_ms||null;T?_.push(T):H&&_.push(H),E?_.push(E):L&&_.push(L),y?_.push(y):ae&&_.push(ae),A&&h.push(A),r&&C&&h.push(C),o&&I&&h.push(I);const N=_.length>0?Vs(_):100,j=h.length>0?Vs(h):10,Se=93.2-g,ve=.18*Se*Se-27.9*Se+1126.62,M=(N+j)/2,D=M-177.3<0?0:1,B=.024*M+.11*(M-177.3)*D,V=ve-B;return Bo(V)},jv=(c,s=x.AUDIO,r,o,a)=>{const t=ct(a,c,$e.INBOUND),n=ct(a,r,$e.INBOUND),d=ct(a,o,$e.INBOUND),_=[],h=[],g=t[s].percent_packets_lost_in/100,T=t[s].delta_jitter_ms_in,E=n&&n[s].delta_jitter_ms_in||null,y=d&&d[s].delta_jitter_ms_in||null,A=c.data.delta_rtt_connectivity_ms,C=r&&r.data.delta_rtt_connectivity_ms||null,I=o&&o.data.delta_rtt_connectivity_ms||null;A&&_.push(A),C&&_.push(C),I&&_.push(I),T&&h.push(T),n&&E&&h.push(E),d&&y&&h.push(y);const H=_.length>0?Vs(_):100,L=h.length>0?Vs(h):10,ae=0,N=19.8,j=29.7,Se=30,ve=(H+L)/2+Se,M=ve-177.3<0?0:1,D=.024*ve+.11*(ve-177.3)*M,V=93.2-(ae+N*Math.log(1+j*g)+D);return Bo(V)},qv=(c,s=x.AUDIO,r,o,a)=>{const t=ct(a,c,$e.OUTBOUND),n=ct(a,r,$e.OUTBOUND),d=ct(a,o,$e.OUTBOUND),_=[],h=[],g=t[s].percent_packets_lost_out/100,T=t[s].delta_rtt_ms_out,E=n&&n[s].delta_rtt_ms_out||null,y=d&&d[s].delta_rtt_ms_out||null,A=t[s].delta_jitter_ms_out,C=n&&n[s].delta_jitter_ms_out||null,I=d&&d[s].delta_jitter_ms_out||null,H=c.data.delta_rtt_connectivity_ms,L=r&&r.data.delta_rtt_connectivity_ms||null,ae=o&&o.data.delta_rtt_connectivity_ms||null;T?_.push(T):H&&_.push(H),E?_.push(E):L&&_.push(L),y?_.push(y):ae&&_.push(ae),A&&h.push(A),n&&C&&h.push(C),d&&I&&h.push(I);const N=_.length>0?Vs(_):100,j=h.length>0?Vs(h):10,Se=0,ve=19.8,M=29.7,D=30,B=(N+j)/2+D,V=B-177.3<0?0:1,J=.024*B+.11*(B-177.3)*V,X=93.2-(Se+ve*Math.log(1+M*g)+J);return Bo(X)};class Vv{constructor(s,r){this._callbacks={onreport:null,onticket:null},this._id=vv(),this._moduleName=this._id,this._probeId=r,this._config=s,this._exporter=new Rv(s),this._state=ps.IDLE,this.registerToPCEvents(),An(this._moduleName,`new collector created for probe ${this._probeId}`)}analyze(s,r,o,a){const t=(_,h)=>_===x.AUDIO?h===Jt.INBOUND_RTP?{...b_}:{...w_}:h===Jt.INBOUND_RTP?{...O_}:{...D_},n=dv(r);n.pname=this._config.pname,n.call_id=this._config.cid,n.user_id=this._config.uid,n.count=r?r.count+1:1;let d=null;return s.forEach(_=>{!d&&_.timestamp&&(d=_.timestamp),$v(_,n,n.pname,a).forEach(g=>{if(g.value&&g.type)if(g.ssrc){let T=n[g.type][g.ssrc];T||(T=t(g.type,_.type),T.ssrc=g.ssrc,n[g.type][g.ssrc]=T),Object.keys(g.value).forEach(E=>{T[E]=g.value[E]})}else Object.keys(g.value).forEach(T=>{n[g.type][T]=g.value[T]})})}),n.timestamp=d,Object.keys(n[x.AUDIO]).forEach(_=>{const h=n[x.AUDIO][_];h.direction===$e.INBOUND?(h.mos_emodel_in=Hv(n,x.AUDIO,r,o,h.ssrc),h.mos_in=jv(n,x.AUDIO,r,o,h.ssrc)):(h.mos_emodel_out=Fv(n,x.AUDIO,r,o,h.ssrc),h.mos_out=qv(n,x.AUDIO,r,o,h.ssrc))}),n}async takeReferenceStats(){return new Promise((s,r)=>{const o=Date.now();setTimeout(async()=>{try{const a=Date.now()-o,t=Date.now(),n=await this._config.pc.getStats(),d=this.analyze(n,null,null,null),_=Date.now();d.experimental.time_to_measure_ms=_-t,d.experimental.time_to_wait_ms=a,this._exporter.saveReferenceReport(d),Pe(this._moduleName,`got reference report for probe ${this._probeId}`),s()}catch(a){r(a)}},this._config.startAfter)})}async collectStats(){try{if(this._state!==ps.RUNNING||!this._config.pc)return Pe(this._moduleName,`report discarded (too late) for probe ${this._probeId}`),null;const s=Date.now(),r=await this._config.pc.getStats(),o=this.analyze(r,this._exporter.getLastReport(),this._exporter.getBeforeLastReport(),this._exporter.getReferenceReport()),a=Date.now();return o.experimental.time_to_measure_ms=a-s,this._exporter.addReport(o),Pe(this._moduleName,`got report for probe ${this._probeId}#${this._exporter.getReportsNumber()+1}`),this.fireOnReport(o),o}catch(s){return cr(this._moduleName,`got error ${s}`),null}}async start(){Pe(this._moduleName,"starting"),this.state=ps.RUNNING,this._startedTime=this._exporter.start(),Pe(this._moduleName,"started")}async mute(){this.state=ps.MUTED,Pe(this._moduleName,"muted")}async unmute(){this.state=ps.RUNNING,Pe(this._moduleName,"unmuted")}async stop(s){if(Pe(this._moduleName,`stopping${s?" by watchdog":""}...`),this._stoppedTime=this._exporter.stop(),this.state=ps.IDLE,this._config.ticket){const{ticket:r}=this._exporter;this.fireOnTicket(r)}this._exporter.reset(),Pe(this._moduleName,"stopped")}registerCallback(s,r,o){s in this._callbacks?(this._callbacks[s]={callback:r,context:o},Pe(this._moduleName,`registered callback '${s}'`)):cr(this._moduleName,`can't register callback for '${s}' - not found`)}unregisterCallback(s){s in this._callbacks?(this._callbacks[s]=null,delete this._callbacks[s],Pe(this._moduleName,`unregistered callback '${s}'`)):cr(this._moduleName,`can't unregister callback for '${s}' - not found`)}fireOnReport(s){this._callbacks.onreport&&Au(this._callbacks.onreport.callback,this._callbacks.onreport.context,s)}fireOnTicket(s){this._callbacks.onticket&&Au(this._callbacks.onticket.callback,this._callbacks.onticket.context,s)}updateConfig(s){this._config=s,this._exporter.updateConfig(s)}get state(){return this._state}set state(s){this._state=s,Pe(this._moduleName,`state changed to ${s}`)}addCustomEvent(s,r,o,a){this._exporter.addCustomEvent({at:typeof s=="object"?s.toJSON():s,category:r,name:o,description:a})}async registerToPCEvents(){const{pc:s}=this._config;if(navigator.mediaDevices.ondevicechange=async()=>{try{const r=await navigator.mediaDevices.enumerateDevices();this.addCustomEvent(new Date().toJSON(),"device",`${r.length} devices found`,"Media Devices state")}catch{cr(this._moduleName,"can't get devices")}},s){s.oniceconnectionstatechange=()=>{const o=s.iceConnectionState;o===Bi.CONNECTED||o===Bi.COMPLETED?this.addCustomEvent(new Date().toJSON(),"call",o,"ICE connection state"):o===Bi.DISCONNECTED||o===Bi.FAILED?this.addCustomEvent(new Date().toJSON(),"call",o,"ICE connection state"):o===Bi.CLOSED&&this.addCustomEvent(new Date().toJSON(),"call","ended","ICE connection state")},s.onicegatheringstatechange=()=>{const o=s.iceGatheringState;this.addCustomEvent(new Date().toJSON(),"call",o,"ICE gathering state")},s.ontrack=o=>{this.addCustomEvent(new Date().toJSON(),"call",`${o.track.kind}track`,"MediaStreamTrack received")},s.onnegotiationneeded=()=>{this.addCustomEvent(new Date().toJSON(),"call","negotiation","Media changed")};const r=s.getReceivers();if(r&&r.length>0){const o=r[0],{transport:a}=o;if(a){const{iceTransport:t}=a;t&&(t.onselectedcandidatepairchange=()=>{this.addCustomEvent(new Date().toJSON(),"call","transport","Candidates Pair changed")})}}}}}class Bv{constructor(s){this._id=s.pname&&s.pname.substr(0,12).padEnd(12," ")||Tv(),this._moduleName=this._id,An(this._moduleName,"probe created"),this._config=s,this._collector=new Vv(this._config,this._id)}set onreport(s){s?this._collector.registerCallback("onreport",s):this._collector.unregisterCallback("onreport")}set onticket(s){s?this._collector.registerCallback("onticket",s):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(s){this._collector.state=s}addCustomEvent(s,r,o,a=new Date().toJSON()){this._collector.addCustomEvent(a,r,s,o)}get isRunning(){return this._collector.state===ps.RUNNING}get isIdle(){return this._collector.state===ps.IDLE}updateUserId(s){this._config.uid=s,this._collector.updateConfig(this._config)}updateCallId(s){this._config.cid=s,this._collector.updateConfig(this._config)}start(){if(!this.isIdle){Ro(this._moduleName,"probe is already running");return}this._collector.start()}stop(s=!1){this.isRunning&&this._collector.stop(s)}async takeReferenceStats(){return this._collector.takeReferenceStats()}async collectStats(){return this._collector.collectStats()}}const Ct="engine ";class Gv{constructor(s){this._config=s,this._probes=[],this._startedTime=null,this._callbacks={onresult:null},An(Ct,`configured for probing every ${this._config.refreshEvery}ms`),An(Ct,`configured for starting after ${this._config.startAfter}ms`),An(Ct,`${!this._config.stopAfter||this._config.stopAfter!==-1?`configured for stopped after ${this._config.stopAfter}ms`:"configured for never stopped"}`),Pe(Ct,"engine initialized")}get probes(){return this._probes}get isRunning(){return this._probes.some(s=>s.isRunning)}get isIdle(){return this._probes.every(s=>s.isIdle)}addNewProbe(s,r){if(!s)throw new Error("undefined peer connection");const o=mv(s,r,this._config),a=new Bv(o);return this._probes.push(a),Pe(Ct,`${this._probes.length} probes registered`),a}removeExistingProbe(s){if(!s)throw new Error("undefined probe");s.state===ps.RUNNING&&s.stop(),this._probes=this._probes.filter(r=>s.id!==r.id)}async start(){const s=()=>{this._probes.forEach(t=>t.start())},r=async()=>Promise.all(this._probes.map(t=>t.takeReferenceStats())),o=()=>this.isIdle?!1:!this._config.stopAfter||this._config.stopAfter<0?!0:Date.now()<this._startedTime+this._config.stopAfter,a=async()=>{const t=hv(),n=this._probes.filter(d=>d.isRunning);for(const d of n){const _=await d.collectStats();_&&t.probes.push(_),Pe(Ct,`got probe ${d.id}`),await Uf(0)}return t.delta_time_to_measure_probes_ms=vn(t.probes,"experimental","time_to_measure_ms"),t.delta_KBytes_in=vn(t.probes,"data","delta_KBytes_in"),t.delta_KBytes_out=vn(t.probes,"data","delta_KBytes_out"),t.delta_kbs_in=vn(t.probes,"data","delta_kbs_in"),t.delta_kbs_out=vn(t.probes,"data","delta_kbs_out"),t.total_time_decoded_in=vn(t.probes,"video","total_time_decoded_in"),t.total_time_encoded_out=vn(t.probes,"video","total_time_encoded_out"),t};for(Pe(Ct,"starting to collect"),s(),Pe(Ct,"generating reference reports..."),await r(),Pe(Ct,"reference reports generated"),this._startedTime=Date.now();o();)if(Pe(Ct,`wait ${this._config.refreshEvery}ms before collecting`),await Uf(this._config.refreshEvery),o()){Pe(Ct,"collecting...");const t=Date.now(),n=await a(),d=Date.now();n.delta_time_consumed_to_measure_ms=d-t,this.fireOnReports(n),Pe(Ct,"collected")}Pe(Ct,"reaching end of the collecting period..."),this.isRunning&&setTimeout(()=>{this.stop()},0)}stop(s){const r=o=>{this._probes.forEach(a=>{a.stop(o)})};An(Ct,"stop collecting"),r(s)}registerCallback(s,r,o){s in this._callbacks?(this._callbacks[s]={callback:r,context:o},Pe(Ct,`registered callback '${s}'`)):cr(Ct,`can't register callback for '${s}' - not found`)}unregisterCallback(s){s in this._callbacks?(this._callbacks[s]=null,delete this._callbacks[s],Pe(this._moduleName,`unregistered callback '${s}'`)):cr(this._moduleName,`can't unregister callback for '${s}' - not found`)}fireOnReports(s){this._callbacks.onresult&&s.probes.length>0&&Au(this._callbacks.onresult.callback,this._callbacks.onresult.context,s)}}const Wv="interface ";class Kv{constructor(s){this._config=gv(s),An(Wv,`welcome to ${this._config.name} version ${this._config.version}`),iv(this._config.verbose||!1),this._engine=new Gv(this._config)}setupLogLevel(s){lv(s)}get version(){return this._config.version}get name(){return this._config.name}get probes(){return this._engine.probes}createProbe(s,r){return this._engine.addNewProbe(s,r)}startAllProbes(){this._engine.start()}stopAllProbes(){this._engine.stop()}get running(){return this._engine.isRunning}get idle(){return this._engine.isIdle}removeProbe(s){this._engine.removeExistingProbe(s)}set onresult(s){s?this._engine.registerCallback("onresult",s):this._engine.unregisterCallback("onresult")}}function Yv(c,s){return Object.keys(c).filter(r=>s.includes(r)).reduce((r,o)=>{const a=o;return{...r,[a]:c[a]}},{})}const Jv=["mos_in","codec_in","delta_KBytes_in","delta_kbs_in","delta_jitter_ms_in","delta_packets_lost_in"];class zv{constructor(s){this.intervals={},this.emitInterval=s.emitInterval||200,this.onChangeFunction=s.onChangeFunction}start(s,r){s&&s.getTracks().length&&requestAnimationFrame(()=>this.beginCalculation(s,r))}stop(s){this.clearVolumeInterval(s)}clearVolumeInterval(s){console.log("clearVolumeInterval",s),clearInterval(this.intervals[s]),delete this.intervals[s]}clearAllIntervals(){Object.keys(this.intervals).forEach(s=>{clearInterval(this.intervals[s])}),this.intervals={}}beginCalculation(s,r){this.clearVolumeInterval(r);const o=yn.createAnalyser(),a=yn.createMediaStreamSource(s),t=yn.createScriptProcessor(2048,1,1);o.smoothingTimeConstant=.8,o.fftSize=1024,a.connect(o),o.connect(t),t.connect(yn.destination),this.intervals[r]=setInterval(()=>{const n=new Uint8Array(o.frequencyBinCount);o.getByteFrequencyData(n);let d=0;const _=n.length;for(let g=0;g<_;g++)d+=n[g];const h=d/_;this.onChangeFunction(r,h)},this.emitInterval)}}const co={SELECTED_INPUT_DEVICE:"OpensipsJSInputDevice",SELECTED_OUTPUT_DEVICE:"OpensipsJSOutputDevice"},Xv=0;class Qv{constructor(s){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=s,this.context.on(this.context.newRTCSessionEventName,this.newRTCSessionCallback.bind(this)),this.VUMeter=new zv({onChangeFunction:this.emitVolumeChange.bind(this)}),this.initializeMediaDevices()}get sipOptions(){return{...this.context.options.sipOptions,mediaConstraints:this.getUserMediaConstraints}}get currentActiveRoomId(){return this.currentActiveRoomIdValue}set currentActiveRoomId(s){this.currentActiveRoomIdValue=s,this.context.emit("currentActiveRoomChanged",s)}get autoAnswer(){return this.isAutoAnswer}get callAddingInProgress(){return this.isCallAddingInProgress}set callAddingInProgress(s){this.isCallAddingInProgress=s,this.context.emit("callAddingInProgressChanged",s)}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(s=>s.kind==="audioinput")}get getOutputDeviceList(){return this.availableMediaDevices.filter(s=>s.kind==="audiooutput")}get getUserMediaConstraints(){return C_()?{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(s){this.availableMediaDevices=s,this.context.emit("changeAvailableDeviceList",s)}async updateDeviceList(){await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);const s=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(s)}async initializeMediaDevices(){const s=localStorage.getItem(co.SELECTED_INPUT_DEVICE)||"default",r=localStorage.getItem(co.SELECTED_OUTPUT_DEVICE)||"default";try{const o=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints),a=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(a),await this.setMicrophone(s),await this.setSpeaker(r),navigator.mediaDevices.addEventListener("devicechange",async()=>{const t=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(t)}),o.getTracks().forEach(t=>t.stop())}catch(o){console.error(o)}}setCallTime(s){const r={...s};delete r.callId,this.callTime={...this.callTime,[s.callId]:r},this.context.emit("changeCallTime",this.callTime)}removeCallTime(s){const r={...this.callTime};delete r[s],this.callTime={...r},this.context.emit("changeCallTime",this.callTime)}setTimeInterval(s,r){this.timeIntervals={...this.timeIntervals,[s]:r}}removeTimeInterval(s){const r={...this.timeIntervals};r[s]&&(clearInterval(r[s]),delete r[s],this.timeIntervals={...r})}stopCallTimer(s){this.removeTimeInterval(s),this.removeCallTime(s)}emitVolumeChange(s,r){this.context.emit("changeCallVolume",{callId:s,volume:r})}setMetricsConfig(s){this.metricConfig={...this.metricConfig,...s}}sendDTMF(s,r){if(!/^[A-D0-9]+$/g.test(r))throw new Error("Not allowed character in DTMF input");this.extendedCalls[s].sendDTMF(r)}setIsMuted(s){this.muted=s,this.context.emit("changeIsMuted",s)}processMute(s){const r=this.currentActiveRoomId;this.setIsMuted(s),this.initialStreamValue.getTracks().forEach(o=>o.enabled=!s),this.roomReconfigure(r)}mute(){this.processMute(!0)}unmute(){this.processMute(!1)}async processHold({callId:s,toHold:r,automatic:o}){const a=this.extendedCalls[s];a._automaticHold=o??!1,await new Promise(d=>{const _=()=>{d()};r?a.hold({},_):a.unhold({},_)}),this.updateCall(a);const n=Object.values(this.extendedCalls).filter(d=>d.roomId===this.currentActiveRoomId&&(r?s!==d._id:!0));n.length>1&&await this.doConference(n)}holdCall(s,r=!1){return this.processHold({callId:s,automatic:r,toHold:!0})}unholdCall(s){return this.processHold({callId:s,toHold:!1})}cancelAllOutgoingUnanswered(){Object.values(this.getActiveCalls).filter(s=>s.direction==="outgoing"&&s.status===Xv).forEach(s=>this.terminateCall(s._id))}answerCall(s){const r=this.extendedCalls[s];this.cancelAllOutgoingUnanswered(),r.answer(this.sipOptions),this.updateCall(r),this.setActiveRoom(r.roomId),r.connection.addEventListener("track",o=>{this.triggerAddStream(o,r)})}async moveCall(s,r){this.updateCallStatus({callId:s,isMoving:!0}),await this.processRoomChange({callId:s,roomId:r}),this.updateCallStatus({callId:s,isMoving:!1})}updateCall(s){this.activeCalls[s._id]=wf(s),this.context.emit("changeActiveCalls",this.activeCalls)}updateRoom(s){const o={...this.activeRooms[s.roomId],...s};this.activeRooms={...this.activeRooms,[s.roomId]:{...o}},this.context.emit("updateRoom",{room:o,roomList:this.activeRooms})}hasAutoAnswerHeaders(s){const r=/answer-after=0/,a=s.request.getHeader("Call-Info");return a&&r.test(a)}addCall(s,r=!0){this.activeCalls={...this.activeCalls,[s._id]:wf(s)},this.extendedCalls[s._id]=s,r&&this.context.emit("changeActiveCalls",this.activeCalls)}addCallStatus(s){this.callStatus={...this.callStatus,[s]:{isMoving:!1,isTransferring:!1,isMerging:!1}},this.context.emit("changeCallStatus",this.callStatus)}updateCallStatus(s){const o={...{...this.callStatus[s.callId]}};s.isMoving!==void 0&&(o.isMoving=s.isMoving),s.isTransferring!==void 0&&(o.isTransferring=s.isTransferring),s.isMerging!==void 0&&(o.isMerging=s.isMerging),this.callStatus={...this.callStatus,[s.callId]:{...o}},this.context.emit("changeCallStatus",this.callStatus)}removeCallStatus(s){const r={...this.callStatus};delete r[s],this.callStatus={...r},this.context.emit("changeCallStatus",this.callStatus)}addRoom(s){this.activeRooms={...this.activeRooms,[s.roomId]:s},this.context.emit("addRoom",{room:s,roomList:this.activeRooms})}getActiveStream(){const s=Df(this.initialStreamValue,this.microphoneInputLevel*2);return s.getTracks().forEach(r=>r.enabled=!this.isMuted),this.setActiveStream(s),s}async setMicrophone(s){if(!this.getInputDeviceList.find(({deviceId:o})=>o===s)||(this.setSelectedInputDevice(s),Object.keys(this.getActiveCalls).length===0))return;await this.setupStream();const r=Object.values(this.extendedCalls).filter(o=>o.roomId===this.currentActiveRoomId);r.length===1?Object.values(r).forEach(async o=>{const a=this.getActiveStream();o.connection.getSenders()[0].replaceTrack(a.getTracks()[0]),this.updateCall(o)}):await this.doConference(r)}setActiveStream(s){this.activeStream&&this.stopVUMeter("origin"),this.setupVUMeter(s,"origin"),this.activeStreamValue=s,this.context.emit("changeActiveStream",s)}async setSpeaker(s){if(!this.getOutputDeviceList.find(({deviceId:a})=>a===s))return;this.setSelectedOutputDevice(s);const r=Object.values(this.extendedCalls);if(r.length===0)return;const o=r.filter(a=>a.roomId===this.currentActiveRoomId);o.length===1?r.forEach(a=>{var t;(t=a.audioTag)==null||t.setSinkId(s),this.updateCall(a)}):await this.doConference(o)}removeRoom(s){const r={...this.activeRooms},o={...r[s]};delete r[s],this.activeRooms={...r},this.context.emit("removeRoom",{room:o,roomList:this.activeRooms})}deleteRoomIfEmpty(s){s!==void 0&&Object.values(this.extendedCalls).filter(r=>r.roomId===s).length===0&&(this.removeRoom(s),this.currentActiveRoomId===s&&(this.currentActiveRoomId=void 0))}checkInitialized(){if(!this.context.initialized)throw new Error("[OpenSIPSJS] You must call `start` method first!")}muteReconfigure(s){this.muted?s.mute({audio:!0}):s.unmute({audio:!0})}async roomReconfigure(s){var o;if(s===void 0)return;const r=Object.values(this.extendedCalls).filter(a=>a.roomId===s);if(this.currentActiveRoomId===s?r.forEach(a=>{a.audioTag&&(this.muteReconfigure(a),a.audioTag.muted=!1,this.updateCall(a))}):r.forEach(a=>{a.audioTag&&(a.audioTag.muted=!0,this.updateCall(a))}),r.length===0)this.deleteRoomIfEmpty(s);else if(r.length===1&&this.currentActiveRoomId!==s)r[0].isOnHold().local||await this.holdCall(r[0].id,!0);else if(r.length===1&&this.currentActiveRoomId===s){if(r[0].isOnHold().local&&r[0]._automaticHold&&await this.unholdCall(r[0].id),r[0].connection&&((o=r[0].connection)!=null&&o.getSenders()[0])){const a=this.getActiveStream();await r[0].connection.getSenders()[0].replaceTrack(a.getTracks()[0]),this.muteReconfigure(r[0])}}else r.length>1&&await this.doConference(r)}async doConference(s){const r=[];s.forEach(o=>{o!=null&&o.connection.getReceivers().forEach(a=>{r.push(a.track)})}),await nv.forEach(s,async o=>{var n;if(o==null)return;const a=new MediaStream,t=yn.createMediaStreamDestination();if(o.connection.getReceivers().forEach(d=>{r.forEach(_=>{a.addTrack(d.track),d.track.id!==_.id&&yn.createMediaStreamSource(new MediaStream([_])).connect(t)})}),s[0].roomId===this.currentActiveRoomId){const d=this.getActiveStream();yn.createMediaStreamSource(d).connect(t)}(n=o.connection)!=null&&n.getSenders()[0]&&(await o.connection.getSenders()[0].replaceTrack(t.stream.getTracks()[0]),this.muteReconfigure(o))})}processCallerMute(s,r){const o=this.extendedCalls[s];o&&o.connection.getReceivers().length&&(o.localMuted=r,o.connection.getReceivers().forEach(a=>{a.track.enabled=!r}),this.updateCall(o))}muteCaller(s){this.processCallerMute(s,!0)}unmuteCaller(s){this.processCallerMute(s,!1)}terminateCall(s){const r=this.extendedCalls[s];r._status!==8&&r.terminate()}transferCall(s,r){if(r.toString().length===0)return new Error("Target must be passed");const o=this.extendedCalls[s];if(!o._is_confirmed&&!o._is_canceled){const a=`sip:${r}@${this.context.sipDomain}`;o.terminate({status_code:302,reason_phrase:"Moved Temporarily",extraHeaders:[`Contact: ${a}`]});return}this.updateCallStatus({callId:s,isTransferring:!0}),o.refer(`sip:${r}@${this.context.sipDomain}`),this.updateCall(o)}mergeCall(s){const r=Object.values(this.extendedCalls).filter(t=>t.roomId===s);if(r.length!==2)return;const o=r[0],a=r[1];!o||!a||(this.updateCallStatus({callId:o._id,isMerging:!0}),this.updateCallStatus({callId:a._id,isMerging:!0}),o.refer(a.remote_identity.uri.toString(),{replaces:a}),this.updateCall(o))}mergeCallByIds(s,r){const o=Object.values(this.extendedCalls).find(t=>t._id===s),a=Object.values(this.extendedCalls).find(t=>t._id===r);if(!o||!a)throw new Error("Call ID is not provided");this.updateCallStatus({callId:s,isMerging:!0}),this.updateCallStatus({callId:r,isMerging:!0}),o.refer(a.remote_identity.uri.toString(),{replaces:a}),this.updateCall(o)}setDND(s){this.isDNDEnabled=s,this.context.emit("changeIsDND",s)}startCallTimer(s){this.removeTimeInterval(s);const r={callId:s,hours:0,minutes:0,seconds:0,formatted:""};this.setCallTime(r);const o=setInterval(()=>{const a={...this.callTime[s]},t=ev(a);this.setCallTime({callId:s,...t})},1e3);this.setTimeInterval(s,o)}async setActiveRoom(s){const r=this.currentActiveRoomId;s!==r&&(this.currentActiveRoomId=s,await this.roomReconfigure(r),await this.roomReconfigure(s))}getNewRoomId(){const s=Object.keys(this.activeRooms);return s.length===0?1:parseInt(s.sort()[s.length-1])+1}async setupCall(s){var h,g;const r=s.session;if(this.getActiveCalls[r.id]!==void 0)return;const a=this.getNewRoomId(),t={started:new Date,incomingInProgress:!1,roomId:a};r.direction==="incoming"?(this.context.logger.log("New incoming call from",(g=(h=r._remote_identity)==null?void 0:h._uri)==null?void 0:g._user),t.incomingInProgress=!0,this.context.subscribe(zt.CALL_CONFIRMED,T=>{r.id===T.id&&(this.updateRoom({incomingInProgress:!1,roomId:a}),this.startCallTimer(r.id))}),this.context.subscribe(zt.CALL_FAILED,T=>{r.id===T.id&&(this.updateRoom({incomingInProgress:!1,roomId:a}),this.deleteRoomIfEmpty(a))})):r.direction==="outgoing"&&(r.once("confirmed",()=>{this.startCallTimer(r.id)}),this.startCallTimer(r.id));const n=r,d=this.hasAutoAnswerHeaders(s),_=n.direction==="incoming"&&!this.hasActiveCalls&&(d||this.autoAnswer);n.roomId=a,n.localMuted=!1,n.autoAnswer=_,_?this.addCall(n,!1):this.addCall(n),this.addCallStatus(r.id),this.addRoom(t),_&&this.answerCall(n._id)}removeCall(s){const r={...this.activeCalls};delete r[s],this.activeCalls={...r};const o={...this.extendedCalls};delete o[s],this.extendedCalls={...o},this.context.emit("changeActiveCalls",this.activeCalls)}activeCallListRemove(s){var a;const r=this.extendedCalls[s._id];this.stopVUMeter("origin"),(a=r.connection)==null||a.getSenders().forEach(t=>{t.track.stop()});const o=r.roomId;this.removeCall(s._id),this.roomReconfigure(o)}async newRTCSessionCallback(s){const r=s.session;if(this.isDND){r.terminate({status_code:486,reason_phrase:"Do Not Disturb"});return}if(this.context.triggerListener({listenerType:zt.NEW_CALL,session:r,event:s}),r.on("ended",o=>{var t,n,d;this.stopVUMeter(r.id),this.context.logger.log("Session ended for",(n=(t=r._remote_identity)==null?void 0:t._uri)==null?void 0:n._user),this.context.triggerListener({listenerType:zt.CALL_ENDED,session:r,event:o});const a=this.getActiveCalls[r.id];a&&this.activeCallListRemove(a),this.stopCallTimer(r.id),this.removeCallStatus(r.id),this.removeCallMetrics(r.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(d=this.initialStreamValue)==null||d.getTracks().forEach(_=>_.stop()),this.initialStreamValue=null)}),r.on("progress",o=>{var a,t;this.context.logger.log("Session in progress for",(t=(a=r._remote_identity)==null?void 0:a._uri)==null?void 0:t._user),this.context.triggerListener({listenerType:zt.CALL_PROGRESS,session:r,event:o})}),r.on("failed",o=>{var t,n,d;this.stopVUMeter(r.id),this.context.logger.log("Session failed for",(n=(t=r._remote_identity)==null?void 0:t._uri)==null?void 0:n._user),this.context.triggerListener({listenerType:zt.CALL_FAILED,session:r,event:o}),r.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0);const a=this.getActiveCalls[r.id];a&&this.activeCallListRemove(a),this.stopCallTimer(r.id),this.removeCallStatus(r.id),this.removeCallMetrics(r.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(d=this.initialStreamValue)==null||d.getTracks().forEach(_=>_.stop()),this.initialStreamValue=null)}),r.on("confirmed",o=>{var a,t;this.context.logger.log("Session confirmed for",(t=(a=r._remote_identity)==null?void 0:a._uri)==null?void 0:t._user),this.context.triggerListener({listenerType:zt.CALL_CONFIRMED,session:r,event:o}),this.updateCall(r),r.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0)}),await this.setupCall(s),r.direction==="outgoing"){const o=this.getActiveCalls[r.id].roomId;this.setActiveRoom(o)}}setMuteWhenJoin(s){this.muteWhenJoinEnabled=s,this.context.emit("changeMuteWhenJoin",s)}setMicrophoneSensitivity(s){if(s<0||s>1)throw new Error("Value should be in range from 0 to 1!");this.microphoneInputLevelValue=s,this.roomReconfigure(this.currentActiveRoomId)}setSpeakerVolume(s){this.speakerVolumeValue=s,Object.values(this.extendedCalls).forEach(r=>{r.audioTag&&(r.audioTag.volume=s,this.updateCall(r))})}setAutoAnswer(s){this.isAutoAnswer=s}setSelectedInputDevice(s){localStorage.setItem(co.SELECTED_INPUT_DEVICE,s),this.selectedMediaDevices.input=s,this.context.emit("changeActiveInputMediaDevice",s)}setSelectedOutputDevice(s){localStorage.setItem(co.SELECTED_OUTPUT_DEVICE,s),this.selectedMediaDevices.output=s,this.context.emit("changeActiveOutputMediaDevice",s)}setCallMetrics(s){const r={...s};delete r.callId,this.callMetrics={...this.callMetrics,[s.callId]:r},this.context.emit("changeCallMetrics",this.callMetrics)}removeCallMetrics(s){const r={...this.callMetrics};delete r[s],this.callMetrics={...r},this.context.emit("changeCallMetrics",this.callMetrics)}getCallQuality(s){const r=new Kv(this.metricConfig),o=r.createProbe(s.connection,{cid:s._id}),a=[];let t;o.onreport=n=>{Object.entries(n.audio).forEach(([h,g])=>{g.direction==="inbound"&&!a.includes(h)&&(a.push(h),t=h)});const d=n.audio[t];if(!d)return;const _=Yv(d,Jv);_.callId=s._id,this.setCallMetrics(_)},this.context.subscribe(zt.CALL_ENDED,n=>{n._id===s._id&&r.stopAllProbes()}),r.startAllProbes()}setupVUMeter(s,r){this.VUMeter.start(s,r)}stopVUMeter(s){this.VUMeter.stop(s)}async setupStream(){const s=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);this.initialStreamValue&&(this.initialStreamValue.getTracks().forEach(r=>r.stop()),this.initialStreamValue=null),this.initialStreamValue=s}async triggerAddStream(s,r){this.setIsMuted(this.muteWhenJoin||this.isMuted),this.initialStreamValue||await this.setupStream();const o=Df(this.initialStreamValue,this.microphoneInputLevel*2),a=this.isMuted||this.muteWhenJoin;o.getTracks().forEach(n=>n.enabled=!a),this.setActiveStream(o),await r.connection.getSenders()[0].replaceTrack(o.getTracks()[0]);const t=new MediaStream([s.track]);$T(t,r,this.selectedOutputDevice,this.speakerVolume),this.setupVUMeter(t,r._id),this.getCallQuality(r),this.updateCall(r)}initCall(s,r){if(s.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${s}@${this.context.sipDomain}...`);const o=this.context.call(`sip:${s}@${this.context.sipDomain}`,this.sipOptions);this.callAddingInProgress=o.id,r&&this.currentActiveRoomId!==void 0&&this.processRoomChange({callId:o.id,roomId:this.currentActiveRoomId}),o.connection.addEventListener("track",a=>{this.triggerAddStream(a,o)})}async processRoomChange({callId:s,roomId:r}){const o=this.extendedCalls[s].roomId;this.extendedCalls[s].roomId=r;const a=this.extendedCalls[s];return this.updateCall(a),await this.setActiveRoom(r),Promise.all([this.roomReconfigure(o),this.roomReconfigure(r)]).then(()=>{this.deleteRoomIfEmpty(o),this.deleteRoomIfEmpty(r)})}}class Zv{constructor(s){this.context=s}get sipOptions(){return{...this.context.options.sipOptions}}initCall(s,r){if(s.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${s}@${this.context.sipDomain}...`),this.context.joinVideoCall(`sip:${s}@${this.context.sipDomain}`,r,this.sipOptions)}stop(s={}){this.context.terminateJanusSessions(s)}}class eE{constructor(s){this.activeMessages={},this.extendedMessages={},this.msrpHistory={},this.context=s,this.context.on(this.context.newMSRPSessionEventName,this.newMSRPSessionCallback.bind(this.context))}get isMSRPInitializing(){return this.isMSRPInitializingValue}get getActiveMessages(){return this.activeMessages}msrpAnswer(s){const r=this.extendedMessages[s];this.updateMSRPSession(r)}updateMSRPSession(s){this.activeMessages[s._id]=Of(s),this.context.emit("changeActiveMessages",this.activeMessages)}addMMSRPSession(s){this.activeMessages={...this.activeMessages,[s._id]:Of(s)},this.extendedMessages[s._id]=s,this.context.emit("changeActiveMessages",this.activeMessages)}addMSRPMessage(s,r){const o=this.msrpHistory[r.id]||[];o.push(s),this.msrpHistory={...this.msrpHistory,[r.id]:[...o]},this.context.emit("newMSRPMessage",{message:s,session:r})}messageTerminate(s){const r=this.extendedMessages[s];r._status!==8&&r.terminate()}addMessageSession(s){if(!s._id||this.getActiveMessages[s._id]!==void 0)return;const o=s;this.addMMSRPSession(o)}triggerMSRPListener({listenerType:s,session:r,event:o}){const a=this.context.listenersList[s];!a||!a.length||a.forEach(t=>{t(r,o)})}removeMMSRPSession(s){const r={...this.activeMessages};delete r[s],this.activeMessages={...r};const o={...this.extendedMessages};delete o[s],this.extendedMessages={...o},this.context.emit("changeActiveMessages",this.activeMessages)}activeMessageListRemove(s){this.removeMMSRPSession(s._id)}newMSRPSessionCallback(s){const r=s.session;r.on("ended",o=>{this.triggerMSRPListener({listenerType:zt.CALL_ENDED,session:r,event:o});const a=this.getActiveMessages[r.id];this.activeMessageListRemove(a)}),r.on("failed",o=>{this.triggerMSRPListener({listenerType:zt.CALL_FAILED,session:r,event:o});const a=this.getActiveMessages[r.id];this.activeMessageListRemove(a)}),r.on("confirmed",o=>{this.triggerMSRPListener({listenerType:zt.CALL_CONFIRMED,session:r,event:o}),this.updateMSRPSession(r)}),r.on("newMessage",o=>{this.addMSRPMessage(o,r)}),this.addMessageSession(r)}setIsMSRPInitializing(s){this.isMSRPInitializingValue=s,this.context.emit("isMSRPInitializingChanged",s)}initMSRP(s,r,o){if(s.length===0)return console.error("Target must be a valid string");const a=this.context.startMSRP(s,o);a.on("active",()=>{this.addMessageSession(a),a.sendMSRP(r),this.setIsMSRPInitializing(!1)}),this.setIsMSRPInitializing(!0)}sendMSRP(s,r){const o=this.extendedMessages[s];if(!o)throw new Error(`MSRP session with id ${s} doesn't exist!`);o.sendMSRP(r)}}const ru={AUDIO:"audio",VIDEO:"video",MSRP:"msrp"};class tE extends NT{constructor(s,r){if(!s.modules.length)throw new Error("options.modules should include at least 1 module");const o={...s.configuration,sockets:s.socketInterfaces.map(a=>new ZT.WebSocketInterface(a))};super(o),this.initialized=!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.audio=null,this.msrp=null,this.video=null,this.listenersList={},this.modules=[],s.pnExtraHeaders&&Object.keys(s.pnExtraHeaders).length&&this.registrator().setExtraContactUriParams(s.pnExtraHeaders),this.options=s,this.modules=s.modules,r&&HT(r)&&(this.logger=r)}on(s,r){return super.on(s,r)}off(s,r){return super.off(s,r)}emit(s,r){return super.emit(s,r)}get sipDomain(){return this.options.sipDomain}begin(){if(this.isConnected()){console.error("Connection is already established");return}return this.modules.includes(ru.AUDIO)&&(this.audio=new Qv(this)),this.modules.includes(ru.MSRP)&&(this.msrp=new eE(this)),this.modules.includes(ru.VIDEO)&&(this.video=new Zv(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.isReconnecting=!1}),this.on(this.disconnectedEventName,()=>{this.isReconnecting||(this.logger.log("Disconnected from",this.options.socketInterfaces[0]),this.logger.log("Reconnecting to",this.options.socketInterfaces[0]),this.isReconnecting=!0,this.stop(),this.setInitialized(!1),setTimeout(this.start.bind(this),5e3))}),this.logger.log("Connecting to",this.options.socketInterfaces[0]),this.start(),this}subscribe(s,r){const a=!this.listenersList[s]||!this.listenersList[s].length?[r]:[...this.listenersList[s],r];this.listenersList={...this.listenersList,[s]:a}}removeIListener(s){const r={...this.listenersList};delete r[s],this.listenersList={...r}}triggerListener({listenerType:s,session:r,event:o}){const a=this.listenersList[s];!a||!a.length||a.forEach(t=>{t(r,o)})}setInitialized(s){this.initialized=s,this.emit("ready",s)}}module.exports=tE;
156
+ `),this._newMSRPSession("local",this._request),this._id=this._request.call_id+this._from_tag,console.log("dialog be",this._dialog),new Ga(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout(),console.log("to")},onTransportError:_=>{this.onTransportError(),console.log(_)},onAuthenticated:_=>{this._request=_},onReceiveResponse:_=>{this._receiveInviteResponse(_),console.log("dialog af",this._dialog),_.status_code===200&&(_.parseSDP(!0),this._status=be.STATUS_CONFIRMED,this.target_addr=_.sdp.media[0].invalid[1].value.replaceAll("path:","").split(" ").reverse(),this.status="active",this.emit("active"),this.emit("confirmed"))}}).send(),this._status=be.STATUS_INVITE_SENT}terminate(s={}){console.log("terminate",this);const i=s.cause||F.causes.BYE,l=$e.cloneArray(s.extraHeaders),a=s.body;let _,e=s.status_code,p=s.reason_phrase;if(this._status===be.STATUS_TERMINATED)throw new zs.InvalidStateError(this._status);switch(this.status="terminated",this._status){case be.STATUS_NULL:case be.STATUS_INVITE_SENT:case be.STATUS_1XX_RECEIVED:if(e&&(e<200||e>=700))throw new TypeError(`Invalid status_code: ${e}`);e&&(p=p||F.REASON_PHRASE[e]||"",_=`SIP ;cause=${e} ;text="${p}"`),this._status===be.STATUS_NULL||this._status===be.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=_):this._status===be.STATUS_1XX_RECEIVED&&this._request.cancel(_),this._status=be.STATUS_CANCELED,console.log("failed 1"),this._failed("local",null,F.causes.CANCELED);break;case be.STATUS_WAITING_FOR_ANSWER:case be.STATUS_ANSWERED:if(e=e||480,console.log("REPLY 480"),e<300||e>=700)throw new TypeError(`Invalid status_code: ${e}`);this._request.reply(e,p,l,a),console.log("failed 2"),this._failed("local",null,F.causes.REJECTED);break;case be.STATUS_WAITING_FOR_ACK:case be.STATUS_CONFIRMED:if(p=s.reason_phrase||F.REASON_PHRASE[e]||"",e&&(e<200||e>=700))throw new TypeError(`Invalid status_code: ${e}`);if(e&&l.push(`Reason: SIP ;cause=${e}; text="${p}"`),this._status===be.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Vt.C.STATUS_TERMINATED){const g=this._dialog;this.receiveRequest=({method:n})=>{n===F.ACK&&(this.sendRequest(F.BYE,{extraHeaders:l,body:a}),g.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Vt.C.STATUS_TERMINATED&&(this.sendRequest(F.BYE,{extraHeaders:l,body:a}),g.terminate())}),this._ended("local",null,i),this._dialog=g,this._ua.newDialog(g)}else console.log("here it is"),this.sendRequest(F.BYE,{extraHeaders:l,body:a}),this._ended("local",null,i)}}sendRequest(s,i){return this._dialog.sendRequest(s,i)}authenticate(s){this.status="auth";let i=new sr("");i.method="AUTH",i.addHeader("To-Path",`msrp://${this._ua._configuration.realm}:2856;ws`),i.addHeader("From-Path",`msrp://${this.credentials.username}.${this.credentials.realm}:2856/${this.auth_id};ws`),s&&i.addHeader("Authorization",s.toString());let l=i.toString();console.log(l);let a=[];for(var _=0;_<l.length;_++)a.push(l.charCodeAt(_).toString(16));console.log(a),this._connection.send(i.toString())}onmessage(s){console.log("onmessage",s);const i=new sr(s.data);if(this.status==="auth"&&i.code===401){const l=this.parseAuth(i.getHeader("WWW-Authenticate")),a=new Gm(this.credentials);a.authenticate({method:"AUTH",ruri:`msrp://${this._ua._configuration.realm}:2856;ws`,body:null},l,$e.createRandomToken(12)),this.authenticate(a)}this.status==="auth"&&i.code===200&&this._direction==="outgoing"?(this.my_addr.push(i.getHeader("To-Path")),this.my_addr.push(i.getHeader("Use-Path")),this.status="active",this.inviteParty(i)):this.status==="auth"&&i.code===200&&this._direction==="incoming"?(this.my_addr.push(i.getHeader("To-Path")),this.my_addr.push(i.getHeader("Use-Path")),this.status="active",this.acceptParty(i),this.emit("confirmed")):i.method==="SEND"&&(this._sendOk(i),this._sendReport(i),i.direction="incoming",this.emit("newMessage",i),this._msgHistory.push(i),this.emit("msgHistoryUpdate",this._msgHistory),console.log("======================================================================")),i.code===480&&this._close()}onclose(){console.log("close")}onopen(){const s=new RTCPeerConnection({iceServers:[]});s.createDataChannel(""),s.createOffer().then(s.setLocalDescription.bind(s)),s.onicecandidate=i=>{if(!i||!i.candidate||!i.candidate.candidate)return;const l=/([0-9]{1,3}(\.[0-9]{1,3}){3})/,a=i.candidate.candidate.match(l);this.my_ip=a&&a[1],s.onicecandidate=()=>{},this.authenticate(null)}}onerror(s){console.log(s)}_receiveInviteResponse(s){if(console.log("resp0000000000000",s),this._dialog&&s.status_code>=200&&s.status_code<=299)if(console.log("200000000000000"),this._dialog.id.call_id===s.call_id&&this._dialog.id.local_tag===s.from_tag&&this._dialog.id.remote_tag===s.to_tag){this.sendRequest(F.ACK);return}else{const i=new aa(this,s,"UAC");if(i.error!==void 0){console.log(i.error);return}this.sendRequest(F.ACK),this.sendRequest(F.BYE);return}if(this._is_canceled){s.status_code>=100&&s.status_code<200?this._request.cancel(this._cancel_reason):s.status_code>=200&&s.status_code<299&&this._acceptAndTerminate(s);return}if(!(this._status!==be.STATUS_INVITE_SENT&&this._status!==be.STATUS_1XX_RECEIVED))switch(console.log("start Switch"),!0){case/^100$/.test(s.status_code):this._status=be.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(s.status_code):{if(!s.to_tag){console.log("1xx response received without to tag");break}if(s.hasHeader("contact")&&!this._createDialog(s,"UAC",!0))break;if(this._status=be.STATUS_1XX_RECEIVED,!s.body){this._progress("remote",s);break}const i={originator:"remote",type:"answer",sdp:s.body};console.log('emit "sdp"'),this.emit("sdp",i);const l=new RTCSessionDescription({type:"answer",sdp:i.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(l)).then(()=>this._progress("remote",s)).catch(a=>{console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)});break}case/^2[0-9]{2}$/.test(s.status_code):{if(console.log("maybe here???"),this._status=be.STATUS_CONFIRMED,!s.body){this._acceptAndTerminate(s,400,F.causes.MISSING_SDP),console.log("failed 3"),this._failed("remote",s,F.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(s,"UAC"))break;const i={originator:"remote",type:"answer",sdp:s.body};console.log('emit "sdp"'),this.emit("sdp",i),new RTCSessionDescription({type:"answer",sdp:i.sdp}),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._connection.signalingState==="stable")return this._connection.createOffer(this._rtcOfferConstraints).then(l=>this._connection.setLocalDescription(l)).catch(l=>{this._acceptAndTerminate(s,500,l.toString()),console.log("failed 4"),this._failed("local",s,F.causes.WEBRTC_ERROR)})}).then(()=>{this._handleSessionTimersInIncomingResponse(s),this._accepted("remote",s),this.sendRequest(F.ACK),this._confirmed("local",null)});break}default:{const i=$e.sipErrorCause(s.status_code);console.log("failed 5"),this._failed("remote",s,i)}}}sendMSRP(s){const i=new sr("");i.method="SEND",i.addHeader("To-Path",`${this.my_addr[1]} ${this.target_addr[1]} ${this.target_addr[0]}`),i.addHeader("From-Path",`${this.my_addr[0]}`),i.addHeader("Message-ID",$e.createRandomToken(10)),i.addHeader("Byte-Range","1-25/25"),i.addHeader("Content-Type","text/plain"),i.addHeader("Success-Report","yes"),i.addHeader("Failure-Report","yes"),i.body=s;let l=i.toString();console.log(l);let a=[];for(var _=0;_<l.length;_++)a.push(l.charCodeAt(_).toString(16));console.log(a),this._connection.send(i.toString()),i.direction="outgoing",this.emit("newMessage",i),this._msgHistory.push(i),this.emit("msgHistoryUpdate",this._msgHistory)}_sendOk(s){let i=s.ident,l=s.getHeader("Message-ID"),a=new sr("");a.method="200 OK",a.addHeader("To-Path",`${this.my_addr[1]}`),a.addHeader("From-Path",`${this.my_addr[0]}`),a.addHeader("Message-ID",l),a.ident=i;let _=a.toString();console.log(_);let e=[];for(var p=0;p<_.length;p++)e.push(_.charCodeAt(p).toString(16));console.log(e),this._connection.send(a.toString())}_sendReport(s){let i=s.ident,l=s.getHeader("Message-ID"),a=new sr("");a.method="REPORT",a.addHeader("To-Path",`${s.getHeader("From-Path")}`),a.addHeader("From-Path",`${this.my_addr[0]}`),a.addHeader("Message-ID",l),a.addHeader("Byte-Range","1-25/25"),a.addHeader("Status","000 200 OK"),a.ident=i;let _=a.toString();console.log(_);let e=[];for(var p=0;p<_.length;p++)e.push(_.charCodeAt(p).toString(16));console.log(e),this._connection.send(a.toString())}parseAuth(s){const i={},l=s.replace("Digest","").split(",");for(const a of l){const _=a.trim().split("=");i[_[0]]=_[1].match('^"(.+)"$')[1]}return i}init_incoming(s,i){let l;const a=s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0;if(s.body&&a!=="application/sdp"){s.reply(415);return}if(this._status=be.STATUS_INVITE_RECEIVED,this._from_tag=s.from_tag,this._id=s.call_id+this._from_tag,this._request=s,this._contact=this._ua.contact.toString(),s.hasHeader("expires")&&(l=s.getHeader("expires")*1e3),s.to_tag=$e.newTag(),!this._createDialog(s,"UAS",!0)){s.reply(500,"Missing Contact header field");return}s.body?this._late_sdp=!1:this._late_sdp=!0,this._status=be.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{s.reply(408),console.log("failed 6"),this._failed("local",null,F.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),l&&(this._timers.expiresTimer=setTimeout(()=>{this._status===be.STATUS_WAITING_FOR_ANSWER&&(s.reply(487),console.log("failed 7"),this._failed("system",null,F.causes.EXPIRES))},l)),this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from,i&&i(this),s.parseSDP(!0),this.target_addr=s.sdp.media[0].invalid[1].value.replaceAll("path:","").split(" ").reverse(),this._newMSRPSession("remote",s),this._status!==be.STATUS_TERMINATED&&(s.reply(180,null,[`Contact: ${this._ua._contact}`]),this._progress("local",null))}_failed(s,i,l){this.emit("_failed",{originator:s,message:i||null,cause:l}),this._close(),this.emit("failed",{originator:s,message:i||null,cause:l})}_close(){if(console.log("CLOSE SESSION"),this._status!==be.STATUS_TERMINATED){if(this._status=be.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(s){console.log("close() | error closing the RTCPeerConnection: %o",s)}for(const s in this._timers)Object.prototype.hasOwnProperty.call(this._timers,s)&&clearTimeout(this._timers[s]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const s in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,s)&&(this._earlyDialogs[s].terminate(),delete this._earlyDialogs[s]);for(const s in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,s)&&delete this._referSubscribers[s];this._ua.destroyMSRPSession(this)}}_createDialog(s,i,l){const a=i==="UAS"?s.to_tag:s.from_tag,_=i==="UAS"?s.from_tag:s.to_tag,e=s.call_id+a+_;let p=this._earlyDialogs[e];if(l)return p?!0:(p=new aa(this,s,i,aa.C.STATUS_EARLY),p.error?(console.log("failed 8"),this._failed("remote",s,F.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[e]=p,!0));{if(this._from_tag=s.from_tag,this._to_tag=s.to_tag,p)return p.update(s,i),this._dialog=p,delete this._earlyDialogs[e],!0;const g=new aa(this,s,i);return g.error?(console.log("failed 9"),this._failed("remote",s,F.causes.INTERNAL_ERROR),!1):(this._dialog=g,!0)}}_newMSRPSession(s,i){this._ua.newMSRPSession(this,{originator:s,session:this,request:i})}_progress(s,i){this.emit("progress",{originator:s,response:i||null})}isEnded(){switch(this._status){case be.STATUS_CANCELED:case be.STATUS_TERMINATED:return!0;default:return!1}}_accepted(s,i){console.log("session accepted"),this._start_time=new Date,console.log('emit "accepted"'),this.emit("accepted",{originator:s,response:i||null})}_confirmed(s,i){console.log("session confirmed"),this._is_confirmed=!0,console.log('emit "confirmed"'),this.emit("confirmed",{originator:s,ack:i||null})}_ended(s,i,l){console.log("session ended"),this._end_time=new Date,this._close(),console.log('emit "ended"'),this.emit("ended",{originator:s,message:i||null,cause:l})}_handleSessionTimersInIncomingResponse(s){if(!this._sessionTimers.enabled)return;let i;s.session_expires&&s.session_expires>=F.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=s.session_expires,i=s.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,i="uac"),this._sessionTimers.refresher=i==="uac",this._runSessionTimer()}receiveRequest(s){if(console.log("receiveRequest()"),s.method===F.CANCEL)(this._status===be.STATUS_WAITING_FOR_ANSWER||this._status===be.STATUS_ANSWERED)&&(this._status=be.STATUS_CANCELED,this._request.reply(487),console.log("failed 10"),this._failed("remote",s,F.causes.CANCELED));else switch(s.method){case F.ACK:if(this._status!==be.STATUS_WAITING_FOR_ACK)return;if(this._status=be.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!s.body){this.terminate({cause:F.causes.MISSING_SDP,status_code:400});break}const i={originator:"remote",type:"answer",sdp:s.body};console.log('emit "sdp"'),this.emit("sdp",i);const l=new RTCSessionDescription({type:"answer",sdp:i.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(l)).then(()=>{this._is_confirmed||this._confirmed("remote",s)}).catch(a=>{this.terminate({cause:F.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',a),this.emit("peerconnection:setremotedescriptionfailed",a)})}else this._is_confirmed||this._confirmed("remote",s);break;case F.BYE:this._status===be.STATUS_CONFIRMED||this._status===be.STATUS_WAITING_FOR_ACK?(s.reply(200),this._ended("remote",s,F.causes.BYE)):this._status===be.STATUS_INVITE_RECEIVED||this._status===be.STATUS_WAITING_FOR_ANSWER?(s.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",s,F.causes.BYE)):s.reply(403,"Wrong Status");break;case F.INVITE:this._status===be.STATUS_CONFIRMED?s.hasHeader("replaces")?this._receiveReplaces(s):this._receiveReinvite(s):s.reply(403,"Wrong Status");break;case F.INFO:this._status===be.STATUS_1XX_RECEIVED||this._status===be.STATUS_WAITING_FOR_ANSWER||this._status===be.STATUS_ANSWERED||this._status===be.STATUS_WAITING_FOR_ACK||this._status===be.STATUS_CONFIRMED?(s.hasHeader("Content-Type")?s.getHeader("Content-Type").toLowerCase():void 0)!==void 0?new yu(this).init_incoming(s):s.reply(415):s.reply(403,"Wrong Status");break;case F.UPDATE:this._status===be.STATUS_CONFIRMED?this._receiveUpdate(s):s.reply(403,"Wrong Status");break;case F.REFER:this._status===be.STATUS_CONFIRMED?this._receiveRefer(s):s.reply(403,"Wrong Status");break;case F.NOTIFY:this._status===be.STATUS_CONFIRMED?this._receiveNotify(s):s.reply(403,"Wrong Status");break;default:s.reply(501)}}onTransportError(){console.log("onTransportError()"),this._status!==be.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:F.causes.CONNECTION_ERROR,cause:F.causes.CONNECTION_ERROR})}onRequestTimeout(){console.log("onRequestTimeout()"),this._status!==be.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:F.causes.REQUEST_TIMEOUT,cause:F.causes.REQUEST_TIMEOUT})}onDialogError(){console.log("onDialogError()"),this._status!==be.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:F.causes.DIALOG_ERROR,cause:F.causes.DIALOG_ERROR})}}var xT=Qt();const Iu=tt(xT),Ta=new Za("Parser"),MT=(c,s)=>{let i,l,a=c.indexOf(`\r
157
+ `);if(a===-1){Ta.warn("parseMessage() | no CRLF found, not a SIP message");return}const _=c.substring(0,a);let e=Iu.parse(_,"Request_Response");if(e===-1){Ta.warn(`parseMessage() | error parsing first line of SIP message: "${_}"`);return}else e.status_code?(i=new Dn.IncomingResponse,i.status_code=e.status_code,i.reason_phrase=e.reason_phrase):(i=new Dn.IncomingRequest(s),i.method=e.method,i.ruri=e.uri);i.data=c;let p=a+2;for(;;){if(a=kT(c,p),a===-2){l=p+2;break}else if(a===-1){Ta.warn("parseMessage() | malformed message");return}if(e=LT(i,c,p,a),e!==!0){Ta.warn("parseMessage() |",e.error);return}p=a+2}if(i.hasHeader("content-length")){const g=i.getHeader("content-length");i.body=c.substr(l,g)}else i.body=c.substring(l);return i};function kT(c,s){let i=s,l=0,a=0;if(c.substring(i,i+2).match(/(^\r\n)/))return-2;for(;l===0;){if(a=c.indexOf(`\r
158
+ `,i),a===-1)return a;!c.substring(a+2,a+4).match(/(^\r\n)/)&&c.charAt(a+2).match(/(^\s+)/)?i=a+2:l=a}return l}function LT(c,s,i,l){let a;const _=s.indexOf(":",i),e=s.substring(i,_).trim(),p=s.substring(_+1,l).trim();switch(e.toLowerCase()){case"via":case"v":c.addHeader("via",p),c.getHeaders("via").length===1?(a=c.parseHeader("Via"),a&&(c.via=a,c.via_branch=a.branch)):a=0;break;case"from":case"f":c.setHeader("from",p),a=c.parseHeader("from"),a&&(c.from=a,c.from_tag=a.getParam("tag"));break;case"to":case"t":c.setHeader("to",p),a=c.parseHeader("to"),a&&(c.to=a,c.to_tag=a.getParam("tag"));break;case"record-route":if(a=Iu.parse(p,"Record_Route"),a===-1)a=void 0;else for(const g of a)c.addHeader("record-route",p.substring(g.possition,g.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=g.parsed;break;case"call-id":case"i":c.setHeader("call-id",p),a=c.parseHeader("call-id"),a&&(c.call_id=p);break;case"contact":case"m":if(a=Iu.parse(p,"Contact"),a===-1)a=void 0;else for(const g of a)c.addHeader("contact",p.substring(g.possition,g.offset)),c.headers.Contact[c.getHeaders("contact").length-1].parsed=g.parsed;break;case"content-length":case"l":c.setHeader("content-length",p),a=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",p),a=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",p),a=c.parseHeader("cseq"),a&&(c.cseq=a.value),c instanceof Dn.IncomingResponse&&(c.method=a.method);break;case"max-forwards":c.setHeader("max-forwards",p),a=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",p),a=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",p),a=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",p),a=c.parseHeader("session-expires"),a&&(c.session_expires=a.expires,c.session_expires_refresher=a.refresher);break;case"refer-to":case"r":c.setHeader("refer-to",p),a=c.parseHeader("refer-to"),a&&(c.refer_to=a);break;case"replaces":c.setHeader("replaces",p),a=c.parseHeader("replaces"),a&&(c.replaces=a);break;case"event":case"o":c.setHeader("event",p),a=c.parseHeader("event"),a&&(c.event=a);break;default:c.addHeader(e,p),a=0}return a===void 0?{error:`error parsing header "${e}"`}:!0}const $T={parseMessage:MT},Vi=new Za("Registrator"),va=10;class HT{constructor(s,i){this._reg_id=1,this._ua=s,this._transport=i,this._registrar=s.configuration.registrar_server,this._expires=s.configuration.register_expires,this._call_id=ys.createRandomToken(22),this._cseq=0,this._to_uri=s.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString();const l=this._contact.indexOf(">");if(l!==-1){const a=this._contact.slice(0,l)+this._contact.slice(l+1,this._contact.length);this._contact=a}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(s){Array.isArray(s)||(s=[]),this._extraHeaders=s.slice()}setExtraContactParams(s){s instanceof Object||(s={}),this._extraContactParams="";for(const i in s)if(Object.prototype.hasOwnProperty.call(s,i)){const l=s[i];this._extraContactParams+=`;${i}`,l&&(this._extraContactParams+=`=${l}`)}}setExtraContactUriParams(s){s instanceof Object||(s={}),this._extraContactParams="";for(const i in s)if(Object.prototype.hasOwnProperty.call(s,i)){const l=s[i];this._extraContactParams+=`;${i}`,l&&(this._extraContactParams+=`=${l}`)}}register(){if(this._registering){Vi.debug("Register request in progress...");return}const s=this._extraHeaders.slice();s.push(`Contact: ${this._contact}${this._extraContactParams}>${this._extra_contact};expires=${this._expires}`),s.push(`Expires: ${this._expires}`);const i=new Dt.OutgoingRequest(F.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},s),l=new Ga(this._ua,i,{onRequestTimeout:()=>{this._registrationFailure(null,F.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,F.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:a=>{if(a.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(a.status_code):break;case/^2[0-9]{2}$/.test(a.status_code):{if(this._registering=!1,!a.hasHeader("Contact")){Vi.debug("no Contact header in response to REGISTER, response ignored");break}const _=a.headers.Contact.reduce((n,v)=>n.concat(v.parsed),[]);let e=_.find(n=>this._sipInstance===n.getParam("+sip.instance")&&this._reg_id===parseInt(n.getParam("reg-id")));if(e||(e=_.find(n=>n.uri.user===this._ua.contact.uri.user)),!e){Vi.debug("no Contact header pointing to us, response ignored");break}let p=e.getParam("expires");!p&&a.hasHeader("expires")&&(p=a.getHeader("expires")),p||(p=this._expires),p=Number(p),p<va&&(p=va);const g=p>64?p*1e3/2+Math.floor((p/2-32)*1e3*Math.random()):p*1e3-5e3;this._registrationTimer=setTimeout(()=>{this._registrationTimer=null,this._ua.listeners("registrationExpiring").length===0?this.register():this._ua.emit("registrationExpiring")},g),e.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=e.getParam("temp-gruu").replace(/"/g,"")),e.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=e.getParam("pub-gruu").replace(/"/g,"")),this._registered||(this._registered=!0,this._ua.registered({response:a}));break}case/^423$/.test(a.status_code):{a.hasHeader("min-expires")?(this._expires=Number(a.getHeader("min-expires")),this._expires<va&&(this._expires=va),this.register()):(Vi.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(a,F.causes.SIP_FAILURE_CODE));break}default:{const _=ys.sipErrorCause(a.status_code);this._registrationFailure(a,_)}}}});this._registering=!0,l.send()}unregister(s={}){if(!this._registered){Vi.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const i=this._extraHeaders.slice();s.all?i.push(`Contact: *${this._extraContactParams}`):i.push(`Contact: ${this._contact}${this._extraContactParams}>${this._extra_contact};expires=0`),i.push("Expires: 0");const l=new Dt.OutgoingRequest(F.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},i);new Ga(this._ua,l,{onRequestTimeout:()=>{this._unregistered(null,F.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,F.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:_=>{switch(!0){case/^1[0-9]{2}$/.test(_.status_code):break;case/^2[0-9]{2}$/.test(_.status_code):this._unregistered(_);break;default:{const e=ys.sipErrorCause(_.status_code);this._unregistered(_,e)}}}}).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(s,i){this._registering=!1,this._ua.registrationFailed({response:s||null,cause:i}),this._registered&&(this._registered=!1,this._ua.unregistered({response:s||null,cause:i}))}_unregistered(s,i){this._registering=!1,this._registered=!1,this._ua.unregistered({response:s||null,cause:i||null})}}const ft=console,Xs={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},FT=IT;class jT extends FT{constructor(s){super(s),this._msrp_sessions=[],this._transactions={nist:{},nict:{},ist:{},ict:{}},this._janus_sessions=[],this._registrator=new HT(this)}call(s,i){return super.call(s,i)}joinVideoCall(s,i,l){ft.debug("call()");const a=new Wa(this);return a.connect(s,i,l),a}_loadConfig(s){try{el.load(this._configuration,s)}catch(a){throw a}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=ys.newUUID()),this._configuration.jssip_id=ys.createRandomToken(5);const i=this._configuration.uri.clone();i.user=null,this._configuration.hostport_params=i.toString().replace(/^sip:/i,"");try{this._transport=new Qg(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=qT.bind(this),this._transport.onconnect=VT.bind(this),this._transport.ondisconnect=BT.bind(this),this._transport.ondata=GT.bind(this)}catch(a){throw ft.warn(a),new zs.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 a=this._configuration.uri.clone();a.user=null,a.clearParams(),a.clearHeaders(),this._configuration.registrar_server=a}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new ar("sip",ys.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(a={}){const _=a.anonymous||null,e=a.outbound||null;let p="<";return _?p+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":p+=this.pub_gruu||this.uri.toString(),e&&(_?!this.temp_gruu:!this.pub_gruu)&&(p+=";ob"),p+=">",p}};const l=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const a in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,a)&&(l.indexOf(a)!==-1?Object.defineProperty(this._configuration,a,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,a,{writable:!1,configurable:!1}));ft.debug("configuration parameters after validation:");for(const a in this._configuration)if(Object.prototype.hasOwnProperty.call(el.settings,a))switch(a){case"uri":case"registrar_server":ft.debug(`- ${a}: ${this._configuration[a]}`);break;case"password":case"ha1":case"authorization_jwt":ft.debug(`- ${a}: NOT SHOWN`);break;default:ft.debug(`- ${a}: ${JSON.stringify(this._configuration[a])}`)}}newMSRPSession(s,i){s.on("msgHistoryUpdate",l=>{console.log(l)}),this._msrp_sessions[s.id]=s,this.emit("newMSRPSession",i)}newJanusSession(s,i){this._janus_sessions[s.id]=s,this.emit("newJanusSession",i)}destroyMSRPSession(s){delete this._msrp_sessions[s.id]}destroyJanusSession(s){delete this._janus_sessions[s.id]}receiveRequest(s){var _,e,p,g;const i=s.method;if(console.log("-----------"),s.ruri.user!==this._configuration.uri.user&&s.ruri.user!==this._contact.uri.user){ft.debug("Request-URI does not point to us"),s.method!==Me.ACK&&s.reply_sl(404);return}if(s.ruri.scheme===Me.SIPS){s.reply_sl(416);return}if(Vt.checkTransaction(this,s))return;if(i===Me.INVITE?new Vt.InviteServerTransaction(this,this._transport,s):i!==Me.ACK&&i!==Me.CANCEL&&new Vt.NonInviteServerTransaction(this,this._transport,s),i===Me.OPTIONS){if(this.listeners("newOptions").length===0){s.reply(200);return}new Qc.Options(this).init_incoming(s)}else if(i===Me.MESSAGE){if(this.listeners("newMessage").length===0){s.reply(405);return}new Qc.Message(this).init_incoming(s)}else if(i===Me.INVITE&&!s.to_tag&&this.listeners("newRTCSession").length===0){s.reply(405);return}let l,a;if(s.to_tag)if(l=this._findDialog(s.call_id,s.from_tag,s.to_tag),l)l.receiveRequest(s);else if(i===Me.NOTIFY)if(a=this._findSession(s),a)a.receiveRequest(s);else{if(s.body)try{const n=JSON.parse(s.body)||{};(e=(_=n.plugindata)==null?void 0:_.data)!=null&&e.publishers&&Object.values(this._janus_sessions)[0].receivePublishers(n),(g=(p=n.plugindata)==null?void 0:p.data)!=null&&g.unpublished&&Object.values(this._janus_sessions)[0].receiveUnpublished(n.plugindata.data.unpublished)}catch(n){console.error(n)}s.reply(200)}else i!==Me.ACK&&s.reply(481);else switch(i){case Me.INVITE:if(window.RTCPeerConnection)if(s.hasHeader("replaces")){const n=s.replaces;l=this._findDialog(n.call_id,n.from_tag,n.to_tag),l?(a=l.owner,a.isEnded()?s.reply(603):a.receiveRequest(s)):s.reply(481)}else s.body.search(/MSRP/ig)>-1?(a=new nu(this),a.init_incoming(s)):s.body.search(/JANUS/ig)>-1||(a=new kg(this),a.init_incoming(s));else ft.warn("INVITE received but WebRTC is not supported"),s.reply(488);break;case Me.BYE:s.reply(481);break;case Me.CANCEL:a=this._findSession(s),a?a.receiveRequest(s):ft.debug("received CANCEL request for a non existent session");break;case Me.ACK:break;case Me.NOTIFY:this.emit("sipEvent",{event:s.event,request:s}),s.reply(200);break;default:s.reply(405);break}}startMSRP(s,i){ft.debug("startMSRP()",i);const l=new nu(this);return l.connect(s),l}startJanus(s,i){ft.debug("startJanus()",i);const l=new nu(this);return l.connect(s),l}terminateMSRPSessions(s){ft.debug("terminateSessions()");for(const i in this._msrp_sessions)this._msrp_sessions[i].isEnded()||this._msrp_sessions[i].terminate(s)}terminateJanusSessions(s){ft.debug("terminateSessions()");for(const i in this._janus_sessions)this._janus_sessions[i].isEnded()||this._janus_sessions[i].terminate(s)}stop(){if(ft.debug("stop()"),this._dynConfiguration={},this._status===Xs.STATUS_USER_CLOSED){ft.debug("UA already closed");return}this._registrator.close();const s=Object.keys(this._sessions).length;for(const l in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,l)){ft.debug(`closing session ${l}`);try{this._sessions[l].terminate()}catch(a){console.error(a)}}for(const l in this._msrp_sessions)if(Object.prototype.hasOwnProperty.call(this._msrp_sessions,l)){ft.debug(`closing session ${l}`);try{this._msrp_sessions[l].terminate()}catch(a){console.error(a)}}for(const l in this._janus_sessions)if(Object.prototype.hasOwnProperty.call(this._janus_sessions,l)){ft.debug(`closing session ${l}`);try{this._janus_sessions[l].terminate()}catch(a){console.error(a)}}for(const l in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,l))try{this._applicants[l].close()}catch(a){console.error(a)}this._status=Xs.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&&s===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}}function qT(c){this.emit("connecting",c)}function VT(c){this._status!==Xs.STATUS_USER_CLOSED&&(this._status=Xs.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function BT(c){const s=["nict","ict","nist","ist"];for(const i of s)for(const l in this._transactions[i])Object.prototype.hasOwnProperty.call(this._transactions[i],l)&&this._transactions[i][l].onTransportError();this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==Xs.STATUS_USER_CLOSED&&(this._status=Xs.STATUS_NOT_READY,this._error=Xs.NETWORK_ERROR)}function GT(c){console.log("onTransportData",c);const s=c.transport;let i=c.message;if(i=$T.parseMessage(i,this),!i){console.log("if 1 return");return}if(this._status===Xs.STATUS_USER_CLOSED&&i instanceof Dn.IncomingRequest){console.log("if 2 return");return}if(!hT(i,this,s)){console.log("if 3 return");return}if(console.log("onTransportData message",i),console.log("onTransportData instanceof",i instanceof Dn.IncomingRequest),i instanceof Dn.IncomingRequest)i.transport=s,console.log("onTransportData receiveRequest"),this.receiveRequest(i);else if(i instanceof Dn.IncomingResponse){let l;switch(i.method){case Me.INVITE:l=this._transactions.ict[i.via_branch],l&&l.receiveResponse(i);break;case Me.ACK:break;default:l=this._transactions.nict[i.via_branch],l&&l.receiveResponse(i);break}}}const WT=["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"],KT=["_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","status","start_time","_remote_identity","target_addr"];function Uf(c){const s={};return WT.forEach(i=>{c[i]!==void 0&&(s[i]=c[i])}),s.localHold=c._localHold,s}function Pf(c){const s={};return KT.forEach(i=>{c[i]!==void 0&&(s[i]=c[i])}),s}function xf(c,s){const i=new AudioContext,l=i.createMediaStreamSource(c),a=i.createMediaStreamDestination(),_=i.createGain();return l.connect(_),_.connect(a),_.gain.value=s,a.stream}function YT(c,s,i,l){const a=document.createElement("audio");a.id=s._id,a.className="audioTag",a.srcObject=c,O_()||(a.setSinkId(i),a.volume=l),a.play(),s.audioTag=a}function JT(c){if(c&&typeof c.log=="function"&&typeof c.warn=="function"&&typeof c.error=="function")return!0}function O_(){return/Mobi|Android|iPhone/i.test(navigator.userAgent)}const zT=ut,XT=Qt(),Pt=new zT("WebSocketInterface");var QT=class{constructor(s){Pt.debug('new() [url:"%s"]',s),this._url=s,this._sip_uri=null,this._via_transport=null,this._ws=null;const i=XT.parse(s,"absoluteURI");if(i===-1)throw Pt.warn(`invalid WebSocket URI: ${s}`),new TypeError(`Invalid argument: ${s}`);if(i.scheme!=="wss"&&i.scheme!=="ws")throw Pt.warn(`invalid WebSocket URI scheme: ${i.scheme}`),new TypeError(`Invalid argument: ${s}`);this._sip_uri=`sip:${i.host}${i.port?`:${i.port}`:""};transport=ws`,this._via_transport=i.scheme.toUpperCase()}get via_transport(){return this._via_transport}set via_transport(s){this._via_transport=s.toUpperCase()}get sip_uri(){return this._sip_uri}get url(){return this._url}connect(){if(Pt.debug("connect()"),this.isConnected()){Pt.debug(`WebSocket ${this._url} is already connected`);return}else if(this.isConnecting()){Pt.debug(`WebSocket ${this._url} is connecting`);return}this._ws&&this.disconnect(),Pt.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(s){this._onError(s)}}disconnect(){Pt.debug("disconnect()"),this._ws&&(this._ws.onopen=()=>{},this._ws.onclose=()=>{},this._ws.onmessage=()=>{},this._ws.onerror=()=>{},this._ws.close(),this._ws=null)}send(s){return Pt.debug("send()"),this.isConnected()?(this._ws.send(s),!0):(Pt.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(){Pt.debug(`WebSocket ${this._url} connected`),this.onconnect()}_onClose({wasClean:s,code:i,reason:l}){Pt.debug(`WebSocket ${this._url} closed`),s===!1&&Pt.debug("WebSocket abrupt disconnection"),this.ondisconnect(!s,i,l)}_onMessage({data:s}){Pt.debug("received WebSocket message"),this.ondata(s)}_onError(s){Pt.warn(`WebSocket ${this._url} error: `,s)}};const bu=Ka,ZT=Me,ev=bs,tv=Ct(),sv=w_,nv=Is(),rv=$u(),iv=Qt(),lv=QT,av=ur("JsSIP");av("version %s",bu.version);var ov={C:ZT,Exceptions:ev,Utils:tv,UA:sv,URI:nv,NameAddrHeader:rv,WebSocketInterface:lv,Grammar:iv,debug:ur,get name(){return bu.title},get version(){return bu.version}};const uv=tt(ov);function ru(c){return c<10?`0${c}`:`${c}`}function cv(c){let s=c.hours||0,i=c.minutes||0,l=c.seconds||0;l++,l===60&&(l=0,i++,i===60&&(i=0,s++));const a=`${ru(s)}:${ru(i)}:${ru(l)}`;return{seconds:l,minutes:i,hours:s,formatted:a}}var Rt={};Rt.forEach=async(c,s,i)=>{const l=[];for(let a=0;a<c.length;a++)if(a in c){const _=Promise.resolve(c[a]).then(e=>s.call(i||globalThis,e,a,c));l.push(_)}await Promise.all(l)};Rt.forEachSeries=async(c,s,i)=>{for(let l=0;l<c.length;l++)l in c&&await s.call(i||globalThis,await c[l],l,c)};Rt.map=async(c,s,i)=>{const l=[];for(let a=0;a<c.length;a++)a in c&&(l[a]=Promise.resolve(c[a]).then(_=>s.call(i||globalThis,_,a,c)));return Promise.all(l)};Rt.mapSeries=async(c,s,i)=>{const l=[];for(let a=0;a<c.length;a++)a in c&&(l[a]=await s.call(i||globalThis,await c[a],a,c));return l};Rt.find=(c,s,i)=>new Promise((l,a)=>{if(c.length===0)return l();let _=1;for(let e=0;e<c.length;e++){const p=g=>{g?l(c[e]):_===c.length&&l(),_++};Promise.resolve(c[e]).then(g=>s.call(i||globalThis,g,e,c)).then(p).catch(a)}});Rt.findSeries=async(c,s,i)=>{for(let l=0;l<c.length;l++)if(await s.call(i||globalThis,await c[l],l,c))return c[l]};Rt.findIndex=(c,s,i)=>new Promise((l,a)=>{if(c.length===0)return l(-1);let _=1;for(let e=0;e<c.length;e++){const p=g=>{g?l(e):_===c.length&&l(-1),_++};Promise.resolve(c[e]).then(g=>s.call(i||globalThis,g,e,c)).then(p).catch(a)}});Rt.findIndexSeries=async(c,s,i)=>{for(let l=0;l<c.length;l++)if(await s.call(i||globalThis,await c[l],l,c))return l};Rt.some=(c,s,i)=>new Promise((l,a)=>{if(c.length===0)return l(!1);let _=1;for(let e=0;e<c.length;e++){if(!(e in c)){_++;continue}const p=g=>{g?l(!0):_===c.length&&l(!1),_++};Promise.resolve(c[e]).then(g=>s.call(i||globalThis,g,e,c)).then(p).catch(a)}});Rt.someSeries=async(c,s,i)=>{for(let l=0;l<c.length;l++)if(l in c&&await s.call(i||globalThis,await c[l],l,c))return!0;return!1};Rt.every=(c,s,i)=>new Promise((l,a)=>{if(c.length===0)return l(!0);let _=1;for(let e=0;e<c.length;e++){if(!(e in c)){_++;continue}const p=g=>{g?_===c.length&&l(!0):l(!1),_++};Promise.resolve(c[e]).then(g=>s.call(i||globalThis,g,e,c)).then(p).catch(a)}});Rt.everySeries=async(c,s,i)=>{for(let l=0;l<c.length;l++)if(l in c&&!await s.call(i||globalThis,await c[l],l,c))return!1;return!0};Rt.filter=(c,s,i)=>new Promise(async(l,a)=>{const _=[];for(let p=0;p<c.length;p++)p in c&&(_[p]=Promise.resolve(c[p]).then(g=>s.call(i||globalThis,g,p,c)).catch(a));const e=[];for(let p=0;p<_.length;p++)await _[p]&&e.push(await c[p]);l(e)});Rt.filterSeries=async(c,s,i)=>{const l=[];for(let a=0;a<c.length;a++)a in c&&await s.call(i||globalThis,await c[a],a,c)&&l.push(await c[a]);return l};Rt.reduce=async(c,s,i)=>{if(c.length===0&&i===void 0)throw TypeError("Reduce of empty array with no initial value");let l,a;for(i!==void 0?(a=i,l=0):(a=c[0],l=1),l;l<c.length;l++)l in c&&(a=await s(await a,await c[l],l,c));return a};var D_={};(function(c){const s=Rt;Object.keys(s).forEach(i=>{const l=i.charAt(0).toUpperCase()+i.slice(1);c[`async${l}`]=async function(...a){return s[i](this,...a)}})})(D_);const fv=Rt,_v=D_;var hv=Object.assign(fv,{instanceMethods:_v});const Un=new AudioContext,Xt={NEW_CALL:"new_call",CALL_CONFIRMED:"confirmed",CALL_FAILED:"failed",CALL_PROGRESS:"progress",CALL_ENDED:"ended"};var dv={exports:{}};(function(c){var s=function(i){var l=Object.prototype,a=l.hasOwnProperty,_=Object.defineProperty||function(N,Y,re){N[Y]=re.value},e,p=typeof Symbol=="function"?Symbol:{},g=p.iterator||"@@iterator",n=p.asyncIterator||"@@asyncIterator",v=p.toStringTag||"@@toStringTag";function S(N,Y,re){return Object.defineProperty(N,Y,{value:re,enumerable:!0,configurable:!0,writable:!0}),N[Y]}try{S({},"")}catch{S=function(Y,re,ae){return Y[re]=ae}}function m(N,Y,re,ae){var Te=Y&&Y.prototype instanceof oe?Y:oe,De=Object.create(Te.prototype),Ce=new U(ae||[]);return _(De,"_invoke",{value:j(N,re,Ce)}),De}i.wrap=m;function C(N,Y,re){try{return{type:"normal",arg:N.call(Y,re)}}catch(ae){return{type:"throw",arg:ae}}}var A="suspendedStart",R="suspendedYield",I="executing",V="completed",W={};function oe(){}function x(){}function $(){}var Re={};S(Re,g,function(){return this});var Ie=Object.getPrototypeOf,H=Ie&&Ie(Ie(se([])));H&&H!==l&&a.call(H,g)&&(Re=H);var D=$.prototype=oe.prototype=Object.create(Re);x.prototype=$,_(D,"constructor",{value:$,configurable:!0}),_($,"constructor",{value:x,configurable:!0}),x.displayName=S($,v,"GeneratorFunction");function L(N){["next","throw","return"].forEach(function(Y){S(N,Y,function(re){return this._invoke(Y,re)})})}i.isGeneratorFunction=function(N){var Y=typeof N=="function"&&N.constructor;return Y?Y===x||(Y.displayName||Y.name)==="GeneratorFunction":!1},i.mark=function(N){return Object.setPrototypeOf?Object.setPrototypeOf(N,$):(N.__proto__=$,S(N,v,"GeneratorFunction")),N.prototype=Object.create(D),N},i.awrap=function(N){return{__await:N}};function q(N,Y){function re(De,Ce,Le,we){var Se=C(N[De],N,Ce);if(Se.type==="throw")we(Se.arg);else{var it=Se.arg,Ue=it.value;return Ue&&typeof Ue=="object"&&a.call(Ue,"__await")?Y.resolve(Ue.__await).then(function(le){re("next",le,Le,we)},function(le){re("throw",le,Le,we)}):Y.resolve(Ue).then(function(le){it.value=le,Le(it)},function(le){return re("throw",le,Le,we)})}}var ae;function Te(De,Ce){function Le(){return new Y(function(we,Se){re(De,Ce,we,Se)})}return ae=ae?ae.then(Le,Le):Le()}_(this,"_invoke",{value:Te})}L(q.prototype),S(q.prototype,n,function(){return this}),i.AsyncIterator=q,i.async=function(N,Y,re,ae,Te){Te===void 0&&(Te=Promise);var De=new q(m(N,Y,re,ae),Te);return i.isGeneratorFunction(Y)?De:De.next().then(function(Ce){return Ce.done?Ce.value:De.next()})};function j(N,Y,re){var ae=A;return function(De,Ce){if(ae===I)throw new Error("Generator is already running");if(ae===V){if(De==="throw")throw Ce;return It()}for(re.method=De,re.arg=Ce;;){var Le=re.delegate;if(Le){var we=B(Le,re);if(we){if(we===W)continue;return we}}if(re.method==="next")re.sent=re._sent=re.arg;else if(re.method==="throw"){if(ae===A)throw ae=V,re.arg;re.dispatchException(re.arg)}else re.method==="return"&&re.abrupt("return",re.arg);ae=I;var Se=C(N,Y,re);if(Se.type==="normal"){if(ae=re.done?V:R,Se.arg===W)continue;return{value:Se.arg,done:re.done}}else Se.type==="throw"&&(ae=V,re.method="throw",re.arg=Se.arg)}}}function B(N,Y){var re=Y.method,ae=N.iterator[re];if(ae===e)return Y.delegate=null,re==="throw"&&N.iterator.return&&(Y.method="return",Y.arg=e,B(N,Y),Y.method==="throw")||re!=="return"&&(Y.method="throw",Y.arg=new TypeError("The iterator does not provide a '"+re+"' method")),W;var Te=C(ae,N.iterator,Y.arg);if(Te.type==="throw")return Y.method="throw",Y.arg=Te.arg,Y.delegate=null,W;var De=Te.arg;if(!De)return Y.method="throw",Y.arg=new TypeError("iterator result is not an object"),Y.delegate=null,W;if(De.done)Y[N.resultName]=De.value,Y.next=N.nextLoc,Y.method!=="return"&&(Y.method="next",Y.arg=e);else return De;return Y.delegate=null,W}L(D),S(D,v,"Generator"),S(D,g,function(){return this}),S(D,"toString",function(){return"[object Generator]"});function X(N){var Y={tryLoc:N[0]};1 in N&&(Y.catchLoc=N[1]),2 in N&&(Y.finallyLoc=N[2],Y.afterLoc=N[3]),this.tryEntries.push(Y)}function Q(N){var Y=N.completion||{};Y.type="normal",delete Y.arg,N.completion=Y}function U(N){this.tryEntries=[{tryLoc:"root"}],N.forEach(X,this),this.reset(!0)}i.keys=function(N){var Y=Object(N),re=[];for(var ae in Y)re.push(ae);return re.reverse(),function Te(){for(;re.length;){var De=re.pop();if(De in Y)return Te.value=De,Te.done=!1,Te}return Te.done=!0,Te}};function se(N){if(N){var Y=N[g];if(Y)return Y.call(N);if(typeof N.next=="function")return N;if(!isNaN(N.length)){var re=-1,ae=function Te(){for(;++re<N.length;)if(a.call(N,re))return Te.value=N[re],Te.done=!1,Te;return Te.value=e,Te.done=!0,Te};return ae.next=ae}}return{next:It}}i.values=se;function It(){return{value:e,done:!0}}return U.prototype={constructor:U,reset:function(N){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(Q),!N)for(var Y in this)Y.charAt(0)==="t"&&a.call(this,Y)&&!isNaN(+Y.slice(1))&&(this[Y]=e)},stop:function(){this.done=!0;var N=this.tryEntries[0],Y=N.completion;if(Y.type==="throw")throw Y.arg;return this.rval},dispatchException:function(N){if(this.done)throw N;var Y=this;function re(we,Se){return De.type="throw",De.arg=N,Y.next=we,Se&&(Y.method="next",Y.arg=e),!!Se}for(var ae=this.tryEntries.length-1;ae>=0;--ae){var Te=this.tryEntries[ae],De=Te.completion;if(Te.tryLoc==="root")return re("end");if(Te.tryLoc<=this.prev){var Ce=a.call(Te,"catchLoc"),Le=a.call(Te,"finallyLoc");if(Ce&&Le){if(this.prev<Te.catchLoc)return re(Te.catchLoc,!0);if(this.prev<Te.finallyLoc)return re(Te.finallyLoc)}else if(Ce){if(this.prev<Te.catchLoc)return re(Te.catchLoc,!0)}else if(Le){if(this.prev<Te.finallyLoc)return re(Te.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(N,Y){for(var re=this.tryEntries.length-1;re>=0;--re){var ae=this.tryEntries[re];if(ae.tryLoc<=this.prev&&a.call(ae,"finallyLoc")&&this.prev<ae.finallyLoc){var Te=ae;break}}Te&&(N==="break"||N==="continue")&&Te.tryLoc<=Y&&Y<=Te.finallyLoc&&(Te=null);var De=Te?Te.completion:{};return De.type=N,De.arg=Y,Te?(this.method="next",this.next=Te.finallyLoc,W):this.complete(De)},complete:function(N,Y){if(N.type==="throw")throw N.arg;return N.type==="break"||N.type==="continue"?this.next=N.arg:N.type==="return"?(this.rval=this.arg=N.arg,this.method="return",this.next="end"):N.type==="normal"&&Y&&(this.next=Y),W},finish:function(N){for(var Y=this.tryEntries.length-1;Y>=0;--Y){var re=this.tryEntries[Y];if(re.finallyLoc===N)return this.complete(re.completion,re.afterLoc),Q(re),W}},catch:function(N){for(var Y=this.tryEntries.length-1;Y>=0;--Y){var re=this.tryEntries[Y];if(re.tryLoc===N){var ae=re.completion;if(ae.type==="throw"){var Te=ae.arg;Q(re)}return Te}}throw new Error("illegal catch attempt")},delegateYield:function(N,Y,re){return this.delegate={iterator:se(N),resultName:Y,nextLoc:re},this.method==="next"&&(this.arg=e),W}},i}(c.exports);try{regeneratorRuntime=s}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=s:Function("r","regeneratorRuntime = r")(s)}})(dv);var N_={exports:{}};(function(c){(function(s,i){c.exports?c.exports=i():s.log=i()})(H_,function(){var s=function(){},i="undefined",l=typeof window!==i&&typeof window.navigator!==i&&/Trident\/|MSIE /.test(window.navigator.userAgent),a=["trace","debug","info","warn","error"];function _(R,I){var V=R[I];if(typeof V.bind=="function")return V.bind(R);try{return Function.prototype.bind.call(V,R)}catch{return function(){return Function.prototype.apply.apply(V,[R,arguments])}}}function e(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function p(R){return R==="debug"&&(R="log"),typeof console===i?!1:R==="trace"&&l?e:console[R]!==void 0?_(console,R):console.log!==void 0?_(console,"log"):s}function g(R,I){for(var V=0;V<a.length;V++){var W=a[V];this[W]=V<R?s:this.methodFactory(W,R,I)}this.log=this.debug}function n(R,I,V){return function(){typeof console!==i&&(g.call(this,I,V),this[R].apply(this,arguments))}}function v(R,I,V){return p(R)||n.apply(this,arguments)}function S(R,I,V){var W=this,oe;I=I??"WARN";var x="loglevel";typeof R=="string"?x+=":"+R:typeof R=="symbol"&&(x=void 0);function $(D){var L=(a[D]||"silent").toUpperCase();if(!(typeof window===i||!x)){try{window.localStorage[x]=L;return}catch{}try{window.document.cookie=encodeURIComponent(x)+"="+L+";"}catch{}}}function Re(){var D;if(!(typeof window===i||!x)){try{D=window.localStorage[x]}catch{}if(typeof D===i)try{var L=window.document.cookie,q=L.indexOf(encodeURIComponent(x)+"=");q!==-1&&(D=/^([^;]+)/.exec(L.slice(q))[1])}catch{}return W.levels[D]===void 0&&(D=void 0),D}}function Ie(){if(!(typeof window===i||!x)){try{window.localStorage.removeItem(x);return}catch{}try{window.document.cookie=encodeURIComponent(x)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}W.name=R,W.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},W.methodFactory=V||v,W.getLevel=function(){return oe},W.setLevel=function(D,L){if(typeof D=="string"&&W.levels[D.toUpperCase()]!==void 0&&(D=W.levels[D.toUpperCase()]),typeof D=="number"&&D>=0&&D<=W.levels.SILENT){if(oe=D,L!==!1&&$(D),g.call(W,D,R),typeof console===i&&D<W.levels.SILENT)return"No console available for logging"}else throw"log.setLevel() called with invalid level: "+D},W.setDefaultLevel=function(D){I=D,Re()||W.setLevel(D,!1)},W.resetLevel=function(){W.setLevel(I,!1),Ie()},W.enableAll=function(D){W.setLevel(W.levels.TRACE,D)},W.disableAll=function(D){W.setLevel(W.levels.SILENT,D)};var H=Re();H==null&&(H=I),W.setLevel(H,!1)}var m=new S,C={};m.getLogger=function(I){if(typeof I!="symbol"&&typeof I!="string"||I==="")throw new TypeError("You must supply a name when creating a logger.");var V=C[I];return V||(V=C[I]=new S(I,m.getLevel(),m.methodFactory)),V};var A=typeof window!==i?window.log:void 0;return m.noConflict=function(){return typeof window!==i&&window.log===m&&(window.log=A),m},m.getLoggers=function(){return C},m.default=m,m})})(N_);var Ot=N_.exports;const As=()=>`${new Date().toISOString()} | metrics`,Cs=(c,s,i)=>`${c} | ${s} | ${i}`;Ot.setDefaultLevel(Ot.levels.TRACE);const pv=c=>{Ot.info(Cs(As(),"log ",`set log level to ${c?"verbose":"info"}`)),Ot.setLevel(c?Ot.levels.TRACE:Ot.levels.INFO)},mv=c=>{const s=[...Object.keys(Ot.levels)];s.includes(c)?(Ot.info(Cs(As(),"log ",`update log level to ${c.toLowerCase()}`)),Ot.setLevel(c)):Ot.warn(Cs(As(),"log ","Incorrect log level please choose one of "),s)},ke=(c,s,i)=>{i?Ot.debug(Cs(As(),c,s),i):Ot.debug(Cs(As(),c,s))},iu=(c,s)=>{Ot.info(Cs(As(),c,s))},Pn=(c,s)=>{Ot.info(Cs(As(),c,s))},Ma=(c,s)=>{Ot.warn(Cs(As(),c,s))},ir=(c,s)=>{Ot.error(Cs(As(),c,s))};function gv(c){return Math.floor(Math.random()*c).toString()}function Mf(c,s){let i=s;return c.forEach(l=>{i=i.replace(l,"")}),i}function Tv(c,s){let i="";for(let l=0;l<s;l+=1)i+=c[gv(c.length)];return i}function vv({length:c=20,useLetters:s=!0,useNumbers:i=!0,includeSymbols:l=[],excludeSymbols:a=[]}={}){let _="abcdefghijklmnopqrstuvwxyz",e="0123456789",p=[],g=[],n=[];return s&&(a.length&&(_=Mf(a,_)),g=_.split("")),i&&(a.length&&(e=Mf(a,e)),n=e.split("")),p=[...g,...n,...l],Tv(p,c)}var Ev=vv;const Ji=tt(Ev),Sv=()=>"WebRTCMetrics",yv=()=>"5.0.3",qe={INBOUND:"inbound",OUTBOUND:"outbound"},Ss={IDLE:"idle",RUNNING:"running",MUTED:"muted"},Bi={NEW:"new",CHECKING:"checking",CONNECTED:"connected",COMPLETED:"completed",DISCONNECTED:"disconnected",FAILED:"failed",CLOSED:"closed"},Av=()=>({...{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:[]}}),U_={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:qe.INBOUND},P_={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:qe.OUTBOUND},x_={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:qe.INBOUND},M_={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:qe.OUTBOUND},Cv=c=>{const s={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 i={...c,audio:{},video:{},data:{...c.data},network:{...c.network},experimental:{...c.experimental}};return Object.keys(c.audio).forEach(l=>{i.audio[l]={...c.audio[l]}}),Object.keys(c.video).forEach(l=>{i.video[l]={...c.video[l]}}),i}return{...s,audio:{},video:{},data:{...s.data},network:{...s.network},experimental:{...s.experimental}}},Rv={refreshEvery:2e3,startAfter:0,stopAfter:-1,verbose:!1,pname:`p-${Ji()}`,cid:`c-${Ji()}`,uid:`u-${Ji()}`,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"},K={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"},M={SUCCEEDED:"succeeded",AUDIO:"audio",VIDEO:"video"},Gi={ETHERNET:0,CELLULAR_5G:2,WIFI:3,CELLULAR_4G:5,CELLULAR:10},lu={ETHERNET:"ethernet",CELLULAR_4G:"cellular",WIFI:"wifi"},ie={AUDIO:"audio",VIDEO:"video",NETWORK:"network",DATA:"data"},au="config ",Iv=(c,s={},i)=>{const l={...i,...s};return s.pname||Ma(au,`Argument [String] 'cfg.pname' for the peerConnection name or id is missing - use generated '${i.pname}'`),s.cid||Ma(au,`Argument [String] 'cfg.cid' for the call name or id is missing - use generated '${i.cid}'`),s.uid||Ma(au,`Argument [String] 'cfg.uid' for the user name or id is missing - use generated '${i.uid}'`),l.pc=c,l},bv=(c={})=>{const s={...Rv,...c};return s.name=Sv(),s.version=yv(),s},_l=(c,s,i,l=!1,a)=>{let _=c.map(e=>{if(!i)return e[s];if(!a)return e[s][i];const p=e[s][a];return p?p[i]:null});return _=_.filter(e=>l?Number.isFinite(e)&&e>0:Number.isFinite(e)),_.length===0?[]:_},Zs=c=>c.reduce((s,i)=>s+i,0)/c.length,wv=()=>`probe-${Ji()}`,Ov=()=>`coltr-${Ji()}`,kf=c=>new Promise(s=>setTimeout(s,c)),wu=(c,s,i)=>{s?c.call(s,i):c(i)},Qe=(c,s,i,l)=>{const a=_l(c,s,i,!0,l);if(a.length===0)return null;const _=a.reduce((n,v)=>n+v,0)/a.length;return _===0?null:a.map(n=>Math.abs(_-n)).reduce((n,v)=>n+v,0)/a.length*100/_},st=(c,s,i,l=!1,a)=>{const _=_l(c,s,i,l,a);return _.length===0?null:_.reduce((e,p)=>e+p,0)/_.length},wn=(c,s,i)=>_l(c,s,i).reduce((a,_)=>a+_,0),Ze=(c,s,i,l)=>{const a=_l(c,s,i,!0,l);return a.length===0?null:Math.min(...a)},et=(c,s,i,l)=>{const a=_l(c,s,i,!1,l);return a.length===0?null:Math.max(...a)},vt=(c,s,i,l)=>{const a=c.slice().pop();if(!a)return null;if(!i)return a[s];if(!l)return a[s][i];const _=a[s][l];return _?_[i]:null},Dv=c=>c.slice().pop(),_t=(c,s,i)=>{if(!s)return null;const l={};let a=s[M.AUDIO][c];a||(a=i===qe.INBOUND?{...U_}:{...P_}),l[M.AUDIO]=a;let _=s[M.VIDEO][c];return _||(_=i===qe.INBOUND?{...x_}:{...M_}),l[M.VIDEO]=_,l},Wi="exporter ",Nv="2.0",Lf=(c,s,i)=>{if(!c||c.length===0)return 0;const l=c[c.length-1];if(!l)return 0;const a=l[s][i];if(a){const _=a.total_rtt_ms_out,e=a.total_rtt_measure_out;return!e||!_?st(c,s,"delta_rtt_ms_out",!1,i):Number(_/e)}return null},Uv=(c,s)=>{if(!c||c.length===0)return 0;const i=c[c.length-1];if(!i)return 0;const l=i[s].total_rtt_connectivity_ms,a=i[s].total_rtt_connectivity_measure;return!a||!l?st(c,s,"delta_rtt_connectivity_ms"):Number(l/a)},Pv=c=>vt(c,"network","local_candidate_type")!=="relay"?`direct/${vt(c,"network","local_candidate_protocol")}`:`turn/${vt(c,"network","local_candidate_relay_protocol")}`,xv=c=>{const s=vt(c,"network","remote_candidate_type"),i=vt(c,"network","remote_candidate_protocol");return s!=="relay"?`direct/${i}`:`turn/${i}`};class Mv{constructor(s){this._start=null,this._end=null,this._cfg=s,this._referenceReport=null,this._reports=[],this._events=[]}start(){iu(Wi,"start() - start exporter...");const s=new Date;return this._start=s.toJSON(),s}stop(){iu(Wi,"stop() - stop exporter...");const s=new Date;return this._end=s.toJSON(),s}saveReferenceReport(s){this._referenceReport=s}getReferenceReport(){return this._referenceReport}addReport(s){this._cfg.ticket&&(ke(Wi,`addReport() - add report to exporter at ${s.timestamp}`),this._reports.push(s))}addCustomEvent(s){this._events.push(s)}reset(){iu(Wi,"resetReports() - reset reports"),this._reports=[],this._referenceReport=null,this._start=null,this._end=null}get ticket(){ke(Wi,"ticket() - generate ticket");const s=vt(this._reports,"audio","total_packets_lost_in"),i=vt(this._reports,"audio","total_packets_in"),l=vt(this._reports,"video","total_packets_lost_in"),a=vt(this._reports,"video","total_packets_in"),_={},e=Dv(this._reports);return e&&(Object.keys(e[M.AUDIO]).forEach(p=>{const g=e[M.AUDIO][p];if(_[g.ssrc]={type:M.AUDIO,direction:g.direction},g.direction===qe.INBOUND){const n={avg:st(this._reports,M.AUDIO,"delta_jitter_ms_in",!1,p),min:Ze(this._reports,M.AUDIO,"delta_jitter_ms_in",p),max:et(this._reports,M.AUDIO,"delta_jitter_ms_in",p),volatility:Qe(this._reports,M.AUDIO,"delta_jitter_ms_in",p),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},v={avg:st(this._reports,M.AUDIO,"delta_kbs_in",!1,p),min:Ze(this._reports,M.AUDIO,"delta_kbs_in",p),max:et(this._reports,M.AUDIO,"delta_kbs_in",p),volatility:Qe(this._reports,M.AUDIO,"delta_kbs_in",p),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},S={avg:st(this._reports,M.AUDIO,"delta_KBytes_in",!1,p),min:Ze(this._reports,M.AUDIO,"delta_KBytes_in",p),max:et(this._reports,M.AUDIO,"delta_KBytes_in",p),volatility:Qe(this._reports,M.AUDIO,"delta_KBytes_in",p),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},m={emodel:{avg:st(this._reports,M.AUDIO,"mos_emodel_in",!1,p),min:Ze(this._reports,M.AUDIO,"mos_emodel_in",p),max:et(this._reports,M.AUDIO,"mos_emodel_in",p),volatility:Qe(this._reports,M.AUDIO,"mos_emodel_in",p)},effective:{avg:st(this._reports,M.AUDIO,"mos_in",!1,p),min:Ze(this._reports,M.AUDIO,"mos_in",p),max:et(this._reports,M.AUDIO,"mos_in",p),volatility:Qe(this._reports,M.AUDIO,"mos_in",p)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}},C=vt(this._reports,M.AUDIO,"total_packets_lost_in",p),A=vt(this._reports,M.AUDIO,"total_packets_in",p),R={lost:C,avg:Math.round((C/(C+A)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};_[p].jitter=n,_[p].mos=m,_[p].traffic=S,_[p].bitrate=v,_[p].loss=R}else{const n={avg:st(this._reports,M.AUDIO,"delta_jitter_ms_out",!1,p),min:Ze(this._reports,M.AUDIO,"delta_jitter_ms_out",p),max:et(this._reports,M.AUDIO,"delta_jitter_ms_out",p),volatility:Qe(this._reports,M.AUDIO,"delta_jitter_ms_out",p),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},v={avg:st(this._reports,M.AUDIO,"delta_kbs_out",!1,p),min:Ze(this._reports,M.AUDIO,"delta_kbs_out",p),max:et(this._reports,M.AUDIO,"delta_kbs_out",p),volatility:Qe(this._reports,M.AUDIO,"delta_kbs_out",p),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},S={avg:st(this._reports,M.AUDIO,"delta_KBytes_out",!1,p),min:Ze(this._reports,M.AUDIO,"delta_KBytes_out",p),max:et(this._reports,M.AUDIO,"delta_KBytes_out",p),volatility:Qe(this._reports,M.AUDIO,"delta_KBytes_out",p),_unit:{avg:"KB",min:"KB",max:"KB",bitrate:"kbs",volatility:"percent"}},m={avg:Lf(this._reports,M.AUDIO,p),min:Ze(this._reports,M.AUDIO,"delta_rtt_ms_out",p),max:et(this._reports,M.AUDIO,"delta_rtt_ms_out",p),volatility:Qe(this._reports,M.AUDIO,"delta_rtt_ms_out",p),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},C=vt(this._reports,M.AUDIO,"total_packets_lost_out",p),A=vt(this._reports,M.AUDIO,"total_packets_out",p),R={lost:C,avg:Math.round((C/(C+A)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}},I={emodel:{avg:st(this._reports,M.AUDIO,"mos_emodel_out",!1,p),min:Ze(this._reports,M.AUDIO,"mos_emodel_out",p),max:et(this._reports,M.AUDIO,"mos_emodel_out",p),volatility:Qe(this._reports,M.AUDIO,"mos_emodel_out",p)},effective:{avg:st(this._reports,M.AUDIO,"mos_out",!1,p),min:Ze(this._reports,M.AUDIO,"mos_out",p),max:et(this._reports,M.AUDIO,"mos_out",p),volatility:Qe(this._reports,M.AUDIO,"mos_out",p)},_unit:{avg:"number (1-5)",min:"number (1-5)",max:"number (1-5)",volatility:"percent"}};_[p].jitter=n,_[p].rtt=m,_[p].traffic=S,_[p].bitrate=v,_[p].loss=R,_[p].mos=I}}),Object.keys(e[M.VIDEO]).forEach(p=>{const g=e[M.VIDEO][p];if(_[p]={type:M.VIDEO,direction:g.direction},g.direction===qe.INBOUND){const n={avg:st(this._reports,M.VIDEO,"delta_jitter_ms_in",!1,p),min:Ze(this._reports,M.VIDEO,"delta_jitter_ms_in",p),max:et(this._reports,M.VIDEO,"delta_jitter_ms_in",p),volatility:Qe(this._reports,M.VIDEO,"delta_jitter_ms_in",p),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},v={avg:st(this._reports,M.VIDEO,"delta_kbs_in",!1,p),min:Ze(this._reports,M.VIDEO,"delta_kbs_in",p),max:et(this._reports,M.VIDEO,"delta_kbs_in",p),volatility:Qe(this._reports,M.VIDEO,"delta_kbs_in",p),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},S={avg:st(this._reports,M.VIDEO,"delta_KBytes_in",!1,p),min:Ze(this._reports,M.VIDEO,"delta_KBytes_in",p),max:et(this._reports,M.VIDEO,"delta_KBytes_in",p),volatility:Qe(this._reports,M.VIDEO,"delta_KBytes_in",p),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},m=vt(this._reports,M.VIDEO,"total_packets_lost_in",p),C=vt(this._reports,M.VIDEO,"total_packets_in",p),A={lost:m,avg:Math.round((m/(m+C)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};_[p].jitter=n,_[p].traffic=S,_[p].bitrate=v,_[p].loss=A}else{const n={avg:st(this._reports,M.VIDEO,"delta_jitter_ms_out",!1,p),min:Ze(this._reports,M.VIDEO,"delta_jitter_ms_out",p),max:et(this._reports,M.VIDEO,"delta_jitter_ms_out",p),volatility:Qe(this._reports,M.VIDEO,"delta_jitter_ms_out",p),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},v={avg:st(this._reports,M.VIDEO,"delta_kbs_out",!1,p),min:Ze(this._reports,M.VIDEO,"delta_kbs_out",p),max:et(this._reports,M.VIDEO,"delta_kbs_out",p),volatility:Qe(this._reports,M.VIDEO,"delta_kbs_out",p),_unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},S={avg:st(this._reports,M.VIDEO,"delta_KBytes_out",!1,p),min:Ze(this._reports,M.VIDEO,"delta_KBytes_out",p),max:et(this._reports,M.VIDEO,"delta_KBytes_out",p),volatility:Qe(this._reports,M.VIDEO,"delta_KBytes_out",p),_unit:{avg:"KB",min:"KB",max:"KB",volatility:"percent"}},m={avg:Lf(this._reports,M.VIDEO,p),min:Ze(this._reports,M.VIDEO,"delta_rtt_ms_out",p),max:et(this._reports,M.VIDEO,"delta_rtt_ms_out",p),volatility:Qe(this._reports,M.VIDEO,"delta_rtt_ms_out",p),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},C=vt(this._reports,M.VIDEO,"total_packets_lost_out",p),A=vt(this._reports,M.VIDEO,"total_packets_out",p),R={lost:C,avg:Math.round((C/(C+A)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};_[p].jitter=n,_[p].rtt=m,_[p].traffic=S,_[p].bitrate=v,_[p].loss=R}})),{version:Nv,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:_,data:{rtt:{avg:Uv(this._reports,"data"),min:Ze(this._reports,"data","delta_rtt_connectivity_ms"),max:et(this._reports,"data","delta_rtt_connectivity_ms"),volatility:Qe(this._reports,"data","delta_rtt_connectivity_ms"),_unit:{avg:"ms",min:"ms",max:"ms",volatility:"percent"}},packetsLost:{audio:{in:{avg:Math.round((s/(s+i)*100||0)*100)/100}},video:{in:{avg:Math.round((l/(l+a)*100||0)*100)/100}},unit:{avg:"percent"}},bitrate:{in:{avg:st(this._reports,"data","delta_kbs_in"),min:Ze(this._reports,"data","delta_kbs_in"),max:et(this._reports,"data","delta_kbs_in"),volatility:Qe(this._reports,"data","delta_kbs_in")},out:{avg:st(this._reports,"data","delta_kbs_out"),min:Ze(this._reports,"data","delta_kbs_out"),max:et(this._reports,"data","delta_kbs_out"),volatility:Qe(this._reports,"data","delta_kbs_out")},unit:{avg:"kbs",min:"kbs",max:"kbs",volatility:"percent"}},traffic:{in:{avg:st(this._reports,"data","delta_KBytes_in"),min:Ze(this._reports,"data","delta_KBytes_in"),max:et(this._reports,"data","delta_KBytes_in"),volatility:Qe(this._reports,"data","delta_KBytes_in")},out:{avg:st(this._reports,"data","delta_KBytes_out"),min:Ze(this._reports,"data","delta_KBytes_out"),max:et(this._reports,"data","delta_KBytes_out"),volatility:Qe(this._reports,"data","delta_KBytes_out")},unit:{avg:"KBytes",min:"KBytes",max:"KBytes",volatility:"percent"}},network:{localConnection:Pv(this._reports),remoteConnection:xv(this._reports)}}}}updateConfig(s){this._cfg=s}getLastReport(){return this._reports.slice().pop()||null}getBeforeLastReport(){const s=this._reports.slice();return s.pop(),s.pop()||null}getReportsNumber(){return this._reports.length}}const Js="extractor ",$f=(c,s,i,l)=>{let a=!1;const _=l[s].total_rtt_ms_out,e=l[s].total_rtt_measure_out,p=i?i[s].total_rtt_ms_out:0,g=i?i[s].total_rtt_measure_out:0,n={rtt:null,totalRTT:_,totalRTTMeasurements:e};if(c[K.TIMESTAMP]===l[s].timestamp_out||!Object.prototype.hasOwnProperty.call(c,K.ROUND_TRIP_TIME)||Object.prototype.hasOwnProperty.call(c,K.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS)&&(a=!0,Number(c[K.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])===0||Number(c[K.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-g===e))return n;const v=1e3*Number(c[K.ROUND_TRIP_TIME]);let S=_+v,m=e+1;return a&&(S=1e3*Number(c[K.TOTAL_ROUND_TRIP_TIME])-p,m=Number(c[K.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-g),{rtt:v,totalRTT:S,totalRTTMeasurements:m}},kv=(c,s,i,l)=>{if(!Object.prototype.hasOwnProperty.call(c,K.CURRENT_ROUND_TRIP_TIME))return{rtt:null,totalRTT:l[s].total_rtt_connectivity_ms,totalRTTMeasurements:l[s].total_rtt_connectivity_measure};const a=1e3*Number(c[K.CURRENT_ROUND_TRIP_TIME]);let _=l[s].total_rtt_connectivity_ms+a,e=l[s].total_rtt_connectivity_measure+1;return Object.prototype.hasOwnProperty.call(c,K.TOTAL_ROUND_TRIP_TIME)&&(_=1e3*Number(c[K.TOTAL_ROUND_TRIP_TIME])-(i?i[s].total_rtt_connectivity_ms:0)),Object.prototype.hasOwnProperty.call(c,K.RESPONSES_RECEIVED)&&(e=Number(c[K.RESPONSES_RECEIVED])-(i?i[s].total_rtt_connectivity_measure:0)),{rtt:a,totalRTT:_,totalRTTMeasurements:e}},Ea=(c,s,i)=>c[K.TIMESTAMP]===i[s].timestamp_out||!Object.prototype.hasOwnProperty.call(c,K.JITTER)?null:1e3*(Number(c[K.JITTER])||0),Lv=(c,s)=>{if(!Object.prototype.hasOwnProperty.call(c,K.FRAMES_DECODED)||!Object.prototype.hasOwnProperty.call(c,K.TOTAL_DECODE_TIME))return{delta_ms_decode_frame:s[M.VIDEO].delta_ms_decode_frame_in,frames_decoded:s[M.VIDEO].total_frames_decoded_in,total_decode_time:s[M.VIDEO].total_time_decoded_in};const i=c[K.FRAMES_DECODED],l=c[K.TOTAL_DECODE_TIME],a=l-s[M.VIDEO].total_time_decoded_in,_=i-s[M.VIDEO].total_frames_decoded_in;return{delta_ms_decode_frame:_>0?a*1e3/_:0,frames_decoded:i,total_decode_time:l}},$v=(c,s)=>{if(!Object.prototype.hasOwnProperty.call(c,K.FRAMES_ENCODED)||!Object.prototype.hasOwnProperty.call(c,K.TOTAL_ENCODE_TIME))return{delta_ms_encode_frame:s[M.VIDEO].delta_ms_encode_frame_out,frames_encoded:s[M.VIDEO].total_frames_encoded_out,total_encode_time:s[M.VIDEO].total_time_encoded_out};const i=c[K.FRAMES_ENCODED],l=c[K.TOTAL_ENCODE_TIME],a=l-s[M.VIDEO].total_time_encoded_out,_=i-s[M.VIDEO].total_frames_encoded_out;return{delta_ms_encode_frame:_>0&&a?a*1e3/_:0,frames_encoded:i,total_encode_time:l}},Hf=(c,s,i,l)=>{if(!Object.prototype.hasOwnProperty.call(c,K.PACKETS_SENT)||!Object.prototype.hasOwnProperty.call(c,K.BYTES_SENT))return{packetsSent:i[s].total_packets_out,packetsLost:i[s].total_packets_lost_out,bytesSent:i[s].total_KBytes_out};const a=Number(c[K.PACKETS_SENT])||0-(l?l[s].total_packets_out:0),_=a-i[s].total_packets_out,e=Number(c[K.BYTES_SENT])/1024-(l?l[s].total_KBytes_out:0),p=e-i[s].total_KBytes_out,g=c[K.TIMESTAMP]||Date.now(),n=l?l.timestamp:null;let v=i.timestamp;!v&&n&&(v=n);const S=v?g-v:0,m=S>0?p*.008*1024/S*1e3:0;return{packetsSent:a,deltaPacketsSent:_,KBytesSent:e,deltaKBytesSent:p,kbsSent:m}},Ff=(c,s,i,l)=>{let a=i[s].total_packets_lost_out,_=0,e=0;return Object.prototype.hasOwnProperty.call(c,K.PACKETS_LOST)&&(a=Number(c[K.PACKETS_LOST])||0-(l?l[s].total_packets_lost_out:0),_=a-i[s].total_packets_lost_out),Object.prototype.hasOwnProperty.call(c,K.FRACTION_LOST)&&(e=Number(100*c[K.FRACTION_LOST])),{packetsLost:a,deltaPacketsLost:_,fractionLost:e}},jf=(c,s,i,l)=>{if(!Object.prototype.hasOwnProperty.call(c,K.PACKETS_RECEIVED)||!Object.prototype.hasOwnProperty.call(c,K.PACKETS_LOST)||!Object.prototype.hasOwnProperty.call(c,K.BYTES_RECEIVED))return{percent_packets_lost:i[s].percent_packets_lost_in,packetsReceived:i[s].total_packets_in,packetsLost:i[s].total_packets_lost_in,bytesReceived:i[s].total_KBytes_in};const a=Number(c[K.PACKETS_RECEIVED])||0-(l?l[s].total_packets_in:0),_=Number(c[K.PACKETS_LOST])||0-(l?l[s].total_packets_lost_in:0),e=_-i[s].total_packets_lost_in,p=a-i[s].total_packets_in,g=a!==i[s].total_packets_in?e*100/(e+p):0,n=Number(c[K.BYTES_RECEIVED])/1024-(l?l[s].total_KBytes_in:0),v=n-i[s].total_KBytes_in,S=c[K.TIMESTAMP]||Date.now(),m=l?l.timestamp:null;let C=i.timestamp;!C&&m&&(C=m);const A=C?S-C:0,R=A>0?v*.008*1024/A*1e3:0;return{percentPacketsLost:g,packetsReceived:a,deltaPacketsReceived:p,packetsLost:_,deltaPacketsLost:e,KBytesReceived:n,deltaKBytesReceived:v,kbsReceived:R}},Hv=c=>c[K.CANDIDATE_TYPE]!=="relay"?"":c[K.RELAY_PROTOCOL]||"",Fv=c=>{if(!Object.prototype.hasOwnProperty.call(c,K.NETWORK_TYPE))return Gi.WIFI;switch(c[K.NETWORK_TYPE]){case lu.ETHERNET:return Gi.ETHERNET;case lu.CELLULAR_4G:return Gi.CELLULAR_4G;case lu.WIFI:return Gi.WIFI;default:return Gi.CELLULAR}},qf=c=>!Object.prototype.hasOwnProperty.call(c,K.FRAME_HEIGHT)||!Object.prototype.hasOwnProperty.call(c,K.FRAME_WIDTH)?{width:null,height:null,framerate:null}:{width:c[K.FRAME_WIDTH]||null,height:c[K.FRAME_HEIGHT]||null,framerate:c[K.FRAMES_PER_SECOND]},jv=c=>{const s=Object.prototype.hasOwnProperty.call(c,K.QUALITY_LIMITATION_REASON)?c[K.QUALITY_LIMITATION_REASON]:null,i=Object.prototype.hasOwnProperty.call(c,K.QUALITY_LIMITATION_RESOLUTION_CHANGES)?c[K.QUALITY_LIMITATION_RESOLUTION_CHANGES]:null,l=Object.prototype.hasOwnProperty.call(c,K.QUALITY_LIMITATION_DURATIONS)?c[K.QUALITY_LIMITATION_DURATIONS]:null;return l&&Object.keys(l).forEach(a=>{l[a]>1e3&&(l[a]=Number(l[a]/1e3))}),{reason:s,durations:l,resolutionChanges:i}},qv=(c,s,i)=>{if(!Object.prototype.hasOwnProperty.call(c,K.PLI)||!Object.prototype.hasOwnProperty.call(c,K.NACK))return{pliCount:s.total_pli_sent_in,nackCount:s.total_nack_sent_in,deltaPliCount:0,deltaNackCount:0};const l=(c[K.PLI]||0)-(i?i[M.VIDEO].total_pli_sent_in:0),a=(c[K.NACK]||0)-(i?i[M.VIDEO].total_nack_sent_in:0);return{pliCount:l,nackCount:a,deltaPliCount:l-s[M.VIDEO].total_pli_sent_in,deltaNackCount:a-s[M.VIDEO].total_nack_sent_in}},Vv=(c,s,i)=>{if(!Object.prototype.hasOwnProperty.call(c,K.PLI)||!Object.prototype.hasOwnProperty.call(c,K.NACK))return{pliCount:s.total_pli_received_out,nackCount:s.total_nack_received_out,deltaPliCount:0,deltaNackCount:0};const l=(c[K.PLI]||0)-(i?i[M.VIDEO].total_pli_received_out:0),a=(c[K.NACK]||0)-(i?i[M.VIDEO].total_nack_received_out:0);return{pliCount:l,nackCount:a,deltaPliCount:l-s[M.VIDEO].total_pli_received_out,deltaNackCount:a-s[M.VIDEO].total_nack_received_out}},Bv=c=>({channels:c[K.CHANNELS]||null,clock_rate:c[K.CLOCK_RATE]||null,mime_type:c[K.MIME_TYPE]||null,sdp_fmtp_line:c[K.SDP_FMTP_LINE]||null}),Gv=c=>({clock_rate:c[K.CLOCK_RATE]||null,mime_type:c[K.MIME_TYPE]||null}),Wv=(c,s,i)=>{const l=(c[K.BYTES_RECEIVED]||0)/1024-(i?i.data.total_KBytes_in:0),a=(c[K.BYTES_SENT]||0)/1024-(i?i.data.total_KBytes_out:0),_=c[K.TIMESTAMP]||Date.now(),e=l-s.data.total_KBytes_in,p=a-s.data.total_KBytes_out,g=i?i.timestamp:null;let n=s.timestamp;!n&&g&&(n=g);const v=n?_-n:0,S=v>0?e*.008*1024/v*1e3:0,m=v>0?p*.008*1024/v*1e3:0;return{total_KBytes_received:l,total_KBytes_sent:a,delta_KBytes_received:e,delta_KBytes_sent:p,kbs_speed_received:S,kbs_speed_sent:m}},Kv=c=>{const s=c[K.AVAILABLE_INCOMING_BITRATE]/1024||0,i=c[K.AVAILABLE_OUTGOING_BITRATE]/1024||0;return{kbs_incoming_bandwidth:s,kbs_outgoing_bandwidth:i}},Yv=(c,s,i,l)=>{if(!c)return[];switch(c[K.TYPE]){case zt.CANDIDATE_PAIR:let a=!1;if(c[K.NOMINATED]&&c[K.STATE]===M.SUCCEEDED&&(a=!0,ke(Js,`analyze() - got stats ${c[K.TYPE]} for ${i}`,c),K.SELECTED in c&&!c[K.SELECTED]&&(a=!1)),a){const e=c[K.LOCAL_CANDIDATE_ID],p=c[K.REMOTE_CANDIDATE_ID],g=Wv(c,s,l),n=Kv(c),v=kv(c,"data",l,s);return[{type:ie.NETWORK,value:{local_candidate_id:e}},{type:ie.NETWORK,value:{remote_candidate_id:p}},{type:ie.DATA,value:{total_KBytes_in:g.total_KBytes_received}},{type:ie.DATA,value:{total_KBytes_out:g.total_KBytes_sent}},{type:ie.DATA,value:{delta_KBytes_in:g.delta_KBytes_received}},{type:ie.DATA,value:{delta_KBytes_out:g.delta_KBytes_sent}},{type:ie.DATA,value:{delta_kbs_in:g.kbs_speed_received}},{type:ie.DATA,value:{delta_kbs_out:g.kbs_speed_sent}},{type:ie.DATA,value:{delta_kbs_bandwidth_in:n.kbs_incoming_bandwidth}},{type:ie.DATA,value:{delta_kbs_bandwidth_out:n.kbs_outgoing_bandwidth}},{type:ie.DATA,value:{delta_rtt_connectivity_ms:v.rtt}},{type:ie.DATA,value:{total_rtt_connectivity_ms:v.totalRTT}},{type:ie.DATA,value:{total_rtt_connectivity_measure:v.totalRTTMeasurements}}]}break;case zt.LOCAL_CANDIDATE:if(c[K.ID]===s.network.local_candidate_id)return[{type:ie.NETWORK,value:{infrastructure:Fv(c)}},{type:ie.NETWORK,value:{local_candidate_type:c[K.CANDIDATE_TYPE]||""}},{type:ie.NETWORK,value:{local_candidate_protocol:c[K.PROTOCOL]||""}},{type:ie.NETWORK,value:{local_candidate_relay_protocol:Hv(c)}}];break;case zt.REMOTE_CANDIDATE:if(c[K.ID]===s.network.remote_candidate_id)return[{type:ie.NETWORK,value:{remote_candidate_type:c[K.CANDIDATE_TYPE]||""}},{type:ie.NETWORK,value:{remote_candidate_protocol:c[K.PROTOCOL]||""}}];break;case zt.INBOUND_RTP:{ke(Js,`analyze() - got stats ${c[K.TYPE]} for ${i}`,c);const e=c[K.SSRC],p=_t(e,s,qe.INBOUND);p&&(p.timestamp=s.timestamp);const g=_t(e,l,qe.INBOUND);if(g&&(g.timestamp=l.timestamp),c[K.MEDIA_TYPE]===M.AUDIO){const n=jf(c,M.AUDIO,p,g),v=Ea(c,M.AUDIO,p),S=c[K.CODEC_ID]||"";return[{ssrc:e,type:ie.AUDIO,value:{codec_id_in:S}},{ssrc:e,type:ie.AUDIO,value:{total_packets_in:n.packetsReceived}},{ssrc:e,type:ie.AUDIO,value:{delta_packets_in:n.deltaPacketsReceived}},{ssrc:e,type:ie.AUDIO,value:{total_packets_lost_in:n.packetsLost}},{ssrc:e,type:ie.AUDIO,value:{delta_packets_lost_in:n.deltaPacketsLost}},{ssrc:e,type:ie.AUDIO,value:{percent_packets_lost_in:n.percentPacketsLost}},{ssrc:e,type:ie.AUDIO,value:{total_KBytes_in:n.KBytesReceived}},{ssrc:e,type:ie.AUDIO,value:{delta_KBytes_in:n.deltaKBytesReceived}},{ssrc:e,type:ie.AUDIO,value:{delta_kbs_in:n.kbsReceived}},{ssrc:e,type:ie.AUDIO,value:{delta_jitter_ms_in:v}}]}if(c[K.MEDIA_TYPE]===M.VIDEO){const n=Lv(c,p),v=jf(c,M.VIDEO,p,g),S=Ea(c,M.VIDEO,p),m=c[K.DECODER_IMPLEMENTATION]||null,C=c[K.CODEC_ID]||null,A=qf(c),R=qv(c,p,g);return[{ssrc:e,type:ie.VIDEO,value:{codec_id_in:C}},{ssrc:e,type:ie.VIDEO,value:{total_packets_in:v.packetsReceived}},{ssrc:e,type:ie.VIDEO,value:{delta_packets_in:v.deltaPacketsReceived}},{ssrc:e,type:ie.VIDEO,value:{total_packets_lost_in:v.packetsLost}},{ssrc:e,type:ie.VIDEO,value:{delta_packets_lost_in:v.deltaPacketsLost}},{ssrc:e,type:ie.VIDEO,value:{percent_packets_lost_in:v.percentPacketsLost}},{ssrc:e,type:ie.VIDEO,value:{total_KBytes_in:v.KBytesReceived}},{ssrc:e,type:ie.VIDEO,value:{delta_KBytes_in:v.deltaKBytesReceived}},{ssrc:e,type:ie.VIDEO,value:{delta_kbs_in:v.kbsReceived}},{ssrc:e,type:ie.VIDEO,value:{delta_jitter_ms_in:S}},{ssrc:e,type:ie.VIDEO,value:{decoder_in:m}},{ssrc:e,type:ie.VIDEO,value:{delta_ms_decode_frame_in:n.delta_ms_decode_frame}},{ssrc:e,type:ie.VIDEO,value:{total_frames_decoded_in:n.frames_decoded}},{ssrc:e,type:ie.VIDEO,value:{total_time_decoded_in:n.total_decode_time}},{ssrc:e,type:ie.VIDEO,value:{total_nack_sent_in:R.nackCount}},{ssrc:e,type:ie.VIDEO,value:{delta_nack_sent_in:R.deltaNackCount}},{ssrc:e,type:ie.VIDEO,value:{total_pli_sent_in:R.pliCount}},{ssrc:e,type:ie.VIDEO,value:{delta_pli_sent_in:R.deltaPliCount}},{ssrc:e,type:ie.VIDEO,value:{size_in:A}}]}break}case zt.OUTBOUND_RTP:{ke(Js,`analyze() - got stats ${c[K.TYPE]} for ${i}`,c);const e=c[K.SSRC],p=_t(e,s,qe.OUTBOUND);p&&(p.timestamp=s.timestamp);const g=_t(e,l,qe.OUTBOUND);if(g&&(g.timestamp=l.timestamp),c[K.MEDIA_TYPE]===M.AUDIO){const n=c[K.CODEC_ID]||null,v=Hf(c,M.AUDIO,p,g);return[{ssrc:e,type:ie.AUDIO,value:{codec_id_out:n}},{ssrc:e,type:ie.AUDIO,value:{total_packets_out:v.packetsSent}},{ssrc:e,type:ie.AUDIO,value:{delta_packets_out:v.deltaPacketsSent}},{ssrc:e,type:ie.AUDIO,value:{total_KBytes_out:v.KBytesSent}},{ssrc:e,type:ie.AUDIO,value:{delta_KBytes_out:v.deltaKBytesSent}},{ssrc:e,type:ie.AUDIO,value:{delta_kbs_out:v.kbsSent}}]}if(c[K.MEDIA_TYPE]===M.VIDEO){const n=c[K.ENCODER_IMPLEMENTATION]||null,v=c[K.CODEC_ID]||null,S=$v(c,p),m=qf(c),C=jv(c),A=Vv(c,p,g),R=Hf(c,M.VIDEO,p,g);return[{ssrc:e,type:ie.VIDEO,value:{codec_id_out:v}},{ssrc:e,type:ie.VIDEO,value:{total_packets_out:R.packetsSent}},{ssrc:e,type:ie.VIDEO,value:{delta_packets_out:R.deltaPacketsSent}},{ssrc:e,type:ie.VIDEO,value:{total_KBytes_out:R.KBytesSent}},{ssrc:e,type:ie.VIDEO,value:{delta_KBytes_out:R.deltaKBytesSent}},{ssrc:e,type:ie.VIDEO,value:{delta_kbs_out:R.kbsSent}},{ssrc:e,type:ie.VIDEO,value:{encoder_out:n}},{ssrc:e,type:ie.VIDEO,value:{delta_ms_encode_frame_out:S.delta_ms_encode_frame}},{ssrc:e,type:ie.VIDEO,value:{total_frames_encoded_out:S.frames_encoded}},{ssrc:e,type:ie.VIDEO,value:{total_time_encoded_out:S.total_encode_time}},{ssrc:e,type:ie.VIDEO,value:{total_nack_received_out:A.nackCount}},{ssrc:e,type:ie.VIDEO,value:{delta_nack_received_out:A.deltaNackCount}},{ssrc:e,type:ie.VIDEO,value:{total_pli_received_out:A.pliCount}},{ssrc:e,type:ie.VIDEO,value:{delta_pli_received_out:A.deltaPliCount}},{ssrc:e,type:ie.VIDEO,value:{size_out:m}},{ssrc:e,type:ie.VIDEO,value:{limitation_out:C}}]}break}case zt.MEDIA_SOURCE:{ke(Js,`analyze() - got stats ${c[K.TYPE]} for ${i}`,c);break}case zt.TRACK:{ke(Js,`analyze() - got stats ${c[K.TYPE]} for ${i}`,c);break}case zt.CODEC:const _=[];return Object.keys(s[M.AUDIO]).forEach(e=>{const p=s[M.AUDIO][e];if(p.codec_id_in===c[K.ID]||p.codec_id_out===c[K.ID]){ke(Js,`analyze() - got stats ${c[K.TYPE]} for ${i}`,c);const g=Bv(c);c[K.ID]===p.codec_id_in?_.push({ssrc:p.ssrc,type:ie.AUDIO,value:{codec_in:g}}):_.push({ssrc:p.ssrc,type:ie.AUDIO,value:{codec_out:g}})}}),Object.keys(s[M.VIDEO]).forEach(e=>{const p=s[M.VIDEO][e];if(p.codec_id_in===c[K.ID]||p.codec_id_out===c[K.ID]){ke(Js,`analyze() - got stats ${c[K.TYPE]} for ${i}`,c);const g=Gv(c);c[K.ID]===p.codec_id_in?_.push({ssrc:p.ssrc,type:ie.VIDEO,value:{codec_in:g}}):_.push({ssrc:p.ssrc,type:ie.VIDEO,value:{codec_out:g}})}}),_;case zt.REMOTE_INBOUND_RTP:{ke(Js,`analyze() - got stats ${c[K.TYPE]} for ${i}`,c);const e=c[K.SSRC],p=_t(e,s,qe.OUTBOUND),g=_t(e,l,qe.OUTBOUND);if(c[K.KIND]===M.AUDIO){const n=$f(c,M.AUDIO,g,p),v=Ea(c,M.AUDIO,p),S=Ff(c,M.AUDIO,p,g);return[{ssrc:e,type:ie.AUDIO,value:{delta_rtt_ms_out:n.rtt}},{ssrc:e,type:ie.AUDIO,value:{total_rtt_ms_out:n.totalRTT}},{ssrc:e,type:ie.AUDIO,value:{total_rtt_measure_out:n.totalRTTMeasurements}},{ssrc:e,type:ie.AUDIO,value:{delta_jitter_ms_out:v}},{ssrc:e,type:ie.AUDIO,value:{timestamp_out:c[K.TIMESTAMP]}},{ssrc:e,type:ie.AUDIO,value:{total_packets_lost_out:S.packetsLost}},{ssrc:e,type:ie.AUDIO,value:{delta_packets_lost_out:S.deltaPacketsLost}},{ssrc:e,type:ie.AUDIO,value:{percent_packets_lost_out:S.fractionLost}}]}if(c[K.KIND]===M.VIDEO){const n=$f(c,M.VIDEO,g,p),v=Ea(c,M.VIDEO,p),S=Ff(c,M.VIDEO,p,g);return[{ssrc:e,type:ie.VIDEO,value:{delta_rtt_ms_out:n.rtt}},{ssrc:e,type:ie.VIDEO,value:{total_rtt_ms_out:n.totalRTT}},{ssrc:e,type:ie.VIDEO,value:{total_rtt_measure_out:n.totalRTTMeasurements}},{ssrc:e,type:ie.VIDEO,value:{delta_jitter_ms_out:v}},{ssrc:e,type:ie.VIDEO,value:{timestamp_out:c[K.TIMESTAMP]}},{ssrc:e,type:ie.VIDEO,value:{total_packets_lost_out:S.packetsLost}},{ssrc:e,type:ie.VIDEO,value:{delta_packets_lost_out:S.deltaPacketsLost}},{ssrc:e,type:ie.VIDEO,value:{percent_packets_lost_out:S.fractionLost}}]}break}}return[]},to=c=>c<0?1:c>100?4.5:1+.035*c+7/1e6*c*(c-60)*(100-c),Jv=(c,s=M.AUDIO,i,l,a)=>{const _=_t(a,c,qe.INBOUND),e=_t(a,i,qe.INBOUND),p=_t(a,l,qe.INBOUND),g=[],n=[],v=_[s].percent_packets_lost_in,S=_[s].delta_jitter_ms_in,m=e&&e[s].delta_jitter_ms_in||null,C=p&&p[s].delta_jitter_ms_in||null,A=c.data.delta_rtt_connectivity_ms,R=i&&i.data.delta_rtt_connectivity_ms||null,I=l&&l.data.delta_rtt_connectivity_ms||null;A&&g.push(A),R&&g.push(R),I&&g.push(I),S&&n.push(S),i&&m&&n.push(m),l&&C&&n.push(C);const V=g.length>0?Zs(g):100,W=n.length>0?Zs(n):10,oe=93.2-v,x=.18*oe*oe-27.9*oe+1126.62,$=(V+W)/2,Re=$-177.3<0?0:1,Ie=.024*$+.11*($-177.3)*Re,H=x-Ie;return to(H)},zv=(c,s=M.AUDIO,i,l,a)=>{const _=_t(a,c,qe.OUTBOUND),e=_t(a,i,qe.OUTBOUND),p=_t(a,l,qe.OUTBOUND),g=[],n=[],v=_[s].percent_packets_lost_out,S=_[s].delta_rtt_ms_out,m=e&&e[s].delta_rtt_ms_out||null,C=p&&p[s].delta_rtt_ms_out||null,A=_[s].delta_jitter_ms_out,R=e&&e[s].delta_jitter_ms_out||null,I=p&&p[s].delta_jitter_ms_out||null,V=c.data.delta_rtt_connectivity_ms,W=i&&i.data.delta_rtt_connectivity_ms||null,oe=l&&l.data.delta_rtt_connectivity_ms||null;S?g.push(S):V&&g.push(V),m?g.push(m):W&&g.push(W),C?g.push(C):oe&&g.push(oe),A&&n.push(A),i&&R&&n.push(R),l&&I&&n.push(I);const x=g.length>0?Zs(g):100,$=n.length>0?Zs(n):10,Re=93.2-v,Ie=.18*Re*Re-27.9*Re+1126.62,H=(x+$)/2,D=H-177.3<0?0:1,L=.024*H+.11*(H-177.3)*D,q=Ie-L;return to(q)},Xv=(c,s=M.AUDIO,i,l,a)=>{const _=_t(a,c,qe.INBOUND),e=_t(a,i,qe.INBOUND),p=_t(a,l,qe.INBOUND),g=[],n=[],v=_[s].percent_packets_lost_in/100,S=_[s].delta_jitter_ms_in,m=e&&e[s].delta_jitter_ms_in||null,C=p&&p[s].delta_jitter_ms_in||null,A=c.data.delta_rtt_connectivity_ms,R=i&&i.data.delta_rtt_connectivity_ms||null,I=l&&l.data.delta_rtt_connectivity_ms||null;A&&g.push(A),R&&g.push(R),I&&g.push(I),S&&n.push(S),e&&m&&n.push(m),p&&C&&n.push(C);const V=g.length>0?Zs(g):100,W=n.length>0?Zs(n):10,oe=0,x=19.8,$=29.7,Re=30,Ie=(V+W)/2+Re,H=Ie-177.3<0?0:1,D=.024*Ie+.11*(Ie-177.3)*H,q=93.2-(oe+x*Math.log(1+$*v)+D);return to(q)},Qv=(c,s=M.AUDIO,i,l,a)=>{const _=_t(a,c,qe.OUTBOUND),e=_t(a,i,qe.OUTBOUND),p=_t(a,l,qe.OUTBOUND),g=[],n=[],v=_[s].percent_packets_lost_out/100,S=_[s].delta_rtt_ms_out,m=e&&e[s].delta_rtt_ms_out||null,C=p&&p[s].delta_rtt_ms_out||null,A=_[s].delta_jitter_ms_out,R=e&&e[s].delta_jitter_ms_out||null,I=p&&p[s].delta_jitter_ms_out||null,V=c.data.delta_rtt_connectivity_ms,W=i&&i.data.delta_rtt_connectivity_ms||null,oe=l&&l.data.delta_rtt_connectivity_ms||null;S?g.push(S):V&&g.push(V),m?g.push(m):W&&g.push(W),C?g.push(C):oe&&g.push(oe),A&&n.push(A),e&&R&&n.push(R),p&&I&&n.push(I);const x=g.length>0?Zs(g):100,$=n.length>0?Zs(n):10,Re=0,Ie=19.8,H=29.7,D=30,L=(x+$)/2+D,q=L-177.3<0?0:1,j=.024*L+.11*(L-177.3)*q,X=93.2-(Re+Ie*Math.log(1+H*v)+j);return to(X)};class Zv{constructor(s,i){this._callbacks={onreport:null,onticket:null},this._id=Ov(),this._moduleName=this._id,this._probeId=i,this._config=s,this._exporter=new Mv(s),this._state=Ss.IDLE,this.registerToPCEvents(),Pn(this._moduleName,`new collector created for probe ${this._probeId}`)}analyze(s,i,l,a){const _=(g,n)=>g===M.AUDIO?n===zt.INBOUND_RTP?{...U_}:{...P_}:n===zt.INBOUND_RTP?{...x_}:{...M_},e=Cv(i);e.pname=this._config.pname,e.call_id=this._config.cid,e.user_id=this._config.uid,e.count=i?i.count+1:1;let p=null;return s.forEach(g=>{!p&&g.timestamp&&(p=g.timestamp),Yv(g,e,e.pname,a).forEach(v=>{if(v.value&&v.type)if(v.ssrc){let S=e[v.type][v.ssrc];S||(S=_(v.type,g.type),S.ssrc=v.ssrc,e[v.type][v.ssrc]=S),Object.keys(v.value).forEach(m=>{S[m]=v.value[m]})}else Object.keys(v.value).forEach(S=>{e[v.type][S]=v.value[S]})})}),e.timestamp=p,Object.keys(e[M.AUDIO]).forEach(g=>{const n=e[M.AUDIO][g];n.direction===qe.INBOUND?(n.mos_emodel_in=Jv(e,M.AUDIO,i,l,n.ssrc),n.mos_in=Xv(e,M.AUDIO,i,l,n.ssrc)):(n.mos_emodel_out=zv(e,M.AUDIO,i,l,n.ssrc),n.mos_out=Qv(e,M.AUDIO,i,l,n.ssrc))}),e}async takeReferenceStats(){return new Promise((s,i)=>{const l=Date.now();setTimeout(async()=>{try{const a=Date.now()-l,_=Date.now(),e=await this._config.pc.getStats(),p=this.analyze(e,null,null,null),g=Date.now();p.experimental.time_to_measure_ms=g-_,p.experimental.time_to_wait_ms=a,this._exporter.saveReferenceReport(p),ke(this._moduleName,`got reference report for probe ${this._probeId}`),s()}catch(a){i(a)}},this._config.startAfter)})}async collectStats(){try{if(this._state!==Ss.RUNNING||!this._config.pc)return ke(this._moduleName,`report discarded (too late) for probe ${this._probeId}`),null;const s=Date.now(),i=await this._config.pc.getStats(),l=this.analyze(i,this._exporter.getLastReport(),this._exporter.getBeforeLastReport(),this._exporter.getReferenceReport()),a=Date.now();return l.experimental.time_to_measure_ms=a-s,this._exporter.addReport(l),ke(this._moduleName,`got report for probe ${this._probeId}#${this._exporter.getReportsNumber()+1}`),this.fireOnReport(l),l}catch(s){return ir(this._moduleName,`got error ${s}`),null}}async start(){ke(this._moduleName,"starting"),this.state=Ss.RUNNING,this._startedTime=this._exporter.start(),ke(this._moduleName,"started")}async mute(){this.state=Ss.MUTED,ke(this._moduleName,"muted")}async unmute(){this.state=Ss.RUNNING,ke(this._moduleName,"unmuted")}async stop(s){if(ke(this._moduleName,`stopping${s?" by watchdog":""}...`),this._stoppedTime=this._exporter.stop(),this.state=Ss.IDLE,this._config.ticket){const{ticket:i}=this._exporter;this.fireOnTicket(i)}this._exporter.reset(),ke(this._moduleName,"stopped")}registerCallback(s,i,l){s in this._callbacks?(this._callbacks[s]={callback:i,context:l},ke(this._moduleName,`registered callback '${s}'`)):ir(this._moduleName,`can't register callback for '${s}' - not found`)}unregisterCallback(s){s in this._callbacks?(this._callbacks[s]=null,delete this._callbacks[s],ke(this._moduleName,`unregistered callback '${s}'`)):ir(this._moduleName,`can't unregister callback for '${s}' - not found`)}fireOnReport(s){this._callbacks.onreport&&wu(this._callbacks.onreport.callback,this._callbacks.onreport.context,s)}fireOnTicket(s){this._callbacks.onticket&&wu(this._callbacks.onticket.callback,this._callbacks.onticket.context,s)}updateConfig(s){this._config=s,this._exporter.updateConfig(s)}get state(){return this._state}set state(s){this._state=s,ke(this._moduleName,`state changed to ${s}`)}addCustomEvent(s,i,l,a){this._exporter.addCustomEvent({at:typeof s=="object"?s.toJSON():s,category:i,name:l,description:a})}async registerToPCEvents(){const{pc:s}=this._config;if(navigator.mediaDevices.ondevicechange=async()=>{try{const i=await navigator.mediaDevices.enumerateDevices();this.addCustomEvent(new Date().toJSON(),"device",`${i.length} devices found`,"Media Devices state")}catch{ir(this._moduleName,"can't get devices")}},s){s.oniceconnectionstatechange=()=>{const l=s.iceConnectionState;l===Bi.CONNECTED||l===Bi.COMPLETED?this.addCustomEvent(new Date().toJSON(),"call",l,"ICE connection state"):l===Bi.DISCONNECTED||l===Bi.FAILED?this.addCustomEvent(new Date().toJSON(),"call",l,"ICE connection state"):l===Bi.CLOSED&&this.addCustomEvent(new Date().toJSON(),"call","ended","ICE connection state")},s.onicegatheringstatechange=()=>{const l=s.iceGatheringState;this.addCustomEvent(new Date().toJSON(),"call",l,"ICE gathering state")},s.ontrack=l=>{this.addCustomEvent(new Date().toJSON(),"call",`${l.track.kind}track`,"MediaStreamTrack received")},s.onnegotiationneeded=()=>{this.addCustomEvent(new Date().toJSON(),"call","negotiation","Media changed")};const i=s.getReceivers();if(i&&i.length>0){const l=i[0],{transport:a}=l;if(a){const{iceTransport:_}=a;_&&(_.onselectedcandidatepairchange=()=>{this.addCustomEvent(new Date().toJSON(),"call","transport","Candidates Pair changed")})}}}}}class eE{constructor(s){this._id=s.pname&&s.pname.substr(0,12).padEnd(12," ")||wv(),this._moduleName=this._id,Pn(this._moduleName,"probe created"),this._config=s,this._collector=new Zv(this._config,this._id)}set onreport(s){s?this._collector.registerCallback("onreport",s):this._collector.unregisterCallback("onreport")}set onticket(s){s?this._collector.registerCallback("onticket",s):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(s){this._collector.state=s}addCustomEvent(s,i,l,a=new Date().toJSON()){this._collector.addCustomEvent(a,i,s,l)}get isRunning(){return this._collector.state===Ss.RUNNING}get isIdle(){return this._collector.state===Ss.IDLE}updateUserId(s){this._config.uid=s,this._collector.updateConfig(this._config)}updateCallId(s){this._config.cid=s,this._collector.updateConfig(this._config)}start(){if(!this.isIdle){Ma(this._moduleName,"probe is already running");return}this._collector.start()}stop(s=!1){this.isRunning&&this._collector.stop(s)}async takeReferenceStats(){return this._collector.takeReferenceStats()}async collectStats(){return this._collector.collectStats()}}const wt="engine ";class tE{constructor(s){this._config=s,this._probes=[],this._startedTime=null,this._callbacks={onresult:null},Pn(wt,`configured for probing every ${this._config.refreshEvery}ms`),Pn(wt,`configured for starting after ${this._config.startAfter}ms`),Pn(wt,`${!this._config.stopAfter||this._config.stopAfter!==-1?`configured for stopped after ${this._config.stopAfter}ms`:"configured for never stopped"}`),ke(wt,"engine initialized")}get probes(){return this._probes}get isRunning(){return this._probes.some(s=>s.isRunning)}get isIdle(){return this._probes.every(s=>s.isIdle)}addNewProbe(s,i){if(!s)throw new Error("undefined peer connection");const l=Iv(s,i,this._config),a=new eE(l);return this._probes.push(a),ke(wt,`${this._probes.length} probes registered`),a}removeExistingProbe(s){if(!s)throw new Error("undefined probe");s.state===Ss.RUNNING&&s.stop(),this._probes=this._probes.filter(i=>s.id!==i.id)}async start(){const s=()=>{this._probes.forEach(_=>_.start())},i=async()=>Promise.all(this._probes.map(_=>_.takeReferenceStats())),l=()=>this.isIdle?!1:!this._config.stopAfter||this._config.stopAfter<0?!0:Date.now()<this._startedTime+this._config.stopAfter,a=async()=>{const _=Av(),e=this._probes.filter(p=>p.isRunning);for(const p of e){const g=await p.collectStats();g&&_.probes.push(g),ke(wt,`got probe ${p.id}`),await kf(0)}return _.delta_time_to_measure_probes_ms=wn(_.probes,"experimental","time_to_measure_ms"),_.delta_KBytes_in=wn(_.probes,"data","delta_KBytes_in"),_.delta_KBytes_out=wn(_.probes,"data","delta_KBytes_out"),_.delta_kbs_in=wn(_.probes,"data","delta_kbs_in"),_.delta_kbs_out=wn(_.probes,"data","delta_kbs_out"),_.total_time_decoded_in=wn(_.probes,"video","total_time_decoded_in"),_.total_time_encoded_out=wn(_.probes,"video","total_time_encoded_out"),_};for(ke(wt,"starting to collect"),s(),ke(wt,"generating reference reports..."),await i(),ke(wt,"reference reports generated"),this._startedTime=Date.now();l();)if(ke(wt,`wait ${this._config.refreshEvery}ms before collecting`),await kf(this._config.refreshEvery),l()){ke(wt,"collecting...");const _=Date.now(),e=await a(),p=Date.now();e.delta_time_consumed_to_measure_ms=p-_,this.fireOnReports(e),ke(wt,"collected")}ke(wt,"reaching end of the collecting period..."),this.isRunning&&setTimeout(()=>{this.stop()},0)}stop(s){const i=l=>{this._probes.forEach(a=>{a.stop(l)})};Pn(wt,"stop collecting"),i(s)}registerCallback(s,i,l){s in this._callbacks?(this._callbacks[s]={callback:i,context:l},ke(wt,`registered callback '${s}'`)):ir(wt,`can't register callback for '${s}' - not found`)}unregisterCallback(s){s in this._callbacks?(this._callbacks[s]=null,delete this._callbacks[s],ke(this._moduleName,`unregistered callback '${s}'`)):ir(this._moduleName,`can't unregister callback for '${s}' - not found`)}fireOnReports(s){this._callbacks.onresult&&s.probes.length>0&&wu(this._callbacks.onresult.callback,this._callbacks.onresult.context,s)}}const sE="interface ";class nE{constructor(s){this._config=bv(s),Pn(sE,`welcome to ${this._config.name} version ${this._config.version}`),pv(this._config.verbose||!1),this._engine=new tE(this._config)}setupLogLevel(s){mv(s)}get version(){return this._config.version}get name(){return this._config.name}get probes(){return this._engine.probes}createProbe(s,i){return this._engine.addNewProbe(s,i)}startAllProbes(){this._engine.start()}stopAllProbes(){this._engine.stop()}get running(){return this._engine.isRunning}get idle(){return this._engine.isIdle}removeProbe(s){this._engine.removeExistingProbe(s)}set onresult(s){s?this._engine.registerCallback("onresult",s):this._engine.unregisterCallback("onresult")}}function rE(c,s){return Object.keys(c).filter(i=>s.includes(i)).reduce((i,l)=>{const a=l;return{...i,[a]:c[a]}},{})}const iE=["mos_in","codec_in","delta_KBytes_in","delta_kbs_in","delta_jitter_ms_in","delta_packets_lost_in"];class lE{constructor(s){this.intervals={},this.emitInterval=s.emitInterval||200,this.onChangeFunction=s.onChangeFunction}start(s,i){s&&s.getTracks().length&&requestAnimationFrame(()=>this.beginCalculation(s,i))}stop(s){this.clearVolumeInterval(s)}clearVolumeInterval(s){console.log("clearVolumeInterval",s),clearInterval(this.intervals[s]),delete this.intervals[s]}clearAllIntervals(){Object.keys(this.intervals).forEach(s=>{clearInterval(this.intervals[s])}),this.intervals={}}beginCalculation(s,i){this.clearVolumeInterval(i);const l=Un.createAnalyser(),a=Un.createMediaStreamSource(s),_=Un.createScriptProcessor(2048,1,1);l.smoothingTimeConstant=.8,l.fftSize=1024,a.connect(l),l.connect(_),_.connect(Un.destination),this.intervals[i]=setInterval(()=>{const e=new Uint8Array(l.frequencyBinCount);l.getByteFrequencyData(e);let p=0;const g=e.length;for(let v=0;v<g;v++)p+=e[v];const n=p/g;this.onChangeFunction(i,n)},this.emitInterval)}}const Sa={SELECTED_INPUT_DEVICE:"OpensipsJSInputDevice",SELECTED_OUTPUT_DEVICE:"OpensipsJSOutputDevice"},aE=0;class oE{constructor(s){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=s,this.context.on(this.context.newRTCSessionEventName,this.newRTCSessionCallback.bind(this)),this.VUMeter=new lE({onChangeFunction:this.emitVolumeChange.bind(this)}),this.initializeMediaDevices()}get sipOptions(){return{...this.context.options.sipOptions,mediaConstraints:this.getUserMediaConstraints}}get currentActiveRoomId(){return this.currentActiveRoomIdValue}set currentActiveRoomId(s){this.currentActiveRoomIdValue=s,this.context.emit("currentActiveRoomChanged",s)}get autoAnswer(){return this.isAutoAnswer}get callAddingInProgress(){return this.isCallAddingInProgress}set callAddingInProgress(s){this.isCallAddingInProgress=s,this.context.emit("callAddingInProgressChanged",s)}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(s=>s.kind==="audioinput")}get getOutputDeviceList(){return this.availableMediaDevices.filter(s=>s.kind==="audiooutput")}get getUserMediaConstraints(){return O_()?{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(s){this.availableMediaDevices=s,this.context.emit("changeAvailableDeviceList",s)}async updateDeviceList(){await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);const s=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(s)}async initializeMediaDevices(){const s=localStorage.getItem(Sa.SELECTED_INPUT_DEVICE)||"default",i=localStorage.getItem(Sa.SELECTED_OUTPUT_DEVICE)||"default";try{const l=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints),a=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(a),await this.setMicrophone(s),await this.setSpeaker(i),navigator.mediaDevices.addEventListener("devicechange",async()=>{const _=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(_)}),l.getTracks().forEach(_=>_.stop())}catch(l){console.error(l)}}setCallTime(s){const i={...s};delete i.callId,this.callTime={...this.callTime,[s.callId]:i},this.context.emit("changeCallTime",this.callTime)}removeCallTime(s){const i={...this.callTime};delete i[s],this.callTime={...i},this.context.emit("changeCallTime",this.callTime)}setTimeInterval(s,i){this.timeIntervals={...this.timeIntervals,[s]:i}}removeTimeInterval(s){const i={...this.timeIntervals};i[s]&&(clearInterval(i[s]),delete i[s],this.timeIntervals={...i})}stopCallTimer(s){this.removeTimeInterval(s),this.removeCallTime(s)}emitVolumeChange(s,i){this.context.emit("changeCallVolume",{callId:s,volume:i})}setMetricsConfig(s){this.metricConfig={...this.metricConfig,...s}}sendDTMF(s,i){if(!/^[A-D0-9]+$/g.test(i))throw new Error("Not allowed character in DTMF input");this.extendedCalls[s].sendDTMF(i)}setIsMuted(s){this.muted=s,this.context.emit("changeIsMuted",s)}processMute(s){const i=this.currentActiveRoomId;this.setIsMuted(s),this.initialStreamValue.getTracks().forEach(l=>l.enabled=!s),this.roomReconfigure(i)}mute(){this.processMute(!0)}unmute(){this.processMute(!1)}async processHold({callId:s,toHold:i,automatic:l}){const a=this.extendedCalls[s];a._automaticHold=l??!1,await new Promise(p=>{const g=()=>{p()};i?a.hold({},g):a.unhold({},g)}),this.updateCall(a);const e=Object.values(this.extendedCalls).filter(p=>p.roomId===this.currentActiveRoomId&&(i?s!==p._id:!0));e.length>1&&await this.doConference(e)}holdCall(s,i=!1){return this.processHold({callId:s,automatic:i,toHold:!0})}unholdCall(s){return this.processHold({callId:s,toHold:!1})}cancelAllOutgoingUnanswered(){Object.values(this.getActiveCalls).filter(s=>s.direction==="outgoing"&&s.status===aE).forEach(s=>this.terminateCall(s._id))}answerCall(s){const i=this.extendedCalls[s];this.cancelAllOutgoingUnanswered(),i.answer(this.sipOptions),this.updateCall(i),this.setActiveRoom(i.roomId),i.connection.addEventListener("track",l=>{this.triggerAddStream(l,i)})}async moveCall(s,i){this.updateCallStatus({callId:s,isMoving:!0}),await this.processRoomChange({callId:s,roomId:i}),this.updateCallStatus({callId:s,isMoving:!1})}updateCall(s){this.activeCalls[s._id]=Uf(s),this.context.emit("changeActiveCalls",this.activeCalls)}updateRoom(s){const l={...this.activeRooms[s.roomId],...s};this.activeRooms={...this.activeRooms,[s.roomId]:{...l}},this.context.emit("updateRoom",{room:l,roomList:this.activeRooms})}hasAutoAnswerHeaders(s){const i=/answer-after=0/,a=s.request.getHeader("Call-Info");return a&&i.test(a)}addCall(s,i=!0){this.activeCalls={...this.activeCalls,[s._id]:Uf(s)},this.extendedCalls[s._id]=s,i&&this.context.emit("changeActiveCalls",this.activeCalls)}addCallStatus(s){this.callStatus={...this.callStatus,[s]:{isMoving:!1,isTransferring:!1,isMerging:!1}},this.context.emit("changeCallStatus",this.callStatus)}updateCallStatus(s){const l={...{...this.callStatus[s.callId]}};s.isMoving!==void 0&&(l.isMoving=s.isMoving),s.isTransferring!==void 0&&(l.isTransferring=s.isTransferring),s.isMerging!==void 0&&(l.isMerging=s.isMerging),this.callStatus={...this.callStatus,[s.callId]:{...l}},this.context.emit("changeCallStatus",this.callStatus)}removeCallStatus(s){const i={...this.callStatus};delete i[s],this.callStatus={...i},this.context.emit("changeCallStatus",this.callStatus)}addRoom(s){this.activeRooms={...this.activeRooms,[s.roomId]:s},this.context.emit("addRoom",{room:s,roomList:this.activeRooms})}getActiveStream(){const s=xf(this.initialStreamValue,this.microphoneInputLevel*2);return s.getTracks().forEach(i=>i.enabled=!this.isMuted),this.setActiveStream(s),s}async setMicrophone(s){if(!this.getInputDeviceList.find(({deviceId:l})=>l===s)||(this.setSelectedInputDevice(s),Object.keys(this.getActiveCalls).length===0))return;await this.setupStream();const i=Object.values(this.extendedCalls).filter(l=>l.roomId===this.currentActiveRoomId);i.length===1?Object.values(i).forEach(async l=>{const a=this.getActiveStream();l.connection.getSenders()[0].replaceTrack(a.getTracks()[0]),this.updateCall(l)}):await this.doConference(i)}setActiveStream(s){this.activeStream&&this.stopVUMeter("origin"),this.setupVUMeter(s,"origin"),this.activeStreamValue=s,this.context.emit("changeActiveStream",s)}async setSpeaker(s){if(!this.getOutputDeviceList.find(({deviceId:a})=>a===s))return;this.setSelectedOutputDevice(s);const i=Object.values(this.extendedCalls);if(i.length===0)return;const l=i.filter(a=>a.roomId===this.currentActiveRoomId);l.length===1?i.forEach(a=>{var _;(_=a.audioTag)==null||_.setSinkId(s),this.updateCall(a)}):await this.doConference(l)}removeRoom(s){const i={...this.activeRooms},l={...i[s]};delete i[s],this.activeRooms={...i},this.context.emit("removeRoom",{room:l,roomList:this.activeRooms})}deleteRoomIfEmpty(s){s!==void 0&&Object.values(this.extendedCalls).filter(i=>i.roomId===s).length===0&&(this.removeRoom(s),this.currentActiveRoomId===s&&(this.currentActiveRoomId=void 0))}checkInitialized(){if(!this.context.initialized)throw new Error("[OpenSIPSJS] You must call `start` method first!")}muteReconfigure(s){this.muted?s.mute({audio:!0}):s.unmute({audio:!0})}async roomReconfigure(s){var l;if(s===void 0)return;const i=Object.values(this.extendedCalls).filter(a=>a.roomId===s);if(this.currentActiveRoomId===s?i.forEach(a=>{a.audioTag&&(this.muteReconfigure(a),a.audioTag.muted=!1,this.updateCall(a))}):i.forEach(a=>{a.audioTag&&(a.audioTag.muted=!0,this.updateCall(a))}),i.length===0)this.deleteRoomIfEmpty(s);else if(i.length===1&&this.currentActiveRoomId!==s)i[0].isOnHold().local||await this.holdCall(i[0].id,!0);else if(i.length===1&&this.currentActiveRoomId===s){if(i[0].isOnHold().local&&i[0]._automaticHold&&await this.unholdCall(i[0].id),i[0].connection&&((l=i[0].connection)!=null&&l.getSenders()[0])){const a=this.getActiveStream();await i[0].connection.getSenders()[0].replaceTrack(a.getTracks()[0]),this.muteReconfigure(i[0])}}else i.length>1&&await this.doConference(i)}async doConference(s){const i=[];s.forEach(l=>{l!=null&&l.connection.getReceivers().forEach(a=>{i.push(a.track)})}),await hv.forEach(s,async l=>{var e;if(l==null)return;const a=new MediaStream,_=Un.createMediaStreamDestination();if(l.connection.getReceivers().forEach(p=>{i.forEach(g=>{a.addTrack(p.track),p.track.id!==g.id&&Un.createMediaStreamSource(new MediaStream([g])).connect(_)})}),s[0].roomId===this.currentActiveRoomId){const p=this.getActiveStream();Un.createMediaStreamSource(p).connect(_)}(e=l.connection)!=null&&e.getSenders()[0]&&(await l.connection.getSenders()[0].replaceTrack(_.stream.getTracks()[0]),this.muteReconfigure(l))})}processCallerMute(s,i){const l=this.extendedCalls[s];l&&l.connection.getReceivers().length&&(l.localMuted=i,l.connection.getReceivers().forEach(a=>{a.track.enabled=!i}),this.updateCall(l))}muteCaller(s){this.processCallerMute(s,!0)}unmuteCaller(s){this.processCallerMute(s,!1)}terminateCall(s){const i=this.extendedCalls[s];i._status!==8&&i.terminate()}transferCall(s,i){if(i.toString().length===0)return new Error("Target must be passed");const l=this.extendedCalls[s];if(!l._is_confirmed&&!l._is_canceled){const a=`sip:${i}@${this.context.sipDomain}`;l.terminate({status_code:302,reason_phrase:"Moved Temporarily",extraHeaders:[`Contact: ${a}`]});return}this.updateCallStatus({callId:s,isTransferring:!0}),l.refer(`sip:${i}@${this.context.sipDomain}`),this.updateCall(l)}mergeCall(s){const i=Object.values(this.extendedCalls).filter(_=>_.roomId===s);if(i.length!==2)return;const l=i[0],a=i[1];!l||!a||(this.updateCallStatus({callId:l._id,isMerging:!0}),this.updateCallStatus({callId:a._id,isMerging:!0}),l.refer(a.remote_identity.uri.toString(),{replaces:a}),this.updateCall(l))}mergeCallByIds(s,i){const l=Object.values(this.extendedCalls).find(_=>_._id===s),a=Object.values(this.extendedCalls).find(_=>_._id===i);if(!l||!a)throw new Error("Call ID is not provided");this.updateCallStatus({callId:s,isMerging:!0}),this.updateCallStatus({callId:i,isMerging:!0}),l.refer(a.remote_identity.uri.toString(),{replaces:a}),this.updateCall(l)}setDND(s){this.isDNDEnabled=s,this.context.emit("changeIsDND",s)}startCallTimer(s){this.removeTimeInterval(s);const i={callId:s,hours:0,minutes:0,seconds:0,formatted:""};this.setCallTime(i);const l=setInterval(()=>{const a={...this.callTime[s]},_=cv(a);this.setCallTime({callId:s,..._})},1e3);this.setTimeInterval(s,l)}async setActiveRoom(s){const i=this.currentActiveRoomId;s!==i&&(this.currentActiveRoomId=s,await this.roomReconfigure(i),await this.roomReconfigure(s))}getNewRoomId(){const s=Object.keys(this.activeRooms);return s.length===0?1:parseInt(s.sort()[s.length-1])+1}async setupCall(s){var n,v;const i=s.session;if(this.getActiveCalls[i.id]!==void 0)return;const a=this.getNewRoomId(),_={started:new Date,incomingInProgress:!1,roomId:a};i.direction==="incoming"?(this.context.logger.log("New incoming call from",(v=(n=i._remote_identity)==null?void 0:n._uri)==null?void 0:v._user),_.incomingInProgress=!0,this.context.subscribe(Xt.CALL_CONFIRMED,S=>{i.id===S.id&&(this.updateRoom({incomingInProgress:!1,roomId:a}),this.startCallTimer(i.id))}),this.context.subscribe(Xt.CALL_FAILED,S=>{i.id===S.id&&(this.updateRoom({incomingInProgress:!1,roomId:a}),this.deleteRoomIfEmpty(a))})):i.direction==="outgoing"&&(i.once("confirmed",()=>{this.startCallTimer(i.id)}),this.startCallTimer(i.id));const e=i,p=this.hasAutoAnswerHeaders(s),g=e.direction==="incoming"&&!this.hasActiveCalls&&(p||this.autoAnswer);e.roomId=a,e.localMuted=!1,e.autoAnswer=g,g?this.addCall(e,!1):this.addCall(e),this.addCallStatus(i.id),this.addRoom(_),g&&this.answerCall(e._id)}removeCall(s){const i={...this.activeCalls};delete i[s],this.activeCalls={...i};const l={...this.extendedCalls};delete l[s],this.extendedCalls={...l},this.context.emit("changeActiveCalls",this.activeCalls)}activeCallListRemove(s){var a;const i=this.extendedCalls[s._id];this.stopVUMeter("origin"),(a=i.connection)==null||a.getSenders().forEach(_=>{_.track.stop()});const l=i.roomId;this.removeCall(s._id),this.roomReconfigure(l)}async newRTCSessionCallback(s){const i=s.session;if(this.isDND){i.terminate({status_code:486,reason_phrase:"Do Not Disturb"});return}if(this.context.triggerListener({listenerType:Xt.NEW_CALL,session:i,event:s}),i.on("ended",l=>{var _,e,p;this.stopVUMeter(i.id),this.context.logger.log("Session ended for",(e=(_=i._remote_identity)==null?void 0:_._uri)==null?void 0:e._user),this.context.triggerListener({listenerType:Xt.CALL_ENDED,session:i,event:l});const a=this.getActiveCalls[i.id];a&&this.activeCallListRemove(a),this.stopCallTimer(i.id),this.removeCallStatus(i.id),this.removeCallMetrics(i.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(p=this.initialStreamValue)==null||p.getTracks().forEach(g=>g.stop()),this.initialStreamValue=null)}),i.on("progress",l=>{var a,_;this.context.logger.log("Session in progress for",(_=(a=i._remote_identity)==null?void 0:a._uri)==null?void 0:_._user),this.context.triggerListener({listenerType:Xt.CALL_PROGRESS,session:i,event:l})}),i.on("failed",l=>{var _,e,p;this.stopVUMeter(i.id),this.context.logger.log("Session failed for",(e=(_=i._remote_identity)==null?void 0:_._uri)==null?void 0:e._user),this.context.triggerListener({listenerType:Xt.CALL_FAILED,session:i,event:l}),i.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0);const a=this.getActiveCalls[i.id];a&&this.activeCallListRemove(a),this.stopCallTimer(i.id),this.removeCallStatus(i.id),this.removeCallMetrics(i.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(p=this.initialStreamValue)==null||p.getTracks().forEach(g=>g.stop()),this.initialStreamValue=null)}),i.on("confirmed",l=>{var a,_;this.context.logger.log("Session confirmed for",(_=(a=i._remote_identity)==null?void 0:a._uri)==null?void 0:_._user),this.context.triggerListener({listenerType:Xt.CALL_CONFIRMED,session:i,event:l}),this.updateCall(i),i.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0)}),await this.setupCall(s),i.direction==="outgoing"){const l=this.getActiveCalls[i.id].roomId;this.setActiveRoom(l)}}setMuteWhenJoin(s){this.muteWhenJoinEnabled=s,this.context.emit("changeMuteWhenJoin",s)}setMicrophoneSensitivity(s){if(s<0||s>1)throw new Error("Value should be in range from 0 to 1!");this.microphoneInputLevelValue=s,this.roomReconfigure(this.currentActiveRoomId)}setSpeakerVolume(s){this.speakerVolumeValue=s,Object.values(this.extendedCalls).forEach(i=>{i.audioTag&&(i.audioTag.volume=s,this.updateCall(i))})}setAutoAnswer(s){this.isAutoAnswer=s}setSelectedInputDevice(s){localStorage.setItem(Sa.SELECTED_INPUT_DEVICE,s),this.selectedMediaDevices.input=s,this.context.emit("changeActiveInputMediaDevice",s)}setSelectedOutputDevice(s){localStorage.setItem(Sa.SELECTED_OUTPUT_DEVICE,s),this.selectedMediaDevices.output=s,this.context.emit("changeActiveOutputMediaDevice",s)}setCallMetrics(s){const i={...s};delete i.callId,this.callMetrics={...this.callMetrics,[s.callId]:i},this.context.emit("changeCallMetrics",this.callMetrics)}removeCallMetrics(s){const i={...this.callMetrics};delete i[s],this.callMetrics={...i},this.context.emit("changeCallMetrics",this.callMetrics)}getCallQuality(s){const i=new nE(this.metricConfig),l=i.createProbe(s.connection,{cid:s._id}),a=[];let _;l.onreport=e=>{Object.entries(e.audio).forEach(([n,v])=>{v.direction==="inbound"&&!a.includes(n)&&(a.push(n),_=n)});const p=e.audio[_];if(!p)return;const g=rE(p,iE);g.callId=s._id,this.setCallMetrics(g)},this.context.subscribe(Xt.CALL_ENDED,e=>{e._id===s._id&&i.stopAllProbes()}),i.startAllProbes()}setupVUMeter(s,i){this.VUMeter.start(s,i)}stopVUMeter(s){this.VUMeter.stop(s)}async setupStream(){const s=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);this.initialStreamValue&&(this.initialStreamValue.getTracks().forEach(i=>i.stop()),this.initialStreamValue=null),this.initialStreamValue=s}async triggerAddStream(s,i){this.setIsMuted(this.muteWhenJoin||this.isMuted),this.initialStreamValue||await this.setupStream();const l=xf(this.initialStreamValue,this.microphoneInputLevel*2),a=this.isMuted||this.muteWhenJoin;l.getTracks().forEach(e=>e.enabled=!a),this.setActiveStream(l),await i.connection.getSenders()[0].replaceTrack(l.getTracks()[0]);const _=new MediaStream([s.track]);YT(_,i,this.selectedOutputDevice,this.speakerVolume),this.setupVUMeter(_,i._id),this.getCallQuality(i),this.updateCall(i)}initCall(s,i){if(s.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${s}@${this.context.sipDomain}...`);const l=this.context.call(`sip:${s}@${this.context.sipDomain}`,this.sipOptions);this.callAddingInProgress=l.id,i&&this.currentActiveRoomId!==void 0&&this.processRoomChange({callId:l.id,roomId:this.currentActiveRoomId}),l.connection.addEventListener("track",a=>{this.triggerAddStream(a,l)})}async processRoomChange({callId:s,roomId:i}){const l=this.extendedCalls[s].roomId;this.extendedCalls[s].roomId=i;const a=this.extendedCalls[s];return this.updateCall(a),await this.setActiveRoom(i),Promise.all([this.roomReconfigure(l),this.roomReconfigure(i)]).then(()=>{this.deleteRoomIfEmpty(l),this.deleteRoomIfEmpty(i)})}}class uE{constructor(s){this.context=s}get sipOptions(){return{...this.context.options.sipOptions}}initCall(s,i){if(s.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${s}@${this.context.sipDomain}...`),this.context.joinVideoCall(`sip:${s}@${this.context.sipDomain}`,i,this.sipOptions)}stop(s={}){this.context.terminateJanusSessions(s)}}class cE{constructor(s){this.activeMessages={},this.extendedMessages={},this.msrpHistory={},this.context=s,this.context.on(this.context.newMSRPSessionEventName,this.newMSRPSessionCallback.bind(this.context))}get isMSRPInitializing(){return this.isMSRPInitializingValue}get getActiveMessages(){return this.activeMessages}msrpAnswer(s){const i=this.extendedMessages[s];this.updateMSRPSession(i)}updateMSRPSession(s){this.activeMessages[s._id]=Pf(s),this.context.emit("changeActiveMessages",this.activeMessages)}addMMSRPSession(s){this.activeMessages={...this.activeMessages,[s._id]:Pf(s)},this.extendedMessages[s._id]=s,this.context.emit("changeActiveMessages",this.activeMessages)}addMSRPMessage(s,i){const l=this.msrpHistory[i.id]||[];l.push(s),this.msrpHistory={...this.msrpHistory,[i.id]:[...l]},this.context.emit("newMSRPMessage",{message:s,session:i})}messageTerminate(s){const i=this.extendedMessages[s];i._status!==8&&i.terminate()}addMessageSession(s){if(!s._id||this.getActiveMessages[s._id]!==void 0)return;const l=s;this.addMMSRPSession(l)}triggerMSRPListener({listenerType:s,session:i,event:l}){const a=this.context.listenersList[s];!a||!a.length||a.forEach(_=>{_(i,l)})}removeMMSRPSession(s){const i={...this.activeMessages};delete i[s],this.activeMessages={...i};const l={...this.extendedMessages};delete l[s],this.extendedMessages={...l},this.context.emit("changeActiveMessages",this.activeMessages)}activeMessageListRemove(s){this.removeMMSRPSession(s._id)}newMSRPSessionCallback(s){const i=s.session;i.on("ended",l=>{this.triggerMSRPListener({listenerType:Xt.CALL_ENDED,session:i,event:l});const a=this.getActiveMessages[i.id];this.activeMessageListRemove(a)}),i.on("failed",l=>{this.triggerMSRPListener({listenerType:Xt.CALL_FAILED,session:i,event:l});const a=this.getActiveMessages[i.id];this.activeMessageListRemove(a)}),i.on("confirmed",l=>{this.triggerMSRPListener({listenerType:Xt.CALL_CONFIRMED,session:i,event:l}),this.updateMSRPSession(i)}),i.on("newMessage",l=>{this.addMSRPMessage(l,i)}),this.addMessageSession(i)}setIsMSRPInitializing(s){this.isMSRPInitializingValue=s,this.context.emit("isMSRPInitializingChanged",s)}initMSRP(s,i,l){if(s.length===0)return console.error("Target must be a valid string");const a=this.context.startMSRP(s,l);a.on("active",()=>{this.addMessageSession(a),a.sendMSRP(i),this.setIsMSRPInitializing(!1)}),this.setIsMSRPInitializing(!0)}sendMSRP(s,i){const l=this.extendedMessages[s];if(!l)throw new Error(`MSRP session with id ${s} doesn't exist!`);l.sendMSRP(i)}}const ou={AUDIO:"audio",VIDEO:"video",MSRP:"msrp"};class fE extends jT{constructor(s,i){if(!s.modules.length)throw new Error("options.modules should include at least 1 module");const l={...s.configuration,sockets:s.socketInterfaces.map(a=>new uv.WebSocketInterface(a))};super(l),this.initialized=!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.audio=null,this.msrp=null,this.video=null,this.listenersList={},this.modules=[],s.pnExtraHeaders&&Object.keys(s.pnExtraHeaders).length&&this.registrator().setExtraContactUriParams(s.pnExtraHeaders),this.options=s,this.modules=s.modules,i&&JT(i)&&(this.logger=i)}on(s,i){return super.on(s,i)}off(s,i){return super.off(s,i)}emit(s,i){return super.emit(s,i)}get sipDomain(){return this.options.sipDomain}begin(){if(this.isConnected()){console.error("Connection is already established");return}return this.modules.includes(ou.AUDIO)&&(this.audio=new oE(this)),this.modules.includes(ou.MSRP)&&(this.msrp=new cE(this)),this.modules.includes(ou.VIDEO)&&(this.video=new uE(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.isReconnecting=!1}),this.on(this.disconnectedEventName,()=>{this.isReconnecting||(this.logger.log("Disconnected from",this.options.socketInterfaces[0]),this.logger.log("Reconnecting to",this.options.socketInterfaces[0]),this.isReconnecting=!0,this.stop(),this.setInitialized(!1),setTimeout(this.start.bind(this),5e3))}),this.logger.log("Connecting to",this.options.socketInterfaces[0]),this.start(),this}subscribe(s,i){const a=!this.listenersList[s]||!this.listenersList[s].length?[i]:[...this.listenersList[s],i];this.listenersList={...this.listenersList,[s]:a}}removeIListener(s){const i={...this.listenersList};delete i[s],this.listenersList={...i}}triggerListener({listenerType:s,session:i,event:l}){const a=this.listenersList[s];!a||!a.length||a.forEach(_=>{_(i,l)})}setInitialized(s){this.initialized=s,this.emit("ready",s)}}module.exports=fE;