@voicenter-team/opensips-js 1.0.143 → 1.0.145
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/opensips-js.cjs.js +27 -27
- package/dist/opensips-js.es.js +515 -515
- package/dist/opensips-js.iife.js +24 -24
- package/dist/opensips-js.umd.js +24 -24
- package/package.json +1 -1
package/dist/opensips-js.cjs.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
"use strict";var Hh=Object.defineProperty;var Fh=(c,t,n)=>t in c?Hh(c,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):c[t]=n;var Kt=(c,t,n)=>(Fh(c,typeof t!="symbol"?t+"":t,n),n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var jh=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ze(c){return c&&c.__esModule&&Object.prototype.hasOwnProperty.call(c,"default")?c.default:c}const qh="jssip",Vh="JsSIP",Bh="the Javascript SIP library",Gh="3.10.0",Wh="https://jssip.net",Kh=["José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)","Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)"],Yh="lib/JsSIP.d.ts",Jh="lib-es5/JsSIP.js",zh=["sip","websocket","webrtc","node","browser","library"],Xh="MIT",Qh={type:"git",url:"https://github.com/versatica/JsSIP.git"},Zh={url:"https://github.com/versatica/JsSIP/issues"},ed={"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},td={"@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"},sd={lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"},Fa={name:qh,title:Vh,description:Bh,version:Gh,homepage:Wh,contributors:Kh,types:Yh,main:Jh,keywords:zh,license:Xh,repository:Qh,bugs:Zh,dependencies:ed,devDependencies:td,scripts:sd};var Gu=Fa,lt={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 ma(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?ma=function(n){return typeof n}:ma=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},ma(c)}function ja(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function qa(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&Zi(c,t)}function Va(c){var t=qf();return function(){var a=el(c),o;if(t){var s=el(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return nd(this,o)}}function nd(c,t){return t&&(ma(t)==="object"||typeof t=="function")?t:rd(c)}function rd(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function mr(c){var t=typeof Map=="function"?new Map:void 0;return mr=function(a){if(a===null||!id(a))return a;if(typeof a!="function")throw new TypeError("Super expression must either be null or a function");if(typeof t<"u"){if(t.has(a))return t.get(a);t.set(a,o)}function o(){return ga(a,arguments,el(this).constructor)}return o.prototype=Object.create(a.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),Zi(o,a)},mr(c)}function ga(c,t,n){return qf()?ga=Reflect.construct:ga=function(o,s,r){var d=[null];d.push.apply(d,s);var h=Function.bind.apply(o,d),_=new h;return r&&Zi(_,r.prototype),_},ga.apply(null,arguments)}function qf(){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 id(c){return Function.toString.call(c).indexOf("[native code]")!==-1}function Zi(c,t){return Zi=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},Zi(c,t)}function el(c){return el=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},el(c)}var ld=function(c){qa(n,c);var t=Va(n);function n(a,o){var s;return ja(this,n),s=t.call(this),s.code=1,s.name="CONFIGURATION_ERROR",s.parameter=a,s.value=o,s.message=s.value?"Invalid value ".concat(JSON.stringify(s.value),' for parameter "').concat(s.parameter,'"'):"Missing parameter: ".concat(s.parameter),s}return n}(mr(Error)),ad=function(c){qa(n,c);var t=Va(n);function n(a){var o;return ja(this,n),o=t.call(this),o.code=2,o.name="INVALID_STATE_ERROR",o.status=a,o.message="Invalid status: ".concat(a),o}return n}(mr(Error)),od=function(c){qa(n,c);var t=Va(n);function n(a){var o;return ja(this,n),o=t.call(this),o.code=3,o.name="NOT_SUPPORTED_ERROR",o.message=a,o}return n}(mr(Error)),ud=function(c){qa(n,c);var t=Va(n);function n(a){var o;return ja(this,n),o=t.call(this),o.code=4,o.name="NOT_READY_ERROR",o.message=a,o}return n}(mr(Error)),Ws={ConfigurationError:ld,InvalidStateError:ad,NotSupportedError:od,NotReadyError:ud},Ze={},fo,Wu;function Ou(){if(Wu)return fo;Wu=1;function c(s,r){if(!(s instanceof r))throw new TypeError("Cannot call a class as a function")}function t(s,r){for(var d=0;d<r.length;d++){var h=r[d];h.enumerable=h.enumerable||!1,h.configurable=!0,"value"in h&&(h.writable=!0),Object.defineProperty(s,h.key,h)}}function n(s,r,d){return r&&t(s.prototype,r),d&&t(s,d),s}var a=Ks(),o=os();return fo=function(){n(s,null,[{key:"parse",value:function(d){if(d=o.parse(d,"Name_Addr_Header"),d!==-1)return d}}]);function s(r,d,h){if(c(this,s),!r||!(r instanceof a))throw new TypeError('missing or invalid "uri" parameter');this._uri=r,this._parameters={},this.display_name=d;for(var _ in h)Object.prototype.hasOwnProperty.call(h,_)&&this.setParam(_,h[_])}return n(s,[{key:"setParam",value:function(d,h){d&&(this._parameters[d.toLowerCase()]=typeof h>"u"||h===null?null:h.toString())}},{key:"getParam",value:function(d){if(d)return this._parameters[d.toLowerCase()]}},{key:"hasParam",value:function(d){if(d)return this._parameters.hasOwnProperty(d.toLowerCase())&&!0||!1}},{key:"deleteParam",value:function(d){if(d=d.toLowerCase(),this._parameters.hasOwnProperty(d)){var h=this._parameters[d];return delete this._parameters[d],h}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"clone",value:function(){return new s(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}},{key:"_quote",value:function(d){return d.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}},{key:"toString",value:function(){var d=this._display_name?'"'.concat(this._quote(this._display_name),'" '):"";d+="<".concat(this._uri.toString(),">");for(var h in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,h)&&(d+=";".concat(h),this._parameters[h]!==null&&(d+="=".concat(this._parameters[h])));return d}},{key:"uri",get:function(){return this._uri}},{key:"display_name",get:function(){return this._display_name},set:function(d){this._display_name=d===0?"0":d}}]),s}(),fo}var ho,Ku;function os(){return Ku||(Ku=1,ho=function(){function c(n){return'"'+n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var t={parse:function(a,o){var s={CRLF:g,DIGIT:T,ALPHA:E,HEXDIG:y,WSP:A,OCTET:C,DQUOTE:I,SP:H,HTAB:$,alphanum:oe,reserved:N,unreserved:j,mark:Se,escaped:ve,LWS:k,SWS:D,HCOLON:B,TEXT_UTF8_TRIM:V,TEXT_UTF8char:J,UTF8_NONASCII:F,UTF8_CONT:X,LHEX:U,token:P,token_nodot:se,separators:st,word:ee,STAR:W,SLASH:G,EQUAL:re,LPAREN:ge,RPAREN:be,RAQUOT:xe,LAQUOT:Ce,COMMA:le,SEMI:ye,COLON:nt,LDQUOT:at,RDQUOT:Ee,comment:Ae,ctext:Ie,quoted_string:Oe,quoted_string_clean:pe,qdtext:ue,quoted_pair:_e,SIP_URI_noparams:we,SIP_URI:Ne,uri_scheme:Qe,uri_scheme_sips:Le,uri_scheme_sip:Lt,userinfo:dt,user:wn,user_unreserved:On,password:Ys,hostport:es,host:us,hostname:Js,domainlabel:Dn,toplabel:Nn,IPv6reference:zs,IPv6address:me,h16:ae,ls32:ot,IPv4address:Wt,dec_octet:Cs,port:Er,uri_parameters:Un,uri_parameter:Pn,transport_param:Sr,user_param:yr,method_param:Ar,ttl_param:Cr,maddr_param:Rr,lr_param:Ir,other_param:br,pname:wr,pvalue:Rs,paramchar:Is,param_unreserved:Or,headers:Xs,header:Qs,hname:Dr,hvalue:bs,hnv_unreserved:Zs,Request_Response:gl,Request_Line:Nr,Request_URI:xn,absoluteURI:kn,hier_part:Ur,net_path:en,abs_path:tn,opaque_part:ws,uric:Os,uric_no_slash:Pr,path_segments:sn,segment:Ds,param:cs,pchar:Ns,scheme:xr,authority:kr,srvr:Mr,reg_name:Lr,query:Mn,SIP_Version:Ln,INVITEm:$r,ACKm:Hr,OPTIONSm:Fr,BYEm:jr,CANCELm:qr,REGISTERm:Vr,SUBSCRIBEm:Br,NOTIFYm:Gr,REFERm:nn,Method:rn,Status_Line:Wr,Status_Code:Kr,extension_code:Yr,Reason_Phrase:Tl,Allow_Events:Ja,Call_ID:za,Contact:$n,contact_param:$t,name_addr:Ht,display_name:Us,contact_params:Hn,c_p_q:Jr,c_p_expires:ts,delta_seconds:ss,qvalue:Ge,generic_param:We,gen_value:vl,Content_Disposition:El,disp_type:Fn,disp_param:jn,handling_param:Sl,Content_Encoding:Xa,Content_Length:Qa,Content_Type:yl,media_type:zr,m_type:Xr,discrete_type:Qr,composite_type:ln,extension_token:an,x_token:Zr,m_subtype:qn,m_parameter:Vn,m_value:Al,CSeq:Cl,CSeq_value:Rl,Expires:Za,Event:on,event_type:un,From:ei,from_param:cn,tag_param:ti,Max_Forwards:eo,Min_Expires:to,Name_Addr_Header:so,Proxy_Authenticate:si,challenge:Bn,other_challenge:Ps,auth_param:ns,digest_cln:fn,realm:ni,realm_value:ri,domain:hn,URI:dn,nonce:ii,nonce_value:li,opaque:ai,stale:oi,algorithm:ui,qop_options:_n,qop_value:Gn,Proxy_Require:no,Record_Route:Wn,rec_route:Kn,Reason:ci,reason_param:Yn,reason_cause:Il,Require:ro,Route:Jn,route_param:zn,Subscription_State:bl,substate_value:Xn,subexp_params:Qn,event_reason_value:wl,Subject:io,Supported:lo,To:fi,to_param:hi,Via:Zn,via_param:xs,via_params:er,via_ttl:di,via_maddr:_i,via_received:pi,via_branch:mi,response_port:gi,rport:Ti,sent_protocol:vi,protocol_name:Ei,transport:Si,sent_by:yi,via_host:Ai,via_port:tr,ttl:Ci,WWW_Authenticate:ao,Session_Expires:Ol,s_e_expires:sr,s_e_params:nr,s_e_refresher:Dl,extension_header:Nl,header_value:Ul,message_body:oo,uuid_URI:Pl,uuid:Ft,hex4:jt,hex8:Ri,hex12:xl,Refer_To:uo,Replaces:kl,call_id:rr,replaces_param:ir,to_tag:Ii,from_tag:bi,early_flag:Ml};if(o!==void 0){if(s[o]===void 0)throw new Error("Invalid rule name: "+c(o)+".")}else o="CRLF";var r=0,d=0,h=[];function _(e){r<d||(r>d&&(d=r,h=[]),h.push(e))}function g(){var e;return a.substr(r,2)===`\r
|
1
|
+
"use strict";var Hh=Object.defineProperty;var Fh=(c,t,n)=>t in c?Hh(c,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):c[t]=n;var Kt=(c,t,n)=>(Fh(c,typeof t!="symbol"?t+"":t,n),n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var jh=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ze(c){return c&&c.__esModule&&Object.prototype.hasOwnProperty.call(c,"default")?c.default:c}const qh="jssip",Vh="JsSIP",Bh="the Javascript SIP library",Gh="3.10.0",Wh="https://jssip.net",Kh=["José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)","Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)"],Yh="lib/JsSIP.d.ts",Jh="lib-es5/JsSIP.js",zh=["sip","websocket","webrtc","node","browser","library"],Xh="MIT",Qh={type:"git",url:"https://github.com/versatica/JsSIP.git"},Zh={url:"https://github.com/versatica/JsSIP/issues"},ed={"@types/events":"^3.0.0","@types/debug":"^4.1.7",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},td={"@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"},sd={lint:"node npm-scripts.js lint",test:"node npm-scripts.js test",prepublish:"node npm-scripts.js prepublish",release:"node npm-scripts.js release"},Fa={name:qh,title:Vh,description:Bh,version:Gh,homepage:Wh,contributors:Kh,types:Yh,main:Jh,keywords:zh,license:Xh,repository:Qh,bugs:Zh,dependencies:ed,devDependencies:td,scripts:sd};var Gu=Fa,lt={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 ma(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?ma=function(n){return typeof n}:ma=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},ma(c)}function ja(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function qa(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&Zi(c,t)}function Va(c){var t=qf();return function(){var a=el(c),o;if(t){var s=el(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return nd(this,o)}}function nd(c,t){return t&&(ma(t)==="object"||typeof t=="function")?t:rd(c)}function rd(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function mr(c){var t=typeof Map=="function"?new Map:void 0;return mr=function(a){if(a===null||!id(a))return a;if(typeof a!="function")throw new TypeError("Super expression must either be null or a function");if(typeof t<"u"){if(t.has(a))return t.get(a);t.set(a,o)}function o(){return ga(a,arguments,el(this).constructor)}return o.prototype=Object.create(a.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),Zi(o,a)},mr(c)}function ga(c,t,n){return qf()?ga=Reflect.construct:ga=function(o,s,r){var d=[null];d.push.apply(d,s);var h=Function.bind.apply(o,d),_=new h;return r&&Zi(_,r.prototype),_},ga.apply(null,arguments)}function qf(){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 id(c){return Function.toString.call(c).indexOf("[native code]")!==-1}function Zi(c,t){return Zi=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},Zi(c,t)}function el(c){return el=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},el(c)}var ld=function(c){qa(n,c);var t=Va(n);function n(a,o){var s;return ja(this,n),s=t.call(this),s.code=1,s.name="CONFIGURATION_ERROR",s.parameter=a,s.value=o,s.message=s.value?"Invalid value ".concat(JSON.stringify(s.value),' for parameter "').concat(s.parameter,'"'):"Missing parameter: ".concat(s.parameter),s}return n}(mr(Error)),ad=function(c){qa(n,c);var t=Va(n);function n(a){var o;return ja(this,n),o=t.call(this),o.code=2,o.name="INVALID_STATE_ERROR",o.status=a,o.message="Invalid status: ".concat(a),o}return n}(mr(Error)),od=function(c){qa(n,c);var t=Va(n);function n(a){var o;return ja(this,n),o=t.call(this),o.code=3,o.name="NOT_SUPPORTED_ERROR",o.message=a,o}return n}(mr(Error)),ud=function(c){qa(n,c);var t=Va(n);function n(a){var o;return ja(this,n),o=t.call(this),o.code=4,o.name="NOT_READY_ERROR",o.message=a,o}return n}(mr(Error)),Ws={ConfigurationError:ld,InvalidStateError:ad,NotSupportedError:od,NotReadyError:ud},Ze={},fo,Wu;function Ou(){if(Wu)return fo;Wu=1;function c(s,r){if(!(s instanceof r))throw new TypeError("Cannot call a class as a function")}function t(s,r){for(var d=0;d<r.length;d++){var h=r[d];h.enumerable=h.enumerable||!1,h.configurable=!0,"value"in h&&(h.writable=!0),Object.defineProperty(s,h.key,h)}}function n(s,r,d){return r&&t(s.prototype,r),d&&t(s,d),s}var a=Ks(),o=os();return fo=function(){n(s,null,[{key:"parse",value:function(d){if(d=o.parse(d,"Name_Addr_Header"),d!==-1)return d}}]);function s(r,d,h){if(c(this,s),!r||!(r instanceof a))throw new TypeError('missing or invalid "uri" parameter');this._uri=r,this._parameters={},this.display_name=d;for(var _ in h)Object.prototype.hasOwnProperty.call(h,_)&&this.setParam(_,h[_])}return n(s,[{key:"setParam",value:function(d,h){d&&(this._parameters[d.toLowerCase()]=typeof h>"u"||h===null?null:h.toString())}},{key:"getParam",value:function(d){if(d)return this._parameters[d.toLowerCase()]}},{key:"hasParam",value:function(d){if(d)return this._parameters.hasOwnProperty(d.toLowerCase())&&!0||!1}},{key:"deleteParam",value:function(d){if(d=d.toLowerCase(),this._parameters.hasOwnProperty(d)){var h=this._parameters[d];return delete this._parameters[d],h}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"clone",value:function(){return new s(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}},{key:"_quote",value:function(d){return d.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}},{key:"toString",value:function(){var d=this._display_name?'"'.concat(this._quote(this._display_name),'" '):"";d+="<".concat(this._uri.toString(),">");for(var h in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,h)&&(d+=";".concat(h),this._parameters[h]!==null&&(d+="=".concat(this._parameters[h])));return d}},{key:"uri",get:function(){return this._uri}},{key:"display_name",get:function(){return this._display_name},set:function(d){this._display_name=d===0?"0":d}}]),s}(),fo}var ho,Ku;function os(){return Ku||(Ku=1,ho=function(){function c(n){return'"'+n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var t={parse:function(a,o){var s={CRLF:g,DIGIT:T,ALPHA:E,HEXDIG:y,WSP:C,OCTET:A,DQUOTE:I,SP:H,HTAB:$,alphanum:oe,reserved:N,unreserved:j,mark:Se,escaped:ve,LWS:k,SWS:D,HCOLON:B,TEXT_UTF8_TRIM:V,TEXT_UTF8char:J,UTF8_NONASCII:F,UTF8_CONT:X,LHEX:U,token:P,token_nodot:se,separators:st,word:ee,STAR:W,SLASH:G,EQUAL:re,LPAREN:ge,RPAREN:be,RAQUOT:xe,LAQUOT:Ae,COMMA:le,SEMI:ye,COLON:nt,LDQUOT:at,RDQUOT:Ee,comment:Ce,ctext:Ie,quoted_string:Oe,quoted_string_clean:pe,qdtext:ue,quoted_pair:_e,SIP_URI_noparams:we,SIP_URI:Ne,uri_scheme:Qe,uri_scheme_sips:Le,uri_scheme_sip:Lt,userinfo:dt,user:wn,user_unreserved:On,password:Ys,hostport:es,host:us,hostname:Js,domainlabel:Dn,toplabel:Nn,IPv6reference:zs,IPv6address:me,h16:ae,ls32:ot,IPv4address:Wt,dec_octet:As,port:Er,uri_parameters:Un,uri_parameter:Pn,transport_param:Sr,user_param:yr,method_param:Cr,ttl_param:Ar,maddr_param:Rr,lr_param:Ir,other_param:br,pname:wr,pvalue:Rs,paramchar:Is,param_unreserved:Or,headers:Xs,header:Qs,hname:Dr,hvalue:bs,hnv_unreserved:Zs,Request_Response:gl,Request_Line:Nr,Request_URI:xn,absoluteURI:kn,hier_part:Ur,net_path:en,abs_path:tn,opaque_part:ws,uric:Os,uric_no_slash:Pr,path_segments:sn,segment:Ds,param:cs,pchar:Ns,scheme:xr,authority:kr,srvr:Mr,reg_name:Lr,query:Mn,SIP_Version:Ln,INVITEm:$r,ACKm:Hr,OPTIONSm:Fr,BYEm:jr,CANCELm:qr,REGISTERm:Vr,SUBSCRIBEm:Br,NOTIFYm:Gr,REFERm:nn,Method:rn,Status_Line:Wr,Status_Code:Kr,extension_code:Yr,Reason_Phrase:Tl,Allow_Events:Ja,Call_ID:za,Contact:$n,contact_param:$t,name_addr:Ht,display_name:Us,contact_params:Hn,c_p_q:Jr,c_p_expires:ts,delta_seconds:ss,qvalue:Ge,generic_param:We,gen_value:vl,Content_Disposition:El,disp_type:Fn,disp_param:jn,handling_param:Sl,Content_Encoding:Xa,Content_Length:Qa,Content_Type:yl,media_type:zr,m_type:Xr,discrete_type:Qr,composite_type:ln,extension_token:an,x_token:Zr,m_subtype:qn,m_parameter:Vn,m_value:Cl,CSeq:Al,CSeq_value:Rl,Expires:Za,Event:on,event_type:un,From:ei,from_param:cn,tag_param:ti,Max_Forwards:eo,Min_Expires:to,Name_Addr_Header:so,Proxy_Authenticate:si,challenge:Bn,other_challenge:Ps,auth_param:ns,digest_cln:fn,realm:ni,realm_value:ri,domain:hn,URI:dn,nonce:ii,nonce_value:li,opaque:ai,stale:oi,algorithm:ui,qop_options:_n,qop_value:Gn,Proxy_Require:no,Record_Route:Wn,rec_route:Kn,Reason:ci,reason_param:Yn,reason_cause:Il,Require:ro,Route:Jn,route_param:zn,Subscription_State:bl,substate_value:Xn,subexp_params:Qn,event_reason_value:wl,Subject:io,Supported:lo,To:fi,to_param:hi,Via:Zn,via_param:xs,via_params:er,via_ttl:di,via_maddr:_i,via_received:pi,via_branch:mi,response_port:gi,rport:Ti,sent_protocol:vi,protocol_name:Ei,transport:Si,sent_by:yi,via_host:Ci,via_port:tr,ttl:Ai,WWW_Authenticate:ao,Session_Expires:Ol,s_e_expires:sr,s_e_params:nr,s_e_refresher:Dl,extension_header:Nl,header_value:Ul,message_body:oo,uuid_URI:Pl,uuid:Ft,hex4:jt,hex8:Ri,hex12:xl,Refer_To:uo,Replaces:kl,call_id:rr,replaces_param:ir,to_tag:Ii,from_tag:bi,early_flag:Ml};if(o!==void 0){if(s[o]===void 0)throw new Error("Invalid rule name: "+c(o)+".")}else o="CRLF";var r=0,d=0,h=[];function _(e){r<d||(r>d&&(d=r,h=[]),h.push(e))}function g(){var e;return a.substr(r,2)===`\r
|
2
2
|
`?(e=`\r
|
3
|
-
`,r+=2):(e=null,_('"\\r\\n"')),e}function T(){var e;return/^[0-9]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[0-9]")),e}function E(){var e;return/^[a-zA-Z]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[a-zA-Z]")),e}function y(){var e;return/^[0-9a-fA-F]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[0-9a-fA-F]")),e}function A(){var e;return e=H(),e===null&&(e=$()),e}function C(){var e;return/^[\0-\xFF]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\0-\\xFF]")),e}function I(){var e;return/^["]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_('["]')),e}function H(){var e;return a.charCodeAt(r)===32?(e=" ",r++):(e=null,_('" "')),e}function $(){var e;return a.charCodeAt(r)===9?(e=" ",r++):(e=null,_('"\\t"')),e}function oe(){var e;return/^[a-zA-Z0-9]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[a-zA-Z0-9]")),e}function N(){var e;return a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","'))))))))))),e}function j(){var e;return e=oe(),e===null&&(e=Se()),e}function Se(){var e;return a.charCodeAt(r)===45?(e="-",r++):(e=null,_('"-"')),e===null&&(a.charCodeAt(r)===95?(e="_",r++):(e=null,_('"_"')),e===null&&(a.charCodeAt(r)===46?(e=".",r++):(e=null,_('"."')),e===null&&(a.charCodeAt(r)===33?(e="!",r++):(e=null,_('"!"')),e===null&&(a.charCodeAt(r)===126?(e="~",r++):(e=null,_('"~"')),e===null&&(a.charCodeAt(r)===42?(e="*",r++):(e=null,_('"*"')),e===null&&(a.charCodeAt(r)===39?(e="'",r++):(e=null,_(`"'"`)),e===null&&(a.charCodeAt(r)===40?(e="(",r++):(e=null,_('"("')),e===null&&(a.charCodeAt(r)===41?(e=")",r++):(e=null,_('")"')))))))))),e}function ve(){var e,l,u,f,p;return f=r,p=r,a.charCodeAt(r)===37?(e="%",r++):(e=null,_('"%"')),e!==null?(l=y(),l!==null?(u=y(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){return v.join("")}(f,e)),e===null&&(r=f),e}function k(){var e,l,u,f,p,m;for(f=r,p=r,m=r,e=[],l=A();l!==null;)e.push(l),l=A();if(e!==null?(l=g(),l!==null?e=[e,l]:(e=null,r=m)):(e=null,r=m),e=e!==null?e:"",e!==null){if(u=A(),u!==null)for(l=[];u!==null;)l.push(u),u=A();else l=null;l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e!==null&&(e=function(v){return" "}()),e===null&&(r=f),e}function D(){var e;return e=k(),e=e!==null?e:"",e}function B(){var e,l,u,f,p;for(f=r,p=r,e=[],l=H(),l===null&&(l=$());l!==null;)e.push(l),l=H(),l===null&&(l=$());return e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return":"}()),e===null&&(r=f),e}function V(){var e,l,u,f,p,m,v;if(p=r,m=r,l=J(),l!==null)for(e=[];l!==null;)e.push(l),l=J();else e=null;if(e!==null){for(l=[],v=r,u=[],f=k();f!==null;)u.push(f),f=k();for(u!==null?(f=J(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;){for(l.push(u),v=r,u=[],f=k();f!==null;)u.push(f),f=k();u!==null?(f=J(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v)}l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){return a.substring(r,S)}(p)),e===null&&(r=p),e}function J(){var e;return/^[!-~]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[!-~]")),e===null&&(e=F()),e}function F(){var e;return/^[\x80-\uFFFF]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\x80-\\uFFFF]")),e}function X(){var e;return/^[\x80-\xBF]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\x80-\\xBF]")),e}function U(){var e;return e=T(),e===null&&(/^[a-f]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[a-f]"))),e}function P(){var e,l,u;if(u=r,l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"'))))))))))));else e=null;return e!==null&&(e=function(f){return a.substring(r,f)}(u)),e===null&&(r=u),e}function se(){var e,l,u;if(u=r,l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"'))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')))))))))));else e=null;return e!==null&&(e=function(f){return a.substring(r,f)}(u)),e===null&&(r=u),e}function st(){var e;return a.charCodeAt(r)===40?(e="(",r++):(e=null,_('"("')),e===null&&(a.charCodeAt(r)===41?(e=")",r++):(e=null,_('")"')),e===null&&(a.charCodeAt(r)===60?(e="<",r++):(e=null,_('"<"')),e===null&&(a.charCodeAt(r)===62?(e=">",r++):(e=null,_('">"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')),e===null&&(a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===92?(e="\\",r++):(e=null,_('"\\\\"')),e===null&&(e=I(),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e===null&&(a.charCodeAt(r)===93?(e="]",r++):(e=null,_('"]"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===123?(e="{",r++):(e=null,_('"{"')),e===null&&(a.charCodeAt(r)===125?(e="}",r++):(e=null,_('"}"')),e===null&&(e=H(),e===null&&(e=$())))))))))))))))))),e}function ee(){var e,l,u;if(u=r,l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')),l===null&&(a.charCodeAt(r)===40?(l="(",r++):(l=null,_('"("')),l===null&&(a.charCodeAt(r)===41?(l=")",r++):(l=null,_('")"')),l===null&&(a.charCodeAt(r)===60?(l="<",r++):(l=null,_('"<"')),l===null&&(a.charCodeAt(r)===62?(l=">",r++):(l=null,_('">"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===92?(l="\\",r++):(l=null,_('"\\\\"')),l===null&&(l=I(),l===null&&(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l===null&&(a.charCodeAt(r)===91?(l="[",r++):(l=null,_('"["')),l===null&&(a.charCodeAt(r)===93?(l="]",r++):(l=null,_('"]"')),l===null&&(a.charCodeAt(r)===63?(l="?",r++):(l=null,_('"?"')),l===null&&(a.charCodeAt(r)===123?(l="{",r++):(l=null,_('"{"')),l===null&&(a.charCodeAt(r)===125?(l="}",r++):(l=null,_('"}"'))))))))))))))))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')),l===null&&(a.charCodeAt(r)===40?(l="(",r++):(l=null,_('"("')),l===null&&(a.charCodeAt(r)===41?(l=")",r++):(l=null,_('")"')),l===null&&(a.charCodeAt(r)===60?(l="<",r++):(l=null,_('"<"')),l===null&&(a.charCodeAt(r)===62?(l=">",r++):(l=null,_('">"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===92?(l="\\",r++):(l=null,_('"\\\\"')),l===null&&(l=I(),l===null&&(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l===null&&(a.charCodeAt(r)===91?(l="[",r++):(l=null,_('"["')),l===null&&(a.charCodeAt(r)===93?(l="]",r++):(l=null,_('"]"')),l===null&&(a.charCodeAt(r)===63?(l="?",r++):(l=null,_('"?"')),l===null&&(a.charCodeAt(r)===123?(l="{",r++):(l=null,_('"{"')),l===null&&(a.charCodeAt(r)===125?(l="}",r++):(l=null,_('"}"')))))))))))))))))))))))));else e=null;return e!==null&&(e=function(f){return a.substring(r,f)}(u)),e===null&&(r=u),e}function W(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"*"}()),e===null&&(r=f),e}function G(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"/"}()),e===null&&(r=f),e}function re(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"="}()),e===null&&(r=f),e}function ge(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===40?(l="(",r++):(l=null,_('"("')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"("}()),e===null&&(r=f),e}function be(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===41?(l=")",r++):(l=null,_('")"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return")"}()),e===null&&(r=f),e}function xe(){var e,l,u,f;return u=r,f=r,a.charCodeAt(r)===62?(e=">",r++):(e=null,_('">"')),e!==null?(l=D(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return">"}()),e===null&&(r=u),e}function Ce(){var e,l,u,f;return u=r,f=r,e=D(),e!==null?(a.charCodeAt(r)===60?(l="<",r++):(l=null,_('"<"')),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return"<"}()),e===null&&(r=u),e}function le(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return","}()),e===null&&(r=f),e}function ye(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return";"}()),e===null&&(r=f),e}function nt(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return":"}()),e===null&&(r=f),e}function at(){var e,l,u,f;return u=r,f=r,e=D(),e!==null?(l=I(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return'"'}()),e===null&&(r=u),e}function Ee(){var e,l,u,f;return u=r,f=r,e=I(),e!==null?(l=D(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return'"'}()),e===null&&(r=u),e}function Ae(){var e,l,u,f;if(f=r,e=ge(),e!==null){for(l=[],u=Ie(),u===null&&(u=_e(),u===null&&(u=Ae()));u!==null;)l.push(u),u=Ie(),u===null&&(u=_e(),u===null&&(u=Ae()));l!==null?(u=be(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)}else e=null,r=f;return e}function Ie(){var e;return/^[!-']/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[!-']")),e===null&&(/^[*-[]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[*-[]")),e===null&&(/^[\]-~]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\]-~]")),e===null&&(e=F(),e===null&&(e=k())))),e}function Oe(){var e,l,u,f,p,m;if(p=r,m=r,e=D(),e!==null)if(l=I(),l!==null){for(u=[],f=ue(),f===null&&(f=_e());f!==null;)u.push(f),f=ue(),f===null&&(f=_e());u!==null?(f=I(),f!==null?e=[e,l,u,f]:(e=null,r=m)):(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e!==null&&(e=function(v){return a.substring(r,v)}(p)),e===null&&(r=p),e}function pe(){var e,l,u,f,p,m;if(p=r,m=r,e=D(),e!==null)if(l=I(),l!==null){for(u=[],f=ue(),f===null&&(f=_e());f!==null;)u.push(f),f=ue(),f===null&&(f=_e());u!==null?(f=I(),f!==null?e=[e,l,u,f]:(e=null,r=m)):(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e!==null&&(e=function(v){var S=a.substring(r,v).trim();return S.substring(1,S.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(p)),e===null&&(r=p),e}function ue(){var e;return e=k(),e===null&&(a.charCodeAt(r)===33?(e="!",r++):(e=null,_('"!"')),e===null&&(/^[#-[]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[#-[]")),e===null&&(/^[\]-~]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\]-~]")),e===null&&(e=F())))),e}function _e(){var e,l,u;return u=r,a.charCodeAt(r)===92?(e="\\",r++):(e=null,_('"\\\\"')),e!==null?(/^[\0-\t]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[\\0-\\t]")),l===null&&(/^[\x0B-\f]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[\\x0B-\\f]")),l===null&&(/^[\x0E-]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[\\x0E-]")))),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function we(){var e,l,u,f,p,m;return p=r,m=r,e=Qe(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=dt(),u=u!==null?u:"",u!==null?(f=es(),f!==null?e=[e,l,u,f]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e!==null&&(e=function(v){try{w.uri=new fs(w.scheme,w.user,w.host,w.port),delete w.scheme,delete w.user,delete w.host,delete w.host_type,delete w.port}catch{w=-1}}()),e===null&&(r=p),e}function Ne(){var e,l,u,f,p,m,v,S;return v=r,S=r,e=Qe(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=dt(),u=u!==null?u:"",u!==null?(f=es(),f!==null?(p=Un(),p!==null?(m=Xs(),m=m!==null?m:"",m!==null?e=[e,l,u,f,p,m]:(e=null,r=S)):(e=null,r=S)):(e=null,r=S)):(e=null,r=S)):(e=null,r=S)):(e=null,r=S),e!==null&&(e=function(O){try{w.uri=new fs(w.scheme,w.user,w.host,w.port,w.uri_params,w.uri_headers),delete w.scheme,delete w.user,delete w.host,delete w.host_type,delete w.port,delete w.uri_params,o==="SIP_URI"&&(w=w.uri)}catch{w=-1}}()),e===null&&(r=v),e}function Qe(){var e;return e=Le(),e===null&&(e=Lt()),e}function Le(){var e,l;return l=r,a.substr(r,4).toLowerCase()==="sips"?(e=a.substr(r,4),r+=4):(e=null,_('"sips"')),e!==null&&(e=function(u,f){w.scheme=f.toLowerCase()}(l,e)),e===null&&(r=l),e}function Lt(){var e,l;return l=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"sip"')),e!==null&&(e=function(u,f){w.scheme=f.toLowerCase()}(l,e)),e===null&&(r=l),e}function dt(){var e,l,u,f,p,m;return f=r,p=r,e=wn(),e!==null?(m=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=Ys(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?(a.charCodeAt(r)===64?(u="@",r++):(u=null,_('"@"')),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w.user=decodeURIComponent(a.substring(r-1,v))}(f)),e===null&&(r=f),e}function wn(){var e,l;if(l=j(),l===null&&(l=ve(),l===null&&(l=On())),l!==null)for(e=[];l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(l=On()));else e=null;return e}function On(){var e;return a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')),e===null&&(a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"'))))))))),e}function Ys(){var e,l,u;for(u=r,e=[],l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","'))))))));l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","'))))))));return e!==null&&(e=function(f){w.password=a.substring(r,f)}(u)),e===null&&(r=u),e}function es(){var e,l,u,f,p;return f=r,e=us(),e!==null?(p=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=Er(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function us(){var e,l;return l=r,e=Js(),e===null&&(e=Wt(),e===null&&(e=zs())),e!==null&&(e=function(u){return w.host=a.substring(r,u).toLowerCase(),w.host}(l)),e===null&&(r=l),e}function Js(){var e,l,u,f,p,m;for(f=r,p=r,e=[],m=r,l=Dn(),l!==null?(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m);l!==null;)e.push(l),m=r,l=Dn(),l!==null?(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m);return e!==null?(l=Nn(),l!==null?(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u=u!==null?u:"",u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){return w.host_type="domain",a.substring(r,v)}(f)),e===null&&(r=f),e}function Dn(){var e,l,u,f;if(f=r,e=oe(),e!==null){for(l=[],u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));u!==null;)l.push(u),u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));l!==null?e=[e,l]:(e=null,r=f)}else e=null,r=f;return e}function Nn(){var e,l,u,f;if(f=r,e=E(),e!==null){for(l=[],u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));u!==null;)l.push(u),u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));l!==null?e=[e,l]:(e=null,r=f)}else e=null,r=f;return e}function zs(){var e,l,u,f,p;return f=r,p=r,a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e!==null?(l=me(),l!==null?(a.charCodeAt(r)===93?(u="]",r++):(u=null,_('"]"')),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return w.host_type="IPv6",a.substring(r,m)}(f)),e===null&&(r=f),e}function me(){var e,l,u,f,p,m,v,S,O,ie,Ue,wt,ks,M,R,Te;return M=r,R=r,e=ae(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?(a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?(a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?(a.charCodeAt(r)===58?(S=":",r++):(S=null,_('":"')),S!==null?(O=ae(),O!==null?(a.charCodeAt(r)===58?(ie=":",r++):(ie=null,_('":"')),ie!==null?(Ue=ae(),Ue!==null?(a.charCodeAt(r)===58?(wt=":",r++):(wt=null,_('":"')),wt!==null?(ks=ot(),ks!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue,wt,ks]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?(a.charCodeAt(r)===58?(O=":",r++):(O=null,_('":"')),O!==null?(ie=ae(),ie!==null?(a.charCodeAt(r)===58?(Ue=":",r++):(Ue=null,_('":"')),Ue!==null?(wt=ot(),wt!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue,wt]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?(a.charCodeAt(r)===58?(O=":",r++):(O=null,_('":"')),O!==null?(ie=ot(),ie!==null?e=[e,l,u,f,p,m,v,S,O,ie]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ot(),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ot(),m!==null?e=[e,l,u,f,p,m]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ot(),f!==null?e=[e,l,u,f]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ot(),l!==null?e=[e,l]:(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?e=[e,l]:(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(a.substr(r,2)==="::"?(l="::",r+=2):(l=null,_('"::"')),l!==null?(u=ae(),u!==null?(a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?(a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?(a.charCodeAt(r)===58?(S=":",r++):(S=null,_('":"')),S!==null?(O=ae(),O!==null?(a.charCodeAt(r)===58?(ie=":",r++):(ie=null,_('":"')),ie!==null?(Ue=ot(),Ue!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(a.substr(r,2)==="::"?(u="::",r+=2):(u=null,_('"::"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?(a.charCodeAt(r)===58?(O=":",r++):(O=null,_('":"')),O!==null?(ie=ot(),ie!==null?e=[e,l,u,f,p,m,v,S,O,ie]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(a.substr(r,2)==="::"?(f="::",r+=2):(f=null,_('"::"')),f!==null?(p=ae(),p!==null?(a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?(a.charCodeAt(r)===58?(S=":",r++):(S=null,_('":"')),S!==null?(O=ot(),O!==null?e=[e,l,u,f,p,m,v,S,O]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(a.substr(r,2)==="::"?(p="::",r+=2):(p=null,_('"::"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ot(),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(Te=r,a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?p=[p,m]:(p=null,r=Te)):(p=null,r=Te),p=p!==null?p:"",p!==null?(a.substr(r,2)==="::"?(m="::",r+=2):(m=null,_('"::"')),m!==null?(v=ot(),v!==null?e=[e,l,u,f,p,m,v]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(Te=r,a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?p=[p,m]:(p=null,r=Te)):(p=null,r=Te),p=p!==null?p:"",p!==null?(Te=r,a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?m=[m,v]:(m=null,r=Te)):(m=null,r=Te),m=m!==null?m:"",m!==null?(a.substr(r,2)==="::"?(v="::",r+=2):(v=null,_('"::"')),v!==null?(S=ae(),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(Te=r,a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?p=[p,m]:(p=null,r=Te)):(p=null,r=Te),p=p!==null?p:"",p!==null?(Te=r,a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?m=[m,v]:(m=null,r=Te)):(m=null,r=Te),m=m!==null?m:"",m!==null?(Te=r,a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?v=[v,S]:(v=null,r=Te)):(v=null,r=Te),v=v!==null?v:"",v!==null?(a.substr(r,2)==="::"?(S="::",r+=2):(S=null,_('"::"')),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R))))))))))))))),e!==null&&(e=function($h){return w.host_type="IPv6",a.substring(r,$h)}(M)),e===null&&(r=M),e}function ae(){var e,l,u,f,p;return p=r,e=y(),e!==null?(l=y(),l=l!==null?l:"",l!==null?(u=y(),u=u!==null?u:"",u!==null?(f=y(),f=f!==null?f:"",f!==null?e=[e,l,u,f]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e}function ot(){var e,l,u,f;return f=r,e=ae(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e===null&&(e=Wt()),e}function Wt(){var e,l,u,f,p,m,v,S,O;return S=r,O=r,e=Cs(),e!==null?(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l!==null?(u=Cs(),u!==null?(a.charCodeAt(r)===46?(f=".",r++):(f=null,_('"."')),f!==null?(p=Cs(),p!==null?(a.charCodeAt(r)===46?(m=".",r++):(m=null,_('"."')),m!==null?(v=Cs(),v!==null?e=[e,l,u,f,p,m,v]:(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O),e!==null&&(e=function(ie){return w.host_type="IPv4",a.substring(r,ie)}(S)),e===null&&(r=S),e}function Cs(){var e,l,u,f;return f=r,a.substr(r,2)==="25"?(e="25",r+=2):(e=null,_('"25"')),e!==null?(/^[0-5]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[0-5]")),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e===null&&(f=r,a.charCodeAt(r)===50?(e="2",r++):(e=null,_('"2"')),e!==null?(/^[0-4]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[0-4]")),l!==null?(u=T(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e===null&&(f=r,a.charCodeAt(r)===49?(e="1",r++):(e=null,_('"1"')),e!==null?(l=T(),l!==null?(u=T(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e===null&&(f=r,/^[1-9]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[1-9]")),e!==null?(l=T(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e===null&&(e=T())))),e}function Er(){var e,l,u,f,p,m,v;return m=r,v=r,e=T(),e=e!==null?e:"",e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?e=[e,l,u,f,p]:(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(S,O){return O=parseInt(O.join("")),w.port=O,O}(m,e)),e===null&&(r=m),e}function Un(){var e,l,u,f;for(e=[],f=r,a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l!==null?(u=Pn(),u!==null?l=[l,u]:(l=null,r=f)):(l=null,r=f);l!==null;)e.push(l),f=r,a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l!==null?(u=Pn(),u!==null?l=[l,u]:(l=null,r=f)):(l=null,r=f);return e}function Pn(){var e;return e=Sr(),e===null&&(e=yr(),e===null&&(e=Ar(),e===null&&(e=Cr(),e===null&&(e=Rr(),e===null&&(e=Ir(),e===null&&(e=br())))))),e}function Sr(){var e,l,u,f;return u=r,f=r,a.substr(r,10).toLowerCase()==="transport="?(e=a.substr(r,10),r+=10):(e=null,_('"transport="')),e!==null?(a.substr(r,3).toLowerCase()==="udp"?(l=a.substr(r,3),r+=3):(l=null,_('"udp"')),l===null&&(a.substr(r,3).toLowerCase()==="tcp"?(l=a.substr(r,3),r+=3):(l=null,_('"tcp"')),l===null&&(a.substr(r,4).toLowerCase()==="sctp"?(l=a.substr(r,4),r+=4):(l=null,_('"sctp"')),l===null&&(a.substr(r,3).toLowerCase()==="tls"?(l=a.substr(r,3),r+=3):(l=null,_('"tls"')),l===null&&(l=P())))),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.transport=m.toLowerCase()}(u,e[1])),e===null&&(r=u),e}function yr(){var e,l,u,f;return u=r,f=r,a.substr(r,5).toLowerCase()==="user="?(e=a.substr(r,5),r+=5):(e=null,_('"user="')),e!==null?(a.substr(r,5).toLowerCase()==="phone"?(l=a.substr(r,5),r+=5):(l=null,_('"phone"')),l===null&&(a.substr(r,2).toLowerCase()==="ip"?(l=a.substr(r,2),r+=2):(l=null,_('"ip"')),l===null&&(l=P())),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.user=m.toLowerCase()}(u,e[1])),e===null&&(r=u),e}function Ar(){var e,l,u,f;return u=r,f=r,a.substr(r,7).toLowerCase()==="method="?(e=a.substr(r,7),r+=7):(e=null,_('"method="')),e!==null?(l=rn(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.method=m}(u,e[1])),e===null&&(r=u),e}function Cr(){var e,l,u,f;return u=r,f=r,a.substr(r,4).toLowerCase()==="ttl="?(e=a.substr(r,4),r+=4):(e=null,_('"ttl="')),e!==null?(l=Ci(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.params||(w.params={}),w.params.ttl=m}(u,e[1])),e===null&&(r=u),e}function Rr(){var e,l,u,f;return u=r,f=r,a.substr(r,6).toLowerCase()==="maddr="?(e=a.substr(r,6),r+=6):(e=null,_('"maddr="')),e!==null?(l=us(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.maddr=m}(u,e[1])),e===null&&(r=u),e}function Ir(){var e,l,u,f,p,m;return f=r,p=r,a.substr(r,2).toLowerCase()==="lr"?(e=a.substr(r,2),r+=2):(e=null,_('"lr"')),e!==null?(m=r,a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=P(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w.uri_params||(w.uri_params={}),w.uri_params.lr=void 0}()),e===null&&(r=f),e}function br(){var e,l,u,f,p,m;return f=r,p=r,e=wr(),e!==null?(m=r,a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=Rs(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v,S,O){w.uri_params||(w.uri_params={}),typeof O>"u"?O=void 0:O=O[1],w.uri_params[S.toLowerCase()]=O}(f,e[0],e[1])),e===null&&(r=f),e}function wr(){var e,l,u;if(u=r,l=Is(),l!==null)for(e=[];l!==null;)e.push(l),l=Is();else e=null;return e!==null&&(e=function(f,p){return p.join("")}(u,e)),e===null&&(r=u),e}function Rs(){var e,l,u;if(u=r,l=Is(),l!==null)for(e=[];l!==null;)e.push(l),l=Is();else e=null;return e!==null&&(e=function(f,p){return p.join("")}(u,e)),e===null&&(r=u),e}function Is(){var e;return e=Or(),e===null&&(e=j(),e===null&&(e=ve())),e}function Or(){var e;return a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e===null&&(a.charCodeAt(r)===93?(e="]",r++):(e=null,_('"]"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')))))))),e}function Xs(){var e,l,u,f,p,m,v;if(m=r,a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e!==null)if(l=Qs(),l!==null){for(u=[],v=r,a.charCodeAt(r)===38?(f="&",r++):(f=null,_('"&"')),f!==null?(p=Qs(),p!==null?f=[f,p]:(f=null,r=v)):(f=null,r=v);f!==null;)u.push(f),v=r,a.charCodeAt(r)===38?(f="&",r++):(f=null,_('"&"')),f!==null?(p=Qs(),p!==null?f=[f,p]:(f=null,r=v)):(f=null,r=v);u!==null?e=[e,l,u]:(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e}function Qs(){var e,l,u,f,p;return f=r,p=r,e=Dr(),e!==null?(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=bs(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v,S){v=v.join("").toLowerCase(),S=S.join(""),w.uri_headers||(w.uri_headers={}),w.uri_headers[v]?w.uri_headers[v].push(S):w.uri_headers[v]=[S]}(f,e[0],e[2])),e===null&&(r=f),e}function Dr(){var e,l;if(l=Zs(),l===null&&(l=j(),l===null&&(l=ve())),l!==null)for(e=[];l!==null;)e.push(l),l=Zs(),l===null&&(l=j(),l===null&&(l=ve()));else e=null;return e}function bs(){var e,l;for(e=[],l=Zs(),l===null&&(l=j(),l===null&&(l=ve()));l!==null;)e.push(l),l=Zs(),l===null&&(l=j(),l===null&&(l=ve()));return e}function Zs(){var e;return a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e===null&&(a.charCodeAt(r)===93?(e="]",r++):(e=null,_('"]"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')))))))),e}function gl(){var e;return e=Wr(),e===null&&(e=Nr()),e}function Nr(){var e,l,u,f,p,m;return m=r,e=rn(),e!==null?(l=H(),l!==null?(u=xn(),u!==null?(f=H(),f!==null?(p=Ln(),p!==null?e=[e,l,u,f,p]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e}function xn(){var e;return e=Ne(),e===null&&(e=kn()),e}function kn(){var e,l,u,f;return f=r,e=xr(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=Ur(),u===null&&(u=ws()),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Ur(){var e,l,u,f,p;return f=r,e=en(),e===null&&(e=tn()),e!==null?(p=r,a.charCodeAt(r)===63?(l="?",r++):(l=null,_('"?"')),l!==null?(u=Mn(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function en(){var e,l,u,f;return f=r,a.substr(r,2)==="//"?(e="//",r+=2):(e=null,_('"//"')),e!==null?(l=kr(),l!==null?(u=tn(),u=u!==null?u:"",u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function tn(){var e,l,u;return u=r,a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e!==null?(l=sn(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function ws(){var e,l,u,f;if(f=r,e=Pr(),e!==null){for(l=[],u=Os();u!==null;)l.push(u),u=Os();l!==null?e=[e,l]:(e=null,r=f)}else e=null,r=f;return e}function Os(){var e;return e=N(),e===null&&(e=j(),e===null&&(e=ve())),e}function Pr(){var e;return e=j(),e===null&&(e=ve(),e===null&&(a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')))))))))))),e}function sn(){var e,l,u,f,p,m;if(p=r,e=Ds(),e!==null){for(l=[],m=r,a.charCodeAt(r)===47?(u="/",r++):(u=null,_('"/"')),u!==null?(f=Ds(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,a.charCodeAt(r)===47?(u="/",r++):(u=null,_('"/"')),u!==null?(f=Ds(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Ds(){var e,l,u,f,p,m;for(p=r,e=[],l=Ns();l!==null;)e.push(l),l=Ns();if(e!==null){for(l=[],m=r,a.charCodeAt(r)===59?(u=";",r++):(u=null,_('";"')),u!==null?(f=cs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,a.charCodeAt(r)===59?(u=";",r++):(u=null,_('";"')),u!==null?(f=cs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function cs(){var e,l;for(e=[],l=Ns();l!==null;)e.push(l),l=Ns();return e}function Ns(){var e;return e=j(),e===null&&(e=ve(),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')))))))))),e}function xr(){var e,l,u,f,p;if(f=r,p=r,e=E(),e!==null){for(l=[],u=E(),u===null&&(u=T(),u===null&&(a.charCodeAt(r)===43?(u="+",r++):(u=null,_('"+"')),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."'))))));u!==null;)l.push(u),u=E(),u===null&&(u=T(),u===null&&(a.charCodeAt(r)===43?(u="+",r++):(u=null,_('"+"')),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."'))))));l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e!==null&&(e=function(m){w.scheme=a.substring(r,m)}(f)),e===null&&(r=f),e}function kr(){var e;return e=Mr(),e===null&&(e=Lr()),e}function Mr(){var e,l,u,f;return u=r,f=r,e=dt(),e!==null?(a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e=e!==null?e:"",e!==null?(l=es(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e=e!==null?e:"",e}function Lr(){var e,l;if(l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","')),l===null&&(a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"'))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","')),l===null&&(a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')))))))))));else e=null;return e}function Mn(){var e,l;for(e=[],l=Os();l!==null;)e.push(l),l=Os();return e}function Ln(){var e,l,u,f,p,m,v,S;if(v=r,S=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"SIP"')),e!==null)if(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l!==null){if(f=T(),f!==null)for(u=[];f!==null;)u.push(f),f=T();else u=null;if(u!==null)if(a.charCodeAt(r)===46?(f=".",r++):(f=null,_('"."')),f!==null){if(m=T(),m!==null)for(p=[];m!==null;)p.push(m),m=T();else p=null;p!==null?e=[e,l,u,f,p]:(e=null,r=S)}else e=null,r=S;else e=null,r=S}else e=null,r=S;else e=null,r=S;return e!==null&&(e=function(O){w.sip_version=a.substring(r,O)}(v)),e===null&&(r=v),e}function $r(){var e;return a.substr(r,6)==="INVITE"?(e="INVITE",r+=6):(e=null,_('"INVITE"')),e}function Hr(){var e;return a.substr(r,3)==="ACK"?(e="ACK",r+=3):(e=null,_('"ACK"')),e}function Fr(){var e;return a.substr(r,7)==="OPTIONS"?(e="OPTIONS",r+=7):(e=null,_('"OPTIONS"')),e}function jr(){var e;return a.substr(r,3)==="BYE"?(e="BYE",r+=3):(e=null,_('"BYE"')),e}function qr(){var e;return a.substr(r,6)==="CANCEL"?(e="CANCEL",r+=6):(e=null,_('"CANCEL"')),e}function Vr(){var e;return a.substr(r,8)==="REGISTER"?(e="REGISTER",r+=8):(e=null,_('"REGISTER"')),e}function Br(){var e;return a.substr(r,9)==="SUBSCRIBE"?(e="SUBSCRIBE",r+=9):(e=null,_('"SUBSCRIBE"')),e}function Gr(){var e;return a.substr(r,6)==="NOTIFY"?(e="NOTIFY",r+=6):(e=null,_('"NOTIFY"')),e}function nn(){var e;return a.substr(r,5)==="REFER"?(e="REFER",r+=5):(e=null,_('"REFER"')),e}function rn(){var e,l;return l=r,e=$r(),e===null&&(e=Hr(),e===null&&(e=Fr(),e===null&&(e=jr(),e===null&&(e=qr(),e===null&&(e=Vr(),e===null&&(e=Br(),e===null&&(e=Gr(),e===null&&(e=nn(),e===null&&(e=P()))))))))),e!==null&&(e=function(u){return w.method=a.substring(r,u),w.method}(l)),e===null&&(r=l),e}function Wr(){var e,l,u,f,p,m;return m=r,e=Ln(),e!==null?(l=H(),l!==null?(u=Kr(),u!==null?(f=H(),f!==null?(p=Tl(),p!==null?e=[e,l,u,f,p]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e}function Kr(){var e,l;return l=r,e=Yr(),e!==null&&(e=function(u,f){w.status_code=parseInt(f.join(""))}(l,e)),e===null&&(r=l),e}function Yr(){var e,l,u,f;return f=r,e=T(),e!==null?(l=T(),l!==null?(u=T(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Tl(){var e,l,u;for(u=r,e=[],l=N(),l===null&&(l=j(),l===null&&(l=ve(),l===null&&(l=F(),l===null&&(l=X(),l===null&&(l=H(),l===null&&(l=$()))))));l!==null;)e.push(l),l=N(),l===null&&(l=j(),l===null&&(l=ve(),l===null&&(l=F(),l===null&&(l=X(),l===null&&(l=H(),l===null&&(l=$()))))));return e!==null&&(e=function(f){w.reason_phrase=a.substring(r,f)}(u)),e===null&&(r=u),e}function Ja(){var e,l,u,f,p,m;if(p=r,e=un(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=un(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=un(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function za(){var e,l,u,f,p,m;return f=r,p=r,e=ee(),e!==null?(m=r,a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l!==null?(u=ee(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w=a.substring(r,v)}(f)),e===null&&(r=f),e}function $n(){var e,l,u,f,p,m,v;if(p=r,e=W(),e===null)if(m=r,e=$t(),e!==null){for(l=[],v=r,u=le(),u!==null?(f=$t(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=le(),u!==null?(f=$t(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O,ie;for(ie=w.multi_header.length,O=0;O<ie;O++)if(w.multi_header[O].parsed===null){w=null;break}w!==null?w=w.multi_header:w=-1}()),e===null&&(r=p),e}function $t(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Ht()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=Hn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=Hn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O;w.multi_header||(w.multi_header=[]);try{O=new b(w.uri,w.display_name,w.params),delete w.uri,delete w.display_name,delete w.params}catch{O=null}w.multi_header.push({possition:r,offset:S,parsed:O})}(p)),e===null&&(r=p),e}function Ht(){var e,l,u,f,p;return p=r,e=Us(),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,r=p)):(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e}function Us(){var e,l,u,f,p,m,v;if(p=r,m=r,e=P(),e!==null){for(l=[],v=r,u=k(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=k(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e===null&&(e=pe()),e!==null&&(e=function(S,O){typeof O=="string"?w.display_name=O:w.display_name=O[1].reduce(function(ie,Ue){return ie+Ue[0]+Ue[1]},O[0])}(p,e)),e===null&&(r=p),e}function Hn(){var e;return e=Jr(),e===null&&(e=ts(),e===null&&(e=We())),e}function Jr(){var e,l,u,f,p;return f=r,p=r,a.substr(r,1).toLowerCase()==="q"?(e=a.substr(r,1),r++):(e=null,_('"q"')),e!==null?(l=re(),l!==null?(u=Ge(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.params||(w.params={}),w.params.q=v}(f,e[2])),e===null&&(r=f),e}function ts(){var e,l,u,f,p;return f=r,p=r,a.substr(r,7).toLowerCase()==="expires"?(e=a.substr(r,7),r+=7):(e=null,_('"expires"')),e!==null?(l=re(),l!==null?(u=ss(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.params||(w.params={}),w.params.expires=v}(f,e[2])),e===null&&(r=f),e}function ss(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){return parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function Ge(){var e,l,u,f,p,m,v,S;return m=r,v=r,a.charCodeAt(r)===48?(e="0",r++):(e=null,_('"0"')),e!==null?(S=r,a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?l=[l,u,f,p]:(l=null,r=S)):(l=null,r=S)):(l=null,r=S)):(l=null,r=S),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(O){return parseFloat(a.substring(r,O))}(m)),e===null&&(r=m),e}function We(){var e,l,u,f,p,m;return f=r,p=r,e=P(),e!==null?(m=r,l=re(),l!==null?(u=vl(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v,S,O){w.params||(w.params={}),typeof O>"u"?O=void 0:O=O[1],w.params[S.toLowerCase()]=O}(f,e[0],e[1])),e===null&&(r=f),e}function vl(){var e;return e=P(),e===null&&(e=us(),e===null&&(e=Oe())),e}function El(){var e,l,u,f,p,m;if(p=r,e=Fn(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=jn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=jn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Fn(){var e;return a.substr(r,6).toLowerCase()==="render"?(e=a.substr(r,6),r+=6):(e=null,_('"render"')),e===null&&(a.substr(r,7).toLowerCase()==="session"?(e=a.substr(r,7),r+=7):(e=null,_('"session"')),e===null&&(a.substr(r,4).toLowerCase()==="icon"?(e=a.substr(r,4),r+=4):(e=null,_('"icon"')),e===null&&(a.substr(r,5).toLowerCase()==="alert"?(e=a.substr(r,5),r+=5):(e=null,_('"alert"')),e===null&&(e=P())))),e}function jn(){var e;return e=Sl(),e===null&&(e=We()),e}function Sl(){var e,l,u,f;return f=r,a.substr(r,8).toLowerCase()==="handling"?(e=a.substr(r,8),r+=8):(e=null,_('"handling"')),e!==null?(l=re(),l!==null?(a.substr(r,8).toLowerCase()==="optional"?(u=a.substr(r,8),r+=8):(u=null,_('"optional"')),u===null&&(a.substr(r,8).toLowerCase()==="required"?(u=a.substr(r,8),r+=8):(u=null,_('"required"')),u===null&&(u=P())),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Xa(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Qa(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){w=parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function yl(){var e,l;return l=r,e=zr(),e!==null&&(e=function(u){w=a.substring(r,u)}(l)),e===null&&(r=l),e}function zr(){var e,l,u,f,p,m,v,S;if(v=r,e=Xr(),e!==null)if(l=G(),l!==null)if(u=qn(),u!==null){for(f=[],S=r,p=ye(),p!==null?(m=Vn(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=ye(),p!==null?(m=Vn(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e}function Xr(){var e;return e=Qr(),e===null&&(e=ln()),e}function Qr(){var e;return a.substr(r,4).toLowerCase()==="text"?(e=a.substr(r,4),r+=4):(e=null,_('"text"')),e===null&&(a.substr(r,5).toLowerCase()==="image"?(e=a.substr(r,5),r+=5):(e=null,_('"image"')),e===null&&(a.substr(r,5).toLowerCase()==="audio"?(e=a.substr(r,5),r+=5):(e=null,_('"audio"')),e===null&&(a.substr(r,5).toLowerCase()==="video"?(e=a.substr(r,5),r+=5):(e=null,_('"video"')),e===null&&(a.substr(r,11).toLowerCase()==="application"?(e=a.substr(r,11),r+=11):(e=null,_('"application"')),e===null&&(e=an()))))),e}function ln(){var e;return a.substr(r,7).toLowerCase()==="message"?(e=a.substr(r,7),r+=7):(e=null,_('"message"')),e===null&&(a.substr(r,9).toLowerCase()==="multipart"?(e=a.substr(r,9),r+=9):(e=null,_('"multipart"')),e===null&&(e=an())),e}function an(){var e;return e=P(),e===null&&(e=Zr()),e}function Zr(){var e,l,u;return u=r,a.substr(r,2).toLowerCase()==="x-"?(e=a.substr(r,2),r+=2):(e=null,_('"x-"')),e!==null?(l=P(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function qn(){var e;return e=an(),e===null&&(e=P()),e}function Vn(){var e,l,u,f;return f=r,e=P(),e!==null?(l=re(),l!==null?(u=Al(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Al(){var e;return e=P(),e===null&&(e=Oe()),e}function Cl(){var e,l,u,f;return f=r,e=Rl(),e!==null?(l=k(),l!==null?(u=rn(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Rl(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){w.value=parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function Za(){var e,l;return l=r,e=ss(),e!==null&&(e=function(u,f){w=f}(l,e)),e===null&&(r=l),e}function on(){var e,l,u,f,p,m,v;if(p=r,m=r,e=un(),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S,O){w.event=O.join("").toLowerCase()}(p,e[0])),e===null&&(r=p),e}function un(){var e,l,u,f,p,m;if(p=r,e=se(),e!==null){for(l=[],m=r,a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?(f=se(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?(f=se(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function ei(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Ht()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=cn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=cn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O=w.tag;try{w=new b(w.uri,w.display_name,w.params),O&&w.setParam("tag",O)}catch{w=-1}}()),e===null&&(r=p),e}function cn(){var e;return e=ti(),e===null&&(e=We()),e}function ti(){var e,l,u,f,p;return f=r,p=r,a.substr(r,3).toLowerCase()==="tag"?(e=a.substr(r,3),r+=3):(e=null,_('"tag"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.tag=v}(f,e[2])),e===null&&(r=f),e}function eo(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){w=parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function to(){var e,l;return l=r,e=ss(),e!==null&&(e=function(u,f){w=f}(l,e)),e===null&&(r=l),e}function so(){var e,l,u,f,p,m,v,S,O,ie;for(S=r,O=r,e=[],l=Us();l!==null;)e.push(l),l=Us();if(e!==null)if(l=Ce(),l!==null)if(u=Ne(),u!==null)if(f=xe(),f!==null){for(p=[],ie=r,m=ye(),m!==null?(v=We(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);m!==null;)p.push(m),ie=r,m=ye(),m!==null?(v=We(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);p!==null?e=[e,l,u,f,p]:(e=null,r=O)}else e=null,r=O;else e=null,r=O;else e=null,r=O;else e=null,r=O;return e!==null&&(e=function(Ue){try{w=new b(w.uri,w.display_name,w.params)}catch{w=-1}}()),e===null&&(r=S),e}function si(){var e;return e=Bn(),e}function Bn(){var e,l,u,f,p,m,v,S;if(v=r,a.substr(r,6).toLowerCase()==="digest"?(e=a.substr(r,6),r+=6):(e=null,_('"Digest"')),e!==null)if(l=k(),l!==null)if(u=fn(),u!==null){for(f=[],S=r,p=le(),p!==null?(m=fn(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=le(),p!==null?(m=fn(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e===null&&(e=Ps()),e}function Ps(){var e,l,u,f,p,m,v,S;if(v=r,e=P(),e!==null)if(l=k(),l!==null)if(u=ns(),u!==null){for(f=[],S=r,p=le(),p!==null?(m=ns(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=le(),p!==null?(m=ns(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e}function ns(){var e,l,u,f;return f=r,e=P(),e!==null?(l=re(),l!==null?(u=P(),u===null&&(u=Oe()),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function fn(){var e;return e=ni(),e===null&&(e=hn(),e===null&&(e=ii(),e===null&&(e=ai(),e===null&&(e=oi(),e===null&&(e=ui(),e===null&&(e=_n(),e===null&&(e=ns()))))))),e}function ni(){var e,l,u,f;return f=r,a.substr(r,5).toLowerCase()==="realm"?(e=a.substr(r,5),r+=5):(e=null,_('"realm"')),e!==null?(l=re(),l!==null?(u=ri(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function ri(){var e,l;return l=r,e=pe(),e!==null&&(e=function(u,f){w.realm=f}(l,e)),e===null&&(r=l),e}function hn(){var e,l,u,f,p,m,v,S,O;if(S=r,a.substr(r,6).toLowerCase()==="domain"?(e=a.substr(r,6),r+=6):(e=null,_('"domain"')),e!==null)if(l=re(),l!==null)if(u=at(),u!==null)if(f=dn(),f!==null){if(p=[],O=r,v=H(),v!==null)for(m=[];v!==null;)m.push(v),v=H();else m=null;for(m!==null?(v=dn(),v!==null?m=[m,v]:(m=null,r=O)):(m=null,r=O);m!==null;){if(p.push(m),O=r,v=H(),v!==null)for(m=[];v!==null;)m.push(v),v=H();else m=null;m!==null?(v=dn(),v!==null?m=[m,v]:(m=null,r=O)):(m=null,r=O)}p!==null?(m=Ee(),m!==null?e=[e,l,u,f,p,m]:(e=null,r=S)):(e=null,r=S)}else e=null,r=S;else e=null,r=S;else e=null,r=S;else e=null,r=S;return e}function dn(){var e;return e=kn(),e===null&&(e=tn()),e}function ii(){var e,l,u,f;return f=r,a.substr(r,5).toLowerCase()==="nonce"?(e=a.substr(r,5),r+=5):(e=null,_('"nonce"')),e!==null?(l=re(),l!==null?(u=li(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function li(){var e,l;return l=r,e=pe(),e!==null&&(e=function(u,f){w.nonce=f}(l,e)),e===null&&(r=l),e}function ai(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6).toLowerCase()==="opaque"?(e=a.substr(r,6),r+=6):(e=null,_('"opaque"')),e!==null?(l=re(),l!==null?(u=pe(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.opaque=v}(f,e[2])),e===null&&(r=f),e}function oi(){var e,l,u,f,p;return f=r,a.substr(r,5).toLowerCase()==="stale"?(e=a.substr(r,5),r+=5):(e=null,_('"stale"')),e!==null?(l=re(),l!==null?(p=r,a.substr(r,4).toLowerCase()==="true"?(u=a.substr(r,4),r+=4):(u=null,_('"true"')),u!==null&&(u=function(m){w.stale=!0}()),u===null&&(r=p),u===null&&(p=r,a.substr(r,5).toLowerCase()==="false"?(u=a.substr(r,5),r+=5):(u=null,_('"false"')),u!==null&&(u=function(m){w.stale=!1}()),u===null&&(r=p)),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function ui(){var e,l,u,f,p;return f=r,p=r,a.substr(r,9).toLowerCase()==="algorithm"?(e=a.substr(r,9),r+=9):(e=null,_('"algorithm"')),e!==null?(l=re(),l!==null?(a.substr(r,3).toLowerCase()==="md5"?(u=a.substr(r,3),r+=3):(u=null,_('"MD5"')),u===null&&(a.substr(r,8).toLowerCase()==="md5-sess"?(u=a.substr(r,8),r+=8):(u=null,_('"MD5-sess"')),u===null&&(u=P())),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.algorithm=v.toUpperCase()}(f,e[2])),e===null&&(r=f),e}function _n(){var e,l,u,f,p,m,v,S,O,ie;if(S=r,a.substr(r,3).toLowerCase()==="qop"?(e=a.substr(r,3),r+=3):(e=null,_('"qop"')),e!==null)if(l=re(),l!==null)if(u=at(),u!==null){if(O=r,f=Gn(),f!==null){for(p=[],ie=r,a.charCodeAt(r)===44?(m=",",r++):(m=null,_('","')),m!==null?(v=Gn(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);m!==null;)p.push(m),ie=r,a.charCodeAt(r)===44?(m=",",r++):(m=null,_('","')),m!==null?(v=Gn(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);p!==null?f=[f,p]:(f=null,r=O)}else f=null,r=O;f!==null?(p=Ee(),p!==null?e=[e,l,u,f,p]:(e=null,r=S)):(e=null,r=S)}else e=null,r=S;else e=null,r=S;else e=null,r=S;return e}function Gn(){var e,l;return l=r,a.substr(r,8).toLowerCase()==="auth-int"?(e=a.substr(r,8),r+=8):(e=null,_('"auth-int"')),e===null&&(a.substr(r,4).toLowerCase()==="auth"?(e=a.substr(r,4),r+=4):(e=null,_('"auth"')),e===null&&(e=P())),e!==null&&(e=function(u,f){w.qop||(w.qop=[]),w.qop.push(f.toLowerCase())}(l,e)),e===null&&(r=l),e}function no(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Wn(){var e,l,u,f,p,m,v;if(p=r,m=r,e=Kn(),e!==null){for(l=[],v=r,u=le(),u!==null?(f=Kn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=le(),u!==null?(f=Kn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O,ie;for(ie=w.multi_header.length,O=0;O<ie;O++)if(w.multi_header[O].parsed===null){w=null;break}w!==null?w=w.multi_header:w=-1}()),e===null&&(r=p),e}function Kn(){var e,l,u,f,p,m,v;if(p=r,m=r,e=Ht(),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O;w.multi_header||(w.multi_header=[]);try{O=new b(w.uri,w.display_name,w.params),delete w.uri,delete w.display_name,delete w.params}catch{O=null}w.multi_header.push({possition:r,offset:S,parsed:O})}(p)),e===null&&(r=p),e}function ci(){var e,l,u,f,p,m,v;if(p=r,m=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"SIP"')),e===null&&(e=P()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=Yn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=Yn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S,O){if(w.protocol=O.toLowerCase(),w.params||(w.params={}),w.params.text&&w.params.text[0]==='"'){var ie=w.params.text;w.text=ie.substring(1,ie.length-1),delete w.params.text}}(p,e[0])),e===null&&(r=p),e}function Yn(){var e;return e=Il(),e===null&&(e=We()),e}function Il(){var e,l,u,f,p,m;if(p=r,m=r,a.substr(r,5).toLowerCase()==="cause"?(e=a.substr(r,5),r+=5):(e=null,_('"cause"')),e!==null)if(l=re(),l!==null){if(f=T(),f!==null)for(u=[];f!==null;)u.push(f),f=T();else u=null;u!==null?e=[e,l,u]:(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e!==null&&(e=function(v,S){w.cause=parseInt(S.join(""))}(p,e[2])),e===null&&(r=p),e}function ro(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Jn(){var e,l,u,f,p,m;if(p=r,e=zn(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=zn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=zn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function zn(){var e,l,u,f,p,m;if(p=r,e=Ht(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function bl(){var e,l,u,f,p,m;if(p=r,e=Xn(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=Qn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=Qn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Xn(){var e,l;return l=r,a.substr(r,6).toLowerCase()==="active"?(e=a.substr(r,6),r+=6):(e=null,_('"active"')),e===null&&(a.substr(r,7).toLowerCase()==="pending"?(e=a.substr(r,7),r+=7):(e=null,_('"pending"')),e===null&&(a.substr(r,10).toLowerCase()==="terminated"?(e=a.substr(r,10),r+=10):(e=null,_('"terminated"')),e===null&&(e=P()))),e!==null&&(e=function(u){w.state=a.substring(r,u)}(l)),e===null&&(r=l),e}function Qn(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6).toLowerCase()==="reason"?(e=a.substr(r,6),r+=6):(e=null,_('"reason"')),e!==null?(l=re(),l!==null?(u=wl(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){typeof v<"u"&&(w.reason=v)}(f,e[2])),e===null&&(r=f),e===null&&(f=r,p=r,a.substr(r,7).toLowerCase()==="expires"?(e=a.substr(r,7),r+=7):(e=null,_('"expires"')),e!==null?(l=re(),l!==null?(u=ss(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){typeof v<"u"&&(w.expires=v)}(f,e[2])),e===null&&(r=f),e===null&&(f=r,p=r,a.substr(r,11).toLowerCase()==="retry_after"?(e=a.substr(r,11),r+=11):(e=null,_('"retry_after"')),e!==null?(l=re(),l!==null?(u=ss(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){typeof v<"u"&&(w.retry_after=v)}(f,e[2])),e===null&&(r=f),e===null&&(e=We()))),e}function wl(){var e;return a.substr(r,11).toLowerCase()==="deactivated"?(e=a.substr(r,11),r+=11):(e=null,_('"deactivated"')),e===null&&(a.substr(r,9).toLowerCase()==="probation"?(e=a.substr(r,9),r+=9):(e=null,_('"probation"')),e===null&&(a.substr(r,8).toLowerCase()==="rejected"?(e=a.substr(r,8),r+=8):(e=null,_('"rejected"')),e===null&&(a.substr(r,7).toLowerCase()==="timeout"?(e=a.substr(r,7),r+=7):(e=null,_('"timeout"')),e===null&&(a.substr(r,6).toLowerCase()==="giveup"?(e=a.substr(r,6),r+=6):(e=null,_('"giveup"')),e===null&&(a.substr(r,10).toLowerCase()==="noresource"?(e=a.substr(r,10),r+=10):(e=null,_('"noresource"')),e===null&&(a.substr(r,9).toLowerCase()==="invariant"?(e=a.substr(r,9),r+=9):(e=null,_('"invariant"')),e===null&&(e=P()))))))),e}function io(){var e;return e=V(),e=e!==null?e:"",e}function lo(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e=e!==null?e:"",e}function fi(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Ht()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=hi(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=hi(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O=w.tag;try{w=new b(w.uri,w.display_name,w.params),O&&w.setParam("tag",O)}catch{w=-1}}()),e===null&&(r=p),e}function hi(){var e;return e=ti(),e===null&&(e=We()),e}function Zn(){var e,l,u,f,p,m;if(p=r,e=xs(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=xs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=xs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function xs(){var e,l,u,f,p,m,v,S;if(v=r,e=vi(),e!==null)if(l=k(),l!==null)if(u=yi(),u!==null){for(f=[],S=r,p=ye(),p!==null?(m=er(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=ye(),p!==null?(m=er(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e}function er(){var e;return e=di(),e===null&&(e=_i(),e===null&&(e=pi(),e===null&&(e=mi(),e===null&&(e=gi(),e===null&&(e=We()))))),e}function di(){var e,l,u,f,p;return f=r,p=r,a.substr(r,3).toLowerCase()==="ttl"?(e=a.substr(r,3),r+=3):(e=null,_('"ttl"')),e!==null?(l=re(),l!==null?(u=Ci(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.ttl=v}(f,e[2])),e===null&&(r=f),e}function _i(){var e,l,u,f,p;return f=r,p=r,a.substr(r,5).toLowerCase()==="maddr"?(e=a.substr(r,5),r+=5):(e=null,_('"maddr"')),e!==null?(l=re(),l!==null?(u=us(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.maddr=v}(f,e[2])),e===null&&(r=f),e}function pi(){var e,l,u,f,p;return f=r,p=r,a.substr(r,8).toLowerCase()==="received"?(e=a.substr(r,8),r+=8):(e=null,_('"received"')),e!==null?(l=re(),l!==null?(u=Wt(),u===null&&(u=me()),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.received=v}(f,e[2])),e===null&&(r=f),e}function mi(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6).toLowerCase()==="branch"?(e=a.substr(r,6),r+=6):(e=null,_('"branch"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.branch=v}(f,e[2])),e===null&&(r=f),e}function gi(){var e,l,u,f,p;return f=r,a.substr(r,5).toLowerCase()==="rport"?(e=a.substr(r,5),r+=5):(e=null,_('"rport"')),e!==null?(p=r,l=re(),l!==null?(u=Ti(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function Ti(){var e,l,u,f,p,m,v;return m=r,v=r,e=T(),e=e!==null?e:"",e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?e=[e,l,u,f,p]:(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(S,O){w.rport=parseInt(O.join(""))}(m,e)),e===null&&(r=m),e}function vi(){var e,l,u,f,p,m;return m=r,e=Ei(),e!==null?(l=G(),l!==null?(u=P(),u!==null?(f=G(),f!==null?(p=Si(),p!==null?e=[e,l,u,f,p]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e}function Ei(){var e,l;return l=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"SIP"')),e===null&&(e=P()),e!==null&&(e=function(u,f){w.protocol=f}(l,e)),e===null&&(r=l),e}function Si(){var e,l;return l=r,a.substr(r,3).toLowerCase()==="udp"?(e=a.substr(r,3),r+=3):(e=null,_('"UDP"')),e===null&&(a.substr(r,3).toLowerCase()==="tcp"?(e=a.substr(r,3),r+=3):(e=null,_('"TCP"')),e===null&&(a.substr(r,3).toLowerCase()==="tls"?(e=a.substr(r,3),r+=3):(e=null,_('"TLS"')),e===null&&(a.substr(r,4).toLowerCase()==="sctp"?(e=a.substr(r,4),r+=4):(e=null,_('"SCTP"')),e===null&&(e=P())))),e!==null&&(e=function(u,f){w.transport=f}(l,e)),e===null&&(r=l),e}function yi(){var e,l,u,f,p;return f=r,e=Ai(),e!==null?(p=r,l=nt(),l!==null?(u=tr(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function Ai(){var e,l;return l=r,e=Wt(),e===null&&(e=zs(),e===null&&(e=Js())),e!==null&&(e=function(u){w.host=a.substring(r,u)}(l)),e===null&&(r=l),e}function tr(){var e,l,u,f,p,m,v;return m=r,v=r,e=T(),e=e!==null?e:"",e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?e=[e,l,u,f,p]:(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(S,O){w.port=parseInt(O.join(""))}(m,e)),e===null&&(r=m),e}function Ci(){var e,l,u,f,p;return f=r,p=r,e=T(),e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){return parseInt(v.join(""))}(f,e)),e===null&&(r=f),e}function ao(){var e;return e=Bn(),e}function Ol(){var e,l,u,f,p,m;if(p=r,e=sr(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=nr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=nr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function sr(){var e,l;return l=r,e=ss(),e!==null&&(e=function(u,f){w.expires=f}(l,e)),e===null&&(r=l),e}function nr(){var e;return e=Dl(),e===null&&(e=We()),e}function Dl(){var e,l,u,f,p;return f=r,p=r,a.substr(r,9).toLowerCase()==="refresher"?(e=a.substr(r,9),r+=9):(e=null,_('"refresher"')),e!==null?(l=re(),l!==null?(a.substr(r,3).toLowerCase()==="uac"?(u=a.substr(r,3),r+=3):(u=null,_('"uac"')),u===null&&(a.substr(r,3).toLowerCase()==="uas"?(u=a.substr(r,3),r+=3):(u=null,_('"uas"'))),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.refresher=v.toLowerCase()}(f,e[2])),e===null&&(r=f),e}function Nl(){var e,l,u,f;return f=r,e=P(),e!==null?(l=B(),l!==null?(u=Ul(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Ul(){var e,l;for(e=[],l=J(),l===null&&(l=X(),l===null&&(l=k()));l!==null;)e.push(l),l=J(),l===null&&(l=X(),l===null&&(l=k()));return e}function oo(){var e,l;for(e=[],l=C();l!==null;)e.push(l),l=C();return e}function Pl(){var e,l,u;return u=r,a.substr(r,5)==="uuid:"?(e="uuid:",r+=5):(e=null,_('"uuid:"')),e!==null?(l=Ft(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function Ft(){var e,l,u,f,p,m,v,S,O,ie,Ue;return ie=r,Ue=r,e=Ri(),e!==null?(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l!==null?(u=jt(),u!==null?(a.charCodeAt(r)===45?(f="-",r++):(f=null,_('"-"')),f!==null?(p=jt(),p!==null?(a.charCodeAt(r)===45?(m="-",r++):(m=null,_('"-"')),m!==null?(v=jt(),v!==null?(a.charCodeAt(r)===45?(S="-",r++):(S=null,_('"-"')),S!==null?(O=xl(),O!==null?e=[e,l,u,f,p,m,v,S,O]:(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue),e!==null&&(e=function(wt,ks){w=a.substring(r+5,wt)}(ie,e[0])),e===null&&(r=ie),e}function jt(){var e,l,u,f,p;return p=r,e=y(),e!==null?(l=y(),l!==null?(u=y(),u!==null?(f=y(),f!==null?e=[e,l,u,f]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e}function Ri(){var e,l,u;return u=r,e=jt(),e!==null?(l=jt(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function xl(){var e,l,u,f;return f=r,e=jt(),e!==null?(l=jt(),l!==null?(u=jt(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function uo(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Ht()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){try{w=new b(w.uri,w.display_name,w.params)}catch{w=-1}}()),e===null&&(r=p),e}function kl(){var e,l,u,f,p,m;if(p=r,e=rr(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=ir(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=ir(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function rr(){var e,l,u,f,p,m;return f=r,p=r,e=ee(),e!==null?(m=r,a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l!==null?(u=ee(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w.call_id=a.substring(r,v)}(f)),e===null&&(r=f),e}function ir(){var e;return e=Ii(),e===null&&(e=bi(),e===null&&(e=Ml(),e===null&&(e=We()))),e}function Ii(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6)==="to-tag"?(e="to-tag",r+=6):(e=null,_('"to-tag"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.to_tag=v}(f,e[2])),e===null&&(r=f),e}function bi(){var e,l,u,f,p;return f=r,p=r,a.substr(r,8)==="from-tag"?(e="from-tag",r+=8):(e=null,_('"from-tag"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.from_tag=v}(f,e[2])),e===null&&(r=f),e}function Ml(){var e,l;return l=r,a.substr(r,10)==="early-only"?(e="early-only",r+=10):(e=null,_('"early-only"')),e!==null&&(e=function(u){w.early_only=!0}()),e===null&&(r=l),e}function co(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 Ll(){for(var e=1,l=1,u=!1,f=0;f<Math.max(r,d);f++){var p=a.charAt(f);p===`
|
3
|
+
`,r+=2):(e=null,_('"\\r\\n"')),e}function T(){var e;return/^[0-9]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[0-9]")),e}function E(){var e;return/^[a-zA-Z]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[a-zA-Z]")),e}function y(){var e;return/^[0-9a-fA-F]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[0-9a-fA-F]")),e}function C(){var e;return e=H(),e===null&&(e=$()),e}function A(){var e;return/^[\0-\xFF]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\0-\\xFF]")),e}function I(){var e;return/^["]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_('["]')),e}function H(){var e;return a.charCodeAt(r)===32?(e=" ",r++):(e=null,_('" "')),e}function $(){var e;return a.charCodeAt(r)===9?(e=" ",r++):(e=null,_('"\\t"')),e}function oe(){var e;return/^[a-zA-Z0-9]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[a-zA-Z0-9]")),e}function N(){var e;return a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","'))))))))))),e}function j(){var e;return e=oe(),e===null&&(e=Se()),e}function Se(){var e;return a.charCodeAt(r)===45?(e="-",r++):(e=null,_('"-"')),e===null&&(a.charCodeAt(r)===95?(e="_",r++):(e=null,_('"_"')),e===null&&(a.charCodeAt(r)===46?(e=".",r++):(e=null,_('"."')),e===null&&(a.charCodeAt(r)===33?(e="!",r++):(e=null,_('"!"')),e===null&&(a.charCodeAt(r)===126?(e="~",r++):(e=null,_('"~"')),e===null&&(a.charCodeAt(r)===42?(e="*",r++):(e=null,_('"*"')),e===null&&(a.charCodeAt(r)===39?(e="'",r++):(e=null,_(`"'"`)),e===null&&(a.charCodeAt(r)===40?(e="(",r++):(e=null,_('"("')),e===null&&(a.charCodeAt(r)===41?(e=")",r++):(e=null,_('")"')))))))))),e}function ve(){var e,l,u,f,p;return f=r,p=r,a.charCodeAt(r)===37?(e="%",r++):(e=null,_('"%"')),e!==null?(l=y(),l!==null?(u=y(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){return v.join("")}(f,e)),e===null&&(r=f),e}function k(){var e,l,u,f,p,m;for(f=r,p=r,m=r,e=[],l=C();l!==null;)e.push(l),l=C();if(e!==null?(l=g(),l!==null?e=[e,l]:(e=null,r=m)):(e=null,r=m),e=e!==null?e:"",e!==null){if(u=C(),u!==null)for(l=[];u!==null;)l.push(u),u=C();else l=null;l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e!==null&&(e=function(v){return" "}()),e===null&&(r=f),e}function D(){var e;return e=k(),e=e!==null?e:"",e}function B(){var e,l,u,f,p;for(f=r,p=r,e=[],l=H(),l===null&&(l=$());l!==null;)e.push(l),l=H(),l===null&&(l=$());return e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return":"}()),e===null&&(r=f),e}function V(){var e,l,u,f,p,m,v;if(p=r,m=r,l=J(),l!==null)for(e=[];l!==null;)e.push(l),l=J();else e=null;if(e!==null){for(l=[],v=r,u=[],f=k();f!==null;)u.push(f),f=k();for(u!==null?(f=J(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;){for(l.push(u),v=r,u=[],f=k();f!==null;)u.push(f),f=k();u!==null?(f=J(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v)}l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){return a.substring(r,S)}(p)),e===null&&(r=p),e}function J(){var e;return/^[!-~]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[!-~]")),e===null&&(e=F()),e}function F(){var e;return/^[\x80-\uFFFF]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\x80-\\uFFFF]")),e}function X(){var e;return/^[\x80-\xBF]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\x80-\\xBF]")),e}function U(){var e;return e=T(),e===null&&(/^[a-f]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[a-f]"))),e}function P(){var e,l,u;if(u=r,l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"'))))))))))));else e=null;return e!==null&&(e=function(f){return a.substring(r,f)}(u)),e===null&&(r=u),e}function se(){var e,l,u;if(u=r,l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"'))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')))))))))));else e=null;return e!==null&&(e=function(f){return a.substring(r,f)}(u)),e===null&&(r=u),e}function st(){var e;return a.charCodeAt(r)===40?(e="(",r++):(e=null,_('"("')),e===null&&(a.charCodeAt(r)===41?(e=")",r++):(e=null,_('")"')),e===null&&(a.charCodeAt(r)===60?(e="<",r++):(e=null,_('"<"')),e===null&&(a.charCodeAt(r)===62?(e=">",r++):(e=null,_('">"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')),e===null&&(a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===92?(e="\\",r++):(e=null,_('"\\\\"')),e===null&&(e=I(),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e===null&&(a.charCodeAt(r)===93?(e="]",r++):(e=null,_('"]"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===123?(e="{",r++):(e=null,_('"{"')),e===null&&(a.charCodeAt(r)===125?(e="}",r++):(e=null,_('"}"')),e===null&&(e=H(),e===null&&(e=$())))))))))))))))))),e}function ee(){var e,l,u;if(u=r,l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')),l===null&&(a.charCodeAt(r)===40?(l="(",r++):(l=null,_('"("')),l===null&&(a.charCodeAt(r)===41?(l=")",r++):(l=null,_('")"')),l===null&&(a.charCodeAt(r)===60?(l="<",r++):(l=null,_('"<"')),l===null&&(a.charCodeAt(r)===62?(l=">",r++):(l=null,_('">"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===92?(l="\\",r++):(l=null,_('"\\\\"')),l===null&&(l=I(),l===null&&(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l===null&&(a.charCodeAt(r)===91?(l="[",r++):(l=null,_('"["')),l===null&&(a.charCodeAt(r)===93?(l="]",r++):(l=null,_('"]"')),l===null&&(a.charCodeAt(r)===63?(l="?",r++):(l=null,_('"?"')),l===null&&(a.charCodeAt(r)===123?(l="{",r++):(l=null,_('"{"')),l===null&&(a.charCodeAt(r)===125?(l="}",r++):(l=null,_('"}"'))))))))))))))))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=oe(),l===null&&(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l===null&&(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l===null&&(a.charCodeAt(r)===33?(l="!",r++):(l=null,_('"!"')),l===null&&(a.charCodeAt(r)===37?(l="%",r++):(l=null,_('"%"')),l===null&&(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l===null&&(a.charCodeAt(r)===95?(l="_",r++):(l=null,_('"_"')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===96?(l="`",r++):(l=null,_('"`"')),l===null&&(a.charCodeAt(r)===39?(l="'",r++):(l=null,_(`"'"`)),l===null&&(a.charCodeAt(r)===126?(l="~",r++):(l=null,_('"~"')),l===null&&(a.charCodeAt(r)===40?(l="(",r++):(l=null,_('"("')),l===null&&(a.charCodeAt(r)===41?(l=")",r++):(l=null,_('")"')),l===null&&(a.charCodeAt(r)===60?(l="<",r++):(l=null,_('"<"')),l===null&&(a.charCodeAt(r)===62?(l=">",r++):(l=null,_('">"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===92?(l="\\",r++):(l=null,_('"\\\\"')),l===null&&(l=I(),l===null&&(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l===null&&(a.charCodeAt(r)===91?(l="[",r++):(l=null,_('"["')),l===null&&(a.charCodeAt(r)===93?(l="]",r++):(l=null,_('"]"')),l===null&&(a.charCodeAt(r)===63?(l="?",r++):(l=null,_('"?"')),l===null&&(a.charCodeAt(r)===123?(l="{",r++):(l=null,_('"{"')),l===null&&(a.charCodeAt(r)===125?(l="}",r++):(l=null,_('"}"')))))))))))))))))))))))));else e=null;return e!==null&&(e=function(f){return a.substring(r,f)}(u)),e===null&&(r=u),e}function W(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===42?(l="*",r++):(l=null,_('"*"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"*"}()),e===null&&(r=f),e}function G(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"/"}()),e===null&&(r=f),e}function re(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"="}()),e===null&&(r=f),e}function ge(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===40?(l="(",r++):(l=null,_('"("')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return"("}()),e===null&&(r=f),e}function be(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===41?(l=")",r++):(l=null,_('")"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return")"}()),e===null&&(r=f),e}function xe(){var e,l,u,f;return u=r,f=r,a.charCodeAt(r)===62?(e=">",r++):(e=null,_('">"')),e!==null?(l=D(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return">"}()),e===null&&(r=u),e}function Ae(){var e,l,u,f;return u=r,f=r,e=D(),e!==null?(a.charCodeAt(r)===60?(l="<",r++):(l=null,_('"<"')),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return"<"}()),e===null&&(r=u),e}function le(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return","}()),e===null&&(r=f),e}function ye(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return";"}()),e===null&&(r=f),e}function nt(){var e,l,u,f,p;return f=r,p=r,e=D(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=D(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return":"}()),e===null&&(r=f),e}function at(){var e,l,u,f;return u=r,f=r,e=D(),e!==null?(l=I(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return'"'}()),e===null&&(r=u),e}function Ee(){var e,l,u,f;return u=r,f=r,e=I(),e!==null?(l=D(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p){return'"'}()),e===null&&(r=u),e}function Ce(){var e,l,u,f;if(f=r,e=ge(),e!==null){for(l=[],u=Ie(),u===null&&(u=_e(),u===null&&(u=Ce()));u!==null;)l.push(u),u=Ie(),u===null&&(u=_e(),u===null&&(u=Ce()));l!==null?(u=be(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)}else e=null,r=f;return e}function Ie(){var e;return/^[!-']/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[!-']")),e===null&&(/^[*-[]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[*-[]")),e===null&&(/^[\]-~]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\]-~]")),e===null&&(e=F(),e===null&&(e=k())))),e}function Oe(){var e,l,u,f,p,m;if(p=r,m=r,e=D(),e!==null)if(l=I(),l!==null){for(u=[],f=ue(),f===null&&(f=_e());f!==null;)u.push(f),f=ue(),f===null&&(f=_e());u!==null?(f=I(),f!==null?e=[e,l,u,f]:(e=null,r=m)):(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e!==null&&(e=function(v){return a.substring(r,v)}(p)),e===null&&(r=p),e}function pe(){var e,l,u,f,p,m;if(p=r,m=r,e=D(),e!==null)if(l=I(),l!==null){for(u=[],f=ue(),f===null&&(f=_e());f!==null;)u.push(f),f=ue(),f===null&&(f=_e());u!==null?(f=I(),f!==null?e=[e,l,u,f]:(e=null,r=m)):(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e!==null&&(e=function(v){var S=a.substring(r,v).trim();return S.substring(1,S.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(p)),e===null&&(r=p),e}function ue(){var e;return e=k(),e===null&&(a.charCodeAt(r)===33?(e="!",r++):(e=null,_('"!"')),e===null&&(/^[#-[]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[#-[]")),e===null&&(/^[\]-~]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[\\]-~]")),e===null&&(e=F())))),e}function _e(){var e,l,u;return u=r,a.charCodeAt(r)===92?(e="\\",r++):(e=null,_('"\\\\"')),e!==null?(/^[\0-\t]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[\\0-\\t]")),l===null&&(/^[\x0B-\f]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[\\x0B-\\f]")),l===null&&(/^[\x0E-]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[\\x0E-]")))),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function we(){var e,l,u,f,p,m;return p=r,m=r,e=Qe(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=dt(),u=u!==null?u:"",u!==null?(f=es(),f!==null?e=[e,l,u,f]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e!==null&&(e=function(v){try{w.uri=new fs(w.scheme,w.user,w.host,w.port),delete w.scheme,delete w.user,delete w.host,delete w.host_type,delete w.port}catch{w=-1}}()),e===null&&(r=p),e}function Ne(){var e,l,u,f,p,m,v,S;return v=r,S=r,e=Qe(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=dt(),u=u!==null?u:"",u!==null?(f=es(),f!==null?(p=Un(),p!==null?(m=Xs(),m=m!==null?m:"",m!==null?e=[e,l,u,f,p,m]:(e=null,r=S)):(e=null,r=S)):(e=null,r=S)):(e=null,r=S)):(e=null,r=S)):(e=null,r=S),e!==null&&(e=function(O){try{w.uri=new fs(w.scheme,w.user,w.host,w.port,w.uri_params,w.uri_headers),delete w.scheme,delete w.user,delete w.host,delete w.host_type,delete w.port,delete w.uri_params,o==="SIP_URI"&&(w=w.uri)}catch{w=-1}}()),e===null&&(r=v),e}function Qe(){var e;return e=Le(),e===null&&(e=Lt()),e}function Le(){var e,l;return l=r,a.substr(r,4).toLowerCase()==="sips"?(e=a.substr(r,4),r+=4):(e=null,_('"sips"')),e!==null&&(e=function(u,f){w.scheme=f.toLowerCase()}(l,e)),e===null&&(r=l),e}function Lt(){var e,l;return l=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"sip"')),e!==null&&(e=function(u,f){w.scheme=f.toLowerCase()}(l,e)),e===null&&(r=l),e}function dt(){var e,l,u,f,p,m;return f=r,p=r,e=wn(),e!==null?(m=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=Ys(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?(a.charCodeAt(r)===64?(u="@",r++):(u=null,_('"@"')),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w.user=decodeURIComponent(a.substring(r-1,v))}(f)),e===null&&(r=f),e}function wn(){var e,l;if(l=j(),l===null&&(l=ve(),l===null&&(l=On())),l!==null)for(e=[];l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(l=On()));else e=null;return e}function On(){var e;return a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')),e===null&&(a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"'))))))))),e}function Ys(){var e,l,u;for(u=r,e=[],l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","'))))))));l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","'))))))));return e!==null&&(e=function(f){w.password=a.substring(r,f)}(u)),e===null&&(r=u),e}function es(){var e,l,u,f,p;return f=r,e=us(),e!==null?(p=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=Er(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function us(){var e,l;return l=r,e=Js(),e===null&&(e=Wt(),e===null&&(e=zs())),e!==null&&(e=function(u){return w.host=a.substring(r,u).toLowerCase(),w.host}(l)),e===null&&(r=l),e}function Js(){var e,l,u,f,p,m;for(f=r,p=r,e=[],m=r,l=Dn(),l!==null?(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m);l!==null;)e.push(l),m=r,l=Dn(),l!==null?(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m);return e!==null?(l=Nn(),l!==null?(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u=u!==null?u:"",u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){return w.host_type="domain",a.substring(r,v)}(f)),e===null&&(r=f),e}function Dn(){var e,l,u,f;if(f=r,e=oe(),e!==null){for(l=[],u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));u!==null;)l.push(u),u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));l!==null?e=[e,l]:(e=null,r=f)}else e=null,r=f;return e}function Nn(){var e,l,u,f;if(f=r,e=E(),e!==null){for(l=[],u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));u!==null;)l.push(u),u=oe(),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===95?(u="_",r++):(u=null,_('"_"'))));l!==null?e=[e,l]:(e=null,r=f)}else e=null,r=f;return e}function zs(){var e,l,u,f,p;return f=r,p=r,a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e!==null?(l=me(),l!==null?(a.charCodeAt(r)===93?(u="]",r++):(u=null,_('"]"')),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m){return w.host_type="IPv6",a.substring(r,m)}(f)),e===null&&(r=f),e}function me(){var e,l,u,f,p,m,v,S,O,ie,Ue,wt,ks,M,R,Te;return M=r,R=r,e=ae(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?(a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?(a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?(a.charCodeAt(r)===58?(S=":",r++):(S=null,_('":"')),S!==null?(O=ae(),O!==null?(a.charCodeAt(r)===58?(ie=":",r++):(ie=null,_('":"')),ie!==null?(Ue=ae(),Ue!==null?(a.charCodeAt(r)===58?(wt=":",r++):(wt=null,_('":"')),wt!==null?(ks=ot(),ks!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue,wt,ks]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?(a.charCodeAt(r)===58?(O=":",r++):(O=null,_('":"')),O!==null?(ie=ae(),ie!==null?(a.charCodeAt(r)===58?(Ue=":",r++):(Ue=null,_('":"')),Ue!==null?(wt=ot(),wt!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue,wt]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?(a.charCodeAt(r)===58?(O=":",r++):(O=null,_('":"')),O!==null?(ie=ot(),ie!==null?e=[e,l,u,f,p,m,v,S,O,ie]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ot(),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ot(),m!==null?e=[e,l,u,f,p,m]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?(a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ot(),f!==null?e=[e,l,u,f]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ot(),l!==null?e=[e,l]:(e=null,r=R)):(e=null,r=R),e===null&&(R=r,a.substr(r,2)==="::"?(e="::",r+=2):(e=null,_('"::"')),e!==null?(l=ae(),l!==null?e=[e,l]:(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(a.substr(r,2)==="::"?(l="::",r+=2):(l=null,_('"::"')),l!==null?(u=ae(),u!==null?(a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?(a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?(a.charCodeAt(r)===58?(S=":",r++):(S=null,_('":"')),S!==null?(O=ae(),O!==null?(a.charCodeAt(r)===58?(ie=":",r++):(ie=null,_('":"')),ie!==null?(Ue=ot(),Ue!==null?e=[e,l,u,f,p,m,v,S,O,ie,Ue]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(a.substr(r,2)==="::"?(u="::",r+=2):(u=null,_('"::"')),u!==null?(f=ae(),f!==null?(a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?(a.charCodeAt(r)===58?(O=":",r++):(O=null,_('":"')),O!==null?(ie=ot(),ie!==null?e=[e,l,u,f,p,m,v,S,O,ie]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(a.substr(r,2)==="::"?(f="::",r+=2):(f=null,_('"::"')),f!==null?(p=ae(),p!==null?(a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?(a.charCodeAt(r)===58?(S=":",r++):(S=null,_('":"')),S!==null?(O=ot(),O!==null?e=[e,l,u,f,p,m,v,S,O]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(a.substr(r,2)==="::"?(p="::",r+=2):(p=null,_('"::"')),p!==null?(m=ae(),m!==null?(a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ot(),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(Te=r,a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?p=[p,m]:(p=null,r=Te)):(p=null,r=Te),p=p!==null?p:"",p!==null?(a.substr(r,2)==="::"?(m="::",r+=2):(m=null,_('"::"')),m!==null?(v=ot(),v!==null?e=[e,l,u,f,p,m,v]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(Te=r,a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?p=[p,m]:(p=null,r=Te)):(p=null,r=Te),p=p!==null?p:"",p!==null?(Te=r,a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?m=[m,v]:(m=null,r=Te)):(m=null,r=Te),m=m!==null?m:"",m!==null?(a.substr(r,2)==="::"?(v="::",r+=2):(v=null,_('"::"')),v!==null?(S=ae(),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R),e===null&&(R=r,e=ae(),e!==null?(Te=r,a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?l=[l,u]:(l=null,r=Te)):(l=null,r=Te),l=l!==null?l:"",l!==null?(Te=r,a.charCodeAt(r)===58?(u=":",r++):(u=null,_('":"')),u!==null?(f=ae(),f!==null?u=[u,f]:(u=null,r=Te)):(u=null,r=Te),u=u!==null?u:"",u!==null?(Te=r,a.charCodeAt(r)===58?(f=":",r++):(f=null,_('":"')),f!==null?(p=ae(),p!==null?f=[f,p]:(f=null,r=Te)):(f=null,r=Te),f=f!==null?f:"",f!==null?(Te=r,a.charCodeAt(r)===58?(p=":",r++):(p=null,_('":"')),p!==null?(m=ae(),m!==null?p=[p,m]:(p=null,r=Te)):(p=null,r=Te),p=p!==null?p:"",p!==null?(Te=r,a.charCodeAt(r)===58?(m=":",r++):(m=null,_('":"')),m!==null?(v=ae(),v!==null?m=[m,v]:(m=null,r=Te)):(m=null,r=Te),m=m!==null?m:"",m!==null?(Te=r,a.charCodeAt(r)===58?(v=":",r++):(v=null,_('":"')),v!==null?(S=ae(),S!==null?v=[v,S]:(v=null,r=Te)):(v=null,r=Te),v=v!==null?v:"",v!==null?(a.substr(r,2)==="::"?(S="::",r+=2):(S=null,_('"::"')),S!==null?e=[e,l,u,f,p,m,v,S]:(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R)):(e=null,r=R))))))))))))))),e!==null&&(e=function($h){return w.host_type="IPv6",a.substring(r,$h)}(M)),e===null&&(r=M),e}function ae(){var e,l,u,f,p;return p=r,e=y(),e!==null?(l=y(),l=l!==null?l:"",l!==null?(u=y(),u=u!==null?u:"",u!==null?(f=y(),f=f!==null?f:"",f!==null?e=[e,l,u,f]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e}function ot(){var e,l,u,f;return f=r,e=ae(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=ae(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e===null&&(e=Wt()),e}function Wt(){var e,l,u,f,p,m,v,S,O;return S=r,O=r,e=As(),e!==null?(a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l!==null?(u=As(),u!==null?(a.charCodeAt(r)===46?(f=".",r++):(f=null,_('"."')),f!==null?(p=As(),p!==null?(a.charCodeAt(r)===46?(m=".",r++):(m=null,_('"."')),m!==null?(v=As(),v!==null?e=[e,l,u,f,p,m,v]:(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O)):(e=null,r=O),e!==null&&(e=function(ie){return w.host_type="IPv4",a.substring(r,ie)}(S)),e===null&&(r=S),e}function As(){var e,l,u,f;return f=r,a.substr(r,2)==="25"?(e="25",r+=2):(e=null,_('"25"')),e!==null?(/^[0-5]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[0-5]")),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e===null&&(f=r,a.charCodeAt(r)===50?(e="2",r++):(e=null,_('"2"')),e!==null?(/^[0-4]/.test(a.charAt(r))?(l=a.charAt(r),r++):(l=null,_("[0-4]")),l!==null?(u=T(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e===null&&(f=r,a.charCodeAt(r)===49?(e="1",r++):(e=null,_('"1"')),e!==null?(l=T(),l!==null?(u=T(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e===null&&(f=r,/^[1-9]/.test(a.charAt(r))?(e=a.charAt(r),r++):(e=null,_("[1-9]")),e!==null?(l=T(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e===null&&(e=T())))),e}function Er(){var e,l,u,f,p,m,v;return m=r,v=r,e=T(),e=e!==null?e:"",e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?e=[e,l,u,f,p]:(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(S,O){return O=parseInt(O.join("")),w.port=O,O}(m,e)),e===null&&(r=m),e}function Un(){var e,l,u,f;for(e=[],f=r,a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l!==null?(u=Pn(),u!==null?l=[l,u]:(l=null,r=f)):(l=null,r=f);l!==null;)e.push(l),f=r,a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l!==null?(u=Pn(),u!==null?l=[l,u]:(l=null,r=f)):(l=null,r=f);return e}function Pn(){var e;return e=Sr(),e===null&&(e=yr(),e===null&&(e=Cr(),e===null&&(e=Ar(),e===null&&(e=Rr(),e===null&&(e=Ir(),e===null&&(e=br())))))),e}function Sr(){var e,l,u,f;return u=r,f=r,a.substr(r,10).toLowerCase()==="transport="?(e=a.substr(r,10),r+=10):(e=null,_('"transport="')),e!==null?(a.substr(r,3).toLowerCase()==="udp"?(l=a.substr(r,3),r+=3):(l=null,_('"udp"')),l===null&&(a.substr(r,3).toLowerCase()==="tcp"?(l=a.substr(r,3),r+=3):(l=null,_('"tcp"')),l===null&&(a.substr(r,4).toLowerCase()==="sctp"?(l=a.substr(r,4),r+=4):(l=null,_('"sctp"')),l===null&&(a.substr(r,3).toLowerCase()==="tls"?(l=a.substr(r,3),r+=3):(l=null,_('"tls"')),l===null&&(l=P())))),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.transport=m.toLowerCase()}(u,e[1])),e===null&&(r=u),e}function yr(){var e,l,u,f;return u=r,f=r,a.substr(r,5).toLowerCase()==="user="?(e=a.substr(r,5),r+=5):(e=null,_('"user="')),e!==null?(a.substr(r,5).toLowerCase()==="phone"?(l=a.substr(r,5),r+=5):(l=null,_('"phone"')),l===null&&(a.substr(r,2).toLowerCase()==="ip"?(l=a.substr(r,2),r+=2):(l=null,_('"ip"')),l===null&&(l=P())),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.user=m.toLowerCase()}(u,e[1])),e===null&&(r=u),e}function Cr(){var e,l,u,f;return u=r,f=r,a.substr(r,7).toLowerCase()==="method="?(e=a.substr(r,7),r+=7):(e=null,_('"method="')),e!==null?(l=rn(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.method=m}(u,e[1])),e===null&&(r=u),e}function Ar(){var e,l,u,f;return u=r,f=r,a.substr(r,4).toLowerCase()==="ttl="?(e=a.substr(r,4),r+=4):(e=null,_('"ttl="')),e!==null?(l=Ai(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.params||(w.params={}),w.params.ttl=m}(u,e[1])),e===null&&(r=u),e}function Rr(){var e,l,u,f;return u=r,f=r,a.substr(r,6).toLowerCase()==="maddr="?(e=a.substr(r,6),r+=6):(e=null,_('"maddr="')),e!==null?(l=us(),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e!==null&&(e=function(p,m){w.uri_params||(w.uri_params={}),w.uri_params.maddr=m}(u,e[1])),e===null&&(r=u),e}function Ir(){var e,l,u,f,p,m;return f=r,p=r,a.substr(r,2).toLowerCase()==="lr"?(e=a.substr(r,2),r+=2):(e=null,_('"lr"')),e!==null?(m=r,a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=P(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w.uri_params||(w.uri_params={}),w.uri_params.lr=void 0}()),e===null&&(r=f),e}function br(){var e,l,u,f,p,m;return f=r,p=r,e=wr(),e!==null?(m=r,a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=Rs(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v,S,O){w.uri_params||(w.uri_params={}),typeof O>"u"?O=void 0:O=O[1],w.uri_params[S.toLowerCase()]=O}(f,e[0],e[1])),e===null&&(r=f),e}function wr(){var e,l,u;if(u=r,l=Is(),l!==null)for(e=[];l!==null;)e.push(l),l=Is();else e=null;return e!==null&&(e=function(f,p){return p.join("")}(u,e)),e===null&&(r=u),e}function Rs(){var e,l,u;if(u=r,l=Is(),l!==null)for(e=[];l!==null;)e.push(l),l=Is();else e=null;return e!==null&&(e=function(f,p){return p.join("")}(u,e)),e===null&&(r=u),e}function Is(){var e;return e=Or(),e===null&&(e=j(),e===null&&(e=ve())),e}function Or(){var e;return a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e===null&&(a.charCodeAt(r)===93?(e="]",r++):(e=null,_('"]"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')))))))),e}function Xs(){var e,l,u,f,p,m,v;if(m=r,a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e!==null)if(l=Qs(),l!==null){for(u=[],v=r,a.charCodeAt(r)===38?(f="&",r++):(f=null,_('"&"')),f!==null?(p=Qs(),p!==null?f=[f,p]:(f=null,r=v)):(f=null,r=v);f!==null;)u.push(f),v=r,a.charCodeAt(r)===38?(f="&",r++):(f=null,_('"&"')),f!==null?(p=Qs(),p!==null?f=[f,p]:(f=null,r=v)):(f=null,r=v);u!==null?e=[e,l,u]:(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e}function Qs(){var e,l,u,f,p;return f=r,p=r,e=Dr(),e!==null?(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l!==null?(u=bs(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v,S){v=v.join("").toLowerCase(),S=S.join(""),w.uri_headers||(w.uri_headers={}),w.uri_headers[v]?w.uri_headers[v].push(S):w.uri_headers[v]=[S]}(f,e[0],e[2])),e===null&&(r=f),e}function Dr(){var e,l;if(l=Zs(),l===null&&(l=j(),l===null&&(l=ve())),l!==null)for(e=[];l!==null;)e.push(l),l=Zs(),l===null&&(l=j(),l===null&&(l=ve()));else e=null;return e}function bs(){var e,l;for(e=[],l=Zs(),l===null&&(l=j(),l===null&&(l=ve()));l!==null;)e.push(l),l=Zs(),l===null&&(l=j(),l===null&&(l=ve()));return e}function Zs(){var e;return a.charCodeAt(r)===91?(e="[",r++):(e=null,_('"["')),e===null&&(a.charCodeAt(r)===93?(e="]",r++):(e=null,_('"]"')),e===null&&(a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')))))))),e}function gl(){var e;return e=Wr(),e===null&&(e=Nr()),e}function Nr(){var e,l,u,f,p,m;return m=r,e=rn(),e!==null?(l=H(),l!==null?(u=xn(),u!==null?(f=H(),f!==null?(p=Ln(),p!==null?e=[e,l,u,f,p]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e}function xn(){var e;return e=Ne(),e===null&&(e=kn()),e}function kn(){var e,l,u,f;return f=r,e=xr(),e!==null?(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l!==null?(u=Ur(),u===null&&(u=ws()),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Ur(){var e,l,u,f,p;return f=r,e=en(),e===null&&(e=tn()),e!==null?(p=r,a.charCodeAt(r)===63?(l="?",r++):(l=null,_('"?"')),l!==null?(u=Mn(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function en(){var e,l,u,f;return f=r,a.substr(r,2)==="//"?(e="//",r+=2):(e=null,_('"//"')),e!==null?(l=kr(),l!==null?(u=tn(),u=u!==null?u:"",u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function tn(){var e,l,u;return u=r,a.charCodeAt(r)===47?(e="/",r++):(e=null,_('"/"')),e!==null?(l=sn(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function ws(){var e,l,u,f;if(f=r,e=Pr(),e!==null){for(l=[],u=Os();u!==null;)l.push(u),u=Os();l!==null?e=[e,l]:(e=null,r=f)}else e=null,r=f;return e}function Os(){var e;return e=N(),e===null&&(e=j(),e===null&&(e=ve())),e}function Pr(){var e;return e=j(),e===null&&(e=ve(),e===null&&(a.charCodeAt(r)===59?(e=";",r++):(e=null,_('";"')),e===null&&(a.charCodeAt(r)===63?(e="?",r++):(e=null,_('"?"')),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')))))))))))),e}function sn(){var e,l,u,f,p,m;if(p=r,e=Ds(),e!==null){for(l=[],m=r,a.charCodeAt(r)===47?(u="/",r++):(u=null,_('"/"')),u!==null?(f=Ds(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,a.charCodeAt(r)===47?(u="/",r++):(u=null,_('"/"')),u!==null?(f=Ds(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Ds(){var e,l,u,f,p,m;for(p=r,e=[],l=Ns();l!==null;)e.push(l),l=Ns();if(e!==null){for(l=[],m=r,a.charCodeAt(r)===59?(u=";",r++):(u=null,_('";"')),u!==null?(f=cs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,a.charCodeAt(r)===59?(u=";",r++):(u=null,_('";"')),u!==null?(f=cs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function cs(){var e,l;for(e=[],l=Ns();l!==null;)e.push(l),l=Ns();return e}function Ns(){var e;return e=j(),e===null&&(e=ve(),e===null&&(a.charCodeAt(r)===58?(e=":",r++):(e=null,_('":"')),e===null&&(a.charCodeAt(r)===64?(e="@",r++):(e=null,_('"@"')),e===null&&(a.charCodeAt(r)===38?(e="&",r++):(e=null,_('"&"')),e===null&&(a.charCodeAt(r)===61?(e="=",r++):(e=null,_('"="')),e===null&&(a.charCodeAt(r)===43?(e="+",r++):(e=null,_('"+"')),e===null&&(a.charCodeAt(r)===36?(e="$",r++):(e=null,_('"$"')),e===null&&(a.charCodeAt(r)===44?(e=",",r++):(e=null,_('","')))))))))),e}function xr(){var e,l,u,f,p;if(f=r,p=r,e=E(),e!==null){for(l=[],u=E(),u===null&&(u=T(),u===null&&(a.charCodeAt(r)===43?(u="+",r++):(u=null,_('"+"')),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."'))))));u!==null;)l.push(u),u=E(),u===null&&(u=T(),u===null&&(a.charCodeAt(r)===43?(u="+",r++):(u=null,_('"+"')),u===null&&(a.charCodeAt(r)===45?(u="-",r++):(u=null,_('"-"')),u===null&&(a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."'))))));l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e!==null&&(e=function(m){w.scheme=a.substring(r,m)}(f)),e===null&&(r=f),e}function kr(){var e;return e=Mr(),e===null&&(e=Lr()),e}function Mr(){var e,l,u,f;return u=r,f=r,e=dt(),e!==null?(a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e=e!==null?e:"",e!==null?(l=es(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e=e!==null?e:"",e}function Lr(){var e,l;if(l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","')),l===null&&(a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"'))))))))))),l!==null)for(e=[];l!==null;)e.push(l),l=j(),l===null&&(l=ve(),l===null&&(a.charCodeAt(r)===36?(l="$",r++):(l=null,_('"$"')),l===null&&(a.charCodeAt(r)===44?(l=",",r++):(l=null,_('","')),l===null&&(a.charCodeAt(r)===59?(l=";",r++):(l=null,_('";"')),l===null&&(a.charCodeAt(r)===58?(l=":",r++):(l=null,_('":"')),l===null&&(a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l===null&&(a.charCodeAt(r)===38?(l="&",r++):(l=null,_('"&"')),l===null&&(a.charCodeAt(r)===61?(l="=",r++):(l=null,_('"="')),l===null&&(a.charCodeAt(r)===43?(l="+",r++):(l=null,_('"+"')))))))))));else e=null;return e}function Mn(){var e,l;for(e=[],l=Os();l!==null;)e.push(l),l=Os();return e}function Ln(){var e,l,u,f,p,m,v,S;if(v=r,S=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"SIP"')),e!==null)if(a.charCodeAt(r)===47?(l="/",r++):(l=null,_('"/"')),l!==null){if(f=T(),f!==null)for(u=[];f!==null;)u.push(f),f=T();else u=null;if(u!==null)if(a.charCodeAt(r)===46?(f=".",r++):(f=null,_('"."')),f!==null){if(m=T(),m!==null)for(p=[];m!==null;)p.push(m),m=T();else p=null;p!==null?e=[e,l,u,f,p]:(e=null,r=S)}else e=null,r=S;else e=null,r=S}else e=null,r=S;else e=null,r=S;return e!==null&&(e=function(O){w.sip_version=a.substring(r,O)}(v)),e===null&&(r=v),e}function $r(){var e;return a.substr(r,6)==="INVITE"?(e="INVITE",r+=6):(e=null,_('"INVITE"')),e}function Hr(){var e;return a.substr(r,3)==="ACK"?(e="ACK",r+=3):(e=null,_('"ACK"')),e}function Fr(){var e;return a.substr(r,7)==="OPTIONS"?(e="OPTIONS",r+=7):(e=null,_('"OPTIONS"')),e}function jr(){var e;return a.substr(r,3)==="BYE"?(e="BYE",r+=3):(e=null,_('"BYE"')),e}function qr(){var e;return a.substr(r,6)==="CANCEL"?(e="CANCEL",r+=6):(e=null,_('"CANCEL"')),e}function Vr(){var e;return a.substr(r,8)==="REGISTER"?(e="REGISTER",r+=8):(e=null,_('"REGISTER"')),e}function Br(){var e;return a.substr(r,9)==="SUBSCRIBE"?(e="SUBSCRIBE",r+=9):(e=null,_('"SUBSCRIBE"')),e}function Gr(){var e;return a.substr(r,6)==="NOTIFY"?(e="NOTIFY",r+=6):(e=null,_('"NOTIFY"')),e}function nn(){var e;return a.substr(r,5)==="REFER"?(e="REFER",r+=5):(e=null,_('"REFER"')),e}function rn(){var e,l;return l=r,e=$r(),e===null&&(e=Hr(),e===null&&(e=Fr(),e===null&&(e=jr(),e===null&&(e=qr(),e===null&&(e=Vr(),e===null&&(e=Br(),e===null&&(e=Gr(),e===null&&(e=nn(),e===null&&(e=P()))))))))),e!==null&&(e=function(u){return w.method=a.substring(r,u),w.method}(l)),e===null&&(r=l),e}function Wr(){var e,l,u,f,p,m;return m=r,e=Ln(),e!==null?(l=H(),l!==null?(u=Kr(),u!==null?(f=H(),f!==null?(p=Tl(),p!==null?e=[e,l,u,f,p]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e}function Kr(){var e,l;return l=r,e=Yr(),e!==null&&(e=function(u,f){w.status_code=parseInt(f.join(""))}(l,e)),e===null&&(r=l),e}function Yr(){var e,l,u,f;return f=r,e=T(),e!==null?(l=T(),l!==null?(u=T(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Tl(){var e,l,u;for(u=r,e=[],l=N(),l===null&&(l=j(),l===null&&(l=ve(),l===null&&(l=F(),l===null&&(l=X(),l===null&&(l=H(),l===null&&(l=$()))))));l!==null;)e.push(l),l=N(),l===null&&(l=j(),l===null&&(l=ve(),l===null&&(l=F(),l===null&&(l=X(),l===null&&(l=H(),l===null&&(l=$()))))));return e!==null&&(e=function(f){w.reason_phrase=a.substring(r,f)}(u)),e===null&&(r=u),e}function Ja(){var e,l,u,f,p,m;if(p=r,e=un(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=un(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=un(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function za(){var e,l,u,f,p,m;return f=r,p=r,e=ee(),e!==null?(m=r,a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l!==null?(u=ee(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w=a.substring(r,v)}(f)),e===null&&(r=f),e}function $n(){var e,l,u,f,p,m,v;if(p=r,e=W(),e===null)if(m=r,e=$t(),e!==null){for(l=[],v=r,u=le(),u!==null?(f=$t(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=le(),u!==null?(f=$t(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O,ie;for(ie=w.multi_header.length,O=0;O<ie;O++)if(w.multi_header[O].parsed===null){w=null;break}w!==null?w=w.multi_header:w=-1}()),e===null&&(r=p),e}function $t(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Ht()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=Hn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=Hn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O;w.multi_header||(w.multi_header=[]);try{O=new b(w.uri,w.display_name,w.params),delete w.uri,delete w.display_name,delete w.params}catch{O=null}w.multi_header.push({possition:r,offset:S,parsed:O})}(p)),e===null&&(r=p),e}function Ht(){var e,l,u,f,p;return p=r,e=Us(),e=e!==null?e:"",e!==null?(l=Ae(),l!==null?(u=Ne(),u!==null?(f=xe(),f!==null?e=[e,l,u,f]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e}function Us(){var e,l,u,f,p,m,v;if(p=r,m=r,e=P(),e!==null){for(l=[],v=r,u=k(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=k(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e===null&&(e=pe()),e!==null&&(e=function(S,O){typeof O=="string"?w.display_name=O:w.display_name=O[1].reduce(function(ie,Ue){return ie+Ue[0]+Ue[1]},O[0])}(p,e)),e===null&&(r=p),e}function Hn(){var e;return e=Jr(),e===null&&(e=ts(),e===null&&(e=We())),e}function Jr(){var e,l,u,f,p;return f=r,p=r,a.substr(r,1).toLowerCase()==="q"?(e=a.substr(r,1),r++):(e=null,_('"q"')),e!==null?(l=re(),l!==null?(u=Ge(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.params||(w.params={}),w.params.q=v}(f,e[2])),e===null&&(r=f),e}function ts(){var e,l,u,f,p;return f=r,p=r,a.substr(r,7).toLowerCase()==="expires"?(e=a.substr(r,7),r+=7):(e=null,_('"expires"')),e!==null?(l=re(),l!==null?(u=ss(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.params||(w.params={}),w.params.expires=v}(f,e[2])),e===null&&(r=f),e}function ss(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){return parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function Ge(){var e,l,u,f,p,m,v,S;return m=r,v=r,a.charCodeAt(r)===48?(e="0",r++):(e=null,_('"0"')),e!==null?(S=r,a.charCodeAt(r)===46?(l=".",r++):(l=null,_('"."')),l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?l=[l,u,f,p]:(l=null,r=S)):(l=null,r=S)):(l=null,r=S)):(l=null,r=S),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(O){return parseFloat(a.substring(r,O))}(m)),e===null&&(r=m),e}function We(){var e,l,u,f,p,m;return f=r,p=r,e=P(),e!==null?(m=r,l=re(),l!==null?(u=vl(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v,S,O){w.params||(w.params={}),typeof O>"u"?O=void 0:O=O[1],w.params[S.toLowerCase()]=O}(f,e[0],e[1])),e===null&&(r=f),e}function vl(){var e;return e=P(),e===null&&(e=us(),e===null&&(e=Oe())),e}function El(){var e,l,u,f,p,m;if(p=r,e=Fn(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=jn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=jn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Fn(){var e;return a.substr(r,6).toLowerCase()==="render"?(e=a.substr(r,6),r+=6):(e=null,_('"render"')),e===null&&(a.substr(r,7).toLowerCase()==="session"?(e=a.substr(r,7),r+=7):(e=null,_('"session"')),e===null&&(a.substr(r,4).toLowerCase()==="icon"?(e=a.substr(r,4),r+=4):(e=null,_('"icon"')),e===null&&(a.substr(r,5).toLowerCase()==="alert"?(e=a.substr(r,5),r+=5):(e=null,_('"alert"')),e===null&&(e=P())))),e}function jn(){var e;return e=Sl(),e===null&&(e=We()),e}function Sl(){var e,l,u,f;return f=r,a.substr(r,8).toLowerCase()==="handling"?(e=a.substr(r,8),r+=8):(e=null,_('"handling"')),e!==null?(l=re(),l!==null?(a.substr(r,8).toLowerCase()==="optional"?(u=a.substr(r,8),r+=8):(u=null,_('"optional"')),u===null&&(a.substr(r,8).toLowerCase()==="required"?(u=a.substr(r,8),r+=8):(u=null,_('"required"')),u===null&&(u=P())),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Xa(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Qa(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){w=parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function yl(){var e,l;return l=r,e=zr(),e!==null&&(e=function(u){w=a.substring(r,u)}(l)),e===null&&(r=l),e}function zr(){var e,l,u,f,p,m,v,S;if(v=r,e=Xr(),e!==null)if(l=G(),l!==null)if(u=qn(),u!==null){for(f=[],S=r,p=ye(),p!==null?(m=Vn(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=ye(),p!==null?(m=Vn(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e}function Xr(){var e;return e=Qr(),e===null&&(e=ln()),e}function Qr(){var e;return a.substr(r,4).toLowerCase()==="text"?(e=a.substr(r,4),r+=4):(e=null,_('"text"')),e===null&&(a.substr(r,5).toLowerCase()==="image"?(e=a.substr(r,5),r+=5):(e=null,_('"image"')),e===null&&(a.substr(r,5).toLowerCase()==="audio"?(e=a.substr(r,5),r+=5):(e=null,_('"audio"')),e===null&&(a.substr(r,5).toLowerCase()==="video"?(e=a.substr(r,5),r+=5):(e=null,_('"video"')),e===null&&(a.substr(r,11).toLowerCase()==="application"?(e=a.substr(r,11),r+=11):(e=null,_('"application"')),e===null&&(e=an()))))),e}function ln(){var e;return a.substr(r,7).toLowerCase()==="message"?(e=a.substr(r,7),r+=7):(e=null,_('"message"')),e===null&&(a.substr(r,9).toLowerCase()==="multipart"?(e=a.substr(r,9),r+=9):(e=null,_('"multipart"')),e===null&&(e=an())),e}function an(){var e;return e=P(),e===null&&(e=Zr()),e}function Zr(){var e,l,u;return u=r,a.substr(r,2).toLowerCase()==="x-"?(e=a.substr(r,2),r+=2):(e=null,_('"x-"')),e!==null?(l=P(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function qn(){var e;return e=an(),e===null&&(e=P()),e}function Vn(){var e,l,u,f;return f=r,e=P(),e!==null?(l=re(),l!==null?(u=Cl(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Cl(){var e;return e=P(),e===null&&(e=Oe()),e}function Al(){var e,l,u,f;return f=r,e=Rl(),e!==null?(l=k(),l!==null?(u=rn(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Rl(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){w.value=parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function Za(){var e,l;return l=r,e=ss(),e!==null&&(e=function(u,f){w=f}(l,e)),e===null&&(r=l),e}function on(){var e,l,u,f,p,m,v;if(p=r,m=r,e=un(),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S,O){w.event=O.join("").toLowerCase()}(p,e[0])),e===null&&(r=p),e}function un(){var e,l,u,f,p,m;if(p=r,e=se(),e!==null){for(l=[],m=r,a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?(f=se(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,a.charCodeAt(r)===46?(u=".",r++):(u=null,_('"."')),u!==null?(f=se(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function ei(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Ht()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=cn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=cn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O=w.tag;try{w=new b(w.uri,w.display_name,w.params),O&&w.setParam("tag",O)}catch{w=-1}}()),e===null&&(r=p),e}function cn(){var e;return e=ti(),e===null&&(e=We()),e}function ti(){var e,l,u,f,p;return f=r,p=r,a.substr(r,3).toLowerCase()==="tag"?(e=a.substr(r,3),r+=3):(e=null,_('"tag"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.tag=v}(f,e[2])),e===null&&(r=f),e}function eo(){var e,l,u;if(u=r,l=T(),l!==null)for(e=[];l!==null;)e.push(l),l=T();else e=null;return e!==null&&(e=function(f,p){w=parseInt(p.join(""))}(u,e)),e===null&&(r=u),e}function to(){var e,l;return l=r,e=ss(),e!==null&&(e=function(u,f){w=f}(l,e)),e===null&&(r=l),e}function so(){var e,l,u,f,p,m,v,S,O,ie;for(S=r,O=r,e=[],l=Us();l!==null;)e.push(l),l=Us();if(e!==null)if(l=Ae(),l!==null)if(u=Ne(),u!==null)if(f=xe(),f!==null){for(p=[],ie=r,m=ye(),m!==null?(v=We(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);m!==null;)p.push(m),ie=r,m=ye(),m!==null?(v=We(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);p!==null?e=[e,l,u,f,p]:(e=null,r=O)}else e=null,r=O;else e=null,r=O;else e=null,r=O;else e=null,r=O;return e!==null&&(e=function(Ue){try{w=new b(w.uri,w.display_name,w.params)}catch{w=-1}}()),e===null&&(r=S),e}function si(){var e;return e=Bn(),e}function Bn(){var e,l,u,f,p,m,v,S;if(v=r,a.substr(r,6).toLowerCase()==="digest"?(e=a.substr(r,6),r+=6):(e=null,_('"Digest"')),e!==null)if(l=k(),l!==null)if(u=fn(),u!==null){for(f=[],S=r,p=le(),p!==null?(m=fn(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=le(),p!==null?(m=fn(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e===null&&(e=Ps()),e}function Ps(){var e,l,u,f,p,m,v,S;if(v=r,e=P(),e!==null)if(l=k(),l!==null)if(u=ns(),u!==null){for(f=[],S=r,p=le(),p!==null?(m=ns(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=le(),p!==null?(m=ns(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e}function ns(){var e,l,u,f;return f=r,e=P(),e!==null?(l=re(),l!==null?(u=P(),u===null&&(u=Oe()),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function fn(){var e;return e=ni(),e===null&&(e=hn(),e===null&&(e=ii(),e===null&&(e=ai(),e===null&&(e=oi(),e===null&&(e=ui(),e===null&&(e=_n(),e===null&&(e=ns()))))))),e}function ni(){var e,l,u,f;return f=r,a.substr(r,5).toLowerCase()==="realm"?(e=a.substr(r,5),r+=5):(e=null,_('"realm"')),e!==null?(l=re(),l!==null?(u=ri(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function ri(){var e,l;return l=r,e=pe(),e!==null&&(e=function(u,f){w.realm=f}(l,e)),e===null&&(r=l),e}function hn(){var e,l,u,f,p,m,v,S,O;if(S=r,a.substr(r,6).toLowerCase()==="domain"?(e=a.substr(r,6),r+=6):(e=null,_('"domain"')),e!==null)if(l=re(),l!==null)if(u=at(),u!==null)if(f=dn(),f!==null){if(p=[],O=r,v=H(),v!==null)for(m=[];v!==null;)m.push(v),v=H();else m=null;for(m!==null?(v=dn(),v!==null?m=[m,v]:(m=null,r=O)):(m=null,r=O);m!==null;){if(p.push(m),O=r,v=H(),v!==null)for(m=[];v!==null;)m.push(v),v=H();else m=null;m!==null?(v=dn(),v!==null?m=[m,v]:(m=null,r=O)):(m=null,r=O)}p!==null?(m=Ee(),m!==null?e=[e,l,u,f,p,m]:(e=null,r=S)):(e=null,r=S)}else e=null,r=S;else e=null,r=S;else e=null,r=S;else e=null,r=S;return e}function dn(){var e;return e=kn(),e===null&&(e=tn()),e}function ii(){var e,l,u,f;return f=r,a.substr(r,5).toLowerCase()==="nonce"?(e=a.substr(r,5),r+=5):(e=null,_('"nonce"')),e!==null?(l=re(),l!==null?(u=li(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function li(){var e,l;return l=r,e=pe(),e!==null&&(e=function(u,f){w.nonce=f}(l,e)),e===null&&(r=l),e}function ai(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6).toLowerCase()==="opaque"?(e=a.substr(r,6),r+=6):(e=null,_('"opaque"')),e!==null?(l=re(),l!==null?(u=pe(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.opaque=v}(f,e[2])),e===null&&(r=f),e}function oi(){var e,l,u,f,p;return f=r,a.substr(r,5).toLowerCase()==="stale"?(e=a.substr(r,5),r+=5):(e=null,_('"stale"')),e!==null?(l=re(),l!==null?(p=r,a.substr(r,4).toLowerCase()==="true"?(u=a.substr(r,4),r+=4):(u=null,_('"true"')),u!==null&&(u=function(m){w.stale=!0}()),u===null&&(r=p),u===null&&(p=r,a.substr(r,5).toLowerCase()==="false"?(u=a.substr(r,5),r+=5):(u=null,_('"false"')),u!==null&&(u=function(m){w.stale=!1}()),u===null&&(r=p)),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function ui(){var e,l,u,f,p;return f=r,p=r,a.substr(r,9).toLowerCase()==="algorithm"?(e=a.substr(r,9),r+=9):(e=null,_('"algorithm"')),e!==null?(l=re(),l!==null?(a.substr(r,3).toLowerCase()==="md5"?(u=a.substr(r,3),r+=3):(u=null,_('"MD5"')),u===null&&(a.substr(r,8).toLowerCase()==="md5-sess"?(u=a.substr(r,8),r+=8):(u=null,_('"MD5-sess"')),u===null&&(u=P())),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.algorithm=v.toUpperCase()}(f,e[2])),e===null&&(r=f),e}function _n(){var e,l,u,f,p,m,v,S,O,ie;if(S=r,a.substr(r,3).toLowerCase()==="qop"?(e=a.substr(r,3),r+=3):(e=null,_('"qop"')),e!==null)if(l=re(),l!==null)if(u=at(),u!==null){if(O=r,f=Gn(),f!==null){for(p=[],ie=r,a.charCodeAt(r)===44?(m=",",r++):(m=null,_('","')),m!==null?(v=Gn(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);m!==null;)p.push(m),ie=r,a.charCodeAt(r)===44?(m=",",r++):(m=null,_('","')),m!==null?(v=Gn(),v!==null?m=[m,v]:(m=null,r=ie)):(m=null,r=ie);p!==null?f=[f,p]:(f=null,r=O)}else f=null,r=O;f!==null?(p=Ee(),p!==null?e=[e,l,u,f,p]:(e=null,r=S)):(e=null,r=S)}else e=null,r=S;else e=null,r=S;else e=null,r=S;return e}function Gn(){var e,l;return l=r,a.substr(r,8).toLowerCase()==="auth-int"?(e=a.substr(r,8),r+=8):(e=null,_('"auth-int"')),e===null&&(a.substr(r,4).toLowerCase()==="auth"?(e=a.substr(r,4),r+=4):(e=null,_('"auth"')),e===null&&(e=P())),e!==null&&(e=function(u,f){w.qop||(w.qop=[]),w.qop.push(f.toLowerCase())}(l,e)),e===null&&(r=l),e}function no(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Wn(){var e,l,u,f,p,m,v;if(p=r,m=r,e=Kn(),e!==null){for(l=[],v=r,u=le(),u!==null?(f=Kn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=le(),u!==null?(f=Kn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O,ie;for(ie=w.multi_header.length,O=0;O<ie;O++)if(w.multi_header[O].parsed===null){w=null;break}w!==null?w=w.multi_header:w=-1}()),e===null&&(r=p),e}function Kn(){var e,l,u,f,p,m,v;if(p=r,m=r,e=Ht(),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O;w.multi_header||(w.multi_header=[]);try{O=new b(w.uri,w.display_name,w.params),delete w.uri,delete w.display_name,delete w.params}catch{O=null}w.multi_header.push({possition:r,offset:S,parsed:O})}(p)),e===null&&(r=p),e}function ci(){var e,l,u,f,p,m,v;if(p=r,m=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"SIP"')),e===null&&(e=P()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=Yn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=Yn(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S,O){if(w.protocol=O.toLowerCase(),w.params||(w.params={}),w.params.text&&w.params.text[0]==='"'){var ie=w.params.text;w.text=ie.substring(1,ie.length-1),delete w.params.text}}(p,e[0])),e===null&&(r=p),e}function Yn(){var e;return e=Il(),e===null&&(e=We()),e}function Il(){var e,l,u,f,p,m;if(p=r,m=r,a.substr(r,5).toLowerCase()==="cause"?(e=a.substr(r,5),r+=5):(e=null,_('"cause"')),e!==null)if(l=re(),l!==null){if(f=T(),f!==null)for(u=[];f!==null;)u.push(f),f=T();else u=null;u!==null?e=[e,l,u]:(e=null,r=m)}else e=null,r=m;else e=null,r=m;return e!==null&&(e=function(v,S){w.cause=parseInt(S.join(""))}(p,e[2])),e===null&&(r=p),e}function ro(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Jn(){var e,l,u,f,p,m;if(p=r,e=zn(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=zn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=zn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function zn(){var e,l,u,f,p,m;if(p=r,e=Ht(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function bl(){var e,l,u,f,p,m;if(p=r,e=Xn(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=Qn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=Qn(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function Xn(){var e,l;return l=r,a.substr(r,6).toLowerCase()==="active"?(e=a.substr(r,6),r+=6):(e=null,_('"active"')),e===null&&(a.substr(r,7).toLowerCase()==="pending"?(e=a.substr(r,7),r+=7):(e=null,_('"pending"')),e===null&&(a.substr(r,10).toLowerCase()==="terminated"?(e=a.substr(r,10),r+=10):(e=null,_('"terminated"')),e===null&&(e=P()))),e!==null&&(e=function(u){w.state=a.substring(r,u)}(l)),e===null&&(r=l),e}function Qn(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6).toLowerCase()==="reason"?(e=a.substr(r,6),r+=6):(e=null,_('"reason"')),e!==null?(l=re(),l!==null?(u=wl(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){typeof v<"u"&&(w.reason=v)}(f,e[2])),e===null&&(r=f),e===null&&(f=r,p=r,a.substr(r,7).toLowerCase()==="expires"?(e=a.substr(r,7),r+=7):(e=null,_('"expires"')),e!==null?(l=re(),l!==null?(u=ss(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){typeof v<"u"&&(w.expires=v)}(f,e[2])),e===null&&(r=f),e===null&&(f=r,p=r,a.substr(r,11).toLowerCase()==="retry_after"?(e=a.substr(r,11),r+=11):(e=null,_('"retry_after"')),e!==null?(l=re(),l!==null?(u=ss(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){typeof v<"u"&&(w.retry_after=v)}(f,e[2])),e===null&&(r=f),e===null&&(e=We()))),e}function wl(){var e;return a.substr(r,11).toLowerCase()==="deactivated"?(e=a.substr(r,11),r+=11):(e=null,_('"deactivated"')),e===null&&(a.substr(r,9).toLowerCase()==="probation"?(e=a.substr(r,9),r+=9):(e=null,_('"probation"')),e===null&&(a.substr(r,8).toLowerCase()==="rejected"?(e=a.substr(r,8),r+=8):(e=null,_('"rejected"')),e===null&&(a.substr(r,7).toLowerCase()==="timeout"?(e=a.substr(r,7),r+=7):(e=null,_('"timeout"')),e===null&&(a.substr(r,6).toLowerCase()==="giveup"?(e=a.substr(r,6),r+=6):(e=null,_('"giveup"')),e===null&&(a.substr(r,10).toLowerCase()==="noresource"?(e=a.substr(r,10),r+=10):(e=null,_('"noresource"')),e===null&&(a.substr(r,9).toLowerCase()==="invariant"?(e=a.substr(r,9),r+=9):(e=null,_('"invariant"')),e===null&&(e=P()))))))),e}function io(){var e;return e=V(),e=e!==null?e:"",e}function lo(){var e,l,u,f,p,m;if(p=r,e=P(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=P(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e=e!==null?e:"",e}function fi(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Ht()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=hi(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=hi(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){var O=w.tag;try{w=new b(w.uri,w.display_name,w.params),O&&w.setParam("tag",O)}catch{w=-1}}()),e===null&&(r=p),e}function hi(){var e;return e=ti(),e===null&&(e=We()),e}function Zn(){var e,l,u,f,p,m;if(p=r,e=xs(),e!==null){for(l=[],m=r,u=le(),u!==null?(f=xs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=le(),u!==null?(f=xs(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function xs(){var e,l,u,f,p,m,v,S;if(v=r,e=vi(),e!==null)if(l=k(),l!==null)if(u=yi(),u!==null){for(f=[],S=r,p=ye(),p!==null?(m=er(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);p!==null;)f.push(p),S=r,p=ye(),p!==null?(m=er(),m!==null?p=[p,m]:(p=null,r=S)):(p=null,r=S);f!==null?e=[e,l,u,f]:(e=null,r=v)}else e=null,r=v;else e=null,r=v;else e=null,r=v;return e}function er(){var e;return e=di(),e===null&&(e=_i(),e===null&&(e=pi(),e===null&&(e=mi(),e===null&&(e=gi(),e===null&&(e=We()))))),e}function di(){var e,l,u,f,p;return f=r,p=r,a.substr(r,3).toLowerCase()==="ttl"?(e=a.substr(r,3),r+=3):(e=null,_('"ttl"')),e!==null?(l=re(),l!==null?(u=Ai(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.ttl=v}(f,e[2])),e===null&&(r=f),e}function _i(){var e,l,u,f,p;return f=r,p=r,a.substr(r,5).toLowerCase()==="maddr"?(e=a.substr(r,5),r+=5):(e=null,_('"maddr"')),e!==null?(l=re(),l!==null?(u=us(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.maddr=v}(f,e[2])),e===null&&(r=f),e}function pi(){var e,l,u,f,p;return f=r,p=r,a.substr(r,8).toLowerCase()==="received"?(e=a.substr(r,8),r+=8):(e=null,_('"received"')),e!==null?(l=re(),l!==null?(u=Wt(),u===null&&(u=me()),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.received=v}(f,e[2])),e===null&&(r=f),e}function mi(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6).toLowerCase()==="branch"?(e=a.substr(r,6),r+=6):(e=null,_('"branch"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.branch=v}(f,e[2])),e===null&&(r=f),e}function gi(){var e,l,u,f,p;return f=r,a.substr(r,5).toLowerCase()==="rport"?(e=a.substr(r,5),r+=5):(e=null,_('"rport"')),e!==null?(p=r,l=re(),l!==null?(u=Ti(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function Ti(){var e,l,u,f,p,m,v;return m=r,v=r,e=T(),e=e!==null?e:"",e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?e=[e,l,u,f,p]:(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(S,O){w.rport=parseInt(O.join(""))}(m,e)),e===null&&(r=m),e}function vi(){var e,l,u,f,p,m;return m=r,e=Ei(),e!==null?(l=G(),l!==null?(u=P(),u!==null?(f=G(),f!==null?(p=Si(),p!==null?e=[e,l,u,f,p]:(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m)):(e=null,r=m),e}function Ei(){var e,l;return l=r,a.substr(r,3).toLowerCase()==="sip"?(e=a.substr(r,3),r+=3):(e=null,_('"SIP"')),e===null&&(e=P()),e!==null&&(e=function(u,f){w.protocol=f}(l,e)),e===null&&(r=l),e}function Si(){var e,l;return l=r,a.substr(r,3).toLowerCase()==="udp"?(e=a.substr(r,3),r+=3):(e=null,_('"UDP"')),e===null&&(a.substr(r,3).toLowerCase()==="tcp"?(e=a.substr(r,3),r+=3):(e=null,_('"TCP"')),e===null&&(a.substr(r,3).toLowerCase()==="tls"?(e=a.substr(r,3),r+=3):(e=null,_('"TLS"')),e===null&&(a.substr(r,4).toLowerCase()==="sctp"?(e=a.substr(r,4),r+=4):(e=null,_('"SCTP"')),e===null&&(e=P())))),e!==null&&(e=function(u,f){w.transport=f}(l,e)),e===null&&(r=l),e}function yi(){var e,l,u,f,p;return f=r,e=Ci(),e!==null?(p=r,l=nt(),l!==null?(u=tr(),u!==null?l=[l,u]:(l=null,r=p)):(l=null,r=p),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=f)):(e=null,r=f),e}function Ci(){var e,l;return l=r,e=Wt(),e===null&&(e=zs(),e===null&&(e=Js())),e!==null&&(e=function(u){w.host=a.substring(r,u)}(l)),e===null&&(r=l),e}function tr(){var e,l,u,f,p,m,v;return m=r,v=r,e=T(),e=e!==null?e:"",e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?(f=T(),f=f!==null?f:"",f!==null?(p=T(),p=p!==null?p:"",p!==null?e=[e,l,u,f,p]:(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v)):(e=null,r=v),e!==null&&(e=function(S,O){w.port=parseInt(O.join(""))}(m,e)),e===null&&(r=m),e}function Ai(){var e,l,u,f,p;return f=r,p=r,e=T(),e!==null?(l=T(),l=l!==null?l:"",l!==null?(u=T(),u=u!==null?u:"",u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){return parseInt(v.join(""))}(f,e)),e===null&&(r=f),e}function ao(){var e;return e=Bn(),e}function Ol(){var e,l,u,f,p,m;if(p=r,e=sr(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=nr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=nr(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function sr(){var e,l;return l=r,e=ss(),e!==null&&(e=function(u,f){w.expires=f}(l,e)),e===null&&(r=l),e}function nr(){var e;return e=Dl(),e===null&&(e=We()),e}function Dl(){var e,l,u,f,p;return f=r,p=r,a.substr(r,9).toLowerCase()==="refresher"?(e=a.substr(r,9),r+=9):(e=null,_('"refresher"')),e!==null?(l=re(),l!==null?(a.substr(r,3).toLowerCase()==="uac"?(u=a.substr(r,3),r+=3):(u=null,_('"uac"')),u===null&&(a.substr(r,3).toLowerCase()==="uas"?(u=a.substr(r,3),r+=3):(u=null,_('"uas"'))),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.refresher=v.toLowerCase()}(f,e[2])),e===null&&(r=f),e}function Nl(){var e,l,u,f;return f=r,e=P(),e!==null?(l=B(),l!==null?(u=Ul(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function Ul(){var e,l;for(e=[],l=J(),l===null&&(l=X(),l===null&&(l=k()));l!==null;)e.push(l),l=J(),l===null&&(l=X(),l===null&&(l=k()));return e}function oo(){var e,l;for(e=[],l=A();l!==null;)e.push(l),l=A();return e}function Pl(){var e,l,u;return u=r,a.substr(r,5)==="uuid:"?(e="uuid:",r+=5):(e=null,_('"uuid:"')),e!==null?(l=Ft(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function Ft(){var e,l,u,f,p,m,v,S,O,ie,Ue;return ie=r,Ue=r,e=Ri(),e!==null?(a.charCodeAt(r)===45?(l="-",r++):(l=null,_('"-"')),l!==null?(u=jt(),u!==null?(a.charCodeAt(r)===45?(f="-",r++):(f=null,_('"-"')),f!==null?(p=jt(),p!==null?(a.charCodeAt(r)===45?(m="-",r++):(m=null,_('"-"')),m!==null?(v=jt(),v!==null?(a.charCodeAt(r)===45?(S="-",r++):(S=null,_('"-"')),S!==null?(O=xl(),O!==null?e=[e,l,u,f,p,m,v,S,O]:(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue)):(e=null,r=Ue),e!==null&&(e=function(wt,ks){w=a.substring(r+5,wt)}(ie,e[0])),e===null&&(r=ie),e}function jt(){var e,l,u,f,p;return p=r,e=y(),e!==null?(l=y(),l!==null?(u=y(),u!==null?(f=y(),f!==null?e=[e,l,u,f]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e}function Ri(){var e,l,u;return u=r,e=jt(),e!==null?(l=jt(),l!==null?e=[e,l]:(e=null,r=u)):(e=null,r=u),e}function xl(){var e,l,u,f;return f=r,e=jt(),e!==null?(l=jt(),l!==null?(u=jt(),u!==null?e=[e,l,u]:(e=null,r=f)):(e=null,r=f)):(e=null,r=f),e}function uo(){var e,l,u,f,p,m,v;if(p=r,m=r,e=we(),e===null&&(e=Ht()),e!==null){for(l=[],v=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);u!==null;)l.push(u),v=r,u=ye(),u!==null?(f=We(),f!==null?u=[u,f]:(u=null,r=v)):(u=null,r=v);l!==null?e=[e,l]:(e=null,r=m)}else e=null,r=m;return e!==null&&(e=function(S){try{w=new b(w.uri,w.display_name,w.params)}catch{w=-1}}()),e===null&&(r=p),e}function kl(){var e,l,u,f,p,m;if(p=r,e=rr(),e!==null){for(l=[],m=r,u=ye(),u!==null?(f=ir(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);u!==null;)l.push(u),m=r,u=ye(),u!==null?(f=ir(),f!==null?u=[u,f]:(u=null,r=m)):(u=null,r=m);l!==null?e=[e,l]:(e=null,r=p)}else e=null,r=p;return e}function rr(){var e,l,u,f,p,m;return f=r,p=r,e=ee(),e!==null?(m=r,a.charCodeAt(r)===64?(l="@",r++):(l=null,_('"@"')),l!==null?(u=ee(),u!==null?l=[l,u]:(l=null,r=m)):(l=null,r=m),l=l!==null?l:"",l!==null?e=[e,l]:(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(v){w.call_id=a.substring(r,v)}(f)),e===null&&(r=f),e}function ir(){var e;return e=Ii(),e===null&&(e=bi(),e===null&&(e=Ml(),e===null&&(e=We()))),e}function Ii(){var e,l,u,f,p;return f=r,p=r,a.substr(r,6)==="to-tag"?(e="to-tag",r+=6):(e=null,_('"to-tag"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.to_tag=v}(f,e[2])),e===null&&(r=f),e}function bi(){var e,l,u,f,p;return f=r,p=r,a.substr(r,8)==="from-tag"?(e="from-tag",r+=8):(e=null,_('"from-tag"')),e!==null?(l=re(),l!==null?(u=P(),u!==null?e=[e,l,u]:(e=null,r=p)):(e=null,r=p)):(e=null,r=p),e!==null&&(e=function(m,v){w.from_tag=v}(f,e[2])),e===null&&(r=f),e}function Ml(){var e,l;return l=r,a.substr(r,10)==="early-only"?(e="early-only",r+=10):(e=null,_('"early-only"')),e!==null&&(e=function(u){w.early_only=!0}()),e===null&&(r=l),e}function co(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 Ll(){for(var e=1,l=1,u=!1,f=0;f<Math.max(r,d);f++){var p=a.charAt(f);p===`
|
4
4
|
`?(u||e++,l=1,u=!1):p==="\r"||p==="\u2028"||p==="\u2029"?(e++,l=1,u=!0):(l++,u=!1)}return{line:e,column:l}}var fs=Ks(),b=Ou(),w={},wi=s[o]();if(wi===null||r!==a.length){var Oi=Math.max(r,d),$l=Oi<a.length?a.charAt(Oi):null,i=Ll();return new this.SyntaxError(co(h),$l,Oi,i.line,i.column),-1}return w},toSource:function(){return this._source}};return t.SyntaxError=function(n,a,o,s,r){function d(h,_){var g,T;switch(h.length){case 0:g="end of input";break;case 1:g=h[0];break;default:g=h.slice(0,h.length-1).join(", ")+" or "+h[h.length-1]}return T=_?c(_):"end of input","Expected "+g+" but "+T+" found."}this.name="SyntaxError",this.expected=n,this.found=a,this.message=d(n,a),this.offset=o,this.line=s,this.column=r},t.SyntaxError.prototype=Error.prototype,t}()),ho}var _o,Yu;function Ks(){if(Yu)return _o;Yu=1;function c(_,g){var T;if(typeof Symbol>"u"||_[Symbol.iterator]==null){if(Array.isArray(_)||(T=t(_))||g&&_&&typeof _.length=="number"){T&&(_=T);var E=0,y=function(){};return{s:y,n:function(){return E>=_.length?{done:!0}:{done:!1,value:_[E++]}},e:function($){throw $},f:y}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
5
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var
|
6
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var C=!0,I=!1,H;return{s:function(){E=g[Symbol.iterator]()},n:function(){var oe=E.next();return C=oe.done,oe},e:function(oe){I=!0,H=oe},f:function(){try{!C&&E.return!=null&&E.return()}finally{if(I)throw H}}}}function n(g,T){if(g){if(typeof g=="string")return a(g,T);var E=Object.prototype.toString.call(g).slice(8,-1);if(E==="Object"&&g.constructor&&(E=g.constructor.name),E==="Map"||E==="Set")return Array.from(g);if(E==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(E))return a(g,T)}}function a(g,T){(T==null||T>g.length)&&(T=g.length);for(var E=0,y=new Array(T);E<T;E++)y[E]=g[E];return y}var o=lt,s=Ks(),r=os();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 h=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 h(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=r.parse(g,"host"),g!==-1)return g.host_type}else return};var _=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 s)return g;if(typeof g=="string"){var E=g.split("@"),y,A;switch(E.length){case 1:if(!T)return;y=g,A=T;break;case 2:y=E[0],A=E[1];break;default:y=E.slice(0,E.length-1).join("@"),A=E[E.length-1]}y=y.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(y)&&(y=y.replace(/[-.()]/g,"")),g="".concat(o.SIP,":").concat(_(y),"@").concat(A);var C;return(C=s.parse(g))?C:void 0}else return}else return},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 o.SIP_ERROR_CAUSES)if(o.SIP_ERROR_CAUSES[T].indexOf(g)!==-1)return o.causes[T];return o.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 _e=pe&2147483648,we=ue&2147483648,Ne=pe&1073741824,Qe=ue&1073741824,Le=(pe&1073741823)+(ue&1073741823);return Ne&Qe?Le^2147483648^_e^we:Ne|Qe?Le&1073741824?Le^3221225472^_e^we:Le^1073741824^_e^we:Le^_e^we}function y(pe,ue,_e){return pe&ue|~pe&_e}function A(pe,ue,_e){return pe&_e|ue&~_e}function C(pe,ue,_e){return pe^ue^_e}function I(pe,ue,_e){return ue^(pe|~_e)}function H(pe,ue,_e,we,Ne,Qe,Le){return pe=E(pe,E(E(y(ue,_e,we),Ne),Le)),E(T(pe,Qe),ue)}function $(pe,ue,_e,we,Ne,Qe,Le){return pe=E(pe,E(E(A(ue,_e,we),Ne),Le)),E(T(pe,Qe),ue)}function oe(pe,ue,_e,we,Ne,Qe,Le){return pe=E(pe,E(E(C(ue,_e,we),Ne),Le)),E(T(pe,Qe),ue)}function N(pe,ue,_e,we,Ne,Qe,Le){return pe=E(pe,E(E(I(ue,_e,we),Ne),Le)),E(T(pe,Qe),ue)}function j(pe){for(var ue,_e=pe.length,we=_e+8,Ne=(we-we%64)/64,Qe=(Ne+1)*16,Le=new Array(Qe-1),Lt=0,dt=0;dt<_e;)ue=(dt-dt%4)/4,Lt=dt%4*8,Le[ue]=Le[ue]|pe.charCodeAt(dt)<<Lt,dt++;return ue=(dt-dt%4)/4,Lt=dt%4*8,Le[ue]=Le[ue]|128<<Lt,Le[Qe-2]=_e<<3,Le[Qe-1]=_e>>>29,Le}function Se(pe){var ue="",_e="",we,Ne;for(Ne=0;Ne<=3;Ne++)we=pe>>>Ne*8&255,_e="0".concat(we.toString(16)),ue=ue+_e.substr(_e.length-2,2);return ue}function ve(pe){for(var ue="",_e=0;_e<pe.length;_e++){var we=pe.charCodeAt(_e);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 k=[],D,B,V,J,F,X,U,P,se,st=7,ee=12,W=17,G=22,re=5,ge=9,be=14,xe=20,Ce=4,le=11,ye=16,nt=23,at=6,Ee=10,Ae=15,Ie=21;for(g=ve(g),k=j(g),X=1732584193,U=4023233417,P=2562383102,se=271733878,D=0;D<k.length;D+=16)B=X,V=U,J=P,F=se,X=H(X,U,P,se,k[D+0],st,3614090360),se=H(se,X,U,P,k[D+1],ee,3905402710),P=H(P,se,X,U,k[D+2],W,606105819),U=H(U,P,se,X,k[D+3],G,3250441966),X=H(X,U,P,se,k[D+4],st,4118548399),se=H(se,X,U,P,k[D+5],ee,1200080426),P=H(P,se,X,U,k[D+6],W,2821735955),U=H(U,P,se,X,k[D+7],G,4249261313),X=H(X,U,P,se,k[D+8],st,1770035416),se=H(se,X,U,P,k[D+9],ee,2336552879),P=H(P,se,X,U,k[D+10],W,4294925233),U=H(U,P,se,X,k[D+11],G,2304563134),X=H(X,U,P,se,k[D+12],st,1804603682),se=H(se,X,U,P,k[D+13],ee,4254626195),P=H(P,se,X,U,k[D+14],W,2792965006),U=H(U,P,se,X,k[D+15],G,1236535329),X=$(X,U,P,se,k[D+1],re,4129170786),se=$(se,X,U,P,k[D+6],ge,3225465664),P=$(P,se,X,U,k[D+11],be,643717713),U=$(U,P,se,X,k[D+0],xe,3921069994),X=$(X,U,P,se,k[D+5],re,3593408605),se=$(se,X,U,P,k[D+10],ge,38016083),P=$(P,se,X,U,k[D+15],be,3634488961),U=$(U,P,se,X,k[D+4],xe,3889429448),X=$(X,U,P,se,k[D+9],re,568446438),se=$(se,X,U,P,k[D+14],ge,3275163606),P=$(P,se,X,U,k[D+3],be,4107603335),U=$(U,P,se,X,k[D+8],xe,1163531501),X=$(X,U,P,se,k[D+13],re,2850285829),se=$(se,X,U,P,k[D+2],ge,4243563512),P=$(P,se,X,U,k[D+7],be,1735328473),U=$(U,P,se,X,k[D+12],xe,2368359562),X=oe(X,U,P,se,k[D+5],Ce,4294588738),se=oe(se,X,U,P,k[D+8],le,2272392833),P=oe(P,se,X,U,k[D+11],ye,1839030562),U=oe(U,P,se,X,k[D+14],nt,4259657740),X=oe(X,U,P,se,k[D+1],Ce,2763975236),se=oe(se,X,U,P,k[D+4],le,1272893353),P=oe(P,se,X,U,k[D+7],ye,4139469664),U=oe(U,P,se,X,k[D+10],nt,3200236656),X=oe(X,U,P,se,k[D+13],Ce,681279174),se=oe(se,X,U,P,k[D+0],le,3936430074),P=oe(P,se,X,U,k[D+3],ye,3572445317),U=oe(U,P,se,X,k[D+6],nt,76029189),X=oe(X,U,P,se,k[D+9],Ce,3654602809),se=oe(se,X,U,P,k[D+12],le,3873151461),P=oe(P,se,X,U,k[D+15],ye,530742520),U=oe(U,P,se,X,k[D+2],nt,3299628645),X=N(X,U,P,se,k[D+0],at,4096336452),se=N(se,X,U,P,k[D+7],Ee,1126891415),P=N(P,se,X,U,k[D+14],Ae,2878612391),U=N(U,P,se,X,k[D+5],Ie,4237533241),X=N(X,U,P,se,k[D+12],at,1700485571),se=N(se,X,U,P,k[D+3],Ee,2399980690),P=N(P,se,X,U,k[D+10],Ae,4293915773),U=N(U,P,se,X,k[D+1],Ie,2240044497),X=N(X,U,P,se,k[D+8],at,1873313359),se=N(se,X,U,P,k[D+15],Ee,4264355552),P=N(P,se,X,U,k[D+6],Ae,2734768916),U=N(U,P,se,X,k[D+13],Ie,1309151649),X=N(X,U,P,se,k[D+4],at,4149444226),se=N(se,X,U,P,k[D+11],Ee,3174756917),P=N(P,se,X,U,k[D+2],Ae,718787259),U=N(U,P,se,X,k[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=t(T),y;try{for(E.s();!(y=E.n()).done;){var A=y.value;A.stop()}}catch(j){E.e(j)}finally{E.f()}}else{T=g.getAudioTracks();var C=t(T),I;try{for(C.s();!(I=C.n()).done;){var H=I.value;H.stop()}}catch(j){C.e(j)}finally{C.f()}T=g.getVideoTracks();var $=t(T),oe;try{for($.s();!(oe=$.n()).done;){var N=oe.value;N.stop()}}catch(j){$.e(j)}finally{$.f()}}}catch{(typeof g.stop=="function"||c(g.stop)==="object")&&g.stop()}},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 Du={exports:{}},_r=typeof Reflect=="object"?Reflect:null,zu=_r&&typeof _r.apply=="function"?_r.apply:function(t,n,a){return Function.prototype.apply.call(t,n,a)},Ta;_r&&typeof _r.ownKeys=="function"?Ta=_r.ownKeys:Object.getOwnPropertySymbols?Ta=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Ta=function(t){return Object.getOwnPropertyNames(t)};function cd(c){console&&console.warn&&console.warn(c)}var Vf=Number.isNaN||function(t){return t!==t};function Me(){Me.init.call(this)}Du.exports=Me;Du.exports.once=_d;Me.EventEmitter=Me;Me.prototype._events=void 0;Me.prototype._eventsCount=0;Me.prototype._maxListeners=void 0;var Xu=10;function Ba(c){if(typeof c!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof c)}Object.defineProperty(Me,"defaultMaxListeners",{enumerable:!0,get:function(){return Xu},set:function(c){if(typeof c!="number"||c<0||Vf(c))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+c+".");Xu=c}});Me.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};Me.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||Vf(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function Bf(c){return c._maxListeners===void 0?Me.defaultMaxListeners:c._maxListeners}Me.prototype.getMaxListeners=function(){return Bf(this)};Me.prototype.emit=function(t){for(var n=[],a=1;a<arguments.length;a++)n.push(arguments[a]);var o=t==="error",s=this._events;if(s!==void 0)o=o&&s.error===void 0;else if(!o)return!1;if(o){var r;if(n.length>0&&(r=n[0]),r instanceof Error)throw r;var d=new Error("Unhandled error."+(r?" ("+r.message+")":""));throw d.context=r,d}var h=s[t];if(h===void 0)return!1;if(typeof h=="function")zu(h,this,n);else for(var _=h.length,g=Jf(h,_),a=0;a<_;++a)zu(g[a],this,n);return!0};function Gf(c,t,n,a){var o,s,r;if(Ba(n),s=c._events,s===void 0?(s=c._events=Object.create(null),c._eventsCount=0):(s.newListener!==void 0&&(c.emit("newListener",t,n.listener?n.listener:n),s=c._events),r=s[t]),r===void 0)r=s[t]=n,++c._eventsCount;else if(typeof r=="function"?r=s[t]=a?[n,r]:[r,n]:a?r.unshift(n):r.push(n),o=Bf(c),o>0&&r.length>o&&!r.warned){r.warned=!0;var d=new Error("Possible EventEmitter memory leak detected. "+r.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");d.name="MaxListenersExceededWarning",d.emitter=c,d.type=t,d.count=r.length,cd(d)}return c}Me.prototype.addListener=function(t,n){return Gf(this,t,n,!1)};Me.prototype.on=Me.prototype.addListener;Me.prototype.prependListener=function(t,n){return Gf(this,t,n,!0)};function fd(){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 Wf(c,t,n){var a={fired:!1,wrapFn:void 0,target:c,type:t,listener:n},o=fd.bind(a);return o.listener=n,a.wrapFn=o,o}Me.prototype.once=function(t,n){return Ba(n),this.on(t,Wf(this,t,n)),this};Me.prototype.prependOnceListener=function(t,n){return Ba(n),this.prependListener(t,Wf(this,t,n)),this};Me.prototype.removeListener=function(t,n){var a,o,s,r,d;if(Ba(n),o=this._events,o===void 0)return this;if(a=o[t],a===void 0)return this;if(a===n||a.listener===n)--this._eventsCount===0?this._events=Object.create(null):(delete o[t],o.removeListener&&this.emit("removeListener",t,a.listener||n));else if(typeof a!="function"){for(s=-1,r=a.length-1;r>=0;r--)if(a[r]===n||a[r].listener===n){d=a[r].listener,s=r;break}if(s<0)return this;s===0?a.shift():hd(a,s),a.length===1&&(o[t]=a[0]),o.removeListener!==void 0&&this.emit("removeListener",t,d||n)}return this};Me.prototype.off=Me.prototype.removeListener;Me.prototype.removeAllListeners=function(t){var n,a,o;if(a=this._events,a===void 0)return this;if(a.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):a[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete a[t]),this;if(arguments.length===0){var s=Object.keys(a),r;for(o=0;o<s.length;++o)r=s[o],r!=="removeListener"&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(n=a[t],typeof n=="function")this.removeListener(t,n);else if(n!==void 0)for(o=n.length-1;o>=0;o--)this.removeListener(t,n[o]);return this};function Kf(c,t,n){var a=c._events;if(a===void 0)return[];var o=a[t];return o===void 0?[]:typeof o=="function"?n?[o.listener||o]:[o]:n?dd(o):Jf(o,o.length)}Me.prototype.listeners=function(t){return Kf(this,t,!0)};Me.prototype.rawListeners=function(t){return Kf(this,t,!1)};Me.listenerCount=function(c,t){return typeof c.listenerCount=="function"?c.listenerCount(t):Yf.call(c,t)};Me.prototype.listenerCount=Yf;function Yf(c){var t=this._events;if(t!==void 0){var n=t[c];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}Me.prototype.eventNames=function(){return this._eventsCount>0?Ta(this._events):[]};function Jf(c,t){for(var n=new Array(t),a=0;a<t;++a)n[a]=c[a];return n}function hd(c,t){for(;t+1<c.length;t++)c[t]=c[t+1];c.pop()}function dd(c){for(var t=new Array(c.length),n=0;n<t.length;++n)t[n]=c[n].listener||c[n];return t}function _d(c,t){return new Promise(function(n,a){function o(r){c.removeListener(t,s),a(r)}function s(){typeof c.removeListener=="function"&&c.removeListener("error",o),n([].slice.call(arguments))}zf(c,t,s,{once:!0}),t!=="error"&&pd(c,o,{once:!0})})}function pd(c,t,n){typeof c.on=="function"&&zf(c,"error",t,n)}function zf(c,t,n,a){if(typeof c.on=="function")a.once?c.once(t,n):c.on(t,n);else if(typeof c.addEventListener=="function")c.addEventListener(t,function o(s){a.once&&c.removeEventListener(t,o),n(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof c)}var ft=Du.exports,uu={exports:{}},po,Qu;function md(){if(Qu)return po;Qu=1;var c=1e3,t=c*60,n=t*60,a=n*24,o=a*7,s=a*365.25;po=function(g,T){T=T||{};var E=typeof g;if(E==="string"&&g.length>0)return r(g);if(E==="number"&&isFinite(g))return T.long?h(g):d(g);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(g))};function r(g){if(g=String(g),!(g.length>100)){var T=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(g);if(T){var E=parseFloat(T[1]),y=(T[2]||"ms").toLowerCase();switch(y){case"years":case"year":case"yrs":case"yr":case"y":return E*s;case"weeks":case"week":case"w":return E*o;case"days":case"day":case"d":return E*a;case"hours":case"hour":case"hrs":case"hr":case"h":return E*n;case"minutes":case"minute":case"mins":case"min":case"m":return E*t;case"seconds":case"second":case"secs":case"sec":case"s":return E*c;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return E;default:return}}}}function d(g){var T=Math.abs(g);return T>=a?Math.round(g/a)+"d":T>=n?Math.round(g/n)+"h":T>=t?Math.round(g/t)+"m":T>=c?Math.round(g/c)+"s":g+"ms"}function h(g){var T=Math.abs(g);return T>=a?_(g,T,a,"day"):T>=n?_(g,T,n,"hour"):T>=t?_(g,T,t,"minute"):T>=c?_(g,T,c,"second"):g+" ms"}function _(g,T,E,y){var A=T>=E*1.5;return Math.round(g/E)+" "+y+(A?"s":"")}return po}function gd(c){n.debug=n,n.default=n,n.coerce=h,n.disable=s,n.enable=o,n.enabled=r,n.humanize=md(),n.destroy=_,Object.keys(c).forEach(g=>{n[g]=c[g]}),n.names=[],n.skips=[],n.formatters={};function t(g){let T=0;for(let E=0;E<g.length;E++)T=(T<<5)-T+g.charCodeAt(E),T|=0;return n.colors[Math.abs(T)%n.colors.length]}n.selectColor=t;function n(g){let T,E=null,y,A;function C(...I){if(!C.enabled)return;const H=C,$=Number(new Date),oe=$-(T||$);H.diff=oe,H.prev=T,H.curr=$,T=$,I[0]=n.coerce(I[0]),typeof I[0]!="string"&&I.unshift("%O");let N=0;I[0]=I[0].replace(/%([a-zA-Z%])/g,(Se,ve)=>{if(Se==="%%")return"%";N++;const k=n.formatters[ve];if(typeof k=="function"){const D=I[N];Se=k.call(H,D),I.splice(N,1),N--}return Se}),n.formatArgs.call(H,I),(H.log||n.log).apply(H,I)}return C.namespace=g,C.useColors=n.useColors(),C.color=n.selectColor(g),C.extend=a,C.destroy=n.destroy,Object.defineProperty(C,"enabled",{enumerable:!0,configurable:!1,get:()=>E!==null?E:(y!==n.namespaces&&(y=n.namespaces,A=n.enabled(g)),A),set:I=>{E=I}}),typeof n.init=="function"&&n.init(C),C}function a(g,T){const E=n(this.namespace+(typeof T>"u"?":":T)+g);return E.log=this.log,E}function o(g){n.save(g),n.namespaces=g,n.names=[],n.skips=[];let T;const E=(typeof g=="string"?g:"").split(/[\s,]+/),y=E.length;for(T=0;T<y;T++)E[T]&&(g=E[T].replace(/\*/g,".*?"),g[0]==="-"?n.skips.push(new RegExp("^"+g.slice(1)+"$")):n.names.push(new RegExp("^"+g+"$")))}function s(){const g=[...n.names.map(d),...n.skips.map(d).map(T=>"-"+T)].join(",");return n.enable(""),g}function r(g){if(g[g.length-1]==="*")return!0;let T,E;for(T=0,E=n.skips.length;T<E;T++)if(n.skips[T].test(g))return!1;for(T=0,E=n.names.length;T<E;T++)if(n.names[T].test(g))return!0;return!1}function d(g){return g.toString().substring(2,g.toString().length-2).replace(/\.\*\?$/,"*")}function h(g){return g instanceof Error?g.stack||g.message:g}function _(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return n.enable(n.load()),n}var Td=gd;(function(c,t){t.formatArgs=a,t.save=o,t.load=s,t.useColors=n,t.storage=r(),t.destroy=(()=>{let h=!1;return()=>{h||(h=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function n(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function a(h){if(h[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+h[0]+(this.useColors?"%c ":" ")+"+"+c.exports.humanize(this.diff),!this.useColors)return;const _="color: "+this.color;h.splice(1,0,_,"color: inherit");let g=0,T=0;h[0].replace(/%[a-zA-Z%]/g,E=>{E!=="%%"&&(g++,E==="%c"&&(T=g))}),h.splice(T,0,_)}t.log=console.debug||console.log||(()=>{});function o(h){try{h?t.storage.setItem("debug",h):t.storage.removeItem("debug")}catch{}}function s(){let h;try{h=t.storage.getItem("debug")}catch{}return!h&&typeof process<"u"&&"env"in process&&(h=process.env.DEBUG),h}function r(){try{return localStorage}catch{}}c.exports=Td(t);const{formatters:d}=c.exports;d.j=function(h){try{return JSON.stringify(h)}catch(_){return"[UnexpectedJSONParseError]: "+_.message}}})(uu,uu.exports);var gr=uu.exports;function vd(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Zu(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Ed(c,t,n){return t&&Zu(c.prototype,t),n&&Zu(c,n),c}var lr=gr,ar="JsSIP",ht=function(){function c(t){vd(this,c),t?(this._debug=lr.default("".concat(ar,":").concat(t)),this._warn=lr.default("".concat(ar,":WARN:").concat(t)),this._error=lr.default("".concat(ar,":ERROR:").concat(t))):(this._debug=lr.default(ar),this._warn=lr.default("".concat(ar,":WARN")),this._error=lr.default("".concat(ar,":ERROR"))),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}return Ed(c,[{key:"debug",get:function(){return this._debug}},{key:"warn",get:function(){return this._warn}},{key:"error",get:function(){return this._error}}]),c}(),xt={},Xf={},Qf={exports:{}},ec=Qf.exports={v:[{name:"version",reg:/^(\d*)$/}],o:[{name:"origin",reg:/^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,names:["username","sessionId","sessionVersion","netType","ipVer","address"],format:"%s %s %d %s IP%d %s"}],s:[{name:"name"}],i:[{name:"description"}],u:[{name:"uri"}],e:[{name:"email"}],p:[{name:"phone"}],z:[{name:"timezones"}],r:[{name:"repeats"}],t:[{name:"timing",reg:/^(\d*) (\d*)/,names:["start","stop"],format:"%d %d"}],c:[{name:"connection",reg:/^IN IP(\d) (\S*)/,names:["version","ip"],format:"IN IP%d %s"}],b:[{push:"bandwidth",reg:/^(TIAS|AS|CT|RR|RS):(\d*)/,names:["type","limit"],format:"%s:%s"}],m:[{reg:/^(\w*) (\d*) ([\w/]*)(?: (.*))?/,names:["type","port","protocol","payloads"],format:"%s %d %s %s"}],a:[{push:"rtp",reg:/^rtpmap:(\d*) ([\w\-.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,names:["payload","codec","rate","encoding"],format:function(c){return c.encoding?"rtpmap:%d %s/%s/%s":c.rate?"rtpmap:%d %s/%s":"rtpmap:%d %s"}},{push:"fmtp",reg:/^fmtp:(\d*) ([\S| ]*)/,names:["payload","config"],format:"fmtp:%d %s"},{name:"control",reg:/^control:(.*)/,format:"control:%s"},{name:"rtcp",reg:/^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,names:["port","netType","ipVer","address"],format:function(c){return c.address!=null?"rtcp:%d %s IP%d %s":"rtcp:%d"}},{push:"rtcpFbTrrInt",reg:/^rtcp-fb:(\*|\d*) trr-int (\d*)/,names:["payload","value"],format:"rtcp-fb:%s trr-int %d"},{push:"rtcpFb",reg:/^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/,names:["payload","type","subtype"],format:function(c){return c.subtype!=null?"rtcp-fb:%s %s %s":"rtcp-fb:%s %s"}},{push:"ext",reg:/^extmap:(\d+)(?:\/(\w+))?(?: (urn:ietf:params:rtp-hdrext:encrypt))? (\S*)(?: (\S*))?/,names:["value","direction","encrypt-uri","uri","config"],format:function(c){return"extmap:%d"+(c.direction?"/%s":"%v")+(c["encrypt-uri"]?" %s":"%v")+" %s"+(c.config?" %s":"")}},{name:"extmapAllowMixed",reg:/^(extmap-allow-mixed)/},{push:"crypto",reg:/^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,names:["id","suite","config","sessionConfig"],format:function(c){return c.sessionConfig!=null?"crypto:%d %s %s %s":"crypto:%d %s %s"}},{name:"setup",reg:/^setup:(\w*)/,format:"setup:%s"},{name:"connectionType",reg:/^connection:(new|existing)/,format:"connection:%s"},{name:"mid",reg:/^mid:([^\s]*)/,format:"mid:%s"},{name:"msid",reg:/^msid:(.*)/,format:"msid:%s"},{name:"ptime",reg:/^ptime:(\d*(?:\.\d*)*)/,format:"ptime:%d"},{name:"maxptime",reg:/^maxptime:(\d*(?:\.\d*)*)/,format:"maxptime:%d"},{name:"direction",reg:/^(sendrecv|recvonly|sendonly|inactive)/},{name:"icelite",reg:/^(ice-lite)/},{name:"iceUfrag",reg:/^ice-ufrag:(\S*)/,format:"ice-ufrag:%s"},{name:"icePwd",reg:/^ice-pwd:(\S*)/,format:"ice-pwd:%s"},{name:"fingerprint",reg:/^fingerprint:(\S*) (\S*)/,names:["type","hash"],format:"fingerprint:%s %s"},{push:"candidates",reg:/^candidate:(\S*) (\d*) (\S*) (\d*) (\S*) (\d*) typ (\S*)(?: raddr (\S*) rport (\d*))?(?: tcptype (\S*))?(?: generation (\d*))?(?: network-id (\d*))?(?: network-cost (\d*))?/,names:["foundation","component","transport","priority","ip","port","type","raddr","rport","tcptype","generation","network-id","network-cost"],format:function(c){var t="candidate:%s %d %s %d %s %d typ %s";return t+=c.raddr!=null?" raddr %s rport %d":"%v%v",t+=c.tcptype!=null?" tcptype %s":"%v",c.generation!=null&&(t+=" generation %d"),t+=c["network-id"]!=null?" network-id %d":"%v",t+=c["network-cost"]!=null?" network-cost %d":"%v",t}},{name:"endOfCandidates",reg:/^(end-of-candidates)/},{name:"remoteCandidates",reg:/^remote-candidates:(.*)/,format:"remote-candidates:%s"},{name:"iceOptions",reg:/^ice-options:(\S*)/,format:"ice-options:%s"},{push:"ssrcs",reg:/^ssrc:(\d*) ([\w_-]*)(?::(.*))?/,names:["id","attribute","value"],format:function(c){var t="ssrc:%d";return c.attribute!=null&&(t+=" %s",c.value!=null&&(t+=":%s")),t}},{push:"ssrcGroups",reg:/^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/,names:["semantics","ssrcs"],format:"ssrc-group:%s %s"},{name:"msidSemantic",reg:/^msid-semantic:\s?(\w*) (\S*)/,names:["semantic","token"],format:"msid-semantic: %s %s"},{push:"groups",reg:/^group:(\w*) (.*)/,names:["type","mids"],format:"group:%s %s"},{name:"rtcpMux",reg:/^(rtcp-mux)/},{name:"rtcpRsize",reg:/^(rtcp-rsize)/},{name:"sctpmap",reg:/^sctpmap:([\w_/]*) (\S*)(?: (\S*))?/,names:["sctpmapNumber","app","maxMessageSize"],format:function(c){return c.maxMessageSize!=null?"sctpmap:%s %s %s":"sctpmap:%s %s"}},{name:"xGoogleFlag",reg:/^x-google-flag:([^\s]*)/,format:"x-google-flag:%s"},{push:"rids",reg:/^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/,names:["id","direction","params"],format:function(c){return c.params?"rid:%s %s %s":"rid:%s %s"}},{push:"imageattrs",reg:new RegExp("^imageattr:(\\d+|\\*)[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?"),names:["pt","dir1","attrs1","dir2","attrs2"],format:function(c){return"imageattr:%s %s %s"+(c.dir2?" %s %s":"")}},{name:"simulcast",reg:new RegExp("^simulcast:(send|recv) ([a-zA-Z0-9\\-_~;,]+)(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?$"),names:["dir1","list1","dir2","list2"],format:function(c){return"simulcast:%s %s"+(c.dir2?" %s %s":"")}},{name:"simulcast_03",reg:/^simulcast:[\s\t]+([\S+\s\t]+)$/,names:["value"],format:"simulcast: %s"},{name:"framerate",reg:/^framerate:(\d+(?:$|\.\d+))/,format:"framerate:%s"},{name:"sourceFilter",reg:/^source-filter: *(excl|incl) (\S*) (IP4|IP6|\*) (\S*) (.*)/,names:["filterMode","netType","addressTypes","destAddress","srcList"],format:"source-filter: %s %s %s %s %s"},{name:"bundleOnly",reg:/^(bundle-only)/},{name:"label",reg:/^label:(.+)/,format:"label:%s"},{name:"sctpPort",reg:/^sctp-port:(\d+)$/,format:"sctp-port:%s"},{name:"maxMessageSize",reg:/^max-message-size:(\d+)$/,format:"max-message-size:%s"},{push:"tsRefClocks",reg:/^ts-refclk:([^\s=]*)(?:=(\S*))?/,names:["clksrc","clksrcExt"],format:function(c){return"ts-refclk:%s"+(c.clksrcExt!=null?"=%s":"")}},{name:"mediaClk",reg:/^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/,names:["id","mediaClockName","mediaClockValue","rateNumerator","rateDenominator"],format:function(c){var t="mediaclk:";return t+=c.id!=null?"id=%s %s":"%v%s",t+=c.mediaClockValue!=null?"=%s":"",t+=c.rateNumerator!=null?" rate=%s":"",t+=c.rateDenominator!=null?"/%s":"",t}},{name:"keywords",reg:/^keywds:(.+)$/,format:"keywds:%s"},{name:"content",reg:/^content:(.+)/,format:"content:%s"},{name:"bfcpFloorCtrl",reg:/^floorctrl:(c-only|s-only|c-s)/,format:"floorctrl:%s"},{name:"bfcpConfId",reg:/^confid:(\d+)/,format:"confid:%s"},{name:"bfcpUserId",reg:/^userid:(\d+)/,format:"userid:%s"},{name:"bfcpFloorId",reg:/^floorid:(.+) (?:m-stream|mstrm):(.+)/,names:["id","mStream"],format:"floorid:%s mstrm:%s"},{push:"invalid",names:["value"]}]};Object.keys(ec).forEach(function(c){var t=ec[c];t.forEach(function(n){n.reg||(n.reg=/(.*)/),n.format||(n.format="%s")})});var Zf=Qf.exports;(function(c){var t=function(d){return String(Number(d))===d?Number(d):d},n=function(d,h,_,g){if(g&&!_)h[g]=t(d[1]);else for(var T=0;T<_.length;T+=1)d[T+1]!=null&&(h[_[T]]=t(d[T+1]))},a=function(d,h,_){var g=d.name&&d.names;d.push&&!h[d.push]?h[d.push]=[]:g&&!h[d.name]&&(h[d.name]={});var T=d.push?{}:g?h[d.name]:h;n(_.match(d.reg),T,d.names,d.name),d.push&&h[d.push].push(T)},o=Zf,s=RegExp.prototype.test.bind(/^([a-z])=(.*)/);c.parse=function(d){var h={},_=[],g=h;return d.split(/(\r\n|\r|\n)/).filter(s).forEach(function(T){var E=T[0],y=T.slice(2);E==="m"&&(_.push({rtp:[],fmtp:[]}),g=_[_.length-1]);for(var A=0;A<(o[E]||[]).length;A+=1){var C=o[E][A];if(C.reg.test(y))return a(C,g,y)}}),h.media=_,h};var r=function(d,h){var _=h.split(/=(.+)/,2);return _.length===2?d[_[0]]=t(_[1]):_.length===1&&h.length>1&&(d[_[0]]=void 0),d};c.parseParams=function(d){return d.split(/;\s?/).reduce(r,{})},c.parseFmtpConfig=c.parseParams,c.parsePayloads=function(d){return d.toString().split(" ").map(Number)},c.parseRemoteCandidates=function(d){for(var h=[],_=d.split(" ").map(t),g=0;g<_.length;g+=3)h.push({component:_[g],ip:_[g+1],port:_[g+2]});return h},c.parseImageAttributes=function(d){return d.split(" ").map(function(h){return h.substring(1,h.length-1).split(",").reduce(r,{})})},c.parseSimulcastStreamList=function(d){return d.split(";").map(function(h){return h.split(",").map(function(_){var g,T=!1;return _[0]!=="~"?g=t(_):(g=t(_.substring(1,_.length)),T=!0),{scid:g,paused:T}})})}})(Xf);var mo=Zf,Sd=/%[sdv%]/g,yd=function(c){var t=1,n=arguments,a=n.length;return c.replace(Sd,function(o){if(t>=a)return o;var s=n[t];switch(t+=1,o){case"%%":return"%";case"%s":return String(s);case"%d":return Number(s);case"%v":return""}})},Di=function(c,t,n){var a=t.format instanceof Function?t.format(t.push?n:n[t.name]):t.format,o=[c+"="+a];if(t.names)for(var s=0;s<t.names.length;s+=1){var r=t.names[s];t.name?o.push(n[t.name][r]):o.push(n[t.names[s]])}else o.push(n[t.name]);return yd.apply(null,o)},Ad=["v","o","s","i","u","e","p","c","b","t","r","z","a"],Cd=["i","c","b","a"],Rd=function(c,t){t=t||{},c.version==null&&(c.version=0),c.name==null&&(c.name=" "),c.media.forEach(function(s){s.payloads==null&&(s.payloads="")});var n=t.outerOrder||Ad,a=t.innerOrder||Cd,o=[];return n.forEach(function(s){mo[s].forEach(function(r){r.name in c&&c[r.name]!=null?o.push(Di(s,r,c)):r.push in c&&c[r.push]!=null&&c[r.push].forEach(function(d){o.push(Di(s,r,d))})})}),c.media.forEach(function(s){o.push(Di("m",mo.m[0],s)),a.forEach(function(r){mo[r].forEach(function(d){d.name in s&&s[d.name]!=null?o.push(Di(r,d,s)):d.push in s&&s[d.push]!=null&&s[d.push].forEach(function(h){o.push(Di(r,d,h))})})})}),o.join(`\r
|
5
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var C=!0,A=!1,I;return{s:function(){T=_[Symbol.iterator]()},n:function(){var $=T.next();return C=$.done,$},e:function($){A=!0,I=$},f:function(){try{!C&&T.return!=null&&T.return()}finally{if(A)throw I}}}}function t(_,g){if(_){if(typeof _=="string")return n(_,g);var T=Object.prototype.toString.call(_).slice(8,-1);if(T==="Object"&&_.constructor&&(T=_.constructor.name),T==="Map"||T==="Set")return Array.from(_);if(T==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(T))return n(_,g)}}function n(_,g){(g==null||g>_.length)&&(g=_.length);for(var T=0,E=new Array(g);T<g;T++)E[T]=_[T];return E}function a(_,g){if(!(_ instanceof g))throw new TypeError("Cannot call a class as a function")}function o(_,g){for(var T=0;T<g.length;T++){var E=g[T];E.enumerable=E.enumerable||!1,E.configurable=!0,"value"in E&&(E.writable=!0),Object.defineProperty(_,E.key,E)}}function s(_,g,T){return g&&o(_.prototype,g),T&&o(_,T),_}var r=lt,d=bt(),h=os();return _o=function(){s(_,null,[{key:"parse",value:function(T){if(T=h.parse(T,"SIP_URI"),T!==-1)return T}}]);function _(g,T,E,y){var C=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{},A=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{};if(a(this,_),!E)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=g||r.SIP,this._user=T,this._host=E,this._port=y;for(var I in C)Object.prototype.hasOwnProperty.call(C,I)&&this.setParam(I,C[I]);for(var H in A)Object.prototype.hasOwnProperty.call(A,H)&&this.setHeader(H,A[H])}return s(_,[{key:"setParam",value:function(T,E){T&&(this._parameters[T.toLowerCase()]=typeof E>"u"||E===null?null:E.toString())}},{key:"getParam",value:function(T){if(T)return this._parameters[T.toLowerCase()]}},{key:"hasParam",value:function(T){if(T)return this._parameters.hasOwnProperty(T.toLowerCase())&&!0||!1}},{key:"deleteParam",value:function(T){if(T=T.toLowerCase(),this._parameters.hasOwnProperty(T)){var E=this._parameters[T];return delete this._parameters[T],E}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"setHeader",value:function(T,E){this._headers[d.headerize(T)]=Array.isArray(E)?E:[E]}},{key:"getHeader",value:function(T){if(T)return this._headers[d.headerize(T)]}},{key:"hasHeader",value:function(T){if(T)return this._headers.hasOwnProperty(d.headerize(T))&&!0||!1}},{key:"deleteHeader",value:function(T){if(T=d.headerize(T),this._headers.hasOwnProperty(T)){var E=this._headers[T];return delete this._headers[T],E}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new _(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var T=[],E="".concat(this._scheme,":");this._user&&(E+="".concat(d.escapeUser(this._user),"@")),E+=this._host,(this._port||this._port===0)&&(E+=":".concat(this._port));for(var y in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,y)&&(E+=";".concat(y),this._parameters[y]!==null&&(E+="=".concat(this._parameters[y])));for(var C in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,C)){var A=c(this._headers[C]),I;try{for(A.s();!(I=A.n()).done;){var H=I.value;T.push("".concat(C,"=").concat(H))}}catch($){A.e($)}finally{A.f()}}return T.length>0&&(E+="?".concat(T.join("&"))),E}},{key:"toAor",value:function(T){var E="".concat(this._scheme,":");return this._user&&(E+="".concat(d.escapeUser(this._user),"@")),E+=this._host,T&&(this._port||this._port===0)&&(E+=":".concat(this._port)),E}},{key:"scheme",get:function(){return this._scheme},set:function(T){this._scheme=T.toLowerCase()}},{key:"user",get:function(){return this._user},set:function(T){this._user=T}},{key:"host",get:function(){return this._host},set:function(T){this._host=T.toLowerCase()}},{key:"port",get:function(){return this._port},set:function(T){this._port=T===0?T:parseInt(T,10)||null}}]),_}(),_o}var Ju;function bt(){if(Ju)return Ze;Ju=1;function c(g){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?c=function(E){return typeof E}:c=function(E){return E&&typeof Symbol=="function"&&E.constructor===Symbol&&E!==Symbol.prototype?"symbol":typeof E},c(g)}function t(g,T){var E;if(typeof Symbol>"u"||g[Symbol.iterator]==null){if(Array.isArray(g)||(E=n(g))||T&&g&&typeof g.length=="number"){E&&(g=E);var y=0,C=function(){};return{s:C,n:function(){return y>=g.length?{done:!0}:{done:!1,value:g[y++]}},e:function(oe){throw oe},f:C}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
6
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var A=!0,I=!1,H;return{s:function(){E=g[Symbol.iterator]()},n:function(){var oe=E.next();return A=oe.done,oe},e:function(oe){I=!0,H=oe},f:function(){try{!A&&E.return!=null&&E.return()}finally{if(I)throw H}}}}function n(g,T){if(g){if(typeof g=="string")return a(g,T);var E=Object.prototype.toString.call(g).slice(8,-1);if(E==="Object"&&g.constructor&&(E=g.constructor.name),E==="Map"||E==="Set")return Array.from(g);if(E==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(E))return a(g,T)}}function a(g,T){(T==null||T>g.length)&&(T=g.length);for(var E=0,y=new Array(T);E<T;E++)y[E]=g[E];return y}var o=lt,s=Ks(),r=os();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 C=0,A=E;C<A.length;C++){var I=A[C];if(d(g[I]))return!1}return!0};var h=Ze.createRandomToken=function(g){var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:32,E,y,C="";for(E=0;E<g;E++)y=Math.random()*T|0,C+=y.toString(T);return C};Ze.newTag=function(){return h(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=r.parse(g,"host"),g!==-1)return g.host_type}else return};var _=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 s)return g;if(typeof g=="string"){var E=g.split("@"),y,C;switch(E.length){case 1:if(!T)return;y=g,C=T;break;case 2:y=E[0],C=E[1];break;default:y=E.slice(0,E.length-1).join("@"),C=E[E.length-1]}y=y.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(y)&&(y=y.replace(/[-.()]/g,"")),g="".concat(o.SIP,":").concat(_(y),"@").concat(C);var A;return(A=s.parse(g))?A:void 0}else return}else return},Ze.headerize=function(g){var T={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},E=g.toLowerCase().replace(/_/g,"-").split("-"),y="",C=E.length,A;for(A=0;A<C;A++)A!==0&&(y+="-"),y+=E[A].charAt(0).toUpperCase()+E[A].substring(1);return T[y]&&(y=T[y]),y},Ze.sipErrorCause=function(g){for(var T in o.SIP_ERROR_CAUSES)if(o.SIP_ERROR_CAUSES[T].indexOf(g)!==-1)return o.causes[T];return o.causes.SIP_FAILURE_CODE},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 _e=pe&2147483648,we=ue&2147483648,Ne=pe&1073741824,Qe=ue&1073741824,Le=(pe&1073741823)+(ue&1073741823);return Ne&Qe?Le^2147483648^_e^we:Ne|Qe?Le&1073741824?Le^3221225472^_e^we:Le^1073741824^_e^we:Le^_e^we}function y(pe,ue,_e){return pe&ue|~pe&_e}function C(pe,ue,_e){return pe&_e|ue&~_e}function A(pe,ue,_e){return pe^ue^_e}function I(pe,ue,_e){return ue^(pe|~_e)}function H(pe,ue,_e,we,Ne,Qe,Le){return pe=E(pe,E(E(y(ue,_e,we),Ne),Le)),E(T(pe,Qe),ue)}function $(pe,ue,_e,we,Ne,Qe,Le){return pe=E(pe,E(E(C(ue,_e,we),Ne),Le)),E(T(pe,Qe),ue)}function oe(pe,ue,_e,we,Ne,Qe,Le){return pe=E(pe,E(E(A(ue,_e,we),Ne),Le)),E(T(pe,Qe),ue)}function N(pe,ue,_e,we,Ne,Qe,Le){return pe=E(pe,E(E(I(ue,_e,we),Ne),Le)),E(T(pe,Qe),ue)}function j(pe){for(var ue,_e=pe.length,we=_e+8,Ne=(we-we%64)/64,Qe=(Ne+1)*16,Le=new Array(Qe-1),Lt=0,dt=0;dt<_e;)ue=(dt-dt%4)/4,Lt=dt%4*8,Le[ue]=Le[ue]|pe.charCodeAt(dt)<<Lt,dt++;return ue=(dt-dt%4)/4,Lt=dt%4*8,Le[ue]=Le[ue]|128<<Lt,Le[Qe-2]=_e<<3,Le[Qe-1]=_e>>>29,Le}function Se(pe){var ue="",_e="",we,Ne;for(Ne=0;Ne<=3;Ne++)we=pe>>>Ne*8&255,_e="0".concat(we.toString(16)),ue=ue+_e.substr(_e.length-2,2);return ue}function ve(pe){for(var ue="",_e=0;_e<pe.length;_e++){var we=pe.charCodeAt(_e);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 k=[],D,B,V,J,F,X,U,P,se,st=7,ee=12,W=17,G=22,re=5,ge=9,be=14,xe=20,Ae=4,le=11,ye=16,nt=23,at=6,Ee=10,Ce=15,Ie=21;for(g=ve(g),k=j(g),X=1732584193,U=4023233417,P=2562383102,se=271733878,D=0;D<k.length;D+=16)B=X,V=U,J=P,F=se,X=H(X,U,P,se,k[D+0],st,3614090360),se=H(se,X,U,P,k[D+1],ee,3905402710),P=H(P,se,X,U,k[D+2],W,606105819),U=H(U,P,se,X,k[D+3],G,3250441966),X=H(X,U,P,se,k[D+4],st,4118548399),se=H(se,X,U,P,k[D+5],ee,1200080426),P=H(P,se,X,U,k[D+6],W,2821735955),U=H(U,P,se,X,k[D+7],G,4249261313),X=H(X,U,P,se,k[D+8],st,1770035416),se=H(se,X,U,P,k[D+9],ee,2336552879),P=H(P,se,X,U,k[D+10],W,4294925233),U=H(U,P,se,X,k[D+11],G,2304563134),X=H(X,U,P,se,k[D+12],st,1804603682),se=H(se,X,U,P,k[D+13],ee,4254626195),P=H(P,se,X,U,k[D+14],W,2792965006),U=H(U,P,se,X,k[D+15],G,1236535329),X=$(X,U,P,se,k[D+1],re,4129170786),se=$(se,X,U,P,k[D+6],ge,3225465664),P=$(P,se,X,U,k[D+11],be,643717713),U=$(U,P,se,X,k[D+0],xe,3921069994),X=$(X,U,P,se,k[D+5],re,3593408605),se=$(se,X,U,P,k[D+10],ge,38016083),P=$(P,se,X,U,k[D+15],be,3634488961),U=$(U,P,se,X,k[D+4],xe,3889429448),X=$(X,U,P,se,k[D+9],re,568446438),se=$(se,X,U,P,k[D+14],ge,3275163606),P=$(P,se,X,U,k[D+3],be,4107603335),U=$(U,P,se,X,k[D+8],xe,1163531501),X=$(X,U,P,se,k[D+13],re,2850285829),se=$(se,X,U,P,k[D+2],ge,4243563512),P=$(P,se,X,U,k[D+7],be,1735328473),U=$(U,P,se,X,k[D+12],xe,2368359562),X=oe(X,U,P,se,k[D+5],Ae,4294588738),se=oe(se,X,U,P,k[D+8],le,2272392833),P=oe(P,se,X,U,k[D+11],ye,1839030562),U=oe(U,P,se,X,k[D+14],nt,4259657740),X=oe(X,U,P,se,k[D+1],Ae,2763975236),se=oe(se,X,U,P,k[D+4],le,1272893353),P=oe(P,se,X,U,k[D+7],ye,4139469664),U=oe(U,P,se,X,k[D+10],nt,3200236656),X=oe(X,U,P,se,k[D+13],Ae,681279174),se=oe(se,X,U,P,k[D+0],le,3936430074),P=oe(P,se,X,U,k[D+3],ye,3572445317),U=oe(U,P,se,X,k[D+6],nt,76029189),X=oe(X,U,P,se,k[D+9],Ae,3654602809),se=oe(se,X,U,P,k[D+12],le,3873151461),P=oe(P,se,X,U,k[D+15],ye,530742520),U=oe(U,P,se,X,k[D+2],nt,3299628645),X=N(X,U,P,se,k[D+0],at,4096336452),se=N(se,X,U,P,k[D+7],Ee,1126891415),P=N(P,se,X,U,k[D+14],Ce,2878612391),U=N(U,P,se,X,k[D+5],Ie,4237533241),X=N(X,U,P,se,k[D+12],at,1700485571),se=N(se,X,U,P,k[D+3],Ee,2399980690),P=N(P,se,X,U,k[D+10],Ce,4293915773),U=N(U,P,se,X,k[D+1],Ie,2240044497),X=N(X,U,P,se,k[D+8],at,1873313359),se=N(se,X,U,P,k[D+15],Ee,4264355552),P=N(P,se,X,U,k[D+6],Ce,2734768916),U=N(U,P,se,X,k[D+13],Ie,1309151649),X=N(X,U,P,se,k[D+4],at,4149444226),se=N(se,X,U,P,k[D+11],Ee,3174756917),P=N(P,se,X,U,k[D+2],Ce,718787259),U=N(U,P,se,X,k[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=t(T),y;try{for(E.s();!(y=E.n()).done;){var C=y.value;C.stop()}}catch(j){E.e(j)}finally{E.f()}}else{T=g.getAudioTracks();var A=t(T),I;try{for(A.s();!(I=A.n()).done;){var H=I.value;H.stop()}}catch(j){A.e(j)}finally{A.f()}T=g.getVideoTracks();var $=t(T),oe;try{for($.s();!(oe=$.n()).done;){var N=oe.value;N.stop()}}catch(j){$.e(j)}finally{$.f()}}}catch{(typeof g.stop=="function"||c(g.stop)==="object")&&g.stop()}},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 Du={exports:{}},_r=typeof Reflect=="object"?Reflect:null,zu=_r&&typeof _r.apply=="function"?_r.apply:function(t,n,a){return Function.prototype.apply.call(t,n,a)},Ta;_r&&typeof _r.ownKeys=="function"?Ta=_r.ownKeys:Object.getOwnPropertySymbols?Ta=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Ta=function(t){return Object.getOwnPropertyNames(t)};function cd(c){console&&console.warn&&console.warn(c)}var Vf=Number.isNaN||function(t){return t!==t};function Me(){Me.init.call(this)}Du.exports=Me;Du.exports.once=_d;Me.EventEmitter=Me;Me.prototype._events=void 0;Me.prototype._eventsCount=0;Me.prototype._maxListeners=void 0;var Xu=10;function Ba(c){if(typeof c!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof c)}Object.defineProperty(Me,"defaultMaxListeners",{enumerable:!0,get:function(){return Xu},set:function(c){if(typeof c!="number"||c<0||Vf(c))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+c+".");Xu=c}});Me.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};Me.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||Vf(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function Bf(c){return c._maxListeners===void 0?Me.defaultMaxListeners:c._maxListeners}Me.prototype.getMaxListeners=function(){return Bf(this)};Me.prototype.emit=function(t){for(var n=[],a=1;a<arguments.length;a++)n.push(arguments[a]);var o=t==="error",s=this._events;if(s!==void 0)o=o&&s.error===void 0;else if(!o)return!1;if(o){var r;if(n.length>0&&(r=n[0]),r instanceof Error)throw r;var d=new Error("Unhandled error."+(r?" ("+r.message+")":""));throw d.context=r,d}var h=s[t];if(h===void 0)return!1;if(typeof h=="function")zu(h,this,n);else for(var _=h.length,g=Jf(h,_),a=0;a<_;++a)zu(g[a],this,n);return!0};function Gf(c,t,n,a){var o,s,r;if(Ba(n),s=c._events,s===void 0?(s=c._events=Object.create(null),c._eventsCount=0):(s.newListener!==void 0&&(c.emit("newListener",t,n.listener?n.listener:n),s=c._events),r=s[t]),r===void 0)r=s[t]=n,++c._eventsCount;else if(typeof r=="function"?r=s[t]=a?[n,r]:[r,n]:a?r.unshift(n):r.push(n),o=Bf(c),o>0&&r.length>o&&!r.warned){r.warned=!0;var d=new Error("Possible EventEmitter memory leak detected. "+r.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");d.name="MaxListenersExceededWarning",d.emitter=c,d.type=t,d.count=r.length,cd(d)}return c}Me.prototype.addListener=function(t,n){return Gf(this,t,n,!1)};Me.prototype.on=Me.prototype.addListener;Me.prototype.prependListener=function(t,n){return Gf(this,t,n,!0)};function fd(){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 Wf(c,t,n){var a={fired:!1,wrapFn:void 0,target:c,type:t,listener:n},o=fd.bind(a);return o.listener=n,a.wrapFn=o,o}Me.prototype.once=function(t,n){return Ba(n),this.on(t,Wf(this,t,n)),this};Me.prototype.prependOnceListener=function(t,n){return Ba(n),this.prependListener(t,Wf(this,t,n)),this};Me.prototype.removeListener=function(t,n){var a,o,s,r,d;if(Ba(n),o=this._events,o===void 0)return this;if(a=o[t],a===void 0)return this;if(a===n||a.listener===n)--this._eventsCount===0?this._events=Object.create(null):(delete o[t],o.removeListener&&this.emit("removeListener",t,a.listener||n));else if(typeof a!="function"){for(s=-1,r=a.length-1;r>=0;r--)if(a[r]===n||a[r].listener===n){d=a[r].listener,s=r;break}if(s<0)return this;s===0?a.shift():hd(a,s),a.length===1&&(o[t]=a[0]),o.removeListener!==void 0&&this.emit("removeListener",t,d||n)}return this};Me.prototype.off=Me.prototype.removeListener;Me.prototype.removeAllListeners=function(t){var n,a,o;if(a=this._events,a===void 0)return this;if(a.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):a[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete a[t]),this;if(arguments.length===0){var s=Object.keys(a),r;for(o=0;o<s.length;++o)r=s[o],r!=="removeListener"&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(n=a[t],typeof n=="function")this.removeListener(t,n);else if(n!==void 0)for(o=n.length-1;o>=0;o--)this.removeListener(t,n[o]);return this};function Kf(c,t,n){var a=c._events;if(a===void 0)return[];var o=a[t];return o===void 0?[]:typeof o=="function"?n?[o.listener||o]:[o]:n?dd(o):Jf(o,o.length)}Me.prototype.listeners=function(t){return Kf(this,t,!0)};Me.prototype.rawListeners=function(t){return Kf(this,t,!1)};Me.listenerCount=function(c,t){return typeof c.listenerCount=="function"?c.listenerCount(t):Yf.call(c,t)};Me.prototype.listenerCount=Yf;function Yf(c){var t=this._events;if(t!==void 0){var n=t[c];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}Me.prototype.eventNames=function(){return this._eventsCount>0?Ta(this._events):[]};function Jf(c,t){for(var n=new Array(t),a=0;a<t;++a)n[a]=c[a];return n}function hd(c,t){for(;t+1<c.length;t++)c[t]=c[t+1];c.pop()}function dd(c){for(var t=new Array(c.length),n=0;n<t.length;++n)t[n]=c[n].listener||c[n];return t}function _d(c,t){return new Promise(function(n,a){function o(r){c.removeListener(t,s),a(r)}function s(){typeof c.removeListener=="function"&&c.removeListener("error",o),n([].slice.call(arguments))}zf(c,t,s,{once:!0}),t!=="error"&&pd(c,o,{once:!0})})}function pd(c,t,n){typeof c.on=="function"&&zf(c,"error",t,n)}function zf(c,t,n,a){if(typeof c.on=="function")a.once?c.once(t,n):c.on(t,n);else if(typeof c.addEventListener=="function")c.addEventListener(t,function o(s){a.once&&c.removeEventListener(t,o),n(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof c)}var ft=Du.exports,uu={exports:{}},po,Qu;function md(){if(Qu)return po;Qu=1;var c=1e3,t=c*60,n=t*60,a=n*24,o=a*7,s=a*365.25;po=function(g,T){T=T||{};var E=typeof g;if(E==="string"&&g.length>0)return r(g);if(E==="number"&&isFinite(g))return T.long?h(g):d(g);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(g))};function r(g){if(g=String(g),!(g.length>100)){var T=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(g);if(T){var E=parseFloat(T[1]),y=(T[2]||"ms").toLowerCase();switch(y){case"years":case"year":case"yrs":case"yr":case"y":return E*s;case"weeks":case"week":case"w":return E*o;case"days":case"day":case"d":return E*a;case"hours":case"hour":case"hrs":case"hr":case"h":return E*n;case"minutes":case"minute":case"mins":case"min":case"m":return E*t;case"seconds":case"second":case"secs":case"sec":case"s":return E*c;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return E;default:return}}}}function d(g){var T=Math.abs(g);return T>=a?Math.round(g/a)+"d":T>=n?Math.round(g/n)+"h":T>=t?Math.round(g/t)+"m":T>=c?Math.round(g/c)+"s":g+"ms"}function h(g){var T=Math.abs(g);return T>=a?_(g,T,a,"day"):T>=n?_(g,T,n,"hour"):T>=t?_(g,T,t,"minute"):T>=c?_(g,T,c,"second"):g+" ms"}function _(g,T,E,y){var C=T>=E*1.5;return Math.round(g/E)+" "+y+(C?"s":"")}return po}function gd(c){n.debug=n,n.default=n,n.coerce=h,n.disable=s,n.enable=o,n.enabled=r,n.humanize=md(),n.destroy=_,Object.keys(c).forEach(g=>{n[g]=c[g]}),n.names=[],n.skips=[],n.formatters={};function t(g){let T=0;for(let E=0;E<g.length;E++)T=(T<<5)-T+g.charCodeAt(E),T|=0;return n.colors[Math.abs(T)%n.colors.length]}n.selectColor=t;function n(g){let T,E=null,y,C;function A(...I){if(!A.enabled)return;const H=A,$=Number(new Date),oe=$-(T||$);H.diff=oe,H.prev=T,H.curr=$,T=$,I[0]=n.coerce(I[0]),typeof I[0]!="string"&&I.unshift("%O");let N=0;I[0]=I[0].replace(/%([a-zA-Z%])/g,(Se,ve)=>{if(Se==="%%")return"%";N++;const k=n.formatters[ve];if(typeof k=="function"){const D=I[N];Se=k.call(H,D),I.splice(N,1),N--}return Se}),n.formatArgs.call(H,I),(H.log||n.log).apply(H,I)}return A.namespace=g,A.useColors=n.useColors(),A.color=n.selectColor(g),A.extend=a,A.destroy=n.destroy,Object.defineProperty(A,"enabled",{enumerable:!0,configurable:!1,get:()=>E!==null?E:(y!==n.namespaces&&(y=n.namespaces,C=n.enabled(g)),C),set:I=>{E=I}}),typeof n.init=="function"&&n.init(A),A}function a(g,T){const E=n(this.namespace+(typeof T>"u"?":":T)+g);return E.log=this.log,E}function o(g){n.save(g),n.namespaces=g,n.names=[],n.skips=[];let T;const E=(typeof g=="string"?g:"").split(/[\s,]+/),y=E.length;for(T=0;T<y;T++)E[T]&&(g=E[T].replace(/\*/g,".*?"),g[0]==="-"?n.skips.push(new RegExp("^"+g.slice(1)+"$")):n.names.push(new RegExp("^"+g+"$")))}function s(){const g=[...n.names.map(d),...n.skips.map(d).map(T=>"-"+T)].join(",");return n.enable(""),g}function r(g){if(g[g.length-1]==="*")return!0;let T,E;for(T=0,E=n.skips.length;T<E;T++)if(n.skips[T].test(g))return!1;for(T=0,E=n.names.length;T<E;T++)if(n.names[T].test(g))return!0;return!1}function d(g){return g.toString().substring(2,g.toString().length-2).replace(/\.\*\?$/,"*")}function h(g){return g instanceof Error?g.stack||g.message:g}function _(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return n.enable(n.load()),n}var Td=gd;(function(c,t){t.formatArgs=a,t.save=o,t.load=s,t.useColors=n,t.storage=r(),t.destroy=(()=>{let h=!1;return()=>{h||(h=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function n(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function a(h){if(h[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+h[0]+(this.useColors?"%c ":" ")+"+"+c.exports.humanize(this.diff),!this.useColors)return;const _="color: "+this.color;h.splice(1,0,_,"color: inherit");let g=0,T=0;h[0].replace(/%[a-zA-Z%]/g,E=>{E!=="%%"&&(g++,E==="%c"&&(T=g))}),h.splice(T,0,_)}t.log=console.debug||console.log||(()=>{});function o(h){try{h?t.storage.setItem("debug",h):t.storage.removeItem("debug")}catch{}}function s(){let h;try{h=t.storage.getItem("debug")}catch{}return!h&&typeof process<"u"&&"env"in process&&(h=process.env.DEBUG),h}function r(){try{return localStorage}catch{}}c.exports=Td(t);const{formatters:d}=c.exports;d.j=function(h){try{return JSON.stringify(h)}catch(_){return"[UnexpectedJSONParseError]: "+_.message}}})(uu,uu.exports);var gr=uu.exports;function vd(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Zu(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Ed(c,t,n){return t&&Zu(c.prototype,t),n&&Zu(c,n),c}var lr=gr,ar="JsSIP",ht=function(){function c(t){vd(this,c),t?(this._debug=lr.default("".concat(ar,":").concat(t)),this._warn=lr.default("".concat(ar,":WARN:").concat(t)),this._error=lr.default("".concat(ar,":ERROR:").concat(t))):(this._debug=lr.default(ar),this._warn=lr.default("".concat(ar,":WARN")),this._error=lr.default("".concat(ar,":ERROR"))),this._debug.log=console.info.bind(console),this._warn.log=console.warn.bind(console),this._error.log=console.error.bind(console)}return Ed(c,[{key:"debug",get:function(){return this._debug}},{key:"warn",get:function(){return this._warn}},{key:"error",get:function(){return this._error}}]),c}(),xt={},Xf={},Qf={exports:{}},ec=Qf.exports={v:[{name:"version",reg:/^(\d*)$/}],o:[{name:"origin",reg:/^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,names:["username","sessionId","sessionVersion","netType","ipVer","address"],format:"%s %s %d %s IP%d %s"}],s:[{name:"name"}],i:[{name:"description"}],u:[{name:"uri"}],e:[{name:"email"}],p:[{name:"phone"}],z:[{name:"timezones"}],r:[{name:"repeats"}],t:[{name:"timing",reg:/^(\d*) (\d*)/,names:["start","stop"],format:"%d %d"}],c:[{name:"connection",reg:/^IN IP(\d) (\S*)/,names:["version","ip"],format:"IN IP%d %s"}],b:[{push:"bandwidth",reg:/^(TIAS|AS|CT|RR|RS):(\d*)/,names:["type","limit"],format:"%s:%s"}],m:[{reg:/^(\w*) (\d*) ([\w/]*)(?: (.*))?/,names:["type","port","protocol","payloads"],format:"%s %d %s %s"}],a:[{push:"rtp",reg:/^rtpmap:(\d*) ([\w\-.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,names:["payload","codec","rate","encoding"],format:function(c){return c.encoding?"rtpmap:%d %s/%s/%s":c.rate?"rtpmap:%d %s/%s":"rtpmap:%d %s"}},{push:"fmtp",reg:/^fmtp:(\d*) ([\S| ]*)/,names:["payload","config"],format:"fmtp:%d %s"},{name:"control",reg:/^control:(.*)/,format:"control:%s"},{name:"rtcp",reg:/^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,names:["port","netType","ipVer","address"],format:function(c){return c.address!=null?"rtcp:%d %s IP%d %s":"rtcp:%d"}},{push:"rtcpFbTrrInt",reg:/^rtcp-fb:(\*|\d*) trr-int (\d*)/,names:["payload","value"],format:"rtcp-fb:%s trr-int %d"},{push:"rtcpFb",reg:/^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/,names:["payload","type","subtype"],format:function(c){return c.subtype!=null?"rtcp-fb:%s %s %s":"rtcp-fb:%s %s"}},{push:"ext",reg:/^extmap:(\d+)(?:\/(\w+))?(?: (urn:ietf:params:rtp-hdrext:encrypt))? (\S*)(?: (\S*))?/,names:["value","direction","encrypt-uri","uri","config"],format:function(c){return"extmap:%d"+(c.direction?"/%s":"%v")+(c["encrypt-uri"]?" %s":"%v")+" %s"+(c.config?" %s":"")}},{name:"extmapAllowMixed",reg:/^(extmap-allow-mixed)/},{push:"crypto",reg:/^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,names:["id","suite","config","sessionConfig"],format:function(c){return c.sessionConfig!=null?"crypto:%d %s %s %s":"crypto:%d %s %s"}},{name:"setup",reg:/^setup:(\w*)/,format:"setup:%s"},{name:"connectionType",reg:/^connection:(new|existing)/,format:"connection:%s"},{name:"mid",reg:/^mid:([^\s]*)/,format:"mid:%s"},{name:"msid",reg:/^msid:(.*)/,format:"msid:%s"},{name:"ptime",reg:/^ptime:(\d*(?:\.\d*)*)/,format:"ptime:%d"},{name:"maxptime",reg:/^maxptime:(\d*(?:\.\d*)*)/,format:"maxptime:%d"},{name:"direction",reg:/^(sendrecv|recvonly|sendonly|inactive)/},{name:"icelite",reg:/^(ice-lite)/},{name:"iceUfrag",reg:/^ice-ufrag:(\S*)/,format:"ice-ufrag:%s"},{name:"icePwd",reg:/^ice-pwd:(\S*)/,format:"ice-pwd:%s"},{name:"fingerprint",reg:/^fingerprint:(\S*) (\S*)/,names:["type","hash"],format:"fingerprint:%s %s"},{push:"candidates",reg:/^candidate:(\S*) (\d*) (\S*) (\d*) (\S*) (\d*) typ (\S*)(?: raddr (\S*) rport (\d*))?(?: tcptype (\S*))?(?: generation (\d*))?(?: network-id (\d*))?(?: network-cost (\d*))?/,names:["foundation","component","transport","priority","ip","port","type","raddr","rport","tcptype","generation","network-id","network-cost"],format:function(c){var t="candidate:%s %d %s %d %s %d typ %s";return t+=c.raddr!=null?" raddr %s rport %d":"%v%v",t+=c.tcptype!=null?" tcptype %s":"%v",c.generation!=null&&(t+=" generation %d"),t+=c["network-id"]!=null?" network-id %d":"%v",t+=c["network-cost"]!=null?" network-cost %d":"%v",t}},{name:"endOfCandidates",reg:/^(end-of-candidates)/},{name:"remoteCandidates",reg:/^remote-candidates:(.*)/,format:"remote-candidates:%s"},{name:"iceOptions",reg:/^ice-options:(\S*)/,format:"ice-options:%s"},{push:"ssrcs",reg:/^ssrc:(\d*) ([\w_-]*)(?::(.*))?/,names:["id","attribute","value"],format:function(c){var t="ssrc:%d";return c.attribute!=null&&(t+=" %s",c.value!=null&&(t+=":%s")),t}},{push:"ssrcGroups",reg:/^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/,names:["semantics","ssrcs"],format:"ssrc-group:%s %s"},{name:"msidSemantic",reg:/^msid-semantic:\s?(\w*) (\S*)/,names:["semantic","token"],format:"msid-semantic: %s %s"},{push:"groups",reg:/^group:(\w*) (.*)/,names:["type","mids"],format:"group:%s %s"},{name:"rtcpMux",reg:/^(rtcp-mux)/},{name:"rtcpRsize",reg:/^(rtcp-rsize)/},{name:"sctpmap",reg:/^sctpmap:([\w_/]*) (\S*)(?: (\S*))?/,names:["sctpmapNumber","app","maxMessageSize"],format:function(c){return c.maxMessageSize!=null?"sctpmap:%s %s %s":"sctpmap:%s %s"}},{name:"xGoogleFlag",reg:/^x-google-flag:([^\s]*)/,format:"x-google-flag:%s"},{push:"rids",reg:/^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/,names:["id","direction","params"],format:function(c){return c.params?"rid:%s %s %s":"rid:%s %s"}},{push:"imageattrs",reg:new RegExp("^imageattr:(\\d+|\\*)[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?"),names:["pt","dir1","attrs1","dir2","attrs2"],format:function(c){return"imageattr:%s %s %s"+(c.dir2?" %s %s":"")}},{name:"simulcast",reg:new RegExp("^simulcast:(send|recv) ([a-zA-Z0-9\\-_~;,]+)(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?$"),names:["dir1","list1","dir2","list2"],format:function(c){return"simulcast:%s %s"+(c.dir2?" %s %s":"")}},{name:"simulcast_03",reg:/^simulcast:[\s\t]+([\S+\s\t]+)$/,names:["value"],format:"simulcast: %s"},{name:"framerate",reg:/^framerate:(\d+(?:$|\.\d+))/,format:"framerate:%s"},{name:"sourceFilter",reg:/^source-filter: *(excl|incl) (\S*) (IP4|IP6|\*) (\S*) (.*)/,names:["filterMode","netType","addressTypes","destAddress","srcList"],format:"source-filter: %s %s %s %s %s"},{name:"bundleOnly",reg:/^(bundle-only)/},{name:"label",reg:/^label:(.+)/,format:"label:%s"},{name:"sctpPort",reg:/^sctp-port:(\d+)$/,format:"sctp-port:%s"},{name:"maxMessageSize",reg:/^max-message-size:(\d+)$/,format:"max-message-size:%s"},{push:"tsRefClocks",reg:/^ts-refclk:([^\s=]*)(?:=(\S*))?/,names:["clksrc","clksrcExt"],format:function(c){return"ts-refclk:%s"+(c.clksrcExt!=null?"=%s":"")}},{name:"mediaClk",reg:/^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/,names:["id","mediaClockName","mediaClockValue","rateNumerator","rateDenominator"],format:function(c){var t="mediaclk:";return t+=c.id!=null?"id=%s %s":"%v%s",t+=c.mediaClockValue!=null?"=%s":"",t+=c.rateNumerator!=null?" rate=%s":"",t+=c.rateDenominator!=null?"/%s":"",t}},{name:"keywords",reg:/^keywds:(.+)$/,format:"keywds:%s"},{name:"content",reg:/^content:(.+)/,format:"content:%s"},{name:"bfcpFloorCtrl",reg:/^floorctrl:(c-only|s-only|c-s)/,format:"floorctrl:%s"},{name:"bfcpConfId",reg:/^confid:(\d+)/,format:"confid:%s"},{name:"bfcpUserId",reg:/^userid:(\d+)/,format:"userid:%s"},{name:"bfcpFloorId",reg:/^floorid:(.+) (?:m-stream|mstrm):(.+)/,names:["id","mStream"],format:"floorid:%s mstrm:%s"},{push:"invalid",names:["value"]}]};Object.keys(ec).forEach(function(c){var t=ec[c];t.forEach(function(n){n.reg||(n.reg=/(.*)/),n.format||(n.format="%s")})});var Zf=Qf.exports;(function(c){var t=function(d){return String(Number(d))===d?Number(d):d},n=function(d,h,_,g){if(g&&!_)h[g]=t(d[1]);else for(var T=0;T<_.length;T+=1)d[T+1]!=null&&(h[_[T]]=t(d[T+1]))},a=function(d,h,_){var g=d.name&&d.names;d.push&&!h[d.push]?h[d.push]=[]:g&&!h[d.name]&&(h[d.name]={});var T=d.push?{}:g?h[d.name]:h;n(_.match(d.reg),T,d.names,d.name),d.push&&h[d.push].push(T)},o=Zf,s=RegExp.prototype.test.bind(/^([a-z])=(.*)/);c.parse=function(d){var h={},_=[],g=h;return d.split(/(\r\n|\r|\n)/).filter(s).forEach(function(T){var E=T[0],y=T.slice(2);E==="m"&&(_.push({rtp:[],fmtp:[]}),g=_[_.length-1]);for(var C=0;C<(o[E]||[]).length;C+=1){var A=o[E][C];if(A.reg.test(y))return a(A,g,y)}}),h.media=_,h};var r=function(d,h){var _=h.split(/=(.+)/,2);return _.length===2?d[_[0]]=t(_[1]):_.length===1&&h.length>1&&(d[_[0]]=void 0),d};c.parseParams=function(d){return d.split(/;\s?/).reduce(r,{})},c.parseFmtpConfig=c.parseParams,c.parsePayloads=function(d){return d.toString().split(" ").map(Number)},c.parseRemoteCandidates=function(d){for(var h=[],_=d.split(" ").map(t),g=0;g<_.length;g+=3)h.push({component:_[g],ip:_[g+1],port:_[g+2]});return h},c.parseImageAttributes=function(d){return d.split(" ").map(function(h){return h.substring(1,h.length-1).split(",").reduce(r,{})})},c.parseSimulcastStreamList=function(d){return d.split(";").map(function(h){return h.split(",").map(function(_){var g,T=!1;return _[0]!=="~"?g=t(_):(g=t(_.substring(1,_.length)),T=!0),{scid:g,paused:T}})})}})(Xf);var mo=Zf,Sd=/%[sdv%]/g,yd=function(c){var t=1,n=arguments,a=n.length;return c.replace(Sd,function(o){if(t>=a)return o;var s=n[t];switch(t+=1,o){case"%%":return"%";case"%s":return String(s);case"%d":return Number(s);case"%v":return""}})},Di=function(c,t,n){var a=t.format instanceof Function?t.format(t.push?n:n[t.name]):t.format,o=[c+"="+a];if(t.names)for(var s=0;s<t.names.length;s+=1){var r=t.names[s];t.name?o.push(n[t.name][r]):o.push(n[t.names[s]])}else o.push(n[t.name]);return yd.apply(null,o)},Cd=["v","o","s","i","u","e","p","c","b","t","r","z","a"],Ad=["i","c","b","a"],Rd=function(c,t){t=t||{},c.version==null&&(c.version=0),c.name==null&&(c.name=" "),c.media.forEach(function(s){s.payloads==null&&(s.payloads="")});var n=t.outerOrder||Cd,a=t.innerOrder||Ad,o=[];return n.forEach(function(s){mo[s].forEach(function(r){r.name in c&&c[r.name]!=null?o.push(Di(s,r,c)):r.push in c&&c[r.push]!=null&&c[r.push].forEach(function(d){o.push(Di(s,r,d))})})}),c.media.forEach(function(s){o.push(Di("m",mo.m[0],s)),a.forEach(function(r){mo[r].forEach(function(d){d.name in s&&s[d.name]!=null?o.push(Di(r,d,s)):d.push in s&&s[d.push]!=null&&s[d.push].forEach(function(h){o.push(Di(r,d,h))})})})}),o.join(`\r
|
7
7
|
`)+`\r
|
8
8
|
`},bn=Xf,Id=Rd;xt.write=Id;xt.parse=bn.parse;xt.parseParams=bn.parseParams;xt.parseFmtpConfig=bn.parseFmtpConfig;xt.parsePayloads=bn.parsePayloads;xt.parseRemoteCandidates=bn.parseRemoteCandidates;xt.parseImageAttributes=bn.parseImageAttributes;xt.parseSimulcastStreamList=bn.parseSimulcastStreamList;function va(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?va=function(n){return typeof n}:va=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},va(c)}function Nu(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&cu(c,t)}function cu(c,t){return cu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},cu(c,t)}function Uu(c){var t=Od();return function(){var a=Da(c),o;if(t){var s=Da(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return bd(this,o)}}function bd(c,t){return t&&(va(t)==="object"||typeof t=="function")?t: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 Od(){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 Da(c){return Da=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Da(c)}function Bt(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=Dd(c))||t&&c&&typeof c.length=="number"){n&&(c=n);var a=0,o=function(){};return{s:o,n:function(){return a>=c.length?{done:!0}:{done:!1,value:c[a++]}},e:function(_){throw _},f:o}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
9
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function Dd(c,t){if(c){if(typeof c=="string")return tc(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return tc(c,t)}}function tc(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}function il(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function sc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Ga(c,t,n){return t&&sc(c.prototype,t),n&&sc(c,n),c}var eh=xt,Nd=ht,Et=lt,rt=bt(),nc=Ou(),Ud=os(),go=new Nd("SIPMessage"),th=function(){function c(t,n,a,o,s,r){if(il(this,c),!t||!n||!a)return null;o=o||{},this.ua=a,this.headers={},this.method=t,this.ruri=n,this.body=r,this.extraHeaders=rt.cloneArray(s),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),o.route_set?this.setHeader("route",o.route_set):a.configuration.use_preloaded_route&&this.setHeader("route","<".concat(a.transport.sip_uri,";lr>")),this.setHeader("via",""),this.setHeader("max-forwards",Et.MAX_FORWARDS);var d=o.to_uri||n,h=o.to_tag?{tag:o.to_tag}:null,_=typeof o.to_display_name<"u"?o.to_display_name:null;this.to=new nc(d,_,h),this.setHeader("to",this.to.toString());var g=o.from_uri||a.configuration.uri,T={tag:o.from_tag||rt.newTag()},E;typeof o.from_display_name<"u"?E=o.from_display_name:a.configuration.display_name?E=a.configuration.display_name:E=null,this.from=new nc(g,E,T),this.setHeader("from",this.from.toString());var y=o.call_id||a.configuration.jssip_id+rt.createRandomToken(15);this.call_id=y,this.setHeader("call-id",y);var
|
9
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function Dd(c,t){if(c){if(typeof c=="string")return tc(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return tc(c,t)}}function tc(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}function il(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function sc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Ga(c,t,n){return t&&sc(c.prototype,t),n&&sc(c,n),c}var eh=xt,Nd=ht,Et=lt,rt=bt(),nc=Ou(),Ud=os(),go=new Nd("SIPMessage"),th=function(){function c(t,n,a,o,s,r){if(il(this,c),!t||!n||!a)return null;o=o||{},this.ua=a,this.headers={},this.method=t,this.ruri=n,this.body=r,this.extraHeaders=rt.cloneArray(s),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),o.route_set?this.setHeader("route",o.route_set):a.configuration.use_preloaded_route&&this.setHeader("route","<".concat(a.transport.sip_uri,";lr>")),this.setHeader("via",""),this.setHeader("max-forwards",Et.MAX_FORWARDS);var d=o.to_uri||n,h=o.to_tag?{tag:o.to_tag}:null,_=typeof o.to_display_name<"u"?o.to_display_name:null;this.to=new nc(d,_,h),this.setHeader("to",this.to.toString());var g=o.from_uri||a.configuration.uri,T={tag:o.from_tag||rt.newTag()},E;typeof o.from_display_name<"u"?E=o.from_display_name:a.configuration.display_name?E=a.configuration.display_name:E=null,this.from=new nc(g,E,T),this.setHeader("from",this.from.toString());var y=o.call_id||a.configuration.jssip_id+rt.createRandomToken(15);this.call_id=y,this.setHeader("call-id",y);var C=o.cseq||Math.floor(Math.random()*1e4);this.cseq=C,this.setHeader("cseq","".concat(C," ").concat(t))}return Ga(c,[{key:"setHeader",value:function(n,a){for(var o=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),s=0;s<this.extraHeaders.length;s++)o.test(this.extraHeaders[s])&&this.extraHeaders.splice(s,1);this.headers[rt.headerize(n)]=Array.isArray(a)?a:[a]}},{key:"getHeader",value:function(n){var a=this.headers[rt.headerize(n)];if(a){if(a[0])return a[0]}else{var o=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),s=Bt(this.extraHeaders),r;try{for(s.s();!(r=s.n()).done;){var d=r.value;if(o.test(d))return d.substring(d.indexOf(":")+1).trim()}}catch(h){s.e(h)}finally{s.f()}}}},{key:"getHeaders",value:function(n){var a=this.headers[rt.headerize(n)],o=[];if(a){var s=Bt(a),r;try{for(s.s();!(r=s.n()).done;){var d=r.value;o.push(d)}}catch(E){s.e(E)}finally{s.f()}return o}else{var h=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),_=Bt(this.extraHeaders),g;try{for(_.s();!(g=_.n()).done;){var T=g.value;h.test(T)&&o.push(T.substring(T.indexOf(":")+1).trim())}}catch(E){_.e(E)}finally{_.f()}return o}}},{key:"hasHeader",value:function(n){if(this.headers[rt.headerize(n)])return!0;var a=new RegExp("^\\s*".concat(n,"\\s*:"),"i"),o=Bt(this.extraHeaders),s;try{for(o.s();!(s=o.n()).done;){var r=s.value;if(a.test(r))return!0}}catch(d){o.e(d)}finally{o.f()}return!1}},{key:"parseSDP",value:function(n){return!n&&this.sdp?this.sdp:(this.sdp=eh.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){var n="".concat(this.method," ").concat(this.ruri,` SIP/2.0\r
|
10
10
|
`);for(var a in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,a)){var o=Bt(this.headers[a]),s;try{for(o.s();!(s=o.n()).done;){var r=s.value;n+="".concat(a,": ").concat(r,`\r
|
11
11
|
`)}}catch(y){o.e(y)}finally{o.f()}}var d=Bt(this.extraHeaders),h;try{for(d.s();!(h=d.n()).done;){var _=h.value;n+="".concat(_.trim(),`\r
|
12
12
|
`)}}catch(y){d.e(y)}finally{d.f()}var g=[];switch(this.method){case 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(n+="Allow: ".concat(Et.ALLOWED_METHODS,`\r
|
@@ -17,8 +17,8 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
17
17
|
`),n+=this.body}else n+=`Content-Length: 0\r
|
18
18
|
\r
|
19
19
|
`;return n}},{key:"clone",value:function(){var n=new c(this.method,this.ruri,this.ua);return Object.keys(this.headers).forEach(function(a){n.headers[a]=this.headers[a].slice()},this),n.body=this.body,n.extraHeaders=rt.cloneArray(this.extraHeaders),n.to=this.to,n.from=this.from,n.call_id=this.call_id,n.cseq=this.cseq,n}}]),c}(),Pd=function(c){Nu(n,c);var t=Uu(n);function n(a,o,s,r,d){var h;return il(this,n),h=t.call(this,Et.INVITE,a,o,s,r,d),h.transaction=null,h}return Ga(n,[{key:"cancel",value:function(o){this.transaction.cancel(o)}},{key:"clone",value:function(){var o=new n(this.ruri,this.ua);return Object.keys(this.headers).forEach(function(s){o.headers[s]=this.headers[s].slice()},this),o.body=this.body,o.extraHeaders=rt.cloneArray(this.extraHeaders),o.to=this.to,o.from=this.from,o.call_id=this.call_id,o.cseq=this.cseq,o.transaction=this.transaction,o}}]),n}(th),sh=function(){function c(){il(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 Ga(c,[{key:"addHeader",value:function(n,a){var o={raw:a};n=rt.headerize(n),this.headers[n]?this.headers[n].push(o):this.headers[n]=[o]}},{key:"getHeader",value:function(n){var a=this.headers[rt.headerize(n)];if(a){if(a[0])return a[0].raw}else return}},{key:"getHeaders",value:function(n){var a=this.headers[rt.headerize(n)],o=[];if(!a)return[];var s=Bt(a),r;try{for(s.s();!(r=s.n()).done;){var d=r.value;o.push(d.raw)}}catch(h){s.e(h)}finally{s.f()}return o}},{key:"hasHeader",value:function(n){return!!this.headers[rt.headerize(n)]}},{key:"parseHeader",value:function(n){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;if(n=rt.headerize(n),this.headers[n]){if(a>=this.headers[n].length){go.debug('not so many "'.concat(n,'" headers present'));return}}else{go.debug('header "'.concat(n,'" not present'));return}var o=this.headers[n][a],s=o.raw;if(o.parsed)return o.parsed;var r=Ud.parse(s,n.replace(/-/g,"_"));if(r===-1){this.headers[n].splice(a,1),go.debug('error parsing "'.concat(n,'" header field with value "').concat(s,'"'));return}else return o.parsed=r,r}},{key:"s",value:function(n,a){return this.parseHeader(n,a)}},{key:"setHeader",value:function(n,a){var o={raw:a};this.headers[rt.headerize(n)]=[o]}},{key:"parseSDP",value:function(n){return!n&&this.sdp?this.sdp:(this.sdp=eh.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}]),c}(),xd=function(c){Nu(n,c);var t=Uu(n);function n(a){var o;return il(this,n),o=t.call(this),o.ua=a,o.headers={},o.ruri=null,o.transport=null,o.server_transaction=null,o}return Ga(n,[{key:"reply",value:function(o,s,r,d,h,_){var g=[],T=this.getHeader("To");if(o=o||null,s=s||null,!o||o<100||o>699)throw new TypeError("Invalid status_code: ".concat(o));if(s&&typeof s!="string"&&!(s instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(s));s=s||Et.REASON_PHRASE[o]||"",r=rt.cloneArray(r),this.ua.configuration.extra_headers&&(r=r.concat(this.ua.configuration.extra_headers));var E="SIP/2.0 ".concat(o," ").concat(s,`\r
|
20
|
-
`);if(this.method===Et.INVITE&&o>100&&o<=200){var y=this.getHeaders("record-route"),
|
21
|
-
`)}}catch(D){
|
20
|
+
`);if(this.method===Et.INVITE&&o>100&&o<=200){var y=this.getHeaders("record-route"),C=Bt(y),A;try{for(C.s();!(A=C.n()).done;){var I=A.value;E+="Record-Route: ".concat(I,`\r
|
21
|
+
`)}}catch(D){C.e(D)}finally{C.f()}}var H=this.getHeaders("via"),$=Bt(H),oe;try{for($.s();!(oe=$.n()).done;){var N=oe.value;E+="Via: ".concat(N,`\r
|
22
22
|
`)}}catch(D){$.e(D)}finally{$.f()}!this.to_tag&&o>100?T+=";tag=".concat(rt.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(T+=";tag=".concat(this.to_tag)),E+="To: ".concat(T,`\r
|
23
23
|
`),E+="From: ".concat(this.getHeader("From"),`\r
|
24
24
|
`),E+="Call-ID: ".concat(this.call_id,`\r
|
@@ -36,18 +36,18 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
36
36
|
\r
|
37
37
|
`);this.server_transaction.receiveResponse(o,E,h,_)}},{key:"reply_sl",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:null,s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:null,r=this.getHeaders("via");if(!o||o<100||o>699)throw new TypeError("Invalid status_code: ".concat(o));if(s&&typeof s!="string"&&!(s instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(s));s=s||Et.REASON_PHRASE[o]||"";var d="SIP/2.0 ".concat(o," ").concat(s,`\r
|
38
38
|
`),h=Bt(r),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;d+="Via: ".concat(g,`\r
|
39
|
-
`)}}catch(
|
39
|
+
`)}}catch(A){h.e(A)}finally{h.f()}var T=this.getHeader("To");if(!this.to_tag&&o>100?T+=";tag=".concat(rt.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(T+=";tag=".concat(this.to_tag)),d+="To: ".concat(T,`\r
|
40
40
|
`),d+="From: ".concat(this.getHeader("From"),`\r
|
41
41
|
`),d+="Call-ID: ".concat(this.call_id,`\r
|
42
42
|
`),d+="CSeq: ".concat(this.cseq," ").concat(this.method,`\r
|
43
|
-
`),this.ua.configuration.extra_headers){var E=Bt(this.ua.configuration.extra_headers),y;try{for(E.s();!(y=E.n()).done;){var
|
44
|
-
`)}}catch(
|
43
|
+
`),this.ua.configuration.extra_headers){var E=Bt(this.ua.configuration.extra_headers),y;try{for(E.s();!(y=E.n()).done;){var C=y.value;d+="".concat(C.trim(),`\r
|
44
|
+
`)}}catch(A){E.e(A)}finally{E.f()}}d+="Content-Length: ".concat(0,`\r
|
45
45
|
\r
|
46
|
-
`),this.transport.send(d)}}]),n}(sh),kd=function(c){Nu(n,c);var t=Uu(n);function n(){var a;return il(this,n),a=t.call(this),a.headers={},a.status_code=null,a.reason_phrase=null,a}return n}(sh),Ss={OutgoingRequest:th,InitialOutgoingInviteRequest:Pd,IncomingRequest:xd,IncomingResponse:kd};function Md(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function rc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Ld(c,t,n){return t&&rc(c.prototype,t),n&&rc(c,n),c}var $d=ht,hs=bt(),Yt=new $d("DigestAuthentication"),Hd=function(){function c(t){Md(this,c),this._credentials=t,this._cnonce=null,this._nc=0,this._ncHex="00000000",this._algorithm=null,this._realm=null,this._nonce=null,this._opaque=null,this._stale=null,this._qop=null,this._method=null,this._uri=null,this._ha1=null,this._response=null}return Ld(c,[{key:"get",value:function(n){switch(n){case"realm":return this._realm;case"ha1":return this._ha1;default:Yt.warn('get() | cannot get "%s" parameter',n);return}}},{key:"authenticate",value:function(n,a){var o=n.method,s=n.ruri,r=n.body,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:null;if(this._algorithm=a.algorithm,this._realm=a.realm,this._nonce=a.nonce,this._opaque=a.opaque,this._stale=a.stale,this._algorithm){if(this._algorithm!=="MD5")return Yt.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return Yt.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return Yt.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return Yt.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return Yt.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(a.qop)if(a.qop.indexOf("auth-int")>-1)this._qop="auth-int";else if(a.qop.indexOf("auth")>-1)this._qop="auth";else return Yt.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;else this._qop=null;this._method=o,this._uri=s,this._cnonce=d||hs.createRandomToken(12),this._nc+=1;var h=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-h.length)+h,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=hs.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1;var _,g;return this._qop==="auth"?(_="".concat(this._method,":").concat(this._uri),g=hs.calculateMD5(_),Yt.debug('authenticate() | using qop=auth [a2:"%s"]',_),this._response=hs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(g))):this._qop==="auth-int"?(_="".concat(this._method,":").concat(this._uri,":").concat(hs.calculateMD5(r||"")),g=hs.calculateMD5(_),Yt.debug('authenticate() | using qop=auth-int [a2:"%s"]',_),this._response=hs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(g))):this._qop===null&&(_="".concat(this._method,":").concat(this._uri),g=hs.calculateMD5(_),Yt.debug('authenticate() | using qop=null [a2:"%s"]',_),this._response=hs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(g))),Yt.debug("authenticate() | response generated"),!0}},{key:"toString",value:function(){var n=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return n.push("algorithm=".concat(this._algorithm)),n.push('username="'.concat(this._credentials.username,'"')),n.push('realm="'.concat(this._realm,'"')),n.push('nonce="'.concat(this._nonce,'"')),n.push('uri="'.concat(this._uri,'"')),n.push('response="'.concat(this._response,'"')),this._opaque&&n.push('opaque="'.concat(this._opaque,'"')),this._qop&&(n.push("qop=".concat(this._qop)),n.push('cnonce="'.concat(this._cnonce,'"')),n.push("nc=".concat(this._ncHex))),"Digest ".concat(n.join(", "))}}]),c}(),ds=500,Fd=4e3,ic=5e3,nh={T1:ds,T2:Fd,T4:ic,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*ic,TIMER_L:64*ds,TIMER_M:64*ds,PROVISIONAL_RESPONSE_INTERVAL:6e4};function Ea(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ea=function(n){return typeof n}:Ea=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Ea(c)}function ll(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function lc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function al(c,t,n){return t&&lc(c.prototype,t),n&&lc(c,n),c}function ol(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&fu(c,t)}function fu(c,t){return fu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},fu(c,t)}function ul(c){var t=qd();return function(){var a=Na(c),o;if(t){var s=Na(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return jd(this,o)}}function jd(c,t){return t&&(Ea(t)==="object"||typeof t=="function")?t:Bs(c)}function Bs(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 Na(c){return Na=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Na(c)}var cl=ft.EventEmitter,fl=ht,zi=lt,ac=Ss,ls=nh,oc=new fl("NonInviteClientTransaction"),Hl=new fl("InviteClientTransaction"),Vd=new fl("AckClientTransaction"),uc=new fl("NonInviteServerTransaction"),Fl=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"},Bd=function(c){ol(n,c);var t=ul(n);function n(a,o,s,r){var d;ll(this,n),d=t.call(this),d.type=he.NON_INVITE_CLIENT,d.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),d.ua=a,d.transport=o,d.request=s,d.eventHandlers=r;var h="SIP/2.0/".concat(o.via_transport);return h+=" ".concat(a.configuration.via_host,";branch=").concat(d.id),d.request.setHeader("via",h),d.ua.newTransaction(Bs(d)),d}return al(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"send",value:function(){var o=this;this.stateChanged(he.STATUS_TRYING),this.F=setTimeout(function(){o.timer_F()},ls.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(he.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(he.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}},{key:"timer_K",value:function(){this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"receiveResponse",value:function(o){var s=this,r=o.status_code;if(r<200)switch(this.state){case he.STATUS_TRYING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(o);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(o),this.K=setTimeout(function(){s.timer_K()},ls.TIMER_K);break;case he.STATUS_COMPLETED:break}}},{key:"C",get:function(){return he}}]),n}(cl),Gd=function(c){ol(n,c);var t=ul(n);function n(a,o,s,r){var d;ll(this,n),d=t.call(this),d.type=he.INVITE_CLIENT,d.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),d.ua=a,d.transport=o,d.request=s,d.eventHandlers=r,s.transaction=Bs(d);var h="SIP/2.0/".concat(o.via_transport);return h+=" ".concat(a.configuration.via_host,";branch=").concat(d.id),d.request.setHeader("via",h),d.ua.newTransaction(Bs(d)),d}return al(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"send",value:function(){var o=this;this.stateChanged(he.STATUS_CALLING),this.B=setTimeout(function(){o.timer_B()},ls.TIMER_B),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==he.STATUS_ACCEPTED&&(Hl.debug("transport error occurred, deleting transaction ".concat(this.id)),this.eventHandlers.onTransportError()),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_M",value:function(){Hl.debug("Timer M expired for transaction ".concat(this.id)),this.state===he.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"timer_B",value:function(){Hl.debug("Timer B expired for transaction ".concat(this.id)),this.state===he.STATUS_CALLING&&(this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}},{key:"timer_D",value:function(){Hl.debug("Timer D expired for transaction ".concat(this.id)),clearTimeout(this.B),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"sendACK",value:function(o){var s=this,r=new ac.OutgoingRequest(zi.ACK,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});r.setHeader("from",this.request.getHeader("from")),r.setHeader("via",this.request.getHeader("via")),r.setHeader("to",o.getHeader("to")),this.D=setTimeout(function(){s.timer_D()},ls.TIMER_D),this.transport.send(r)}},{key:"cancel",value:function(o){if(this.state===he.STATUS_PROCEEDING){var s=new ac.OutgoingRequest(zi.CANCEL,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});s.setHeader("from",this.request.getHeader("from")),s.setHeader("via",this.request.getHeader("via")),s.setHeader("to",this.request.getHeader("to")),o&&s.setHeader("reason",o),this.transport.send(s)}}},{key:"receiveResponse",value:function(o){var s=this,r=o.status_code;if(r>=100&&r<=199)switch(this.state){case he.STATUS_CALLING:this.stateChanged(he.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(o);break;case he.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(o);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(function(){s.timer_M()},ls.TIMER_M),this.eventHandlers.onReceiveResponse(o);break;case he.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(o);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(o),this.eventHandlers.onReceiveResponse(o);break;case he.STATUS_COMPLETED:this.sendACK(o);break}}},{key:"C",get:function(){return he}}]),n}(cl),Wd=function(c){ol(n,c);var t=ul(n);function n(a,o,s,r){var d;ll(this,n),d=t.call(this),d.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),d.transport=o,d.request=s,d.eventHandlers=r;var h="SIP/2.0/".concat(o.via_transport);return h+=" ".concat(a.configuration.via_host,";branch=").concat(d.id),d.request.setHeader("via",h),d}return al(n,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){Vd.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return he}}]),n}(cl),Kd=function(c){ol(n,c);var t=ul(n);function n(a,o,s){var r;return ll(this,n),r=t.call(this),r.type=he.NON_INVITE_SERVER,r.id=s.via_branch,r.ua=a,r.transport=o,r.request=s,r.last_response="",s.server_transaction=Bs(r),r.state=he.STATUS_TRYING,a.newTransaction(Bs(r)),r}return al(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"timer_J",value:function(){uc.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(he.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(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(o,s,r,d){var h=this;if(o===100)switch(this.state){case he.STATUS_TRYING:this.stateChanged(he.STATUS_PROCEEDING),this.transport.send(s)||this.onTransportError();break;case he.STATUS_PROCEEDING:this.last_response=s,this.transport.send(s)?r&&r():(this.onTransportError(),d&&d());break}else if(o>=200&&o<=699)switch(this.state){case he.STATUS_TRYING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_COMPLETED),this.last_response=s,this.J=setTimeout(function(){h.timer_J()},ls.TIMER_J),this.transport.send(s)?r&&r():(this.onTransportError(),d&&d());break;case he.STATUS_COMPLETED:break}}},{key:"C",get:function(){return he}}]),n}(cl),Yd=function(c){ol(n,c);var t=ul(n);function n(a,o,s){var r;return ll(this,n),r=t.call(this),r.type=he.INVITE_SERVER,r.id=s.via_branch,r.ua=a,r.transport=o,r.request=s,r.last_response="",s.server_transaction=Bs(r),r.state=he.STATUS_PROCEEDING,a.newTransaction(Bs(r)),r.resendProvisionalTimer=null,s.reply(100),r}return al(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"timer_H",value:function(){Fl.debug("Timer H expired for transaction ".concat(this.id)),this.state===he.STATUS_COMPLETED&&Fl.debug("ACK not received, dialog will be terminated"),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){Fl.debug("Timer L expired for transaction ".concat(this.id)),this.state===he.STATUS_ACCEPTED&&(this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,Fl.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(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"resend_provisional",value:function(){this.transport.send(this.last_response)||this.onTransportError()}},{key:"receiveResponse",value:function(o,s,r,d){var h=this;if(o>=100&&o<=199)switch(this.state){case he.STATUS_PROCEEDING:this.transport.send(s)||this.onTransportError(),this.last_response=s;break}if(o>100&&o<=199&&this.state===he.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(function(){h.resend_provisional()},ls.PROVISIONAL_RESPONSE_INTERVAL));else if(o>=200&&o<=299)switch(this.state){case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_ACCEPTED),this.last_response=s,this.L=setTimeout(function(){h.timer_L()},ls.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case he.STATUS_ACCEPTED:this.transport.send(s)?r&&r():(this.onTransportError(),d&&d());break}else if(o>=300&&o<=699)switch(this.state){case he.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(s)?(this.stateChanged(he.STATUS_COMPLETED),this.H=setTimeout(function(){h.timer_H()},ls.TIMER_H),r&&r()):(this.onTransportError(),d&&d());break}}},{key:"C",get:function(){return he}}]),n}(cl);function Jd(c,t){var n=c._transactions,a;switch(t.method){case zi.INVITE:if(a=n.ist[t.via_branch],a){switch(a.state){case he.STATUS_PROCEEDING:a.transport.send(a.last_response);break;case he.STATUS_ACCEPTED:break}return!0}break;case zi.ACK:if(a=n.ist[t.via_branch],a){if(a.state===he.STATUS_ACCEPTED)return!1;if(a.state===he.STATUS_COMPLETED)return a.state=he.STATUS_CONFIRMED,a.I=setTimeout(function(){a.timer_I()},ls.TIMER_I),!0}else return!1;break;case zi.CANCEL:return a=n.ist[t.via_branch],a?(t.reply_sl(200),a.state!==he.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(a=n.nist[t.via_branch],a){switch(a.state){case he.STATUS_TRYING:break;case he.STATUS_PROCEEDING:case he.STATUS_COMPLETED:a.transport.send(a.last_response);break}return!0}break}}var hl={C:he,NonInviteClientTransaction:Bd,InviteClientTransaction:Gd,AckClientTransaction:Wd,NonInviteServerTransaction:Kd,InviteServerTransaction:Yd,checkTransaction:Jd};function zd(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function cc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Xd(c,t,n){return t&&cc(c.prototype,t),n&&cc(c,n),c}var Qd=ht,fc=lt,Zd=Hd,To=hl,e_=new Qd("RequestSender"),vo={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}},dl=function(){function c(t,n,a){zd(this,c),this._ua=t,this._eventHandlers=a,this._method=n.method,this._request=n,this._auth=null,this._challenged=!1,this._staled=!1;for(var o in vo)Object.prototype.hasOwnProperty.call(vo,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=vo[o]));t.status===t.C.STATUS_USER_CLOSED&&(this._method!==fc.BYE||this._method!==fc.ACK)&&this._eventHandlers.onTransportError()}return Xd(c,[{key:"send",value:function(){var n=this,a={onRequestTimeout:function(){n._eventHandlers.onRequestTimeout()},onTransportError:function(){n._eventHandlers.onTransportError()},onReceiveResponse:function(s){n._receiveResponse(s)}};switch(this._method){case"INVITE":this.clientTransaction=new To.InviteClientTransaction(this._ua,this._ua.transport,this._request,a);break;case"ACK":this.clientTransaction=new To.AckClientTransaction(this._ua,this._ua.transport,this._request,a);break;default:this.clientTransaction=new To.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,a)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}},{key:"_receiveResponse",value:function(n){var a,o,s=n.status_code;if((s===401||s===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(n.status_code===401?(a=n.parseHeader("www-authenticate"),o="authorization"):(a=n.parseHeader("proxy-authenticate"),o="proxy-authorization"),!a){e_.debug("".concat(n.status_code," with wrong or missing challenge, cannot authenticate")),this._eventHandlers.onReceiveResponse(n);return}if(!this._challenged||!this._staled&&a.stale===!0){if(this._auth||(this._auth=new Zd({username:this._ua.configuration.authorization_user,password:this._ua.configuration.password,realm:this._ua.configuration.realm,ha1:this._ua.configuration.ha1})),!this._auth.authenticate(this._request,a)){this._eventHandlers.onReceiveResponse(n);return}this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),a.stale&&(this._staled=!0),this._request=this._request.clone(),this._request.cseq+=1,this._request.setHeader("cseq","".concat(this._request.cseq," ").concat(this._method)),this._request.setHeader(o,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(n)}else this._eventHandlers.onReceiveResponse(n)}}]),c}();function t_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function hc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function s_(c,t,n){return t&&hc(c.prototype,t),n&&hc(c,n),c}var n_=ht,Eo=bt(),pn=lt,dc=Ss,_c=dl,Ni=new n_("Registrator"),jl=10,r_=function(){function c(t,n){t_(this,c),this._reg_id=1,this._ua=t,this._transport=n,this._registrar=t.configuration.registrar_server,this._expires=t.configuration.register_expires,this._call_id=Eo.createRandomToken(22),this._cseq=0,this._to_uri=t.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString(),this._contact+=";+sip.ice",this._extraHeaders=[],this._extraContactParams="",this._sipInstance='"<urn:uuid:'.concat(this._ua.configuration.instance_id,'>"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}return s_(c,[{key:"setExtraHeaders",value:function(n){Array.isArray(n)||(n=[]),this._extraHeaders=n.slice()}},{key:"setExtraContactParams",value:function(n){n instanceof Object||(n={}),this._extraContactParams="";for(var a in n)if(Object.prototype.hasOwnProperty.call(n,a)){var o=n[a];this._extraContactParams+=";".concat(a),o&&(this._extraContactParams+="=".concat(o))}}},{key:"register",value:function(){var n=this;if(this._registering){Ni.debug("Register request in progress...");return}var a=this._extraHeaders.slice();a.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),a.push("Expires: ".concat(this._expires));var o=new dc.OutgoingRequest(pn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},a),s=new _c(this._ua,o,{onRequestTimeout:function(){n._registrationFailure(null,pn.causes.REQUEST_TIMEOUT)},onTransportError:function(){n._registrationFailure(null,pn.causes.CONNECTION_ERROR)},onAuthenticated:function(){n._cseq+=1},onReceiveResponse:function(d){if(d.cseq===n._cseq)switch(n._registrationTimer!==null&&(clearTimeout(n._registrationTimer),n._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(d.status_code):break;case/^2[0-9]{2}$/.test(d.status_code):{if(n._registering=!1,!d.hasHeader("Contact")){Ni.debug("no Contact header in response to REGISTER, response ignored");break}var h=d.headers.Contact.reduce(function(y,A){return y.concat(A.parsed)},[]),_=h.find(function(y){return n._sipInstance===y.getParam("+sip.instance")&&n._reg_id===parseInt(y.getParam("reg-id"))});if(_||(_=h.find(function(y){return y.uri.user===n._ua.contact.uri.user})),!_){Ni.debug("no Contact header pointing to us, response ignored");break}var g=_.getParam("expires");!g&&d.hasHeader("expires")&&(g=d.getHeader("expires")),g||(g=n._expires),g=Number(g),g<jl&&(g=jl);var T=g>64?g*1e3/2+Math.floor((g/2-32)*1e3*Math.random()):g*1e3-5e3;n._registrationTimer=setTimeout(function(){n._registrationTimer=null,n._ua.listeners("registrationExpiring").length===0?n.register():n._ua.emit("registrationExpiring")},T),_.hasParam("temp-gruu")&&(n._ua.contact.temp_gruu=_.getParam("temp-gruu").replace(/"/g,"")),_.hasParam("pub-gruu")&&(n._ua.contact.pub_gruu=_.getParam("pub-gruu").replace(/"/g,"")),n._registered||(n._registered=!0,n._ua.registered({response:d}));break}case/^423$/.test(d.status_code):{d.hasHeader("min-expires")?(n._expires=Number(d.getHeader("min-expires")),n._expires<jl&&(n._expires=jl),n.register()):(Ni.debug("423 response received for REGISTER without Min-Expires"),n._registrationFailure(d,pn.causes.SIP_FAILURE_CODE));break}default:{var E=Eo.sipErrorCause(d.status_code);n._registrationFailure(d,E)}}}});this._registering=!0,s.send()}},{key:"unregister",value:function(){var n=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!this._registered){Ni.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);var o=this._extraHeaders.slice();a.all?o.push("Contact: *".concat(this._extraContactParams)):o.push("Contact: ".concat(this._contact,";expires=0").concat(this._extraContactParams)),o.push("Expires: 0");var s=new dc.OutgoingRequest(pn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},o),r=new _c(this._ua,s,{onRequestTimeout:function(){n._unregistered(null,pn.causes.REQUEST_TIMEOUT)},onTransportError:function(){n._unregistered(null,pn.causes.CONNECTION_ERROR)},onAuthenticated:function(){n._cseq+=1},onReceiveResponse:function(h){switch(!0){case/^1[0-9]{2}$/.test(h.status_code):break;case/^2[0-9]{2}$/.test(h.status_code):n._unregistered(h);break;default:{var _=Eo.sipErrorCause(h.status_code);n._unregistered(h,_)}}}});r.send()}},{key:"close",value:function(){this._registered&&this.unregister()}},{key:"onTransportClosed",value:function(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}},{key:"_registrationFailure",value:function(n,a){this._registering=!1,this._ua.registrationFailed({response:n||null,cause:a}),this._registered&&(this._registered=!1,this._ua.unregistered({response:n||null,cause:a}))}},{key:"_unregistered",value:function(n,a){this._registering=!1,this._registered=!1,this._ua.unregistered({response:n||null,cause:a||null})}},{key:"registered",get:function(){return this._registered}}]),c}();function i_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function pc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function l_(c,t,n){return t&&pc(c.prototype,t),n&&pc(c,n),c}var So=lt,ql=hl,a_=dl,yo={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}},o_=function(){function c(t,n,a){i_(this,c),this._dialog=t,this._ua=t._ua,this._request=n,this._eventHandlers=a,this._reattempt=!1,this._reattemptTimer=null;for(var o in yo)Object.prototype.hasOwnProperty.call(yo,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=yo[o]))}return l_(c,[{key:"send",value:function(){var n=this,a=new a_(this._ua,this._request,{onRequestTimeout:function(){n._eventHandlers.onRequestTimeout()},onTransportError:function(){n._eventHandlers.onTransportError()},onAuthenticated:function(r){n._eventHandlers.onAuthenticated(r)},onReceiveResponse:function(r){n._receiveResponse(r)}});if(a.send(),(this._request.method===So.INVITE||this._request.method===So.UPDATE&&this._request.body)&&a.clientTransaction.state!==ql.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;var o=function s(){(a.clientTransaction.state===ql.C.STATUS_ACCEPTED||a.clientTransaction.state===ql.C.STATUS_COMPLETED||a.clientTransaction.state===ql.C.STATUS_TERMINATED)&&(a.clientTransaction.removeListener("stateChanged",s),n._dialog.uac_pending_reply=!1)};a.clientTransaction.on("stateChanged",o)}}},{key:"_receiveResponse",value:function(n){var a=this;n.status_code===408||n.status_code===481?this._eventHandlers.onDialogError(n):n.method===So.INVITE&&n.status_code===491?this._reattempt?n.status_code>=200&&n.status_code<300?this._eventHandlers.onSuccessResponse(n):n.status_code>=300&&this._eventHandlers.onErrorResponse(n):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(function(){a._dialog.isTerminated()||(a._reattempt=!0,a.send())},1e3)):n.status_code>=200&&n.status_code<300?this._eventHandlers.onSuccessResponse(n):n.status_code>=300&&this._eventHandlers.onErrorResponse(n)}},{key:"request",get:function(){return this._request}}]),c}();function u_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function mc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function gc(c,t,n){return t&&mc(c.prototype,t),n&&mc(c,n),c}var c_=ht,Tc=Ss,Ms=lt,Ui=hl,f_=o_,Ao=bt(),Co=new c_("Dialog"),Ls={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3},h_=function(){gc(c,null,[{key:"C",get:function(){return Ls}}]);function c(t,n,a){var o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:Ls.STATUS_CONFIRMED;if(u_(this,c),this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!n.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};n instanceof Tc.IncomingResponse&&(o=n.status_code<200?Ls.STATUS_EARLY:Ls.STATUS_CONFIRMED);var s=n.parseHeader("contact");a==="UAS"?(this._id={call_id:n.call_id,local_tag:n.to_tag,remote_tag:n.from_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri,this._remote_target=s.uri,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):a==="UAC"&&(this._id={call_id:n.call_id,local_tag:n.from_tag,remote_tag:n.to_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=s.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),Co.debug("new ".concat(a," dialog created with status ").concat(this._state===Ls.STATUS_EARLY?"EARLY":"CONFIRMED"))}return gc(c,[{key:"isTerminated",value:function(){return this._status===Ls.STATUS_TERMINATED}},{key:"update",value:function(n,a){this._state=Ls.STATUS_CONFIRMED,Co.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),a==="UAC"&&(this._route_set=n.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){Co.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this),this._state=Ls.STATUS_TERMINATED}},{key:"sendRequest",value:function(n){var a=this,o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},s=Ao.cloneArray(o.extraHeaders),r=Ao.cloneObject(o.eventHandlers),d=o.body||null,h=this._createRequest(n,s,d);r.onAuthenticated=function(){a._local_seqnum+=1};var _=new f_(this,h,r);return _.send(),h}},{key:"receiveRequest",value:function(n){this._checkInDialogRequest(n)&&(n.method===Ms.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:n.method===Ms.INVITE&&(this._ack_seqnum=n.cseq),this._owner.receiveRequest(n))}},{key:"_createRequest",value:function(n,a,o){a=Ao.cloneArray(a),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));var s=n===Ms.CANCEL||n===Ms.ACK?this._local_seqnum:this._local_seqnum+=1,r=new Tc.OutgoingRequest(n,this._remote_target,this._ua,{cseq:s,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},a,o);return r}},{key:"_checkInDialogRequest",value:function(n){var a=this;if(!this._remote_seqnum)this._remote_seqnum=n.cseq;else if(n.cseq<this._remote_seqnum)if(n.method===Ms.ACK){if(this._ack_seqnum===null||n.cseq!==this._ack_seqnum)return!1}else return n.reply(500),!1;else n.cseq>this._remote_seqnum&&(this._remote_seqnum=n.cseq);if(n.method===Ms.INVITE||n.method===Ms.UPDATE&&n.body){if(this._uac_pending_reply===!0)n.reply(491);else if(this._uas_pending_reply===!0){var o=(Math.random()*10|0)+1;return n.reply(500,null,["Retry-After:".concat(o)]),!1}else{this._uas_pending_reply=!0;var s=function r(){(n.server_transaction.state===Ui.C.STATUS_ACCEPTED||n.server_transaction.state===Ui.C.STATUS_COMPLETED||n.server_transaction.state===Ui.C.STATUS_TERMINATED)&&(n.server_transaction.removeListener("stateChanged",r),a._uas_pending_reply=!1)};n.server_transaction.on("stateChanged",s)}n.hasHeader("contact")&&n.server_transaction.on("stateChanged",function(){n.server_transaction.state===Ui.C.STATUS_ACCEPTED&&(a._remote_target=n.parseHeader("contact").uri)})}else n.method===Ms.NOTIFY&&n.hasHeader("contact")&&n.server_transaction.on("stateChanged",function(){n.server_transaction.state===Ui.C.STATUS_COMPLETED&&(a._remote_target=n.parseHeader("contact").uri)});return!0}},{key:"id",get:function(){return this._id}},{key:"local_seqnum",get:function(){return this._local_seqnum},set:function(n){this._local_seqnum=n}},{key:"owner",get:function(){return this._owner}},{key:"uac_pending_reply",get:function(){return this._uac_pending_reply},set:function(n){this._uac_pending_reply=n}},{key:"uas_pending_reply",get:function(){return this._uas_pending_reply}}]),c}(),Pu={exports:{}};function Sa(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Sa=function(n){return typeof n}:Sa=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Sa(c)}function d_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function vc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function __(c,t,n){return t&&vc(c.prototype,t),n&&vc(c,n),c}function p_(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&hu(c,t)}function hu(c,t){return hu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},hu(c,t)}function m_(c){var t=v_();return function(){var a=Ua(c),o;if(t){var s=Ua(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return g_(this,o)}}function g_(c,t){return t&&(Sa(t)==="object"||typeof t=="function")?t:T_(c)}function T_(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function v_(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Ua(c){return Ua=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Ua(c)}var E_=ft.EventEmitter,S_=ht,y_=lt,A_=Ws,Ec=bt(),C_=new S_("RTCSession:DTMF"),rh={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};Pu.exports=function(c){p_(n,c);var t=m_(n);function n(a){var o;return d_(this,n),o=t.call(this),o._session=a,o._direction=null,o._tone=null,o._duration=null,o._request=null,o}return __(n,[{key:"send",value:function(o){var s=this,r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(o===void 0)throw new TypeError("Not enough arguments");if(this._direction="outgoing",this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new A_.InvalidStateError(this._session.status);var d=Ec.cloneArray(r.extraHeaders);if(this.eventHandlers=Ec.cloneObject(r.eventHandlers),typeof o=="string")o=o.toUpperCase();else if(typeof o=="number")o=o.toString();else throw new TypeError("Invalid tone: ".concat(o));if(o.match(/^[0-9A-DR#*]$/))this._tone=o;else throw new TypeError("Invalid tone: ".concat(o));this._duration=r.duration,d.push("Content-Type: application/dtmf-relay");var h="Signal=".concat(this._tone,`\r
|
46
|
+
`),this.transport.send(d)}}]),n}(sh),kd=function(c){Nu(n,c);var t=Uu(n);function n(){var a;return il(this,n),a=t.call(this),a.headers={},a.status_code=null,a.reason_phrase=null,a}return n}(sh),Ss={OutgoingRequest:th,InitialOutgoingInviteRequest:Pd,IncomingRequest:xd,IncomingResponse:kd};function Md(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function rc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Ld(c,t,n){return t&&rc(c.prototype,t),n&&rc(c,n),c}var $d=ht,hs=bt(),Yt=new $d("DigestAuthentication"),Hd=function(){function c(t){Md(this,c),this._credentials=t,this._cnonce=null,this._nc=0,this._ncHex="00000000",this._algorithm=null,this._realm=null,this._nonce=null,this._opaque=null,this._stale=null,this._qop=null,this._method=null,this._uri=null,this._ha1=null,this._response=null}return Ld(c,[{key:"get",value:function(n){switch(n){case"realm":return this._realm;case"ha1":return this._ha1;default:Yt.warn('get() | cannot get "%s" parameter',n);return}}},{key:"authenticate",value:function(n,a){var o=n.method,s=n.ruri,r=n.body,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:null;if(this._algorithm=a.algorithm,this._realm=a.realm,this._nonce=a.nonce,this._opaque=a.opaque,this._stale=a.stale,this._algorithm){if(this._algorithm!=="MD5")return Yt.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return Yt.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return Yt.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return Yt.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return Yt.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(a.qop)if(a.qop.indexOf("auth-int")>-1)this._qop="auth-int";else if(a.qop.indexOf("auth")>-1)this._qop="auth";else return Yt.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;else this._qop=null;this._method=o,this._uri=s,this._cnonce=d||hs.createRandomToken(12),this._nc+=1;var h=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-h.length)+h,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=hs.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1;var _,g;return this._qop==="auth"?(_="".concat(this._method,":").concat(this._uri),g=hs.calculateMD5(_),Yt.debug('authenticate() | using qop=auth [a2:"%s"]',_),this._response=hs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(g))):this._qop==="auth-int"?(_="".concat(this._method,":").concat(this._uri,":").concat(hs.calculateMD5(r||"")),g=hs.calculateMD5(_),Yt.debug('authenticate() | using qop=auth-int [a2:"%s"]',_),this._response=hs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(g))):this._qop===null&&(_="".concat(this._method,":").concat(this._uri),g=hs.calculateMD5(_),Yt.debug('authenticate() | using qop=null [a2:"%s"]',_),this._response=hs.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(g))),Yt.debug("authenticate() | response generated"),!0}},{key:"toString",value:function(){var n=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return n.push("algorithm=".concat(this._algorithm)),n.push('username="'.concat(this._credentials.username,'"')),n.push('realm="'.concat(this._realm,'"')),n.push('nonce="'.concat(this._nonce,'"')),n.push('uri="'.concat(this._uri,'"')),n.push('response="'.concat(this._response,'"')),this._opaque&&n.push('opaque="'.concat(this._opaque,'"')),this._qop&&(n.push("qop=".concat(this._qop)),n.push('cnonce="'.concat(this._cnonce,'"')),n.push("nc=".concat(this._ncHex))),"Digest ".concat(n.join(", "))}}]),c}(),ds=500,Fd=4e3,ic=5e3,nh={T1:ds,T2:Fd,T4:ic,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*ic,TIMER_L:64*ds,TIMER_M:64*ds,PROVISIONAL_RESPONSE_INTERVAL:6e4};function Ea(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ea=function(n){return typeof n}:Ea=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Ea(c)}function ll(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function lc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function al(c,t,n){return t&&lc(c.prototype,t),n&&lc(c,n),c}function ol(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&fu(c,t)}function fu(c,t){return fu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},fu(c,t)}function ul(c){var t=qd();return function(){var a=Na(c),o;if(t){var s=Na(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return jd(this,o)}}function jd(c,t){return t&&(Ea(t)==="object"||typeof t=="function")?t:Bs(c)}function Bs(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 Na(c){return Na=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Na(c)}var cl=ft.EventEmitter,fl=ht,zi=lt,ac=Ss,ls=nh,oc=new fl("NonInviteClientTransaction"),Hl=new fl("InviteClientTransaction"),Vd=new fl("AckClientTransaction"),uc=new fl("NonInviteServerTransaction"),Fl=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"},Bd=function(c){ol(n,c);var t=ul(n);function n(a,o,s,r){var d;ll(this,n),d=t.call(this),d.type=he.NON_INVITE_CLIENT,d.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),d.ua=a,d.transport=o,d.request=s,d.eventHandlers=r;var h="SIP/2.0/".concat(o.via_transport);return h+=" ".concat(a.configuration.via_host,";branch=").concat(d.id),d.request.setHeader("via",h),d.ua.newTransaction(Bs(d)),d}return al(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"send",value:function(){var o=this;this.stateChanged(he.STATUS_TRYING),this.F=setTimeout(function(){o.timer_F()},ls.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(he.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(he.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}},{key:"timer_K",value:function(){this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"receiveResponse",value:function(o){var s=this,r=o.status_code;if(r<200)switch(this.state){case he.STATUS_TRYING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(o);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(o),this.K=setTimeout(function(){s.timer_K()},ls.TIMER_K);break;case he.STATUS_COMPLETED:break}}},{key:"C",get:function(){return he}}]),n}(cl),Gd=function(c){ol(n,c);var t=ul(n);function n(a,o,s,r){var d;ll(this,n),d=t.call(this),d.type=he.INVITE_CLIENT,d.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),d.ua=a,d.transport=o,d.request=s,d.eventHandlers=r,s.transaction=Bs(d);var h="SIP/2.0/".concat(o.via_transport);return h+=" ".concat(a.configuration.via_host,";branch=").concat(d.id),d.request.setHeader("via",h),d.ua.newTransaction(Bs(d)),d}return al(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"send",value:function(){var o=this;this.stateChanged(he.STATUS_CALLING),this.B=setTimeout(function(){o.timer_B()},ls.TIMER_B),this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==he.STATUS_ACCEPTED&&(Hl.debug("transport error occurred, deleting transaction ".concat(this.id)),this.eventHandlers.onTransportError()),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_M",value:function(){Hl.debug("Timer M expired for transaction ".concat(this.id)),this.state===he.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"timer_B",value:function(){Hl.debug("Timer B expired for transaction ".concat(this.id)),this.state===he.STATUS_CALLING&&(this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}},{key:"timer_D",value:function(){Hl.debug("Timer D expired for transaction ".concat(this.id)),clearTimeout(this.B),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"sendACK",value:function(o){var s=this,r=new ac.OutgoingRequest(zi.ACK,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});r.setHeader("from",this.request.getHeader("from")),r.setHeader("via",this.request.getHeader("via")),r.setHeader("to",o.getHeader("to")),this.D=setTimeout(function(){s.timer_D()},ls.TIMER_D),this.transport.send(r)}},{key:"cancel",value:function(o){if(this.state===he.STATUS_PROCEEDING){var s=new ac.OutgoingRequest(zi.CANCEL,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});s.setHeader("from",this.request.getHeader("from")),s.setHeader("via",this.request.getHeader("via")),s.setHeader("to",this.request.getHeader("to")),o&&s.setHeader("reason",o),this.transport.send(s)}}},{key:"receiveResponse",value:function(o){var s=this,r=o.status_code;if(r>=100&&r<=199)switch(this.state){case he.STATUS_CALLING:this.stateChanged(he.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(o);break;case he.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(o);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(function(){s.timer_M()},ls.TIMER_M),this.eventHandlers.onReceiveResponse(o);break;case he.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(o);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(o),this.eventHandlers.onReceiveResponse(o);break;case he.STATUS_COMPLETED:this.sendACK(o);break}}},{key:"C",get:function(){return he}}]),n}(cl),Wd=function(c){ol(n,c);var t=ul(n);function n(a,o,s,r){var d;ll(this,n),d=t.call(this),d.id="z9hG4bK".concat(Math.floor(Math.random()*1e7)),d.transport=o,d.request=s,d.eventHandlers=r;var h="SIP/2.0/".concat(o.via_transport);return h+=" ".concat(a.configuration.via_host,";branch=").concat(d.id),d.request.setHeader("via",h),d}return al(n,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){Vd.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return he}}]),n}(cl),Kd=function(c){ol(n,c);var t=ul(n);function n(a,o,s){var r;return ll(this,n),r=t.call(this),r.type=he.NON_INVITE_SERVER,r.id=s.via_branch,r.ua=a,r.transport=o,r.request=s,r.last_response="",s.server_transaction=Bs(r),r.state=he.STATUS_TRYING,a.newTransaction(Bs(r)),r}return al(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"timer_J",value:function(){uc.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(he.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(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(o,s,r,d){var h=this;if(o===100)switch(this.state){case he.STATUS_TRYING:this.stateChanged(he.STATUS_PROCEEDING),this.transport.send(s)||this.onTransportError();break;case he.STATUS_PROCEEDING:this.last_response=s,this.transport.send(s)?r&&r():(this.onTransportError(),d&&d());break}else if(o>=200&&o<=699)switch(this.state){case he.STATUS_TRYING:case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_COMPLETED),this.last_response=s,this.J=setTimeout(function(){h.timer_J()},ls.TIMER_J),this.transport.send(s)?r&&r():(this.onTransportError(),d&&d());break;case he.STATUS_COMPLETED:break}}},{key:"C",get:function(){return he}}]),n}(cl),Yd=function(c){ol(n,c);var t=ul(n);function n(a,o,s){var r;return ll(this,n),r=t.call(this),r.type=he.INVITE_SERVER,r.id=s.via_branch,r.ua=a,r.transport=o,r.request=s,r.last_response="",s.server_transaction=Bs(r),r.state=he.STATUS_PROCEEDING,a.newTransaction(Bs(r)),r.resendProvisionalTimer=null,s.reply(100),r}return al(n,[{key:"stateChanged",value:function(o){this.state=o,this.emit("stateChanged")}},{key:"timer_H",value:function(){Fl.debug("Timer H expired for transaction ".concat(this.id)),this.state===he.STATUS_COMPLETED&&Fl.debug("ACK not received, dialog will be terminated"),this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){Fl.debug("Timer L expired for transaction ".concat(this.id)),this.state===he.STATUS_ACCEPTED&&(this.stateChanged(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,Fl.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(he.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"resend_provisional",value:function(){this.transport.send(this.last_response)||this.onTransportError()}},{key:"receiveResponse",value:function(o,s,r,d){var h=this;if(o>=100&&o<=199)switch(this.state){case he.STATUS_PROCEEDING:this.transport.send(s)||this.onTransportError(),this.last_response=s;break}if(o>100&&o<=199&&this.state===he.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(function(){h.resend_provisional()},ls.PROVISIONAL_RESPONSE_INTERVAL));else if(o>=200&&o<=299)switch(this.state){case he.STATUS_PROCEEDING:this.stateChanged(he.STATUS_ACCEPTED),this.last_response=s,this.L=setTimeout(function(){h.timer_L()},ls.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case he.STATUS_ACCEPTED:this.transport.send(s)?r&&r():(this.onTransportError(),d&&d());break}else if(o>=300&&o<=699)switch(this.state){case he.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(s)?(this.stateChanged(he.STATUS_COMPLETED),this.H=setTimeout(function(){h.timer_H()},ls.TIMER_H),r&&r()):(this.onTransportError(),d&&d());break}}},{key:"C",get:function(){return he}}]),n}(cl);function Jd(c,t){var n=c._transactions,a;switch(t.method){case zi.INVITE:if(a=n.ist[t.via_branch],a){switch(a.state){case he.STATUS_PROCEEDING:a.transport.send(a.last_response);break;case he.STATUS_ACCEPTED:break}return!0}break;case zi.ACK:if(a=n.ist[t.via_branch],a){if(a.state===he.STATUS_ACCEPTED)return!1;if(a.state===he.STATUS_COMPLETED)return a.state=he.STATUS_CONFIRMED,a.I=setTimeout(function(){a.timer_I()},ls.TIMER_I),!0}else return!1;break;case zi.CANCEL:return a=n.ist[t.via_branch],a?(t.reply_sl(200),a.state!==he.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(a=n.nist[t.via_branch],a){switch(a.state){case he.STATUS_TRYING:break;case he.STATUS_PROCEEDING:case he.STATUS_COMPLETED:a.transport.send(a.last_response);break}return!0}break}}var hl={C:he,NonInviteClientTransaction:Bd,InviteClientTransaction:Gd,AckClientTransaction:Wd,NonInviteServerTransaction:Kd,InviteServerTransaction:Yd,checkTransaction:Jd};function zd(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function cc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Xd(c,t,n){return t&&cc(c.prototype,t),n&&cc(c,n),c}var Qd=ht,fc=lt,Zd=Hd,To=hl,e_=new Qd("RequestSender"),vo={onRequestTimeout:function(){},onTransportError:function(){},onReceiveResponse:function(){},onAuthenticated:function(){}},dl=function(){function c(t,n,a){zd(this,c),this._ua=t,this._eventHandlers=a,this._method=n.method,this._request=n,this._auth=null,this._challenged=!1,this._staled=!1;for(var o in vo)Object.prototype.hasOwnProperty.call(vo,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=vo[o]));t.status===t.C.STATUS_USER_CLOSED&&(this._method!==fc.BYE||this._method!==fc.ACK)&&this._eventHandlers.onTransportError()}return Xd(c,[{key:"send",value:function(){var n=this,a={onRequestTimeout:function(){n._eventHandlers.onRequestTimeout()},onTransportError:function(){n._eventHandlers.onTransportError()},onReceiveResponse:function(s){n._receiveResponse(s)}};switch(this._method){case"INVITE":this.clientTransaction=new To.InviteClientTransaction(this._ua,this._ua.transport,this._request,a);break;case"ACK":this.clientTransaction=new To.AckClientTransaction(this._ua,this._ua.transport,this._request,a);break;default:this.clientTransaction=new To.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,a)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}},{key:"_receiveResponse",value:function(n){var a,o,s=n.status_code;if((s===401||s===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(n.status_code===401?(a=n.parseHeader("www-authenticate"),o="authorization"):(a=n.parseHeader("proxy-authenticate"),o="proxy-authorization"),!a){e_.debug("".concat(n.status_code," with wrong or missing challenge, cannot authenticate")),this._eventHandlers.onReceiveResponse(n);return}if(!this._challenged||!this._staled&&a.stale===!0){if(this._auth||(this._auth=new Zd({username:this._ua.configuration.authorization_user,password:this._ua.configuration.password,realm:this._ua.configuration.realm,ha1:this._ua.configuration.ha1})),!this._auth.authenticate(this._request,a)){this._eventHandlers.onReceiveResponse(n);return}this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),a.stale&&(this._staled=!0),this._request=this._request.clone(),this._request.cseq+=1,this._request.setHeader("cseq","".concat(this._request.cseq," ").concat(this._method)),this._request.setHeader(o,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(n)}else this._eventHandlers.onReceiveResponse(n)}}]),c}();function t_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function hc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function s_(c,t,n){return t&&hc(c.prototype,t),n&&hc(c,n),c}var n_=ht,Eo=bt(),pn=lt,dc=Ss,_c=dl,Ni=new n_("Registrator"),jl=10,r_=function(){function c(t,n){t_(this,c),this._reg_id=1,this._ua=t,this._transport=n,this._registrar=t.configuration.registrar_server,this._expires=t.configuration.register_expires,this._call_id=Eo.createRandomToken(22),this._cseq=0,this._to_uri=t.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString(),this._contact+=";+sip.ice",this._extraHeaders=[],this._extraContactParams="",this._sipInstance='"<urn:uuid:'.concat(this._ua.configuration.instance_id,'>"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)}return s_(c,[{key:"setExtraHeaders",value:function(n){Array.isArray(n)||(n=[]),this._extraHeaders=n.slice()}},{key:"setExtraContactParams",value:function(n){n instanceof Object||(n={}),this._extraContactParams="";for(var a in n)if(Object.prototype.hasOwnProperty.call(n,a)){var o=n[a];this._extraContactParams+=";".concat(a),o&&(this._extraContactParams+="=".concat(o))}}},{key:"register",value:function(){var n=this;if(this._registering){Ni.debug("Register request in progress...");return}var a=this._extraHeaders.slice();a.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),a.push("Expires: ".concat(this._expires));var o=new dc.OutgoingRequest(pn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},a),s=new _c(this._ua,o,{onRequestTimeout:function(){n._registrationFailure(null,pn.causes.REQUEST_TIMEOUT)},onTransportError:function(){n._registrationFailure(null,pn.causes.CONNECTION_ERROR)},onAuthenticated:function(){n._cseq+=1},onReceiveResponse:function(d){if(d.cseq===n._cseq)switch(n._registrationTimer!==null&&(clearTimeout(n._registrationTimer),n._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(d.status_code):break;case/^2[0-9]{2}$/.test(d.status_code):{if(n._registering=!1,!d.hasHeader("Contact")){Ni.debug("no Contact header in response to REGISTER, response ignored");break}var h=d.headers.Contact.reduce(function(y,C){return y.concat(C.parsed)},[]),_=h.find(function(y){return n._sipInstance===y.getParam("+sip.instance")&&n._reg_id===parseInt(y.getParam("reg-id"))});if(_||(_=h.find(function(y){return y.uri.user===n._ua.contact.uri.user})),!_){Ni.debug("no Contact header pointing to us, response ignored");break}var g=_.getParam("expires");!g&&d.hasHeader("expires")&&(g=d.getHeader("expires")),g||(g=n._expires),g=Number(g),g<jl&&(g=jl);var T=g>64?g*1e3/2+Math.floor((g/2-32)*1e3*Math.random()):g*1e3-5e3;n._registrationTimer=setTimeout(function(){n._registrationTimer=null,n._ua.listeners("registrationExpiring").length===0?n.register():n._ua.emit("registrationExpiring")},T),_.hasParam("temp-gruu")&&(n._ua.contact.temp_gruu=_.getParam("temp-gruu").replace(/"/g,"")),_.hasParam("pub-gruu")&&(n._ua.contact.pub_gruu=_.getParam("pub-gruu").replace(/"/g,"")),n._registered||(n._registered=!0,n._ua.registered({response:d}));break}case/^423$/.test(d.status_code):{d.hasHeader("min-expires")?(n._expires=Number(d.getHeader("min-expires")),n._expires<jl&&(n._expires=jl),n.register()):(Ni.debug("423 response received for REGISTER without Min-Expires"),n._registrationFailure(d,pn.causes.SIP_FAILURE_CODE));break}default:{var E=Eo.sipErrorCause(d.status_code);n._registrationFailure(d,E)}}}});this._registering=!0,s.send()}},{key:"unregister",value:function(){var n=this,a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!this._registered){Ni.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);var o=this._extraHeaders.slice();a.all?o.push("Contact: *".concat(this._extraContactParams)):o.push("Contact: ".concat(this._contact,";expires=0").concat(this._extraContactParams)),o.push("Expires: 0");var s=new dc.OutgoingRequest(pn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},o),r=new _c(this._ua,s,{onRequestTimeout:function(){n._unregistered(null,pn.causes.REQUEST_TIMEOUT)},onTransportError:function(){n._unregistered(null,pn.causes.CONNECTION_ERROR)},onAuthenticated:function(){n._cseq+=1},onReceiveResponse:function(h){switch(!0){case/^1[0-9]{2}$/.test(h.status_code):break;case/^2[0-9]{2}$/.test(h.status_code):n._unregistered(h);break;default:{var _=Eo.sipErrorCause(h.status_code);n._unregistered(h,_)}}}});r.send()}},{key:"close",value:function(){this._registered&&this.unregister()}},{key:"onTransportClosed",value:function(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}},{key:"_registrationFailure",value:function(n,a){this._registering=!1,this._ua.registrationFailed({response:n||null,cause:a}),this._registered&&(this._registered=!1,this._ua.unregistered({response:n||null,cause:a}))}},{key:"_unregistered",value:function(n,a){this._registering=!1,this._registered=!1,this._ua.unregistered({response:n||null,cause:a||null})}},{key:"registered",get:function(){return this._registered}}]),c}();function i_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function pc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function l_(c,t,n){return t&&pc(c.prototype,t),n&&pc(c,n),c}var So=lt,ql=hl,a_=dl,yo={onRequestTimeout:function(){},onTransportError:function(){},onSuccessResponse:function(){},onErrorResponse:function(){},onAuthenticated:function(){},onDialogError:function(){}},o_=function(){function c(t,n,a){i_(this,c),this._dialog=t,this._ua=t._ua,this._request=n,this._eventHandlers=a,this._reattempt=!1,this._reattemptTimer=null;for(var o in yo)Object.prototype.hasOwnProperty.call(yo,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=yo[o]))}return l_(c,[{key:"send",value:function(){var n=this,a=new a_(this._ua,this._request,{onRequestTimeout:function(){n._eventHandlers.onRequestTimeout()},onTransportError:function(){n._eventHandlers.onTransportError()},onAuthenticated:function(r){n._eventHandlers.onAuthenticated(r)},onReceiveResponse:function(r){n._receiveResponse(r)}});if(a.send(),(this._request.method===So.INVITE||this._request.method===So.UPDATE&&this._request.body)&&a.clientTransaction.state!==ql.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;var o=function s(){(a.clientTransaction.state===ql.C.STATUS_ACCEPTED||a.clientTransaction.state===ql.C.STATUS_COMPLETED||a.clientTransaction.state===ql.C.STATUS_TERMINATED)&&(a.clientTransaction.removeListener("stateChanged",s),n._dialog.uac_pending_reply=!1)};a.clientTransaction.on("stateChanged",o)}}},{key:"_receiveResponse",value:function(n){var a=this;n.status_code===408||n.status_code===481?this._eventHandlers.onDialogError(n):n.method===So.INVITE&&n.status_code===491?this._reattempt?n.status_code>=200&&n.status_code<300?this._eventHandlers.onSuccessResponse(n):n.status_code>=300&&this._eventHandlers.onErrorResponse(n):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(function(){a._dialog.isTerminated()||(a._reattempt=!0,a.send())},1e3)):n.status_code>=200&&n.status_code<300?this._eventHandlers.onSuccessResponse(n):n.status_code>=300&&this._eventHandlers.onErrorResponse(n)}},{key:"request",get:function(){return this._request}}]),c}();function u_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function mc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function gc(c,t,n){return t&&mc(c.prototype,t),n&&mc(c,n),c}var c_=ht,Tc=Ss,Ms=lt,Ui=hl,f_=o_,Co=bt(),Ao=new c_("Dialog"),Ls={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3},h_=function(){gc(c,null,[{key:"C",get:function(){return Ls}}]);function c(t,n,a){var o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:Ls.STATUS_CONFIRMED;if(u_(this,c),this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!n.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};n instanceof Tc.IncomingResponse&&(o=n.status_code<200?Ls.STATUS_EARLY:Ls.STATUS_CONFIRMED);var s=n.parseHeader("contact");a==="UAS"?(this._id={call_id:n.call_id,local_tag:n.to_tag,remote_tag:n.from_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri,this._remote_target=s.uri,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):a==="UAC"&&(this._id={call_id:n.call_id,local_tag:n.from_tag,remote_tag:n.to_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=s.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),Ao.debug("new ".concat(a," dialog created with status ").concat(this._state===Ls.STATUS_EARLY?"EARLY":"CONFIRMED"))}return gc(c,[{key:"isTerminated",value:function(){return this._status===Ls.STATUS_TERMINATED}},{key:"update",value:function(n,a){this._state=Ls.STATUS_CONFIRMED,Ao.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),a==="UAC"&&(this._route_set=n.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){Ao.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this),this._state=Ls.STATUS_TERMINATED}},{key:"sendRequest",value:function(n){var a=this,o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},s=Co.cloneArray(o.extraHeaders),r=Co.cloneObject(o.eventHandlers),d=o.body||null,h=this._createRequest(n,s,d);r.onAuthenticated=function(){a._local_seqnum+=1};var _=new f_(this,h,r);return _.send(),h}},{key:"receiveRequest",value:function(n){this._checkInDialogRequest(n)&&(n.method===Ms.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:n.method===Ms.INVITE&&(this._ack_seqnum=n.cseq),this._owner.receiveRequest(n))}},{key:"_createRequest",value:function(n,a,o){a=Co.cloneArray(a),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));var s=n===Ms.CANCEL||n===Ms.ACK?this._local_seqnum:this._local_seqnum+=1,r=new Tc.OutgoingRequest(n,this._remote_target,this._ua,{cseq:s,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},a,o);return r}},{key:"_checkInDialogRequest",value:function(n){var a=this;if(!this._remote_seqnum)this._remote_seqnum=n.cseq;else if(n.cseq<this._remote_seqnum)if(n.method===Ms.ACK){if(this._ack_seqnum===null||n.cseq!==this._ack_seqnum)return!1}else return n.reply(500),!1;else n.cseq>this._remote_seqnum&&(this._remote_seqnum=n.cseq);if(n.method===Ms.INVITE||n.method===Ms.UPDATE&&n.body){if(this._uac_pending_reply===!0)n.reply(491);else if(this._uas_pending_reply===!0){var o=(Math.random()*10|0)+1;return n.reply(500,null,["Retry-After:".concat(o)]),!1}else{this._uas_pending_reply=!0;var s=function r(){(n.server_transaction.state===Ui.C.STATUS_ACCEPTED||n.server_transaction.state===Ui.C.STATUS_COMPLETED||n.server_transaction.state===Ui.C.STATUS_TERMINATED)&&(n.server_transaction.removeListener("stateChanged",r),a._uas_pending_reply=!1)};n.server_transaction.on("stateChanged",s)}n.hasHeader("contact")&&n.server_transaction.on("stateChanged",function(){n.server_transaction.state===Ui.C.STATUS_ACCEPTED&&(a._remote_target=n.parseHeader("contact").uri)})}else n.method===Ms.NOTIFY&&n.hasHeader("contact")&&n.server_transaction.on("stateChanged",function(){n.server_transaction.state===Ui.C.STATUS_COMPLETED&&(a._remote_target=n.parseHeader("contact").uri)});return!0}},{key:"id",get:function(){return this._id}},{key:"local_seqnum",get:function(){return this._local_seqnum},set:function(n){this._local_seqnum=n}},{key:"owner",get:function(){return this._owner}},{key:"uac_pending_reply",get:function(){return this._uac_pending_reply},set:function(n){this._uac_pending_reply=n}},{key:"uas_pending_reply",get:function(){return this._uas_pending_reply}}]),c}(),Pu={exports:{}};function Sa(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Sa=function(n){return typeof n}:Sa=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Sa(c)}function d_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function vc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function __(c,t,n){return t&&vc(c.prototype,t),n&&vc(c,n),c}function p_(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&hu(c,t)}function hu(c,t){return hu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},hu(c,t)}function m_(c){var t=v_();return function(){var a=Ua(c),o;if(t){var s=Ua(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return g_(this,o)}}function g_(c,t){return t&&(Sa(t)==="object"||typeof t=="function")?t:T_(c)}function T_(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function v_(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Ua(c){return Ua=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Ua(c)}var E_=ft.EventEmitter,S_=ht,y_=lt,C_=Ws,Ec=bt(),A_=new S_("RTCSession:DTMF"),rh={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};Pu.exports=function(c){p_(n,c);var t=m_(n);function n(a){var o;return d_(this,n),o=t.call(this),o._session=a,o._direction=null,o._tone=null,o._duration=null,o._request=null,o}return __(n,[{key:"send",value:function(o){var s=this,r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(o===void 0)throw new TypeError("Not enough arguments");if(this._direction="outgoing",this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new C_.InvalidStateError(this._session.status);var d=Ec.cloneArray(r.extraHeaders);if(this.eventHandlers=Ec.cloneObject(r.eventHandlers),typeof o=="string")o=o.toUpperCase();else if(typeof o=="number")o=o.toString();else throw new TypeError("Invalid tone: ".concat(o));if(o.match(/^[0-9A-DR#*]$/))this._tone=o;else throw new TypeError("Invalid tone: ".concat(o));this._duration=r.duration,d.push("Content-Type: application/dtmf-relay");var h="Signal=".concat(this._tone,`\r
|
47
47
|
`);h+="Duration=".concat(this._duration),this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(y_.INFO,{extraHeaders:d,eventHandlers:{onSuccessResponse:function(g){s.emit("succeeded",{originator:"remote",response:g})},onErrorResponse:function(g){s.eventHandlers.onFailed&&s.eventHandlers.onFailed(),s.emit("failed",{originator:"remote",response:g})},onRequestTimeout:function(){s._session.onRequestTimeout()},onTransportError:function(){s._session.onTransportError()},onDialogError:function(){s._session.onDialogError()}},body:h})}},{key:"init_incoming",value:function(o){var s=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,r=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=o,o.reply(200),o.body){var d=o.body.split(`
|
48
|
-
`);d.length>=1&&s.test(d[0])&&(this._tone=d[0].replace(s,"$2")),d.length>=2&&r.test(d[1])&&(this._duration=parseInt(d[1].replace(r,"$2"),10))}this._duration||(this._duration=rh.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:o}):
|
49
|
-
`,1)[0],"Status_Line");if(s===-1){mn.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(o.body,'"'));return}switch(!0){case/^100$/.test(s.status_code):this.emit("trying",{request:o,status_line:s});break;case/^1[0-9]{2}$/.test(s.status_code):this.emit("progress",{request:o,status_line:s});break;case/^2[0-9]{2}$/.test(s.status_code):this.emit("accepted",{request:o,status_line:s});break;default:this.emit("failed",{request:o,status_line:s});break}}}},{key:"_requestSucceeded",value:function(o){mn.debug("REFER succeeded"),mn.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:o})}},{key:"_requestFailed",value:function(o,s){mn.debug("REFER failed"),mn.debug('emit "requestFailed"'),this.emit("requestFailed",{response:o||null,cause:s})}},{key:"id",get:function(){return this._id}}]),n}(z_);function
|
50
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function ep(c,t){if(c){if(typeof c=="string")return Ic(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Ic(c,t)}}function Ic(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}function tp(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function bc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function wc(c,t,n){return t&&bc(c.prototype,t),n&&bc(c,n),c}function sp(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&pu(c,t)}function pu(c,t){return pu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},pu(c,t)}function np(c){var t=lp();return function(){var a=ka(c),o;if(t){var s=ka(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return rp(this,o)}}function rp(c,t){return t&&(Ca(t)==="object"||typeof t=="function")?t:ip(c)}function ip(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function lp(){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(n){return n.__proto__||Object.getPrototypeOf(n)},ka(c)}var ap=ft.EventEmitter,Oc=xt,op=ht,ce=lt,gn=Ws,Dc=hl,Ve=bt(),xi=nh,up=Ss,Vl=h_,cp=dl,kt=R_,Nc=L_,fp=q_,hp=Z_,Uc=Ks(),K=new op("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},Bl=["audio","video"],dp=function(c){sp(n,c);var t=np(n);wc(n,null,[{key:"C",get:function(){return Q}}]);function n(a){var o;return tp(this,n),K.debug("new"),o=t.call(this),o._id=null,o._ua=a,o._status=Q.STATUS_NULL,o._dialog=null,o._earlyDialogs={},o._contact=null,o._from_tag=null,o._to_tag=null,o._connection=null,o._connectionPromiseQueue=Promise.resolve(),o._request=null,o._is_canceled=!1,o._cancel_reason="",o._is_confirmed=!1,o._late_sdp=!1,o._rtcOfferConstraints=null,o._rtcAnswerConstraints=null,o._localMediaStream=null,o._localMediaStreamLocallyGenerated=!1,o._rtcReady=!0,o._iceReady=!1,o._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},o._direction=null,o._local_identity=null,o._remote_identity=null,o._start_time=null,o._end_time=null,o._tones=null,o._audioMuted=!1,o._videoMuted=!1,o._localHold=!1,o._remoteHold=!1,o._sessionTimers={enabled:o._ua.configuration.session_timers,refreshMethod:o._ua.configuration.session_timers_refresh_method,defaultExpires:ce.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},o._referSubscribers={},o._data={},o}return wc(n,[{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(o){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;K.debug("connect()");var d=o,h=Ve.cloneObject(s.eventHandlers),_=Ve.cloneArray(s.extraHeaders),g=Ve.cloneObject(s.mediaConstraints,{audio:!0,video:!0}),T=s.mediaStream||null,E=Ve.cloneObject(s.pcConfig,{iceServers:[]}),y=s.rtcConstraints||null,A=s.rtcOfferConstraints||null;if(this._rtcOfferConstraints=A,this._rtcAnswerConstraints=s.rtcAnswerConstraints||null,this._data=s.data||this._data,o===void 0)throw new TypeError("Not enough arguments");if(this._status!==Q.STATUS_NULL)throw new gn.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new gn.NotSupportedError("WebRTC not supported");if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(d));this._sessionTimers.enabled&&Ve.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES);for(var C in h)Object.prototype.hasOwnProperty.call(h,C)&&this.on(C,h[C]);this._from_tag=Ve.newTag();var I=s.anonymous||!1,H={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:I,outbound:!0}),I?(H.from_display_name="Anonymous",H.from_uri=new Uc("sip","anonymous","anonymous.invalid"),_.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),_.push("Privacy: id")):s.fromUserName&&(H.from_uri=new Uc("sip",s.fromUserName,this._ua.configuration.uri.host),_.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),s.fromDisplayName&&(H.from_display_name=s.fromDisplayName),_.push("Contact: ".concat(this._contact)),_.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&_.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher?";refresher=uac":"")),this._request=new up.InitialOutgoingInviteRequest(o,this._ua,H,_),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(E,y),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,r&&r(this),this._newRTCSession("local",this._request),this._sendInitialRequest(g,A,T)}},{key:"init_incoming",value:function(o,s){var r=this;K.debug("init_incoming()");var d,h=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0;if(o.body&&h!=="application/sdp"){o.reply(415);return}if(this._status=Q.STATUS_INVITE_RECEIVED,this._from_tag=o.from_tag,this._id=o.call_id+this._from_tag,this._request=o,this._contact=this._ua.contact.toString(),o.hasHeader("expires")&&(d=o.getHeader("expires")*1e3),o.to_tag=Ve.newTag(),!this._createDialog(o,"UAS",!0)){o.reply(500,"Missing Contact header field");return}o.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Q.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){o.reply(408),r._failed("local",null,ce.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),d&&(this._timers.expiresTimer=setTimeout(function(){r._status===Q.STATUS_WAITING_FOR_ANSWER&&(o.reply(487),r._failed("system",null,ce.causes.EXPIRES))},d)),this._direction="incoming",this._local_identity=o.to,this._remote_identity=o.from,s&&s(this),this._newRTCSession("remote",o),this._status!==Q.STATUS_TERMINATED&&(o.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))}},{key:"answer",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};K.debug("answer()");var r=this._request,d=Ve.cloneArray(s.extraHeaders),h=Ve.cloneObject(s.mediaConstraints),_=s.mediaStream||null,g=Ve.cloneObject(s.pcConfig,{iceServers:[]}),T=s.rtcConstraints||null,E=s.rtcAnswerConstraints||null,y=Ve.cloneObject(s.rtcOfferConstraints),A,C=!1,I=!1,H=!1,$=!1;if(this._rtcAnswerConstraints=E,this._rtcOfferConstraints=s.rtcOfferConstraints||null,this._data=s.data||this._data,this._direction!=="incoming")throw new gn.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==Q.STATUS_WAITING_FOR_ANSWER)throw new gn.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Ve.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES),this._status=Q.STATUS_ANSWERED,!this._createDialog(r,"UAS")){r.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),d.unshift("Contact: ".concat(this._contact));var oe=r.parseSDP();Array.isArray(oe.media)||(oe.media=[oe.media]);var N=_s(oe.media),j;try{for(N.s();!(j=N.n()).done;){var Se=j.value;Se.type==="audio"&&(C=!0,(!Se.direction||Se.direction==="sendrecv")&&(H=!0)),Se.type==="video"&&(I=!0,(!Se.direction||Se.direction==="sendrecv")&&($=!0))}}catch(F){N.e(F)}finally{N.f()}if(_&&h.audio===!1){A=_.getAudioTracks();var ve=_s(A),k;try{for(ve.s();!(k=ve.n()).done;){var D=k.value;_.removeTrack(D)}}catch(F){ve.e(F)}finally{ve.f()}}if(_&&h.video===!1){A=_.getVideoTracks();var B=_s(A),V;try{for(B.s();!(V=B.n()).done;){var J=V.value;_.removeTrack(J)}}catch(F){B.e(F)}finally{B.f()}}!_&&h.audio===void 0&&(h.audio=H),!_&&h.video===void 0&&(h.video=$),!_&&!C&&!y.offerToReceiveAudio&&(h.audio=!1),!_&&!I&&!y.offerToReceiveVideo&&(h.video=!1),this._createRTCConnection(g,T),Promise.resolve().then(function(){if(_)return _;if(h.audio||h.video)return o._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(h).catch(function(F){throw o._status===Q.STATUS_TERMINATED?new Error("terminated"):(r.reply(480),o._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',F),o.emit("getusermediafailed",F),new Error("getUserMedia() failed"))})}).then(function(F){if(o._status===Q.STATUS_TERMINATED)throw new Error("terminated");o._localMediaStream=F,F&&F.getTracks().forEach(function(X){o._connection.addTrack(X,F)})}).then(function(){if(!o._late_sdp){var F={originator:"remote",type:"offer",sdp:r.body};K.debug('emit "sdp"'),o.emit("sdp",F);var X=new RTCSessionDescription({type:"offer",sdp:F.sdp});return o._connectionPromiseQueue=o._connectionPromiseQueue.then(function(){return o._connection.setRemoteDescription(X)}).catch(function(U){throw r.reply(488),o._failed("system",null,ce.causes.WEBRTC_ERROR),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',U),o.emit("peerconnection:setremotedescriptionfailed",U),new Error("peerconnection.setRemoteDescription() failed")}),o._connectionPromiseQueue}}).then(function(){if(o._status===Q.STATUS_TERMINATED)throw new Error("terminated");return o._connecting(r),o._late_sdp?o._createLocalDescription("offer",o._rtcOfferConstraints).catch(function(){throw r.reply(500),new Error("_createLocalDescription() failed")}):o._createLocalDescription("answer",E).catch(function(){throw r.reply(500),new Error("_createLocalDescription() failed")})}).then(function(F){if(o._status===Q.STATUS_TERMINATED)throw new Error("terminated");o._handleSessionTimersInIncomingRequest(r,d),r.reply(200,null,d,F,function(){o._status=Q.STATUS_WAITING_FOR_ACK,o._setInvite2xxTimer(r,F),o._setACKTimer(),o._accepted("local")},function(){o._failed("system",null,ce.causes.CONNECTION_ERROR)})}).catch(function(F){o._status!==Q.STATUS_TERMINATED&&K.warn(F)})}},{key:"terminate",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};K.debug("terminate()");var r=s.cause||ce.causes.BYE,d=Ve.cloneArray(s.extraHeaders),h=s.body,_,g=s.status_code,T=s.reason_phrase;if(this._status===Q.STATUS_TERMINATED)throw new gn.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]||"",_="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=_):this._status===Q.STATUS_1XX_RECEIVED&&this._request.cancel(_),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,h),this._failed("local",null,ce.causes.REJECTED);break;case Q.STATUS_WAITING_FOR_ACK:case Q.STATUS_CONFIRMED:if(K.debug("terminating session"),T=s.reason_phrase||ce.REASON_PHRASE[g]||"",g&&(g<200||g>=700))throw new TypeError("Invalid status_code: ".concat(g));if(g&&d.push("Reason: SIP ;cause=".concat(g,'; text="').concat(T,'"')),this._status===Q.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Dc.C.STATUS_TERMINATED){var E=this._dialog;this.receiveRequest=function(y){var A=y.method;A===ce.ACK&&(o.sendRequest(ce.BYE,{extraHeaders:d,body:h}),E.terminate())},this._request.server_transaction.on("stateChanged",function(){o._request.server_transaction.state===Dc.C.STATUS_TERMINATED&&(o.sendRequest(ce.BYE,{extraHeaders:d,body:h}),E.terminate())}),this._ended("local",null,r),this._dialog=E,this._ua.newDialog(E)}else this.sendRequest(ce.BYE,{extraHeaders:d,body:h}),this._ended("local",null,r)}}},{key:"sendDTMF",value:function(o){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};K.debug("sendDTMF() | tones: %s",o);var r=0,d=s.duration||null,h=s.interToneGap||null,_=s.transportType||ce.DTMF_TRANSPORT.INFO;if(o===void 0)throw new TypeError("Not enough arguments");if(this._status!==Q.STATUS_CONFIRMED&&this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_1XX_RECEIVED)throw new gn.InvalidStateError(this._status);if(_!==ce.DTMF_TRANSPORT.INFO&&_!==ce.DTMF_TRANSPORT.RFC2833)throw new TypeError("invalid transportType: ".concat(_));if(typeof o=="number"&&(o=o.toString()),!o||typeof o!="string"||!o.match(/^[0-9A-DR#*,]+$/i))throw new TypeError("Invalid tones: ".concat(o));if(d&&!Ve.isDecimal(d))throw new TypeError("Invalid tone duration: ".concat(d));if(d?d<kt.C.MIN_DURATION?(K.debug('"duration" value is lower than the minimum allowed, setting it to '.concat(kt.C.MIN_DURATION," milliseconds")),d=kt.C.MIN_DURATION):d>kt.C.MAX_DURATION?(K.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(kt.C.MAX_DURATION," milliseconds")),d=kt.C.MAX_DURATION):d=Math.abs(d):d=kt.C.DEFAULT_DURATION,s.duration=d,h&&!Ve.isDecimal(h))throw new TypeError("Invalid interToneGap: ".concat(h));if(h?h<kt.C.MIN_INTER_TONE_GAP?(K.debug('"interToneGap" value is lower than the minimum allowed, setting it to '.concat(kt.C.MIN_INTER_TONE_GAP," milliseconds")),h=kt.C.MIN_INTER_TONE_GAP):h=Math.abs(h):h=kt.C.DEFAULT_INTER_TONE_GAP,_===ce.DTMF_TRANSPORT.RFC2833){var g=this._getDTMFRTPSender();g&&(o=g.toneBuffer+o,g.insertDTMF(o,d,h));return}if(this._tones){this._tones+=o;return}this._tones=o,T.call(this);function T(){var E=this,y;if(this._status===Q.STATUS_TERMINATED||!this._tones||r>=this._tones.length){this._tones=null;return}var A=this._tones[r];if(r+=1,A===",")y=2e3;else{var C=new kt(this);s.eventHandlers={onFailed:function(){E._tones=null}},C.send(A,s),y=d+h}setTimeout(T.bind(this),y)}}},{key:"sendInfo",value:function(o,s){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(K.debug("sendInfo()"),this._status!==Q.STATUS_CONFIRMED&&this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_1XX_RECEIVED)throw new gn.InvalidStateError(this._status);var d=new Nc(this);d.send(o,s,r)}},{key:"mute",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!1};K.debug("mute()");var s=!1,r=!1;this._audioMuted===!1&&o.audio&&(s=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&o.video&&(r=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(s===!0||r===!0)&&this._onmute({audio:s,video:r})}},{key:"unmute",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!0};K.debug("unmute()");var s=!1,r=!1;this._audioMuted===!0&&o.audio&&(s=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&o.video&&(r=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(s===!0||r===!0)&&this._onunmute({audio:s,video:r})}},{key:"hold",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;if(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(){r&&r()},failed:function(){o.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:d,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:d,extraHeaders:s.extraHeaders}),!0}},{key:"unhold",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;if(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(){r&&r()},failed:function(){o.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:d,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:d,extraHeaders:s.extraHeaders}),!0}},{key:"renegotiate",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;K.debug("renegotiate()");var d=s.rtcOfferConstraints||null;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;var h={succeeded:function(){r&&r()},failed:function(){o.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:h,rtcOfferConstraints:d,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:h,rtcOfferConstraints:d,extraHeaders:s.extraHeaders}),!0}},{key:"refer",value:function(o,s){var r=this;K.debug("refer()");var d=o;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(d));var h=new hp(this);h.sendRefer(o,s);var _=h.id;return this._referSubscribers[_]=h,h.on("requestFailed",function(){delete r._referSubscribers[_]}),h.on("accepted",function(){delete r._referSubscribers[_]}),h.on("failed",function(){delete r._referSubscribers[_]}),h}},{key:"sendRequest",value:function(o,s){return K.debug("sendRequest()"),this._dialog.sendRequest(o,s)}},{key:"receiveRequest",value:function(o){var s=this;if(K.debug("receiveRequest()"),o.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",o,ce.causes.CANCELED));else switch(o.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(!o.body){this.terminate({cause:ce.causes.MISSING_SDP,status_code:400});break}var r={originator:"remote",type:"answer",sdp:o.body};K.debug('emit "sdp"'),this.emit("sdp",r);var d=new RTCSessionDescription({type:"answer",sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._connection.setRemoteDescription(d)}).then(function(){s._is_confirmed||s._confirmed("remote",o)}).catch(function(_){s.terminate({cause:ce.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',_),s.emit("peerconnection:setremotedescriptionfailed",_)})}else this._is_confirmed||this._confirmed("remote",o);break;case ce.BYE:this._status===Q.STATUS_CONFIRMED||this._status===Q.STATUS_WAITING_FOR_ACK?(o.reply(200),this._ended("remote",o,ce.causes.BYE)):this._status===Q.STATUS_INVITE_RECEIVED||this._status===Q.STATUS_WAITING_FOR_ANSWER?(o.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",o,ce.causes.BYE)):o.reply(403,"Wrong Status");break;case ce.INVITE:this._status===Q.STATUS_CONFIRMED?o.hasHeader("replaces")?this._receiveReplaces(o):this._receiveReinvite(o):o.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 h=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0;h&&h.match(/^application\/dtmf-relay/i)?new kt(this).init_incoming(o):h!==void 0?new Nc(this).init_incoming(o):o.reply(415)}else o.reply(403,"Wrong Status");break;case ce.UPDATE:this._status===Q.STATUS_CONFIRMED?this._receiveUpdate(o):o.reply(403,"Wrong Status");break;case ce.REFER:this._status===Q.STATUS_CONFIRMED?this._receiveRefer(o):o.reply(403,"Wrong Status");break;case ce.NOTIFY:this._status===Q.STATUS_CONFIRMED?this._receiveNotify(o):o.reply(403,"Wrong Status");break;default:o.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(o){K.debug("newDTMF()"),this.emit("newDTMF",o)}},{key:"newInfo",value:function(o){K.debug("newInfo()"),this.emit("newInfo",o)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(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 o in this._timers)Object.prototype.hasOwnProperty.call(this._timers,o)&&clearTimeout(this._timers[o]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(var s in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,s)&&(this._earlyDialogs[s].terminate(),delete this._earlyDialogs[s]);for(var r in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,r)&&delete this._referSubscribers[r];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(o,s){var r=xi.T1;function d(){this._status===Q.STATUS_WAITING_FOR_ACK&&(o.reply(200,null,["Contact: ".concat(this._contact)],s),r<xi.T2&&(r=r*2,r>xi.T2&&(r=xi.T2)),this._timers.invite2xxTimer=setTimeout(d.bind(this),r))}this._timers.invite2xxTimer=setTimeout(d.bind(this),r)}},{key:"_setACKTimer",value:function(){var o=this;this._timers.ackTimer=setTimeout(function(){o._status===Q.STATUS_WAITING_FOR_ACK&&(K.debug("no ACK received, terminating the session"),clearTimeout(o._timers.invite2xxTimer),o.sendRequest(ce.BYE),o._ended("remote",null,ce.causes.NO_ACK))},xi.TIMER_H)}},{key:"_createRTCConnection",value:function(o,s){var r=this;this._connection=new RTCPeerConnection(o,s),this._connection.addEventListener("iceconnectionstatechange",function(){var d=r._connection.iceConnectionState;d==="failed"&&r.terminate({cause:ce.causes.RTP_TIMEOUT,status_code:408,reason_phrase:ce.causes.RTP_TIMEOUT})}),K.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(o,s){var r=this;if(K.debug("createLocalDescription()"),o!=="offer"&&o!=="answer")throw new Error('createLocalDescription() | invalid type "'.concat(o,'"'));var d=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return o==="offer"?d.createOffer(s).catch(function(h){return K.warn('emit "peerconnection:createofferfailed" [error:%o]',h),r.emit("peerconnection:createofferfailed",h),Promise.reject(h)}):d.createAnswer(s).catch(function(h){return K.warn('emit "peerconnection:createanswerfailed" [error:%o]',h),r.emit("peerconnection:createanswerfailed",h),Promise.reject(h)})}).then(function(h){return d.setLocalDescription(h).catch(function(_){return r._rtcReady=!0,K.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',_),r.emit("peerconnection:setlocaldescriptionfailed",_),Promise.reject(_)})}).then(function(){var h=s&&s.iceRestart;if(d.iceGatheringState==="complete"&&!h||d.iceGatheringState==="gathering"&&r._iceReady){r._rtcReady=!0;var _={originator:"local",type:o,sdp:d.localDescription.sdp};return K.debug('emit "sdp"'),r.emit("sdp",_),Promise.resolve(_.sdp)}return new Promise(function(g){var T=!1,E,y;r._iceReady=!1;var A=function(){d.removeEventListener("icecandidate",E),d.removeEventListener("icegatheringstatechange",y),T=!0,r._rtcReady=!0,r._iceReady=!0;var I={originator:"local",type:o,sdp:d.localDescription.sdp};K.debug('emit "sdp"'),r.emit("sdp",I),g(I.sdp)};d.addEventListener("icecandidate",E=function(I){var H=I.candidate;H?r.emit("icecandidate",{candidate:H,ready:A}):T||A()}),d.addEventListener("icegatheringstatechange",y=function(){d.iceGatheringState==="complete"&&!T&&A()})})})}},{key:"_createDialog",value:function(o,s,r){var d=s==="UAS"?o.to_tag:o.from_tag,h=s==="UAS"?o.from_tag:o.to_tag,_=o.call_id+d+h,g=this._earlyDialogs[_];if(r)return g?!0:(g=new Vl(this,o,s,Vl.C.STATUS_EARLY),g.error?(K.debug(g.error),this._failed("remote",o,ce.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[_]=g,!0));if(this._from_tag=o.from_tag,this._to_tag=o.to_tag,g)return g.update(o,s),this._dialog=g,delete this._earlyDialogs[_],!0;var T=new Vl(this,o,s);return T.error?(K.debug(T.error),this._failed("remote",o,ce.causes.INTERNAL_ERROR),!1):(this._dialog=T,!0)}},{key:"_receiveReinvite",value:function(o){var s=this;K.debug("receiveReinvite()");var r=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0,d={request:o,callback:void 0,reject:_.bind(this)},h=!1;function _(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};h=!0;var E=T.status_code||403,y=T.reason_phrase||"",A=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));o.reply(E,y,A)}if(this.emit("reinvite",d),h)return;if(this._late_sdp=!1,!o.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._createLocalDescription("offer",s._rtcOfferConstraints)}).then(function(T){g.call(s,T)}).catch(function(){o.reply(500)});return}if(r!=="application/sdp"){K.debug("invalid Content-Type"),o.reply(415);return}this._processInDialogSdpOffer(o).then(function(T){s._status!==Q.STATUS_TERMINATED&&g.call(s,T)}).catch(function(T){K.warn(T)});function g(T){var E=this,y=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(o,y),this._late_sdp&&(T=this._mangleOffer(T)),o.reply(200,null,y,T,function(){E._status=Q.STATUS_WAITING_FOR_ACK,E._setInvite2xxTimer(o,T),E._setACKTimer()}),typeof d.callback=="function"&&d.callback()}}},{key:"_receiveUpdate",value:function(o){var s=this;K.debug("receiveUpdate()");var r=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0,d={request:o,callback:void 0,reject:_.bind(this)},h=!1;function _(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};h=!0;var E=T.status_code||403,y=T.reason_phrase||"",A=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));o.reply(E,y,A)}if(this.emit("update",d),h)return;if(!o.body){g.call(this,null);return}if(r!=="application/sdp"){K.debug("invalid Content-Type"),o.reply(415);return}this._processInDialogSdpOffer(o).then(function(T){s._status!==Q.STATUS_TERMINATED&&g.call(s,T)}).catch(function(T){K.warn(T)});function g(T){var E=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(o,E),o.reply(200,null,E,T),typeof d.callback=="function"&&d.callback()}}},{key:"_processInDialogSdpOffer",value:function(o){var s=this;K.debug("_processInDialogSdpOffer()");var r=o.parseSDP(),d=!1,h=_s(r.media),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;if(Bl.indexOf(g.type)!==-1){var T=g.direction||r.direction||"sendrecv";if(T==="sendonly"||T==="inactive")d=!0;else{d=!1;break}}}}catch(A){h.e(A)}finally{h.f()}var E={originator:"remote",type:"offer",sdp:o.body};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(s._status===Q.STATUS_TERMINATED)throw new Error("terminated");return s._connection.setRemoteDescription(y).catch(function(A){throw o.reply(488),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',A),s.emit("peerconnection:setremotedescriptionfailed",A),A})}).then(function(){if(s._status===Q.STATUS_TERMINATED)throw new Error("terminated");s._remoteHold===!0&&d===!1?(s._remoteHold=!1,s._onunhold("remote")):s._remoteHold===!1&&d===!0&&(s._remoteHold=!0,s._onhold("remote"))}).then(function(){if(s._status===Q.STATUS_TERMINATED)throw new Error("terminated");return s._createLocalDescription("answer",s._rtcAnswerConstraints).catch(function(A){throw o.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(o){var s=this;if(K.debug("receiveRefer()"),!o.refer_to){K.debug("no Refer-To header field present in REFER"),o.reply(400);return}if(o.refer_to.uri.scheme!==ce.SIP){K.debug("Refer-To header field points to a non-SIP URI scheme"),o.reply(416);return}o.reply(202);var r=new fp(this,o.cseq);K.debug('emit "refer"'),this.emit("refer",{request:o,accept:function(g,T){d.call(s,g,T)},reject:function(){h.call(s)}});function d(_){var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(_=typeof _=="function"?_:null,this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;var T=new n(this._ua);if(T.on("progress",function(y){var A=y.response;r.notify(A.status_code,A.reason_phrase)}),T.on("accepted",function(y){var A=y.response;r.notify(A.status_code,A.reason_phrase)}),T.on("_failed",function(y){var A=y.message,C=y.cause;A?r.notify(A.status_code,A.reason_phrase):r.notify(487,C)}),o.refer_to.uri.hasHeader("replaces")){var E=decodeURIComponent(o.refer_to.uri.getHeader("replaces"));g.extraHeaders=Ve.cloneArray(g.extraHeaders),g.extraHeaders.push("Replaces: ".concat(E))}T.connect(o.refer_to.uri.toAor(),g,_)}function h(){r.notify(603)}}},{key:"_receiveNotify",value:function(o){switch(K.debug("receiveNotify()"),o.event||o.reply(400),o.event.event){case"refer":{var s,r;if(o.event.params&&o.event.params.id)s=o.event.params.id,r=this._referSubscribers[s];else if(Object.keys(this._referSubscribers).length===1)r=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{o.reply(400,"Missing event id parameter");return}if(!r){o.reply(481,"Subscription does not exist");return}r.receiveNotify(o),o.reply(200);break}default:o.reply(489)}}},{key:"_receiveReplaces",value:function(o){var s=this;K.debug("receiveReplaces()");function r(h){var _=this;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;var g=new n(this._ua);g.on("confirmed",function(){_.terminate()}),g.init_incoming(o,h)}function d(){K.debug("Replaced INVITE rejected by the user"),o.reply(486)}this.emit("replaces",{request:o,accept:function(_){r.call(s,_)},reject:function(){d.call(s)}})}},{key:"_sendInitialRequest",value:function(o,s,r){var d=this,h=new cp(this._ua,this._request,{onRequestTimeout:function(){d.onRequestTimeout()},onTransportError:function(){d.onTransportError()},onAuthenticated:function(g){d._request=g},onReceiveResponse:function(g){d._receiveInviteResponse(g)}});Promise.resolve().then(function(){if(r)return r;if(o.audio||o.video)return d._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(o).catch(function(_){throw d._status===Q.STATUS_TERMINATED?new Error("terminated"):(d._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',_),d.emit("getusermediafailed",_),_)})}).then(function(_){if(d._status===Q.STATUS_TERMINATED)throw new Error("terminated");return d._localMediaStream=_,_&&_.getTracks().forEach(function(g){d._connection.addTrack(g,_)}),d._connecting(d._request),d._createLocalDescription("offer",s).catch(function(g){throw d._failed("local",null,ce.causes.WEBRTC_ERROR),g})}).then(function(_){if(d._is_canceled||d._status===Q.STATUS_TERMINATED)throw new Error("terminated");d._request.body=_,d._status=Q.STATUS_INVITE_SENT,K.debug('emit "sending" [request:%o]',d._request),d.emit("sending",{request:d._request}),h.send()}).catch(function(_){d._status!==Q.STATUS_TERMINATED&&K.warn(_)})}},{key:"_getDTMFRTPSender",value:function(){var o=this._connection.getSenders().find(function(s){return s.track&&s.track.kind==="audio"});if(!(o&&o.dtmf)){K.warn("sendDTMF() | no local audio track to send DTMF with");return}return o.dtmf}},{key:"_receiveInviteResponse",value:function(o){var s=this;if(K.debug("receiveInviteResponse()"),this._dialog&&o.status_code>=200&&o.status_code<=299)if(this._dialog.id.call_id===o.call_id&&this._dialog.id.local_tag===o.from_tag&&this._dialog.id.remote_tag===o.to_tag){this.sendRequest(ce.ACK);return}else{var r=new Vl(this,o,"UAC");if(r.error!==void 0){K.debug(r.error);return}this.sendRequest(ce.ACK),this.sendRequest(ce.BYE);return}if(this._is_canceled){o.status_code>=100&&o.status_code<200?this._request.cancel(this._cancel_reason):o.status_code>=200&&o.status_code<299&&this._acceptAndTerminate(o);return}if(!(this._status!==Q.STATUS_INVITE_SENT&&this._status!==Q.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(o.status_code):this._status=Q.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(o.status_code):{if(!o.to_tag){K.debug("1xx response received without to tag");break}if(o.hasHeader("contact")&&!this._createDialog(o,"UAC",!0))break;if(this._status=Q.STATUS_1XX_RECEIVED,!o.body){this._progress("remote",o);break}var d={originator:"remote",type:"answer",sdp:o.body};K.debug('emit "sdp"'),this.emit("sdp",d);var h=new RTCSessionDescription({type:"answer",sdp:d.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._connection.setRemoteDescription(h)}).then(function(){return s._progress("remote",o)}).catch(function(E){K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),s.emit("peerconnection:setremotedescriptionfailed",E)});break}case/^2[0-9]{2}$/.test(o.status_code):{if(this._status=Q.STATUS_CONFIRMED,!o.body){this._acceptAndTerminate(o,400,ce.causes.MISSING_SDP),this._failed("remote",o,ce.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(o,"UAC"))break;var _={originator:"remote",type:"answer",sdp:o.body};K.debug('emit "sdp"'),this.emit("sdp",_);var g=new RTCSessionDescription({type:"answer",sdp:_.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(s._connection.signalingState==="stable")return s._connection.createOffer(s._rtcOfferConstraints).then(function(E){return s._connection.setLocalDescription(E)}).catch(function(E){s._acceptAndTerminate(o,500,E.toString()),s._failed("local",o,ce.causes.WEBRTC_ERROR)})}).then(function(){s._connection.setRemoteDescription(g).then(function(){s._handleSessionTimersInIncomingResponse(o),s._accepted("remote",o),s.sendRequest(ce.ACK),s._confirmed("local",null)}).catch(function(E){s._acceptAndTerminate(o,488,"Not Acceptable Here"),s._failed("remote",o,ce.causes.BAD_MEDIA_DESCRIPTION),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),s.emit("peerconnection:setremotedescriptionfailed",E)})});break}default:{var T=Ve.sipErrorCause(o.status_code);this._failed("remote",o,T)}}}},{key:"_sendReinvite",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};K.debug("sendReinvite()");var r=Ve.cloneArray(s.extraHeaders),d=Ve.cloneObject(s.eventHandlers),h=s.rtcOfferConstraints||this._rtcOfferConstraints||null,_=!1;r.push("Contact: ".concat(this._contact)),r.push("Content-Type: application/sdp"),this._sessionTimers.running&&r.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return o._createLocalDescription("offer",h)}).then(function(E){E=o._mangleOffer(E);var y={originator:"local",type:"offer",sdp:E};K.debug('emit "sdp"'),o.emit("sdp",y),o.sendRequest(ce.INVITE,{extraHeaders:r,body:E,eventHandlers:{onSuccessResponse:function(C){g.call(o,C),_=!0},onErrorResponse:function(C){T.call(o,C)},onTransportError:function(){o.onTransportError()},onRequestTimeout:function(){o.onRequestTimeout()},onDialogError:function(){o.onDialogError()}}})}).catch(function(){T()});function g(E){var y=this;if(this._status!==Q.STATUS_TERMINATED&&(this.sendRequest(ce.ACK),!_)){if(this._handleSessionTimersInIncomingResponse(E),E.body){if(!E.hasHeader("Content-Type")||E.getHeader("Content-Type").toLowerCase()!=="application/sdp"){T.call(this);return}}else{T.call(this);return}var A={originator:"remote",type:"answer",sdp:E.body};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 o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};K.debug("sendUpdate()");var r=Ve.cloneArray(s.extraHeaders),d=Ve.cloneObject(s.eventHandlers),h=s.rtcOfferConstraints||this._rtcOfferConstraints||null,_=s.sdpOffer||!1,g=!1;r.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&r.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),_?(r.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return o._createLocalDescription("offer",h)}).then(function(y){y=o._mangleOffer(y);var A={originator:"local",type:"offer",sdp:y};K.debug('emit "sdp"'),o.emit("sdp",A),o.sendRequest(ce.UPDATE,{extraHeaders:r,body:y,eventHandlers:{onSuccessResponse:function(I){T.call(o,I),g=!0},onErrorResponse:function(I){E.call(o,I)},onTransportError:function(){o.onTransportError()},onRequestTimeout:function(){o.onRequestTimeout()},onDialogError:function(){o.onDialogError()}}})}).catch(function(){E.call(o)})):this.sendRequest(ce.UPDATE,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(A){T.call(o,A)},onErrorResponse:function(A){E.call(o,A)},onTransportError:function(){o.onTransportError()},onRequestTimeout:function(){o.onRequestTimeout()},onDialogError:function(){o.onDialogError()}}});function T(y){var A=this;if(this._status!==Q.STATUS_TERMINATED&&!g)if(this._handleSessionTimersInIncomingResponse(y),_){if(y.body){if(!y.hasHeader("Content-Type")||y.getHeader("Content-Type").toLowerCase()!=="application/sdp"){E.call(this);return}}else{E.call(this);return}var C={originator:"remote",type:"answer",sdp:y.body};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(o,s,r){K.debug("acceptAndTerminate()");var d=[];s&&(r=r||ce.REASON_PHRASE[s]||"",d.push("Reason: SIP ;cause=".concat(s,'; text="').concat(r,'"'))),(this._dialog||this._createDialog(o,"UAC"))&&(this.sendRequest(ce.ACK),this.sendRequest(ce.BYE,{extraHeaders:d})),this._status=Q.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(o){if(!this._localHold&&!this._remoteHold)return o;if(o=Oc.parse(o),this._localHold&&!this._remoteHold){K.debug("mangleOffer() | me on hold, mangling offer");var s=_s(o.media),r;try{for(s.s();!(r=s.n()).done;){var d=r.value;Bl.indexOf(d.type)!==-1&&(d.direction?d.direction==="sendrecv"?d.direction="sendonly":d.direction==="recvonly"&&(d.direction="inactive"):d.direction="sendonly")}}catch(A){s.e(A)}finally{s.f()}}else if(this._localHold&&this._remoteHold){K.debug("mangleOffer() | both on hold, mangling offer");var h=_s(o.media),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;Bl.indexOf(g.type)!==-1&&(g.direction="inactive")}}catch(A){h.e(A)}finally{h.f()}}else if(this._remoteHold){K.debug("mangleOffer() | remote on hold, mangling offer");var T=_s(o.media),E;try{for(T.s();!(E=T.n()).done;){var y=E.value;Bl.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 Oc.write(o)}},{key:"_setLocalMediaStatus",value:function(){var o=!0,s=!0;(this._localHold||this._remoteHold)&&(o=!1,s=!1),this._audioMuted&&(o=!1),this._videoMuted&&(s=!1),this._toggleMuteAudio(!o),this._toggleMuteVideo(!s)}},{key:"_handleSessionTimersInIncomingRequest",value:function(o,s){if(this._sessionTimers.enabled){var r;o.session_expires&&o.session_expires>=ce.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=o.session_expires,r=o.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,r="uas"),s.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(r)),this._sessionTimers.refresher=r==="uas",this._runSessionTimer()}}},{key:"_handleSessionTimersInIncomingResponse",value:function(o){if(this._sessionTimers.enabled){var s;o.session_expires&&o.session_expires>=ce.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=o.session_expires,s=o.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,s="uac"),this._sessionTimers.refresher=s==="uac",this._runSessionTimer()}}},{key:"_runSessionTimer",value:function(){var o=this,s=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){o._status!==Q.STATUS_TERMINATED&&o._isReadyToReOffer()&&(K.debug("runSessionTimer() | sending session refresh request"),o._sessionTimers.refreshMethod===ce.UPDATE?o._sendUpdate():o._sendReinvite())},s*500):this._sessionTimers.timer=setTimeout(function(){o._status!==Q.STATUS_TERMINATED&&(K.warn("runSessionTimer() | timer expired, terminating the session"),o.terminate({cause:ce.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},s*1100)}},{key:"_toggleMuteAudio",value:function(o){var s=this._connection.getSenders().filter(function(_){return _.track&&_.track.kind==="audio"}),r=_s(s),d;try{for(r.s();!(d=r.n()).done;){var h=d.value;h.track.enabled=!o}}catch(_){r.e(_)}finally{r.f()}}},{key:"_toggleMuteVideo",value:function(o){var s=this._connection.getSenders().filter(function(_){return _.track&&_.track.kind==="video"}),r=_s(s),d;try{for(r.s();!(d=r.n()).done;){var h=d.value;h.track.enabled=!o}}catch(_){r.e(_)}finally{r.f()}}},{key:"_newRTCSession",value:function(o,s){K.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:o,session:this,request:s})}},{key:"_connecting",value:function(o){K.debug("session connecting"),K.debug('emit "connecting"'),this.emit("connecting",{request:o})}},{key:"_progress",value:function(o,s){K.debug("session progress"),K.debug('emit "progress"'),this.emit("progress",{originator:o,response:s||null})}},{key:"_accepted",value:function(o,s){K.debug("session accepted"),this._start_time=new Date,K.debug('emit "accepted"'),this.emit("accepted",{originator:o,response:s||null})}},{key:"_confirmed",value:function(o,s){K.debug("session confirmed"),this._is_confirmed=!0,K.debug('emit "confirmed"'),this.emit("confirmed",{originator:o,ack:s||null})}},{key:"_ended",value:function(o,s,r){K.debug("session ended"),this._end_time=new Date,this._close(),K.debug('emit "ended"'),this.emit("ended",{originator:o,message:s||null,cause:r})}},{key:"_failed",value:function(o,s,r){K.debug("session failed"),K.debug('emit "_failed"'),this.emit("_failed",{originator:o,message:s||null,cause:r}),this._close(),K.debug('emit "failed"'),this.emit("failed",{originator:o,message:s||null,cause:r})}},{key:"_onhold",value:function(o){K.debug("session onhold"),this._setLocalMediaStatus(),K.debug('emit "hold"'),this.emit("hold",{originator:o})}},{key:"_onunhold",value:function(o){K.debug("session onunhold"),this._setLocalMediaStatus(),K.debug('emit "unhold"'),this.emit("unhold",{originator:o})}},{key:"_onmute",value:function(o){var s=o.audio,r=o.video;K.debug("session onmute"),this._setLocalMediaStatus(),K.debug('emit "muted"'),this.emit("muted",{audio:s,video:r})}},{key:"_onunmute",value:function(o){var s=o.audio,r=o.video;K.debug("session onunmute"),this._setLocalMediaStatus(),K.debug('emit "unmuted"'),this.emit("unmuted",{audio:s,video:r})}},{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(o){this._data=o}},{key:"status",get:function(){return this._status}}]),n}(ap);function Ra(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ra=function(n){return typeof n}:Ra=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Ra(c)}function _p(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Pc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function pp(c,t,n){return t&&Pc(c.prototype,t),n&&Pc(c,n),c}function mp(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&mu(c,t)}function mu(c,t){return mu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},mu(c,t)}function gp(c){var t=Ep();return function(){var a=Ma(c),o;if(t){var s=Ma(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return Tp(this,o)}}function Tp(c,t){return t&&(Ra(t)==="object"||typeof t=="function")?t:vp(c)}function vp(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Ep(){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 Ma(c){return Ma=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Ma(c)}var Sp=ft.EventEmitter,yp=ht,Io=lt,Ap=Ss,ki=bt(),Cp=dl,xc=Ws,Rp=Ks(),Gl=new yp("Message"),Ip=function(c){mp(n,c);var t=gp(n);function n(a){var o;return _p(this,n),o=t.call(this),o._ua=a,o._request=null,o._closed=!1,o._direction=null,o._local_identity=null,o._remote_identity=null,o._is_replied=!1,o._data={},o}return pp(n,[{key:"send",value:function(o,s){var r=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},h=o;if(o===void 0||s===void 0)throw new TypeError("Not enough arguments");if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(h));var _=ki.cloneArray(d.extraHeaders),g=ki.cloneObject(d.eventHandlers),T=d.contentType||"text/plain",E={};d.fromUserName&&(E.from_uri=new Rp("sip",d.fromUserName,this._ua.configuration.uri.host),_.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),d.fromDisplayName&&(E.from_display_name=d.fromDisplayName);for(var y in g)Object.prototype.hasOwnProperty.call(g,y)&&this.on(y,g[y]);_.push("Content-Type: ".concat(T)),this._request=new Ap.OutgoingRequest(Io.MESSAGE,o,this._ua,E,_),s&&(this._request.body=s);var A=new Cp(this._ua,this._request,{onRequestTimeout:function(){r._onRequestTimeout()},onTransportError:function(){r._onTransportError()},onReceiveResponse:function(I){r._receiveResponse(I)}});this._newMessage("local",this._request),A.send()}},{key:"init_incoming",value:function(o){this._request=o,this._newMessage("remote",o),this._is_replied||(this._is_replied=!0,o.reply(200)),this._close()}},{key:"accept",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=ki.cloneArray(o.extraHeaders),r=o.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,s,r)}},{key:"reject",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=o.status_code||480,r=o.reason_phrase,d=ki.cloneArray(o.extraHeaders),h=o.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(s<300||s>=700)throw new TypeError("Invalid status_code: ".concat(s));this._is_replied=!0,this._request.reply(s,r,d,h)}},{key:"_receiveResponse",value:function(o){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):this._succeeded("remote",o);break;default:{var s=ki.sipErrorCause(o.status_code);this._failed("remote",o,s);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,Io.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,Io.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newMessage",value:function(o,s){o==="remote"?(this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from):o==="local"&&(this._direction="outgoing",this._local_identity=s.from,this._remote_identity=s.to),this._ua.newMessage(this,{originator:o,message:this,request:s})}},{key:"_failed",value:function(o,s,r){Gl.debug("MESSAGE failed"),this._close(),Gl.debug('emit "failed"'),this.emit("failed",{originator:o,response:s||null,cause:r})}},{key:"_succeeded",value:function(o,s){Gl.debug("MESSAGE succeeded"),this._close(),Gl.debug('emit "succeeded"'),this.emit("succeeded",{originator:o,response:s})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}]),n}(Sp);function Ia(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ia=function(n){return typeof n}:Ia=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Ia(c)}function bp(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function kc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function wp(c,t,n){return t&&kc(c.prototype,t),n&&kc(c,n),c}function Op(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&gu(c,t)}function gu(c,t){return gu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},gu(c,t)}function Dp(c){var t=Pp();return function(){var a=La(c),o;if(t){var s=La(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return Np(this,o)}}function Np(c,t){return t&&(Ia(t)==="object"||typeof t=="function")?t:Up(c)}function Up(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Pp(){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(n){return n.__proto__||Object.getPrototypeOf(n)},La(c)}var xp=ft.EventEmitter,kp=ht,bo=lt,Mp=Ss,Mi=bt(),Lp=dl,Mc=Ws,Wl=new kp("Options"),$p=function(c){Op(n,c);var t=Dp(n);function n(a){var o;return bp(this,n),o=t.call(this),o._ua=a,o._request=null,o._closed=!1,o._direction=null,o._local_identity=null,o._remote_identity=null,o._is_replied=!1,o._data={},o}return wp(n,[{key:"send",value:function(o,s){var r=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},h=o;if(o===void 0)throw new TypeError("A target is required for OPTIONS");if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(h));var _=Mi.cloneArray(d.extraHeaders),g=Mi.cloneObject(d.eventHandlers),T=d.contentType||"application/sdp";for(var E in g)Object.prototype.hasOwnProperty.call(g,E)&&this.on(E,g[E]);_.push("Content-Type: ".concat(T)),this._request=new Mp.OutgoingRequest(bo.OPTIONS,o,this._ua,null,_),s&&(this._request.body=s);var y=new Lp(this._ua,this._request,{onRequestTimeout:function(){r._onRequestTimeout()},onTransportError:function(){r._onTransportError()},onReceiveResponse:function(C){r._receiveResponse(C)}});this._newOptions("local",this._request),y.send()}},{key:"init_incoming",value:function(o){this._request=o,this._newOptions("remote",o),this._is_replied||(this._is_replied=!0,o.reply(200)),this._close()}},{key:"accept",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=Mi.cloneArray(o.extraHeaders),r=o.body;if(this._direction!=="incoming")throw new Mc.NotSupportedError('"accept" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");this._is_replied=!0,this._request.reply(200,null,s,r)}},{key:"reject",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=o.status_code||480,r=o.reason_phrase,d=Mi.cloneArray(o.extraHeaders),h=o.body;if(this._direction!=="incoming")throw new Mc.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(s<300||s>=700)throw new TypeError("Invalid status_code: ".concat(s));this._is_replied=!0,this._request.reply(s,r,d,h)}},{key:"_receiveResponse",value:function(o){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):this._succeeded("remote",o);break;default:{var s=Mi.sipErrorCause(o.status_code);this._failed("remote",o,s);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(o,s){o==="remote"?(this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from):o==="local"&&(this._direction="outgoing",this._local_identity=s.from,this._remote_identity=s.to),this._ua.newOptions(this,{originator:o,message:this,request:s})}},{key:"_failed",value:function(o,s,r){Wl.debug("OPTIONS failed"),this._close(),Wl.debug('emit "failed"'),this.emit("failed",{originator:o,response:s||null,cause:r})}},{key:"_succeeded",value:function(o,s){Wl.debug("OPTIONS succeeded"),this._close(),Wl.debug('emit "succeeded"'),this.emit("succeeded",{originator:o,response:s})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}]),n}(xp),xu={},Hp=ht,wo=bt(),Fp=os(),Li=new Hp("Socket");xu.isSocket=function(c){if(Array.isArray(c))return!1;if(typeof c>"u")return Li.warn("undefined JsSIP.Socket instance"),!1;try{if(!wo.isString(c.url))throw Li.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!wo.isString(c.via_transport))throw Li.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(Fp.parse(c.sip_uri,"SIP_URI")===-1)throw Li.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch{return!1}try{["connect","disconnect","send"].forEach(function(t){if(!wo.isFunction(c[t]))throw Li.warn("missing or invalid JsSIP.Socket method: ".concat(t)),new Error("Missing or invalid JsSIP.Socket method: ".concat(t))})}catch{return!1}return!0};function jp(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Lc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function qp(c,t,n){return t&&Lc(c.prototype,t),n&&Lc(c,n),c}var Vp=ht,Bp=xu,$c=lt,Nt=new Vp("Transport"),qt={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}},Gp=function(){function c(t){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:qt.recovery_options;jp(this,c),Nt.debug("new()"),this.status=qt.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(a){Nt.warn("cannot use TextDecoder: ".concat(a))}if(typeof t>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(a){if(!Bp.isSocket(a.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(a.weight&&!Number(a.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:a.socket,weight:a.weight||0,status:qt.SOCKET_STATUS_READY})},this),this._getSocket()}return qp(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=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())}},{key:"disconnect",value:function(){Nt.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=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(n){if(Nt.debug("send()"),!this.isConnected())return Nt.warn("unable to send message, transport is not connected"),!1;var a=n.toString();return Nt.debug(`sending message:
|
48
|
+
`);d.length>=1&&s.test(d[0])&&(this._tone=d[0].replace(s,"$2")),d.length>=2&&r.test(d[1])&&(this._duration=parseInt(d[1].replace(r,"$2"),10))}this._duration||(this._duration=rh.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:o}):A_.debug("invalid INFO DTMF received, discarded")}},{key:"tone",get:function(){return this._tone}},{key:"duration",get:function(){return this._duration}}]),n}(E_);Pu.exports.C=rh;var R_=Pu.exports;function ya(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?ya=function(n){return typeof n}:ya=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},ya(c)}function I_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Sc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function b_(c,t,n){return t&&Sc(c.prototype,t),n&&Sc(c,n),c}function w_(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&du(c,t)}function du(c,t){return du=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},du(c,t)}function O_(c){var t=U_();return function(){var a=Pa(c),o;if(t){var s=Pa(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return D_(this,o)}}function D_(c,t){return t&&(ya(t)==="object"||typeof t=="function")?t:N_(c)}function N_(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function U_(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}function Pa(c){return Pa=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Pa(c)}var P_=ft.EventEmitter,x_=lt,k_=Ws,M_=bt(),L_=function(c){w_(n,c);var t=O_(n);function n(a){var o;return I_(this,n),o=t.call(this),o._session=a,o._direction=null,o._contentType=null,o._body=null,o}return b_(n,[{key:"send",value:function(o,s){var r=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(this._direction="outgoing",o===void 0)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new k_.InvalidStateError(this._session.status);this._contentType=o,this._body=s;var h=M_.cloneArray(d.extraHeaders);h.push("Content-Type: ".concat(o)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(x_.INFO,{extraHeaders:h,eventHandlers:{onSuccessResponse:function(g){r.emit("succeeded",{originator:"remote",response:g})},onErrorResponse:function(g){r.emit("failed",{originator:"remote",response:g})},onTransportError:function(){r._session.onTransportError()},onRequestTimeout:function(){r._session.onRequestTimeout()},onDialogError:function(){r._session.onDialogError()}},body:s})}},{key:"init_incoming",value:function(o){this._direction="incoming",this.request=o,o.reply(200),this._contentType=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0,this._body=o.body,this._session.newInfo({originator:"remote",info:this,request:o})}},{key:"contentType",get:function(){return this._contentType}},{key:"body",get:function(){return this._body}}]),n}(P_);function $_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function yc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function H_(c,t,n){return t&&yc(c.prototype,t),n&&yc(c,n),c}var F_=ht,Cc=lt,j_=new F_("RTCSession:ReferNotifier"),Ro={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300},q_=function(){function c(t,n,a){$_(this,c),this._session=t,this._id=n,this._expires=a||Ro.expires,this._active=!0,this.notify(100)}return H_(c,[{key:"notify",value:function(n,a){if(j_.debug("notify()"),this._active!==!1){a=a||Cc.REASON_PHRASE[n]||"";var o;n>=200?o="terminated;reason=noresource":o="active;expires=".concat(this._expires),this._session.sendRequest(Cc.NOTIFY,{extraHeaders:["Event: ".concat(Ro.event_type,";id=").concat(this._id),"Subscription-State: ".concat(o),"Content-Type: ".concat(Ro.body_type)],body:"SIP/2.0 ".concat(n," ").concat(a),eventHandlers:{onErrorResponse:function(){this._active=!1}}})}}}]),c}();function Ca(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ca=function(n){return typeof n}:Ca=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Ca(c)}function V_(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Ac(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function B_(c,t,n){return t&&Ac(c.prototype,t),n&&Ac(c,n),c}function G_(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&_u(c,t)}function _u(c,t){return _u=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},_u(c,t)}function W_(c){var t=J_();return function(){var a=xa(c),o;if(t){var s=xa(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return K_(this,o)}}function K_(c,t){return t&&(Ca(t)==="object"||typeof t=="function")?t:Y_(c)}function Y_(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function J_(){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 xa(c){return xa=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},xa(c)}var z_=ft.EventEmitter,X_=ht,Pi=lt,Q_=os(),Rc=bt(),mn=new X_("RTCSession:ReferSubscriber"),Z_=function(c){G_(n,c);var t=W_(n);function n(a){var o;return V_(this,n),o=t.call(this),o._id=null,o._session=a,o}return B_(n,[{key:"sendRefer",value:function(o){var s=this,r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};mn.debug("sendRefer()");var d=Rc.cloneArray(r.extraHeaders),h=Rc.cloneObject(r.eventHandlers);for(var _ in h)Object.prototype.hasOwnProperty.call(h,_)&&this.on(_,h[_]);var g=null;r.replaces&&(g=r.replaces._request.call_id,g+=";to-tag=".concat(r.replaces._to_tag),g+=";from-tag=".concat(r.replaces._from_tag),g=encodeURIComponent(g));var T="Refer-To: <".concat(o).concat(g?"?Replaces=".concat(g):"",">");if(d.push(T),!d.some(function(C){return C.toLowerCase().startsWith("referred-by:")})){var E="Referred-By: <".concat(this._session._ua._configuration.uri._scheme,":").concat(this._session._ua._configuration.uri._user,"@").concat(this._session._ua._configuration.uri._host,">");d.push(E)}d.push("Contact: ".concat(this._session.contact));var y=this._session.sendRequest(Pi.REFER,{extraHeaders:d,eventHandlers:{onSuccessResponse:function(A){s._requestSucceeded(A)},onErrorResponse:function(A){s._requestFailed(A,Pi.causes.REJECTED)},onTransportError:function(){s._requestFailed(null,Pi.causes.CONNECTION_ERROR)},onRequestTimeout:function(){s._requestFailed(null,Pi.causes.REQUEST_TIMEOUT)},onDialogError:function(){s._requestFailed(null,Pi.causes.DIALOG_ERROR)}}});this._id=y.cseq}},{key:"receiveNotify",value:function(o){if(mn.debug("receiveNotify()"),!!o.body){var s=Q_.parse(o.body.trim().split(`\r
|
49
|
+
`,1)[0],"Status_Line");if(s===-1){mn.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(o.body,'"'));return}switch(!0){case/^100$/.test(s.status_code):this.emit("trying",{request:o,status_line:s});break;case/^1[0-9]{2}$/.test(s.status_code):this.emit("progress",{request:o,status_line:s});break;case/^2[0-9]{2}$/.test(s.status_code):this.emit("accepted",{request:o,status_line:s});break;default:this.emit("failed",{request:o,status_line:s});break}}}},{key:"_requestSucceeded",value:function(o){mn.debug("REFER succeeded"),mn.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:o})}},{key:"_requestFailed",value:function(o,s){mn.debug("REFER failed"),mn.debug('emit "requestFailed"'),this.emit("requestFailed",{response:o||null,cause:s})}},{key:"id",get:function(){return this._id}}]),n}(z_);function Aa(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Aa=function(n){return typeof n}:Aa=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Aa(c)}function _s(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=ep(c))||t&&c&&typeof c.length=="number"){n&&(c=n);var a=0,o=function(){};return{s:o,n:function(){return a>=c.length?{done:!0}:{done:!1,value:c[a++]}},e:function(_){throw _},f:o}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
50
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function ep(c,t){if(c){if(typeof c=="string")return Ic(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Ic(c,t)}}function Ic(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}function tp(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function bc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function wc(c,t,n){return t&&bc(c.prototype,t),n&&bc(c,n),c}function sp(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&pu(c,t)}function pu(c,t){return pu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},pu(c,t)}function np(c){var t=lp();return function(){var a=ka(c),o;if(t){var s=ka(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return rp(this,o)}}function rp(c,t){return t&&(Aa(t)==="object"||typeof t=="function")?t:ip(c)}function ip(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function lp(){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(n){return n.__proto__||Object.getPrototypeOf(n)},ka(c)}var ap=ft.EventEmitter,Oc=xt,op=ht,ce=lt,gn=Ws,Dc=hl,Ve=bt(),xi=nh,up=Ss,Vl=h_,cp=dl,kt=R_,Nc=L_,fp=q_,hp=Z_,Uc=Ks(),K=new op("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},Bl=["audio","video"],dp=function(c){sp(n,c);var t=np(n);wc(n,null,[{key:"C",get:function(){return Q}}]);function n(a){var o;return tp(this,n),K.debug("new"),o=t.call(this),o._id=null,o._ua=a,o._status=Q.STATUS_NULL,o._dialog=null,o._earlyDialogs={},o._contact=null,o._from_tag=null,o._to_tag=null,o._connection=null,o._connectionPromiseQueue=Promise.resolve(),o._request=null,o._is_canceled=!1,o._cancel_reason="",o._is_confirmed=!1,o._late_sdp=!1,o._rtcOfferConstraints=null,o._rtcAnswerConstraints=null,o._localMediaStream=null,o._localMediaStreamLocallyGenerated=!1,o._rtcReady=!0,o._iceReady=!1,o._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},o._direction=null,o._local_identity=null,o._remote_identity=null,o._start_time=null,o._end_time=null,o._tones=null,o._audioMuted=!1,o._videoMuted=!1,o._localHold=!1,o._remoteHold=!1,o._sessionTimers={enabled:o._ua.configuration.session_timers,refreshMethod:o._ua.configuration.session_timers_refresh_method,defaultExpires:ce.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},o._referSubscribers={},o._data={},o}return wc(n,[{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(o){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;K.debug("connect()");var d=o,h=Ve.cloneObject(s.eventHandlers),_=Ve.cloneArray(s.extraHeaders),g=Ve.cloneObject(s.mediaConstraints,{audio:!0,video:!0}),T=s.mediaStream||null,E=Ve.cloneObject(s.pcConfig,{iceServers:[]}),y=s.rtcConstraints||null,C=s.rtcOfferConstraints||null;if(this._rtcOfferConstraints=C,this._rtcAnswerConstraints=s.rtcAnswerConstraints||null,this._data=s.data||this._data,o===void 0)throw new TypeError("Not enough arguments");if(this._status!==Q.STATUS_NULL)throw new gn.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new gn.NotSupportedError("WebRTC not supported");if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(d));this._sessionTimers.enabled&&Ve.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES);for(var A in h)Object.prototype.hasOwnProperty.call(h,A)&&this.on(A,h[A]);this._from_tag=Ve.newTag();var I=s.anonymous||!1,H={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:I,outbound:!0}),I?(H.from_display_name="Anonymous",H.from_uri=new Uc("sip","anonymous","anonymous.invalid"),_.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),_.push("Privacy: id")):s.fromUserName&&(H.from_uri=new Uc("sip",s.fromUserName,this._ua.configuration.uri.host),_.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),s.fromDisplayName&&(H.from_display_name=s.fromDisplayName),_.push("Contact: ".concat(this._contact)),_.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&_.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher?";refresher=uac":"")),this._request=new up.InitialOutgoingInviteRequest(o,this._ua,H,_),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(E,y),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,r&&r(this),this._newRTCSession("local",this._request),this._sendInitialRequest(g,C,T)}},{key:"init_incoming",value:function(o,s){var r=this;K.debug("init_incoming()");var d,h=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0;if(o.body&&h!=="application/sdp"){o.reply(415);return}if(this._status=Q.STATUS_INVITE_RECEIVED,this._from_tag=o.from_tag,this._id=o.call_id+this._from_tag,this._request=o,this._contact=this._ua.contact.toString(),o.hasHeader("expires")&&(d=o.getHeader("expires")*1e3),o.to_tag=Ve.newTag(),!this._createDialog(o,"UAS",!0)){o.reply(500,"Missing Contact header field");return}o.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Q.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){o.reply(408),r._failed("local",null,ce.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),d&&(this._timers.expiresTimer=setTimeout(function(){r._status===Q.STATUS_WAITING_FOR_ANSWER&&(o.reply(487),r._failed("system",null,ce.causes.EXPIRES))},d)),this._direction="incoming",this._local_identity=o.to,this._remote_identity=o.from,s&&s(this),this._newRTCSession("remote",o),this._status!==Q.STATUS_TERMINATED&&(o.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))}},{key:"answer",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};K.debug("answer()");var r=this._request,d=Ve.cloneArray(s.extraHeaders),h=Ve.cloneObject(s.mediaConstraints),_=s.mediaStream||null,g=Ve.cloneObject(s.pcConfig,{iceServers:[]}),T=s.rtcConstraints||null,E=s.rtcAnswerConstraints||null,y=Ve.cloneObject(s.rtcOfferConstraints),C,A=!1,I=!1,H=!1,$=!1;if(this._rtcAnswerConstraints=E,this._rtcOfferConstraints=s.rtcOfferConstraints||null,this._data=s.data||this._data,this._direction!=="incoming")throw new gn.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==Q.STATUS_WAITING_FOR_ANSWER)throw new gn.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Ve.isDecimal(s.sessionTimersExpires)&&(s.sessionTimersExpires>=ce.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=s.sessionTimersExpires:this._sessionTimers.defaultExpires=ce.SESSION_EXPIRES),this._status=Q.STATUS_ANSWERED,!this._createDialog(r,"UAS")){r.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),d.unshift("Contact: ".concat(this._contact));var oe=r.parseSDP();Array.isArray(oe.media)||(oe.media=[oe.media]);var N=_s(oe.media),j;try{for(N.s();!(j=N.n()).done;){var Se=j.value;Se.type==="audio"&&(A=!0,(!Se.direction||Se.direction==="sendrecv")&&(H=!0)),Se.type==="video"&&(I=!0,(!Se.direction||Se.direction==="sendrecv")&&($=!0))}}catch(F){N.e(F)}finally{N.f()}if(_&&h.audio===!1){C=_.getAudioTracks();var ve=_s(C),k;try{for(ve.s();!(k=ve.n()).done;){var D=k.value;_.removeTrack(D)}}catch(F){ve.e(F)}finally{ve.f()}}if(_&&h.video===!1){C=_.getVideoTracks();var B=_s(C),V;try{for(B.s();!(V=B.n()).done;){var J=V.value;_.removeTrack(J)}}catch(F){B.e(F)}finally{B.f()}}!_&&h.audio===void 0&&(h.audio=H),!_&&h.video===void 0&&(h.video=$),!_&&!A&&!y.offerToReceiveAudio&&(h.audio=!1),!_&&!I&&!y.offerToReceiveVideo&&(h.video=!1),this._createRTCConnection(g,T),Promise.resolve().then(function(){if(_)return _;if(h.audio||h.video)return o._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(h).catch(function(F){throw o._status===Q.STATUS_TERMINATED?new Error("terminated"):(r.reply(480),o._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',F),o.emit("getusermediafailed",F),new Error("getUserMedia() failed"))})}).then(function(F){if(o._status===Q.STATUS_TERMINATED)throw new Error("terminated");o._localMediaStream=F,F&&F.getTracks().forEach(function(X){o._connection.addTrack(X,F)})}).then(function(){if(!o._late_sdp){var F={originator:"remote",type:"offer",sdp:r.body};K.debug('emit "sdp"'),o.emit("sdp",F);var X=new RTCSessionDescription({type:"offer",sdp:F.sdp});return o._connectionPromiseQueue=o._connectionPromiseQueue.then(function(){return o._connection.setRemoteDescription(X)}).catch(function(U){throw r.reply(488),o._failed("system",null,ce.causes.WEBRTC_ERROR),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',U),o.emit("peerconnection:setremotedescriptionfailed",U),new Error("peerconnection.setRemoteDescription() failed")}),o._connectionPromiseQueue}}).then(function(){if(o._status===Q.STATUS_TERMINATED)throw new Error("terminated");return o._connecting(r),o._late_sdp?o._createLocalDescription("offer",o._rtcOfferConstraints).catch(function(){throw r.reply(500),new Error("_createLocalDescription() failed")}):o._createLocalDescription("answer",E).catch(function(){throw r.reply(500),new Error("_createLocalDescription() failed")})}).then(function(F){if(o._status===Q.STATUS_TERMINATED)throw new Error("terminated");o._handleSessionTimersInIncomingRequest(r,d),r.reply(200,null,d,F,function(){o._status=Q.STATUS_WAITING_FOR_ACK,o._setInvite2xxTimer(r,F),o._setACKTimer(),o._accepted("local")},function(){o._failed("system",null,ce.causes.CONNECTION_ERROR)})}).catch(function(F){o._status!==Q.STATUS_TERMINATED&&K.warn(F)})}},{key:"terminate",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};K.debug("terminate()");var r=s.cause||ce.causes.BYE,d=Ve.cloneArray(s.extraHeaders),h=s.body,_,g=s.status_code,T=s.reason_phrase;if(this._status===Q.STATUS_TERMINATED)throw new gn.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]||"",_="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=_):this._status===Q.STATUS_1XX_RECEIVED&&this._request.cancel(_),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,h),this._failed("local",null,ce.causes.REJECTED);break;case Q.STATUS_WAITING_FOR_ACK:case Q.STATUS_CONFIRMED:if(K.debug("terminating session"),T=s.reason_phrase||ce.REASON_PHRASE[g]||"",g&&(g<200||g>=700))throw new TypeError("Invalid status_code: ".concat(g));if(g&&d.push("Reason: SIP ;cause=".concat(g,'; text="').concat(T,'"')),this._status===Q.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Dc.C.STATUS_TERMINATED){var E=this._dialog;this.receiveRequest=function(y){var C=y.method;C===ce.ACK&&(o.sendRequest(ce.BYE,{extraHeaders:d,body:h}),E.terminate())},this._request.server_transaction.on("stateChanged",function(){o._request.server_transaction.state===Dc.C.STATUS_TERMINATED&&(o.sendRequest(ce.BYE,{extraHeaders:d,body:h}),E.terminate())}),this._ended("local",null,r),this._dialog=E,this._ua.newDialog(E)}else this.sendRequest(ce.BYE,{extraHeaders:d,body:h}),this._ended("local",null,r)}}},{key:"sendDTMF",value:function(o){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};K.debug("sendDTMF() | tones: %s",o);var r=0,d=s.duration||null,h=s.interToneGap||null,_=s.transportType||ce.DTMF_TRANSPORT.INFO;if(o===void 0)throw new TypeError("Not enough arguments");if(this._status!==Q.STATUS_CONFIRMED&&this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_1XX_RECEIVED)throw new gn.InvalidStateError(this._status);if(_!==ce.DTMF_TRANSPORT.INFO&&_!==ce.DTMF_TRANSPORT.RFC2833)throw new TypeError("invalid transportType: ".concat(_));if(typeof o=="number"&&(o=o.toString()),!o||typeof o!="string"||!o.match(/^[0-9A-DR#*,]+$/i))throw new TypeError("Invalid tones: ".concat(o));if(d&&!Ve.isDecimal(d))throw new TypeError("Invalid tone duration: ".concat(d));if(d?d<kt.C.MIN_DURATION?(K.debug('"duration" value is lower than the minimum allowed, setting it to '.concat(kt.C.MIN_DURATION," milliseconds")),d=kt.C.MIN_DURATION):d>kt.C.MAX_DURATION?(K.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(kt.C.MAX_DURATION," milliseconds")),d=kt.C.MAX_DURATION):d=Math.abs(d):d=kt.C.DEFAULT_DURATION,s.duration=d,h&&!Ve.isDecimal(h))throw new TypeError("Invalid interToneGap: ".concat(h));if(h?h<kt.C.MIN_INTER_TONE_GAP?(K.debug('"interToneGap" value is lower than the minimum allowed, setting it to '.concat(kt.C.MIN_INTER_TONE_GAP," milliseconds")),h=kt.C.MIN_INTER_TONE_GAP):h=Math.abs(h):h=kt.C.DEFAULT_INTER_TONE_GAP,_===ce.DTMF_TRANSPORT.RFC2833){var g=this._getDTMFRTPSender();g&&(o=g.toneBuffer+o,g.insertDTMF(o,d,h));return}if(this._tones){this._tones+=o;return}this._tones=o,T.call(this);function T(){var E=this,y;if(this._status===Q.STATUS_TERMINATED||!this._tones||r>=this._tones.length){this._tones=null;return}var C=this._tones[r];if(r+=1,C===",")y=2e3;else{var A=new kt(this);s.eventHandlers={onFailed:function(){E._tones=null}},A.send(C,s),y=d+h}setTimeout(T.bind(this),y)}}},{key:"sendInfo",value:function(o,s){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(K.debug("sendInfo()"),this._status!==Q.STATUS_CONFIRMED&&this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_1XX_RECEIVED)throw new gn.InvalidStateError(this._status);var d=new Nc(this);d.send(o,s,r)}},{key:"mute",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!1};K.debug("mute()");var s=!1,r=!1;this._audioMuted===!1&&o.audio&&(s=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&o.video&&(r=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(s===!0||r===!0)&&this._onmute({audio:s,video:r})}},{key:"unmute",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{audio:!0,video:!0};K.debug("unmute()");var s=!1,r=!1;this._audioMuted===!0&&o.audio&&(s=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&o.video&&(r=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(s===!0||r===!0)&&this._onunmute({audio:s,video:r})}},{key:"hold",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;if(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(){r&&r()},failed:function(){o.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:d,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:d,extraHeaders:s.extraHeaders}),!0}},{key:"unhold",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;if(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(){r&&r()},failed:function(){o.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:d,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:d,extraHeaders:s.extraHeaders}),!0}},{key:"renegotiate",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;K.debug("renegotiate()");var d=s.rtcOfferConstraints||null;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;var h={succeeded:function(){r&&r()},failed:function(){o.terminate({cause:ce.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),s.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:h,rtcOfferConstraints:d,extraHeaders:s.extraHeaders}):this._sendReinvite({eventHandlers:h,rtcOfferConstraints:d,extraHeaders:s.extraHeaders}),!0}},{key:"refer",value:function(o,s){var r=this;K.debug("refer()");var d=o;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(d));var h=new hp(this);h.sendRefer(o,s);var _=h.id;return this._referSubscribers[_]=h,h.on("requestFailed",function(){delete r._referSubscribers[_]}),h.on("accepted",function(){delete r._referSubscribers[_]}),h.on("failed",function(){delete r._referSubscribers[_]}),h}},{key:"sendRequest",value:function(o,s){return K.debug("sendRequest()"),this._dialog.sendRequest(o,s)}},{key:"receiveRequest",value:function(o){var s=this;if(K.debug("receiveRequest()"),o.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",o,ce.causes.CANCELED));else switch(o.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(!o.body){this.terminate({cause:ce.causes.MISSING_SDP,status_code:400});break}var r={originator:"remote",type:"answer",sdp:o.body};K.debug('emit "sdp"'),this.emit("sdp",r);var d=new RTCSessionDescription({type:"answer",sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._connection.setRemoteDescription(d)}).then(function(){s._is_confirmed||s._confirmed("remote",o)}).catch(function(_){s.terminate({cause:ce.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',_),s.emit("peerconnection:setremotedescriptionfailed",_)})}else this._is_confirmed||this._confirmed("remote",o);break;case ce.BYE:this._status===Q.STATUS_CONFIRMED||this._status===Q.STATUS_WAITING_FOR_ACK?(o.reply(200),this._ended("remote",o,ce.causes.BYE)):this._status===Q.STATUS_INVITE_RECEIVED||this._status===Q.STATUS_WAITING_FOR_ANSWER?(o.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",o,ce.causes.BYE)):o.reply(403,"Wrong Status");break;case ce.INVITE:this._status===Q.STATUS_CONFIRMED?o.hasHeader("replaces")?this._receiveReplaces(o):this._receiveReinvite(o):o.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 h=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0;h&&h.match(/^application\/dtmf-relay/i)?new kt(this).init_incoming(o):h!==void 0?new Nc(this).init_incoming(o):o.reply(415)}else o.reply(403,"Wrong Status");break;case ce.UPDATE:this._status===Q.STATUS_CONFIRMED?this._receiveUpdate(o):o.reply(403,"Wrong Status");break;case ce.REFER:this._status===Q.STATUS_CONFIRMED?this._receiveRefer(o):o.reply(403,"Wrong Status");break;case ce.NOTIFY:this._status===Q.STATUS_CONFIRMED?this._receiveNotify(o):o.reply(403,"Wrong Status");break;default:o.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(o){K.debug("newDTMF()"),this.emit("newDTMF",o)}},{key:"newInfo",value:function(o){K.debug("newInfo()"),this.emit("newInfo",o)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(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 o in this._timers)Object.prototype.hasOwnProperty.call(this._timers,o)&&clearTimeout(this._timers[o]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(var s in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,s)&&(this._earlyDialogs[s].terminate(),delete this._earlyDialogs[s]);for(var r in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,r)&&delete this._referSubscribers[r];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(o,s){var r=xi.T1;function d(){this._status===Q.STATUS_WAITING_FOR_ACK&&(o.reply(200,null,["Contact: ".concat(this._contact)],s),r<xi.T2&&(r=r*2,r>xi.T2&&(r=xi.T2)),this._timers.invite2xxTimer=setTimeout(d.bind(this),r))}this._timers.invite2xxTimer=setTimeout(d.bind(this),r)}},{key:"_setACKTimer",value:function(){var o=this;this._timers.ackTimer=setTimeout(function(){o._status===Q.STATUS_WAITING_FOR_ACK&&(K.debug("no ACK received, terminating the session"),clearTimeout(o._timers.invite2xxTimer),o.sendRequest(ce.BYE),o._ended("remote",null,ce.causes.NO_ACK))},xi.TIMER_H)}},{key:"_createRTCConnection",value:function(o,s){var r=this;this._connection=new RTCPeerConnection(o,s),this._connection.addEventListener("iceconnectionstatechange",function(){var d=r._connection.iceConnectionState;d==="failed"&&r.terminate({cause:ce.causes.RTP_TIMEOUT,status_code:408,reason_phrase:ce.causes.RTP_TIMEOUT})}),K.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(o,s){var r=this;if(K.debug("createLocalDescription()"),o!=="offer"&&o!=="answer")throw new Error('createLocalDescription() | invalid type "'.concat(o,'"'));var d=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return o==="offer"?d.createOffer(s).catch(function(h){return K.warn('emit "peerconnection:createofferfailed" [error:%o]',h),r.emit("peerconnection:createofferfailed",h),Promise.reject(h)}):d.createAnswer(s).catch(function(h){return K.warn('emit "peerconnection:createanswerfailed" [error:%o]',h),r.emit("peerconnection:createanswerfailed",h),Promise.reject(h)})}).then(function(h){return d.setLocalDescription(h).catch(function(_){return r._rtcReady=!0,K.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',_),r.emit("peerconnection:setlocaldescriptionfailed",_),Promise.reject(_)})}).then(function(){var h=s&&s.iceRestart;if(d.iceGatheringState==="complete"&&!h||d.iceGatheringState==="gathering"&&r._iceReady){r._rtcReady=!0;var _={originator:"local",type:o,sdp:d.localDescription.sdp};return K.debug('emit "sdp"'),r.emit("sdp",_),Promise.resolve(_.sdp)}return new Promise(function(g){var T=!1,E,y;r._iceReady=!1;var C=function(){d.removeEventListener("icecandidate",E),d.removeEventListener("icegatheringstatechange",y),T=!0,r._rtcReady=!0,r._iceReady=!0;var I={originator:"local",type:o,sdp:d.localDescription.sdp};K.debug('emit "sdp"'),r.emit("sdp",I),g(I.sdp)};d.addEventListener("icecandidate",E=function(I){var H=I.candidate;H?r.emit("icecandidate",{candidate:H,ready:C}):T||C()}),d.addEventListener("icegatheringstatechange",y=function(){d.iceGatheringState==="complete"&&!T&&C()})})})}},{key:"_createDialog",value:function(o,s,r){var d=s==="UAS"?o.to_tag:o.from_tag,h=s==="UAS"?o.from_tag:o.to_tag,_=o.call_id+d+h,g=this._earlyDialogs[_];if(r)return g?!0:(g=new Vl(this,o,s,Vl.C.STATUS_EARLY),g.error?(K.debug(g.error),this._failed("remote",o,ce.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[_]=g,!0));if(this._from_tag=o.from_tag,this._to_tag=o.to_tag,g)return g.update(o,s),this._dialog=g,delete this._earlyDialogs[_],!0;var T=new Vl(this,o,s);return T.error?(K.debug(T.error),this._failed("remote",o,ce.causes.INTERNAL_ERROR),!1):(this._dialog=T,!0)}},{key:"_receiveReinvite",value:function(o){var s=this;K.debug("receiveReinvite()");var r=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0,d={request:o,callback:void 0,reject:_.bind(this)},h=!1;function _(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};h=!0;var E=T.status_code||403,y=T.reason_phrase||"",C=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));o.reply(E,y,C)}if(this.emit("reinvite",d),h)return;if(this._late_sdp=!1,!o.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._createLocalDescription("offer",s._rtcOfferConstraints)}).then(function(T){g.call(s,T)}).catch(function(){o.reply(500)});return}if(r!=="application/sdp"){K.debug("invalid Content-Type"),o.reply(415);return}this._processInDialogSdpOffer(o).then(function(T){s._status!==Q.STATUS_TERMINATED&&g.call(s,T)}).catch(function(T){K.warn(T)});function g(T){var E=this,y=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(o,y),this._late_sdp&&(T=this._mangleOffer(T)),o.reply(200,null,y,T,function(){E._status=Q.STATUS_WAITING_FOR_ACK,E._setInvite2xxTimer(o,T),E._setACKTimer()}),typeof d.callback=="function"&&d.callback()}}},{key:"_receiveUpdate",value:function(o){var s=this;K.debug("receiveUpdate()");var r=o.hasHeader("Content-Type")?o.getHeader("Content-Type").toLowerCase():void 0,d={request:o,callback:void 0,reject:_.bind(this)},h=!1;function _(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};h=!0;var E=T.status_code||403,y=T.reason_phrase||"",C=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));o.reply(E,y,C)}if(this.emit("update",d),h)return;if(!o.body){g.call(this,null);return}if(r!=="application/sdp"){K.debug("invalid Content-Type"),o.reply(415);return}this._processInDialogSdpOffer(o).then(function(T){s._status!==Q.STATUS_TERMINATED&&g.call(s,T)}).catch(function(T){K.warn(T)});function g(T){var E=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(o,E),o.reply(200,null,E,T),typeof d.callback=="function"&&d.callback()}}},{key:"_processInDialogSdpOffer",value:function(o){var s=this;K.debug("_processInDialogSdpOffer()");var r=o.parseSDP(),d=!1,h=_s(r.media),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;if(Bl.indexOf(g.type)!==-1){var T=g.direction||r.direction||"sendrecv";if(T==="sendonly"||T==="inactive")d=!0;else{d=!1;break}}}}catch(C){h.e(C)}finally{h.f()}var E={originator:"remote",type:"offer",sdp:o.body};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(s._status===Q.STATUS_TERMINATED)throw new Error("terminated");return s._connection.setRemoteDescription(y).catch(function(C){throw o.reply(488),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',C),s.emit("peerconnection:setremotedescriptionfailed",C),C})}).then(function(){if(s._status===Q.STATUS_TERMINATED)throw new Error("terminated");s._remoteHold===!0&&d===!1?(s._remoteHold=!1,s._onunhold("remote")):s._remoteHold===!1&&d===!0&&(s._remoteHold=!0,s._onhold("remote"))}).then(function(){if(s._status===Q.STATUS_TERMINATED)throw new Error("terminated");return s._createLocalDescription("answer",s._rtcAnswerConstraints).catch(function(C){throw o.reply(500),K.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',C),C})}).catch(function(C){K.warn("_processInDialogSdpOffer() failed [error: %o]",C)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(o){var s=this;if(K.debug("receiveRefer()"),!o.refer_to){K.debug("no Refer-To header field present in REFER"),o.reply(400);return}if(o.refer_to.uri.scheme!==ce.SIP){K.debug("Refer-To header field points to a non-SIP URI scheme"),o.reply(416);return}o.reply(202);var r=new fp(this,o.cseq);K.debug('emit "refer"'),this.emit("refer",{request:o,accept:function(g,T){d.call(s,g,T)},reject:function(){h.call(s)}});function d(_){var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(_=typeof _=="function"?_:null,this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;var T=new n(this._ua);if(T.on("progress",function(y){var C=y.response;r.notify(C.status_code,C.reason_phrase)}),T.on("accepted",function(y){var C=y.response;r.notify(C.status_code,C.reason_phrase)}),T.on("_failed",function(y){var C=y.message,A=y.cause;C?r.notify(C.status_code,C.reason_phrase):r.notify(487,A)}),o.refer_to.uri.hasHeader("replaces")){var E=decodeURIComponent(o.refer_to.uri.getHeader("replaces"));g.extraHeaders=Ve.cloneArray(g.extraHeaders),g.extraHeaders.push("Replaces: ".concat(E))}T.connect(o.refer_to.uri.toAor(),g,_)}function h(){r.notify(603)}}},{key:"_receiveNotify",value:function(o){switch(K.debug("receiveNotify()"),o.event||o.reply(400),o.event.event){case"refer":{var s,r;if(o.event.params&&o.event.params.id)s=o.event.params.id,r=this._referSubscribers[s];else if(Object.keys(this._referSubscribers).length===1)r=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{o.reply(400,"Missing event id parameter");return}if(!r){o.reply(481,"Subscription does not exist");return}r.receiveNotify(o),o.reply(200);break}default:o.reply(489)}}},{key:"_receiveReplaces",value:function(o){var s=this;K.debug("receiveReplaces()");function r(h){var _=this;if(this._status!==Q.STATUS_WAITING_FOR_ACK&&this._status!==Q.STATUS_CONFIRMED)return!1;var g=new n(this._ua);g.on("confirmed",function(){_.terminate()}),g.init_incoming(o,h)}function d(){K.debug("Replaced INVITE rejected by the user"),o.reply(486)}this.emit("replaces",{request:o,accept:function(_){r.call(s,_)},reject:function(){d.call(s)}})}},{key:"_sendInitialRequest",value:function(o,s,r){var d=this,h=new cp(this._ua,this._request,{onRequestTimeout:function(){d.onRequestTimeout()},onTransportError:function(){d.onTransportError()},onAuthenticated:function(g){d._request=g},onReceiveResponse:function(g){d._receiveInviteResponse(g)}});Promise.resolve().then(function(){if(r)return r;if(o.audio||o.video)return d._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(o).catch(function(_){throw d._status===Q.STATUS_TERMINATED?new Error("terminated"):(d._failed("local",null,ce.causes.USER_DENIED_MEDIA_ACCESS),K.warn('emit "getusermediafailed" [error:%o]',_),d.emit("getusermediafailed",_),_)})}).then(function(_){if(d._status===Q.STATUS_TERMINATED)throw new Error("terminated");return d._localMediaStream=_,_&&_.getTracks().forEach(function(g){d._connection.addTrack(g,_)}),d._connecting(d._request),d._createLocalDescription("offer",s).catch(function(g){throw d._failed("local",null,ce.causes.WEBRTC_ERROR),g})}).then(function(_){if(d._is_canceled||d._status===Q.STATUS_TERMINATED)throw new Error("terminated");d._request.body=_,d._status=Q.STATUS_INVITE_SENT,K.debug('emit "sending" [request:%o]',d._request),d.emit("sending",{request:d._request}),h.send()}).catch(function(_){d._status!==Q.STATUS_TERMINATED&&K.warn(_)})}},{key:"_getDTMFRTPSender",value:function(){var o=this._connection.getSenders().find(function(s){return s.track&&s.track.kind==="audio"});if(!(o&&o.dtmf)){K.warn("sendDTMF() | no local audio track to send DTMF with");return}return o.dtmf}},{key:"_receiveInviteResponse",value:function(o){var s=this;if(K.debug("receiveInviteResponse()"),this._dialog&&o.status_code>=200&&o.status_code<=299)if(this._dialog.id.call_id===o.call_id&&this._dialog.id.local_tag===o.from_tag&&this._dialog.id.remote_tag===o.to_tag){this.sendRequest(ce.ACK);return}else{var r=new Vl(this,o,"UAC");if(r.error!==void 0){K.debug(r.error);return}this.sendRequest(ce.ACK),this.sendRequest(ce.BYE);return}if(this._is_canceled){o.status_code>=100&&o.status_code<200?this._request.cancel(this._cancel_reason):o.status_code>=200&&o.status_code<299&&this._acceptAndTerminate(o);return}if(!(this._status!==Q.STATUS_INVITE_SENT&&this._status!==Q.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(o.status_code):this._status=Q.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(o.status_code):{if(!o.to_tag){K.debug("1xx response received without to tag");break}if(o.hasHeader("contact")&&!this._createDialog(o,"UAC",!0))break;if(this._status=Q.STATUS_1XX_RECEIVED,!o.body){this._progress("remote",o);break}var d={originator:"remote",type:"answer",sdp:o.body};K.debug('emit "sdp"'),this.emit("sdp",d);var h=new RTCSessionDescription({type:"answer",sdp:d.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return s._connection.setRemoteDescription(h)}).then(function(){return s._progress("remote",o)}).catch(function(E){K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),s.emit("peerconnection:setremotedescriptionfailed",E)});break}case/^2[0-9]{2}$/.test(o.status_code):{if(this._status=Q.STATUS_CONFIRMED,!o.body){this._acceptAndTerminate(o,400,ce.causes.MISSING_SDP),this._failed("remote",o,ce.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(o,"UAC"))break;var _={originator:"remote",type:"answer",sdp:o.body};K.debug('emit "sdp"'),this.emit("sdp",_);var g=new RTCSessionDescription({type:"answer",sdp:_.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(s._connection.signalingState==="stable")return s._connection.createOffer(s._rtcOfferConstraints).then(function(E){return s._connection.setLocalDescription(E)}).catch(function(E){s._acceptAndTerminate(o,500,E.toString()),s._failed("local",o,ce.causes.WEBRTC_ERROR)})}).then(function(){s._connection.setRemoteDescription(g).then(function(){s._handleSessionTimersInIncomingResponse(o),s._accepted("remote",o),s.sendRequest(ce.ACK),s._confirmed("local",null)}).catch(function(E){s._acceptAndTerminate(o,488,"Not Acceptable Here"),s._failed("remote",o,ce.causes.BAD_MEDIA_DESCRIPTION),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),s.emit("peerconnection:setremotedescriptionfailed",E)})});break}default:{var T=Ve.sipErrorCause(o.status_code);this._failed("remote",o,T)}}}},{key:"_sendReinvite",value:function(){var o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};K.debug("sendReinvite()");var r=Ve.cloneArray(s.extraHeaders),d=Ve.cloneObject(s.eventHandlers),h=s.rtcOfferConstraints||this._rtcOfferConstraints||null,_=!1;r.push("Contact: ".concat(this._contact)),r.push("Content-Type: application/sdp"),this._sessionTimers.running&&r.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return o._createLocalDescription("offer",h)}).then(function(E){E=o._mangleOffer(E);var y={originator:"local",type:"offer",sdp:E};K.debug('emit "sdp"'),o.emit("sdp",y),o.sendRequest(ce.INVITE,{extraHeaders:r,body:E,eventHandlers:{onSuccessResponse:function(A){g.call(o,A),_=!0},onErrorResponse:function(A){T.call(o,A)},onTransportError:function(){o.onTransportError()},onRequestTimeout:function(){o.onRequestTimeout()},onDialogError:function(){o.onDialogError()}}})}).catch(function(){T()});function g(E){var y=this;if(this._status!==Q.STATUS_TERMINATED&&(this.sendRequest(ce.ACK),!_)){if(this._handleSessionTimersInIncomingResponse(E),E.body){if(!E.hasHeader("Content-Type")||E.getHeader("Content-Type").toLowerCase()!=="application/sdp"){T.call(this);return}}else{T.call(this);return}var C={originator:"remote",type:"answer",sdp:E.body};K.debug('emit "sdp"'),this.emit("sdp",C);var A=new RTCSessionDescription({type:"answer",sdp:C.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return y._connection.setRemoteDescription(A)}).then(function(){d.succeeded&&d.succeeded(E)}).catch(function(I){T.call(y),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 o=this,s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};K.debug("sendUpdate()");var r=Ve.cloneArray(s.extraHeaders),d=Ve.cloneObject(s.eventHandlers),h=s.rtcOfferConstraints||this._rtcOfferConstraints||null,_=s.sdpOffer||!1,g=!1;r.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&r.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),_?(r.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return o._createLocalDescription("offer",h)}).then(function(y){y=o._mangleOffer(y);var C={originator:"local",type:"offer",sdp:y};K.debug('emit "sdp"'),o.emit("sdp",C),o.sendRequest(ce.UPDATE,{extraHeaders:r,body:y,eventHandlers:{onSuccessResponse:function(I){T.call(o,I),g=!0},onErrorResponse:function(I){E.call(o,I)},onTransportError:function(){o.onTransportError()},onRequestTimeout:function(){o.onRequestTimeout()},onDialogError:function(){o.onDialogError()}}})}).catch(function(){E.call(o)})):this.sendRequest(ce.UPDATE,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(C){T.call(o,C)},onErrorResponse:function(C){E.call(o,C)},onTransportError:function(){o.onTransportError()},onRequestTimeout:function(){o.onRequestTimeout()},onDialogError:function(){o.onDialogError()}}});function T(y){var C=this;if(this._status!==Q.STATUS_TERMINATED&&!g)if(this._handleSessionTimersInIncomingResponse(y),_){if(y.body){if(!y.hasHeader("Content-Type")||y.getHeader("Content-Type").toLowerCase()!=="application/sdp"){E.call(this);return}}else{E.call(this);return}var A={originator:"remote",type:"answer",sdp:y.body};K.debug('emit "sdp"'),this.emit("sdp",A);var I=new RTCSessionDescription({type:"answer",sdp:A.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return C._connection.setRemoteDescription(I)}).then(function(){d.succeeded&&d.succeeded(y)}).catch(function(H){E.call(C),K.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',H),C.emit("peerconnection:setremotedescriptionfailed",H)})}else d.succeeded&&d.succeeded(y)}function E(y){d.failed&&d.failed(y)}}},{key:"_acceptAndTerminate",value:function(o,s,r){K.debug("acceptAndTerminate()");var d=[];s&&(r=r||ce.REASON_PHRASE[s]||"",d.push("Reason: SIP ;cause=".concat(s,'; text="').concat(r,'"'))),(this._dialog||this._createDialog(o,"UAC"))&&(this.sendRequest(ce.ACK),this.sendRequest(ce.BYE,{extraHeaders:d})),this._status=Q.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(o){if(!this._localHold&&!this._remoteHold)return o;if(o=Oc.parse(o),this._localHold&&!this._remoteHold){K.debug("mangleOffer() | me on hold, mangling offer");var s=_s(o.media),r;try{for(s.s();!(r=s.n()).done;){var d=r.value;Bl.indexOf(d.type)!==-1&&(d.direction?d.direction==="sendrecv"?d.direction="sendonly":d.direction==="recvonly"&&(d.direction="inactive"):d.direction="sendonly")}}catch(C){s.e(C)}finally{s.f()}}else if(this._localHold&&this._remoteHold){K.debug("mangleOffer() | both on hold, mangling offer");var h=_s(o.media),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;Bl.indexOf(g.type)!==-1&&(g.direction="inactive")}}catch(C){h.e(C)}finally{h.f()}}else if(this._remoteHold){K.debug("mangleOffer() | remote on hold, mangling offer");var T=_s(o.media),E;try{for(T.s();!(E=T.n()).done;){var y=E.value;Bl.indexOf(y.type)!==-1&&(y.direction?y.direction==="sendrecv"?y.direction="recvonly":y.direction==="recvonly"&&(y.direction="inactive"):y.direction="recvonly")}}catch(C){T.e(C)}finally{T.f()}}return Oc.write(o)}},{key:"_setLocalMediaStatus",value:function(){var o=!0,s=!0;(this._localHold||this._remoteHold)&&(o=!1,s=!1),this._audioMuted&&(o=!1),this._videoMuted&&(s=!1),this._toggleMuteAudio(!o),this._toggleMuteVideo(!s)}},{key:"_handleSessionTimersInIncomingRequest",value:function(o,s){if(this._sessionTimers.enabled){var r;o.session_expires&&o.session_expires>=ce.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=o.session_expires,r=o.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,r="uas"),s.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(r)),this._sessionTimers.refresher=r==="uas",this._runSessionTimer()}}},{key:"_handleSessionTimersInIncomingResponse",value:function(o){if(this._sessionTimers.enabled){var s;o.session_expires&&o.session_expires>=ce.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=o.session_expires,s=o.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,s="uac"),this._sessionTimers.refresher=s==="uac",this._runSessionTimer()}}},{key:"_runSessionTimer",value:function(){var o=this,s=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){o._status!==Q.STATUS_TERMINATED&&o._isReadyToReOffer()&&(K.debug("runSessionTimer() | sending session refresh request"),o._sessionTimers.refreshMethod===ce.UPDATE?o._sendUpdate():o._sendReinvite())},s*500):this._sessionTimers.timer=setTimeout(function(){o._status!==Q.STATUS_TERMINATED&&(K.warn("runSessionTimer() | timer expired, terminating the session"),o.terminate({cause:ce.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},s*1100)}},{key:"_toggleMuteAudio",value:function(o){var s=this._connection.getSenders().filter(function(_){return _.track&&_.track.kind==="audio"}),r=_s(s),d;try{for(r.s();!(d=r.n()).done;){var h=d.value;h.track.enabled=!o}}catch(_){r.e(_)}finally{r.f()}}},{key:"_toggleMuteVideo",value:function(o){var s=this._connection.getSenders().filter(function(_){return _.track&&_.track.kind==="video"}),r=_s(s),d;try{for(r.s();!(d=r.n()).done;){var h=d.value;h.track.enabled=!o}}catch(_){r.e(_)}finally{r.f()}}},{key:"_newRTCSession",value:function(o,s){K.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:o,session:this,request:s})}},{key:"_connecting",value:function(o){K.debug("session connecting"),K.debug('emit "connecting"'),this.emit("connecting",{request:o})}},{key:"_progress",value:function(o,s){K.debug("session progress"),K.debug('emit "progress"'),this.emit("progress",{originator:o,response:s||null})}},{key:"_accepted",value:function(o,s){K.debug("session accepted"),this._start_time=new Date,K.debug('emit "accepted"'),this.emit("accepted",{originator:o,response:s||null})}},{key:"_confirmed",value:function(o,s){K.debug("session confirmed"),this._is_confirmed=!0,K.debug('emit "confirmed"'),this.emit("confirmed",{originator:o,ack:s||null})}},{key:"_ended",value:function(o,s,r){K.debug("session ended"),this._end_time=new Date,this._close(),K.debug('emit "ended"'),this.emit("ended",{originator:o,message:s||null,cause:r})}},{key:"_failed",value:function(o,s,r){K.debug("session failed"),K.debug('emit "_failed"'),this.emit("_failed",{originator:o,message:s||null,cause:r}),this._close(),K.debug('emit "failed"'),this.emit("failed",{originator:o,message:s||null,cause:r})}},{key:"_onhold",value:function(o){K.debug("session onhold"),this._setLocalMediaStatus(),K.debug('emit "hold"'),this.emit("hold",{originator:o})}},{key:"_onunhold",value:function(o){K.debug("session onunhold"),this._setLocalMediaStatus(),K.debug('emit "unhold"'),this.emit("unhold",{originator:o})}},{key:"_onmute",value:function(o){var s=o.audio,r=o.video;K.debug("session onmute"),this._setLocalMediaStatus(),K.debug('emit "muted"'),this.emit("muted",{audio:s,video:r})}},{key:"_onunmute",value:function(o){var s=o.audio,r=o.video;K.debug("session onunmute"),this._setLocalMediaStatus(),K.debug('emit "unmuted"'),this.emit("unmuted",{audio:s,video:r})}},{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(o){this._data=o}},{key:"status",get:function(){return this._status}}]),n}(ap);function Ra(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ra=function(n){return typeof n}:Ra=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Ra(c)}function _p(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Pc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function pp(c,t,n){return t&&Pc(c.prototype,t),n&&Pc(c,n),c}function mp(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&mu(c,t)}function mu(c,t){return mu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},mu(c,t)}function gp(c){var t=Ep();return function(){var a=Ma(c),o;if(t){var s=Ma(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return Tp(this,o)}}function Tp(c,t){return t&&(Ra(t)==="object"||typeof t=="function")?t:vp(c)}function vp(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Ep(){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 Ma(c){return Ma=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Ma(c)}var Sp=ft.EventEmitter,yp=ht,Io=lt,Cp=Ss,ki=bt(),Ap=dl,xc=Ws,Rp=Ks(),Gl=new yp("Message"),Ip=function(c){mp(n,c);var t=gp(n);function n(a){var o;return _p(this,n),o=t.call(this),o._ua=a,o._request=null,o._closed=!1,o._direction=null,o._local_identity=null,o._remote_identity=null,o._is_replied=!1,o._data={},o}return pp(n,[{key:"send",value:function(o,s){var r=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},h=o;if(o===void 0||s===void 0)throw new TypeError("Not enough arguments");if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(h));var _=ki.cloneArray(d.extraHeaders),g=ki.cloneObject(d.eventHandlers),T=d.contentType||"text/plain",E={};d.fromUserName&&(E.from_uri=new Rp("sip",d.fromUserName,this._ua.configuration.uri.host),_.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),d.fromDisplayName&&(E.from_display_name=d.fromDisplayName);for(var y in g)Object.prototype.hasOwnProperty.call(g,y)&&this.on(y,g[y]);_.push("Content-Type: ".concat(T)),this._request=new Cp.OutgoingRequest(Io.MESSAGE,o,this._ua,E,_),s&&(this._request.body=s);var C=new Ap(this._ua,this._request,{onRequestTimeout:function(){r._onRequestTimeout()},onTransportError:function(){r._onTransportError()},onReceiveResponse:function(I){r._receiveResponse(I)}});this._newMessage("local",this._request),C.send()}},{key:"init_incoming",value:function(o){this._request=o,this._newMessage("remote",o),this._is_replied||(this._is_replied=!0,o.reply(200)),this._close()}},{key:"accept",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=ki.cloneArray(o.extraHeaders),r=o.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,s,r)}},{key:"reject",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=o.status_code||480,r=o.reason_phrase,d=ki.cloneArray(o.extraHeaders),h=o.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(s<300||s>=700)throw new TypeError("Invalid status_code: ".concat(s));this._is_replied=!0,this._request.reply(s,r,d,h)}},{key:"_receiveResponse",value:function(o){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):this._succeeded("remote",o);break;default:{var s=ki.sipErrorCause(o.status_code);this._failed("remote",o,s);break}}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,Io.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,Io.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newMessage",value:function(o,s){o==="remote"?(this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from):o==="local"&&(this._direction="outgoing",this._local_identity=s.from,this._remote_identity=s.to),this._ua.newMessage(this,{originator:o,message:this,request:s})}},{key:"_failed",value:function(o,s,r){Gl.debug("MESSAGE failed"),this._close(),Gl.debug('emit "failed"'),this.emit("failed",{originator:o,response:s||null,cause:r})}},{key:"_succeeded",value:function(o,s){Gl.debug("MESSAGE succeeded"),this._close(),Gl.debug('emit "succeeded"'),this.emit("succeeded",{originator:o,response:s})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}]),n}(Sp);function Ia(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Ia=function(n){return typeof n}:Ia=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Ia(c)}function bp(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function kc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function wp(c,t,n){return t&&kc(c.prototype,t),n&&kc(c,n),c}function Op(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&gu(c,t)}function gu(c,t){return gu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},gu(c,t)}function Dp(c){var t=Pp();return function(){var a=La(c),o;if(t){var s=La(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return Np(this,o)}}function Np(c,t){return t&&(Ia(t)==="object"||typeof t=="function")?t:Up(c)}function Up(c){if(c===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function Pp(){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(n){return n.__proto__||Object.getPrototypeOf(n)},La(c)}var xp=ft.EventEmitter,kp=ht,bo=lt,Mp=Ss,Mi=bt(),Lp=dl,Mc=Ws,Wl=new kp("Options"),$p=function(c){Op(n,c);var t=Dp(n);function n(a){var o;return bp(this,n),o=t.call(this),o._ua=a,o._request=null,o._closed=!1,o._direction=null,o._local_identity=null,o._remote_identity=null,o._is_replied=!1,o._data={},o}return wp(n,[{key:"send",value:function(o,s){var r=this,d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},h=o;if(o===void 0)throw new TypeError("A target is required for OPTIONS");if(o=this._ua.normalizeTarget(o),!o)throw new TypeError("Invalid target: ".concat(h));var _=Mi.cloneArray(d.extraHeaders),g=Mi.cloneObject(d.eventHandlers),T=d.contentType||"application/sdp";for(var E in g)Object.prototype.hasOwnProperty.call(g,E)&&this.on(E,g[E]);_.push("Content-Type: ".concat(T)),this._request=new Mp.OutgoingRequest(bo.OPTIONS,o,this._ua,null,_),s&&(this._request.body=s);var y=new Lp(this._ua,this._request,{onRequestTimeout:function(){r._onRequestTimeout()},onTransportError:function(){r._onTransportError()},onReceiveResponse:function(A){r._receiveResponse(A)}});this._newOptions("local",this._request),y.send()}},{key:"init_incoming",value:function(o){this._request=o,this._newOptions("remote",o),this._is_replied||(this._is_replied=!0,o.reply(200)),this._close()}},{key:"accept",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=Mi.cloneArray(o.extraHeaders),r=o.body;if(this._direction!=="incoming")throw new Mc.NotSupportedError('"accept" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");this._is_replied=!0,this._request.reply(200,null,s,r)}},{key:"reject",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=o.status_code||480,r=o.reason_phrase,d=Mi.cloneArray(o.extraHeaders),h=o.body;if(this._direction!=="incoming")throw new Mc.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(s<300||s>=700)throw new TypeError("Invalid status_code: ".concat(s));this._is_replied=!0,this._request.reply(s,r,d,h)}},{key:"_receiveResponse",value:function(o){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):this._succeeded("remote",o);break;default:{var s=Mi.sipErrorCause(o.status_code);this._failed("remote",o,s);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(o,s){o==="remote"?(this._direction="incoming",this._local_identity=s.to,this._remote_identity=s.from):o==="local"&&(this._direction="outgoing",this._local_identity=s.from,this._remote_identity=s.to),this._ua.newOptions(this,{originator:o,message:this,request:s})}},{key:"_failed",value:function(o,s,r){Wl.debug("OPTIONS failed"),this._close(),Wl.debug('emit "failed"'),this.emit("failed",{originator:o,response:s||null,cause:r})}},{key:"_succeeded",value:function(o,s){Wl.debug("OPTIONS succeeded"),this._close(),Wl.debug('emit "succeeded"'),this.emit("succeeded",{originator:o,response:s})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}]),n}(xp),xu={},Hp=ht,wo=bt(),Fp=os(),Li=new Hp("Socket");xu.isSocket=function(c){if(Array.isArray(c))return!1;if(typeof c>"u")return Li.warn("undefined JsSIP.Socket instance"),!1;try{if(!wo.isString(c.url))throw Li.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!wo.isString(c.via_transport))throw Li.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(Fp.parse(c.sip_uri,"SIP_URI")===-1)throw Li.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch{return!1}try{["connect","disconnect","send"].forEach(function(t){if(!wo.isFunction(c[t]))throw Li.warn("missing or invalid JsSIP.Socket method: ".concat(t)),new Error("Missing or invalid JsSIP.Socket method: ".concat(t))})}catch{return!1}return!0};function jp(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Lc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function qp(c,t,n){return t&&Lc(c.prototype,t),n&&Lc(c,n),c}var Vp=ht,Bp=xu,$c=lt,Nt=new Vp("Transport"),qt={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}},Gp=function(){function c(t){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:qt.recovery_options;jp(this,c),Nt.debug("new()"),this.status=qt.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(a){Nt.warn("cannot use TextDecoder: ".concat(a))}if(typeof t>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(a){if(!Bp.isSocket(a.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(a.weight&&!Number(a.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:a.socket,weight:a.weight||0,status:qt.SOCKET_STATUS_READY})},this),this._getSocket()}return qp(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=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())}},{key:"disconnect",value:function(){Nt.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=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(n){if(Nt.debug("send()"),!this.isConnected())return Nt.warn("unable to send message, transport is not connected"),!1;var a=n.toString();return Nt.debug(`sending message:
|
51
51
|
|
52
52
|
`.concat(a,`
|
53
53
|
`)),this.socket.send(a)}},{key:"isConnected",value:function(){return this.status===qt.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===qt.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var n=this;this.recover_attempts+=1;var a=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);a<this.recovery_options.min_interval?a=this.recovery_options.min_interval:a>this.recovery_options.max_interval&&(a=this.recovery_options.max_interval),Nt.debug("reconnection attempt: ".concat(this.recover_attempts,". next connection attempt in ").concat(a," seconds")),this.recovery_timer=setTimeout(function(){!n.close_requested&&!(n.isConnected()||n.isConnecting())&&(n._getSocket(),n.connect())},a*1e3)}},{key:"_getSocket",value:function(){var n=[];if(this.sockets.forEach(function(o){o.status!==qt.SOCKET_STATUS_ERROR&&(n.length===0?n.push(o):o.weight>n[0].weight?n=[o]:o.weight===n[0].weight&&n.push(o))}),n.length===0){this.sockets.forEach(function(o){o.status=qt.SOCKET_STATUS_READY}),this._getSocket();return}var a=Math.floor(Math.random()*n.length);this.socket=n[a].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=qt.STATUS_CONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(n,a,o){this.status=qt.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:n,code:a,reason:o}),!this.close_requested&&(this.sockets.forEach(function(s){this.socket===s.socket&&(s.status=qt.SOCKET_STATUS_ERROR)},this),this._reconnect(n))}},{key:"_onData",value:function(n){if(n===`\r
|
@@ -60,7 +60,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
60
60
|
`));this.ondata({transport:this,message:n})}},{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}}]),c}(),ih={};function Hc(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=Wp(c))||t&&c&&typeof c.length=="number"){n&&(c=n);var a=0,o=function(){};return{s:o,n:function(){return a>=c.length?{done:!0}:{done:!1,value:c[a++]}},e:function(_){throw _},f:o}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
61
61
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function Wp(c,t){if(c){if(typeof c=="string")return Fc(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Fc(c,t)}}function Fc(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}var Kp=ht,Tu=os(),vu=Ss,Kl=new Kp("Parser");ih.parseMessage=function(c,t){var n,a,o=c.indexOf(`\r
|
62
62
|
`);if(o===-1){Kl.warn("parseMessage() | no CRLF found, not a SIP message");return}var s=c.substring(0,o),r=Tu.parse(s,"Request_Response");if(r===-1){Kl.warn('parseMessage() | error parsing first line of SIP message: "'.concat(s,'"'));return}else r.status_code?(n=new vu.IncomingResponse,n.status_code=r.status_code,n.reason_phrase=r.reason_phrase):(n=new vu.IncomingRequest(t),n.method=r.method,n.ruri=r.uri);n.data=c;for(var d=o+2;;){if(o=Yp(c,d),o===-2){a=d+2;break}else if(o===-1){Kl.warn("parseMessage() | malformed message");return}if(r=Jp(n,c,d,o),r!==!0){Kl.warn("parseMessage() |",r.error);return}d=o+2}if(n.hasHeader("content-length")){var h=n.getHeader("content-length");n.body=c.substr(a,h)}else n.body=c.substring(a);return n};function Yp(c,t){var n=t,a=0,o=0;if(c.substring(n,n+2).match(/(^\r\n)/))return-2;for(;a===0;){if(o=c.indexOf(`\r
|
63
|
-
`,n),o===-1)return o;!c.substring(o+2,o+4).match(/(^\r\n)/)&&c.charAt(o+2).match(/(^\s+)/)?n=o+2:a=o}return a}function Jp(c,t,n,a){var o,s=t.indexOf(":",n),r=t.substring(n,s).trim(),d=t.substring(s+1,a).trim();switch(r.toLowerCase()){case"via":case"v":c.addHeader("via",d),c.getHeaders("via").length===1?(o=c.parseHeader("Via"),o&&(c.via=o,c.via_branch=o.branch)):o=0;break;case"from":case"f":c.setHeader("from",d),o=c.parseHeader("from"),o&&(c.from=o,c.from_tag=o.getParam("tag"));break;case"to":case"t":c.setHeader("to",d),o=c.parseHeader("to"),o&&(c.to=o,c.to_tag=o.getParam("tag"));break;case"record-route":if(o=Tu.parse(d,"Record_Route"),o===-1)o=void 0;else{var h=Hc(o),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;c.addHeader("record-route",d.substring(g.possition,g.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=g.parsed}}catch(
|
63
|
+
`,n),o===-1)return o;!c.substring(o+2,o+4).match(/(^\r\n)/)&&c.charAt(o+2).match(/(^\s+)/)?n=o+2:a=o}return a}function Jp(c,t,n,a){var o,s=t.indexOf(":",n),r=t.substring(n,s).trim(),d=t.substring(s+1,a).trim();switch(r.toLowerCase()){case"via":case"v":c.addHeader("via",d),c.getHeaders("via").length===1?(o=c.parseHeader("Via"),o&&(c.via=o,c.via_branch=o.branch)):o=0;break;case"from":case"f":c.setHeader("from",d),o=c.parseHeader("from"),o&&(c.from=o,c.from_tag=o.getParam("tag"));break;case"to":case"t":c.setHeader("to",d),o=c.parseHeader("to"),o&&(c.to=o,c.to_tag=o.getParam("tag"));break;case"record-route":if(o=Tu.parse(d,"Record_Route"),o===-1)o=void 0;else{var h=Hc(o),_;try{for(h.s();!(_=h.n()).done;){var g=_.value;c.addHeader("record-route",d.substring(g.possition,g.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=g.parsed}}catch(C){h.e(C)}finally{h.f()}}break;case"call-id":case"i":c.setHeader("call-id",d),o=c.parseHeader("call-id"),o&&(c.call_id=d);break;case"contact":case"m":if(o=Tu.parse(d,"Contact"),o===-1)o=void 0;else{var T=Hc(o),E;try{for(T.s();!(E=T.n()).done;){var y=E.value;c.addHeader("contact",d.substring(y.possition,y.offset)),c.headers.Contact[c.getHeaders("contact").length-1].parsed=y.parsed}}catch(C){T.e(C)}finally{T.f()}}break;case"content-length":case"l":c.setHeader("content-length",d),o=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",d),o=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",d),o=c.parseHeader("cseq"),o&&(c.cseq=o.value),c instanceof vu.IncomingResponse&&(c.method=o.method);break;case"max-forwards":c.setHeader("max-forwards",d),o=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",d),o=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",d),o=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",d),o=c.parseHeader("session-expires"),o&&(c.session_expires=o.expires,c.session_expires_refresher=o.refresher);break;case"refer-to":case"r":c.setHeader("refer-to",d),o=c.parseHeader("refer-to"),o&&(c.refer_to=o);break;case"replaces":c.setHeader("replaces",d),o=c.parseHeader("replaces"),o&&(c.replaces=o);break;case"event":case"o":c.setHeader("event",d),o=c.parseHeader("event"),o&&(c.event=o);break;default:c.addHeader(r,d),o=0}return o===void 0?{error:'error parsing header "'.concat(r,'"')}:!0}function ba(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=zp(c))||t&&c&&typeof c.length=="number"){n&&(c=n);var a=0,o=function(){};return{s:o,n:function(){return a>=c.length?{done:!0}:{done:!1,value:c[a++]}},e:function(_){throw _},f:o}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
64
64
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function zp(c,t){if(c){if(typeof c=="string")return jc(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return jc(c,t)}}function jc(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}var Xp=ht,lh=lt,qc=Ss,ku=bt(),Mu=new Xp("sanityCheck"),Qp=[om],Zp=[sm,nm,rm,im],em=[lm,am],He,rs,ah,tm=function(c,t,n){He=c,rs=t,ah=n;var a=ba(Qp),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;if(s()===!1)return!1}}catch(E){a.e(E)}finally{a.f()}if(He instanceof qc.IncomingRequest){var r=ba(Zp),d;try{for(r.s();!(d=r.n()).done;){var h=d.value;if(h()===!1)return!1}}catch(E){r.e(E)}finally{r.f()}}else if(He instanceof qc.IncomingResponse){var _=ba(em),g;try{for(_.s();!(g=_.n()).done;){var T=g.value;if(T()===!1)return!1}}catch(E){_.e(E)}finally{_.f()}}return!0};function sm(){if(He.s("to").uri.scheme!=="sip")return tl(416),!1}function nm(){if(!He.to_tag&&He.call_id.substr(0,5)===rs.configuration.jssip_id)return tl(482),!1}function rm(){var c=ku.str_utf8_length(He.body),t=He.getHeader("content-length");if(c<t)return tl(400),!1}function im(){var c=He.from_tag,t=He.call_id,n=He.cseq,a;if(!He.to_tag)if(He.method===lh.INVITE){if(rs._transactions.ist[He.via_branch])return!1;for(var o in rs._transactions.ist)if(Object.prototype.hasOwnProperty.call(rs._transactions.ist,o)&&(a=rs._transactions.ist[o],a.request.from_tag===c&&a.request.call_id===t&&a.request.cseq===n))return tl(482),!1}else{if(rs._transactions.nist[He.via_branch])return!1;for(var s in rs._transactions.nist)if(Object.prototype.hasOwnProperty.call(rs._transactions.nist,s)&&(a=rs._transactions.nist[s],a.request.from_tag===c&&a.request.call_id===t&&a.request.cseq===n))return tl(482),!1}}function lm(){if(He.getHeaders("via").length>1)return Mu.debug("more than one Via header field present in the response, dropping the response"),!1}function am(){var c=ku.str_utf8_length(He.body),t=He.getHeader("content-length");if(c<t)return Mu.debug("message body length is lower than the value in Content-Length header field, dropping the response"),!1}function om(){for(var c=["from","to","call_id","cseq","via"],t=0,n=c;t<n.length;t++){var a=n[t];if(!He.hasHeader(a))return Mu.debug("missing mandatory header field : ".concat(a,", dropping the response")),!1}}function tl(c){var t=He.getHeaders("via"),n,a="SIP/2.0 ".concat(c," ").concat(lh.REASON_PHRASE[c],`\r
|
65
65
|
`),o=ba(t),s;try{for(o.s();!(s=o.n()).done;){var r=s.value;a+="Via: ".concat(r,`\r
|
66
66
|
`)}}catch(d){o.e(d)}finally{o.f()}n=He.getHeader("To"),He.to_tag||(n+=";tag=".concat(ku.newTag())),a+="To: ".concat(n,`\r
|
@@ -69,10 +69,10 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
69
69
|
`),a+="CSeq: ".concat(He.cseq," ").concat(He.method,`\r
|
70
70
|
`),a+=`\r
|
71
71
|
`,ah.send(a)}var Lu={};function Vc(c,t){var n;if(typeof Symbol>"u"||c[Symbol.iterator]==null){if(Array.isArray(c)||(n=um(c))||t&&c&&typeof c.length=="number"){n&&(c=n);var a=0,o=function(){};return{s:o,n:function(){return a>=c.length?{done:!0}:{done:!1,value:c[a++]}},e:function(_){throw _},f:o}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
72
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function um(c,t){if(c){if(typeof c=="string")return Bc(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Bc(c,t)}}function Bc(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}var fr=bt(),yn=lt,Oo=os(),Gc=Ks(),Do=xu,No=Ws;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:yn.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:yn.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:yn.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:"".concat(fr.createRandomToken(12),".invalid")};var Yl={mandatory:{sockets:function(t){var n=[];if(Do.isSocket(t))n.push({socket:t});else if(Array.isArray(t)&&t.length){var a=Vc(t),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;Object.prototype.hasOwnProperty.call(s,"socket")&&Do.isSocket(s.socket)?n.push(s):Do.isSocket(s)&&n.push({socket:s})}}catch(r){a.e(r)}finally{a.f()}}else return;return n},uri:function(t){/^sip:/i.test(t)||(t="".concat(yn.SIP,":").concat(t));var n=Gc.parse(t);if(n)return n.user?n:void 0}},optional:{authorization_user:function(t){if(Oo.parse('"'.concat(t,'"'),"quoted_string")!==-1)return t},authorization_jwt:function(t){if(typeof t=="string")return t},user_agent:function(t){if(typeof t=="string")return t},connection_recovery_max_interval:function(t){if(fr.isDecimal(t)){var n=Number(t);if(n>0)return n}},connection_recovery_min_interval:function(t){if(fr.isDecimal(t)){var n=Number(t);if(n>0)return n}},contact_uri:function(t){if(typeof t=="string"){var n=Oo.parse(t,"SIP_URI");if(n!==-1)return n}},display_name:function(t){return t},instance_id:function(t){if(/^uuid:/i.test(t)&&(t=t.substr(5)),Oo.parse(t,"uuid")!==-1)return t},no_answer_timeout:function(t){if(fr.isDecimal(t)){var n=Number(t);if(n>0)return n}},session_timers:function(t){if(typeof t=="boolean")return t},session_timers_refresh_method:function(t){if(typeof t=="string"&&(t=t.toUpperCase(),t===yn.INVITE||t===yn.UPDATE))return t},session_timers_force_refresher:function(t){if(typeof t=="boolean")return t},password:function(t){return String(t)},realm:function(t){return String(t)},ha1:function(t){return String(t)},register:function(t){if(typeof t=="boolean")return t},register_expires:function(t){if(fr.isDecimal(t)){var n=Number(t);if(n>0)return n}},registrar_server:function(t){/^sip:/i.test(t)||(t="".concat(yn.SIP,":").concat(t));var n=Gc.parse(t);if(n)return n.user?void 0:n},use_preloaded_route:function(t){if(typeof t=="boolean")return t},extra_headers:function(t){var n=[];if(Array.isArray(t)&&t.length){var a=Vc(t),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;typeof s=="string"&&n.push(s)}}catch(r){a.e(r)}finally{a.f()}}else return;return n}}};Lu.load=function(c,t){for(var n in Yl.mandatory)if(t.hasOwnProperty(n)){var a=t[n],o=Yl.mandatory[n](a);if(o!==void 0)c[n]=o;else throw new No.ConfigurationError(n,a)}else throw new No.ConfigurationError(n);for(var s in Yl.optional)if(t.hasOwnProperty(s)){var r=t[s];if(fr.isEmpty(r))continue;var d=Yl.optional[s](r);if(d!==void 0)c[s]=d;else throw new No.ConfigurationError(s,r)}};function wa(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?wa=function(n){return typeof n}:wa=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},wa(c)}function cm(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Wc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Kc(c,t,n){return t&&Wc(c.prototype,t),n&&Wc(c,n),c}function fm(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&Eu(c,t)}function Eu(c,t){return Eu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},Eu(c,t)}function hm(c){var t=_m();return function(){var a=$a(c),o;if(t){var s=$a(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return dm(this,o)}}function dm(c,t){return t&&(wa(t)==="object"||typeof t=="function")?t:oh(c)}function oh(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 $a(c){return $a=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},$a(c)}var pm=ft.EventEmitter,mm=ht,pt=lt,gm=r_,Yc=dp,Jc=Ip,zc=$p,Uo=hl,Tm=Gp,Jl=bt(),vm=Ws,Em=Ks(),Sm=ih,Po=Ss,ym=tm,xo=Lu,je=new mm("UA"),Tt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},Am=function(c){fm(n,c);var t=hm(n);Kc(n,null,[{key:"C",get:function(){return Tt}}]);function n(a){var o;if(cm(this,n),je.debug("new() [configuration:%o]",a),o=t.call(this),o._cache={credentials:{}},o._configuration=Object.assign({},xo.settings),o._dynConfiguration={},o._dialogs={},o._applicants={},o._sessions={},o._transport=null,o._contact=null,o._status=Tt.STATUS_INIT,o._error=null,o._transactions={nist:{},nict:{},ist:{},ict:{}},o._data={},o._closeTimer=null,a===void 0)throw new TypeError("Not enough arguments");try{o._loadConfig(a)}catch(s){throw o._status=Tt.STATUS_NOT_READY,o._error=Tt.CONFIGURATION_ERROR,s}return o._registrator=new gm(oh(o)),o}return Kc(n,[{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(o){je.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(o)}},{key:"registrator",value:function(){return this._registrator}},{key:"isRegistered",value:function(){return this._registrator.registered}},{key:"isConnected",value:function(){return this._transport.isConnected()}},{key:"call",value:function(o,s){je.debug("call()");var r=new Yc(this);return r.connect(o,s),r}},{key:"sendMessage",value:function(o,s,r){je.debug("sendMessage()");var d=new Jc(this);return d.send(o,s,r),d}},{key:"sendOptions",value:function(o,s,r){je.debug("sendOptions()");var d=new zc(this);return d.send(o,s,r),d}},{key:"terminateSessions",value:function(o){je.debug("terminateSessions()");for(var s in this._sessions)this._sessions[s].isEnded()||this._sessions[s].terminate(o)}},{key:"stop",value:function(){var o=this;if(je.debug("stop()"),this._dynConfiguration={},this._status===Tt.STATUS_USER_CLOSED){je.debug("UA already closed");return}this._registrator.close();var s=Object.keys(this._sessions).length;for(var r in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,r)){je.debug("closing session ".concat(r));try{this._sessions[r].terminate()}catch{}}for(var d in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,d))try{this._applicants[d].close()}catch{}this._status=Tt.STATUS_USER_CLOSED;var h=Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length;h===0&&s===0?this._transport.disconnect():this._closeTimer=setTimeout(function(){o._closeTimer=null,o._transport.disconnect()},2e3)}},{key:"normalizeTarget",value:function(o){return Jl.normalizeTarget(o,this._configuration.hostport_params)}},{key:"get",value:function(o){switch(o){case"authorization_user":return this._configuration.authorization_user;case"realm":return this._configuration.realm;case"ha1":return this._configuration.ha1;case"authorization_jwt":return this._configuration.authorization_jwt;default:je.warn('get() | cannot get "%s" parameter in runtime',o);return}}},{key:"set",value:function(o,s){switch(o){case"authorization_user":{this._configuration.authorization_user=String(s);break}case"password":{this._configuration.password=String(s);break}case"realm":{this._configuration.realm=String(s);break}case"ha1":{this._configuration.ha1=String(s),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(s);break}case"display_name":{this._configuration.display_name=s;break}default:return je.warn('set() | cannot set "%s" parameter in runtime',o),!1}return!0}},{key:"newTransaction",value:function(o){this._transactions[o.type][o.id]=o,this.emit("newTransaction",{transaction:o})}},{key:"destroyTransaction",value:function(o){delete this._transactions[o.type][o.id],this.emit("transactionDestroyed",{transaction:o})}},{key:"newDialog",value:function(o){this._dialogs[o.id]=o}},{key:"destroyDialog",value:function(o){delete this._dialogs[o.id]}},{key:"newMessage",value:function(o,s){this._applicants[o]=o,this.emit("newMessage",s)}},{key:"newOptions",value:function(o,s){this._applicants[o]=o,this.emit("newOptions",s)}},{key:"destroyMessage",value:function(o){delete this._applicants[o]}},{key:"newRTCSession",value:function(o,s){this._sessions[o.id]=o,this.emit("newRTCSession",s)}},{key:"destroyRTCSession",value:function(o){delete this._sessions[o.id]}},{key:"registered",value:function(o){this.emit("registered",o)}},{key:"unregistered",value:function(o){this.emit("unregistered",o)}},{key:"registrationFailed",value:function(o){this.emit("registrationFailed",o)}},{key:"receiveRequest",value:function(o){var s=o.method;if(o.ruri.user!==this._configuration.uri.user&&o.ruri.user!==this._contact.uri.user){je.debug("Request-URI does not point to us"),o.method!==pt.ACK&&o.reply_sl(404);return}if(o.ruri.scheme===pt.SIPS){o.reply_sl(416);return}if(!Uo.checkTransaction(this,o)){if(s===pt.INVITE?new Uo.InviteServerTransaction(this,this._transport,o):s!==pt.ACK&&s!==pt.CANCEL&&new Uo.NonInviteServerTransaction(this,this._transport,o),s===pt.OPTIONS){if(this.listeners("newOptions").length===0){o.reply(200);return}var r=new zc(this);r.init_incoming(o)}else if(s===pt.MESSAGE){if(this.listeners("newMessage").length===0){o.reply(405);return}var d=new Jc(this);d.init_incoming(o)}else if(s===pt.INVITE&&!o.to_tag&&this.listeners("newRTCSession").length===0){o.reply(405);return}var h,_;if(o.to_tag)h=this._findDialog(o.call_id,o.from_tag,o.to_tag),h?h.receiveRequest(o):s===pt.NOTIFY?(_=this._findSession(o),_?_.receiveRequest(o):(je.debug("received NOTIFY request for a non existent subscription"),o.reply(481,"Subscription does not exist"))):s!==pt.ACK&&o.reply(481);else switch(s){case pt.INVITE:if(window.RTCPeerConnection)if(o.hasHeader("replaces")){var g=o.replaces;h=this._findDialog(g.call_id,g.from_tag,g.to_tag),h?(_=h.owner,_.isEnded()?o.reply(603):_.receiveRequest(o)):o.reply(481)}else _=new Yc(this),_.init_incoming(o);else je.warn("INVITE received but WebRTC is not supported"),o.reply(488);break;case pt.BYE:o.reply(481);break;case pt.CANCEL:_=this._findSession(o),_?_.receiveRequest(o):je.debug("received CANCEL request for a non existent session");break;case pt.ACK:break;case pt.NOTIFY:this.emit("sipEvent",{event:o.event,request:o}),o.reply(200);break;default:o.reply(405);break}}}},{key:"_findSession",value:function(o){var s=o.call_id,r=o.from_tag,d=o.to_tag,h=s+r,_=this._sessions[h],g=s+d,T=this._sessions[g];return _||T||null}},{key:"_findDialog",value:function(o,s,r){var d=o+s+r,h=this._dialogs[d];return h||(d=o+r+s,h=this._dialogs[d],h||null)}},{key:"_loadConfig",value:function(o){try{xo.load(this._configuration,o)}catch(g){throw g}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=Jl.newUUID()),this._configuration.jssip_id=Jl.createRandomToken(5);var s=this._configuration.uri.clone();s.user=null,this._configuration.hostport_params=s.toString().replace(/^sip:/i,"");try{this._transport=new Tm(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=Cm.bind(this),this._transport.onconnect=Rm.bind(this),this._transport.ondisconnect=Im.bind(this),this._transport.ondata=bm.bind(this)}catch(g){throw je.warn(g),new vm.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){var r=this._configuration.uri.clone();r.user=null,r.clearParams(),r.clearHeaders(),this._configuration.registrar_server=r}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new Em("sip",Jl.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString:function(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},E=T.anonymous||null,y=T.outbound||null,A="<";return E?A+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":A+=this.pub_gruu||this.uri.toString(),y&&(E?!this.temp_gruu:!this.pub_gruu)&&(A+=";ob"),A+=">",A}};var d=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(var h in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,h)&&(d.indexOf(h)!==-1?Object.defineProperty(this._configuration,h,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,h,{writable:!1,configurable:!1}));je.debug("configuration parameters after validation:");for(var _ in this._configuration)if(Object.prototype.hasOwnProperty.call(xo.settings,_))switch(_){case"uri":case"registrar_server":je.debug("- ".concat(_,": ").concat(this._configuration[_]));break;case"password":case"ha1":case"authorization_jwt":je.debug("- ".concat(_,": NOT SHOWN"));break;default:je.debug("- ".concat(_,": ").concat(JSON.stringify(this._configuration[_])))}}},{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}}]),n}(pm);function Cm(c){this.emit("connecting",c)}function Rm(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 Im(c){for(var t=["nict","ict","nist","ist"],n=0,a=t;n<a.length;n++){var o=a[n];for(var s in this._transactions[o])Object.prototype.hasOwnProperty.call(this._transactions[o],s)&&this._transactions[o][s].onTransportError()}this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==Tt.STATUS_USER_CLOSED&&(this._status=Tt.STATUS_NOT_READY,this._error=Tt.NETWORK_ERROR)}function bm(c){var t=c.transport,n=c.message;if(n=Sm.parseMessage(n,this),!!n&&!(this._status===Tt.STATUS_USER_CLOSED&&n instanceof Po.IncomingRequest)&&ym(n,this,t)){if(n instanceof Po.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof Po.IncomingResponse){var a;switch(n.method){case pt.INVITE:a=this._transactions.ict[n.via_branch],a&&a.receiveResponse(n);break;case pt.ACK:break;default:a=this._transactions.nict[n.via_branch],a&&a.receiveResponse(n);break}}}}function wm(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Xc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Om(c,t,n){return t&&Xc(c.prototype,t),n&&Xc(c,n),c}var Dm=ht,Nm=os(),Ot=new Dm("WebSocketInterface"),Um=function(){function c(t){wm(this,c),Ot.debug('new() [url:"%s"]',t),this._url=t,this._sip_uri=null,this._via_transport=null,this._ws=null;var n=Nm.parse(t,"absoluteURI");if(n===-1)throw Ot.warn("invalid WebSocket URI: ".concat(t)),new TypeError("Invalid argument: ".concat(t));if(n.scheme!=="wss"&&n.scheme!=="ws")throw Ot.warn("invalid WebSocket URI scheme: ".concat(n.scheme)),new TypeError("Invalid argument: ".concat(t));this._sip_uri="sip:".concat(n.host).concat(n.port?":".concat(n.port):"",";transport=ws"),this._via_transport=n.scheme.toUpperCase()}return Om(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(n){this._onError(n)}}},{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(n){return Ot.debug("send()"),this.isConnected()?(this._ws.send(n),!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(n){var a=n.wasClean,o=n.code,s=n.reason;Ot.debug("WebSocket ".concat(this._url," closed")),a===!1&&Ot.debug("WebSocket abrupt disconnection"),this.ondisconnect(!a,o,s)}},{key:"_onMessage",value:function(n){var a=n.data;Ot.debug("received WebSocket message"),this.ondata(a)}},{key:"_onError",value:function(n){Ot.warn("WebSocket ".concat(this._url," error: "),n)}},{key:"via_transport",get:function(){return this._via_transport},set:function(n){this._via_transport=n.toUpperCase()}},{key:"sip_uri",get:function(){return this._sip_uri}},{key:"url",get:function(){return this._url}}]),c}(),Su=Fa,Pm=lt,xm=Ws,km=bt(),Mm=Am,Lm=Ks(),$m=Ou(),Hm=os(),Fm=Um,jm=gr("JsSIP");jm("version %s",Su.version);var Qc={C:Pm,Exceptions:xm,Utils:km,UA:Mm,URI:Lm,NameAddrHeader:$m,WebSocketInterface:Fm,Grammar:Hm,debug:gr,get name(){return Su.title},get version(){return Su.version}};const or=gr,ur="JsSIP";var ut=class{constructor(t){t?(this._debug=or.default(`${ur}:${t}`),this._warn=or.default(`${ur}:WARN:${t}`),this._error=or.default(`${ur}:ERROR:${t}`)):(this._debug=or.default(ur),this._warn=or.default(`${ur}:WARN`),this._error=or.default(`${ur}: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 Wa=ze(ut),Zc=Fa;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 L=ze(De);var et={},ko,ef;function $u(){if(ef)return ko;ef=1;const c=ys(),t=Zt();return ko=class uh{static parse(a){if(a=t.parse(a,"Name_Addr_Header"),a!==-1)return a}constructor(a,o,s){if(!a||!(a instanceof c))throw new TypeError('missing or invalid "uri" parameter');this._uri=a,this._parameters={},this.display_name=o;for(const r in s)Object.prototype.hasOwnProperty.call(s,r)&&this.setParam(r,s[r])}get uri(){return this._uri}get display_name(){return this._display_name}set display_name(a){this._display_name=a===0?"0":a}setParam(a,o){a&&(this._parameters[a.toLowerCase()]=typeof o>"u"||o===null?null:o.toString())}getParam(a){if(a)return this._parameters[a.toLowerCase()]}hasParam(a){if(a)return this._parameters.hasOwnProperty(a.toLowerCase())&&!0||!1}deleteParam(a){if(a=a.toLowerCase(),this._parameters.hasOwnProperty(a)){const o=this._parameters[a];return delete this._parameters[a],o}}clearParams(){this._parameters={}}clone(){return new uh(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}_quote(a){return a.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}toString(){let a=this._display_name?`"${this._quote(this._display_name)}" `:"";a+=`<${this._uri.toString()}>`;for(const o in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,o)&&(a+=`;${o}`,this._parameters[o]!==null&&(a+=`=${this._parameters[o]}`));return a}},ko}var Mo,tf;function Zt(){return tf||(tf=1,Mo=function(){function c(n){return'"'+n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var t={parse:function(n,a){var o={CRLF:_,DIGIT:g,ALPHA:T,HEXDIG:E,WSP:y,OCTET:A,DQUOTE:C,SP:I,HTAB:H,alphanum:$,reserved:oe,unreserved:N,mark:j,escaped:Se,LWS:ve,SWS:k,HCOLON:D,TEXT_UTF8_TRIM:B,TEXT_UTF8char:V,UTF8_NONASCII:J,UTF8_CONT:F,LHEX:X,token:U,token_nodot:P,separators:se,word:st,STAR:ee,SLASH:W,EQUAL:G,LPAREN:re,RPAREN:ge,RAQUOT:be,LAQUOT:xe,COMMA:Ce,SEMI:le,COLON:ye,LDQUOT:nt,RDQUOT:at,comment:Ee,ctext:Ae,quoted_string:Ie,quoted_string_clean:Oe,qdtext:pe,quoted_pair:ue,SIP_URI_noparams:_e,SIP_URI:we,uri_scheme:Ne,uri_scheme_sips:Qe,uri_scheme_sip:Le,userinfo:Lt,user:dt,user_unreserved:wn,password:On,hostport:Ys,host:es,hostname:us,domainlabel:Js,toplabel:Dn,IPv6reference:Nn,IPv6address:zs,h16:me,ls32:ae,IPv4address:ot,dec_octet:Wt,port:Cs,uri_parameters:Er,uri_parameter:Un,transport_param:Pn,user_param:Sr,method_param:yr,ttl_param:Ar,maddr_param:Cr,lr_param:Rr,other_param:Ir,pname:br,pvalue:wr,paramchar:Rs,param_unreserved:Is,headers:Or,header:Xs,hname:Qs,hvalue:Dr,hnv_unreserved:bs,Request_Response:Zs,Request_Line:gl,Request_URI:Nr,absoluteURI:xn,hier_part:kn,net_path:Ur,abs_path:en,opaque_part:tn,uric:ws,uric_no_slash:Os,path_segments:Pr,segment:sn,param:Ds,pchar:cs,scheme:Ns,authority:xr,srvr:kr,reg_name:Mr,query:Lr,SIP_Version:Mn,INVITEm:Ln,ACKm:$r,OPTIONSm:Hr,BYEm:Fr,CANCELm:jr,REGISTERm:qr,SUBSCRIBEm:Vr,NOTIFYm:Br,REFERm:Gr,Method:nn,Status_Line:rn,Status_Code:Wr,extension_code:Kr,Reason_Phrase:Yr,Allow_Events:Tl,Call_ID:Ja,Contact:za,contact_param:$n,name_addr:$t,display_name:Ht,contact_params:Us,c_p_q:Hn,c_p_expires:Jr,delta_seconds:ts,qvalue:ss,generic_param:Ge,gen_value:We,Content_Disposition:vl,disp_type:El,disp_param:Fn,handling_param:jn,Content_Encoding:Sl,Content_Length:Xa,Content_Type:Qa,media_type:yl,m_type:zr,discrete_type:Xr,composite_type:Qr,extension_token:ln,x_token:an,m_subtype:Zr,m_parameter:qn,m_value:Vn,CSeq:Al,CSeq_value:Cl,Expires:Rl,Event:Za,event_type:on,From:un,from_param:ei,tag_param:cn,Max_Forwards:ti,Min_Expires:eo,Name_Addr_Header:to,Proxy_Authenticate:so,challenge:si,other_challenge:Bn,auth_param:Ps,digest_cln:ns,realm:fn,realm_value:ni,domain:ri,URI:hn,nonce:dn,nonce_value:ii,opaque:li,stale:ai,algorithm:oi,qop_options:ui,qop_value:_n,Proxy_Require:Gn,Record_Route:no,rec_route:Wn,Reason:Kn,reason_param:ci,reason_cause:Yn,Require:Il,Route:ro,route_param:Jn,Subscription_State:zn,substate_value:bl,subexp_params:Xn,event_reason_value:Qn,Subject:wl,Supported:io,To:lo,to_param:fi,Via:hi,via_param:Zn,via_params:xs,via_ttl:er,via_maddr:di,via_received:_i,via_branch:pi,response_port:mi,rport:gi,sent_protocol:Ti,protocol_name:vi,transport:Ei,sent_by:Si,via_host:yi,via_port:Ai,ttl:tr,WWW_Authenticate:Ci,Session_Expires:ao,s_e_expires:Ol,s_e_params:sr,s_e_refresher:nr,extension_header:Dl,header_value:Nl,message_body:Ul,uuid_URI:oo,uuid:Pl,hex4:Ft,hex8:jt,hex12:Ri,Refer_To:xl,Replaces:uo,call_id:kl,replaces_param:rr,to_tag:ir,from_tag:Ii,early_flag:bi};if(a!==void 0){if(o[a]===void 0)throw new Error("Invalid rule name: "+c(a)+".")}else a="CRLF";var s=0,r=0,d=[];function h(i){s<r||(s>r&&(r=s,d=[]),d.push(i))}function _(){var i;return n.substr(s,2)===`\r
|
72
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s=!0,r=!1,d;return{s:function(){n=c[Symbol.iterator]()},n:function(){var _=n.next();return s=_.done,_},e:function(_){r=!0,d=_},f:function(){try{!s&&n.return!=null&&n.return()}finally{if(r)throw d}}}}function um(c,t){if(c){if(typeof c=="string")return Bc(c,t);var n=Object.prototype.toString.call(c).slice(8,-1);if(n==="Object"&&c.constructor&&(n=c.constructor.name),n==="Map"||n==="Set")return Array.from(c);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Bc(c,t)}}function Bc(c,t){(t==null||t>c.length)&&(t=c.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=c[n];return a}var fr=bt(),yn=lt,Oo=os(),Gc=Ks(),Do=xu,No=Ws;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:yn.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:yn.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:yn.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:"".concat(fr.createRandomToken(12),".invalid")};var Yl={mandatory:{sockets:function(t){var n=[];if(Do.isSocket(t))n.push({socket:t});else if(Array.isArray(t)&&t.length){var a=Vc(t),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;Object.prototype.hasOwnProperty.call(s,"socket")&&Do.isSocket(s.socket)?n.push(s):Do.isSocket(s)&&n.push({socket:s})}}catch(r){a.e(r)}finally{a.f()}}else return;return n},uri:function(t){/^sip:/i.test(t)||(t="".concat(yn.SIP,":").concat(t));var n=Gc.parse(t);if(n)return n.user?n:void 0}},optional:{authorization_user:function(t){if(Oo.parse('"'.concat(t,'"'),"quoted_string")!==-1)return t},authorization_jwt:function(t){if(typeof t=="string")return t},user_agent:function(t){if(typeof t=="string")return t},connection_recovery_max_interval:function(t){if(fr.isDecimal(t)){var n=Number(t);if(n>0)return n}},connection_recovery_min_interval:function(t){if(fr.isDecimal(t)){var n=Number(t);if(n>0)return n}},contact_uri:function(t){if(typeof t=="string"){var n=Oo.parse(t,"SIP_URI");if(n!==-1)return n}},display_name:function(t){return t},instance_id:function(t){if(/^uuid:/i.test(t)&&(t=t.substr(5)),Oo.parse(t,"uuid")!==-1)return t},no_answer_timeout:function(t){if(fr.isDecimal(t)){var n=Number(t);if(n>0)return n}},session_timers:function(t){if(typeof t=="boolean")return t},session_timers_refresh_method:function(t){if(typeof t=="string"&&(t=t.toUpperCase(),t===yn.INVITE||t===yn.UPDATE))return t},session_timers_force_refresher:function(t){if(typeof t=="boolean")return t},password:function(t){return String(t)},realm:function(t){return String(t)},ha1:function(t){return String(t)},register:function(t){if(typeof t=="boolean")return t},register_expires:function(t){if(fr.isDecimal(t)){var n=Number(t);if(n>0)return n}},registrar_server:function(t){/^sip:/i.test(t)||(t="".concat(yn.SIP,":").concat(t));var n=Gc.parse(t);if(n)return n.user?void 0:n},use_preloaded_route:function(t){if(typeof t=="boolean")return t},extra_headers:function(t){var n=[];if(Array.isArray(t)&&t.length){var a=Vc(t),o;try{for(a.s();!(o=a.n()).done;){var s=o.value;typeof s=="string"&&n.push(s)}}catch(r){a.e(r)}finally{a.f()}}else return;return n}}};Lu.load=function(c,t){for(var n in Yl.mandatory)if(t.hasOwnProperty(n)){var a=t[n],o=Yl.mandatory[n](a);if(o!==void 0)c[n]=o;else throw new No.ConfigurationError(n,a)}else throw new No.ConfigurationError(n);for(var s in Yl.optional)if(t.hasOwnProperty(s)){var r=t[s];if(fr.isEmpty(r))continue;var d=Yl.optional[s](r);if(d!==void 0)c[s]=d;else throw new No.ConfigurationError(s,r)}};function wa(c){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?wa=function(n){return typeof n}:wa=function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},wa(c)}function cm(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Wc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Kc(c,t,n){return t&&Wc(c.prototype,t),n&&Wc(c,n),c}function fm(c,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(t&&t.prototype,{constructor:{value:c,writable:!0,configurable:!0}}),t&&Eu(c,t)}function Eu(c,t){return Eu=Object.setPrototypeOf||function(a,o){return a.__proto__=o,a},Eu(c,t)}function hm(c){var t=_m();return function(){var a=$a(c),o;if(t){var s=$a(this).constructor;o=Reflect.construct(a,arguments,s)}else o=a.apply(this,arguments);return dm(this,o)}}function dm(c,t){return t&&(wa(t)==="object"||typeof t=="function")?t:oh(c)}function oh(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 $a(c){return $a=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},$a(c)}var pm=ft.EventEmitter,mm=ht,pt=lt,gm=r_,Yc=dp,Jc=Ip,zc=$p,Uo=hl,Tm=Gp,Jl=bt(),vm=Ws,Em=Ks(),Sm=ih,Po=Ss,ym=tm,xo=Lu,je=new mm("UA"),Tt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},Cm=function(c){fm(n,c);var t=hm(n);Kc(n,null,[{key:"C",get:function(){return Tt}}]);function n(a){var o;if(cm(this,n),je.debug("new() [configuration:%o]",a),o=t.call(this),o._cache={credentials:{}},o._configuration=Object.assign({},xo.settings),o._dynConfiguration={},o._dialogs={},o._applicants={},o._sessions={},o._transport=null,o._contact=null,o._status=Tt.STATUS_INIT,o._error=null,o._transactions={nist:{},nict:{},ist:{},ict:{}},o._data={},o._closeTimer=null,a===void 0)throw new TypeError("Not enough arguments");try{o._loadConfig(a)}catch(s){throw o._status=Tt.STATUS_NOT_READY,o._error=Tt.CONFIGURATION_ERROR,s}return o._registrator=new gm(oh(o)),o}return Kc(n,[{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(o){je.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(o)}},{key:"registrator",value:function(){return this._registrator}},{key:"isRegistered",value:function(){return this._registrator.registered}},{key:"isConnected",value:function(){return this._transport.isConnected()}},{key:"call",value:function(o,s){je.debug("call()");var r=new Yc(this);return r.connect(o,s),r}},{key:"sendMessage",value:function(o,s,r){je.debug("sendMessage()");var d=new Jc(this);return d.send(o,s,r),d}},{key:"sendOptions",value:function(o,s,r){je.debug("sendOptions()");var d=new zc(this);return d.send(o,s,r),d}},{key:"terminateSessions",value:function(o){je.debug("terminateSessions()");for(var s in this._sessions)this._sessions[s].isEnded()||this._sessions[s].terminate(o)}},{key:"stop",value:function(){var o=this;if(je.debug("stop()"),this._dynConfiguration={},this._status===Tt.STATUS_USER_CLOSED){je.debug("UA already closed");return}this._registrator.close();var s=Object.keys(this._sessions).length;for(var r in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,r)){je.debug("closing session ".concat(r));try{this._sessions[r].terminate()}catch{}}for(var d in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,d))try{this._applicants[d].close()}catch{}this._status=Tt.STATUS_USER_CLOSED;var h=Object.keys(this._transactions.nict).length+Object.keys(this._transactions.nist).length+Object.keys(this._transactions.ict).length+Object.keys(this._transactions.ist).length;h===0&&s===0?this._transport.disconnect():this._closeTimer=setTimeout(function(){o._closeTimer=null,o._transport.disconnect()},2e3)}},{key:"normalizeTarget",value:function(o){return Jl.normalizeTarget(o,this._configuration.hostport_params)}},{key:"get",value:function(o){switch(o){case"authorization_user":return this._configuration.authorization_user;case"realm":return this._configuration.realm;case"ha1":return this._configuration.ha1;case"authorization_jwt":return this._configuration.authorization_jwt;default:je.warn('get() | cannot get "%s" parameter in runtime',o);return}}},{key:"set",value:function(o,s){switch(o){case"authorization_user":{this._configuration.authorization_user=String(s);break}case"password":{this._configuration.password=String(s);break}case"realm":{this._configuration.realm=String(s);break}case"ha1":{this._configuration.ha1=String(s),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(s);break}case"display_name":{this._configuration.display_name=s;break}default:return je.warn('set() | cannot set "%s" parameter in runtime',o),!1}return!0}},{key:"newTransaction",value:function(o){this._transactions[o.type][o.id]=o,this.emit("newTransaction",{transaction:o})}},{key:"destroyTransaction",value:function(o){delete this._transactions[o.type][o.id],this.emit("transactionDestroyed",{transaction:o})}},{key:"newDialog",value:function(o){this._dialogs[o.id]=o}},{key:"destroyDialog",value:function(o){delete this._dialogs[o.id]}},{key:"newMessage",value:function(o,s){this._applicants[o]=o,this.emit("newMessage",s)}},{key:"newOptions",value:function(o,s){this._applicants[o]=o,this.emit("newOptions",s)}},{key:"destroyMessage",value:function(o){delete this._applicants[o]}},{key:"newRTCSession",value:function(o,s){this._sessions[o.id]=o,this.emit("newRTCSession",s)}},{key:"destroyRTCSession",value:function(o){delete this._sessions[o.id]}},{key:"registered",value:function(o){this.emit("registered",o)}},{key:"unregistered",value:function(o){this.emit("unregistered",o)}},{key:"registrationFailed",value:function(o){this.emit("registrationFailed",o)}},{key:"receiveRequest",value:function(o){var s=o.method;if(o.ruri.user!==this._configuration.uri.user&&o.ruri.user!==this._contact.uri.user){je.debug("Request-URI does not point to us"),o.method!==pt.ACK&&o.reply_sl(404);return}if(o.ruri.scheme===pt.SIPS){o.reply_sl(416);return}if(!Uo.checkTransaction(this,o)){if(s===pt.INVITE?new Uo.InviteServerTransaction(this,this._transport,o):s!==pt.ACK&&s!==pt.CANCEL&&new Uo.NonInviteServerTransaction(this,this._transport,o),s===pt.OPTIONS){if(this.listeners("newOptions").length===0){o.reply(200);return}var r=new zc(this);r.init_incoming(o)}else if(s===pt.MESSAGE){if(this.listeners("newMessage").length===0){o.reply(405);return}var d=new Jc(this);d.init_incoming(o)}else if(s===pt.INVITE&&!o.to_tag&&this.listeners("newRTCSession").length===0){o.reply(405);return}var h,_;if(o.to_tag)h=this._findDialog(o.call_id,o.from_tag,o.to_tag),h?h.receiveRequest(o):s===pt.NOTIFY?(_=this._findSession(o),_?_.receiveRequest(o):(je.debug("received NOTIFY request for a non existent subscription"),o.reply(481,"Subscription does not exist"))):s!==pt.ACK&&o.reply(481);else switch(s){case pt.INVITE:if(window.RTCPeerConnection)if(o.hasHeader("replaces")){var g=o.replaces;h=this._findDialog(g.call_id,g.from_tag,g.to_tag),h?(_=h.owner,_.isEnded()?o.reply(603):_.receiveRequest(o)):o.reply(481)}else _=new Yc(this),_.init_incoming(o);else je.warn("INVITE received but WebRTC is not supported"),o.reply(488);break;case pt.BYE:o.reply(481);break;case pt.CANCEL:_=this._findSession(o),_?_.receiveRequest(o):je.debug("received CANCEL request for a non existent session");break;case pt.ACK:break;case pt.NOTIFY:this.emit("sipEvent",{event:o.event,request:o}),o.reply(200);break;default:o.reply(405);break}}}},{key:"_findSession",value:function(o){var s=o.call_id,r=o.from_tag,d=o.to_tag,h=s+r,_=this._sessions[h],g=s+d,T=this._sessions[g];return _||T||null}},{key:"_findDialog",value:function(o,s,r){var d=o+s+r,h=this._dialogs[d];return h||(d=o+r+s,h=this._dialogs[d],h||null)}},{key:"_loadConfig",value:function(o){try{xo.load(this._configuration,o)}catch(g){throw g}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=Jl.newUUID()),this._configuration.jssip_id=Jl.createRandomToken(5);var s=this._configuration.uri.clone();s.user=null,this._configuration.hostport_params=s.toString().replace(/^sip:/i,"");try{this._transport=new Tm(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=Am.bind(this),this._transport.onconnect=Rm.bind(this),this._transport.ondisconnect=Im.bind(this),this._transport.ondata=bm.bind(this)}catch(g){throw je.warn(g),new vm.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){var r=this._configuration.uri.clone();r.user=null,r.clearParams(),r.clearHeaders(),this._configuration.registrar_server=r}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new Em("sip",Jl.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString:function(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},E=T.anonymous||null,y=T.outbound||null,C="<";return E?C+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":C+=this.pub_gruu||this.uri.toString(),y&&(E?!this.temp_gruu:!this.pub_gruu)&&(C+=";ob"),C+=">",C}};var d=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(var h in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,h)&&(d.indexOf(h)!==-1?Object.defineProperty(this._configuration,h,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,h,{writable:!1,configurable:!1}));je.debug("configuration parameters after validation:");for(var _ in this._configuration)if(Object.prototype.hasOwnProperty.call(xo.settings,_))switch(_){case"uri":case"registrar_server":je.debug("- ".concat(_,": ").concat(this._configuration[_]));break;case"password":case"ha1":case"authorization_jwt":je.debug("- ".concat(_,": NOT SHOWN"));break;default:je.debug("- ".concat(_,": ").concat(JSON.stringify(this._configuration[_])))}}},{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}}]),n}(pm);function Am(c){this.emit("connecting",c)}function Rm(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 Im(c){for(var t=["nict","ict","nist","ist"],n=0,a=t;n<a.length;n++){var o=a[n];for(var s in this._transactions[o])Object.prototype.hasOwnProperty.call(this._transactions[o],s)&&this._transactions[o][s].onTransportError()}this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==Tt.STATUS_USER_CLOSED&&(this._status=Tt.STATUS_NOT_READY,this._error=Tt.NETWORK_ERROR)}function bm(c){var t=c.transport,n=c.message;if(n=Sm.parseMessage(n,this),!!n&&!(this._status===Tt.STATUS_USER_CLOSED&&n instanceof Po.IncomingRequest)&&ym(n,this,t)){if(n instanceof Po.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof Po.IncomingResponse){var a;switch(n.method){case pt.INVITE:a=this._transactions.ict[n.via_branch],a&&a.receiveResponse(n);break;case pt.ACK:break;default:a=this._transactions.nict[n.via_branch],a&&a.receiveResponse(n);break}}}}function wm(c,t){if(!(c instanceof t))throw new TypeError("Cannot call a class as a function")}function Xc(c,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}}function Om(c,t,n){return t&&Xc(c.prototype,t),n&&Xc(c,n),c}var Dm=ht,Nm=os(),Ot=new Dm("WebSocketInterface"),Um=function(){function c(t){wm(this,c),Ot.debug('new() [url:"%s"]',t),this._url=t,this._sip_uri=null,this._via_transport=null,this._ws=null;var n=Nm.parse(t,"absoluteURI");if(n===-1)throw Ot.warn("invalid WebSocket URI: ".concat(t)),new TypeError("Invalid argument: ".concat(t));if(n.scheme!=="wss"&&n.scheme!=="ws")throw Ot.warn("invalid WebSocket URI scheme: ".concat(n.scheme)),new TypeError("Invalid argument: ".concat(t));this._sip_uri="sip:".concat(n.host).concat(n.port?":".concat(n.port):"",";transport=ws"),this._via_transport=n.scheme.toUpperCase()}return Om(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(n){this._onError(n)}}},{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(n){return Ot.debug("send()"),this.isConnected()?(this._ws.send(n),!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(n){var a=n.wasClean,o=n.code,s=n.reason;Ot.debug("WebSocket ".concat(this._url," closed")),a===!1&&Ot.debug("WebSocket abrupt disconnection"),this.ondisconnect(!a,o,s)}},{key:"_onMessage",value:function(n){var a=n.data;Ot.debug("received WebSocket message"),this.ondata(a)}},{key:"_onError",value:function(n){Ot.warn("WebSocket ".concat(this._url," error: "),n)}},{key:"via_transport",get:function(){return this._via_transport},set:function(n){this._via_transport=n.toUpperCase()}},{key:"sip_uri",get:function(){return this._sip_uri}},{key:"url",get:function(){return this._url}}]),c}(),Su=Fa,Pm=lt,xm=Ws,km=bt(),Mm=Cm,Lm=Ks(),$m=Ou(),Hm=os(),Fm=Um,jm=gr("JsSIP");jm("version %s",Su.version);var Qc={C:Pm,Exceptions:xm,Utils:km,UA:Mm,URI:Lm,NameAddrHeader:$m,WebSocketInterface:Fm,Grammar:Hm,debug:gr,get name(){return Su.title},get version(){return Su.version}};const or=gr,ur="JsSIP";var ut=class{constructor(t){t?(this._debug=or.default(`${ur}:${t}`),this._warn=or.default(`${ur}:WARN:${t}`),this._error=or.default(`${ur}:ERROR:${t}`)):(this._debug=or.default(ur),this._warn=or.default(`${ur}:WARN`),this._error=or.default(`${ur}: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 Wa=ze(ut),Zc=Fa;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 L=ze(De);var et={},ko,ef;function $u(){if(ef)return ko;ef=1;const c=ys(),t=Zt();return ko=class uh{static parse(a){if(a=t.parse(a,"Name_Addr_Header"),a!==-1)return a}constructor(a,o,s){if(!a||!(a instanceof c))throw new TypeError('missing or invalid "uri" parameter');this._uri=a,this._parameters={},this.display_name=o;for(const r in s)Object.prototype.hasOwnProperty.call(s,r)&&this.setParam(r,s[r])}get uri(){return this._uri}get display_name(){return this._display_name}set display_name(a){this._display_name=a===0?"0":a}setParam(a,o){a&&(this._parameters[a.toLowerCase()]=typeof o>"u"||o===null?null:o.toString())}getParam(a){if(a)return this._parameters[a.toLowerCase()]}hasParam(a){if(a)return this._parameters.hasOwnProperty(a.toLowerCase())&&!0||!1}deleteParam(a){if(a=a.toLowerCase(),this._parameters.hasOwnProperty(a)){const o=this._parameters[a];return delete this._parameters[a],o}}clearParams(){this._parameters={}}clone(){return new uh(this._uri.clone(),this._display_name,JSON.parse(JSON.stringify(this._parameters)))}_quote(a){return a.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}toString(){let a=this._display_name?`"${this._quote(this._display_name)}" `:"";a+=`<${this._uri.toString()}>`;for(const o in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,o)&&(a+=`;${o}`,this._parameters[o]!==null&&(a+=`=${this._parameters[o]}`));return a}},ko}var Mo,tf;function Zt(){return tf||(tf=1,Mo=function(){function c(n){return'"'+n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var t={parse:function(n,a){var o={CRLF:_,DIGIT:g,ALPHA:T,HEXDIG:E,WSP:y,OCTET:C,DQUOTE:A,SP:I,HTAB:H,alphanum:$,reserved:oe,unreserved:N,mark:j,escaped:Se,LWS:ve,SWS:k,HCOLON:D,TEXT_UTF8_TRIM:B,TEXT_UTF8char:V,UTF8_NONASCII:J,UTF8_CONT:F,LHEX:X,token:U,token_nodot:P,separators:se,word:st,STAR:ee,SLASH:W,EQUAL:G,LPAREN:re,RPAREN:ge,RAQUOT:be,LAQUOT:xe,COMMA:Ae,SEMI:le,COLON:ye,LDQUOT:nt,RDQUOT:at,comment:Ee,ctext:Ce,quoted_string:Ie,quoted_string_clean:Oe,qdtext:pe,quoted_pair:ue,SIP_URI_noparams:_e,SIP_URI:we,uri_scheme:Ne,uri_scheme_sips:Qe,uri_scheme_sip:Le,userinfo:Lt,user:dt,user_unreserved:wn,password:On,hostport:Ys,host:es,hostname:us,domainlabel:Js,toplabel:Dn,IPv6reference:Nn,IPv6address:zs,h16:me,ls32:ae,IPv4address:ot,dec_octet:Wt,port:As,uri_parameters:Er,uri_parameter:Un,transport_param:Pn,user_param:Sr,method_param:yr,ttl_param:Cr,maddr_param:Ar,lr_param:Rr,other_param:Ir,pname:br,pvalue:wr,paramchar:Rs,param_unreserved:Is,headers:Or,header:Xs,hname:Qs,hvalue:Dr,hnv_unreserved:bs,Request_Response:Zs,Request_Line:gl,Request_URI:Nr,absoluteURI:xn,hier_part:kn,net_path:Ur,abs_path:en,opaque_part:tn,uric:ws,uric_no_slash:Os,path_segments:Pr,segment:sn,param:Ds,pchar:cs,scheme:Ns,authority:xr,srvr:kr,reg_name:Mr,query:Lr,SIP_Version:Mn,INVITEm:Ln,ACKm:$r,OPTIONSm:Hr,BYEm:Fr,CANCELm:jr,REGISTERm:qr,SUBSCRIBEm:Vr,NOTIFYm:Br,REFERm:Gr,Method:nn,Status_Line:rn,Status_Code:Wr,extension_code:Kr,Reason_Phrase:Yr,Allow_Events:Tl,Call_ID:Ja,Contact:za,contact_param:$n,name_addr:$t,display_name:Ht,contact_params:Us,c_p_q:Hn,c_p_expires:Jr,delta_seconds:ts,qvalue:ss,generic_param:Ge,gen_value:We,Content_Disposition:vl,disp_type:El,disp_param:Fn,handling_param:jn,Content_Encoding:Sl,Content_Length:Xa,Content_Type:Qa,media_type:yl,m_type:zr,discrete_type:Xr,composite_type:Qr,extension_token:ln,x_token:an,m_subtype:Zr,m_parameter:qn,m_value:Vn,CSeq:Cl,CSeq_value:Al,Expires:Rl,Event:Za,event_type:on,From:un,from_param:ei,tag_param:cn,Max_Forwards:ti,Min_Expires:eo,Name_Addr_Header:to,Proxy_Authenticate:so,challenge:si,other_challenge:Bn,auth_param:Ps,digest_cln:ns,realm:fn,realm_value:ni,domain:ri,URI:hn,nonce:dn,nonce_value:ii,opaque:li,stale:ai,algorithm:oi,qop_options:ui,qop_value:_n,Proxy_Require:Gn,Record_Route:no,rec_route:Wn,Reason:Kn,reason_param:ci,reason_cause:Yn,Require:Il,Route:ro,route_param:Jn,Subscription_State:zn,substate_value:bl,subexp_params:Xn,event_reason_value:Qn,Subject:wl,Supported:io,To:lo,to_param:fi,Via:hi,via_param:Zn,via_params:xs,via_ttl:er,via_maddr:di,via_received:_i,via_branch:pi,response_port:mi,rport:gi,sent_protocol:Ti,protocol_name:vi,transport:Ei,sent_by:Si,via_host:yi,via_port:Ci,ttl:tr,WWW_Authenticate:Ai,Session_Expires:ao,s_e_expires:Ol,s_e_params:sr,s_e_refresher:nr,extension_header:Dl,header_value:Nl,message_body:Ul,uuid_URI:oo,uuid:Pl,hex4:Ft,hex8:jt,hex12:Ri,Refer_To:xl,Replaces:uo,call_id:kl,replaces_param:rr,to_tag:ir,from_tag:Ii,early_flag:bi};if(a!==void 0){if(o[a]===void 0)throw new Error("Invalid rule name: "+c(a)+".")}else a="CRLF";var s=0,r=0,d=[];function h(i){s<r||(s>r&&(r=s,d=[]),d.push(i))}function _(){var i;return n.substr(s,2)===`\r
|
73
73
|
`?(i=`\r
|
74
|
-
`,s+=2):(i=null,h('"\\r\\n"')),i}function g(){var i;return/^[0-9]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[0-9]")),i}function T(){var i;return/^[a-zA-Z]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[a-zA-Z]")),i}function E(){var i;return/^[0-9a-fA-F]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[0-9a-fA-F]")),i}function y(){var i;return i=I(),i===null&&(i=H()),i}function A(){var i;return/^[\0-\xFF]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\0-\\xFF]")),i}function C(){var i;return/^["]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h('["]')),i}function I(){var i;return n.charCodeAt(s)===32?(i=" ",s++):(i=null,h('" "')),i}function H(){var i;return n.charCodeAt(s)===9?(i=" ",s++):(i=null,h('"\\t"')),i}function $(){var i;return/^[a-zA-Z0-9]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[a-zA-Z0-9]")),i}function oe(){var i;return n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","'))))))))))),i}function N(){var i;return i=$(),i===null&&(i=j()),i}function j(){var i;return n.charCodeAt(s)===45?(i="-",s++):(i=null,h('"-"')),i===null&&(n.charCodeAt(s)===95?(i="_",s++):(i=null,h('"_"')),i===null&&(n.charCodeAt(s)===46?(i=".",s++):(i=null,h('"."')),i===null&&(n.charCodeAt(s)===33?(i="!",s++):(i=null,h('"!"')),i===null&&(n.charCodeAt(s)===126?(i="~",s++):(i=null,h('"~"')),i===null&&(n.charCodeAt(s)===42?(i="*",s++):(i=null,h('"*"')),i===null&&(n.charCodeAt(s)===39?(i="'",s++):(i=null,h(`"'"`)),i===null&&(n.charCodeAt(s)===40?(i="(",s++):(i=null,h('"("')),i===null&&(n.charCodeAt(s)===41?(i=")",s++):(i=null,h('")"')))))))))),i}function Se(){var i,e,l,u,f;return u=s,f=s,n.charCodeAt(s)===37?(i="%",s++):(i=null,h('"%"')),i!==null?(e=E(),e!==null?(l=E(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){return m.join("")}(u,i)),i===null&&(s=u),i}function ve(){var i,e,l,u,f,p;for(u=s,f=s,p=s,i=[],e=y();e!==null;)i.push(e),e=y();if(i!==null?(e=_(),e!==null?i=[i,e]:(i=null,s=p)):(i=null,s=p),i=i!==null?i:"",i!==null){if(l=y(),l!==null)for(e=[];l!==null;)e.push(l),l=y();else e=null;e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i!==null&&(i=function(m){return" "}()),i===null&&(s=u),i}function k(){var i;return i=ve(),i=i!==null?i:"",i}function D(){var i,e,l,u,f;for(u=s,f=s,i=[],e=I(),e===null&&(e=H());e!==null;)i.push(e),e=I(),e===null&&(e=H());return i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return":"}()),i===null&&(s=u),i}function B(){var i,e,l,u,f,p,m;if(f=s,p=s,e=V(),e!==null)for(i=[];e!==null;)i.push(e),e=V();else i=null;if(i!==null){for(e=[],m=s,l=[],u=ve();u!==null;)l.push(u),u=ve();for(l!==null?(u=V(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;){for(e.push(l),m=s,l=[],u=ve();u!==null;)l.push(u),u=ve();l!==null?(u=V(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m)}e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){return n.substring(s,v)}(f)),i===null&&(s=f),i}function V(){var i;return/^[!-~]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[!-~]")),i===null&&(i=J()),i}function J(){var i;return/^[\x80-\uFFFF]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\x80-\\uFFFF]")),i}function F(){var i;return/^[\x80-\xBF]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\x80-\\xBF]")),i}function X(){var i;return i=g(),i===null&&(/^[a-f]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[a-f]"))),i}function U(){var i,e,l;if(l=s,e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"'))))))))))));else i=null;return i!==null&&(i=function(u){return n.substring(s,u)}(l)),i===null&&(s=l),i}function P(){var i,e,l;if(l=s,e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"'))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')))))))))));else i=null;return i!==null&&(i=function(u){return n.substring(s,u)}(l)),i===null&&(s=l),i}function se(){var i;return n.charCodeAt(s)===40?(i="(",s++):(i=null,h('"("')),i===null&&(n.charCodeAt(s)===41?(i=")",s++):(i=null,h('")"')),i===null&&(n.charCodeAt(s)===60?(i="<",s++):(i=null,h('"<"')),i===null&&(n.charCodeAt(s)===62?(i=">",s++):(i=null,h('">"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===92?(i="\\",s++):(i=null,h('"\\\\"')),i===null&&(i=C(),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i===null&&(n.charCodeAt(s)===93?(i="]",s++):(i=null,h('"]"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===123?(i="{",s++):(i=null,h('"{"')),i===null&&(n.charCodeAt(s)===125?(i="}",s++):(i=null,h('"}"')),i===null&&(i=I(),i===null&&(i=H())))))))))))))))))),i}function st(){var i,e,l;if(l=s,e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')),e===null&&(n.charCodeAt(s)===40?(e="(",s++):(e=null,h('"("')),e===null&&(n.charCodeAt(s)===41?(e=")",s++):(e=null,h('")"')),e===null&&(n.charCodeAt(s)===60?(e="<",s++):(e=null,h('"<"')),e===null&&(n.charCodeAt(s)===62?(e=">",s++):(e=null,h('">"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===92?(e="\\",s++):(e=null,h('"\\\\"')),e===null&&(e=C(),e===null&&(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e===null&&(n.charCodeAt(s)===91?(e="[",s++):(e=null,h('"["')),e===null&&(n.charCodeAt(s)===93?(e="]",s++):(e=null,h('"]"')),e===null&&(n.charCodeAt(s)===63?(e="?",s++):(e=null,h('"?"')),e===null&&(n.charCodeAt(s)===123?(e="{",s++):(e=null,h('"{"')),e===null&&(n.charCodeAt(s)===125?(e="}",s++):(e=null,h('"}"'))))))))))))))))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')),e===null&&(n.charCodeAt(s)===40?(e="(",s++):(e=null,h('"("')),e===null&&(n.charCodeAt(s)===41?(e=")",s++):(e=null,h('")"')),e===null&&(n.charCodeAt(s)===60?(e="<",s++):(e=null,h('"<"')),e===null&&(n.charCodeAt(s)===62?(e=">",s++):(e=null,h('">"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===92?(e="\\",s++):(e=null,h('"\\\\"')),e===null&&(e=C(),e===null&&(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e===null&&(n.charCodeAt(s)===91?(e="[",s++):(e=null,h('"["')),e===null&&(n.charCodeAt(s)===93?(e="]",s++):(e=null,h('"]"')),e===null&&(n.charCodeAt(s)===63?(e="?",s++):(e=null,h('"?"')),e===null&&(n.charCodeAt(s)===123?(e="{",s++):(e=null,h('"{"')),e===null&&(n.charCodeAt(s)===125?(e="}",s++):(e=null,h('"}"')))))))))))))))))))))))));else i=null;return i!==null&&(i=function(u){return n.substring(s,u)}(l)),i===null&&(s=l),i}function ee(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"*"}()),i===null&&(s=u),i}function W(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"/"}()),i===null&&(s=u),i}function G(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"="}()),i===null&&(s=u),i}function re(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===40?(e="(",s++):(e=null,h('"("')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"("}()),i===null&&(s=u),i}function ge(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===41?(e=")",s++):(e=null,h('")"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return")"}()),i===null&&(s=u),i}function be(){var i,e,l,u;return l=s,u=s,n.charCodeAt(s)===62?(i=">",s++):(i=null,h('">"')),i!==null?(e=k(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return">"}()),i===null&&(s=l),i}function xe(){var i,e,l,u;return l=s,u=s,i=k(),i!==null?(n.charCodeAt(s)===60?(e="<",s++):(e=null,h('"<"')),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return"<"}()),i===null&&(s=l),i}function Ce(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return","}()),i===null&&(s=u),i}function le(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return";"}()),i===null&&(s=u),i}function ye(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return":"}()),i===null&&(s=u),i}function nt(){var i,e,l,u;return l=s,u=s,i=k(),i!==null?(e=C(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return'"'}()),i===null&&(s=l),i}function at(){var i,e,l,u;return l=s,u=s,i=C(),i!==null?(e=k(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return'"'}()),i===null&&(s=l),i}function Ee(){var i,e,l,u;if(u=s,i=re(),i!==null){for(e=[],l=Ae(),l===null&&(l=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,s=u)):(i=null,s=u)}else i=null,s=u;return i}function Ae(){var i;return/^[!-']/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[!-']")),i===null&&(/^[*-[]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[*-[]")),i===null&&(/^[\]-~]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\]-~]")),i===null&&(i=J(),i===null&&(i=ve())))),i}function Ie(){var i,e,l,u,f,p;if(f=s,p=s,i=k(),i!==null)if(e=C(),e!==null){for(l=[],u=pe(),u===null&&(u=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,s=p)):(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i!==null&&(i=function(m){return n.substring(s,m)}(f)),i===null&&(s=f),i}function Oe(){var i,e,l,u,f,p;if(f=s,p=s,i=k(),i!==null)if(e=C(),e!==null){for(l=[],u=pe(),u===null&&(u=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,s=p)):(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i!==null&&(i=function(m){var v=n.substring(s,m).trim();return v.substring(1,v.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(f)),i===null&&(s=f),i}function pe(){var i;return i=ve(),i===null&&(n.charCodeAt(s)===33?(i="!",s++):(i=null,h('"!"')),i===null&&(/^[#-[]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[#-[]")),i===null&&(/^[\]-~]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\]-~]")),i===null&&(i=J())))),i}function ue(){var i,e,l;return l=s,n.charCodeAt(s)===92?(i="\\",s++):(i=null,h('"\\\\"')),i!==null?(/^[\0-\t]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[\\0-\\t]")),e===null&&(/^[\x0B-\f]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[\\x0B-\\f]")),e===null&&(/^[\x0E-]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[\\x0E-]")))),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function _e(){var i,e,l,u,f,p;return f=s,p=s,i=Ne(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=Lt(),l=l!==null?l:"",l!==null?(u=Ys(),u!==null?i=[i,e,l,u]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i!==null&&(i=function(m){try{b.uri=new Ll(b.scheme,b.user,b.host,b.port),delete b.scheme,delete b.user,delete b.host,delete b.host_type,delete b.port}catch{b=-1}}()),i===null&&(s=f),i}function we(){var i,e,l,u,f,p,m,v;return m=s,v=s,i=Ne(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=Lt(),l=l!==null?l:"",l!==null?(u=Ys(),u!==null?(f=Er(),f!==null?(p=Or(),p=p!==null?p:"",p!==null?i=[i,e,l,u,f,p]:(i=null,s=v)):(i=null,s=v)):(i=null,s=v)):(i=null,s=v)):(i=null,s=v)):(i=null,s=v),i!==null&&(i=function(S){try{b.uri=new Ll(b.scheme,b.user,b.host,b.port,b.uri_params,b.uri_headers),delete b.scheme,delete b.user,delete b.host,delete b.host_type,delete b.port,delete b.uri_params,a==="SIP_URI"&&(b=b.uri)}catch{b=-1}}()),i===null&&(s=m),i}function Ne(){var i;return i=Qe(),i===null&&(i=Le()),i}function Qe(){var i,e;return e=s,n.substr(s,4).toLowerCase()==="sips"?(i=n.substr(s,4),s+=4):(i=null,h('"sips"')),i!==null&&(i=function(l,u){b.scheme=u.toLowerCase()}(e,i)),i===null&&(s=e),i}function Le(){var i,e;return e=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"sip"')),i!==null&&(i=function(l,u){b.scheme=u.toLowerCase()}(e,i)),i===null&&(s=e),i}function Lt(){var i,e,l,u,f,p;return u=s,f=s,i=dt(),i!==null?(p=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=On(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?(n.charCodeAt(s)===64?(l="@",s++):(l=null,h('"@"')),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b.user=decodeURIComponent(n.substring(s-1,m))}(u)),i===null&&(s=u),i}function dt(){var i,e;if(e=N(),e===null&&(e=Se(),e===null&&(e=wn())),e!==null)for(i=[];e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(e=wn()));else i=null;return i}function wn(){var i;return n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"'))))))))),i}function On(){var i,e,l;for(l=s,i=[],e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","'))))))));e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","'))))))));return i!==null&&(i=function(u){b.password=n.substring(s,u)}(l)),i===null&&(s=l),i}function Ys(){var i,e,l,u,f;return u=s,i=es(),i!==null?(f=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=Cs(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function es(){var i,e;return e=s,i=us(),i===null&&(i=ot(),i===null&&(i=Nn())),i!==null&&(i=function(l){return b.host=n.substring(s,l).toLowerCase(),b.host}(e)),i===null&&(s=e),i}function us(){var i,e,l,u,f,p;for(u=s,f=s,i=[],p=s,e=Js(),e!==null?(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p);e!==null;)i.push(e),p=s,e=Js(),e!==null?(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p);return i!==null?(e=Dn(),e!==null?(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l=l!==null?l:"",l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){return b.host_type="domain",n.substring(s,m)}(u)),i===null&&(s=u),i}function Js(){var i,e,l,u;if(u=s,i=$(),i!==null){for(e=[],l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));l!==null;)e.push(l),l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));e!==null?i=[i,e]:(i=null,s=u)}else i=null,s=u;return i}function Dn(){var i,e,l,u;if(u=s,i=T(),i!==null){for(e=[],l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));l!==null;)e.push(l),l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));e!==null?i=[i,e]:(i=null,s=u)}else i=null,s=u;return i}function Nn(){var i,e,l,u,f;return u=s,f=s,n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i!==null?(e=zs(),e!==null?(n.charCodeAt(s)===93?(l="]",s++):(l=null,h('"]"')),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return b.host_type="IPv6",n.substring(s,p)}(u)),i===null&&(s=u),i}function zs(){var i,e,l,u,f,p,m,v,S,O,ie,Ue,wt,ks,M,R;return ks=s,M=s,i=me(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?(n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?(n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?(n.charCodeAt(s)===58?(v=":",s++):(v=null,h('":"')),v!==null?(S=me(),S!==null?(n.charCodeAt(s)===58?(O=":",s++):(O=null,h('":"')),O!==null?(ie=me(),ie!==null?(n.charCodeAt(s)===58?(Ue=":",s++):(Ue=null,h('":"')),Ue!==null?(wt=ae(),wt!==null?i=[i,e,l,u,f,p,m,v,S,O,ie,Ue,wt]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?(n.charCodeAt(s)===58?(S=":",s++):(S=null,h('":"')),S!==null?(O=me(),O!==null?(n.charCodeAt(s)===58?(ie=":",s++):(ie=null,h('":"')),ie!==null?(Ue=ae(),Ue!==null?i=[i,e,l,u,f,p,m,v,S,O,ie,Ue]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?(n.charCodeAt(s)===58?(S=":",s++):(S=null,h('":"')),S!==null?(O=ae(),O!==null?i=[i,e,l,u,f,p,m,v,S,O]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=ae(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=ae(),p!==null?i=[i,e,l,u,f,p]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=ae(),u!==null?i=[i,e,l,u]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=ae(),e!==null?i=[i,e]:(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?i=[i,e]:(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(n.substr(s,2)==="::"?(e="::",s+=2):(e=null,h('"::"')),e!==null?(l=me(),l!==null?(n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?(n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?(n.charCodeAt(s)===58?(v=":",s++):(v=null,h('":"')),v!==null?(S=me(),S!==null?(n.charCodeAt(s)===58?(O=":",s++):(O=null,h('":"')),O!==null?(ie=ae(),ie!==null?i=[i,e,l,u,f,p,m,v,S,O,ie]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(n.substr(s,2)==="::"?(l="::",s+=2):(l=null,h('"::"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?(n.charCodeAt(s)===58?(S=":",s++):(S=null,h('":"')),S!==null?(O=ae(),O!==null?i=[i,e,l,u,f,p,m,v,S,O]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(n.substr(s,2)==="::"?(u="::",s+=2):(u=null,h('"::"')),u!==null?(f=me(),f!==null?(n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?(n.charCodeAt(s)===58?(v=":",s++):(v=null,h('":"')),v!==null?(S=ae(),S!==null?i=[i,e,l,u,f,p,m,v,S]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(n.substr(s,2)==="::"?(f="::",s+=2):(f=null,h('"::"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=ae(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(R=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,s=R)):(f=null,s=R),f=f!==null?f:"",f!==null?(n.substr(s,2)==="::"?(p="::",s+=2):(p=null,h('"::"')),p!==null?(m=ae(),m!==null?i=[i,e,l,u,f,p,m]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(R=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,s=R)):(f=null,s=R),f=f!==null?f:"",f!==null?(R=s,n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?p=[p,m]:(p=null,s=R)):(p=null,s=R),p=p!==null?p:"",p!==null?(n.substr(s,2)==="::"?(m="::",s+=2):(m=null,h('"::"')),m!==null?(v=me(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(R=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,s=R)):(f=null,s=R),f=f!==null?f:"",f!==null?(R=s,n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?p=[p,m]:(p=null,s=R)):(p=null,s=R),p=p!==null?p:"",p!==null?(R=s,n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?m=[m,v]:(m=null,s=R)):(m=null,s=R),m=m!==null?m:"",m!==null?(n.substr(s,2)==="::"?(v="::",s+=2):(v=null,h('"::"')),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M))))))))))))))),i!==null&&(i=function(Te){return b.host_type="IPv6",n.substring(s,Te)}(ks)),i===null&&(s=ks),i}function me(){var i,e,l,u,f;return f=s,i=E(),i!==null?(e=E(),e=e!==null?e:"",e!==null?(l=E(),l=l!==null?l:"",l!==null?(u=E(),u=u!==null?u:"",u!==null?i=[i,e,l,u]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i}function ae(){var i,e,l,u;return u=s,i=me(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i===null&&(i=ot()),i}function ot(){var i,e,l,u,f,p,m,v,S;return v=s,S=s,i=Wt(),i!==null?(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e!==null?(l=Wt(),l!==null?(n.charCodeAt(s)===46?(u=".",s++):(u=null,h('"."')),u!==null?(f=Wt(),f!==null?(n.charCodeAt(s)===46?(p=".",s++):(p=null,h('"."')),p!==null?(m=Wt(),m!==null?i=[i,e,l,u,f,p,m]:(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S),i!==null&&(i=function(O){return b.host_type="IPv4",n.substring(s,O)}(v)),i===null&&(s=v),i}function Wt(){var i,e,l,u;return u=s,n.substr(s,2)==="25"?(i="25",s+=2):(i=null,h('"25"')),i!==null?(/^[0-5]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[0-5]")),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i===null&&(u=s,n.charCodeAt(s)===50?(i="2",s++):(i=null,h('"2"')),i!==null?(/^[0-4]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[0-4]")),e!==null?(l=g(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i===null&&(u=s,n.charCodeAt(s)===49?(i="1",s++):(i=null,h('"1"')),i!==null?(e=g(),e!==null?(l=g(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i===null&&(u=s,/^[1-9]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[1-9]")),i!==null?(e=g(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i===null&&(i=g())))),i}function Cs(){var i,e,l,u,f,p,m;return p=s,m=s,i=g(),i=i!==null?i:"",i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?i=[i,e,l,u,f]:(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(v,S){return S=parseInt(S.join("")),b.port=S,S}(p,i)),i===null&&(s=p),i}function Er(){var i,e,l,u;for(i=[],u=s,n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e!==null?(l=Un(),l!==null?e=[e,l]:(e=null,s=u)):(e=null,s=u);e!==null;)i.push(e),u=s,n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e!==null?(l=Un(),l!==null?e=[e,l]:(e=null,s=u)):(e=null,s=u);return i}function Un(){var i;return i=Pn(),i===null&&(i=Sr(),i===null&&(i=yr(),i===null&&(i=Ar(),i===null&&(i=Cr(),i===null&&(i=Rr(),i===null&&(i=Ir())))))),i}function Pn(){var i,e,l,u;return l=s,u=s,n.substr(s,10).toLowerCase()==="transport="?(i=n.substr(s,10),s+=10):(i=null,h('"transport="')),i!==null?(n.substr(s,3).toLowerCase()==="udp"?(e=n.substr(s,3),s+=3):(e=null,h('"udp"')),e===null&&(n.substr(s,3).toLowerCase()==="tcp"?(e=n.substr(s,3),s+=3):(e=null,h('"tcp"')),e===null&&(n.substr(s,4).toLowerCase()==="sctp"?(e=n.substr(s,4),s+=4):(e=null,h('"sctp"')),e===null&&(n.substr(s,3).toLowerCase()==="tls"?(e=n.substr(s,3),s+=3):(e=null,h('"tls"')),e===null&&(e=U())))),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.transport=p.toLowerCase()}(l,i[1])),i===null&&(s=l),i}function Sr(){var i,e,l,u;return l=s,u=s,n.substr(s,5).toLowerCase()==="user="?(i=n.substr(s,5),s+=5):(i=null,h('"user="')),i!==null?(n.substr(s,5).toLowerCase()==="phone"?(e=n.substr(s,5),s+=5):(e=null,h('"phone"')),e===null&&(n.substr(s,2).toLowerCase()==="ip"?(e=n.substr(s,2),s+=2):(e=null,h('"ip"')),e===null&&(e=U())),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.user=p.toLowerCase()}(l,i[1])),i===null&&(s=l),i}function yr(){var i,e,l,u;return l=s,u=s,n.substr(s,7).toLowerCase()==="method="?(i=n.substr(s,7),s+=7):(i=null,h('"method="')),i!==null?(e=nn(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.method=p}(l,i[1])),i===null&&(s=l),i}function Ar(){var i,e,l,u;return l=s,u=s,n.substr(s,4).toLowerCase()==="ttl="?(i=n.substr(s,4),s+=4):(i=null,h('"ttl="')),i!==null?(e=tr(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.params||(b.params={}),b.params.ttl=p}(l,i[1])),i===null&&(s=l),i}function Cr(){var i,e,l,u;return l=s,u=s,n.substr(s,6).toLowerCase()==="maddr="?(i=n.substr(s,6),s+=6):(i=null,h('"maddr="')),i!==null?(e=es(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.maddr=p}(l,i[1])),i===null&&(s=l),i}function Rr(){var i,e,l,u,f,p;return u=s,f=s,n.substr(s,2).toLowerCase()==="lr"?(i=n.substr(s,2),s+=2):(i=null,h('"lr"')),i!==null?(p=s,n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=U(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b.uri_params||(b.uri_params={}),b.uri_params.lr=void 0}()),i===null&&(s=u),i}function Ir(){var i,e,l,u,f,p;return u=s,f=s,i=br(),i!==null?(p=s,n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=wr(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m,v,S){b.uri_params||(b.uri_params={}),typeof S>"u"?S=void 0:S=S[1],b.uri_params[v.toLowerCase()]=S}(u,i[0],i[1])),i===null&&(s=u),i}function br(){var i,e,l;if(l=s,e=Rs(),e!==null)for(i=[];e!==null;)i.push(e),e=Rs();else i=null;return i!==null&&(i=function(u,f){return f.join("")}(l,i)),i===null&&(s=l),i}function wr(){var i,e,l;if(l=s,e=Rs(),e!==null)for(i=[];e!==null;)i.push(e),e=Rs();else i=null;return i!==null&&(i=function(u,f){return f.join("")}(l,i)),i===null&&(s=l),i}function Rs(){var i;return i=Is(),i===null&&(i=N(),i===null&&(i=Se())),i}function Is(){var i;return n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i===null&&(n.charCodeAt(s)===93?(i="]",s++):(i=null,h('"]"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')))))))),i}function Or(){var i,e,l,u,f,p,m;if(p=s,n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i!==null)if(e=Xs(),e!==null){for(l=[],m=s,n.charCodeAt(s)===38?(u="&",s++):(u=null,h('"&"')),u!==null?(f=Xs(),f!==null?u=[u,f]:(u=null,s=m)):(u=null,s=m);u!==null;)l.push(u),m=s,n.charCodeAt(s)===38?(u="&",s++):(u=null,h('"&"')),u!==null?(f=Xs(),f!==null?u=[u,f]:(u=null,s=m)):(u=null,s=m);l!==null?i=[i,e,l]:(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i}function Xs(){var i,e,l,u,f;return u=s,f=s,i=Qs(),i!==null?(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=Dr(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m,v){m=m.join("").toLowerCase(),v=v.join(""),b.uri_headers||(b.uri_headers={}),b.uri_headers[m]?b.uri_headers[m].push(v):b.uri_headers[m]=[v]}(u,i[0],i[2])),i===null&&(s=u),i}function Qs(){var i,e;if(e=bs(),e===null&&(e=N(),e===null&&(e=Se())),e!==null)for(i=[];e!==null;)i.push(e),e=bs(),e===null&&(e=N(),e===null&&(e=Se()));else i=null;return i}function Dr(){var i,e;for(i=[],e=bs(),e===null&&(e=N(),e===null&&(e=Se()));e!==null;)i.push(e),e=bs(),e===null&&(e=N(),e===null&&(e=Se()));return i}function bs(){var i;return n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i===null&&(n.charCodeAt(s)===93?(i="]",s++):(i=null,h('"]"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')))))))),i}function Zs(){var i;return i=rn(),i===null&&(i=gl()),i}function gl(){var i,e,l,u,f,p;return p=s,i=nn(),i!==null?(e=I(),e!==null?(l=Nr(),l!==null?(u=I(),u!==null?(f=Mn(),f!==null?i=[i,e,l,u,f]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i}function Nr(){var i;return i=we(),i===null&&(i=xn()),i}function xn(){var i,e,l,u;return u=s,i=Ns(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=kn(),l===null&&(l=tn()),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function kn(){var i,e,l,u,f;return u=s,i=Ur(),i===null&&(i=en()),i!==null?(f=s,n.charCodeAt(s)===63?(e="?",s++):(e=null,h('"?"')),e!==null?(l=Lr(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function Ur(){var i,e,l,u;return u=s,n.substr(s,2)==="//"?(i="//",s+=2):(i=null,h('"//"')),i!==null?(e=xr(),e!==null?(l=en(),l=l!==null?l:"",l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function en(){var i,e,l;return l=s,n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i!==null?(e=Pr(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function tn(){var i,e,l,u;if(u=s,i=Os(),i!==null){for(e=[],l=ws();l!==null;)e.push(l),l=ws();e!==null?i=[i,e]:(i=null,s=u)}else i=null,s=u;return i}function ws(){var i;return i=oe(),i===null&&(i=N(),i===null&&(i=Se())),i}function Os(){var i;return i=N(),i===null&&(i=Se(),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')))))))))))),i}function Pr(){var i,e,l,u,f,p;if(f=s,i=sn(),i!==null){for(e=[],p=s,n.charCodeAt(s)===47?(l="/",s++):(l=null,h('"/"')),l!==null?(u=sn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,n.charCodeAt(s)===47?(l="/",s++):(l=null,h('"/"')),l!==null?(u=sn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function sn(){var i,e,l,u,f,p;for(f=s,i=[],e=cs();e!==null;)i.push(e),e=cs();if(i!==null){for(e=[],p=s,n.charCodeAt(s)===59?(l=";",s++):(l=null,h('";"')),l!==null?(u=Ds(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,n.charCodeAt(s)===59?(l=";",s++):(l=null,h('";"')),l!==null?(u=Ds(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Ds(){var i,e;for(i=[],e=cs();e!==null;)i.push(e),e=cs();return i}function cs(){var i;return i=N(),i===null&&(i=Se(),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')))))))))),i}function Ns(){var i,e,l,u,f;if(u=s,f=s,i=T(),i!==null){for(e=[],l=T(),l===null&&(l=g(),l===null&&(n.charCodeAt(s)===43?(l="+",s++):(l=null,h('"+"')),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."'))))));l!==null;)e.push(l),l=T(),l===null&&(l=g(),l===null&&(n.charCodeAt(s)===43?(l="+",s++):(l=null,h('"+"')),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."'))))));e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i!==null&&(i=function(p){b.scheme=n.substring(s,p)}(u)),i===null&&(s=u),i}function xr(){var i;return i=kr(),i===null&&(i=Mr()),i}function kr(){var i,e,l,u;return l=s,u=s,i=Lt(),i!==null?(n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i=i!==null?i:"",i!==null?(e=Ys(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i=i!==null?i:"",i}function Mr(){var i,e;if(e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","')),e===null&&(n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"'))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","')),e===null&&(n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')))))))))));else i=null;return i}function Lr(){var i,e;for(i=[],e=ws();e!==null;)i.push(e),e=ws();return i}function Mn(){var i,e,l,u,f,p,m,v;if(m=s,v=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"SIP"')),i!==null)if(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e!==null){if(u=g(),u!==null)for(l=[];u!==null;)l.push(u),u=g();else l=null;if(l!==null)if(n.charCodeAt(s)===46?(u=".",s++):(u=null,h('"."')),u!==null){if(p=g(),p!==null)for(f=[];p!==null;)f.push(p),p=g();else f=null;f!==null?i=[i,e,l,u,f]:(i=null,s=v)}else i=null,s=v;else i=null,s=v}else i=null,s=v;else i=null,s=v;return i!==null&&(i=function(S){b.sip_version=n.substring(s,S)}(m)),i===null&&(s=m),i}function Ln(){var i;return n.substr(s,6)==="INVITE"?(i="INVITE",s+=6):(i=null,h('"INVITE"')),i}function $r(){var i;return n.substr(s,3)==="ACK"?(i="ACK",s+=3):(i=null,h('"ACK"')),i}function Hr(){var i;return n.substr(s,7)==="OPTIONS"?(i="OPTIONS",s+=7):(i=null,h('"OPTIONS"')),i}function Fr(){var i;return n.substr(s,3)==="BYE"?(i="BYE",s+=3):(i=null,h('"BYE"')),i}function jr(){var i;return n.substr(s,6)==="CANCEL"?(i="CANCEL",s+=6):(i=null,h('"CANCEL"')),i}function qr(){var i;return n.substr(s,8)==="REGISTER"?(i="REGISTER",s+=8):(i=null,h('"REGISTER"')),i}function Vr(){var i;return n.substr(s,9)==="SUBSCRIBE"?(i="SUBSCRIBE",s+=9):(i=null,h('"SUBSCRIBE"')),i}function Br(){var i;return n.substr(s,6)==="NOTIFY"?(i="NOTIFY",s+=6):(i=null,h('"NOTIFY"')),i}function Gr(){var i;return n.substr(s,5)==="REFER"?(i="REFER",s+=5):(i=null,h('"REFER"')),i}function nn(){var i,e;return e=s,i=Ln(),i===null&&(i=$r(),i===null&&(i=Hr(),i===null&&(i=Fr(),i===null&&(i=jr(),i===null&&(i=qr(),i===null&&(i=Vr(),i===null&&(i=Br(),i===null&&(i=Gr(),i===null&&(i=U()))))))))),i!==null&&(i=function(l){return b.method=n.substring(s,l),b.method}(e)),i===null&&(s=e),i}function rn(){var i,e,l,u,f,p;return p=s,i=Mn(),i!==null?(e=I(),e!==null?(l=Wr(),l!==null?(u=I(),u!==null?(f=Yr(),f!==null?i=[i,e,l,u,f]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i}function Wr(){var i,e;return e=s,i=Kr(),i!==null&&(i=function(l,u){b.status_code=parseInt(u.join(""))}(e,i)),i===null&&(s=e),i}function Kr(){var i,e,l,u;return u=s,i=g(),i!==null?(e=g(),e!==null?(l=g(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Yr(){var i,e,l;for(l=s,i=[],e=oe(),e===null&&(e=N(),e===null&&(e=Se(),e===null&&(e=J(),e===null&&(e=F(),e===null&&(e=I(),e===null&&(e=H()))))));e!==null;)i.push(e),e=oe(),e===null&&(e=N(),e===null&&(e=Se(),e===null&&(e=J(),e===null&&(e=F(),e===null&&(e=I(),e===null&&(e=H()))))));return i!==null&&(i=function(u){b.reason_phrase=n.substring(s,u)}(l)),i===null&&(s=l),i}function Tl(){var i,e,l,u,f,p;if(f=s,i=on(),i!==null){for(e=[],p=s,l=Ce(),l!==null?(u=on(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ce(),l!==null?(u=on(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Ja(){var i,e,l,u,f,p;return u=s,f=s,i=st(),i!==null?(p=s,n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e!==null?(l=st(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b=n.substring(s,m)}(u)),i===null&&(s=u),i}function za(){var i,e,l,u,f,p,m;if(f=s,i=ee(),i===null)if(p=s,i=$n(),i!==null){for(e=[],m=s,l=Ce(),l!==null?(u=$n(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=Ce(),l!==null?(u=$n(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S,O;for(O=b.multi_header.length,S=0;S<O;S++)if(b.multi_header[S].parsed===null){b=null;break}b!==null?b=b.multi_header:b=-1}()),i===null&&(s=f),i}function $n(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=$t()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Us(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Us(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S;b.multi_header||(b.multi_header=[]);try{S=new fs(b.uri,b.display_name,b.params),delete b.uri,delete b.display_name,delete b.params}catch{S=null}b.multi_header.push({possition:s,offset:v,parsed:S})}(f)),i===null&&(s=f),i}function $t(){var i,e,l,u,f;return f=s,i=Ht(),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,s=f)):(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i}function Ht(){var i,e,l,u,f,p,m;if(f=s,p=s,i=U(),i!==null){for(e=[],m=s,l=ve(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=ve(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i===null&&(i=Oe()),i!==null&&(i=function(v,S){typeof S=="string"?b.display_name=S:b.display_name=S[1].reduce(function(O,ie){return O+ie[0]+ie[1]},S[0])}(f,i)),i===null&&(s=f),i}function Us(){var i;return i=Hn(),i===null&&(i=Jr(),i===null&&(i=Ge())),i}function Hn(){var i,e,l,u,f;return u=s,f=s,n.substr(s,1).toLowerCase()==="q"?(i=n.substr(s,1),s++):(i=null,h('"q"')),i!==null?(e=G(),e!==null?(l=ss(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.params||(b.params={}),b.params.q=m}(u,i[2])),i===null&&(s=u),i}function Jr(){var i,e,l,u,f;return u=s,f=s,n.substr(s,7).toLowerCase()==="expires"?(i=n.substr(s,7),s+=7):(i=null,h('"expires"')),i!==null?(e=G(),e!==null?(l=ts(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.params||(b.params={}),b.params.expires=m}(u,i[2])),i===null&&(s=u),i}function ts(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){return parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function ss(){var i,e,l,u,f,p,m,v;return p=s,m=s,n.charCodeAt(s)===48?(i="0",s++):(i=null,h('"0"')),i!==null?(v=s,n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?e=[e,l,u,f]:(e=null,s=v)):(e=null,s=v)):(e=null,s=v)):(e=null,s=v),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(S){return parseFloat(n.substring(s,S))}(p)),i===null&&(s=p),i}function Ge(){var i,e,l,u,f,p;return u=s,f=s,i=U(),i!==null?(p=s,e=G(),e!==null?(l=We(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m,v,S){b.params||(b.params={}),typeof S>"u"?S=void 0:S=S[1],b.params[v.toLowerCase()]=S}(u,i[0],i[1])),i===null&&(s=u),i}function We(){var i;return i=U(),i===null&&(i=es(),i===null&&(i=Ie())),i}function vl(){var i,e,l,u,f,p;if(f=s,i=El(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=Fn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=Fn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function El(){var i;return n.substr(s,6).toLowerCase()==="render"?(i=n.substr(s,6),s+=6):(i=null,h('"render"')),i===null&&(n.substr(s,7).toLowerCase()==="session"?(i=n.substr(s,7),s+=7):(i=null,h('"session"')),i===null&&(n.substr(s,4).toLowerCase()==="icon"?(i=n.substr(s,4),s+=4):(i=null,h('"icon"')),i===null&&(n.substr(s,5).toLowerCase()==="alert"?(i=n.substr(s,5),s+=5):(i=null,h('"alert"')),i===null&&(i=U())))),i}function Fn(){var i;return i=jn(),i===null&&(i=Ge()),i}function jn(){var i,e,l,u;return u=s,n.substr(s,8).toLowerCase()==="handling"?(i=n.substr(s,8),s+=8):(i=null,h('"handling"')),i!==null?(e=G(),e!==null?(n.substr(s,8).toLowerCase()==="optional"?(l=n.substr(s,8),s+=8):(l=null,h('"optional"')),l===null&&(n.substr(s,8).toLowerCase()==="required"?(l=n.substr(s,8),s+=8):(l=null,h('"required"')),l===null&&(l=U())),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Sl(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Xa(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){b=parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function Qa(){var i,e;return e=s,i=yl(),i!==null&&(i=function(l){b=n.substring(s,l)}(e)),i===null&&(s=e),i}function yl(){var i,e,l,u,f,p,m,v;if(m=s,i=zr(),i!==null)if(e=W(),e!==null)if(l=Zr(),l!==null){for(u=[],v=s,f=le(),f!==null?(p=qn(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=le(),f!==null?(p=qn(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i}function zr(){var i;return i=Xr(),i===null&&(i=Qr()),i}function Xr(){var i;return n.substr(s,4).toLowerCase()==="text"?(i=n.substr(s,4),s+=4):(i=null,h('"text"')),i===null&&(n.substr(s,5).toLowerCase()==="image"?(i=n.substr(s,5),s+=5):(i=null,h('"image"')),i===null&&(n.substr(s,5).toLowerCase()==="audio"?(i=n.substr(s,5),s+=5):(i=null,h('"audio"')),i===null&&(n.substr(s,5).toLowerCase()==="video"?(i=n.substr(s,5),s+=5):(i=null,h('"video"')),i===null&&(n.substr(s,11).toLowerCase()==="application"?(i=n.substr(s,11),s+=11):(i=null,h('"application"')),i===null&&(i=ln()))))),i}function Qr(){var i;return n.substr(s,7).toLowerCase()==="message"?(i=n.substr(s,7),s+=7):(i=null,h('"message"')),i===null&&(n.substr(s,9).toLowerCase()==="multipart"?(i=n.substr(s,9),s+=9):(i=null,h('"multipart"')),i===null&&(i=ln())),i}function ln(){var i;return i=U(),i===null&&(i=an()),i}function an(){var i,e,l;return l=s,n.substr(s,2).toLowerCase()==="x-"?(i=n.substr(s,2),s+=2):(i=null,h('"x-"')),i!==null?(e=U(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function Zr(){var i;return i=ln(),i===null&&(i=U()),i}function qn(){var i,e,l,u;return u=s,i=U(),i!==null?(e=G(),e!==null?(l=Vn(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Vn(){var i;return i=U(),i===null&&(i=Ie()),i}function Al(){var i,e,l,u;return u=s,i=Cl(),i!==null?(e=ve(),e!==null?(l=nn(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Cl(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){b.value=parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function Rl(){var i,e;return e=s,i=ts(),i!==null&&(i=function(l,u){b=u}(e,i)),i===null&&(s=e),i}function Za(){var i,e,l,u,f,p,m;if(f=s,p=s,i=on(),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v,S){b.event=S.join("").toLowerCase()}(f,i[0])),i===null&&(s=f),i}function on(){var i,e,l,u,f,p;if(f=s,i=P(),i!==null){for(e=[],p=s,n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?(u=P(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?(u=P(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function un(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=$t()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=ei(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=ei(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S=b.tag;try{b=new fs(b.uri,b.display_name,b.params),S&&b.setParam("tag",S)}catch{b=-1}}()),i===null&&(s=f),i}function ei(){var i;return i=cn(),i===null&&(i=Ge()),i}function cn(){var i,e,l,u,f;return u=s,f=s,n.substr(s,3).toLowerCase()==="tag"?(i=n.substr(s,3),s+=3):(i=null,h('"tag"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.tag=m}(u,i[2])),i===null&&(s=u),i}function ti(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){b=parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function eo(){var i,e;return e=s,i=ts(),i!==null&&(i=function(l,u){b=u}(e,i)),i===null&&(s=e),i}function to(){var i,e,l,u,f,p,m,v,S,O;for(v=s,S=s,i=[],e=Ht();e!==null;)i.push(e),e=Ht();if(i!==null)if(e=xe(),e!==null)if(l=we(),l!==null)if(u=be(),u!==null){for(f=[],O=s,p=le(),p!==null?(m=Ge(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);p!==null;)f.push(p),O=s,p=le(),p!==null?(m=Ge(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);f!==null?i=[i,e,l,u,f]:(i=null,s=S)}else i=null,s=S;else i=null,s=S;else i=null,s=S;else i=null,s=S;return i!==null&&(i=function(ie){try{b=new fs(b.uri,b.display_name,b.params)}catch{b=-1}}()),i===null&&(s=v),i}function so(){var i;return i=si(),i}function si(){var i,e,l,u,f,p,m,v;if(m=s,n.substr(s,6).toLowerCase()==="digest"?(i=n.substr(s,6),s+=6):(i=null,h('"Digest"')),i!==null)if(e=ve(),e!==null)if(l=ns(),l!==null){for(u=[],v=s,f=Ce(),f!==null?(p=ns(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=Ce(),f!==null?(p=ns(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i===null&&(i=Bn()),i}function Bn(){var i,e,l,u,f,p,m,v;if(m=s,i=U(),i!==null)if(e=ve(),e!==null)if(l=Ps(),l!==null){for(u=[],v=s,f=Ce(),f!==null?(p=Ps(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=Ce(),f!==null?(p=Ps(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i}function Ps(){var i,e,l,u;return u=s,i=U(),i!==null?(e=G(),e!==null?(l=U(),l===null&&(l=Ie()),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function ns(){var i;return i=fn(),i===null&&(i=ri(),i===null&&(i=dn(),i===null&&(i=li(),i===null&&(i=ai(),i===null&&(i=oi(),i===null&&(i=ui(),i===null&&(i=Ps()))))))),i}function fn(){var i,e,l,u;return u=s,n.substr(s,5).toLowerCase()==="realm"?(i=n.substr(s,5),s+=5):(i=null,h('"realm"')),i!==null?(e=G(),e!==null?(l=ni(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function ni(){var i,e;return e=s,i=Oe(),i!==null&&(i=function(l,u){b.realm=u}(e,i)),i===null&&(s=e),i}function ri(){var i,e,l,u,f,p,m,v,S;if(v=s,n.substr(s,6).toLowerCase()==="domain"?(i=n.substr(s,6),s+=6):(i=null,h('"domain"')),i!==null)if(e=G(),e!==null)if(l=nt(),l!==null)if(u=hn(),u!==null){if(f=[],S=s,m=I(),m!==null)for(p=[];m!==null;)p.push(m),m=I();else p=null;for(p!==null?(m=hn(),m!==null?p=[p,m]:(p=null,s=S)):(p=null,s=S);p!==null;){if(f.push(p),S=s,m=I(),m!==null)for(p=[];m!==null;)p.push(m),m=I();else p=null;p!==null?(m=hn(),m!==null?p=[p,m]:(p=null,s=S)):(p=null,s=S)}f!==null?(p=at(),p!==null?i=[i,e,l,u,f,p]:(i=null,s=v)):(i=null,s=v)}else i=null,s=v;else i=null,s=v;else i=null,s=v;else i=null,s=v;return i}function hn(){var i;return i=xn(),i===null&&(i=en()),i}function dn(){var i,e,l,u;return u=s,n.substr(s,5).toLowerCase()==="nonce"?(i=n.substr(s,5),s+=5):(i=null,h('"nonce"')),i!==null?(e=G(),e!==null?(l=ii(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function ii(){var i,e;return e=s,i=Oe(),i!==null&&(i=function(l,u){b.nonce=u}(e,i)),i===null&&(s=e),i}function li(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6).toLowerCase()==="opaque"?(i=n.substr(s,6),s+=6):(i=null,h('"opaque"')),i!==null?(e=G(),e!==null?(l=Oe(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.opaque=m}(u,i[2])),i===null&&(s=u),i}function ai(){var i,e,l,u,f;return u=s,n.substr(s,5).toLowerCase()==="stale"?(i=n.substr(s,5),s+=5):(i=null,h('"stale"')),i!==null?(e=G(),e!==null?(f=s,n.substr(s,4).toLowerCase()==="true"?(l=n.substr(s,4),s+=4):(l=null,h('"true"')),l!==null&&(l=function(p){b.stale=!0}()),l===null&&(s=f),l===null&&(f=s,n.substr(s,5).toLowerCase()==="false"?(l=n.substr(s,5),s+=5):(l=null,h('"false"')),l!==null&&(l=function(p){b.stale=!1}()),l===null&&(s=f)),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function oi(){var i,e,l,u,f;return u=s,f=s,n.substr(s,9).toLowerCase()==="algorithm"?(i=n.substr(s,9),s+=9):(i=null,h('"algorithm"')),i!==null?(e=G(),e!==null?(n.substr(s,3).toLowerCase()==="md5"?(l=n.substr(s,3),s+=3):(l=null,h('"MD5"')),l===null&&(n.substr(s,8).toLowerCase()==="md5-sess"?(l=n.substr(s,8),s+=8):(l=null,h('"MD5-sess"')),l===null&&(l=U())),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.algorithm=m.toUpperCase()}(u,i[2])),i===null&&(s=u),i}function ui(){var i,e,l,u,f,p,m,v,S,O;if(v=s,n.substr(s,3).toLowerCase()==="qop"?(i=n.substr(s,3),s+=3):(i=null,h('"qop"')),i!==null)if(e=G(),e!==null)if(l=nt(),l!==null){if(S=s,u=_n(),u!==null){for(f=[],O=s,n.charCodeAt(s)===44?(p=",",s++):(p=null,h('","')),p!==null?(m=_n(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);p!==null;)f.push(p),O=s,n.charCodeAt(s)===44?(p=",",s++):(p=null,h('","')),p!==null?(m=_n(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);f!==null?u=[u,f]:(u=null,s=S)}else u=null,s=S;u!==null?(f=at(),f!==null?i=[i,e,l,u,f]:(i=null,s=v)):(i=null,s=v)}else i=null,s=v;else i=null,s=v;else i=null,s=v;return i}function _n(){var i,e;return e=s,n.substr(s,8).toLowerCase()==="auth-int"?(i=n.substr(s,8),s+=8):(i=null,h('"auth-int"')),i===null&&(n.substr(s,4).toLowerCase()==="auth"?(i=n.substr(s,4),s+=4):(i=null,h('"auth"')),i===null&&(i=U())),i!==null&&(i=function(l,u){b.qop||(b.qop=[]),b.qop.push(u.toLowerCase())}(e,i)),i===null&&(s=e),i}function Gn(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function no(){var i,e,l,u,f,p,m;if(f=s,p=s,i=Wn(),i!==null){for(e=[],m=s,l=Ce(),l!==null?(u=Wn(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=Ce(),l!==null?(u=Wn(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S,O;for(O=b.multi_header.length,S=0;S<O;S++)if(b.multi_header[S].parsed===null){b=null;break}b!==null?b=b.multi_header:b=-1}()),i===null&&(s=f),i}function Wn(){var i,e,l,u,f,p,m;if(f=s,p=s,i=$t(),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S;b.multi_header||(b.multi_header=[]);try{S=new fs(b.uri,b.display_name,b.params),delete b.uri,delete b.display_name,delete b.params}catch{S=null}b.multi_header.push({possition:s,offset:v,parsed:S})}(f)),i===null&&(s=f),i}function Kn(){var i,e,l,u,f,p,m;if(f=s,p=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"SIP"')),i===null&&(i=U()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=ci(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=ci(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v,S){if(b.protocol=S.toLowerCase(),b.params||(b.params={}),b.params.text&&b.params.text[0]==='"'){var O=b.params.text;b.text=O.substring(1,O.length-1),delete b.params.text}}(f,i[0])),i===null&&(s=f),i}function ci(){var i;return i=Yn(),i===null&&(i=Ge()),i}function Yn(){var i,e,l,u,f,p;if(f=s,p=s,n.substr(s,5).toLowerCase()==="cause"?(i=n.substr(s,5),s+=5):(i=null,h('"cause"')),i!==null)if(e=G(),e!==null){if(u=g(),u!==null)for(l=[];u!==null;)l.push(u),u=g();else l=null;l!==null?i=[i,e,l]:(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i!==null&&(i=function(m,v){b.cause=parseInt(v.join(""))}(f,i[2])),i===null&&(s=f),i}function Il(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function ro(){var i,e,l,u,f,p;if(f=s,i=Jn(),i!==null){for(e=[],p=s,l=Ce(),l!==null?(u=Jn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ce(),l!==null?(u=Jn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Jn(){var i,e,l,u,f,p;if(f=s,i=$t(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function zn(){var i,e,l,u,f,p;if(f=s,i=bl(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=Xn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=Xn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function bl(){var i,e;return e=s,n.substr(s,6).toLowerCase()==="active"?(i=n.substr(s,6),s+=6):(i=null,h('"active"')),i===null&&(n.substr(s,7).toLowerCase()==="pending"?(i=n.substr(s,7),s+=7):(i=null,h('"pending"')),i===null&&(n.substr(s,10).toLowerCase()==="terminated"?(i=n.substr(s,10),s+=10):(i=null,h('"terminated"')),i===null&&(i=U()))),i!==null&&(i=function(l){b.state=n.substring(s,l)}(e)),i===null&&(s=e),i}function Xn(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6).toLowerCase()==="reason"?(i=n.substr(s,6),s+=6):(i=null,h('"reason"')),i!==null?(e=G(),e!==null?(l=Qn(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){typeof m<"u"&&(b.reason=m)}(u,i[2])),i===null&&(s=u),i===null&&(u=s,f=s,n.substr(s,7).toLowerCase()==="expires"?(i=n.substr(s,7),s+=7):(i=null,h('"expires"')),i!==null?(e=G(),e!==null?(l=ts(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){typeof m<"u"&&(b.expires=m)}(u,i[2])),i===null&&(s=u),i===null&&(u=s,f=s,n.substr(s,11).toLowerCase()==="retry_after"?(i=n.substr(s,11),s+=11):(i=null,h('"retry_after"')),i!==null?(e=G(),e!==null?(l=ts(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){typeof m<"u"&&(b.retry_after=m)}(u,i[2])),i===null&&(s=u),i===null&&(i=Ge()))),i}function Qn(){var i;return n.substr(s,11).toLowerCase()==="deactivated"?(i=n.substr(s,11),s+=11):(i=null,h('"deactivated"')),i===null&&(n.substr(s,9).toLowerCase()==="probation"?(i=n.substr(s,9),s+=9):(i=null,h('"probation"')),i===null&&(n.substr(s,8).toLowerCase()==="rejected"?(i=n.substr(s,8),s+=8):(i=null,h('"rejected"')),i===null&&(n.substr(s,7).toLowerCase()==="timeout"?(i=n.substr(s,7),s+=7):(i=null,h('"timeout"')),i===null&&(n.substr(s,6).toLowerCase()==="giveup"?(i=n.substr(s,6),s+=6):(i=null,h('"giveup"')),i===null&&(n.substr(s,10).toLowerCase()==="noresource"?(i=n.substr(s,10),s+=10):(i=null,h('"noresource"')),i===null&&(n.substr(s,9).toLowerCase()==="invariant"?(i=n.substr(s,9),s+=9):(i=null,h('"invariant"')),i===null&&(i=U()))))))),i}function wl(){var i;return i=B(),i=i!==null?i:"",i}function io(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ce(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i=i!==null?i:"",i}function lo(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=$t()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=fi(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=fi(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S=b.tag;try{b=new fs(b.uri,b.display_name,b.params),S&&b.setParam("tag",S)}catch{b=-1}}()),i===null&&(s=f),i}function fi(){var i;return i=cn(),i===null&&(i=Ge()),i}function hi(){var i,e,l,u,f,p;if(f=s,i=Zn(),i!==null){for(e=[],p=s,l=Ce(),l!==null?(u=Zn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ce(),l!==null?(u=Zn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Zn(){var i,e,l,u,f,p,m,v;if(m=s,i=Ti(),i!==null)if(e=ve(),e!==null)if(l=Si(),l!==null){for(u=[],v=s,f=le(),f!==null?(p=xs(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=le(),f!==null?(p=xs(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i}function xs(){var i;return i=er(),i===null&&(i=di(),i===null&&(i=_i(),i===null&&(i=pi(),i===null&&(i=mi(),i===null&&(i=Ge()))))),i}function er(){var i,e,l,u,f;return u=s,f=s,n.substr(s,3).toLowerCase()==="ttl"?(i=n.substr(s,3),s+=3):(i=null,h('"ttl"')),i!==null?(e=G(),e!==null?(l=tr(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.ttl=m}(u,i[2])),i===null&&(s=u),i}function di(){var i,e,l,u,f;return u=s,f=s,n.substr(s,5).toLowerCase()==="maddr"?(i=n.substr(s,5),s+=5):(i=null,h('"maddr"')),i!==null?(e=G(),e!==null?(l=es(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.maddr=m}(u,i[2])),i===null&&(s=u),i}function _i(){var i,e,l,u,f;return u=s,f=s,n.substr(s,8).toLowerCase()==="received"?(i=n.substr(s,8),s+=8):(i=null,h('"received"')),i!==null?(e=G(),e!==null?(l=ot(),l===null&&(l=zs()),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.received=m}(u,i[2])),i===null&&(s=u),i}function pi(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6).toLowerCase()==="branch"?(i=n.substr(s,6),s+=6):(i=null,h('"branch"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.branch=m}(u,i[2])),i===null&&(s=u),i}function mi(){var i,e,l,u,f;return u=s,n.substr(s,5).toLowerCase()==="rport"?(i=n.substr(s,5),s+=5):(i=null,h('"rport"')),i!==null?(f=s,e=G(),e!==null?(l=gi(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function gi(){var i,e,l,u,f,p,m;return p=s,m=s,i=g(),i=i!==null?i:"",i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?i=[i,e,l,u,f]:(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(v,S){b.rport=parseInt(S.join(""))}(p,i)),i===null&&(s=p),i}function Ti(){var i,e,l,u,f,p;return p=s,i=vi(),i!==null?(e=W(),e!==null?(l=U(),l!==null?(u=W(),u!==null?(f=Ei(),f!==null?i=[i,e,l,u,f]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i}function vi(){var i,e;return e=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"SIP"')),i===null&&(i=U()),i!==null&&(i=function(l,u){b.protocol=u}(e,i)),i===null&&(s=e),i}function Ei(){var i,e;return e=s,n.substr(s,3).toLowerCase()==="udp"?(i=n.substr(s,3),s+=3):(i=null,h('"UDP"')),i===null&&(n.substr(s,3).toLowerCase()==="tcp"?(i=n.substr(s,3),s+=3):(i=null,h('"TCP"')),i===null&&(n.substr(s,3).toLowerCase()==="tls"?(i=n.substr(s,3),s+=3):(i=null,h('"TLS"')),i===null&&(n.substr(s,4).toLowerCase()==="sctp"?(i=n.substr(s,4),s+=4):(i=null,h('"SCTP"')),i===null&&(i=U())))),i!==null&&(i=function(l,u){b.transport=u}(e,i)),i===null&&(s=e),i}function Si(){var i,e,l,u,f;return u=s,i=yi(),i!==null?(f=s,e=ye(),e!==null?(l=Ai(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function yi(){var i,e;return e=s,i=ot(),i===null&&(i=Nn(),i===null&&(i=us())),i!==null&&(i=function(l){b.host=n.substring(s,l)}(e)),i===null&&(s=e),i}function Ai(){var i,e,l,u,f,p,m;return p=s,m=s,i=g(),i=i!==null?i:"",i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?i=[i,e,l,u,f]:(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(v,S){b.port=parseInt(S.join(""))}(p,i)),i===null&&(s=p),i}function tr(){var i,e,l,u,f;return u=s,f=s,i=g(),i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){return parseInt(m.join(""))}(u,i)),i===null&&(s=u),i}function Ci(){var i;return i=si(),i}function ao(){var i,e,l,u,f,p;if(f=s,i=Ol(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=sr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=sr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Ol(){var i,e;return e=s,i=ts(),i!==null&&(i=function(l,u){b.expires=u}(e,i)),i===null&&(s=e),i}function sr(){var i;return i=nr(),i===null&&(i=Ge()),i}function nr(){var i,e,l,u,f;return u=s,f=s,n.substr(s,9).toLowerCase()==="refresher"?(i=n.substr(s,9),s+=9):(i=null,h('"refresher"')),i!==null?(e=G(),e!==null?(n.substr(s,3).toLowerCase()==="uac"?(l=n.substr(s,3),s+=3):(l=null,h('"uac"')),l===null&&(n.substr(s,3).toLowerCase()==="uas"?(l=n.substr(s,3),s+=3):(l=null,h('"uas"'))),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.refresher=m.toLowerCase()}(u,i[2])),i===null&&(s=u),i}function Dl(){var i,e,l,u;return u=s,i=U(),i!==null?(e=D(),e!==null?(l=Nl(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Nl(){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 Ul(){var i,e;for(i=[],e=A();e!==null;)i.push(e),e=A();return i}function oo(){var i,e,l;return l=s,n.substr(s,5)==="uuid:"?(i="uuid:",s+=5):(i=null,h('"uuid:"')),i!==null?(e=Pl(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function Pl(){var i,e,l,u,f,p,m,v,S,O,ie;return O=s,ie=s,i=jt(),i!==null?(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e!==null?(l=Ft(),l!==null?(n.charCodeAt(s)===45?(u="-",s++):(u=null,h('"-"')),u!==null?(f=Ft(),f!==null?(n.charCodeAt(s)===45?(p="-",s++):(p=null,h('"-"')),p!==null?(m=Ft(),m!==null?(n.charCodeAt(s)===45?(v="-",s++):(v=null,h('"-"')),v!==null?(S=Ri(),S!==null?i=[i,e,l,u,f,p,m,v,S]:(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie),i!==null&&(i=function(Ue,wt){b=n.substring(s+5,Ue)}(O,i[0])),i===null&&(s=O),i}function Ft(){var i,e,l,u,f;return f=s,i=E(),i!==null?(e=E(),e!==null?(l=E(),l!==null?(u=E(),u!==null?i=[i,e,l,u]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i}function jt(){var i,e,l;return l=s,i=Ft(),i!==null?(e=Ft(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function Ri(){var i,e,l,u;return u=s,i=Ft(),i!==null?(e=Ft(),e!==null?(l=Ft(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function xl(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=$t()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){try{b=new fs(b.uri,b.display_name,b.params)}catch{b=-1}}()),i===null&&(s=f),i}function uo(){var i,e,l,u,f,p;if(f=s,i=kl(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=rr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=rr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function kl(){var i,e,l,u,f,p;return u=s,f=s,i=st(),i!==null?(p=s,n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e!==null?(l=st(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b.call_id=n.substring(s,m)}(u)),i===null&&(s=u),i}function rr(){var i;return i=ir(),i===null&&(i=Ii(),i===null&&(i=bi(),i===null&&(i=Ge()))),i}function ir(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6)==="to-tag"?(i="to-tag",s+=6):(i=null,h('"to-tag"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.to_tag=m}(u,i[2])),i===null&&(s=u),i}function Ii(){var i,e,l,u,f;return u=s,f=s,n.substr(s,8)==="from-tag"?(i="from-tag",s+=8):(i=null,h('"from-tag"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.from_tag=m}(u,i[2])),i===null&&(s=u),i}function bi(){var i,e;return e=s,n.substr(s,10)==="early-only"?(i="early-only",s+=10):(i=null,h('"early-only"')),i!==null&&(i=function(l){b.early_only=!0}()),i===null&&(s=e),i}function Ml(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 co(){for(var i=1,e=1,l=!1,u=0;u<Math.max(s,r);u++){var f=n.charAt(u);f===`
|
75
|
-
`?(l||i++,e=1,l=!1):f==="\r"||f==="\u2028"||f==="\u2029"?(i++,e=1,l=!0):(e++,l=!1)}return{line:i,column:e}}var Ll=ys(),fs=$u(),b={},w=o[a]();if(w===null||s!==n.length){var wi=Math.max(s,r),Oi=wi<n.length?n.charAt(wi):null,$l=co();return new this.SyntaxError(Ml(d),Oi,wi,$l.line,$l.column),-1}return b},toSource:function(){return this._source}};return t.SyntaxError=function(n,a,o,s,r){function d(h,_){var g,T;switch(h.length){case 0:g="end of input";break;case 1:g=h[0];break;default:g=h.slice(0,h.length-1).join(", ")+" or "+h[h.length-1]}return T=_?c(_):"end of input","Expected "+g+" but "+T+" found."}this.name="SyntaxError",this.expected=n,this.found=a,this.message=d(n,a),this.offset=o,this.line=s,this.column=r},t.SyntaxError.prototype=Error.prototype,t}()),Mo}var Lo,sf;function ys(){if(sf)return Lo;sf=1;const c=De,t=At(),n=Zt();return Lo=class ch{static parse(o){if(o=n.parse(o,"SIP_URI"),o!==-1)return o}constructor(o,s,r,d,h={},_={}){if(!r)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=o||c.SIP,this._user=s,this._host=r,this._port=d;for(const g in h)Object.prototype.hasOwnProperty.call(h,g)&&this.setParam(g,h[g]);for(const g in _)Object.prototype.hasOwnProperty.call(_,g)&&this.setHeader(g,_[g])}get scheme(){return this._scheme}set scheme(o){this._scheme=o.toLowerCase()}get user(){return this._user}set user(o){this._user=o}get host(){return this._host}set host(o){this._host=o.toLowerCase()}get port(){return this._port}set port(o){this._port=o===0?o:parseInt(o,10)||null}setParam(o,s){o&&(this._parameters[o.toLowerCase()]=typeof s>"u"||s===null?null:s.toString())}getParam(o){if(o)return this._parameters[o.toLowerCase()]}hasParam(o){if(o)return this._parameters.hasOwnProperty(o.toLowerCase())&&!0||!1}deleteParam(o){if(o=o.toLowerCase(),this._parameters.hasOwnProperty(o)){const s=this._parameters[o];return delete this._parameters[o],s}}clearParams(){this._parameters={}}setHeader(o,s){this._headers[t.headerize(o)]=Array.isArray(s)?s:[s]}getHeader(o){if(o)return this._headers[t.headerize(o)]}hasHeader(o){if(o)return this._headers.hasOwnProperty(t.headerize(o))&&!0||!1}deleteHeader(o){if(o=t.headerize(o),this._headers.hasOwnProperty(o)){const s=this._headers[o];return delete this._headers[o],s}}clearHeaders(){this._headers={}}clone(){return new ch(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}toString(){const o=[];let s=`${this._scheme}:`;this._user&&(s+=`${t.escapeUser(this._user)}@`),s+=this._host,(this._port||this._port===0)&&(s+=`:${this._port}`);for(const r in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,r)&&(s+=`;${r}`,this._parameters[r]!==null&&(s+=`=${this._parameters[r]}`));for(const r in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,r))for(const d of this._headers[r])o.push(`${r}=${d}`);return o.length>0&&(s+=`?${o.join("&")}`),s}toAor(o){let s=`${this._scheme}:`;return this._user&&(s+=`${t.escapeUser(this._user)}@`),s+=this._host,o&&(this._port||this._port===0)&&(s+=`:${this._port}`),s}},Lo}var nf;function At(){if(nf)return et;nf=1;const c=De,t=ys(),n=Zt();et.str_utf8_length=r=>unescape(encodeURIComponent(r)).length;const a=et.isFunction=r=>r!==void 0?Object.prototype.toString.call(r)==="[object Function]":!1;et.isString=r=>r!==void 0?Object.prototype.toString.call(r)==="[object String]":!1,et.isDecimal=r=>!isNaN(r)&&parseFloat(r)===parseInt(r,10),et.isEmpty=r=>r===null||r===""||r===void 0||Array.isArray(r)&&r.length===0||typeof r=="number"&&isNaN(r),et.hasMethods=function(r,...d){for(const h of d)if(a(r[h]))return!1;return!0};const o=et.createRandomToken=(r,d=32)=>{let h,_,g="";for(h=0;h<r;h++)_=Math.random()*d|0,g+=_.toString(d);return g};et.newTag=()=>o(10),et.newUUID=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,d=>{const h=Math.random()*16|0;return(d==="x"?h:h&3|8).toString(16)}),et.hostType=r=>{if(r){if(r=n.parse(r,"host"),r!==-1)return r.host_type}else return};const s=et.escapeUser=r=>encodeURIComponent(decodeURIComponent(r)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/");return et.normalizeTarget=(r,d)=>{if(r){if(r instanceof t)return r;if(typeof r=="string"){const h=r.split("@");let _,g;switch(h.length){case 1:if(!d)return;_=r,g=d;break;case 2:_=h[0],g=h[1];break;default:_=h.slice(0,h.length-1).join("@"),g=h[h.length-1]}_=_.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(_)&&(_=_.replace(/[-.()]/g,"")),r=`${c.SIP}:${s(_)}@${g}`;let T;return(T=t.parse(r))?T:void 0}else return}else return},et.headerize=r=>{const d={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},h=r.toLowerCase().replace(/_/g,"-").split("-");let _="";const g=h.length;let T;for(T=0;T<g;T++)T!==0&&(_+="-"),_+=h[T].charAt(0).toUpperCase()+h[T].substring(1);return d[_]&&(_=d[_]),_},et.sipErrorCause=r=>{for(const d in c.SIP_ERROR_CAUSES)if(c.SIP_ERROR_CAUSES[d].indexOf(r)!==-1)return c.causes[d];return c.causes.SIP_FAILURE_CODE},et.getRandomTestNetIP=()=>{function r(d,h){return Math.floor(Math.random()*(h-d+1)+d)}return`192.0.2.${r(1,254)}`},et.calculateMD5=r=>{function d(Ee,Ae){return Ee<<Ae|Ee>>>32-Ae}function h(Ee,Ae){const Ie=Ee&2147483648,Oe=Ae&2147483648,pe=Ee&1073741824,ue=Ae&1073741824,_e=(Ee&1073741823)+(Ae&1073741823);return pe&ue?_e^2147483648^Ie^Oe:pe|ue?_e&1073741824?_e^3221225472^Ie^Oe:_e^1073741824^Ie^Oe:_e^Ie^Oe}function _(Ee,Ae,Ie){return Ee&Ae|~Ee&Ie}function g(Ee,Ae,Ie){return Ee&Ie|Ae&~Ie}function T(Ee,Ae,Ie){return Ee^Ae^Ie}function E(Ee,Ae,Ie){return Ae^(Ee|~Ie)}function y(Ee,Ae,Ie,Oe,pe,ue,_e){return Ee=h(Ee,h(h(_(Ae,Ie,Oe),pe),_e)),h(d(Ee,ue),Ae)}function A(Ee,Ae,Ie,Oe,pe,ue,_e){return Ee=h(Ee,h(h(g(Ae,Ie,Oe),pe),_e)),h(d(Ee,ue),Ae)}function C(Ee,Ae,Ie,Oe,pe,ue,_e){return Ee=h(Ee,h(h(T(Ae,Ie,Oe),pe),_e)),h(d(Ee,ue),Ae)}function I(Ee,Ae,Ie,Oe,pe,ue,_e){return Ee=h(Ee,h(h(E(Ae,Ie,Oe),pe),_e)),h(d(Ee,ue),Ae)}function H(Ee){let Ae;const Ie=Ee.length,Oe=Ie+8,ue=((Oe-Oe%64)/64+1)*16,_e=new Array(ue-1);let we=0,Ne=0;for(;Ne<Ie;)Ae=(Ne-Ne%4)/4,we=Ne%4*8,_e[Ae]=_e[Ae]|Ee.charCodeAt(Ne)<<we,Ne++;return Ae=(Ne-Ne%4)/4,we=Ne%4*8,_e[Ae]=_e[Ae]|128<<we,_e[ue-2]=Ie<<3,_e[ue-1]=Ie>>>29,_e}function $(Ee){let Ae="",Ie="",Oe,pe;for(pe=0;pe<=3;pe++)Oe=Ee>>>pe*8&255,Ie=`0${Oe.toString(16)}`,Ae=Ae+Ie.substr(Ie.length-2,2);return Ae}function oe(Ee){let Ae="";for(let Ie=0;Ie<Ee.length;Ie++){const Oe=Ee.charCodeAt(Ie);Oe<128?Ae+=String.fromCharCode(Oe):Oe>127&&Oe<2048?(Ae+=String.fromCharCode(Oe>>6|192),Ae+=String.fromCharCode(Oe&63|128)):(Ae+=String.fromCharCode(Oe>>12|224),Ae+=String.fromCharCode(Oe>>6&63|128),Ae+=String.fromCharCode(Oe&63|128))}return Ae}let N=[],j,Se,ve,k,D,B,V,J,F;const X=7,U=12,P=17,se=22,st=5,ee=9,W=14,G=20,re=4,ge=11,be=16,xe=23,Ce=6,le=10,ye=15,nt=21;for(r=oe(r),N=H(r),B=1732584193,V=4023233417,J=2562383102,F=271733878,j=0;j<N.length;j+=16)Se=B,ve=V,k=J,D=F,B=y(B,V,J,F,N[j+0],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],st,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],st,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],st,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],st,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],nt,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],nt,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],nt,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],nt,3951481745),B=h(B,Se),V=h(V,ve),J=h(J,k),F=h(F,D);return($(B)+$(V)+$(J)+$(F)).toLowerCase()},et.closeMediaStream=r=>{if(r)try{let d;if(r.getTracks){d=r.getTracks();for(const h of d)h.stop()}else{d=r.getAudioTracks();for(const h of d)h.stop();d=r.getVideoTracks();for(const h of d)h.stop()}}catch{(typeof r.stop=="function"||typeof r.stop=="object")&&r.stop()}},et.cloneArray=r=>r&&r.slice()||[],et.cloneObject=(r,d={})=>r&&Object.assign({},r)||d,et}const fh=xt,qm=ut,St=De,it=At(),rf=$u(),Vm=Zt(),$o=new qm("SIPMessage");class Ka{constructor(t,n,a,o,s,r){if(!t||!n||!a)return null;o=o||{},this.ua=a,this.headers={},this.method=t,this.ruri=n,this.body=r,this.extraHeaders=it.cloneArray(s),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),o.route_set?this.setHeader("route",o.route_set):a.configuration.use_preloaded_route&&this.setHeader("route",`<${a.transport.sip_uri};lr>`),this.setHeader("via",""),this.setHeader("max-forwards",St.MAX_FORWARDS);const d=o.to_uri||n,h=o.to_tag?{tag:o.to_tag}:null,_=typeof o.to_display_name<"u"?o.to_display_name:null;this.to=new rf(d,_,h),this.setHeader("to",this.to.toString());const g=o.from_uri||a.configuration.uri,T={tag:o.from_tag||it.newTag()};let E;typeof o.from_display_name<"u"?E=o.from_display_name:a.configuration.display_name?E=a.configuration.display_name:E=null,this.from=new rf(g,E,T),this.setHeader("from",this.from.toString());const y=o.call_id||a.configuration.jssip_id+it.createRandomToken(15);this.call_id=y,this.setHeader("call-id",y);const A=o.cseq||Math.floor(Math.random()*1e4);this.cseq=A,this.setHeader("cseq",`${A} ${t}`)}setHeader(t,n){const a=new RegExp(`^\\s*${t}\\s*:`,"i");for(let o=0;o<this.extraHeaders.length;o++)a.test(this.extraHeaders[o])&&this.extraHeaders.splice(o,1);this.headers[it.headerize(t)]=Array.isArray(n)?n:[n]}getHeader(t){const n=this.headers[it.headerize(t)];if(n){if(n[0])return n[0]}else{const a=new RegExp(`^\\s*${t}\\s*:`,"i");for(const o of this.extraHeaders)if(a.test(o))return o.substring(o.indexOf(":")+1).trim()}}getHeaders(t){const n=this.headers[it.headerize(t)],a=[];if(n){for(const o of n)a.push(o);return a}else{const o=new RegExp(`^\\s*${t}\\s*:`,"i");for(const s of this.extraHeaders)o.test(s)&&a.push(s.substring(s.indexOf(":")+1).trim());return a}}hasHeader(t){if(this.headers[it.headerize(t)])return!0;{const n=new RegExp(`^\\s*${t}\\s*:`,"i");for(const a of this.extraHeaders)if(n.test(a))return!0}return!1}parseSDP(t){return!t&&this.sdp?this.sdp:(this.sdp=fh.parse(this.body||""),this.sdp)}toString(){let t=`${this.method} ${this.ruri} SIP/2.0\r
|
74
|
+
`,s+=2):(i=null,h('"\\r\\n"')),i}function g(){var i;return/^[0-9]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[0-9]")),i}function T(){var i;return/^[a-zA-Z]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[a-zA-Z]")),i}function E(){var i;return/^[0-9a-fA-F]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[0-9a-fA-F]")),i}function y(){var i;return i=I(),i===null&&(i=H()),i}function C(){var i;return/^[\0-\xFF]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\0-\\xFF]")),i}function A(){var i;return/^["]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h('["]')),i}function I(){var i;return n.charCodeAt(s)===32?(i=" ",s++):(i=null,h('" "')),i}function H(){var i;return n.charCodeAt(s)===9?(i=" ",s++):(i=null,h('"\\t"')),i}function $(){var i;return/^[a-zA-Z0-9]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[a-zA-Z0-9]")),i}function oe(){var i;return n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","'))))))))))),i}function N(){var i;return i=$(),i===null&&(i=j()),i}function j(){var i;return n.charCodeAt(s)===45?(i="-",s++):(i=null,h('"-"')),i===null&&(n.charCodeAt(s)===95?(i="_",s++):(i=null,h('"_"')),i===null&&(n.charCodeAt(s)===46?(i=".",s++):(i=null,h('"."')),i===null&&(n.charCodeAt(s)===33?(i="!",s++):(i=null,h('"!"')),i===null&&(n.charCodeAt(s)===126?(i="~",s++):(i=null,h('"~"')),i===null&&(n.charCodeAt(s)===42?(i="*",s++):(i=null,h('"*"')),i===null&&(n.charCodeAt(s)===39?(i="'",s++):(i=null,h(`"'"`)),i===null&&(n.charCodeAt(s)===40?(i="(",s++):(i=null,h('"("')),i===null&&(n.charCodeAt(s)===41?(i=")",s++):(i=null,h('")"')))))))))),i}function Se(){var i,e,l,u,f;return u=s,f=s,n.charCodeAt(s)===37?(i="%",s++):(i=null,h('"%"')),i!==null?(e=E(),e!==null?(l=E(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){return m.join("")}(u,i)),i===null&&(s=u),i}function ve(){var i,e,l,u,f,p;for(u=s,f=s,p=s,i=[],e=y();e!==null;)i.push(e),e=y();if(i!==null?(e=_(),e!==null?i=[i,e]:(i=null,s=p)):(i=null,s=p),i=i!==null?i:"",i!==null){if(l=y(),l!==null)for(e=[];l!==null;)e.push(l),l=y();else e=null;e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i!==null&&(i=function(m){return" "}()),i===null&&(s=u),i}function k(){var i;return i=ve(),i=i!==null?i:"",i}function D(){var i,e,l,u,f;for(u=s,f=s,i=[],e=I(),e===null&&(e=H());e!==null;)i.push(e),e=I(),e===null&&(e=H());return i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return":"}()),i===null&&(s=u),i}function B(){var i,e,l,u,f,p,m;if(f=s,p=s,e=V(),e!==null)for(i=[];e!==null;)i.push(e),e=V();else i=null;if(i!==null){for(e=[],m=s,l=[],u=ve();u!==null;)l.push(u),u=ve();for(l!==null?(u=V(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;){for(e.push(l),m=s,l=[],u=ve();u!==null;)l.push(u),u=ve();l!==null?(u=V(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m)}e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){return n.substring(s,v)}(f)),i===null&&(s=f),i}function V(){var i;return/^[!-~]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[!-~]")),i===null&&(i=J()),i}function J(){var i;return/^[\x80-\uFFFF]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\x80-\\uFFFF]")),i}function F(){var i;return/^[\x80-\xBF]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\x80-\\xBF]")),i}function X(){var i;return i=g(),i===null&&(/^[a-f]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[a-f]"))),i}function U(){var i,e,l;if(l=s,e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"'))))))))))));else i=null;return i!==null&&(i=function(u){return n.substring(s,u)}(l)),i===null&&(s=l),i}function P(){var i,e,l;if(l=s,e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"'))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')))))))))));else i=null;return i!==null&&(i=function(u){return n.substring(s,u)}(l)),i===null&&(s=l),i}function se(){var i;return n.charCodeAt(s)===40?(i="(",s++):(i=null,h('"("')),i===null&&(n.charCodeAt(s)===41?(i=")",s++):(i=null,h('")"')),i===null&&(n.charCodeAt(s)===60?(i="<",s++):(i=null,h('"<"')),i===null&&(n.charCodeAt(s)===62?(i=">",s++):(i=null,h('">"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===92?(i="\\",s++):(i=null,h('"\\\\"')),i===null&&(i=A(),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i===null&&(n.charCodeAt(s)===93?(i="]",s++):(i=null,h('"]"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===123?(i="{",s++):(i=null,h('"{"')),i===null&&(n.charCodeAt(s)===125?(i="}",s++):(i=null,h('"}"')),i===null&&(i=I(),i===null&&(i=H())))))))))))))))))),i}function st(){var i,e,l;if(l=s,e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')),e===null&&(n.charCodeAt(s)===40?(e="(",s++):(e=null,h('"("')),e===null&&(n.charCodeAt(s)===41?(e=")",s++):(e=null,h('")"')),e===null&&(n.charCodeAt(s)===60?(e="<",s++):(e=null,h('"<"')),e===null&&(n.charCodeAt(s)===62?(e=">",s++):(e=null,h('">"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===92?(e="\\",s++):(e=null,h('"\\\\"')),e===null&&(e=A(),e===null&&(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e===null&&(n.charCodeAt(s)===91?(e="[",s++):(e=null,h('"["')),e===null&&(n.charCodeAt(s)===93?(e="]",s++):(e=null,h('"]"')),e===null&&(n.charCodeAt(s)===63?(e="?",s++):(e=null,h('"?"')),e===null&&(n.charCodeAt(s)===123?(e="{",s++):(e=null,h('"{"')),e===null&&(n.charCodeAt(s)===125?(e="}",s++):(e=null,h('"}"'))))))))))))))))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=$(),e===null&&(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e===null&&(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e===null&&(n.charCodeAt(s)===33?(e="!",s++):(e=null,h('"!"')),e===null&&(n.charCodeAt(s)===37?(e="%",s++):(e=null,h('"%"')),e===null&&(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e===null&&(n.charCodeAt(s)===95?(e="_",s++):(e=null,h('"_"')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===96?(e="`",s++):(e=null,h('"`"')),e===null&&(n.charCodeAt(s)===39?(e="'",s++):(e=null,h(`"'"`)),e===null&&(n.charCodeAt(s)===126?(e="~",s++):(e=null,h('"~"')),e===null&&(n.charCodeAt(s)===40?(e="(",s++):(e=null,h('"("')),e===null&&(n.charCodeAt(s)===41?(e=")",s++):(e=null,h('")"')),e===null&&(n.charCodeAt(s)===60?(e="<",s++):(e=null,h('"<"')),e===null&&(n.charCodeAt(s)===62?(e=">",s++):(e=null,h('">"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===92?(e="\\",s++):(e=null,h('"\\\\"')),e===null&&(e=A(),e===null&&(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e===null&&(n.charCodeAt(s)===91?(e="[",s++):(e=null,h('"["')),e===null&&(n.charCodeAt(s)===93?(e="]",s++):(e=null,h('"]"')),e===null&&(n.charCodeAt(s)===63?(e="?",s++):(e=null,h('"?"')),e===null&&(n.charCodeAt(s)===123?(e="{",s++):(e=null,h('"{"')),e===null&&(n.charCodeAt(s)===125?(e="}",s++):(e=null,h('"}"')))))))))))))))))))))))));else i=null;return i!==null&&(i=function(u){return n.substring(s,u)}(l)),i===null&&(s=l),i}function ee(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===42?(e="*",s++):(e=null,h('"*"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"*"}()),i===null&&(s=u),i}function W(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"/"}()),i===null&&(s=u),i}function G(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"="}()),i===null&&(s=u),i}function re(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===40?(e="(",s++):(e=null,h('"("')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return"("}()),i===null&&(s=u),i}function ge(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===41?(e=")",s++):(e=null,h('")"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return")"}()),i===null&&(s=u),i}function be(){var i,e,l,u;return l=s,u=s,n.charCodeAt(s)===62?(i=">",s++):(i=null,h('">"')),i!==null?(e=k(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return">"}()),i===null&&(s=l),i}function xe(){var i,e,l,u;return l=s,u=s,i=k(),i!==null?(n.charCodeAt(s)===60?(e="<",s++):(e=null,h('"<"')),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return"<"}()),i===null&&(s=l),i}function Ae(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return","}()),i===null&&(s=u),i}function le(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return";"}()),i===null&&(s=u),i}function ye(){var i,e,l,u,f;return u=s,f=s,i=k(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=k(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return":"}()),i===null&&(s=u),i}function nt(){var i,e,l,u;return l=s,u=s,i=k(),i!==null?(e=A(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return'"'}()),i===null&&(s=l),i}function at(){var i,e,l,u;return l=s,u=s,i=A(),i!==null?(e=k(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f){return'"'}()),i===null&&(s=l),i}function Ee(){var i,e,l,u;if(u=s,i=re(),i!==null){for(e=[],l=Ce(),l===null&&(l=ue(),l===null&&(l=Ee()));l!==null;)e.push(l),l=Ce(),l===null&&(l=ue(),l===null&&(l=Ee()));e!==null?(l=ge(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)}else i=null,s=u;return i}function Ce(){var i;return/^[!-']/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[!-']")),i===null&&(/^[*-[]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[*-[]")),i===null&&(/^[\]-~]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\]-~]")),i===null&&(i=J(),i===null&&(i=ve())))),i}function Ie(){var i,e,l,u,f,p;if(f=s,p=s,i=k(),i!==null)if(e=A(),e!==null){for(l=[],u=pe(),u===null&&(u=ue());u!==null;)l.push(u),u=pe(),u===null&&(u=ue());l!==null?(u=A(),u!==null?i=[i,e,l,u]:(i=null,s=p)):(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i!==null&&(i=function(m){return n.substring(s,m)}(f)),i===null&&(s=f),i}function Oe(){var i,e,l,u,f,p;if(f=s,p=s,i=k(),i!==null)if(e=A(),e!==null){for(l=[],u=pe(),u===null&&(u=ue());u!==null;)l.push(u),u=pe(),u===null&&(u=ue());l!==null?(u=A(),u!==null?i=[i,e,l,u]:(i=null,s=p)):(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i!==null&&(i=function(m){var v=n.substring(s,m).trim();return v.substring(1,v.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")}(f)),i===null&&(s=f),i}function pe(){var i;return i=ve(),i===null&&(n.charCodeAt(s)===33?(i="!",s++):(i=null,h('"!"')),i===null&&(/^[#-[]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[#-[]")),i===null&&(/^[\]-~]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[\\]-~]")),i===null&&(i=J())))),i}function ue(){var i,e,l;return l=s,n.charCodeAt(s)===92?(i="\\",s++):(i=null,h('"\\\\"')),i!==null?(/^[\0-\t]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[\\0-\\t]")),e===null&&(/^[\x0B-\f]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[\\x0B-\\f]")),e===null&&(/^[\x0E-]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[\\x0E-]")))),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function _e(){var i,e,l,u,f,p;return f=s,p=s,i=Ne(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=Lt(),l=l!==null?l:"",l!==null?(u=Ys(),u!==null?i=[i,e,l,u]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i!==null&&(i=function(m){try{b.uri=new Ll(b.scheme,b.user,b.host,b.port),delete b.scheme,delete b.user,delete b.host,delete b.host_type,delete b.port}catch{b=-1}}()),i===null&&(s=f),i}function we(){var i,e,l,u,f,p,m,v;return m=s,v=s,i=Ne(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=Lt(),l=l!==null?l:"",l!==null?(u=Ys(),u!==null?(f=Er(),f!==null?(p=Or(),p=p!==null?p:"",p!==null?i=[i,e,l,u,f,p]:(i=null,s=v)):(i=null,s=v)):(i=null,s=v)):(i=null,s=v)):(i=null,s=v)):(i=null,s=v),i!==null&&(i=function(S){try{b.uri=new Ll(b.scheme,b.user,b.host,b.port,b.uri_params,b.uri_headers),delete b.scheme,delete b.user,delete b.host,delete b.host_type,delete b.port,delete b.uri_params,a==="SIP_URI"&&(b=b.uri)}catch{b=-1}}()),i===null&&(s=m),i}function Ne(){var i;return i=Qe(),i===null&&(i=Le()),i}function Qe(){var i,e;return e=s,n.substr(s,4).toLowerCase()==="sips"?(i=n.substr(s,4),s+=4):(i=null,h('"sips"')),i!==null&&(i=function(l,u){b.scheme=u.toLowerCase()}(e,i)),i===null&&(s=e),i}function Le(){var i,e;return e=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"sip"')),i!==null&&(i=function(l,u){b.scheme=u.toLowerCase()}(e,i)),i===null&&(s=e),i}function Lt(){var i,e,l,u,f,p;return u=s,f=s,i=dt(),i!==null?(p=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=On(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?(n.charCodeAt(s)===64?(l="@",s++):(l=null,h('"@"')),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b.user=decodeURIComponent(n.substring(s-1,m))}(u)),i===null&&(s=u),i}function dt(){var i,e;if(e=N(),e===null&&(e=Se(),e===null&&(e=wn())),e!==null)for(i=[];e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(e=wn()));else i=null;return i}function wn(){var i;return n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"'))))))))),i}function On(){var i,e,l;for(l=s,i=[],e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","'))))))));e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","'))))))));return i!==null&&(i=function(u){b.password=n.substring(s,u)}(l)),i===null&&(s=l),i}function Ys(){var i,e,l,u,f;return u=s,i=es(),i!==null?(f=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=As(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function es(){var i,e;return e=s,i=us(),i===null&&(i=ot(),i===null&&(i=Nn())),i!==null&&(i=function(l){return b.host=n.substring(s,l).toLowerCase(),b.host}(e)),i===null&&(s=e),i}function us(){var i,e,l,u,f,p;for(u=s,f=s,i=[],p=s,e=Js(),e!==null?(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p);e!==null;)i.push(e),p=s,e=Js(),e!==null?(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p);return i!==null?(e=Dn(),e!==null?(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l=l!==null?l:"",l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){return b.host_type="domain",n.substring(s,m)}(u)),i===null&&(s=u),i}function Js(){var i,e,l,u;if(u=s,i=$(),i!==null){for(e=[],l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));l!==null;)e.push(l),l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));e!==null?i=[i,e]:(i=null,s=u)}else i=null,s=u;return i}function Dn(){var i,e,l,u;if(u=s,i=T(),i!==null){for(e=[],l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));l!==null;)e.push(l),l=$(),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===95?(l="_",s++):(l=null,h('"_"'))));e!==null?i=[i,e]:(i=null,s=u)}else i=null,s=u;return i}function Nn(){var i,e,l,u,f;return u=s,f=s,n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i!==null?(e=zs(),e!==null?(n.charCodeAt(s)===93?(l="]",s++):(l=null,h('"]"')),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p){return b.host_type="IPv6",n.substring(s,p)}(u)),i===null&&(s=u),i}function zs(){var i,e,l,u,f,p,m,v,S,O,ie,Ue,wt,ks,M,R;return ks=s,M=s,i=me(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?(n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?(n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?(n.charCodeAt(s)===58?(v=":",s++):(v=null,h('":"')),v!==null?(S=me(),S!==null?(n.charCodeAt(s)===58?(O=":",s++):(O=null,h('":"')),O!==null?(ie=me(),ie!==null?(n.charCodeAt(s)===58?(Ue=":",s++):(Ue=null,h('":"')),Ue!==null?(wt=ae(),wt!==null?i=[i,e,l,u,f,p,m,v,S,O,ie,Ue,wt]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?(n.charCodeAt(s)===58?(S=":",s++):(S=null,h('":"')),S!==null?(O=me(),O!==null?(n.charCodeAt(s)===58?(ie=":",s++):(ie=null,h('":"')),ie!==null?(Ue=ae(),Ue!==null?i=[i,e,l,u,f,p,m,v,S,O,ie,Ue]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?(n.charCodeAt(s)===58?(S=":",s++):(S=null,h('":"')),S!==null?(O=ae(),O!==null?i=[i,e,l,u,f,p,m,v,S,O]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=ae(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=ae(),p!==null?i=[i,e,l,u,f,p]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?(n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=ae(),u!==null?i=[i,e,l,u]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=ae(),e!==null?i=[i,e]:(i=null,s=M)):(i=null,s=M),i===null&&(M=s,n.substr(s,2)==="::"?(i="::",s+=2):(i=null,h('"::"')),i!==null?(e=me(),e!==null?i=[i,e]:(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(n.substr(s,2)==="::"?(e="::",s+=2):(e=null,h('"::"')),e!==null?(l=me(),l!==null?(n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?(n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?(n.charCodeAt(s)===58?(v=":",s++):(v=null,h('":"')),v!==null?(S=me(),S!==null?(n.charCodeAt(s)===58?(O=":",s++):(O=null,h('":"')),O!==null?(ie=ae(),ie!==null?i=[i,e,l,u,f,p,m,v,S,O,ie]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(n.substr(s,2)==="::"?(l="::",s+=2):(l=null,h('"::"')),l!==null?(u=me(),u!==null?(n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?(n.charCodeAt(s)===58?(S=":",s++):(S=null,h('":"')),S!==null?(O=ae(),O!==null?i=[i,e,l,u,f,p,m,v,S,O]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(n.substr(s,2)==="::"?(u="::",s+=2):(u=null,h('"::"')),u!==null?(f=me(),f!==null?(n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?(n.charCodeAt(s)===58?(v=":",s++):(v=null,h('":"')),v!==null?(S=ae(),S!==null?i=[i,e,l,u,f,p,m,v,S]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(n.substr(s,2)==="::"?(f="::",s+=2):(f=null,h('"::"')),f!==null?(p=me(),p!==null?(n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=ae(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(R=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,s=R)):(f=null,s=R),f=f!==null?f:"",f!==null?(n.substr(s,2)==="::"?(p="::",s+=2):(p=null,h('"::"')),p!==null?(m=ae(),m!==null?i=[i,e,l,u,f,p,m]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(R=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,s=R)):(f=null,s=R),f=f!==null?f:"",f!==null?(R=s,n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?p=[p,m]:(p=null,s=R)):(p=null,s=R),p=p!==null?p:"",p!==null?(n.substr(s,2)==="::"?(m="::",s+=2):(m=null,h('"::"')),m!==null?(v=me(),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M),i===null&&(M=s,i=me(),i!==null?(R=s,n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?e=[e,l]:(e=null,s=R)):(e=null,s=R),e=e!==null?e:"",e!==null?(R=s,n.charCodeAt(s)===58?(l=":",s++):(l=null,h('":"')),l!==null?(u=me(),u!==null?l=[l,u]:(l=null,s=R)):(l=null,s=R),l=l!==null?l:"",l!==null?(R=s,n.charCodeAt(s)===58?(u=":",s++):(u=null,h('":"')),u!==null?(f=me(),f!==null?u=[u,f]:(u=null,s=R)):(u=null,s=R),u=u!==null?u:"",u!==null?(R=s,n.charCodeAt(s)===58?(f=":",s++):(f=null,h('":"')),f!==null?(p=me(),p!==null?f=[f,p]:(f=null,s=R)):(f=null,s=R),f=f!==null?f:"",f!==null?(R=s,n.charCodeAt(s)===58?(p=":",s++):(p=null,h('":"')),p!==null?(m=me(),m!==null?p=[p,m]:(p=null,s=R)):(p=null,s=R),p=p!==null?p:"",p!==null?(R=s,n.charCodeAt(s)===58?(m=":",s++):(m=null,h('":"')),m!==null?(v=me(),v!==null?m=[m,v]:(m=null,s=R)):(m=null,s=R),m=m!==null?m:"",m!==null?(n.substr(s,2)==="::"?(v="::",s+=2):(v=null,h('"::"')),v!==null?i=[i,e,l,u,f,p,m,v]:(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M)):(i=null,s=M))))))))))))))),i!==null&&(i=function(Te){return b.host_type="IPv6",n.substring(s,Te)}(ks)),i===null&&(s=ks),i}function me(){var i,e,l,u,f;return f=s,i=E(),i!==null?(e=E(),e=e!==null?e:"",e!==null?(l=E(),l=l!==null?l:"",l!==null?(u=E(),u=u!==null?u:"",u!==null?i=[i,e,l,u]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i}function ae(){var i,e,l,u;return u=s,i=me(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=me(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i===null&&(i=ot()),i}function ot(){var i,e,l,u,f,p,m,v,S;return v=s,S=s,i=Wt(),i!==null?(n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e!==null?(l=Wt(),l!==null?(n.charCodeAt(s)===46?(u=".",s++):(u=null,h('"."')),u!==null?(f=Wt(),f!==null?(n.charCodeAt(s)===46?(p=".",s++):(p=null,h('"."')),p!==null?(m=Wt(),m!==null?i=[i,e,l,u,f,p,m]:(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S)):(i=null,s=S),i!==null&&(i=function(O){return b.host_type="IPv4",n.substring(s,O)}(v)),i===null&&(s=v),i}function Wt(){var i,e,l,u;return u=s,n.substr(s,2)==="25"?(i="25",s+=2):(i=null,h('"25"')),i!==null?(/^[0-5]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[0-5]")),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i===null&&(u=s,n.charCodeAt(s)===50?(i="2",s++):(i=null,h('"2"')),i!==null?(/^[0-4]/.test(n.charAt(s))?(e=n.charAt(s),s++):(e=null,h("[0-4]")),e!==null?(l=g(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i===null&&(u=s,n.charCodeAt(s)===49?(i="1",s++):(i=null,h('"1"')),i!==null?(e=g(),e!==null?(l=g(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i===null&&(u=s,/^[1-9]/.test(n.charAt(s))?(i=n.charAt(s),s++):(i=null,h("[1-9]")),i!==null?(e=g(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i===null&&(i=g())))),i}function As(){var i,e,l,u,f,p,m;return p=s,m=s,i=g(),i=i!==null?i:"",i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?i=[i,e,l,u,f]:(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(v,S){return S=parseInt(S.join("")),b.port=S,S}(p,i)),i===null&&(s=p),i}function Er(){var i,e,l,u;for(i=[],u=s,n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e!==null?(l=Un(),l!==null?e=[e,l]:(e=null,s=u)):(e=null,s=u);e!==null;)i.push(e),u=s,n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e!==null?(l=Un(),l!==null?e=[e,l]:(e=null,s=u)):(e=null,s=u);return i}function Un(){var i;return i=Pn(),i===null&&(i=Sr(),i===null&&(i=yr(),i===null&&(i=Cr(),i===null&&(i=Ar(),i===null&&(i=Rr(),i===null&&(i=Ir())))))),i}function Pn(){var i,e,l,u;return l=s,u=s,n.substr(s,10).toLowerCase()==="transport="?(i=n.substr(s,10),s+=10):(i=null,h('"transport="')),i!==null?(n.substr(s,3).toLowerCase()==="udp"?(e=n.substr(s,3),s+=3):(e=null,h('"udp"')),e===null&&(n.substr(s,3).toLowerCase()==="tcp"?(e=n.substr(s,3),s+=3):(e=null,h('"tcp"')),e===null&&(n.substr(s,4).toLowerCase()==="sctp"?(e=n.substr(s,4),s+=4):(e=null,h('"sctp"')),e===null&&(n.substr(s,3).toLowerCase()==="tls"?(e=n.substr(s,3),s+=3):(e=null,h('"tls"')),e===null&&(e=U())))),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.transport=p.toLowerCase()}(l,i[1])),i===null&&(s=l),i}function Sr(){var i,e,l,u;return l=s,u=s,n.substr(s,5).toLowerCase()==="user="?(i=n.substr(s,5),s+=5):(i=null,h('"user="')),i!==null?(n.substr(s,5).toLowerCase()==="phone"?(e=n.substr(s,5),s+=5):(e=null,h('"phone"')),e===null&&(n.substr(s,2).toLowerCase()==="ip"?(e=n.substr(s,2),s+=2):(e=null,h('"ip"')),e===null&&(e=U())),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.user=p.toLowerCase()}(l,i[1])),i===null&&(s=l),i}function yr(){var i,e,l,u;return l=s,u=s,n.substr(s,7).toLowerCase()==="method="?(i=n.substr(s,7),s+=7):(i=null,h('"method="')),i!==null?(e=nn(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.method=p}(l,i[1])),i===null&&(s=l),i}function Cr(){var i,e,l,u;return l=s,u=s,n.substr(s,4).toLowerCase()==="ttl="?(i=n.substr(s,4),s+=4):(i=null,h('"ttl="')),i!==null?(e=tr(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.params||(b.params={}),b.params.ttl=p}(l,i[1])),i===null&&(s=l),i}function Ar(){var i,e,l,u;return l=s,u=s,n.substr(s,6).toLowerCase()==="maddr="?(i=n.substr(s,6),s+=6):(i=null,h('"maddr="')),i!==null?(e=es(),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i!==null&&(i=function(f,p){b.uri_params||(b.uri_params={}),b.uri_params.maddr=p}(l,i[1])),i===null&&(s=l),i}function Rr(){var i,e,l,u,f,p;return u=s,f=s,n.substr(s,2).toLowerCase()==="lr"?(i=n.substr(s,2),s+=2):(i=null,h('"lr"')),i!==null?(p=s,n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=U(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b.uri_params||(b.uri_params={}),b.uri_params.lr=void 0}()),i===null&&(s=u),i}function Ir(){var i,e,l,u,f,p;return u=s,f=s,i=br(),i!==null?(p=s,n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=wr(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m,v,S){b.uri_params||(b.uri_params={}),typeof S>"u"?S=void 0:S=S[1],b.uri_params[v.toLowerCase()]=S}(u,i[0],i[1])),i===null&&(s=u),i}function br(){var i,e,l;if(l=s,e=Rs(),e!==null)for(i=[];e!==null;)i.push(e),e=Rs();else i=null;return i!==null&&(i=function(u,f){return f.join("")}(l,i)),i===null&&(s=l),i}function wr(){var i,e,l;if(l=s,e=Rs(),e!==null)for(i=[];e!==null;)i.push(e),e=Rs();else i=null;return i!==null&&(i=function(u,f){return f.join("")}(l,i)),i===null&&(s=l),i}function Rs(){var i;return i=Is(),i===null&&(i=N(),i===null&&(i=Se())),i}function Is(){var i;return n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i===null&&(n.charCodeAt(s)===93?(i="]",s++):(i=null,h('"]"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')))))))),i}function Or(){var i,e,l,u,f,p,m;if(p=s,n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i!==null)if(e=Xs(),e!==null){for(l=[],m=s,n.charCodeAt(s)===38?(u="&",s++):(u=null,h('"&"')),u!==null?(f=Xs(),f!==null?u=[u,f]:(u=null,s=m)):(u=null,s=m);u!==null;)l.push(u),m=s,n.charCodeAt(s)===38?(u="&",s++):(u=null,h('"&"')),u!==null?(f=Xs(),f!==null?u=[u,f]:(u=null,s=m)):(u=null,s=m);l!==null?i=[i,e,l]:(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i}function Xs(){var i,e,l,u,f;return u=s,f=s,i=Qs(),i!==null?(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e!==null?(l=Dr(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m,v){m=m.join("").toLowerCase(),v=v.join(""),b.uri_headers||(b.uri_headers={}),b.uri_headers[m]?b.uri_headers[m].push(v):b.uri_headers[m]=[v]}(u,i[0],i[2])),i===null&&(s=u),i}function Qs(){var i,e;if(e=bs(),e===null&&(e=N(),e===null&&(e=Se())),e!==null)for(i=[];e!==null;)i.push(e),e=bs(),e===null&&(e=N(),e===null&&(e=Se()));else i=null;return i}function Dr(){var i,e;for(i=[],e=bs(),e===null&&(e=N(),e===null&&(e=Se()));e!==null;)i.push(e),e=bs(),e===null&&(e=N(),e===null&&(e=Se()));return i}function bs(){var i;return n.charCodeAt(s)===91?(i="[",s++):(i=null,h('"["')),i===null&&(n.charCodeAt(s)===93?(i="]",s++):(i=null,h('"]"')),i===null&&(n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')))))))),i}function Zs(){var i;return i=rn(),i===null&&(i=gl()),i}function gl(){var i,e,l,u,f,p;return p=s,i=nn(),i!==null?(e=I(),e!==null?(l=Nr(),l!==null?(u=I(),u!==null?(f=Mn(),f!==null?i=[i,e,l,u,f]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i}function Nr(){var i;return i=we(),i===null&&(i=xn()),i}function xn(){var i,e,l,u;return u=s,i=Ns(),i!==null?(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e!==null?(l=kn(),l===null&&(l=tn()),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function kn(){var i,e,l,u,f;return u=s,i=Ur(),i===null&&(i=en()),i!==null?(f=s,n.charCodeAt(s)===63?(e="?",s++):(e=null,h('"?"')),e!==null?(l=Lr(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function Ur(){var i,e,l,u;return u=s,n.substr(s,2)==="//"?(i="//",s+=2):(i=null,h('"//"')),i!==null?(e=xr(),e!==null?(l=en(),l=l!==null?l:"",l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function en(){var i,e,l;return l=s,n.charCodeAt(s)===47?(i="/",s++):(i=null,h('"/"')),i!==null?(e=Pr(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function tn(){var i,e,l,u;if(u=s,i=Os(),i!==null){for(e=[],l=ws();l!==null;)e.push(l),l=ws();e!==null?i=[i,e]:(i=null,s=u)}else i=null,s=u;return i}function ws(){var i;return i=oe(),i===null&&(i=N(),i===null&&(i=Se())),i}function Os(){var i;return i=N(),i===null&&(i=Se(),i===null&&(n.charCodeAt(s)===59?(i=";",s++):(i=null,h('";"')),i===null&&(n.charCodeAt(s)===63?(i="?",s++):(i=null,h('"?"')),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')))))))))))),i}function Pr(){var i,e,l,u,f,p;if(f=s,i=sn(),i!==null){for(e=[],p=s,n.charCodeAt(s)===47?(l="/",s++):(l=null,h('"/"')),l!==null?(u=sn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,n.charCodeAt(s)===47?(l="/",s++):(l=null,h('"/"')),l!==null?(u=sn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function sn(){var i,e,l,u,f,p;for(f=s,i=[],e=cs();e!==null;)i.push(e),e=cs();if(i!==null){for(e=[],p=s,n.charCodeAt(s)===59?(l=";",s++):(l=null,h('";"')),l!==null?(u=Ds(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,n.charCodeAt(s)===59?(l=";",s++):(l=null,h('";"')),l!==null?(u=Ds(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Ds(){var i,e;for(i=[],e=cs();e!==null;)i.push(e),e=cs();return i}function cs(){var i;return i=N(),i===null&&(i=Se(),i===null&&(n.charCodeAt(s)===58?(i=":",s++):(i=null,h('":"')),i===null&&(n.charCodeAt(s)===64?(i="@",s++):(i=null,h('"@"')),i===null&&(n.charCodeAt(s)===38?(i="&",s++):(i=null,h('"&"')),i===null&&(n.charCodeAt(s)===61?(i="=",s++):(i=null,h('"="')),i===null&&(n.charCodeAt(s)===43?(i="+",s++):(i=null,h('"+"')),i===null&&(n.charCodeAt(s)===36?(i="$",s++):(i=null,h('"$"')),i===null&&(n.charCodeAt(s)===44?(i=",",s++):(i=null,h('","')))))))))),i}function Ns(){var i,e,l,u,f;if(u=s,f=s,i=T(),i!==null){for(e=[],l=T(),l===null&&(l=g(),l===null&&(n.charCodeAt(s)===43?(l="+",s++):(l=null,h('"+"')),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."'))))));l!==null;)e.push(l),l=T(),l===null&&(l=g(),l===null&&(n.charCodeAt(s)===43?(l="+",s++):(l=null,h('"+"')),l===null&&(n.charCodeAt(s)===45?(l="-",s++):(l=null,h('"-"')),l===null&&(n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."'))))));e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i!==null&&(i=function(p){b.scheme=n.substring(s,p)}(u)),i===null&&(s=u),i}function xr(){var i;return i=kr(),i===null&&(i=Mr()),i}function kr(){var i,e,l,u;return l=s,u=s,i=Lt(),i!==null?(n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i=i!==null?i:"",i!==null?(e=Ys(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i=i!==null?i:"",i}function Mr(){var i,e;if(e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","')),e===null&&(n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"'))))))))))),e!==null)for(i=[];e!==null;)i.push(e),e=N(),e===null&&(e=Se(),e===null&&(n.charCodeAt(s)===36?(e="$",s++):(e=null,h('"$"')),e===null&&(n.charCodeAt(s)===44?(e=",",s++):(e=null,h('","')),e===null&&(n.charCodeAt(s)===59?(e=";",s++):(e=null,h('";"')),e===null&&(n.charCodeAt(s)===58?(e=":",s++):(e=null,h('":"')),e===null&&(n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e===null&&(n.charCodeAt(s)===38?(e="&",s++):(e=null,h('"&"')),e===null&&(n.charCodeAt(s)===61?(e="=",s++):(e=null,h('"="')),e===null&&(n.charCodeAt(s)===43?(e="+",s++):(e=null,h('"+"')))))))))));else i=null;return i}function Lr(){var i,e;for(i=[],e=ws();e!==null;)i.push(e),e=ws();return i}function Mn(){var i,e,l,u,f,p,m,v;if(m=s,v=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"SIP"')),i!==null)if(n.charCodeAt(s)===47?(e="/",s++):(e=null,h('"/"')),e!==null){if(u=g(),u!==null)for(l=[];u!==null;)l.push(u),u=g();else l=null;if(l!==null)if(n.charCodeAt(s)===46?(u=".",s++):(u=null,h('"."')),u!==null){if(p=g(),p!==null)for(f=[];p!==null;)f.push(p),p=g();else f=null;f!==null?i=[i,e,l,u,f]:(i=null,s=v)}else i=null,s=v;else i=null,s=v}else i=null,s=v;else i=null,s=v;return i!==null&&(i=function(S){b.sip_version=n.substring(s,S)}(m)),i===null&&(s=m),i}function Ln(){var i;return n.substr(s,6)==="INVITE"?(i="INVITE",s+=6):(i=null,h('"INVITE"')),i}function $r(){var i;return n.substr(s,3)==="ACK"?(i="ACK",s+=3):(i=null,h('"ACK"')),i}function Hr(){var i;return n.substr(s,7)==="OPTIONS"?(i="OPTIONS",s+=7):(i=null,h('"OPTIONS"')),i}function Fr(){var i;return n.substr(s,3)==="BYE"?(i="BYE",s+=3):(i=null,h('"BYE"')),i}function jr(){var i;return n.substr(s,6)==="CANCEL"?(i="CANCEL",s+=6):(i=null,h('"CANCEL"')),i}function qr(){var i;return n.substr(s,8)==="REGISTER"?(i="REGISTER",s+=8):(i=null,h('"REGISTER"')),i}function Vr(){var i;return n.substr(s,9)==="SUBSCRIBE"?(i="SUBSCRIBE",s+=9):(i=null,h('"SUBSCRIBE"')),i}function Br(){var i;return n.substr(s,6)==="NOTIFY"?(i="NOTIFY",s+=6):(i=null,h('"NOTIFY"')),i}function Gr(){var i;return n.substr(s,5)==="REFER"?(i="REFER",s+=5):(i=null,h('"REFER"')),i}function nn(){var i,e;return e=s,i=Ln(),i===null&&(i=$r(),i===null&&(i=Hr(),i===null&&(i=Fr(),i===null&&(i=jr(),i===null&&(i=qr(),i===null&&(i=Vr(),i===null&&(i=Br(),i===null&&(i=Gr(),i===null&&(i=U()))))))))),i!==null&&(i=function(l){return b.method=n.substring(s,l),b.method}(e)),i===null&&(s=e),i}function rn(){var i,e,l,u,f,p;return p=s,i=Mn(),i!==null?(e=I(),e!==null?(l=Wr(),l!==null?(u=I(),u!==null?(f=Yr(),f!==null?i=[i,e,l,u,f]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i}function Wr(){var i,e;return e=s,i=Kr(),i!==null&&(i=function(l,u){b.status_code=parseInt(u.join(""))}(e,i)),i===null&&(s=e),i}function Kr(){var i,e,l,u;return u=s,i=g(),i!==null?(e=g(),e!==null?(l=g(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Yr(){var i,e,l;for(l=s,i=[],e=oe(),e===null&&(e=N(),e===null&&(e=Se(),e===null&&(e=J(),e===null&&(e=F(),e===null&&(e=I(),e===null&&(e=H()))))));e!==null;)i.push(e),e=oe(),e===null&&(e=N(),e===null&&(e=Se(),e===null&&(e=J(),e===null&&(e=F(),e===null&&(e=I(),e===null&&(e=H()))))));return i!==null&&(i=function(u){b.reason_phrase=n.substring(s,u)}(l)),i===null&&(s=l),i}function Tl(){var i,e,l,u,f,p;if(f=s,i=on(),i!==null){for(e=[],p=s,l=Ae(),l!==null?(u=on(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ae(),l!==null?(u=on(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Ja(){var i,e,l,u,f,p;return u=s,f=s,i=st(),i!==null?(p=s,n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e!==null?(l=st(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b=n.substring(s,m)}(u)),i===null&&(s=u),i}function za(){var i,e,l,u,f,p,m;if(f=s,i=ee(),i===null)if(p=s,i=$n(),i!==null){for(e=[],m=s,l=Ae(),l!==null?(u=$n(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=Ae(),l!==null?(u=$n(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S,O;for(O=b.multi_header.length,S=0;S<O;S++)if(b.multi_header[S].parsed===null){b=null;break}b!==null?b=b.multi_header:b=-1}()),i===null&&(s=f),i}function $n(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=$t()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Us(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Us(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S;b.multi_header||(b.multi_header=[]);try{S=new fs(b.uri,b.display_name,b.params),delete b.uri,delete b.display_name,delete b.params}catch{S=null}b.multi_header.push({possition:s,offset:v,parsed:S})}(f)),i===null&&(s=f),i}function $t(){var i,e,l,u,f;return f=s,i=Ht(),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,s=f)):(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i}function Ht(){var i,e,l,u,f,p,m;if(f=s,p=s,i=U(),i!==null){for(e=[],m=s,l=ve(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=ve(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i===null&&(i=Oe()),i!==null&&(i=function(v,S){typeof S=="string"?b.display_name=S:b.display_name=S[1].reduce(function(O,ie){return O+ie[0]+ie[1]},S[0])}(f,i)),i===null&&(s=f),i}function Us(){var i;return i=Hn(),i===null&&(i=Jr(),i===null&&(i=Ge())),i}function Hn(){var i,e,l,u,f;return u=s,f=s,n.substr(s,1).toLowerCase()==="q"?(i=n.substr(s,1),s++):(i=null,h('"q"')),i!==null?(e=G(),e!==null?(l=ss(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.params||(b.params={}),b.params.q=m}(u,i[2])),i===null&&(s=u),i}function Jr(){var i,e,l,u,f;return u=s,f=s,n.substr(s,7).toLowerCase()==="expires"?(i=n.substr(s,7),s+=7):(i=null,h('"expires"')),i!==null?(e=G(),e!==null?(l=ts(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.params||(b.params={}),b.params.expires=m}(u,i[2])),i===null&&(s=u),i}function ts(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){return parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function ss(){var i,e,l,u,f,p,m,v;return p=s,m=s,n.charCodeAt(s)===48?(i="0",s++):(i=null,h('"0"')),i!==null?(v=s,n.charCodeAt(s)===46?(e=".",s++):(e=null,h('"."')),e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?e=[e,l,u,f]:(e=null,s=v)):(e=null,s=v)):(e=null,s=v)):(e=null,s=v),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(S){return parseFloat(n.substring(s,S))}(p)),i===null&&(s=p),i}function Ge(){var i,e,l,u,f,p;return u=s,f=s,i=U(),i!==null?(p=s,e=G(),e!==null?(l=We(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m,v,S){b.params||(b.params={}),typeof S>"u"?S=void 0:S=S[1],b.params[v.toLowerCase()]=S}(u,i[0],i[1])),i===null&&(s=u),i}function We(){var i;return i=U(),i===null&&(i=es(),i===null&&(i=Ie())),i}function vl(){var i,e,l,u,f,p;if(f=s,i=El(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=Fn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=Fn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function El(){var i;return n.substr(s,6).toLowerCase()==="render"?(i=n.substr(s,6),s+=6):(i=null,h('"render"')),i===null&&(n.substr(s,7).toLowerCase()==="session"?(i=n.substr(s,7),s+=7):(i=null,h('"session"')),i===null&&(n.substr(s,4).toLowerCase()==="icon"?(i=n.substr(s,4),s+=4):(i=null,h('"icon"')),i===null&&(n.substr(s,5).toLowerCase()==="alert"?(i=n.substr(s,5),s+=5):(i=null,h('"alert"')),i===null&&(i=U())))),i}function Fn(){var i;return i=jn(),i===null&&(i=Ge()),i}function jn(){var i,e,l,u;return u=s,n.substr(s,8).toLowerCase()==="handling"?(i=n.substr(s,8),s+=8):(i=null,h('"handling"')),i!==null?(e=G(),e!==null?(n.substr(s,8).toLowerCase()==="optional"?(l=n.substr(s,8),s+=8):(l=null,h('"optional"')),l===null&&(n.substr(s,8).toLowerCase()==="required"?(l=n.substr(s,8),s+=8):(l=null,h('"required"')),l===null&&(l=U())),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Sl(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Ae(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ae(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Xa(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){b=parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function Qa(){var i,e;return e=s,i=yl(),i!==null&&(i=function(l){b=n.substring(s,l)}(e)),i===null&&(s=e),i}function yl(){var i,e,l,u,f,p,m,v;if(m=s,i=zr(),i!==null)if(e=W(),e!==null)if(l=Zr(),l!==null){for(u=[],v=s,f=le(),f!==null?(p=qn(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=le(),f!==null?(p=qn(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i}function zr(){var i;return i=Xr(),i===null&&(i=Qr()),i}function Xr(){var i;return n.substr(s,4).toLowerCase()==="text"?(i=n.substr(s,4),s+=4):(i=null,h('"text"')),i===null&&(n.substr(s,5).toLowerCase()==="image"?(i=n.substr(s,5),s+=5):(i=null,h('"image"')),i===null&&(n.substr(s,5).toLowerCase()==="audio"?(i=n.substr(s,5),s+=5):(i=null,h('"audio"')),i===null&&(n.substr(s,5).toLowerCase()==="video"?(i=n.substr(s,5),s+=5):(i=null,h('"video"')),i===null&&(n.substr(s,11).toLowerCase()==="application"?(i=n.substr(s,11),s+=11):(i=null,h('"application"')),i===null&&(i=ln()))))),i}function Qr(){var i;return n.substr(s,7).toLowerCase()==="message"?(i=n.substr(s,7),s+=7):(i=null,h('"message"')),i===null&&(n.substr(s,9).toLowerCase()==="multipart"?(i=n.substr(s,9),s+=9):(i=null,h('"multipart"')),i===null&&(i=ln())),i}function ln(){var i;return i=U(),i===null&&(i=an()),i}function an(){var i,e,l;return l=s,n.substr(s,2).toLowerCase()==="x-"?(i=n.substr(s,2),s+=2):(i=null,h('"x-"')),i!==null?(e=U(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function Zr(){var i;return i=ln(),i===null&&(i=U()),i}function qn(){var i,e,l,u;return u=s,i=U(),i!==null?(e=G(),e!==null?(l=Vn(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Vn(){var i;return i=U(),i===null&&(i=Ie()),i}function Cl(){var i,e,l,u;return u=s,i=Al(),i!==null?(e=ve(),e!==null?(l=nn(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Al(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){b.value=parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function Rl(){var i,e;return e=s,i=ts(),i!==null&&(i=function(l,u){b=u}(e,i)),i===null&&(s=e),i}function Za(){var i,e,l,u,f,p,m;if(f=s,p=s,i=on(),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v,S){b.event=S.join("").toLowerCase()}(f,i[0])),i===null&&(s=f),i}function on(){var i,e,l,u,f,p;if(f=s,i=P(),i!==null){for(e=[],p=s,n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?(u=P(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,n.charCodeAt(s)===46?(l=".",s++):(l=null,h('"."')),l!==null?(u=P(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function un(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=$t()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=ei(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=ei(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S=b.tag;try{b=new fs(b.uri,b.display_name,b.params),S&&b.setParam("tag",S)}catch{b=-1}}()),i===null&&(s=f),i}function ei(){var i;return i=cn(),i===null&&(i=Ge()),i}function cn(){var i,e,l,u,f;return u=s,f=s,n.substr(s,3).toLowerCase()==="tag"?(i=n.substr(s,3),s+=3):(i=null,h('"tag"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.tag=m}(u,i[2])),i===null&&(s=u),i}function ti(){var i,e,l;if(l=s,e=g(),e!==null)for(i=[];e!==null;)i.push(e),e=g();else i=null;return i!==null&&(i=function(u,f){b=parseInt(f.join(""))}(l,i)),i===null&&(s=l),i}function eo(){var i,e;return e=s,i=ts(),i!==null&&(i=function(l,u){b=u}(e,i)),i===null&&(s=e),i}function to(){var i,e,l,u,f,p,m,v,S,O;for(v=s,S=s,i=[],e=Ht();e!==null;)i.push(e),e=Ht();if(i!==null)if(e=xe(),e!==null)if(l=we(),l!==null)if(u=be(),u!==null){for(f=[],O=s,p=le(),p!==null?(m=Ge(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);p!==null;)f.push(p),O=s,p=le(),p!==null?(m=Ge(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);f!==null?i=[i,e,l,u,f]:(i=null,s=S)}else i=null,s=S;else i=null,s=S;else i=null,s=S;else i=null,s=S;return i!==null&&(i=function(ie){try{b=new fs(b.uri,b.display_name,b.params)}catch{b=-1}}()),i===null&&(s=v),i}function so(){var i;return i=si(),i}function si(){var i,e,l,u,f,p,m,v;if(m=s,n.substr(s,6).toLowerCase()==="digest"?(i=n.substr(s,6),s+=6):(i=null,h('"Digest"')),i!==null)if(e=ve(),e!==null)if(l=ns(),l!==null){for(u=[],v=s,f=Ae(),f!==null?(p=ns(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=Ae(),f!==null?(p=ns(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i===null&&(i=Bn()),i}function Bn(){var i,e,l,u,f,p,m,v;if(m=s,i=U(),i!==null)if(e=ve(),e!==null)if(l=Ps(),l!==null){for(u=[],v=s,f=Ae(),f!==null?(p=Ps(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=Ae(),f!==null?(p=Ps(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i}function Ps(){var i,e,l,u;return u=s,i=U(),i!==null?(e=G(),e!==null?(l=U(),l===null&&(l=Ie()),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function ns(){var i;return i=fn(),i===null&&(i=ri(),i===null&&(i=dn(),i===null&&(i=li(),i===null&&(i=ai(),i===null&&(i=oi(),i===null&&(i=ui(),i===null&&(i=Ps()))))))),i}function fn(){var i,e,l,u;return u=s,n.substr(s,5).toLowerCase()==="realm"?(i=n.substr(s,5),s+=5):(i=null,h('"realm"')),i!==null?(e=G(),e!==null?(l=ni(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function ni(){var i,e;return e=s,i=Oe(),i!==null&&(i=function(l,u){b.realm=u}(e,i)),i===null&&(s=e),i}function ri(){var i,e,l,u,f,p,m,v,S;if(v=s,n.substr(s,6).toLowerCase()==="domain"?(i=n.substr(s,6),s+=6):(i=null,h('"domain"')),i!==null)if(e=G(),e!==null)if(l=nt(),l!==null)if(u=hn(),u!==null){if(f=[],S=s,m=I(),m!==null)for(p=[];m!==null;)p.push(m),m=I();else p=null;for(p!==null?(m=hn(),m!==null?p=[p,m]:(p=null,s=S)):(p=null,s=S);p!==null;){if(f.push(p),S=s,m=I(),m!==null)for(p=[];m!==null;)p.push(m),m=I();else p=null;p!==null?(m=hn(),m!==null?p=[p,m]:(p=null,s=S)):(p=null,s=S)}f!==null?(p=at(),p!==null?i=[i,e,l,u,f,p]:(i=null,s=v)):(i=null,s=v)}else i=null,s=v;else i=null,s=v;else i=null,s=v;else i=null,s=v;return i}function hn(){var i;return i=xn(),i===null&&(i=en()),i}function dn(){var i,e,l,u;return u=s,n.substr(s,5).toLowerCase()==="nonce"?(i=n.substr(s,5),s+=5):(i=null,h('"nonce"')),i!==null?(e=G(),e!==null?(l=ii(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function ii(){var i,e;return e=s,i=Oe(),i!==null&&(i=function(l,u){b.nonce=u}(e,i)),i===null&&(s=e),i}function li(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6).toLowerCase()==="opaque"?(i=n.substr(s,6),s+=6):(i=null,h('"opaque"')),i!==null?(e=G(),e!==null?(l=Oe(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.opaque=m}(u,i[2])),i===null&&(s=u),i}function ai(){var i,e,l,u,f;return u=s,n.substr(s,5).toLowerCase()==="stale"?(i=n.substr(s,5),s+=5):(i=null,h('"stale"')),i!==null?(e=G(),e!==null?(f=s,n.substr(s,4).toLowerCase()==="true"?(l=n.substr(s,4),s+=4):(l=null,h('"true"')),l!==null&&(l=function(p){b.stale=!0}()),l===null&&(s=f),l===null&&(f=s,n.substr(s,5).toLowerCase()==="false"?(l=n.substr(s,5),s+=5):(l=null,h('"false"')),l!==null&&(l=function(p){b.stale=!1}()),l===null&&(s=f)),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function oi(){var i,e,l,u,f;return u=s,f=s,n.substr(s,9).toLowerCase()==="algorithm"?(i=n.substr(s,9),s+=9):(i=null,h('"algorithm"')),i!==null?(e=G(),e!==null?(n.substr(s,3).toLowerCase()==="md5"?(l=n.substr(s,3),s+=3):(l=null,h('"MD5"')),l===null&&(n.substr(s,8).toLowerCase()==="md5-sess"?(l=n.substr(s,8),s+=8):(l=null,h('"MD5-sess"')),l===null&&(l=U())),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.algorithm=m.toUpperCase()}(u,i[2])),i===null&&(s=u),i}function ui(){var i,e,l,u,f,p,m,v,S,O;if(v=s,n.substr(s,3).toLowerCase()==="qop"?(i=n.substr(s,3),s+=3):(i=null,h('"qop"')),i!==null)if(e=G(),e!==null)if(l=nt(),l!==null){if(S=s,u=_n(),u!==null){for(f=[],O=s,n.charCodeAt(s)===44?(p=",",s++):(p=null,h('","')),p!==null?(m=_n(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);p!==null;)f.push(p),O=s,n.charCodeAt(s)===44?(p=",",s++):(p=null,h('","')),p!==null?(m=_n(),m!==null?p=[p,m]:(p=null,s=O)):(p=null,s=O);f!==null?u=[u,f]:(u=null,s=S)}else u=null,s=S;u!==null?(f=at(),f!==null?i=[i,e,l,u,f]:(i=null,s=v)):(i=null,s=v)}else i=null,s=v;else i=null,s=v;else i=null,s=v;return i}function _n(){var i,e;return e=s,n.substr(s,8).toLowerCase()==="auth-int"?(i=n.substr(s,8),s+=8):(i=null,h('"auth-int"')),i===null&&(n.substr(s,4).toLowerCase()==="auth"?(i=n.substr(s,4),s+=4):(i=null,h('"auth"')),i===null&&(i=U())),i!==null&&(i=function(l,u){b.qop||(b.qop=[]),b.qop.push(u.toLowerCase())}(e,i)),i===null&&(s=e),i}function Gn(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Ae(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ae(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function no(){var i,e,l,u,f,p,m;if(f=s,p=s,i=Wn(),i!==null){for(e=[],m=s,l=Ae(),l!==null?(u=Wn(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=Ae(),l!==null?(u=Wn(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S,O;for(O=b.multi_header.length,S=0;S<O;S++)if(b.multi_header[S].parsed===null){b=null;break}b!==null?b=b.multi_header:b=-1}()),i===null&&(s=f),i}function Wn(){var i,e,l,u,f,p,m;if(f=s,p=s,i=$t(),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S;b.multi_header||(b.multi_header=[]);try{S=new fs(b.uri,b.display_name,b.params),delete b.uri,delete b.display_name,delete b.params}catch{S=null}b.multi_header.push({possition:s,offset:v,parsed:S})}(f)),i===null&&(s=f),i}function Kn(){var i,e,l,u,f,p,m;if(f=s,p=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"SIP"')),i===null&&(i=U()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=ci(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=ci(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v,S){if(b.protocol=S.toLowerCase(),b.params||(b.params={}),b.params.text&&b.params.text[0]==='"'){var O=b.params.text;b.text=O.substring(1,O.length-1),delete b.params.text}}(f,i[0])),i===null&&(s=f),i}function ci(){var i;return i=Yn(),i===null&&(i=Ge()),i}function Yn(){var i,e,l,u,f,p;if(f=s,p=s,n.substr(s,5).toLowerCase()==="cause"?(i=n.substr(s,5),s+=5):(i=null,h('"cause"')),i!==null)if(e=G(),e!==null){if(u=g(),u!==null)for(l=[];u!==null;)l.push(u),u=g();else l=null;l!==null?i=[i,e,l]:(i=null,s=p)}else i=null,s=p;else i=null,s=p;return i!==null&&(i=function(m,v){b.cause=parseInt(v.join(""))}(f,i[2])),i===null&&(s=f),i}function Il(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Ae(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ae(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function ro(){var i,e,l,u,f,p;if(f=s,i=Jn(),i!==null){for(e=[],p=s,l=Ae(),l!==null?(u=Jn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ae(),l!==null?(u=Jn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Jn(){var i,e,l,u,f,p;if(f=s,i=$t(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function zn(){var i,e,l,u,f,p;if(f=s,i=bl(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=Xn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=Xn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function bl(){var i,e;return e=s,n.substr(s,6).toLowerCase()==="active"?(i=n.substr(s,6),s+=6):(i=null,h('"active"')),i===null&&(n.substr(s,7).toLowerCase()==="pending"?(i=n.substr(s,7),s+=7):(i=null,h('"pending"')),i===null&&(n.substr(s,10).toLowerCase()==="terminated"?(i=n.substr(s,10),s+=10):(i=null,h('"terminated"')),i===null&&(i=U()))),i!==null&&(i=function(l){b.state=n.substring(s,l)}(e)),i===null&&(s=e),i}function Xn(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6).toLowerCase()==="reason"?(i=n.substr(s,6),s+=6):(i=null,h('"reason"')),i!==null?(e=G(),e!==null?(l=Qn(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){typeof m<"u"&&(b.reason=m)}(u,i[2])),i===null&&(s=u),i===null&&(u=s,f=s,n.substr(s,7).toLowerCase()==="expires"?(i=n.substr(s,7),s+=7):(i=null,h('"expires"')),i!==null?(e=G(),e!==null?(l=ts(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){typeof m<"u"&&(b.expires=m)}(u,i[2])),i===null&&(s=u),i===null&&(u=s,f=s,n.substr(s,11).toLowerCase()==="retry_after"?(i=n.substr(s,11),s+=11):(i=null,h('"retry_after"')),i!==null?(e=G(),e!==null?(l=ts(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){typeof m<"u"&&(b.retry_after=m)}(u,i[2])),i===null&&(s=u),i===null&&(i=Ge()))),i}function Qn(){var i;return n.substr(s,11).toLowerCase()==="deactivated"?(i=n.substr(s,11),s+=11):(i=null,h('"deactivated"')),i===null&&(n.substr(s,9).toLowerCase()==="probation"?(i=n.substr(s,9),s+=9):(i=null,h('"probation"')),i===null&&(n.substr(s,8).toLowerCase()==="rejected"?(i=n.substr(s,8),s+=8):(i=null,h('"rejected"')),i===null&&(n.substr(s,7).toLowerCase()==="timeout"?(i=n.substr(s,7),s+=7):(i=null,h('"timeout"')),i===null&&(n.substr(s,6).toLowerCase()==="giveup"?(i=n.substr(s,6),s+=6):(i=null,h('"giveup"')),i===null&&(n.substr(s,10).toLowerCase()==="noresource"?(i=n.substr(s,10),s+=10):(i=null,h('"noresource"')),i===null&&(n.substr(s,9).toLowerCase()==="invariant"?(i=n.substr(s,9),s+=9):(i=null,h('"invariant"')),i===null&&(i=U()))))))),i}function wl(){var i;return i=B(),i=i!==null?i:"",i}function io(){var i,e,l,u,f,p;if(f=s,i=U(),i!==null){for(e=[],p=s,l=Ae(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ae(),l!==null?(u=U(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i=i!==null?i:"",i}function lo(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=$t()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=fi(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=fi(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){var S=b.tag;try{b=new fs(b.uri,b.display_name,b.params),S&&b.setParam("tag",S)}catch{b=-1}}()),i===null&&(s=f),i}function fi(){var i;return i=cn(),i===null&&(i=Ge()),i}function hi(){var i,e,l,u,f,p;if(f=s,i=Zn(),i!==null){for(e=[],p=s,l=Ae(),l!==null?(u=Zn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=Ae(),l!==null?(u=Zn(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Zn(){var i,e,l,u,f,p,m,v;if(m=s,i=Ti(),i!==null)if(e=ve(),e!==null)if(l=Si(),l!==null){for(u=[],v=s,f=le(),f!==null?(p=xs(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);f!==null;)u.push(f),v=s,f=le(),f!==null?(p=xs(),p!==null?f=[f,p]:(f=null,s=v)):(f=null,s=v);u!==null?i=[i,e,l,u]:(i=null,s=m)}else i=null,s=m;else i=null,s=m;else i=null,s=m;return i}function xs(){var i;return i=er(),i===null&&(i=di(),i===null&&(i=_i(),i===null&&(i=pi(),i===null&&(i=mi(),i===null&&(i=Ge()))))),i}function er(){var i,e,l,u,f;return u=s,f=s,n.substr(s,3).toLowerCase()==="ttl"?(i=n.substr(s,3),s+=3):(i=null,h('"ttl"')),i!==null?(e=G(),e!==null?(l=tr(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.ttl=m}(u,i[2])),i===null&&(s=u),i}function di(){var i,e,l,u,f;return u=s,f=s,n.substr(s,5).toLowerCase()==="maddr"?(i=n.substr(s,5),s+=5):(i=null,h('"maddr"')),i!==null?(e=G(),e!==null?(l=es(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.maddr=m}(u,i[2])),i===null&&(s=u),i}function _i(){var i,e,l,u,f;return u=s,f=s,n.substr(s,8).toLowerCase()==="received"?(i=n.substr(s,8),s+=8):(i=null,h('"received"')),i!==null?(e=G(),e!==null?(l=ot(),l===null&&(l=zs()),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.received=m}(u,i[2])),i===null&&(s=u),i}function pi(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6).toLowerCase()==="branch"?(i=n.substr(s,6),s+=6):(i=null,h('"branch"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.branch=m}(u,i[2])),i===null&&(s=u),i}function mi(){var i,e,l,u,f;return u=s,n.substr(s,5).toLowerCase()==="rport"?(i=n.substr(s,5),s+=5):(i=null,h('"rport"')),i!==null?(f=s,e=G(),e!==null?(l=gi(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function gi(){var i,e,l,u,f,p,m;return p=s,m=s,i=g(),i=i!==null?i:"",i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?i=[i,e,l,u,f]:(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(v,S){b.rport=parseInt(S.join(""))}(p,i)),i===null&&(s=p),i}function Ti(){var i,e,l,u,f,p;return p=s,i=vi(),i!==null?(e=W(),e!==null?(l=U(),l!==null?(u=W(),u!==null?(f=Ei(),f!==null?i=[i,e,l,u,f]:(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p)):(i=null,s=p),i}function vi(){var i,e;return e=s,n.substr(s,3).toLowerCase()==="sip"?(i=n.substr(s,3),s+=3):(i=null,h('"SIP"')),i===null&&(i=U()),i!==null&&(i=function(l,u){b.protocol=u}(e,i)),i===null&&(s=e),i}function Ei(){var i,e;return e=s,n.substr(s,3).toLowerCase()==="udp"?(i=n.substr(s,3),s+=3):(i=null,h('"UDP"')),i===null&&(n.substr(s,3).toLowerCase()==="tcp"?(i=n.substr(s,3),s+=3):(i=null,h('"TCP"')),i===null&&(n.substr(s,3).toLowerCase()==="tls"?(i=n.substr(s,3),s+=3):(i=null,h('"TLS"')),i===null&&(n.substr(s,4).toLowerCase()==="sctp"?(i=n.substr(s,4),s+=4):(i=null,h('"SCTP"')),i===null&&(i=U())))),i!==null&&(i=function(l,u){b.transport=u}(e,i)),i===null&&(s=e),i}function Si(){var i,e,l,u,f;return u=s,i=yi(),i!==null?(f=s,e=ye(),e!==null?(l=Ci(),l!==null?e=[e,l]:(e=null,s=f)):(e=null,s=f),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=u)):(i=null,s=u),i}function yi(){var i,e;return e=s,i=ot(),i===null&&(i=Nn(),i===null&&(i=us())),i!==null&&(i=function(l){b.host=n.substring(s,l)}(e)),i===null&&(s=e),i}function Ci(){var i,e,l,u,f,p,m;return p=s,m=s,i=g(),i=i!==null?i:"",i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?(u=g(),u=u!==null?u:"",u!==null?(f=g(),f=f!==null?f:"",f!==null?i=[i,e,l,u,f]:(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m)):(i=null,s=m),i!==null&&(i=function(v,S){b.port=parseInt(S.join(""))}(p,i)),i===null&&(s=p),i}function tr(){var i,e,l,u,f;return u=s,f=s,i=g(),i!==null?(e=g(),e=e!==null?e:"",e!==null?(l=g(),l=l!==null?l:"",l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){return parseInt(m.join(""))}(u,i)),i===null&&(s=u),i}function Ai(){var i;return i=si(),i}function ao(){var i,e,l,u,f,p;if(f=s,i=Ol(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=sr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=sr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function Ol(){var i,e;return e=s,i=ts(),i!==null&&(i=function(l,u){b.expires=u}(e,i)),i===null&&(s=e),i}function sr(){var i;return i=nr(),i===null&&(i=Ge()),i}function nr(){var i,e,l,u,f;return u=s,f=s,n.substr(s,9).toLowerCase()==="refresher"?(i=n.substr(s,9),s+=9):(i=null,h('"refresher"')),i!==null?(e=G(),e!==null?(n.substr(s,3).toLowerCase()==="uac"?(l=n.substr(s,3),s+=3):(l=null,h('"uac"')),l===null&&(n.substr(s,3).toLowerCase()==="uas"?(l=n.substr(s,3),s+=3):(l=null,h('"uas"'))),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.refresher=m.toLowerCase()}(u,i[2])),i===null&&(s=u),i}function Dl(){var i,e,l,u;return u=s,i=U(),i!==null?(e=D(),e!==null?(l=Nl(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function Nl(){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 Ul(){var i,e;for(i=[],e=C();e!==null;)i.push(e),e=C();return i}function oo(){var i,e,l;return l=s,n.substr(s,5)==="uuid:"?(i="uuid:",s+=5):(i=null,h('"uuid:"')),i!==null?(e=Pl(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function Pl(){var i,e,l,u,f,p,m,v,S,O,ie;return O=s,ie=s,i=jt(),i!==null?(n.charCodeAt(s)===45?(e="-",s++):(e=null,h('"-"')),e!==null?(l=Ft(),l!==null?(n.charCodeAt(s)===45?(u="-",s++):(u=null,h('"-"')),u!==null?(f=Ft(),f!==null?(n.charCodeAt(s)===45?(p="-",s++):(p=null,h('"-"')),p!==null?(m=Ft(),m!==null?(n.charCodeAt(s)===45?(v="-",s++):(v=null,h('"-"')),v!==null?(S=Ri(),S!==null?i=[i,e,l,u,f,p,m,v,S]:(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie)):(i=null,s=ie),i!==null&&(i=function(Ue,wt){b=n.substring(s+5,Ue)}(O,i[0])),i===null&&(s=O),i}function Ft(){var i,e,l,u,f;return f=s,i=E(),i!==null?(e=E(),e!==null?(l=E(),l!==null?(u=E(),u!==null?i=[i,e,l,u]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i}function jt(){var i,e,l;return l=s,i=Ft(),i!==null?(e=Ft(),e!==null?i=[i,e]:(i=null,s=l)):(i=null,s=l),i}function Ri(){var i,e,l,u;return u=s,i=Ft(),i!==null?(e=Ft(),e!==null?(l=Ft(),l!==null?i=[i,e,l]:(i=null,s=u)):(i=null,s=u)):(i=null,s=u),i}function xl(){var i,e,l,u,f,p,m;if(f=s,p=s,i=_e(),i===null&&(i=$t()),i!==null){for(e=[],m=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);l!==null;)e.push(l),m=s,l=le(),l!==null?(u=Ge(),u!==null?l=[l,u]:(l=null,s=m)):(l=null,s=m);e!==null?i=[i,e]:(i=null,s=p)}else i=null,s=p;return i!==null&&(i=function(v){try{b=new fs(b.uri,b.display_name,b.params)}catch{b=-1}}()),i===null&&(s=f),i}function uo(){var i,e,l,u,f,p;if(f=s,i=kl(),i!==null){for(e=[],p=s,l=le(),l!==null?(u=rr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);l!==null;)e.push(l),p=s,l=le(),l!==null?(u=rr(),u!==null?l=[l,u]:(l=null,s=p)):(l=null,s=p);e!==null?i=[i,e]:(i=null,s=f)}else i=null,s=f;return i}function kl(){var i,e,l,u,f,p;return u=s,f=s,i=st(),i!==null?(p=s,n.charCodeAt(s)===64?(e="@",s++):(e=null,h('"@"')),e!==null?(l=st(),l!==null?e=[e,l]:(e=null,s=p)):(e=null,s=p),e=e!==null?e:"",e!==null?i=[i,e]:(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(m){b.call_id=n.substring(s,m)}(u)),i===null&&(s=u),i}function rr(){var i;return i=ir(),i===null&&(i=Ii(),i===null&&(i=bi(),i===null&&(i=Ge()))),i}function ir(){var i,e,l,u,f;return u=s,f=s,n.substr(s,6)==="to-tag"?(i="to-tag",s+=6):(i=null,h('"to-tag"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.to_tag=m}(u,i[2])),i===null&&(s=u),i}function Ii(){var i,e,l,u,f;return u=s,f=s,n.substr(s,8)==="from-tag"?(i="from-tag",s+=8):(i=null,h('"from-tag"')),i!==null?(e=G(),e!==null?(l=U(),l!==null?i=[i,e,l]:(i=null,s=f)):(i=null,s=f)):(i=null,s=f),i!==null&&(i=function(p,m){b.from_tag=m}(u,i[2])),i===null&&(s=u),i}function bi(){var i,e;return e=s,n.substr(s,10)==="early-only"?(i="early-only",s+=10):(i=null,h('"early-only"')),i!==null&&(i=function(l){b.early_only=!0}()),i===null&&(s=e),i}function Ml(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 co(){for(var i=1,e=1,l=!1,u=0;u<Math.max(s,r);u++){var f=n.charAt(u);f===`
|
75
|
+
`?(l||i++,e=1,l=!1):f==="\r"||f==="\u2028"||f==="\u2029"?(i++,e=1,l=!0):(e++,l=!1)}return{line:i,column:e}}var Ll=ys(),fs=$u(),b={},w=o[a]();if(w===null||s!==n.length){var wi=Math.max(s,r),Oi=wi<n.length?n.charAt(wi):null,$l=co();return new this.SyntaxError(Ml(d),Oi,wi,$l.line,$l.column),-1}return b},toSource:function(){return this._source}};return t.SyntaxError=function(n,a,o,s,r){function d(h,_){var g,T;switch(h.length){case 0:g="end of input";break;case 1:g=h[0];break;default:g=h.slice(0,h.length-1).join(", ")+" or "+h[h.length-1]}return T=_?c(_):"end of input","Expected "+g+" but "+T+" found."}this.name="SyntaxError",this.expected=n,this.found=a,this.message=d(n,a),this.offset=o,this.line=s,this.column=r},t.SyntaxError.prototype=Error.prototype,t}()),Mo}var Lo,sf;function ys(){if(sf)return Lo;sf=1;const c=De,t=Ct(),n=Zt();return Lo=class ch{static parse(o){if(o=n.parse(o,"SIP_URI"),o!==-1)return o}constructor(o,s,r,d,h={},_={}){if(!r)throw new TypeError('missing or invalid "host" parameter');this._parameters={},this._headers={},this._scheme=o||c.SIP,this._user=s,this._host=r,this._port=d;for(const g in h)Object.prototype.hasOwnProperty.call(h,g)&&this.setParam(g,h[g]);for(const g in _)Object.prototype.hasOwnProperty.call(_,g)&&this.setHeader(g,_[g])}get scheme(){return this._scheme}set scheme(o){this._scheme=o.toLowerCase()}get user(){return this._user}set user(o){this._user=o}get host(){return this._host}set host(o){this._host=o.toLowerCase()}get port(){return this._port}set port(o){this._port=o===0?o:parseInt(o,10)||null}setParam(o,s){o&&(this._parameters[o.toLowerCase()]=typeof s>"u"||s===null?null:s.toString())}getParam(o){if(o)return this._parameters[o.toLowerCase()]}hasParam(o){if(o)return this._parameters.hasOwnProperty(o.toLowerCase())&&!0||!1}deleteParam(o){if(o=o.toLowerCase(),this._parameters.hasOwnProperty(o)){const s=this._parameters[o];return delete this._parameters[o],s}}clearParams(){this._parameters={}}setHeader(o,s){this._headers[t.headerize(o)]=Array.isArray(s)?s:[s]}getHeader(o){if(o)return this._headers[t.headerize(o)]}hasHeader(o){if(o)return this._headers.hasOwnProperty(t.headerize(o))&&!0||!1}deleteHeader(o){if(o=t.headerize(o),this._headers.hasOwnProperty(o)){const s=this._headers[o];return delete this._headers[o],s}}clearHeaders(){this._headers={}}clone(){return new ch(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}toString(){const o=[];let s=`${this._scheme}:`;this._user&&(s+=`${t.escapeUser(this._user)}@`),s+=this._host,(this._port||this._port===0)&&(s+=`:${this._port}`);for(const r in this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,r)&&(s+=`;${r}`,this._parameters[r]!==null&&(s+=`=${this._parameters[r]}`));for(const r in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,r))for(const d of this._headers[r])o.push(`${r}=${d}`);return o.length>0&&(s+=`?${o.join("&")}`),s}toAor(o){let s=`${this._scheme}:`;return this._user&&(s+=`${t.escapeUser(this._user)}@`),s+=this._host,o&&(this._port||this._port===0)&&(s+=`:${this._port}`),s}},Lo}var nf;function Ct(){if(nf)return et;nf=1;const c=De,t=ys(),n=Zt();et.str_utf8_length=r=>unescape(encodeURIComponent(r)).length;const a=et.isFunction=r=>r!==void 0?Object.prototype.toString.call(r)==="[object Function]":!1;et.isString=r=>r!==void 0?Object.prototype.toString.call(r)==="[object String]":!1,et.isDecimal=r=>!isNaN(r)&&parseFloat(r)===parseInt(r,10),et.isEmpty=r=>r===null||r===""||r===void 0||Array.isArray(r)&&r.length===0||typeof r=="number"&&isNaN(r),et.hasMethods=function(r,...d){for(const h of d)if(a(r[h]))return!1;return!0};const o=et.createRandomToken=(r,d=32)=>{let h,_,g="";for(h=0;h<r;h++)_=Math.random()*d|0,g+=_.toString(d);return g};et.newTag=()=>o(10),et.newUUID=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,d=>{const h=Math.random()*16|0;return(d==="x"?h:h&3|8).toString(16)}),et.hostType=r=>{if(r){if(r=n.parse(r,"host"),r!==-1)return r.host_type}else return};const s=et.escapeUser=r=>encodeURIComponent(decodeURIComponent(r)).replace(/%3A/ig,":").replace(/%2B/ig,"+").replace(/%3F/ig,"?").replace(/%2F/ig,"/");return et.normalizeTarget=(r,d)=>{if(r){if(r instanceof t)return r;if(typeof r=="string"){const h=r.split("@");let _,g;switch(h.length){case 1:if(!d)return;_=r,g=d;break;case 2:_=h[0],g=h[1];break;default:_=h.slice(0,h.length-1).join("@"),g=h[h.length-1]}_=_.replace(/^(sips?|tel):/i,""),/^[-.()]*\+?[0-9\-.()]+$/.test(_)&&(_=_.replace(/[-.()]/g,"")),r=`${c.SIP}:${s(_)}@${g}`;let T;return(T=t.parse(r))?T:void 0}else return}else return},et.headerize=r=>{const d={"Call-Id":"Call-ID",Cseq:"CSeq","Www-Authenticate":"WWW-Authenticate"},h=r.toLowerCase().replace(/_/g,"-").split("-");let _="";const g=h.length;let T;for(T=0;T<g;T++)T!==0&&(_+="-"),_+=h[T].charAt(0).toUpperCase()+h[T].substring(1);return d[_]&&(_=d[_]),_},et.sipErrorCause=r=>{for(const d in c.SIP_ERROR_CAUSES)if(c.SIP_ERROR_CAUSES[d].indexOf(r)!==-1)return c.causes[d];return c.causes.SIP_FAILURE_CODE},et.getRandomTestNetIP=()=>{function r(d,h){return Math.floor(Math.random()*(h-d+1)+d)}return`192.0.2.${r(1,254)}`},et.calculateMD5=r=>{function d(Ee,Ce){return Ee<<Ce|Ee>>>32-Ce}function h(Ee,Ce){const Ie=Ee&2147483648,Oe=Ce&2147483648,pe=Ee&1073741824,ue=Ce&1073741824,_e=(Ee&1073741823)+(Ce&1073741823);return pe&ue?_e^2147483648^Ie^Oe:pe|ue?_e&1073741824?_e^3221225472^Ie^Oe:_e^1073741824^Ie^Oe:_e^Ie^Oe}function _(Ee,Ce,Ie){return Ee&Ce|~Ee&Ie}function g(Ee,Ce,Ie){return Ee&Ie|Ce&~Ie}function T(Ee,Ce,Ie){return Ee^Ce^Ie}function E(Ee,Ce,Ie){return Ce^(Ee|~Ie)}function y(Ee,Ce,Ie,Oe,pe,ue,_e){return Ee=h(Ee,h(h(_(Ce,Ie,Oe),pe),_e)),h(d(Ee,ue),Ce)}function C(Ee,Ce,Ie,Oe,pe,ue,_e){return Ee=h(Ee,h(h(g(Ce,Ie,Oe),pe),_e)),h(d(Ee,ue),Ce)}function A(Ee,Ce,Ie,Oe,pe,ue,_e){return Ee=h(Ee,h(h(T(Ce,Ie,Oe),pe),_e)),h(d(Ee,ue),Ce)}function I(Ee,Ce,Ie,Oe,pe,ue,_e){return Ee=h(Ee,h(h(E(Ce,Ie,Oe),pe),_e)),h(d(Ee,ue),Ce)}function H(Ee){let Ce;const Ie=Ee.length,Oe=Ie+8,ue=((Oe-Oe%64)/64+1)*16,_e=new Array(ue-1);let we=0,Ne=0;for(;Ne<Ie;)Ce=(Ne-Ne%4)/4,we=Ne%4*8,_e[Ce]=_e[Ce]|Ee.charCodeAt(Ne)<<we,Ne++;return Ce=(Ne-Ne%4)/4,we=Ne%4*8,_e[Ce]=_e[Ce]|128<<we,_e[ue-2]=Ie<<3,_e[ue-1]=Ie>>>29,_e}function $(Ee){let Ce="",Ie="",Oe,pe;for(pe=0;pe<=3;pe++)Oe=Ee>>>pe*8&255,Ie=`0${Oe.toString(16)}`,Ce=Ce+Ie.substr(Ie.length-2,2);return Ce}function oe(Ee){let Ce="";for(let Ie=0;Ie<Ee.length;Ie++){const Oe=Ee.charCodeAt(Ie);Oe<128?Ce+=String.fromCharCode(Oe):Oe>127&&Oe<2048?(Ce+=String.fromCharCode(Oe>>6|192),Ce+=String.fromCharCode(Oe&63|128)):(Ce+=String.fromCharCode(Oe>>12|224),Ce+=String.fromCharCode(Oe>>6&63|128),Ce+=String.fromCharCode(Oe&63|128))}return Ce}let N=[],j,Se,ve,k,D,B,V,J,F;const X=7,U=12,P=17,se=22,st=5,ee=9,W=14,G=20,re=4,ge=11,be=16,xe=23,Ae=6,le=10,ye=15,nt=21;for(r=oe(r),N=H(r),B=1732584193,V=4023233417,J=2562383102,F=271733878,j=0;j<N.length;j+=16)Se=B,ve=V,k=J,D=F,B=y(B,V,J,F,N[j+0],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=C(B,V,J,F,N[j+1],st,4129170786),F=C(F,B,V,J,N[j+6],ee,3225465664),J=C(J,F,B,V,N[j+11],W,643717713),V=C(V,J,F,B,N[j+0],G,3921069994),B=C(B,V,J,F,N[j+5],st,3593408605),F=C(F,B,V,J,N[j+10],ee,38016083),J=C(J,F,B,V,N[j+15],W,3634488961),V=C(V,J,F,B,N[j+4],G,3889429448),B=C(B,V,J,F,N[j+9],st,568446438),F=C(F,B,V,J,N[j+14],ee,3275163606),J=C(J,F,B,V,N[j+3],W,4107603335),V=C(V,J,F,B,N[j+8],G,1163531501),B=C(B,V,J,F,N[j+13],st,2850285829),F=C(F,B,V,J,N[j+2],ee,4243563512),J=C(J,F,B,V,N[j+7],W,1735328473),V=C(V,J,F,B,N[j+12],G,2368359562),B=A(B,V,J,F,N[j+5],re,4294588738),F=A(F,B,V,J,N[j+8],ge,2272392833),J=A(J,F,B,V,N[j+11],be,1839030562),V=A(V,J,F,B,N[j+14],xe,4259657740),B=A(B,V,J,F,N[j+1],re,2763975236),F=A(F,B,V,J,N[j+4],ge,1272893353),J=A(J,F,B,V,N[j+7],be,4139469664),V=A(V,J,F,B,N[j+10],xe,3200236656),B=A(B,V,J,F,N[j+13],re,681279174),F=A(F,B,V,J,N[j+0],ge,3936430074),J=A(J,F,B,V,N[j+3],be,3572445317),V=A(V,J,F,B,N[j+6],xe,76029189),B=A(B,V,J,F,N[j+9],re,3654602809),F=A(F,B,V,J,N[j+12],ge,3873151461),J=A(J,F,B,V,N[j+15],be,530742520),V=A(V,J,F,B,N[j+2],xe,3299628645),B=I(B,V,J,F,N[j+0],Ae,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],nt,4237533241),B=I(B,V,J,F,N[j+12],Ae,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],nt,2240044497),B=I(B,V,J,F,N[j+8],Ae,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],nt,1309151649),B=I(B,V,J,F,N[j+4],Ae,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],nt,3951481745),B=h(B,Se),V=h(V,ve),J=h(J,k),F=h(F,D);return($(B)+$(V)+$(J)+$(F)).toLowerCase()},et.closeMediaStream=r=>{if(r)try{let d;if(r.getTracks){d=r.getTracks();for(const h of d)h.stop()}else{d=r.getAudioTracks();for(const h of d)h.stop();d=r.getVideoTracks();for(const h of d)h.stop()}}catch{(typeof r.stop=="function"||typeof r.stop=="object")&&r.stop()}},et.cloneArray=r=>r&&r.slice()||[],et.cloneObject=(r,d={})=>r&&Object.assign({},r)||d,et}const fh=xt,qm=ut,St=De,it=Ct(),rf=$u(),Vm=Zt(),$o=new qm("SIPMessage");class Ka{constructor(t,n,a,o,s,r){if(!t||!n||!a)return null;o=o||{},this.ua=a,this.headers={},this.method=t,this.ruri=n,this.body=r,this.extraHeaders=it.cloneArray(s),this.ua.configuration.extra_headers&&(this.extraHeaders=this.extraHeaders.concat(this.ua.configuration.extra_headers)),o.route_set?this.setHeader("route",o.route_set):a.configuration.use_preloaded_route&&this.setHeader("route",`<${a.transport.sip_uri};lr>`),this.setHeader("via",""),this.setHeader("max-forwards",St.MAX_FORWARDS);const d=o.to_uri||n,h=o.to_tag?{tag:o.to_tag}:null,_=typeof o.to_display_name<"u"?o.to_display_name:null;this.to=new rf(d,_,h),this.setHeader("to",this.to.toString());const g=o.from_uri||a.configuration.uri,T={tag:o.from_tag||it.newTag()};let E;typeof o.from_display_name<"u"?E=o.from_display_name:a.configuration.display_name?E=a.configuration.display_name:E=null,this.from=new rf(g,E,T),this.setHeader("from",this.from.toString());const y=o.call_id||a.configuration.jssip_id+it.createRandomToken(15);this.call_id=y,this.setHeader("call-id",y);const C=o.cseq||Math.floor(Math.random()*1e4);this.cseq=C,this.setHeader("cseq",`${C} ${t}`)}setHeader(t,n){const a=new RegExp(`^\\s*${t}\\s*:`,"i");for(let o=0;o<this.extraHeaders.length;o++)a.test(this.extraHeaders[o])&&this.extraHeaders.splice(o,1);this.headers[it.headerize(t)]=Array.isArray(n)?n:[n]}getHeader(t){const n=this.headers[it.headerize(t)];if(n){if(n[0])return n[0]}else{const a=new RegExp(`^\\s*${t}\\s*:`,"i");for(const o of this.extraHeaders)if(a.test(o))return o.substring(o.indexOf(":")+1).trim()}}getHeaders(t){const n=this.headers[it.headerize(t)],a=[];if(n){for(const o of n)a.push(o);return a}else{const o=new RegExp(`^\\s*${t}\\s*:`,"i");for(const s of this.extraHeaders)o.test(s)&&a.push(s.substring(s.indexOf(":")+1).trim());return a}}hasHeader(t){if(this.headers[it.headerize(t)])return!0;{const n=new RegExp(`^\\s*${t}\\s*:`,"i");for(const a of this.extraHeaders)if(n.test(a))return!0}return!1}parseSDP(t){return!t&&this.sdp?this.sdp:(this.sdp=fh.parse(this.body||""),this.sdp)}toString(){let t=`${this.method} ${this.ruri} SIP/2.0\r
|
76
76
|
`;for(const o in this.headers)if(Object.prototype.hasOwnProperty.call(this.headers,o))for(const s of this.headers[o])t+=`${o}: ${s}\r
|
77
77
|
`;for(const o of this.extraHeaders)t+=`${o.trim()}\r
|
78
78
|
`;const n=[];switch(this.method){case St.REGISTER:n.push("path","gruu");break;case St.INVITE:this.ua.configuration.session_timers&&n.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&n.push("gruu"),n.push("ice","replaces");break;case St.UPDATE:this.ua.configuration.session_timers&&n.push("timer"),n.push("ice");break}n.push("outbound");const a=this.ua.configuration.user_agent||St.USER_AGENT;if(t+=`Allow: ${St.ALLOWED_METHODS}\r
|
@@ -109,10 +109,10 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
109
109
|
`,this.ua.configuration.extra_headers)for(const r of this.ua.configuration.extra_headers)o+=`${r.trim()}\r
|
110
110
|
`;o+=`Content-Length: 0\r
|
111
111
|
\r
|
112
|
-
`,this.transport.send(o)}}class Gm extends hh{constructor(){super(),this.headers={},this.status_code=null,this.reason_phrase=null}}var yt={OutgoingRequest:Ka,InitialOutgoingInviteRequest:Hu,IncomingRequest:Bm,IncomingResponse:Gm};const pr=ze(yt),Wm=ut,ps=At(),Jt=new Wm("DigestAuthentication");var dh=class{constructor(t){this._credentials=t,this._cnonce=null,this._nc=0,this._ncHex="00000000",this._algorithm=null,this._realm=null,this._nonce=null,this._opaque=null,this._stale=null,this._qop=null,this._method=null,this._uri=null,this._ha1=null,this._response=null}get(t){switch(t){case"realm":return this._realm;case"ha1":return this._ha1;default:Jt.warn('get() | cannot get "%s" parameter',t);return}}authenticate({method:t,ruri:n,body:a},o,s=null){if(this._algorithm=o.algorithm,this._realm=o.realm,this._nonce=o.nonce,this._opaque=o.opaque,this._stale=o.stale,this._algorithm){if(this._algorithm!=="MD5")return 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(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 Jt.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;else this._qop=null;this._method=t,this._uri=n,this._cnonce=s||ps.createRandomToken(12),this._nc+=1;const r=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-r.length)+r,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=ps.calculateMD5(`${this._credentials.username}:${this._realm}:${this._credentials.password}`):this._ha1=this._credentials.ha1;let d,h;return this._qop==="auth"?(d=`${this._method}:${this._uri}`,h=ps.calculateMD5(d),Jt.debug('authenticate() | using qop=auth [a2:"%s"]',d),this._response=ps.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${h}`)):this._qop==="auth-int"?(d=`${this._method}:${this._uri}:${ps.calculateMD5(a||"")}`,h=ps.calculateMD5(d),Jt.debug('authenticate() | using qop=auth-int [a2:"%s"]',d),this._response=ps.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${h}`)):this._qop===null&&(d=`${this._method}:${this._uri}`,h=ps.calculateMD5(d),Jt.debug('authenticate() | using qop=null [a2:"%s"]',d),this._response=ps.calculateMD5(`${this._ha1}:${this._nonce}:${h}`)),Jt.debug("authenticate() | response generated"),!0}toString(){const t=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return t.push(`algorithm=${this._algorithm}`),t.push(`username="${this._credentials.username}"`),t.push(`realm="${this._realm}"`),t.push(`nonce="${this._nonce}"`),t.push(`uri="${this._uri}"`),t.push(`response="${this._response}"`),this._opaque&&t.push(`opaque="${this._opaque}"`),this._qop&&(t.push(`qop=${this._qop}`),t.push(`cnonce="${this._cnonce}"`),t.push(`nc=${this._ncHex}`)),`Digest ${t.join(", ")}`}};const Km=ze(dh),ms=500,Ym=4e3,lf=5e3;var Fu={T1:ms,T2:Ym,T4:lf,TIMER_B:64*ms,TIMER_D:0*ms,TIMER_F:64*ms,TIMER_H:64*ms,TIMER_I:0*ms,TIMER_J:0*ms,TIMER_K:0*lf,TIMER_L:64*ms,TIMER_M:64*ms,PROVISIONAL_RESPONSE_INTERVAL:6e4};const $i=ze(Fu),_l=ft.EventEmitter,pl=ut,Xi=De,af=yt,as=Fu,of=new pl("NonInviteClientTransaction"),zl=new pl("InviteClientTransaction"),Jm=new pl("AckClientTransaction"),uf=new pl("NonInviteServerTransaction"),Xl=new pl("InviteServerTransaction"),de={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 zm extends _l{constructor(t,n,a,o){super(),this.type=de.NON_INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=t,this.transport=n,this.request=a,this.eventHandlers=o;let s=`SIP/2.0/${n.via_transport}`;s+=` ${t.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",s),this.ua.newTransaction(this)}get C(){return de}stateChanged(t){this.state=t,this.emit("stateChanged")}send(){this.stateChanged(de.STATUS_TRYING),this.F=setTimeout(()=>{this.timer_F()},as.TIMER_F),this.transport.send(this.request)||this.onTransportError()}onTransportError(){of.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}timer_F(){of.debug(`Timer F expired for transaction ${this.id}`),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}timer_K(){this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}receiveResponse(t){const n=t.status_code;if(n<200)switch(this.state){case de.STATUS_TRYING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(t);break}else switch(this.state){case de.STATUS_TRYING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_COMPLETED),clearTimeout(this.F),n===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(t),this.K=setTimeout(()=>{this.timer_K()},as.TIMER_K);break;case de.STATUS_COMPLETED:break}}}class Xm extends _l{constructor(t,n,a,o){super(),this.type=de.INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=t,this.transport=n,this.request=a,this.eventHandlers=o,a.transaction=this;let s=`SIP/2.0/${n.via_transport}`;s+=` ${t.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",s),this.ua.newTransaction(this)}get C(){return de}stateChanged(t){this.state=t,this.emit("stateChanged")}send(){this.stateChanged(de.STATUS_CALLING),this.B=setTimeout(()=>{this.timer_B()},as.TIMER_B),this.transport.send(this.request)||this.onTransportError()}onTransportError(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==de.STATUS_ACCEPTED&&(zl.debug(`transport error occurred, deleting transaction ${this.id}`),this.eventHandlers.onTransportError()),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_M(){zl.debug(`Timer M expired for transaction ${this.id}`),this.state===de.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this))}timer_B(){zl.debug(`Timer B expired for transaction ${this.id}`),this.state===de.STATUS_CALLING&&(this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}timer_D(){zl.debug(`Timer D expired for transaction ${this.id}`),clearTimeout(this.B),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}sendACK(t){const n=new af.OutgoingRequest(Xi.ACK,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});n.setHeader("from",this.request.getHeader("from")),n.setHeader("via",this.request.getHeader("via")),n.setHeader("to",t.getHeader("to")),this.D=setTimeout(()=>{this.timer_D()},as.TIMER_D),this.transport.send(n)}cancel(t){if(this.state!==de.STATUS_PROCEEDING)return;const n=new af.OutgoingRequest(Xi.CANCEL,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});n.setHeader("from",this.request.getHeader("from")),n.setHeader("via",this.request.getHeader("via")),n.setHeader("to",this.request.getHeader("to")),t&&n.setHeader("reason",t),this.transport.send(n)}receiveResponse(t){const n=t.status_code;if(n>=100&&n<=199)switch(this.state){case de.STATUS_CALLING:this.stateChanged(de.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(t);break;case de.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(t);break}else if(n>=200&&n<=299)switch(this.state){case de.STATUS_CALLING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_ACCEPTED),this.M=setTimeout(()=>{this.timer_M()},as.TIMER_M),this.eventHandlers.onReceiveResponse(t);break;case de.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(t);break}else if(n>=300&&n<=699)switch(this.state){case de.STATUS_CALLING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_COMPLETED),this.sendACK(t),this.eventHandlers.onReceiveResponse(t);break;case de.STATUS_COMPLETED:this.sendACK(t);break}}}class Qm extends _l{constructor(t,n,a,o){super(),this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.transport=n,this.request=a,this.eventHandlers=o;let s=`SIP/2.0/${n.via_transport}`;s+=` ${t.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",s)}get C(){return de}send(){this.transport.send(this.request)||this.onTransportError()}onTransportError(){Jm.debug(`transport error occurred for transaction ${this.id}`),this.eventHandlers.onTransportError()}}class Zm extends _l{constructor(t,n,a){super(),this.type=de.NON_INVITE_SERVER,this.id=a.via_branch,this.ua=t,this.transport=n,this.request=a,this.last_response="",a.server_transaction=this,this.state=de.STATUS_TRYING,t.newTransaction(this)}get C(){return de}stateChanged(t){this.state=t,this.emit("stateChanged")}timer_J(){uf.debug(`Timer J expired for transaction ${this.id}`),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}onTransportError(){this.transportError||(this.transportError=!0,uf.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.J),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this))}receiveResponse(t,n,a,o){if(t===100)switch(this.state){case de.STATUS_TRYING:this.stateChanged(de.STATUS_PROCEEDING),this.transport.send(n)||this.onTransportError();break;case de.STATUS_PROCEEDING:this.last_response=n,this.transport.send(n)?a&&a():(this.onTransportError(),o&&o());break}else if(t>=200&&t<=699)switch(this.state){case de.STATUS_TRYING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_COMPLETED),this.last_response=n,this.J=setTimeout(()=>{this.timer_J()},as.TIMER_J),this.transport.send(n)?a&&a():(this.onTransportError(),o&&o());break;case de.STATUS_COMPLETED:break}}}class eg extends _l{constructor(t,n,a){super(),this.type=de.INVITE_SERVER,this.id=a.via_branch,this.ua=t,this.transport=n,this.request=a,this.last_response="",a.server_transaction=this,this.state=de.STATUS_PROCEEDING,t.newTransaction(this),this.resendProvisionalTimer=null,a.reply(100)}get C(){return de}stateChanged(t){this.state=t,this.emit("stateChanged")}timer_H(){Xl.debug(`Timer H expired for transaction ${this.id}`),this.state===de.STATUS_COMPLETED&&Xl.debug("ACK not received, dialog will be terminated"),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_I(){this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_L(){Xl.debug(`Timer L expired for transaction ${this.id}`),this.state===de.STATUS_ACCEPTED&&(this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this))}onTransportError(){this.transportError||(this.transportError=!0,Xl.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(de.STATUS_TERMINATED),this.ua.destroyTransaction(this))}resend_provisional(){this.transport.send(this.last_response)||this.onTransportError()}receiveResponse(t,n,a,o){if(t>=100&&t<=199)switch(this.state){case de.STATUS_PROCEEDING:this.transport.send(n)||this.onTransportError(),this.last_response=n;break}if(t>100&&t<=199&&this.state===de.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(()=>{this.resend_provisional()},as.PROVISIONAL_RESPONSE_INTERVAL));else if(t>=200&&t<=299)switch(this.state){case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_ACCEPTED),this.last_response=n,this.L=setTimeout(()=>{this.timer_L()},as.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case de.STATUS_ACCEPTED:this.transport.send(n)?a&&a():(this.onTransportError(),o&&o());break}else if(t>=300&&t<=699)switch(this.state){case de.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(n)?(this.stateChanged(de.STATUS_COMPLETED),this.H=setTimeout(()=>{this.timer_H()},as.TIMER_H),a&&a()):(this.onTransportError(),o&&o());break}}}function tg({_transactions:c},t){let n;switch(t.method){case Xi.INVITE:if(n=c.ist[t.via_branch],n){switch(n.state){case de.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case de.STATUS_ACCEPTED:break}return!0}break;case Xi.ACK:if(n=c.ist[t.via_branch],n){if(n.state===de.STATUS_ACCEPTED)return!1;if(n.state===de.STATUS_COMPLETED)return n.state=de.STATUS_CONFIRMED,n.I=setTimeout(()=>{n.timer_I()},as.TIMER_I),!0}else return!1;break;case Xi.CANCEL:return n=c.ist[t.via_branch],n?(t.reply_sl(200),n.state!==de.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=c.nist[t.via_branch],n){switch(n.state){case de.STATUS_TRYING:break;case de.STATUS_PROCEEDING:case de.STATUS_COMPLETED:n.transport.send(n.last_response);break}return!0}break}}var Tr={C:de,NonInviteClientTransaction:zm,InviteClientTransaction:Xm,AckClientTransaction:Qm,NonInviteServerTransaction:Zm,InviteServerTransaction:eg,checkTransaction:tg};const Gt=ze(Tr),sg=ut,cf=De,ng=dh,Ho=Tr,rg=new sg("RequestSender"),Fo={onRequestTimeout:()=>{},onTransportError:()=>{},onReceiveResponse:()=>{},onAuthenticated:()=>{}};var vr=class{constructor(t,n,a){this._ua=t,this._eventHandlers=a,this._method=n.method,this._request=n,this._auth=null,this._challenged=!1,this._staled=!1;for(const o in Fo)Object.prototype.hasOwnProperty.call(Fo,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=Fo[o]));t.status===t.C.STATUS_USER_CLOSED&&(this._method!==cf.BYE||this._method!==cf.ACK)&&this._eventHandlers.onTransportError()}send(){const t={onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onReceiveResponse:n=>{this._receiveResponse(n)}};switch(this._method){case"INVITE":this.clientTransaction=new Ho.InviteClientTransaction(this._ua,this._ua.transport,this._request,t);break;case"ACK":this.clientTransaction=new Ho.AckClientTransaction(this._ua,this._ua.transport,this._request,t);break;default:this.clientTransaction=new Ho.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,t)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}_receiveResponse(t){let n,a;const o=t.status_code;if((o===401||o===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(t.status_code===401?(n=t.parseHeader("www-authenticate"),a="authorization"):(n=t.parseHeader("proxy-authenticate"),a="proxy-authorization"),!n){rg.debug(`${t.status_code} with wrong or missing challenge, cannot authenticate`),this._eventHandlers.onReceiveResponse(t);return}if(!this._challenged||!this._staled&&n.stale===!0){if(this._auth||(this._auth=new ng({username:this._ua.configuration.authorization_user,password:this._ua.configuration.password,realm:this._ua.configuration.realm,ha1:this._ua.configuration.ha1})),!this._auth.authenticate(this._request,n)){this._eventHandlers.onReceiveResponse(t);return}this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),n.stale&&(this._staled=!0),this._request=this._request.clone(),this._request.cseq+=1,this._request.setHeader("cseq",`${this._request.cseq} ${this._method}`),this._request.setHeader(a,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(t)}else this._eventHandlers.onReceiveResponse(t)}};const sl=ze(vr),ig=ut,jo=At(),Tn=De,ff=yt,hf=vr,Hi=new ig("Registrator"),Ql=10;var lg=class{constructor(t,n){this._reg_id=1,this._ua=t,this._transport=n,this._registrar=t.configuration.registrar_server,this._expires=t.configuration.register_expires,this._call_id=jo.createRandomToken(22),this._cseq=0,this._to_uri=t.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString(),this._contact+=";+sip.ice",this._extraHeaders=[],this._extraContactParams="",this._sipInstance=`"<urn:uuid:${this._ua.configuration.instance_id}>"`,this._contact+=`;reg-id=${this._reg_id}`,this._contact+=`;+sip.instance=${this._sipInstance}`}get registered(){return this._registered}setExtraHeaders(t){Array.isArray(t)||(t=[]),this._extraHeaders=t.slice()}setExtraContactParams(t){t instanceof Object||(t={}),this._extraContactParams="";for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)){const a=t[n];this._extraContactParams+=`;${n}`,a&&(this._extraContactParams+=`=${a}`)}}register(){if(this._registering){Hi.debug("Register request in progress...");return}const t=this._extraHeaders.slice();t.push(`Contact: ${this._contact};expires=${this._expires}${this._extraContactParams}`),t.push(`Expires: ${this._expires}`);const n=new ff.OutgoingRequest(Tn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),a=new hf(this._ua,n,{onRequestTimeout:()=>{this._registrationFailure(null,Tn.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,Tn.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:o=>{if(o.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):{if(this._registering=!1,!o.hasHeader("Contact")){Hi.debug("no Contact header in response to REGISTER, response ignored");break}const s=o.headers.Contact.reduce((_,g)=>_.concat(g.parsed),[]);let r=s.find(_=>this._sipInstance===_.getParam("+sip.instance")&&this._reg_id===parseInt(_.getParam("reg-id")));if(r||(r=s.find(_=>_.uri.user===this._ua.contact.uri.user)),!r){Hi.debug("no Contact header pointing to us, response ignored");break}let d=r.getParam("expires");!d&&o.hasHeader("expires")&&(d=o.getHeader("expires")),d||(d=this._expires),d=Number(d),d<Ql&&(d=Ql);const h=d>64?d*1e3/2+Math.floor((d/2-32)*1e3*Math.random()):d*1e3-5e3;this._registrationTimer=setTimeout(()=>{this._registrationTimer=null,this._ua.listeners("registrationExpiring").length===0?this.register():this._ua.emit("registrationExpiring")},h),r.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),this._registered||(this._registered=!0,this._ua.registered({response:o}));break}case/^423$/.test(o.status_code):{o.hasHeader("min-expires")?(this._expires=Number(o.getHeader("min-expires")),this._expires<Ql&&(this._expires=Ql),this.register()):(Hi.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(o,Tn.causes.SIP_FAILURE_CODE));break}default:{const s=jo.sipErrorCause(o.status_code);this._registrationFailure(o,s)}}}});this._registering=!0,a.send()}unregister(t={}){if(!this._registered){Hi.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const n=this._extraHeaders.slice();t.all?n.push(`Contact: *${this._extraContactParams}`):n.push(`Contact: ${this._contact};expires=0${this._extraContactParams}`),n.push("Expires: 0");const a=new ff.OutgoingRequest(Tn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new hf(this._ua,a,{onRequestTimeout:()=>{this._unregistered(null,Tn.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,Tn.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:s=>{switch(!0){case/^1[0-9]{2}$/.test(s.status_code):break;case/^2[0-9]{2}$/.test(s.status_code):this._unregistered(s);break;default:{const r=jo.sipErrorCause(s.status_code);this._unregistered(s,r)}}}}).send()}close(){this._registered&&this.unregister()}onTransportClosed(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}_registrationFailure(t,n){this._registering=!1,this._ua.registrationFailed({response:t||null,cause:n}),this._registered&&(this._registered=!1,this._ua.unregistered({response:t||null,cause:n}))}_unregistered(t,n){this._registering=!1,this._registered=!1,this._ua.unregistered({response:t||null,cause:n||null})}};class ag extends Error{constructor(t,n){super(),this.code=1,this.name="CONFIGURATION_ERROR",this.parameter=t,this.value=n,this.message=this.value?`Invalid value ${JSON.stringify(this.value)} for parameter "${this.parameter}"`:`Missing parameter: ${this.parameter}`}}class og extends Error{constructor(t){super(),this.code=2,this.name="INVALID_STATE_ERROR",this.status=t,this.message=`Invalid status: ${t}`}}class ug extends Error{constructor(t){super(),this.code=3,this.name="NOT_SUPPORTED_ERROR",this.message=t}}class cg extends Error{constructor(t){super(),this.code=4,this.name="NOT_READY_ERROR",this.message=t}}var As={ConfigurationError:ag,InvalidStateError:og,NotSupportedError:ug,NotReadyError:cg};const qs=ze(As),qo=De,Zl=Tr,fg=vr,Vo={onRequestTimeout:()=>{},onTransportError:()=>{},onSuccessResponse:()=>{},onErrorResponse:()=>{},onAuthenticated:()=>{},onDialogError:()=>{}};var _h=class{constructor(t,n,a){this._dialog=t,this._ua=t._ua,this._request=n,this._eventHandlers=a,this._reattempt=!1,this._reattemptTimer=null;for(const o in Vo)Object.prototype.hasOwnProperty.call(Vo,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=Vo[o]))}get request(){return this._request}send(){const t=new fg(this._ua,this._request,{onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onAuthenticated:n=>{this._eventHandlers.onAuthenticated(n)},onReceiveResponse:n=>{this._receiveResponse(n)}});if(t.send(),(this._request.method===qo.INVITE||this._request.method===qo.UPDATE&&this._request.body)&&t.clientTransaction.state!==Zl.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;const n=()=>{(t.clientTransaction.state===Zl.C.STATUS_ACCEPTED||t.clientTransaction.state===Zl.C.STATUS_COMPLETED||t.clientTransaction.state===Zl.C.STATUS_TERMINATED)&&(t.clientTransaction.removeListener("stateChanged",n),this._dialog.uac_pending_reply=!1)};t.clientTransaction.on("stateChanged",n)}}_receiveResponse(t){t.status_code===408||t.status_code===481?this._eventHandlers.onDialogError(t):t.method===qo.INVITE&&t.status_code===491?this._reattempt?t.status_code>=200&&t.status_code<300?this._eventHandlers.onSuccessResponse(t):t.status_code>=300&&this._eventHandlers.onErrorResponse(t):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(()=>{this._dialog.isTerminated()||(this._reattempt=!0,this.send())},1e3)):t.status_code>=200&&t.status_code<300?this._eventHandlers.onSuccessResponse(t):t.status_code>=300&&this._eventHandlers.onErrorResponse(t)}};const hg=ze(_h),dg=ut,df=yt,$s=De,Fi=Tr,_g=_h,Bo=At(),Go=new dg("Dialog"),Hs={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};var ph=class{static get C(){return Hs}constructor(t,n,a,o=Hs.STATUS_CONFIRMED){if(this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!n.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};n instanceof df.IncomingResponse&&(o=n.status_code<200?Hs.STATUS_EARLY:Hs.STATUS_CONFIRMED);const s=n.parseHeader("contact");a==="UAS"?(this._id={call_id:n.call_id,local_tag:n.to_tag,remote_tag:n.from_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri,this._remote_target=s.uri,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):a==="UAC"&&(this._id={call_id:n.call_id,local_tag:n.from_tag,remote_tag:n.to_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=s.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),Go.debug(`new ${a} dialog created with status ${this._state===Hs.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(t){this._local_seqnum=t}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(t){this._uac_pending_reply=t}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===Hs.STATUS_TERMINATED}update(t,n){this._state=Hs.STATUS_CONFIRMED,Go.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),n==="UAC"&&(this._route_set=t.getHeaders("record-route").reverse())}terminate(){Go.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Hs.STATUS_TERMINATED}sendRequest(t,n={}){const a=Bo.cloneArray(n.extraHeaders),o=Bo.cloneObject(n.eventHandlers),s=n.body||null,r=this._createRequest(t,a,s);return o.onAuthenticated=()=>{this._local_seqnum+=1},new _g(this,r,o).send(),r}receiveRequest(t){this._checkInDialogRequest(t)&&(t.method===$s.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:t.method===$s.INVITE&&(this._ack_seqnum=t.cseq),this._owner.receiveRequest(t))}_createRequest(t,n,a){n=Bo.cloneArray(n),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const o=t===$s.CANCEL||t===$s.ACK?this._local_seqnum:this._local_seqnum+=1;return new df.OutgoingRequest(t,this._remote_target,this._ua,{cseq:o,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},n,a)}_checkInDialogRequest(t){if(!this._remote_seqnum)this._remote_seqnum=t.cseq;else if(t.cseq<this._remote_seqnum)if(t.method===$s.ACK){if(this._ack_seqnum===null||t.cseq!==this._ack_seqnum)return!1}else return t.reply(500),!1;else t.cseq>this._remote_seqnum&&(this._remote_seqnum=t.cseq);if(t.method===$s.INVITE||t.method===$s.UPDATE&&t.body){if(this._uac_pending_reply===!0)t.reply(491);else if(this._uas_pending_reply===!0){const n=(Math.random()*10|0)+1;return t.reply(500,null,[`Retry-After:${n}`]),!1}else{this._uas_pending_reply=!0;const n=()=>{(t.server_transaction.state===Fi.C.STATUS_ACCEPTED||t.server_transaction.state===Fi.C.STATUS_COMPLETED||t.server_transaction.state===Fi.C.STATUS_TERMINATED)&&(t.server_transaction.removeListener("stateChanged",n),this._uas_pending_reply=!1)};t.server_transaction.on("stateChanged",n)}t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===Fi.C.STATUS_ACCEPTED&&(this._remote_target=t.parseHeader("contact").uri)})}else t.method===$s.NOTIFY&&t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===Fi.C.STATUS_COMPLETED&&(this._remote_target=t.parseHeader("contact").uri)});return!0}};const ea=ze(ph);var ju={exports:{}};const pg=ft.EventEmitter,mg=ut,gg=De,Tg=As,_f=At(),vg=new mg("RTCSession:DTMF"),mh={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};ju.exports=class extends pg{constructor(t){super(),this._session=t,this._direction=null,this._tone=null,this._duration=null,this._request=null}get tone(){return this._tone}get duration(){return this._duration}send(t,n={}){if(t===void 0)throw new TypeError("Not enough arguments");if(this._direction="outgoing",this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new Tg.InvalidStateError(this._session.status);const a=_f.cloneArray(n.extraHeaders);if(this.eventHandlers=_f.cloneObject(n.eventHandlers),typeof t=="string")t=t.toUpperCase();else if(typeof t=="number")t=t.toString();else throw new TypeError(`Invalid tone: ${t}`);if(t.match(/^[0-9A-DR#*]$/))this._tone=t;else throw new TypeError(`Invalid tone: ${t}`);this._duration=n.duration,a.push("Content-Type: application/dtmf-relay");let o=`Signal=${this._tone}\r
|
112
|
+
`,this.transport.send(o)}}class Gm extends hh{constructor(){super(),this.headers={},this.status_code=null,this.reason_phrase=null}}var yt={OutgoingRequest:Ka,InitialOutgoingInviteRequest:Hu,IncomingRequest:Bm,IncomingResponse:Gm};const pr=ze(yt),Wm=ut,ps=Ct(),Jt=new Wm("DigestAuthentication");var dh=class{constructor(t){this._credentials=t,this._cnonce=null,this._nc=0,this._ncHex="00000000",this._algorithm=null,this._realm=null,this._nonce=null,this._opaque=null,this._stale=null,this._qop=null,this._method=null,this._uri=null,this._ha1=null,this._response=null}get(t){switch(t){case"realm":return this._realm;case"ha1":return this._ha1;default:Jt.warn('get() | cannot get "%s" parameter',t);return}}authenticate({method:t,ruri:n,body:a},o,s=null){if(this._algorithm=o.algorithm,this._realm=o.realm,this._nonce=o.nonce,this._opaque=o.opaque,this._stale=o.stale,this._algorithm){if(this._algorithm!=="MD5")return 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(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 Jt.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;else this._qop=null;this._method=t,this._uri=n,this._cnonce=s||ps.createRandomToken(12),this._nc+=1;const r=Number(this._nc).toString(16);this._ncHex="00000000".substr(0,8-r.length)+r,this._nc===4294967296&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=ps.calculateMD5(`${this._credentials.username}:${this._realm}:${this._credentials.password}`):this._ha1=this._credentials.ha1;let d,h;return this._qop==="auth"?(d=`${this._method}:${this._uri}`,h=ps.calculateMD5(d),Jt.debug('authenticate() | using qop=auth [a2:"%s"]',d),this._response=ps.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${h}`)):this._qop==="auth-int"?(d=`${this._method}:${this._uri}:${ps.calculateMD5(a||"")}`,h=ps.calculateMD5(d),Jt.debug('authenticate() | using qop=auth-int [a2:"%s"]',d),this._response=ps.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${h}`)):this._qop===null&&(d=`${this._method}:${this._uri}`,h=ps.calculateMD5(d),Jt.debug('authenticate() | using qop=null [a2:"%s"]',d),this._response=ps.calculateMD5(`${this._ha1}:${this._nonce}:${h}`)),Jt.debug("authenticate() | response generated"),!0}toString(){const t=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return t.push(`algorithm=${this._algorithm}`),t.push(`username="${this._credentials.username}"`),t.push(`realm="${this._realm}"`),t.push(`nonce="${this._nonce}"`),t.push(`uri="${this._uri}"`),t.push(`response="${this._response}"`),this._opaque&&t.push(`opaque="${this._opaque}"`),this._qop&&(t.push(`qop=${this._qop}`),t.push(`cnonce="${this._cnonce}"`),t.push(`nc=${this._ncHex}`)),`Digest ${t.join(", ")}`}};const Km=ze(dh),ms=500,Ym=4e3,lf=5e3;var Fu={T1:ms,T2:Ym,T4:lf,TIMER_B:64*ms,TIMER_D:0*ms,TIMER_F:64*ms,TIMER_H:64*ms,TIMER_I:0*ms,TIMER_J:0*ms,TIMER_K:0*lf,TIMER_L:64*ms,TIMER_M:64*ms,PROVISIONAL_RESPONSE_INTERVAL:6e4};const $i=ze(Fu),_l=ft.EventEmitter,pl=ut,Xi=De,af=yt,as=Fu,of=new pl("NonInviteClientTransaction"),zl=new pl("InviteClientTransaction"),Jm=new pl("AckClientTransaction"),uf=new pl("NonInviteServerTransaction"),Xl=new pl("InviteServerTransaction"),de={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 zm extends _l{constructor(t,n,a,o){super(),this.type=de.NON_INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=t,this.transport=n,this.request=a,this.eventHandlers=o;let s=`SIP/2.0/${n.via_transport}`;s+=` ${t.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",s),this.ua.newTransaction(this)}get C(){return de}stateChanged(t){this.state=t,this.emit("stateChanged")}send(){this.stateChanged(de.STATUS_TRYING),this.F=setTimeout(()=>{this.timer_F()},as.TIMER_F),this.transport.send(this.request)||this.onTransportError()}onTransportError(){of.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.F),clearTimeout(this.K),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onTransportError()}timer_F(){of.debug(`Timer F expired for transaction ${this.id}`),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout()}timer_K(){this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}receiveResponse(t){const n=t.status_code;if(n<200)switch(this.state){case de.STATUS_TRYING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(t);break}else switch(this.state){case de.STATUS_TRYING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_COMPLETED),clearTimeout(this.F),n===408?this.eventHandlers.onRequestTimeout():this.eventHandlers.onReceiveResponse(t),this.K=setTimeout(()=>{this.timer_K()},as.TIMER_K);break;case de.STATUS_COMPLETED:break}}}class Xm extends _l{constructor(t,n,a,o){super(),this.type=de.INVITE_CLIENT,this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.ua=t,this.transport=n,this.request=a,this.eventHandlers=o,a.transaction=this;let s=`SIP/2.0/${n.via_transport}`;s+=` ${t.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",s),this.ua.newTransaction(this)}get C(){return de}stateChanged(t){this.state=t,this.emit("stateChanged")}send(){this.stateChanged(de.STATUS_CALLING),this.B=setTimeout(()=>{this.timer_B()},as.TIMER_B),this.transport.send(this.request)||this.onTransportError()}onTransportError(){clearTimeout(this.B),clearTimeout(this.D),clearTimeout(this.M),this.state!==de.STATUS_ACCEPTED&&(zl.debug(`transport error occurred, deleting transaction ${this.id}`),this.eventHandlers.onTransportError()),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_M(){zl.debug(`Timer M expired for transaction ${this.id}`),this.state===de.STATUS_ACCEPTED&&(clearTimeout(this.B),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this))}timer_B(){zl.debug(`Timer B expired for transaction ${this.id}`),this.state===de.STATUS_CALLING&&(this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this),this.eventHandlers.onRequestTimeout())}timer_D(){zl.debug(`Timer D expired for transaction ${this.id}`),clearTimeout(this.B),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}sendACK(t){const n=new af.OutgoingRequest(Xi.ACK,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});n.setHeader("from",this.request.getHeader("from")),n.setHeader("via",this.request.getHeader("via")),n.setHeader("to",t.getHeader("to")),this.D=setTimeout(()=>{this.timer_D()},as.TIMER_D),this.transport.send(n)}cancel(t){if(this.state!==de.STATUS_PROCEEDING)return;const n=new af.OutgoingRequest(Xi.CANCEL,this.request.ruri,this.ua,{route_set:this.request.getHeaders("route"),call_id:this.request.getHeader("call-id"),cseq:this.request.cseq});n.setHeader("from",this.request.getHeader("from")),n.setHeader("via",this.request.getHeader("via")),n.setHeader("to",this.request.getHeader("to")),t&&n.setHeader("reason",t),this.transport.send(n)}receiveResponse(t){const n=t.status_code;if(n>=100&&n<=199)switch(this.state){case de.STATUS_CALLING:this.stateChanged(de.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(t);break;case de.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(t);break}else if(n>=200&&n<=299)switch(this.state){case de.STATUS_CALLING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_ACCEPTED),this.M=setTimeout(()=>{this.timer_M()},as.TIMER_M),this.eventHandlers.onReceiveResponse(t);break;case de.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(t);break}else if(n>=300&&n<=699)switch(this.state){case de.STATUS_CALLING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_COMPLETED),this.sendACK(t),this.eventHandlers.onReceiveResponse(t);break;case de.STATUS_COMPLETED:this.sendACK(t);break}}}class Qm extends _l{constructor(t,n,a,o){super(),this.id=`z9hG4bK${Math.floor(Math.random()*1e7)}`,this.transport=n,this.request=a,this.eventHandlers=o;let s=`SIP/2.0/${n.via_transport}`;s+=` ${t.configuration.via_host};branch=${this.id}`,this.request.setHeader("via",s)}get C(){return de}send(){this.transport.send(this.request)||this.onTransportError()}onTransportError(){Jm.debug(`transport error occurred for transaction ${this.id}`),this.eventHandlers.onTransportError()}}class Zm extends _l{constructor(t,n,a){super(),this.type=de.NON_INVITE_SERVER,this.id=a.via_branch,this.ua=t,this.transport=n,this.request=a,this.last_response="",a.server_transaction=this,this.state=de.STATUS_TRYING,t.newTransaction(this)}get C(){return de}stateChanged(t){this.state=t,this.emit("stateChanged")}timer_J(){uf.debug(`Timer J expired for transaction ${this.id}`),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}onTransportError(){this.transportError||(this.transportError=!0,uf.debug(`transport error occurred, deleting transaction ${this.id}`),clearTimeout(this.J),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this))}receiveResponse(t,n,a,o){if(t===100)switch(this.state){case de.STATUS_TRYING:this.stateChanged(de.STATUS_PROCEEDING),this.transport.send(n)||this.onTransportError();break;case de.STATUS_PROCEEDING:this.last_response=n,this.transport.send(n)?a&&a():(this.onTransportError(),o&&o());break}else if(t>=200&&t<=699)switch(this.state){case de.STATUS_TRYING:case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_COMPLETED),this.last_response=n,this.J=setTimeout(()=>{this.timer_J()},as.TIMER_J),this.transport.send(n)?a&&a():(this.onTransportError(),o&&o());break;case de.STATUS_COMPLETED:break}}}class eg extends _l{constructor(t,n,a){super(),this.type=de.INVITE_SERVER,this.id=a.via_branch,this.ua=t,this.transport=n,this.request=a,this.last_response="",a.server_transaction=this,this.state=de.STATUS_PROCEEDING,t.newTransaction(this),this.resendProvisionalTimer=null,a.reply(100)}get C(){return de}stateChanged(t){this.state=t,this.emit("stateChanged")}timer_H(){Xl.debug(`Timer H expired for transaction ${this.id}`),this.state===de.STATUS_COMPLETED&&Xl.debug("ACK not received, dialog will be terminated"),this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_I(){this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this)}timer_L(){Xl.debug(`Timer L expired for transaction ${this.id}`),this.state===de.STATUS_ACCEPTED&&(this.stateChanged(de.STATUS_TERMINATED),this.ua.destroyTransaction(this))}onTransportError(){this.transportError||(this.transportError=!0,Xl.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(de.STATUS_TERMINATED),this.ua.destroyTransaction(this))}resend_provisional(){this.transport.send(this.last_response)||this.onTransportError()}receiveResponse(t,n,a,o){if(t>=100&&t<=199)switch(this.state){case de.STATUS_PROCEEDING:this.transport.send(n)||this.onTransportError(),this.last_response=n;break}if(t>100&&t<=199&&this.state===de.STATUS_PROCEEDING)this.resendProvisionalTimer===null&&(this.resendProvisionalTimer=setInterval(()=>{this.resend_provisional()},as.PROVISIONAL_RESPONSE_INTERVAL));else if(t>=200&&t<=299)switch(this.state){case de.STATUS_PROCEEDING:this.stateChanged(de.STATUS_ACCEPTED),this.last_response=n,this.L=setTimeout(()=>{this.timer_L()},as.TIMER_L),this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case de.STATUS_ACCEPTED:this.transport.send(n)?a&&a():(this.onTransportError(),o&&o());break}else if(t>=300&&t<=699)switch(this.state){case de.STATUS_PROCEEDING:this.resendProvisionalTimer!==null&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(n)?(this.stateChanged(de.STATUS_COMPLETED),this.H=setTimeout(()=>{this.timer_H()},as.TIMER_H),a&&a()):(this.onTransportError(),o&&o());break}}}function tg({_transactions:c},t){let n;switch(t.method){case Xi.INVITE:if(n=c.ist[t.via_branch],n){switch(n.state){case de.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case de.STATUS_ACCEPTED:break}return!0}break;case Xi.ACK:if(n=c.ist[t.via_branch],n){if(n.state===de.STATUS_ACCEPTED)return!1;if(n.state===de.STATUS_COMPLETED)return n.state=de.STATUS_CONFIRMED,n.I=setTimeout(()=>{n.timer_I()},as.TIMER_I),!0}else return!1;break;case Xi.CANCEL:return n=c.ist[t.via_branch],n?(t.reply_sl(200),n.state!==de.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=c.nist[t.via_branch],n){switch(n.state){case de.STATUS_TRYING:break;case de.STATUS_PROCEEDING:case de.STATUS_COMPLETED:n.transport.send(n.last_response);break}return!0}break}}var Tr={C:de,NonInviteClientTransaction:zm,InviteClientTransaction:Xm,AckClientTransaction:Qm,NonInviteServerTransaction:Zm,InviteServerTransaction:eg,checkTransaction:tg};const Gt=ze(Tr),sg=ut,cf=De,ng=dh,Ho=Tr,rg=new sg("RequestSender"),Fo={onRequestTimeout:()=>{},onTransportError:()=>{},onReceiveResponse:()=>{},onAuthenticated:()=>{}};var vr=class{constructor(t,n,a){this._ua=t,this._eventHandlers=a,this._method=n.method,this._request=n,this._auth=null,this._challenged=!1,this._staled=!1;for(const o in Fo)Object.prototype.hasOwnProperty.call(Fo,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=Fo[o]));t.status===t.C.STATUS_USER_CLOSED&&(this._method!==cf.BYE||this._method!==cf.ACK)&&this._eventHandlers.onTransportError()}send(){const t={onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onReceiveResponse:n=>{this._receiveResponse(n)}};switch(this._method){case"INVITE":this.clientTransaction=new Ho.InviteClientTransaction(this._ua,this._ua.transport,this._request,t);break;case"ACK":this.clientTransaction=new Ho.AckClientTransaction(this._ua,this._ua.transport,this._request,t);break;default:this.clientTransaction=new Ho.NonInviteClientTransaction(this._ua,this._ua.transport,this._request,t)}this._ua._configuration.authorization_jwt&&this._request.setHeader("Authorization",this._ua._configuration.authorization_jwt),this.clientTransaction.send()}_receiveResponse(t){let n,a;const o=t.status_code;if((o===401||o===407)&&(this._ua.configuration.password!==null||this._ua.configuration.ha1!==null)){if(t.status_code===401?(n=t.parseHeader("www-authenticate"),a="authorization"):(n=t.parseHeader("proxy-authenticate"),a="proxy-authorization"),!n){rg.debug(`${t.status_code} with wrong or missing challenge, cannot authenticate`),this._eventHandlers.onReceiveResponse(t);return}if(!this._challenged||!this._staled&&n.stale===!0){if(this._auth||(this._auth=new ng({username:this._ua.configuration.authorization_user,password:this._ua.configuration.password,realm:this._ua.configuration.realm,ha1:this._ua.configuration.ha1})),!this._auth.authenticate(this._request,n)){this._eventHandlers.onReceiveResponse(t);return}this._challenged=!0,this._ua.set("realm",this._auth.get("realm")),this._ua.set("ha1",this._auth.get("ha1")),n.stale&&(this._staled=!0),this._request=this._request.clone(),this._request.cseq+=1,this._request.setHeader("cseq",`${this._request.cseq} ${this._method}`),this._request.setHeader(a,this._auth.toString()),this._eventHandlers.onAuthenticated(this._request),this.send()}else this._eventHandlers.onReceiveResponse(t)}else this._eventHandlers.onReceiveResponse(t)}};const sl=ze(vr),ig=ut,jo=Ct(),Tn=De,ff=yt,hf=vr,Hi=new ig("Registrator"),Ql=10;var lg=class{constructor(t,n){this._reg_id=1,this._ua=t,this._transport=n,this._registrar=t.configuration.registrar_server,this._expires=t.configuration.register_expires,this._call_id=jo.createRandomToken(22),this._cseq=0,this._to_uri=t.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString(),this._contact+=";+sip.ice",this._extraHeaders=[],this._extraContactParams="",this._sipInstance=`"<urn:uuid:${this._ua.configuration.instance_id}>"`,this._contact+=`;reg-id=${this._reg_id}`,this._contact+=`;+sip.instance=${this._sipInstance}`}get registered(){return this._registered}setExtraHeaders(t){Array.isArray(t)||(t=[]),this._extraHeaders=t.slice()}setExtraContactParams(t){t instanceof Object||(t={}),this._extraContactParams="";for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)){const a=t[n];this._extraContactParams+=`;${n}`,a&&(this._extraContactParams+=`=${a}`)}}register(){if(this._registering){Hi.debug("Register request in progress...");return}const t=this._extraHeaders.slice();t.push(`Contact: ${this._contact};expires=${this._expires}${this._extraContactParams}`),t.push(`Expires: ${this._expires}`);const n=new ff.OutgoingRequest(Tn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),a=new hf(this._ua,n,{onRequestTimeout:()=>{this._registrationFailure(null,Tn.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,Tn.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:o=>{if(o.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):{if(this._registering=!1,!o.hasHeader("Contact")){Hi.debug("no Contact header in response to REGISTER, response ignored");break}const s=o.headers.Contact.reduce((_,g)=>_.concat(g.parsed),[]);let r=s.find(_=>this._sipInstance===_.getParam("+sip.instance")&&this._reg_id===parseInt(_.getParam("reg-id")));if(r||(r=s.find(_=>_.uri.user===this._ua.contact.uri.user)),!r){Hi.debug("no Contact header pointing to us, response ignored");break}let d=r.getParam("expires");!d&&o.hasHeader("expires")&&(d=o.getHeader("expires")),d||(d=this._expires),d=Number(d),d<Ql&&(d=Ql);const h=d>64?d*1e3/2+Math.floor((d/2-32)*1e3*Math.random()):d*1e3-5e3;this._registrationTimer=setTimeout(()=>{this._registrationTimer=null,this._ua.listeners("registrationExpiring").length===0?this.register():this._ua.emit("registrationExpiring")},h),r.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),this._registered||(this._registered=!0,this._ua.registered({response:o}));break}case/^423$/.test(o.status_code):{o.hasHeader("min-expires")?(this._expires=Number(o.getHeader("min-expires")),this._expires<Ql&&(this._expires=Ql),this.register()):(Hi.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(o,Tn.causes.SIP_FAILURE_CODE));break}default:{const s=jo.sipErrorCause(o.status_code);this._registrationFailure(o,s)}}}});this._registering=!0,a.send()}unregister(t={}){if(!this._registered){Hi.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const n=this._extraHeaders.slice();t.all?n.push(`Contact: *${this._extraContactParams}`):n.push(`Contact: ${this._contact};expires=0${this._extraContactParams}`),n.push("Expires: 0");const a=new ff.OutgoingRequest(Tn.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new hf(this._ua,a,{onRequestTimeout:()=>{this._unregistered(null,Tn.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,Tn.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:s=>{switch(!0){case/^1[0-9]{2}$/.test(s.status_code):break;case/^2[0-9]{2}$/.test(s.status_code):this._unregistered(s);break;default:{const r=jo.sipErrorCause(s.status_code);this._unregistered(s,r)}}}}).send()}close(){this._registered&&this.unregister()}onTransportClosed(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}_registrationFailure(t,n){this._registering=!1,this._ua.registrationFailed({response:t||null,cause:n}),this._registered&&(this._registered=!1,this._ua.unregistered({response:t||null,cause:n}))}_unregistered(t,n){this._registering=!1,this._registered=!1,this._ua.unregistered({response:t||null,cause:n||null})}};class ag extends Error{constructor(t,n){super(),this.code=1,this.name="CONFIGURATION_ERROR",this.parameter=t,this.value=n,this.message=this.value?`Invalid value ${JSON.stringify(this.value)} for parameter "${this.parameter}"`:`Missing parameter: ${this.parameter}`}}class og extends Error{constructor(t){super(),this.code=2,this.name="INVALID_STATE_ERROR",this.status=t,this.message=`Invalid status: ${t}`}}class ug extends Error{constructor(t){super(),this.code=3,this.name="NOT_SUPPORTED_ERROR",this.message=t}}class cg extends Error{constructor(t){super(),this.code=4,this.name="NOT_READY_ERROR",this.message=t}}var Cs={ConfigurationError:ag,InvalidStateError:og,NotSupportedError:ug,NotReadyError:cg};const qs=ze(Cs),qo=De,Zl=Tr,fg=vr,Vo={onRequestTimeout:()=>{},onTransportError:()=>{},onSuccessResponse:()=>{},onErrorResponse:()=>{},onAuthenticated:()=>{},onDialogError:()=>{}};var _h=class{constructor(t,n,a){this._dialog=t,this._ua=t._ua,this._request=n,this._eventHandlers=a,this._reattempt=!1,this._reattemptTimer=null;for(const o in Vo)Object.prototype.hasOwnProperty.call(Vo,o)&&(this._eventHandlers[o]||(this._eventHandlers[o]=Vo[o]))}get request(){return this._request}send(){const t=new fg(this._ua,this._request,{onRequestTimeout:()=>{this._eventHandlers.onRequestTimeout()},onTransportError:()=>{this._eventHandlers.onTransportError()},onAuthenticated:n=>{this._eventHandlers.onAuthenticated(n)},onReceiveResponse:n=>{this._receiveResponse(n)}});if(t.send(),(this._request.method===qo.INVITE||this._request.method===qo.UPDATE&&this._request.body)&&t.clientTransaction.state!==Zl.C.STATUS_TERMINATED){this._dialog.uac_pending_reply=!0;const n=()=>{(t.clientTransaction.state===Zl.C.STATUS_ACCEPTED||t.clientTransaction.state===Zl.C.STATUS_COMPLETED||t.clientTransaction.state===Zl.C.STATUS_TERMINATED)&&(t.clientTransaction.removeListener("stateChanged",n),this._dialog.uac_pending_reply=!1)};t.clientTransaction.on("stateChanged",n)}}_receiveResponse(t){t.status_code===408||t.status_code===481?this._eventHandlers.onDialogError(t):t.method===qo.INVITE&&t.status_code===491?this._reattempt?t.status_code>=200&&t.status_code<300?this._eventHandlers.onSuccessResponse(t):t.status_code>=300&&this._eventHandlers.onErrorResponse(t):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(()=>{this._dialog.isTerminated()||(this._reattempt=!0,this.send())},1e3)):t.status_code>=200&&t.status_code<300?this._eventHandlers.onSuccessResponse(t):t.status_code>=300&&this._eventHandlers.onErrorResponse(t)}};const hg=ze(_h),dg=ut,df=yt,$s=De,Fi=Tr,_g=_h,Bo=Ct(),Go=new dg("Dialog"),Hs={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};var ph=class{static get C(){return Hs}constructor(t,n,a,o=Hs.STATUS_CONFIRMED){if(this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!n.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};n instanceof df.IncomingResponse&&(o=n.status_code<200?Hs.STATUS_EARLY:Hs.STATUS_CONFIRMED);const s=n.parseHeader("contact");a==="UAS"?(this._id={call_id:n.call_id,local_tag:n.to_tag,remote_tag:n.from_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri,this._remote_target=s.uri,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):a==="UAC"&&(this._id={call_id:n.call_id,local_tag:n.from_tag,remote_tag:n.to_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=s.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),Go.debug(`new ${a} dialog created with status ${this._state===Hs.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(t){this._local_seqnum=t}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(t){this._uac_pending_reply=t}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===Hs.STATUS_TERMINATED}update(t,n){this._state=Hs.STATUS_CONFIRMED,Go.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),n==="UAC"&&(this._route_set=t.getHeaders("record-route").reverse())}terminate(){Go.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Hs.STATUS_TERMINATED}sendRequest(t,n={}){const a=Bo.cloneArray(n.extraHeaders),o=Bo.cloneObject(n.eventHandlers),s=n.body||null,r=this._createRequest(t,a,s);return o.onAuthenticated=()=>{this._local_seqnum+=1},new _g(this,r,o).send(),r}receiveRequest(t){this._checkInDialogRequest(t)&&(t.method===$s.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:t.method===$s.INVITE&&(this._ack_seqnum=t.cseq),this._owner.receiveRequest(t))}_createRequest(t,n,a){n=Bo.cloneArray(n),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const o=t===$s.CANCEL||t===$s.ACK?this._local_seqnum:this._local_seqnum+=1;return new df.OutgoingRequest(t,this._remote_target,this._ua,{cseq:o,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},n,a)}_checkInDialogRequest(t){if(!this._remote_seqnum)this._remote_seqnum=t.cseq;else if(t.cseq<this._remote_seqnum)if(t.method===$s.ACK){if(this._ack_seqnum===null||t.cseq!==this._ack_seqnum)return!1}else return t.reply(500),!1;else t.cseq>this._remote_seqnum&&(this._remote_seqnum=t.cseq);if(t.method===$s.INVITE||t.method===$s.UPDATE&&t.body){if(this._uac_pending_reply===!0)t.reply(491);else if(this._uas_pending_reply===!0){const n=(Math.random()*10|0)+1;return t.reply(500,null,[`Retry-After:${n}`]),!1}else{this._uas_pending_reply=!0;const n=()=>{(t.server_transaction.state===Fi.C.STATUS_ACCEPTED||t.server_transaction.state===Fi.C.STATUS_COMPLETED||t.server_transaction.state===Fi.C.STATUS_TERMINATED)&&(t.server_transaction.removeListener("stateChanged",n),this._uas_pending_reply=!1)};t.server_transaction.on("stateChanged",n)}t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===Fi.C.STATUS_ACCEPTED&&(this._remote_target=t.parseHeader("contact").uri)})}else t.method===$s.NOTIFY&&t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===Fi.C.STATUS_COMPLETED&&(this._remote_target=t.parseHeader("contact").uri)});return!0}};const ea=ze(ph);var ju={exports:{}};const pg=ft.EventEmitter,mg=ut,gg=De,Tg=Cs,_f=Ct(),vg=new mg("RTCSession:DTMF"),mh={MIN_DURATION:70,MAX_DURATION:6e3,DEFAULT_DURATION:100,MIN_INTER_TONE_GAP:50,DEFAULT_INTER_TONE_GAP:500};ju.exports=class extends pg{constructor(t){super(),this._session=t,this._direction=null,this._tone=null,this._duration=null,this._request=null}get tone(){return this._tone}get duration(){return this._duration}send(t,n={}){if(t===void 0)throw new TypeError("Not enough arguments");if(this._direction="outgoing",this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new Tg.InvalidStateError(this._session.status);const a=_f.cloneArray(n.extraHeaders);if(this.eventHandlers=_f.cloneObject(n.eventHandlers),typeof t=="string")t=t.toUpperCase();else if(typeof t=="number")t=t.toString();else throw new TypeError(`Invalid tone: ${t}`);if(t.match(/^[0-9A-DR#*]$/))this._tone=t;else throw new TypeError(`Invalid tone: ${t}`);this._duration=n.duration,a.push("Content-Type: application/dtmf-relay");let o=`Signal=${this._tone}\r
|
113
113
|
`;o+=`Duration=${this._duration}`,this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(gg.INFO,{extraHeaders:a,eventHandlers:{onSuccessResponse:s=>{this.emit("succeeded",{originator:"remote",response:s})},onErrorResponse:s=>{this.eventHandlers.onFailed&&this.eventHandlers.onFailed(),this.emit("failed",{originator:"remote",response:s})},onRequestTimeout:()=>{this._session.onRequestTimeout()},onTransportError:()=>{this._session.onTransportError()},onDialogError:()=>{this._session.onDialogError()}},body:o})}init_incoming(t){const n=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,a=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=t,t.reply(200),t.body){const o=t.body.split(`
|
114
|
-
`);o.length>=1&&n.test(o[0])&&(this._tone=o[0].replace(n,"$2")),o.length>=2&&a.test(o[1])&&(this._duration=parseInt(o[1].replace(a,"$2"),10))}this._duration||(this._duration=mh.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:t}):vg.debug("invalid INFO DTMF received, discarded")}};ju.exports.C=mh;var gh=ju.exports;const Eg=ze(gh),Sg=ft.EventEmitter,yg=De,
|
115
|
-
`,1)[0],"Status_Line");if(n===-1){vn.debug(`receiveNotify() | error parsing NOTIFY body: "${t.body}"`);return}switch(!0){case/^100$/.test(n.status_code):this.emit("trying",{request:t,status_line:n});break;case/^1[0-9]{2}$/.test(n.status_code):this.emit("progress",{request:t,status_line:n});break;case/^2[0-9]{2}$/.test(n.status_code):this.emit("accepted",{request:t,status_line:n});break;default:this.emit("failed",{request:t,status_line:n});break}}_requestSucceeded(t){vn.debug("REFER succeeded"),vn.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:t})}_requestFailed(t,n){vn.debug("REFER failed"),vn.debug('emit "requestFailed"'),this.emit("requestFailed",{response:t||null,cause:n})}};const Ng=ze(Eh),Ug=ft.EventEmitter,gf=xt,Pg=ut,fe=De,En=As,Tf=Tr,Be=At(),qi=Fu,xg=yt,ta=ph,kg=vr,Mt=gh,vf=Th,Mg=vh,Lg=Eh,Ef=ys(),Y=new Pg("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},sa=["audio","video"];var Sh=class Au extends Ug{static get C(){return Z}constructor(t){Y.debug("new"),super(),this._id=null,this._ua=t,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(t){this._data=t}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(t,n={},a){Y.debug("connect()");const o=t,s=Be.cloneObject(n.eventHandlers),r=Be.cloneArray(n.extraHeaders),d=Be.cloneObject(n.mediaConstraints,{audio:!0,video:!0}),h=n.mediaStream||null,_=Be.cloneObject(n.pcConfig,{iceServers:[]}),g=n.rtcConstraints||null,T=n.rtcOfferConstraints||null;if(this._rtcOfferConstraints=T,this._rtcAnswerConstraints=n.rtcAnswerConstraints||null,this._data=n.data||this._data,t===void 0)throw new TypeError("Not enough arguments");if(this._status!==Z.STATUS_NULL)throw new En.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new En.NotSupportedError("WebRTC not supported");if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${o}`);this._sessionTimers.enabled&&Be.isDecimal(n.sessionTimersExpires)&&(n.sessionTimersExpires>=fe.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=n.sessionTimersExpires:this._sessionTimers.defaultExpires=fe.SESSION_EXPIRES);for(const A in s)Object.prototype.hasOwnProperty.call(s,A)&&this.on(A,s[A]);this._from_tag=Be.newTag();const E=n.anonymous||!1,y={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:E,outbound:!0}),E?(y.from_display_name="Anonymous",y.from_uri=new Ef("sip","anonymous","anonymous.invalid"),r.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),r.push("Privacy: id")):n.fromUserName&&(y.from_uri=new Ef("sip",n.fromUserName,this._ua.configuration.uri.host),r.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),n.fromDisplayName&&(y.from_display_name=n.fromDisplayName),r.push(`Contact: ${this._contact}`),r.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&r.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new xg.InitialOutgoingInviteRequest(t,this._ua,y,r),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(_,g),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,a&&a(this),this._newRTCSession("local",this._request),this._sendInitialRequest(d,T,h)}init_incoming(t,n){Y.debug("init_incoming()");let a;const o=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;if(t.body&&o!=="application/sdp"){t.reply(415);return}if(this._status=Z.STATUS_INVITE_RECEIVED,this._from_tag=t.from_tag,this._id=t.call_id+this._from_tag,this._request=t,this._contact=this._ua.contact.toString(),t.hasHeader("expires")&&(a=t.getHeader("expires")*1e3),t.to_tag=Be.newTag(),!this._createDialog(t,"UAS",!0)){t.reply(500,"Missing Contact header field");return}t.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Z.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{t.reply(408),this._failed("local",null,fe.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),a&&(this._timers.expiresTimer=setTimeout(()=>{this._status===Z.STATUS_WAITING_FOR_ANSWER&&(t.reply(487),this._failed("system",null,fe.causes.EXPIRES))},a)),this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from,n&&n(this),this._newRTCSession("remote",t),this._status!==Z.STATUS_TERMINATED&&(t.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(t={}){Y.debug("answer()");const n=this._request,a=Be.cloneArray(t.extraHeaders),o=Be.cloneObject(t.mediaConstraints),s=t.mediaStream||null,r=Be.cloneObject(t.pcConfig,{iceServers:[]}),d=t.rtcConstraints||null,h=t.rtcAnswerConstraints||null,_=Be.cloneObject(t.rtcOfferConstraints);let g,T=!1,E=!1,y=!1,A=!1;if(this._rtcAnswerConstraints=h,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,this._direction!=="incoming")throw new En.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==Z.STATUS_WAITING_FOR_ANSWER)throw new En.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Be.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=fe.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=fe.SESSION_EXPIRES),this._status=Z.STATUS_ANSWERED,!this._createDialog(n,"UAS")){n.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),a.unshift(`Contact: ${this._contact}`);const C=n.parseSDP();Array.isArray(C.media)||(C.media=[C.media]);for(const I of C.media)I.type==="audio"&&(T=!0,(!I.direction||I.direction==="sendrecv")&&(y=!0)),I.type==="video"&&(E=!0,(!I.direction||I.direction==="sendrecv")&&(A=!0));if(s&&o.audio===!1){g=s.getAudioTracks();for(const I of g)s.removeTrack(I)}if(s&&o.video===!1){g=s.getVideoTracks();for(const I of g)s.removeTrack(I)}!s&&o.audio===void 0&&(o.audio=y),!s&&o.video===void 0&&(o.video=A),!s&&!T&&!_.offerToReceiveAudio&&(o.audio=!1),!s&&!E&&!_.offerToReceiveVideo&&(o.video=!1),this._createRTCConnection(r,d),Promise.resolve().then(()=>{if(s)return s;if(o.audio||o.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(o).catch(I=>{throw this._status===Z.STATUS_TERMINATED?new Error("terminated"):(n.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:n.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($=>{throw n.reply(488),this._failed("system",null,fe.causes.WEBRTC_ERROR),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',$),this.emit("peerconnection:setremotedescriptionfailed",$),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(n),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",h).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(I=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,a),n.reply(200,null,a,I,()=>{this._status=Z.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,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(t={}){console.log("IN TERMINATE"),Y.debug("terminate()");const n=t.cause||fe.causes.BYE,a=Be.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,d=t.reason_phrase;if(this._status===Z.STATUS_TERMINATED)throw console.log("IN TERMINATE EXC 1"),new En.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"),r&&(r<200||r>=700))throw console.log("IN TERMINATE EXC 2"),new TypeError(`Invalid status_code: ${r}`);r&&(d=d||fe.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${d}"`),this._status===Z.STATUS_NULL||this._status===Z.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===Z.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=Z.STATUS_CANCELED,this._failed("local",null,fe.causes.CANCELED);break;case Z.STATUS_WAITING_FOR_ANSWER:case Z.STATUS_ANSWERED:if(console.log("IN TERMINATE STATUS ANSWERED"),Y.debug("rejecting session"),r=r||480,r<300||r>=700)throw console.log("IN TERMINATE EXC 3"),new TypeError(`Invalid status_code: ${r}`);console.log("IN TERMINATE EMIT FAILED"),this._request.reply(r,d,a,o),this._failed("local",null,fe.causes.REJECTED);break;case Z.STATUS_WAITING_FOR_ACK:case Z.STATUS_CONFIRMED:if(console.log("IN TERMINATE CONFIRMED"),Y.debug("terminating session"),d=t.reason_phrase||fe.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw console.log("IN TERMINATE EXC 4"),new TypeError(`Invalid status_code: ${r}`);if(r&&a.push(`Reason: SIP ;cause=${r}; text="${d}"`),this._status===Z.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Tf.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:_})=>{_===fe.ACK&&(this.sendRequest(fe.BYE,{extraHeaders:a,body:o}),console.log("IN TERMINATE DIALOG TERMINATE"),h.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Tf.C.STATUS_TERMINATED&&(this.sendRequest(fe.BYE,{extraHeaders:a,body:o}),console.log("IN TERMINATE DIALOG TERMINATE 2"),h.terminate())}),console.log("IN TERMINATE EMIT ENDED"),this._ended("local",null,n),this._dialog=h,this._ua.newDialog(h)}else this.sendRequest(fe.BYE,{extraHeaders:a,body:o}),console.log("IN TERMINATE EMIT ENDED 2"),this._ended("local",null,n)}}sendDTMF(t,n={}){Y.debug("sendDTMF() | tones: %s",t);let a=0,o=n.duration||null,s=n.interToneGap||null;const r=n.transportType||fe.DTMF_TRANSPORT.INFO;if(t===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 En.InvalidStateError(this._status);if(r!==fe.DTMF_TRANSPORT.INFO&&r!==fe.DTMF_TRANSPORT.RFC2833)throw new TypeError(`invalid transportType: ${r}`);if(typeof t=="number"&&(t=t.toString()),!t||typeof t!="string"||!t.match(/^[0-9A-DR#*,]+$/i))throw new TypeError(`Invalid tones: ${t}`);if(o&&!Be.isDecimal(o))throw new TypeError(`Invalid tone duration: ${o}`);if(o?o<Mt.C.MIN_DURATION?(Y.debug(`"duration" value is lower than the minimum allowed, setting it to ${Mt.C.MIN_DURATION} milliseconds`),o=Mt.C.MIN_DURATION):o>Mt.C.MAX_DURATION?(Y.debug(`"duration" value is greater than the maximum allowed, setting it to ${Mt.C.MAX_DURATION} milliseconds`),o=Mt.C.MAX_DURATION):o=Math.abs(o):o=Mt.C.DEFAULT_DURATION,n.duration=o,s&&!Be.isDecimal(s))throw new TypeError(`Invalid interToneGap: ${s}`);if(s?s<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`),s=Mt.C.MIN_INTER_TONE_GAP):s=Math.abs(s):s=Mt.C.DEFAULT_INTER_TONE_GAP,r===fe.DTMF_TRANSPORT.RFC2833){const h=this._getDTMFRTPSender();h&&(t=h.toneBuffer+t,h.insertDTMF(t,o,s));return}if(this._tones){this._tones+=t;return}this._tones=t,d.call(this);function d(){let h;if(this._status===Z.STATUS_TERMINATED||!this._tones||a>=this._tones.length){this._tones=null;return}const _=this._tones[a];if(a+=1,_===",")h=2e3;else{const g=new Mt(this);n.eventHandlers={onFailed:()=>{this._tones=null}},g.send(_,n),h=o+s}setTimeout(d.bind(this),h)}}sendInfo(t,n,a={}){if(Y.debug("sendInfo()"),this._status!==Z.STATUS_CONFIRMED&&this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_1XX_RECEIVED)throw new En.InvalidStateError(this._status);new vf(this).send(t,n,a)}mute(t={audio:!0,video:!1}){Y.debug("mute()");let n=!1,a=!1;this._audioMuted===!1&&t.audio&&(n=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&t.video&&(a=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(n===!0||a===!0)&&this._onmute({audio:n,video:a})}unmute(t={audio:!0,video:!0}){Y.debug("unmute()");let n=!1,a=!1;this._audioMuted===!0&&t.audio&&(n=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&t.video&&(a=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(n===!0||a===!0)&&this._onunmute({audio:n,video:a})}hold(t={},n){if(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 a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:fe.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}unhold(t={},n){if(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 a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:fe.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}renegotiate(t={},n){Y.debug("renegotiate()");const a=t.rtcOfferConstraints||null;if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const o={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:fe.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}),!0}refer(t,n){Y.debug("refer()");const a=t;if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${a}`);const o=new Lg(this);o.sendRefer(t,n);const s=o.id;return this._referSubscribers[s]=o,o.on("requestFailed",()=>{delete this._referSubscribers[s]}),o.on("accepted",()=>{delete this._referSubscribers[s]}),o.on("failed",()=>{delete this._referSubscribers[s]}),o}sendRequest(t,n){return Y.debug("sendRequest()"),this._dialog.sendRequest(t,n)}receiveRequest(t){if(Y.debug("receiveRequest()"),t.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",t,fe.causes.CANCELED));else switch(t.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(!t.body){this.terminate({cause:fe.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:t.body};Y.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>{this._is_confirmed||this._confirmed("remote",t)}).catch(o=>{this.terminate({cause:fe.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})}else this._is_confirmed||this._confirmed("remote",t);break;case fe.BYE:this._status===Z.STATUS_CONFIRMED||this._status===Z.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,fe.causes.BYE)):this._status===Z.STATUS_INVITE_RECEIVED||this._status===Z.STATUS_WAITING_FOR_ANSWER?(t.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",t,fe.causes.BYE)):t.reply(403,"Wrong Status");break;case fe.INVITE:this._status===Z.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.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 n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;n&&n.match(/^application\/dtmf-relay/i)?new Mt(this).init_incoming(t):n!==void 0?new vf(this).init_incoming(t):t.reply(415)}else t.reply(403,"Wrong Status");break;case fe.UPDATE:this._status===Z.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case fe.REFER:this._status===Z.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case fe.NOTIFY:this._status===Z.STATUS_CONFIRMED?this._receiveNotify(t):t.reply(403,"Wrong Status");break;default:t.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(t){Y.debug("newDTMF()"),this.emit("newDTMF",t)}newInfo(t){Y.debug("newInfo()"),this.emit("newInfo",t)}_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(t){Y.warn("close() | error closing the RTCPeerConnection: %o",t)}for(const t in this._timers)Object.prototype.hasOwnProperty.call(this._timers,t)&&clearTimeout(this._timers[t]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const t in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(const t in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,t)&&delete this._referSubscribers[t];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(t,n){let a=qi.T1;function o(){this._status===Z.STATUS_WAITING_FOR_ACK&&(t.reply(200,null,[`Contact: ${this._contact}`],n),a<qi.T2&&(a=a*2,a>qi.T2&&(a=qi.T2)),this._timers.invite2xxTimer=setTimeout(o.bind(this),a))}this._timers.invite2xxTimer=setTimeout(o.bind(this),a)}_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))},qi.TIMER_H)}_createRTCConnection(t,n){this._connection=new RTCPeerConnection(t,n),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(t,n){if(Y.debug("createLocalDescription()"),t!=="offer"&&t!=="answer")throw new Error(`createLocalDescription() | invalid type "${t}"`);const a=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>t==="offer"?a.createOffer(n).catch(o=>(Y.warn('emit "peerconnection:createofferfailed" [error:%o]',o),this.emit("peerconnection:createofferfailed",o),Promise.reject(o))):a.createAnswer(n).catch(o=>(Y.warn('emit "peerconnection:createanswerfailed" [error:%o]',o),this.emit("peerconnection:createanswerfailed",o),Promise.reject(o)))).then(o=>a.setLocalDescription(o).catch(s=>(this._rtcReady=!0,Y.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',s),this.emit("peerconnection:setlocaldescriptionfailed",s),Promise.reject(s)))).then(()=>{const o=n&&n.iceRestart;if(a.iceGatheringState==="complete"&&!o||a.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const s={originator:"local",type:t,sdp:a.localDescription.sdp};return Y.debug('emit "sdp"'),this.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(s=>{let r=!1,d,h;this._iceReady=!1;const _=()=>{a.removeEventListener("icecandidate",d),a.removeEventListener("icegatheringstatechange",h),r=!0,this._rtcReady=!0,this._iceReady=!0;const g={originator:"local",type:t,sdp:a.localDescription.sdp};Y.debug('emit "sdp"'),this.emit("sdp",g),s(g.sdp)};a.addEventListener("icecandidate",d=g=>{const T=g.candidate;T?this.emit("icecandidate",{candidate:T,ready:_}):r||_()}),a.addEventListener("icegatheringstatechange",h=()=>{a.iceGatheringState==="complete"&&!r&&_()})})})}_createDialog(t,n,a){const o=n==="UAS"?t.to_tag:t.from_tag,s=n==="UAS"?t.from_tag:t.to_tag,r=t.call_id+o+s;let d=this._earlyDialogs[r];if(a)return d?!0:(d=new ta(this,t,n,ta.C.STATUS_EARLY),d.error?(Y.debug(d.error),this._failed("remote",t,fe.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=d,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,d)return d.update(t,n),this._dialog=d,delete this._earlyDialogs[r],!0;const h=new ta(this,t,n);return h.error?(Y.debug(h.error),this._failed("remote",t,fe.causes.INTERNAL_ERROR),!1):(this._dialog=h,!0)}}_receiveReinvite(t){Y.debug("receiveReinvite()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=Be.cloneArray(d.extraHeaders);if(this._status!==Z.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("reinvite",a),o)return;if(this._late_sdp=!1,!t.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(d=>{r.call(this,d)}).catch(()=>{t.reply(500)});return}if(n!=="application/sdp"){Y.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==Z.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{Y.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),this._late_sdp&&(d=this._mangleOffer(d)),t.reply(200,null,h,d,()=>{this._status=Z.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(t,d),this._setACKTimer()}),typeof a.callback=="function"&&a.callback()}}_receiveUpdate(t){Y.debug("receiveUpdate()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=Be.cloneArray(d.extraHeaders);if(this._status!==Z.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("update",a),o)return;if(!t.body){r.call(this,null);return}if(n!=="application/sdp"){Y.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==Z.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{Y.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),t.reply(200,null,h,d),typeof a.callback=="function"&&a.callback()}}_processInDialogSdpOffer(t){Y.debug("_processInDialogSdpOffer()");const n=t.parseSDP();let a=!1;for(const r of n.media){if(sa.indexOf(r.type)===-1)continue;const d=r.direction||n.direction||"sendrecv";if(d==="sendonly"||d==="inactive")a=!0;else{a=!1;break}}const o={originator:"remote",type:"offer",sdp:t.body};Y.debug('emit "sdp"'),this.emit("sdp",o);const s=new RTCSessionDescription({type:"offer",sdp:o.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(s).catch(r=>{throw t.reply(488),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',r),this.emit("peerconnection:setremotedescriptionfailed",r),r})}).then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&a===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&a===!0&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(r=>{throw t.reply(500),Y.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',r),r})}).catch(r=>{Y.warn("_processInDialogSdpOffer() failed [error: %o]",r)}),this._connectionPromiseQueue}_receiveRefer(t){if(Y.debug("receiveRefer()"),!t.refer_to){Y.debug("no Refer-To header field present in REFER"),t.reply(400);return}if(t.refer_to.uri.scheme!==fe.SIP){Y.debug("Refer-To header field points to a non-SIP URI scheme"),t.reply(416);return}t.reply(202);const n=new Mg(this,t.cseq);Y.debug('emit "refer"'),this.emit("refer",{request:t,accept:(s,r)=>{a.call(this,s,r)},reject:()=>{o.call(this)}});function a(s,r={}){if(s=typeof s=="function"?s:null,this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;const d=new Au(this._ua);if(d.on("progress",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("accepted",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("_failed",({message:h,cause:_})=>{h?n.notify(h.status_code,h.reason_phrase):n.notify(487,_)}),t.refer_to.uri.hasHeader("replaces")){const h=decodeURIComponent(t.refer_to.uri.getHeader("replaces"));r.extraHeaders=Be.cloneArray(r.extraHeaders),r.extraHeaders.push(`Replaces: ${h}`)}d.connect(t.refer_to.uri.toAor(),r,s)}function o(){n.notify(603)}}_receiveNotify(t){switch(Y.debug("receiveNotify()"),t.event||t.reply(400),t.event.event){case"refer":{let n,a;if(t.event.params&&t.event.params.id)n=t.event.params.id,a=this._referSubscribers[n];else if(Object.keys(this._referSubscribers).length===1)a=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{t.reply(400,"Missing event id parameter");return}if(!a){t.reply(481,"Subscription does not exist");return}a.receiveNotify(t),t.reply(200);break}default:t.reply(489)}}_receiveReplaces(t){Y.debug("receiveReplaces()");function n(o){if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;const s=new Au(this._ua);s.on("confirmed",()=>{this.terminate()}),s.init_incoming(t,o)}function a(){Y.debug("Replaced INVITE rejected by the user"),t.reply(486)}this.emit("replaces",{request:t,accept:o=>{n.call(this,o)},reject:()=>{a.call(this)}})}_sendInitialRequest(t,n,a){const o=new kg(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});Promise.resolve().then(()=>{if(a)return a;if(t.audio||t.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(t).catch(s=>{throw this._status===Z.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,fe.causes.USER_DENIED_MEDIA_ACCESS),Y.warn('emit "getusermediafailed" [error:%o]',s),this.emit("getusermediafailed",s),s)})}).then(s=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=s,s&&s.getTracks().forEach(r=>{this._connection.addTrack(r,s)}),this._connecting(this._request),this._createLocalDescription("offer",n).catch(r=>{throw this._failed("local",null,fe.causes.WEBRTC_ERROR),r})}).then(s=>{if(this._is_canceled||this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._request.body=s,this._status=Z.STATUS_INVITE_SENT,Y.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),o.send()}).catch(s=>{this._status!==Z.STATUS_TERMINATED&&Y.warn(s)})}_getDTMFRTPSender(){const t=this._connection.getSenders().find(n=>n.track&&n.track.kind==="audio");if(!(t&&t.dtmf)){Y.warn("sendDTMF() | no local audio track to send DTMF with");return}return t.dtmf}_receiveInviteResponse(t){if(Y.debug("receiveInviteResponse()"),this._dialog&&t.status_code>=200&&t.status_code<=299)if(this._dialog.id.call_id===t.call_id&&this._dialog.id.local_tag===t.from_tag&&this._dialog.id.remote_tag===t.to_tag){this.sendRequest(fe.ACK);return}else{const n=new ta(this,t,"UAC");if(n.error!==void 0){Y.debug(n.error);return}this.sendRequest(fe.ACK),this.sendRequest(fe.BYE);return}if(this._is_canceled){t.status_code>=100&&t.status_code<200?this._request.cancel(this._cancel_reason):t.status_code>=200&&t.status_code<299&&this._acceptAndTerminate(t);return}if(!(this._status!==Z.STATUS_INVITE_SENT&&this._status!==Z.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(t.status_code):this._status=Z.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(t.status_code):{if(!t.to_tag){Y.debug("1xx response received without to tag");break}if(t.hasHeader("contact")&&!this._createDialog(t,"UAC",!0))break;if(this._status=Z.STATUS_1XX_RECEIVED,!t.body){this._progress("remote",t);break}const n={originator:"remote",type:"answer",sdp:t.body};Y.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>this._progress("remote",t)).catch(o=>{Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)});break}case/^2[0-9]{2}$/.test(t.status_code):{if(this._status=Z.STATUS_CONFIRMED,!t.body){this._acceptAndTerminate(t,400,fe.causes.MISSING_SDP),this._failed("remote",t,fe.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(t,"UAC"))break;const n={originator:"remote",type:"answer",sdp:t.body};Y.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._connection.signalingState==="stable")return this._connection.createOffer(this._rtcOfferConstraints).then(o=>this._connection.setLocalDescription(o)).catch(o=>{this._acceptAndTerminate(t,500,o.toString()),this._failed("local",t,fe.causes.WEBRTC_ERROR)})}).then(()=>{this._connection.setRemoteDescription(a).then(()=>{this._handleSessionTimersInIncomingResponse(t),this._accepted("remote",t),this.sendRequest(fe.ACK),this._confirmed("local",null)}).catch(o=>{this._acceptAndTerminate(t,488,"Not Acceptable Here"),this._failed("remote",t,fe.causes.BAD_MEDIA_DESCRIPTION),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})});break}default:{const n=Be.sipErrorCause(t.status_code);this._failed("remote",t,n)}}}_sendReinvite(t={}){Y.debug("sendReinvite()");const n=Be.cloneArray(t.extraHeaders),a=Be.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null;let s=!1;n.push(`Contact: ${this._contact}`),n.push("Content-Type: application/sdp"),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(h=>{h=this._mangleOffer(h);const _={originator:"local",type:"offer",sdp:h};Y.debug('emit "sdp"'),this.emit("sdp",_),this.sendRequest(fe.INVITE,{extraHeaders:n,body:h,eventHandlers:{onSuccessResponse:g=>{r.call(this,g),s=!0},onErrorResponse:g=>{d.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{d()});function r(h){if(this._status===Z.STATUS_TERMINATED||(this.sendRequest(fe.ACK),s))return;if(this._handleSessionTimersInIncomingResponse(h),h.body){if(!h.hasHeader("Content-Type")||h.getHeader("Content-Type").toLowerCase()!=="application/sdp"){d.call(this);return}}else{d.call(this);return}const _={originator:"remote",type:"answer",sdp:h.body};Y.debug('emit "sdp"'),this.emit("sdp",_);const g=new RTCSessionDescription({type:"answer",sdp:_.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(g)).then(()=>{a.succeeded&&a.succeeded(h)}).catch(T=>{d.call(this),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function d(h){a.failed&&a.failed(h)}}_sendUpdate(t={}){Y.debug("sendUpdate()");const n=Be.cloneArray(t.extraHeaders),a=Be.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null,s=t.sdpOffer||!1;let r=!1;n.push(`Contact: ${this._contact}`),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),s?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(_=>{_=this._mangleOffer(_);const g={originator:"local",type:"offer",sdp:_};Y.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(fe.UPDATE,{extraHeaders:n,body:_,eventHandlers:{onSuccessResponse:T=>{d.call(this,T),r=!0},onErrorResponse:T=>{h.call(this,T)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{h.call(this)})):this.sendRequest(fe.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:_=>{d.call(this,_)},onErrorResponse:_=>{h.call(this,_)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function d(_){if(this._status!==Z.STATUS_TERMINATED&&!r)if(this._handleSessionTimersInIncomingResponse(_),s){if(_.body){if(!_.hasHeader("Content-Type")||_.getHeader("Content-Type").toLowerCase()!=="application/sdp"){h.call(this);return}}else{h.call(this);return}const g={originator:"remote",type:"answer",sdp:_.body};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(()=>{a.succeeded&&a.succeeded(_)}).catch(E=>{h.call(this),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),this.emit("peerconnection:setremotedescriptionfailed",E)})}else a.succeeded&&a.succeeded(_)}function h(_){a.failed&&a.failed(_)}}_acceptAndTerminate(t,n,a){Y.debug("acceptAndTerminate()");const o=[];n&&(a=a||fe.REASON_PHRASE[n]||"",o.push(`Reason: SIP ;cause=${n}; text="${a}"`)),(this._dialog||this._createDialog(t,"UAC"))&&(this.sendRequest(fe.ACK),this.sendRequest(fe.BYE,{extraHeaders:o})),this._status=Z.STATUS_TERMINATED}_mangleOffer(t){if(!this._localHold&&!this._remoteHold)return t;if(t=gf.parse(t),this._localHold&&!this._remoteHold){Y.debug("mangleOffer() | me on hold, mangling offer");for(const n of t.media)sa.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="sendonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="sendonly")}else if(this._localHold&&this._remoteHold){Y.debug("mangleOffer() | both on hold, mangling offer");for(const n of t.media)sa.indexOf(n.type)!==-1&&(n.direction="inactive")}else if(this._remoteHold){Y.debug("mangleOffer() | remote on hold, mangling offer");for(const n of t.media)sa.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="recvonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="recvonly")}return gf.write(t)}_setLocalMediaStatus(){let t=!0,n=!0;(this._localHold||this._remoteHold)&&(t=!1,n=!1),this._audioMuted&&(t=!1),this._videoMuted&&(n=!1),this._toggleMuteAudio(!t),this._toggleMuteVideo(!n)}_handleSessionTimersInIncomingRequest(t,n){if(!this._sessionTimers.enabled)return;let a;t.session_expires&&t.session_expires>=fe.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,a=t.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,a="uas"),n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${a}`),this._sessionTimers.refresher=a==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(t){if(!this._sessionTimers.enabled)return;let n;t.session_expires&&t.session_expires>=fe.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,n=t.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uac"),this._sessionTimers.refresher=n==="uac",this._runSessionTimer()}_runSessionTimer(){const t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(()=>{this._status!==Z.STATUS_TERMINATED&&this._isReadyToReOffer()&&(Y.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===fe.UPDATE?this._sendUpdate():this._sendReinvite())},t*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"}))},t*1100)}_toggleMuteAudio(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="audio");for(const a of n)a.track.enabled=!t}_toggleMuteVideo(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="video");for(const a of n)a.track.enabled=!t}_newRTCSession(t,n){Y.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:t,session:this,request:n})}_connecting(t){Y.debug("session connecting"),Y.debug('emit "connecting"'),this.emit("connecting",{request:t})}_progress(t,n){Y.debug("session progress"),Y.debug('emit "progress"'),this.emit("progress",{originator:t,response:n||null})}_accepted(t,n){Y.debug("session accepted"),this._start_time=new Date,Y.debug('emit "accepted"'),this.emit("accepted",{originator:t,response:n||null})}_confirmed(t,n){Y.debug("session confirmed"),this._is_confirmed=!0,Y.debug('emit "confirmed"'),this.emit("confirmed",{originator:t,ack:n||null})}_ended(t,n,a){Y.debug("session ended"),this._end_time=new Date,this._close(),Y.debug('emit "ended"'),this.emit("ended",{originator:t,message:n||null,cause:a})}_failed(t,n,a){Y.debug("session failed"),Y.debug('emit "_failed"'),this.emit("_failed",{originator:t,message:n||null,cause:a}),this._close(),Y.debug('emit "failed"'),this.emit("failed",{originator:t,message:n||null,cause:a})}_onhold(t){Y.debug("session onhold"),this._setLocalMediaStatus(),Y.debug('emit "hold"'),this.emit("hold",{originator:t})}_onunhold(t){Y.debug("session onunhold"),this._setLocalMediaStatus(),Y.debug('emit "unhold"'),this.emit("unhold",{originator:t})}_onmute({audio:t,video:n}){Y.debug("session onmute"),this._setLocalMediaStatus(),Y.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}_onunmute({audio:t,video:n}){Y.debug("session onunmute"),this._setLocalMediaStatus(),Y.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}};const $g=ze(Sh),Hg=ft.EventEmitter,Fg=ut,Ko=De,jg=yt,Vi=At(),qg=vr,Sf=As,Vg=ys(),na=new Fg("Message");var Bg=class extends Hg{constructor(t){super(),this._ua=t,this._request=null,this._closed=!1,this._direction=null,this._local_identity=null,this._remote_identity=null,this._is_replied=!1,this._data={}}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}send(t,n,a={}){const o=t;if(t===void 0||n===void 0)throw new TypeError("Not enough arguments");if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${o}`);const s=Vi.cloneArray(a.extraHeaders),r=Vi.cloneObject(a.eventHandlers),d=a.contentType||"text/plain",h={};a.fromUserName&&(h.from_uri=new Vg("sip",a.fromUserName,this._ua.configuration.uri.host),s.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),a.fromDisplayName&&(h.from_display_name=a.fromDisplayName);for(const g in r)Object.prototype.hasOwnProperty.call(r,g)&&this.on(g,r[g]);s.push(`Content-Type: ${d}`),this._request=new jg.OutgoingRequest(Ko.MESSAGE,t,this._ua,h,s),n&&(this._request.body=n);const _=new qg(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:g=>{this._receiveResponse(g)}});this._newMessage("local",this._request),_.send()}init_incoming(t){this._request=t,this._newMessage("remote",t),this._is_replied||(this._is_replied=!0,t.reply(200)),this._close()}accept(t={}){const n=Vi.cloneArray(t.extraHeaders),a=t.body;if(this._direction!=="incoming")throw new Sf.NotSupportedError('"accept" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");this._is_replied=!0,this._request.reply(200,null,n,a)}reject(t={}){const n=t.status_code||480,a=t.reason_phrase,o=Vi.cloneArray(t.extraHeaders),s=t.body;if(this._direction!=="incoming")throw new Sf.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(n<300||n>=700)throw new TypeError(`Invalid status_code: ${n}`);this._is_replied=!0,this._request.reply(n,a,o,s)}_receiveResponse(t){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):this._succeeded("remote",t);break;default:{const n=Vi.sipErrorCause(t.status_code);this._failed("remote",t,n);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)}_newMessage(t,n){t==="remote"?(this._direction="incoming",this._local_identity=n.to,this._remote_identity=n.from):t==="local"&&(this._direction="outgoing",this._local_identity=n.from,this._remote_identity=n.to),this._ua.newMessage(this,{originator:t,message:this,request:n})}_failed(t,n,a){na.debug("MESSAGE failed"),this._close(),na.debug('emit "failed"'),this.emit("failed",{originator:t,response:n||null,cause:a})}_succeeded(t,n){na.debug("MESSAGE succeeded"),this._close(),na.debug('emit "succeeded"'),this.emit("succeeded",{originator:t,response:n})}};const Gg=ft.EventEmitter,Wg=ut,Yo=De,Kg=yt,Bi=At(),Yg=vr,yf=As,ra=new Wg("Options");var Jg=class extends Gg{constructor(t){super(),this._ua=t,this._request=null,this._closed=!1,this._direction=null,this._local_identity=null,this._remote_identity=null,this._is_replied=!1,this._data={}}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}send(t,n,a={}){const o=t;if(t===void 0)throw new TypeError("A target is required for OPTIONS");if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${o}`);const s=Bi.cloneArray(a.extraHeaders),r=Bi.cloneObject(a.eventHandlers),d=a.contentType||"application/sdp";for(const _ in r)Object.prototype.hasOwnProperty.call(r,_)&&this.on(_,r[_]);s.push(`Content-Type: ${d}`),this._request=new Kg.OutgoingRequest(Yo.OPTIONS,t,this._ua,null,s),n&&(this._request.body=n);const h=new Yg(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:_=>{this._receiveResponse(_)}});this._newOptions("local",this._request),h.send()}init_incoming(t){this._request=t,this._newOptions("remote",t),this._is_replied||(this._is_replied=!0,t.reply(200)),this._close()}accept(t={}){const n=Bi.cloneArray(t.extraHeaders),a=t.body;if(this._direction!=="incoming")throw new yf.NotSupportedError('"accept" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");this._is_replied=!0,this._request.reply(200,null,n,a)}reject(t={}){const n=t.status_code||480,a=t.reason_phrase,o=Bi.cloneArray(t.extraHeaders),s=t.body;if(this._direction!=="incoming")throw new yf.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(n<300||n>=700)throw new TypeError(`Invalid status_code: ${n}`);this._is_replied=!0,this._request.reply(n,a,o,s)}_receiveResponse(t){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):this._succeeded("remote",t);break;default:{const n=Bi.sipErrorCause(t.status_code);this._failed("remote",t,n);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,Yo.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,Yo.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newOptions(t,n){t==="remote"?(this._direction="incoming",this._local_identity=n.to,this._remote_identity=n.from):t==="local"&&(this._direction="outgoing",this._local_identity=n.from,this._remote_identity=n.to),this._ua.newOptions(this,{originator:t,message:this,request:n})}_failed(t,n,a){ra.debug("OPTIONS failed"),this._close(),ra.debug('emit "failed"'),this.emit("failed",{originator:t,response:n||null,cause:a})}_succeeded(t,n){ra.debug("OPTIONS succeeded"),this._close(),ra.debug('emit "succeeded"'),this.emit("succeeded",{originator:t,response:n})}},qu={};const zg=ut,Jo=At(),Xg=Zt(),Gi=new zg("Socket");qu.isSocket=c=>{if(Array.isArray(c))return!1;if(typeof c>"u")return Gi.warn("undefined JsSIP.Socket instance"),!1;try{if(!Jo.isString(c.url))throw Gi.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!Jo.isString(c.via_transport))throw Gi.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(Xg.parse(c.sip_uri,"SIP_URI")===-1)throw Gi.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch{return!1}try{["connect","disconnect","send"].forEach(t=>{if(!Jo.isFunction(c[t]))throw Gi.warn(`missing or invalid JsSIP.Socket method: ${t}`),new Error(`Missing or invalid JsSIP.Socket method: ${t}`)})}catch{return!1}return!0};const Qg=ut,Zg=qu,Af=De,Ut=new Qg("Transport"),Vt={STATUS_CONNECTED:0,STATUS_CONNECTING:1,STATUS_DISCONNECTED:2,SOCKET_STATUS_READY:0,SOCKET_STATUS_ERROR:1,recovery_options:{min_interval:Af.CONNECTION_RECOVERY_MIN_INTERVAL,max_interval:Af.CONNECTION_RECOVERY_MAX_INTERVAL}};var yh=class{constructor(t,n=Vt.recovery_options){Ut.debug("new()"),this.status=Vt.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(a){Ut.warn(`cannot use TextDecoder: ${a}`)}if(typeof t>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(a){if(!Zg.isSocket(a.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(a.weight&&!Number(a.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:a.socket,weight:a.weight||0,status:Vt.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=Vt.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=Vt.STATUS_DISCONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=()=>{},this.socket.ondisconnect=()=>{},this.socket.ondata=()=>{},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}send(t){if(Ut.debug("send()"),!this.isConnected())return Ut.warn("unable to send message, transport is not connected"),!1;const n=t.toString();return Ut.debug(`sending message:
|
114
|
+
`);o.length>=1&&n.test(o[0])&&(this._tone=o[0].replace(n,"$2")),o.length>=2&&a.test(o[1])&&(this._duration=parseInt(o[1].replace(a,"$2"),10))}this._duration||(this._duration=mh.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:t}):vg.debug("invalid INFO DTMF received, discarded")}};ju.exports.C=mh;var gh=ju.exports;const Eg=ze(gh),Sg=ft.EventEmitter,yg=De,Cg=Cs,Ag=Ct();var Th=class extends Sg{constructor(t){super(),this._session=t,this._direction=null,this._contentType=null,this._body=null}get contentType(){return this._contentType}get body(){return this._body}send(t,n,a={}){if(this._direction="outgoing",t===void 0)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new Cg.InvalidStateError(this._session.status);this._contentType=t,this._body=n;const o=Ag.cloneArray(a.extraHeaders);o.push(`Content-Type: ${t}`),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(yg.INFO,{extraHeaders:o,eventHandlers:{onSuccessResponse:s=>{this.emit("succeeded",{originator:"remote",response:s})},onErrorResponse:s=>{this.emit("failed",{originator:"remote",response:s})},onTransportError:()=>{this._session.onTransportError()},onRequestTimeout:()=>{this._session.onRequestTimeout()},onDialogError:()=>{this._session.onDialogError()}},body:n})}init_incoming(t){this._direction="incoming",this.request=t,t.reply(200),this._contentType=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,this._body=t.body,this._session.newInfo({originator:"remote",info:this,request:t})}};const yu=ze(Th),Rg=ut,pf=De,Ig=new Rg("RTCSession:ReferNotifier"),Wo={event_type:"refer",body_type:"message/sipfrag;version=2.0",expires:300};var vh=class{constructor(t,n,a){this._session=t,this._id=n,this._expires=a||Wo.expires,this._active=!0,this.notify(100)}notify(t,n){if(Ig.debug("notify()"),this._active===!1)return;n=n||pf.REASON_PHRASE[t]||"";let a;t>=200?a="terminated;reason=noresource":a=`active;expires=${this._expires}`,this._session.sendRequest(pf.NOTIFY,{extraHeaders:[`Event: ${Wo.event_type};id=${this._id}`,`Subscription-State: ${a}`,`Content-Type: ${Wo.body_type}`],body:`SIP/2.0 ${t} ${n}`,eventHandlers:{onErrorResponse(){this._active=!1}}})}};const bg=ze(vh),wg=ft.EventEmitter,Og=ut,ji=De,Dg=Zt(),mf=Ct(),vn=new Og("RTCSession:ReferSubscriber");var Eh=class extends wg{constructor(t){super(),this._id=null,this._session=t}get id(){return this._id}sendRefer(t,n={}){vn.debug("sendRefer()");const a=mf.cloneArray(n.extraHeaders),o=mf.cloneObject(n.eventHandlers);for(const h in o)Object.prototype.hasOwnProperty.call(o,h)&&this.on(h,o[h]);let s=null;n.replaces&&(s=n.replaces._request.call_id,s+=`;to-tag=${n.replaces._to_tag}`,s+=`;from-tag=${n.replaces._from_tag}`,s=encodeURIComponent(s));const r=`Refer-To: <${t}${s?`?Replaces=${s}`:""}>`;if(a.push(r),!a.some(h=>h.toLowerCase().startsWith("referred-by:"))){const h=`Referred-By: <${this._session._ua._configuration.uri._scheme}:${this._session._ua._configuration.uri._user}@${this._session._ua._configuration.uri._host}>`;a.push(h)}a.push(`Contact: ${this._session.contact}`);const d=this._session.sendRequest(ji.REFER,{extraHeaders:a,eventHandlers:{onSuccessResponse:h=>{this._requestSucceeded(h)},onErrorResponse:h=>{this._requestFailed(h,ji.causes.REJECTED)},onTransportError:()=>{this._requestFailed(null,ji.causes.CONNECTION_ERROR)},onRequestTimeout:()=>{this._requestFailed(null,ji.causes.REQUEST_TIMEOUT)},onDialogError:()=>{this._requestFailed(null,ji.causes.DIALOG_ERROR)}}});this._id=d.cseq}receiveNotify(t){if(vn.debug("receiveNotify()"),!t.body)return;const n=Dg.parse(t.body.trim().split(`\r
|
115
|
+
`,1)[0],"Status_Line");if(n===-1){vn.debug(`receiveNotify() | error parsing NOTIFY body: "${t.body}"`);return}switch(!0){case/^100$/.test(n.status_code):this.emit("trying",{request:t,status_line:n});break;case/^1[0-9]{2}$/.test(n.status_code):this.emit("progress",{request:t,status_line:n});break;case/^2[0-9]{2}$/.test(n.status_code):this.emit("accepted",{request:t,status_line:n});break;default:this.emit("failed",{request:t,status_line:n});break}}_requestSucceeded(t){vn.debug("REFER succeeded"),vn.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:t})}_requestFailed(t,n){vn.debug("REFER failed"),vn.debug('emit "requestFailed"'),this.emit("requestFailed",{response:t||null,cause:n})}};const Ng=ze(Eh),Ug=ft.EventEmitter,gf=xt,Pg=ut,fe=De,En=Cs,Tf=Tr,Be=Ct(),qi=Fu,xg=yt,ta=ph,kg=vr,Mt=gh,vf=Th,Mg=vh,Lg=Eh,Ef=ys(),Y=new Pg("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},sa=["audio","video"];var Sh=class Cu extends Ug{static get C(){return Z}constructor(t){Y.debug("new"),super(),this._id=null,this._ua=t,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(t){this._data=t}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(t,n={},a){Y.debug("connect()");const o=t,s=Be.cloneObject(n.eventHandlers),r=Be.cloneArray(n.extraHeaders),d=Be.cloneObject(n.mediaConstraints,{audio:!0,video:!0}),h=n.mediaStream||null,_=Be.cloneObject(n.pcConfig,{iceServers:[]}),g=n.rtcConstraints||null,T=n.rtcOfferConstraints||null;if(this._rtcOfferConstraints=T,this._rtcAnswerConstraints=n.rtcAnswerConstraints||null,this._data=n.data||this._data,t===void 0)throw new TypeError("Not enough arguments");if(this._status!==Z.STATUS_NULL)throw new En.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new En.NotSupportedError("WebRTC not supported");if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${o}`);this._sessionTimers.enabled&&Be.isDecimal(n.sessionTimersExpires)&&(n.sessionTimersExpires>=fe.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=n.sessionTimersExpires:this._sessionTimers.defaultExpires=fe.SESSION_EXPIRES);for(const C in s)Object.prototype.hasOwnProperty.call(s,C)&&this.on(C,s[C]);this._from_tag=Be.newTag();const E=n.anonymous||!1,y={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:E,outbound:!0}),E?(y.from_display_name="Anonymous",y.from_uri=new Ef("sip","anonymous","anonymous.invalid"),r.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),r.push("Privacy: id")):n.fromUserName&&(y.from_uri=new Ef("sip",n.fromUserName,this._ua.configuration.uri.host),r.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),n.fromDisplayName&&(y.from_display_name=n.fromDisplayName),r.push(`Contact: ${this._contact}`),r.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&r.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new xg.InitialOutgoingInviteRequest(t,this._ua,y,r),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(_,g),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,a&&a(this),this._newRTCSession("local",this._request),this._sendInitialRequest(d,T,h)}init_incoming(t,n){Y.debug("init_incoming()");let a;const o=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;if(t.body&&o!=="application/sdp"){t.reply(415);return}if(this._status=Z.STATUS_INVITE_RECEIVED,this._from_tag=t.from_tag,this._id=t.call_id+this._from_tag,this._request=t,this._contact=this._ua.contact.toString(),t.hasHeader("expires")&&(a=t.getHeader("expires")*1e3),t.to_tag=Be.newTag(),!this._createDialog(t,"UAS",!0)){t.reply(500,"Missing Contact header field");return}t.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Z.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{t.reply(408),this._failed("local",null,fe.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),a&&(this._timers.expiresTimer=setTimeout(()=>{this._status===Z.STATUS_WAITING_FOR_ANSWER&&(t.reply(487),this._failed("system",null,fe.causes.EXPIRES))},a)),this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from,n&&n(this),this._newRTCSession("remote",t),this._status!==Z.STATUS_TERMINATED&&(t.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(t={}){Y.debug("answer()");const n=this._request,a=Be.cloneArray(t.extraHeaders),o=Be.cloneObject(t.mediaConstraints),s=t.mediaStream||null,r=Be.cloneObject(t.pcConfig,{iceServers:[]}),d=t.rtcConstraints||null,h=t.rtcAnswerConstraints||null,_=Be.cloneObject(t.rtcOfferConstraints);let g,T=!1,E=!1,y=!1,C=!1;if(this._rtcAnswerConstraints=h,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,this._direction!=="incoming")throw new En.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==Z.STATUS_WAITING_FOR_ANSWER)throw new En.InvalidStateError(this._status);if(this._sessionTimers.enabled&&Be.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=fe.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=fe.SESSION_EXPIRES),this._status=Z.STATUS_ANSWERED,!this._createDialog(n,"UAS")){n.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),a.unshift(`Contact: ${this._contact}`);const A=n.parseSDP();Array.isArray(A.media)||(A.media=[A.media]);for(const I of A.media)I.type==="audio"&&(T=!0,(!I.direction||I.direction==="sendrecv")&&(y=!0)),I.type==="video"&&(E=!0,(!I.direction||I.direction==="sendrecv")&&(C=!0));if(s&&o.audio===!1){g=s.getAudioTracks();for(const I of g)s.removeTrack(I)}if(s&&o.video===!1){g=s.getVideoTracks();for(const I of g)s.removeTrack(I)}!s&&o.audio===void 0&&(o.audio=y),!s&&o.video===void 0&&(o.video=C),!s&&!T&&!_.offerToReceiveAudio&&(o.audio=!1),!s&&!E&&!_.offerToReceiveVideo&&(o.video=!1),this._createRTCConnection(r,d),Promise.resolve().then(()=>{if(s)return s;if(o.audio||o.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(o).catch(I=>{throw this._status===Z.STATUS_TERMINATED?new Error("terminated"):(n.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:n.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($=>{throw n.reply(488),this._failed("system",null,fe.causes.WEBRTC_ERROR),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',$),this.emit("peerconnection:setremotedescriptionfailed",$),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(n),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",h).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(I=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,a),n.reply(200,null,a,I,()=>{this._status=Z.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,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(t={}){Y.debug("terminate()");const n=t.cause||fe.causes.BYE,a=Be.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,d=t.reason_phrase;if(this._status===Z.STATUS_TERMINATED)throw new En.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"),r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);r&&(d=d||fe.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${d}"`),this._status===Z.STATUS_NULL||this._status===Z.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===Z.STATUS_1XX_RECEIVED&&this._request.cancel(s),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"),r=r||480,r<300||r>=700)throw new TypeError(`Invalid status_code: ${r}`);this._request.reply(r,d,a,o),this._failed("local",null,fe.causes.REJECTED);break;case Z.STATUS_WAITING_FOR_ACK:case Z.STATUS_CONFIRMED:if(Y.debug("terminating session"),d=t.reason_phrase||fe.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);if(r&&a.push(`Reason: SIP ;cause=${r}; text="${d}"`),this._status===Z.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Tf.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:_})=>{_===fe.ACK&&(this.sendRequest(fe.BYE,{extraHeaders:a,body:o}),h.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Tf.C.STATUS_TERMINATED&&(this.sendRequest(fe.BYE,{extraHeaders:a,body:o}),h.terminate())}),this._ended("local",null,n),this._dialog=h,this._ua.newDialog(h)}else this.sendRequest(fe.BYE,{extraHeaders:a,body:o}),this._ended("local",null,n)}}sendDTMF(t,n={}){Y.debug("sendDTMF() | tones: %s",t);let a=0,o=n.duration||null,s=n.interToneGap||null;const r=n.transportType||fe.DTMF_TRANSPORT.INFO;if(t===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 En.InvalidStateError(this._status);if(r!==fe.DTMF_TRANSPORT.INFO&&r!==fe.DTMF_TRANSPORT.RFC2833)throw new TypeError(`invalid transportType: ${r}`);if(typeof t=="number"&&(t=t.toString()),!t||typeof t!="string"||!t.match(/^[0-9A-DR#*,]+$/i))throw new TypeError(`Invalid tones: ${t}`);if(o&&!Be.isDecimal(o))throw new TypeError(`Invalid tone duration: ${o}`);if(o?o<Mt.C.MIN_DURATION?(Y.debug(`"duration" value is lower than the minimum allowed, setting it to ${Mt.C.MIN_DURATION} milliseconds`),o=Mt.C.MIN_DURATION):o>Mt.C.MAX_DURATION?(Y.debug(`"duration" value is greater than the maximum allowed, setting it to ${Mt.C.MAX_DURATION} milliseconds`),o=Mt.C.MAX_DURATION):o=Math.abs(o):o=Mt.C.DEFAULT_DURATION,n.duration=o,s&&!Be.isDecimal(s))throw new TypeError(`Invalid interToneGap: ${s}`);if(s?s<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`),s=Mt.C.MIN_INTER_TONE_GAP):s=Math.abs(s):s=Mt.C.DEFAULT_INTER_TONE_GAP,r===fe.DTMF_TRANSPORT.RFC2833){const h=this._getDTMFRTPSender();h&&(t=h.toneBuffer+t,h.insertDTMF(t,o,s));return}if(this._tones){this._tones+=t;return}this._tones=t,d.call(this);function d(){let h;if(this._status===Z.STATUS_TERMINATED||!this._tones||a>=this._tones.length){this._tones=null;return}const _=this._tones[a];if(a+=1,_===",")h=2e3;else{const g=new Mt(this);n.eventHandlers={onFailed:()=>{this._tones=null}},g.send(_,n),h=o+s}setTimeout(d.bind(this),h)}}sendInfo(t,n,a={}){if(Y.debug("sendInfo()"),this._status!==Z.STATUS_CONFIRMED&&this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_1XX_RECEIVED)throw new En.InvalidStateError(this._status);new vf(this).send(t,n,a)}mute(t={audio:!0,video:!1}){Y.debug("mute()");let n=!1,a=!1;this._audioMuted===!1&&t.audio&&(n=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&t.video&&(a=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(n===!0||a===!0)&&this._onmute({audio:n,video:a})}unmute(t={audio:!0,video:!0}){Y.debug("unmute()");let n=!1,a=!1;this._audioMuted===!0&&t.audio&&(n=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&t.video&&(a=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(n===!0||a===!0)&&this._onunmute({audio:n,video:a})}hold(t={},n){if(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 a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:fe.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}unhold(t={},n){if(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 a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:fe.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}renegotiate(t={},n){Y.debug("renegotiate()");const a=t.rtcOfferConstraints||null;if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const o={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:fe.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}),!0}refer(t,n){Y.debug("refer()");const a=t;if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${a}`);const o=new Lg(this);o.sendRefer(t,n);const s=o.id;return this._referSubscribers[s]=o,o.on("requestFailed",()=>{delete this._referSubscribers[s]}),o.on("accepted",()=>{delete this._referSubscribers[s]}),o.on("failed",()=>{delete this._referSubscribers[s]}),o}sendRequest(t,n){return Y.debug("sendRequest()"),this._dialog.sendRequest(t,n)}receiveRequest(t){if(Y.debug("receiveRequest()"),t.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",t,fe.causes.CANCELED));else switch(t.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(!t.body){this.terminate({cause:fe.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:t.body};Y.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>{this._is_confirmed||this._confirmed("remote",t)}).catch(o=>{this.terminate({cause:fe.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})}else this._is_confirmed||this._confirmed("remote",t);break;case fe.BYE:this._status===Z.STATUS_CONFIRMED||this._status===Z.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,fe.causes.BYE)):this._status===Z.STATUS_INVITE_RECEIVED||this._status===Z.STATUS_WAITING_FOR_ANSWER?(t.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",t,fe.causes.BYE)):t.reply(403,"Wrong Status");break;case fe.INVITE:this._status===Z.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.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 n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;n&&n.match(/^application\/dtmf-relay/i)?new Mt(this).init_incoming(t):n!==void 0?new vf(this).init_incoming(t):t.reply(415)}else t.reply(403,"Wrong Status");break;case fe.UPDATE:this._status===Z.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case fe.REFER:this._status===Z.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case fe.NOTIFY:this._status===Z.STATUS_CONFIRMED?this._receiveNotify(t):t.reply(403,"Wrong Status");break;default:t.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(t){Y.debug("newDTMF()"),this.emit("newDTMF",t)}newInfo(t){Y.debug("newInfo()"),this.emit("newInfo",t)}_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(t){Y.warn("close() | error closing the RTCPeerConnection: %o",t)}for(const t in this._timers)Object.prototype.hasOwnProperty.call(this._timers,t)&&clearTimeout(this._timers[t]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const t in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(const t in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,t)&&delete this._referSubscribers[t];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(t,n){let a=qi.T1;function o(){this._status===Z.STATUS_WAITING_FOR_ACK&&(t.reply(200,null,[`Contact: ${this._contact}`],n),a<qi.T2&&(a=a*2,a>qi.T2&&(a=qi.T2)),this._timers.invite2xxTimer=setTimeout(o.bind(this),a))}this._timers.invite2xxTimer=setTimeout(o.bind(this),a)}_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))},qi.TIMER_H)}_createRTCConnection(t,n){this._connection=new RTCPeerConnection(t,n),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(t,n){if(Y.debug("createLocalDescription()"),t!=="offer"&&t!=="answer")throw new Error(`createLocalDescription() | invalid type "${t}"`);const a=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>t==="offer"?a.createOffer(n).catch(o=>(Y.warn('emit "peerconnection:createofferfailed" [error:%o]',o),this.emit("peerconnection:createofferfailed",o),Promise.reject(o))):a.createAnswer(n).catch(o=>(Y.warn('emit "peerconnection:createanswerfailed" [error:%o]',o),this.emit("peerconnection:createanswerfailed",o),Promise.reject(o)))).then(o=>a.setLocalDescription(o).catch(s=>(this._rtcReady=!0,Y.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',s),this.emit("peerconnection:setlocaldescriptionfailed",s),Promise.reject(s)))).then(()=>{const o=n&&n.iceRestart;if(a.iceGatheringState==="complete"&&!o||a.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const s={originator:"local",type:t,sdp:a.localDescription.sdp};return Y.debug('emit "sdp"'),this.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(s=>{let r=!1,d,h;this._iceReady=!1;const _=()=>{a.removeEventListener("icecandidate",d),a.removeEventListener("icegatheringstatechange",h),r=!0,this._rtcReady=!0,this._iceReady=!0;const g={originator:"local",type:t,sdp:a.localDescription.sdp};Y.debug('emit "sdp"'),this.emit("sdp",g),s(g.sdp)};a.addEventListener("icecandidate",d=g=>{const T=g.candidate;T?this.emit("icecandidate",{candidate:T,ready:_}):r||_()}),a.addEventListener("icegatheringstatechange",h=()=>{a.iceGatheringState==="complete"&&!r&&_()})})})}_createDialog(t,n,a){const o=n==="UAS"?t.to_tag:t.from_tag,s=n==="UAS"?t.from_tag:t.to_tag,r=t.call_id+o+s;let d=this._earlyDialogs[r];if(a)return d?!0:(d=new ta(this,t,n,ta.C.STATUS_EARLY),d.error?(Y.debug(d.error),this._failed("remote",t,fe.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=d,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,d)return d.update(t,n),this._dialog=d,delete this._earlyDialogs[r],!0;const h=new ta(this,t,n);return h.error?(Y.debug(h.error),this._failed("remote",t,fe.causes.INTERNAL_ERROR),!1):(this._dialog=h,!0)}}_receiveReinvite(t){Y.debug("receiveReinvite()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=Be.cloneArray(d.extraHeaders);if(this._status!==Z.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("reinvite",a),o)return;if(this._late_sdp=!1,!t.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(d=>{r.call(this,d)}).catch(()=>{t.reply(500)});return}if(n!=="application/sdp"){Y.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==Z.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{Y.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),this._late_sdp&&(d=this._mangleOffer(d)),t.reply(200,null,h,d,()=>{this._status=Z.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(t,d),this._setACKTimer()}),typeof a.callback=="function"&&a.callback()}}_receiveUpdate(t){Y.debug("receiveUpdate()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=Be.cloneArray(d.extraHeaders);if(this._status!==Z.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("update",a),o)return;if(!t.body){r.call(this,null);return}if(n!=="application/sdp"){Y.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==Z.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{Y.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),t.reply(200,null,h,d),typeof a.callback=="function"&&a.callback()}}_processInDialogSdpOffer(t){Y.debug("_processInDialogSdpOffer()");const n=t.parseSDP();let a=!1;for(const r of n.media){if(sa.indexOf(r.type)===-1)continue;const d=r.direction||n.direction||"sendrecv";if(d==="sendonly"||d==="inactive")a=!0;else{a=!1;break}}const o={originator:"remote",type:"offer",sdp:t.body};Y.debug('emit "sdp"'),this.emit("sdp",o);const s=new RTCSessionDescription({type:"offer",sdp:o.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(s).catch(r=>{throw t.reply(488),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',r),this.emit("peerconnection:setremotedescriptionfailed",r),r})}).then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&a===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&a===!0&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(r=>{throw t.reply(500),Y.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',r),r})}).catch(r=>{Y.warn("_processInDialogSdpOffer() failed [error: %o]",r)}),this._connectionPromiseQueue}_receiveRefer(t){if(Y.debug("receiveRefer()"),!t.refer_to){Y.debug("no Refer-To header field present in REFER"),t.reply(400);return}if(t.refer_to.uri.scheme!==fe.SIP){Y.debug("Refer-To header field points to a non-SIP URI scheme"),t.reply(416);return}t.reply(202);const n=new Mg(this,t.cseq);Y.debug('emit "refer"'),this.emit("refer",{request:t,accept:(s,r)=>{a.call(this,s,r)},reject:()=>{o.call(this)}});function a(s,r={}){if(s=typeof s=="function"?s:null,this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;const d=new Cu(this._ua);if(d.on("progress",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("accepted",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("_failed",({message:h,cause:_})=>{h?n.notify(h.status_code,h.reason_phrase):n.notify(487,_)}),t.refer_to.uri.hasHeader("replaces")){const h=decodeURIComponent(t.refer_to.uri.getHeader("replaces"));r.extraHeaders=Be.cloneArray(r.extraHeaders),r.extraHeaders.push(`Replaces: ${h}`)}d.connect(t.refer_to.uri.toAor(),r,s)}function o(){n.notify(603)}}_receiveNotify(t){switch(Y.debug("receiveNotify()"),t.event||t.reply(400),t.event.event){case"refer":{let n,a;if(t.event.params&&t.event.params.id)n=t.event.params.id,a=this._referSubscribers[n];else if(Object.keys(this._referSubscribers).length===1)a=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{t.reply(400,"Missing event id parameter");return}if(!a){t.reply(481,"Subscription does not exist");return}a.receiveNotify(t),t.reply(200);break}default:t.reply(489)}}_receiveReplaces(t){Y.debug("receiveReplaces()");function n(o){if(this._status!==Z.STATUS_WAITING_FOR_ACK&&this._status!==Z.STATUS_CONFIRMED)return!1;const s=new Cu(this._ua);s.on("confirmed",()=>{this.terminate()}),s.init_incoming(t,o)}function a(){Y.debug("Replaced INVITE rejected by the user"),t.reply(486)}this.emit("replaces",{request:t,accept:o=>{n.call(this,o)},reject:()=>{a.call(this)}})}_sendInitialRequest(t,n,a){const o=new kg(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});Promise.resolve().then(()=>{if(a)return a;if(t.audio||t.video)return this._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(t).catch(s=>{throw this._status===Z.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,fe.causes.USER_DENIED_MEDIA_ACCESS),Y.warn('emit "getusermediafailed" [error:%o]',s),this.emit("getusermediafailed",s),s)})}).then(s=>{if(this._status===Z.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=s,s&&s.getTracks().forEach(r=>{this._connection.addTrack(r,s)}),this._connecting(this._request),this._createLocalDescription("offer",n).catch(r=>{throw this._failed("local",null,fe.causes.WEBRTC_ERROR),r})}).then(s=>{if(this._is_canceled||this._status===Z.STATUS_TERMINATED)throw new Error("terminated");this._request.body=s,this._status=Z.STATUS_INVITE_SENT,Y.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),o.send()}).catch(s=>{this._status!==Z.STATUS_TERMINATED&&Y.warn(s)})}_getDTMFRTPSender(){const t=this._connection.getSenders().find(n=>n.track&&n.track.kind==="audio");if(!(t&&t.dtmf)){Y.warn("sendDTMF() | no local audio track to send DTMF with");return}return t.dtmf}_receiveInviteResponse(t){if(Y.debug("receiveInviteResponse()"),this._dialog&&t.status_code>=200&&t.status_code<=299)if(this._dialog.id.call_id===t.call_id&&this._dialog.id.local_tag===t.from_tag&&this._dialog.id.remote_tag===t.to_tag){this.sendRequest(fe.ACK);return}else{const n=new ta(this,t,"UAC");if(n.error!==void 0){Y.debug(n.error);return}this.sendRequest(fe.ACK),this.sendRequest(fe.BYE);return}if(this._is_canceled){t.status_code>=100&&t.status_code<200?this._request.cancel(this._cancel_reason):t.status_code>=200&&t.status_code<299&&this._acceptAndTerminate(t);return}if(!(this._status!==Z.STATUS_INVITE_SENT&&this._status!==Z.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(t.status_code):this._status=Z.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(t.status_code):{if(!t.to_tag){Y.debug("1xx response received without to tag");break}if(t.hasHeader("contact")&&!this._createDialog(t,"UAC",!0))break;if(this._status=Z.STATUS_1XX_RECEIVED,!t.body){this._progress("remote",t);break}const n={originator:"remote",type:"answer",sdp:t.body};Y.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>this._progress("remote",t)).catch(o=>{Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)});break}case/^2[0-9]{2}$/.test(t.status_code):{if(this._status=Z.STATUS_CONFIRMED,!t.body){this._acceptAndTerminate(t,400,fe.causes.MISSING_SDP),this._failed("remote",t,fe.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(t,"UAC"))break;const n={originator:"remote",type:"answer",sdp:t.body};Y.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._connection.signalingState==="stable")return this._connection.createOffer(this._rtcOfferConstraints).then(o=>this._connection.setLocalDescription(o)).catch(o=>{this._acceptAndTerminate(t,500,o.toString()),this._failed("local",t,fe.causes.WEBRTC_ERROR)})}).then(()=>{this._connection.setRemoteDescription(a).then(()=>{this._handleSessionTimersInIncomingResponse(t),this._accepted("remote",t),this.sendRequest(fe.ACK),this._confirmed("local",null)}).catch(o=>{this._acceptAndTerminate(t,488,"Not Acceptable Here"),this._failed("remote",t,fe.causes.BAD_MEDIA_DESCRIPTION),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})});break}default:{const n=Be.sipErrorCause(t.status_code);this._failed("remote",t,n)}}}_sendReinvite(t={}){Y.debug("sendReinvite()");const n=Be.cloneArray(t.extraHeaders),a=Be.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null;let s=!1;n.push(`Contact: ${this._contact}`),n.push("Content-Type: application/sdp"),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(h=>{h=this._mangleOffer(h);const _={originator:"local",type:"offer",sdp:h};Y.debug('emit "sdp"'),this.emit("sdp",_),this.sendRequest(fe.INVITE,{extraHeaders:n,body:h,eventHandlers:{onSuccessResponse:g=>{r.call(this,g),s=!0},onErrorResponse:g=>{d.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{d()});function r(h){if(this._status===Z.STATUS_TERMINATED||(this.sendRequest(fe.ACK),s))return;if(this._handleSessionTimersInIncomingResponse(h),h.body){if(!h.hasHeader("Content-Type")||h.getHeader("Content-Type").toLowerCase()!=="application/sdp"){d.call(this);return}}else{d.call(this);return}const _={originator:"remote",type:"answer",sdp:h.body};Y.debug('emit "sdp"'),this.emit("sdp",_);const g=new RTCSessionDescription({type:"answer",sdp:_.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(g)).then(()=>{a.succeeded&&a.succeeded(h)}).catch(T=>{d.call(this),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function d(h){a.failed&&a.failed(h)}}_sendUpdate(t={}){Y.debug("sendUpdate()");const n=Be.cloneArray(t.extraHeaders),a=Be.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null,s=t.sdpOffer||!1;let r=!1;n.push(`Contact: ${this._contact}`),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),s?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(_=>{_=this._mangleOffer(_);const g={originator:"local",type:"offer",sdp:_};Y.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(fe.UPDATE,{extraHeaders:n,body:_,eventHandlers:{onSuccessResponse:T=>{d.call(this,T),r=!0},onErrorResponse:T=>{h.call(this,T)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{h.call(this)})):this.sendRequest(fe.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:_=>{d.call(this,_)},onErrorResponse:_=>{h.call(this,_)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function d(_){if(this._status!==Z.STATUS_TERMINATED&&!r)if(this._handleSessionTimersInIncomingResponse(_),s){if(_.body){if(!_.hasHeader("Content-Type")||_.getHeader("Content-Type").toLowerCase()!=="application/sdp"){h.call(this);return}}else{h.call(this);return}const g={originator:"remote",type:"answer",sdp:_.body};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(()=>{a.succeeded&&a.succeeded(_)}).catch(E=>{h.call(this),Y.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),this.emit("peerconnection:setremotedescriptionfailed",E)})}else a.succeeded&&a.succeeded(_)}function h(_){a.failed&&a.failed(_)}}_acceptAndTerminate(t,n,a){Y.debug("acceptAndTerminate()");const o=[];n&&(a=a||fe.REASON_PHRASE[n]||"",o.push(`Reason: SIP ;cause=${n}; text="${a}"`)),(this._dialog||this._createDialog(t,"UAC"))&&(this.sendRequest(fe.ACK),this.sendRequest(fe.BYE,{extraHeaders:o})),this._status=Z.STATUS_TERMINATED}_mangleOffer(t){if(!this._localHold&&!this._remoteHold)return t;if(t=gf.parse(t),this._localHold&&!this._remoteHold){Y.debug("mangleOffer() | me on hold, mangling offer");for(const n of t.media)sa.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="sendonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="sendonly")}else if(this._localHold&&this._remoteHold){Y.debug("mangleOffer() | both on hold, mangling offer");for(const n of t.media)sa.indexOf(n.type)!==-1&&(n.direction="inactive")}else if(this._remoteHold){Y.debug("mangleOffer() | remote on hold, mangling offer");for(const n of t.media)sa.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="recvonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="recvonly")}return gf.write(t)}_setLocalMediaStatus(){let t=!0,n=!0;(this._localHold||this._remoteHold)&&(t=!1,n=!1),this._audioMuted&&(t=!1),this._videoMuted&&(n=!1),this._toggleMuteAudio(!t),this._toggleMuteVideo(!n)}_handleSessionTimersInIncomingRequest(t,n){if(!this._sessionTimers.enabled)return;let a;t.session_expires&&t.session_expires>=fe.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,a=t.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,a="uas"),n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${a}`),this._sessionTimers.refresher=a==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(t){if(!this._sessionTimers.enabled)return;let n;t.session_expires&&t.session_expires>=fe.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,n=t.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uac"),this._sessionTimers.refresher=n==="uac",this._runSessionTimer()}_runSessionTimer(){const t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(()=>{this._status!==Z.STATUS_TERMINATED&&this._isReadyToReOffer()&&(Y.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===fe.UPDATE?this._sendUpdate():this._sendReinvite())},t*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"}))},t*1100)}_toggleMuteAudio(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="audio");for(const a of n)a.track.enabled=!t}_toggleMuteVideo(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="video");for(const a of n)a.track.enabled=!t}_newRTCSession(t,n){Y.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:t,session:this,request:n})}_connecting(t){Y.debug("session connecting"),Y.debug('emit "connecting"'),this.emit("connecting",{request:t})}_progress(t,n){Y.debug("session progress"),Y.debug('emit "progress"'),this.emit("progress",{originator:t,response:n||null})}_accepted(t,n){Y.debug("session accepted"),this._start_time=new Date,Y.debug('emit "accepted"'),this.emit("accepted",{originator:t,response:n||null})}_confirmed(t,n){Y.debug("session confirmed"),this._is_confirmed=!0,Y.debug('emit "confirmed"'),this.emit("confirmed",{originator:t,ack:n||null})}_ended(t,n,a){Y.debug("session ended"),this._end_time=new Date,this._close(),Y.debug('emit "ended"'),this.emit("ended",{originator:t,message:n||null,cause:a})}_failed(t,n,a){Y.debug("session failed"),Y.debug('emit "_failed"'),this.emit("_failed",{originator:t,message:n||null,cause:a}),this._close(),Y.debug('emit "failed"'),this.emit("failed",{originator:t,message:n||null,cause:a})}_onhold(t){Y.debug("session onhold"),this._setLocalMediaStatus(),Y.debug('emit "hold"'),this.emit("hold",{originator:t})}_onunhold(t){Y.debug("session onunhold"),this._setLocalMediaStatus(),Y.debug('emit "unhold"'),this.emit("unhold",{originator:t})}_onmute({audio:t,video:n}){Y.debug("session onmute"),this._setLocalMediaStatus(),Y.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}_onunmute({audio:t,video:n}){Y.debug("session onunmute"),this._setLocalMediaStatus(),Y.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}};const $g=ze(Sh),Hg=ft.EventEmitter,Fg=ut,Ko=De,jg=yt,Vi=Ct(),qg=vr,Sf=Cs,Vg=ys(),na=new Fg("Message");var Bg=class extends Hg{constructor(t){super(),this._ua=t,this._request=null,this._closed=!1,this._direction=null,this._local_identity=null,this._remote_identity=null,this._is_replied=!1,this._data={}}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}send(t,n,a={}){const o=t;if(t===void 0||n===void 0)throw new TypeError("Not enough arguments");if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${o}`);const s=Vi.cloneArray(a.extraHeaders),r=Vi.cloneObject(a.eventHandlers),d=a.contentType||"text/plain",h={};a.fromUserName&&(h.from_uri=new Vg("sip",a.fromUserName,this._ua.configuration.uri.host),s.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),a.fromDisplayName&&(h.from_display_name=a.fromDisplayName);for(const g in r)Object.prototype.hasOwnProperty.call(r,g)&&this.on(g,r[g]);s.push(`Content-Type: ${d}`),this._request=new jg.OutgoingRequest(Ko.MESSAGE,t,this._ua,h,s),n&&(this._request.body=n);const _=new qg(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:g=>{this._receiveResponse(g)}});this._newMessage("local",this._request),_.send()}init_incoming(t){this._request=t,this._newMessage("remote",t),this._is_replied||(this._is_replied=!0,t.reply(200)),this._close()}accept(t={}){const n=Vi.cloneArray(t.extraHeaders),a=t.body;if(this._direction!=="incoming")throw new Sf.NotSupportedError('"accept" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");this._is_replied=!0,this._request.reply(200,null,n,a)}reject(t={}){const n=t.status_code||480,a=t.reason_phrase,o=Vi.cloneArray(t.extraHeaders),s=t.body;if(this._direction!=="incoming")throw new Sf.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(n<300||n>=700)throw new TypeError(`Invalid status_code: ${n}`);this._is_replied=!0,this._request.reply(n,a,o,s)}_receiveResponse(t){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):this._succeeded("remote",t);break;default:{const n=Vi.sipErrorCause(t.status_code);this._failed("remote",t,n);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)}_newMessage(t,n){t==="remote"?(this._direction="incoming",this._local_identity=n.to,this._remote_identity=n.from):t==="local"&&(this._direction="outgoing",this._local_identity=n.from,this._remote_identity=n.to),this._ua.newMessage(this,{originator:t,message:this,request:n})}_failed(t,n,a){na.debug("MESSAGE failed"),this._close(),na.debug('emit "failed"'),this.emit("failed",{originator:t,response:n||null,cause:a})}_succeeded(t,n){na.debug("MESSAGE succeeded"),this._close(),na.debug('emit "succeeded"'),this.emit("succeeded",{originator:t,response:n})}};const Gg=ft.EventEmitter,Wg=ut,Yo=De,Kg=yt,Bi=Ct(),Yg=vr,yf=Cs,ra=new Wg("Options");var Jg=class extends Gg{constructor(t){super(),this._ua=t,this._request=null,this._closed=!1,this._direction=null,this._local_identity=null,this._remote_identity=null,this._is_replied=!1,this._data={}}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}send(t,n,a={}){const o=t;if(t===void 0)throw new TypeError("A target is required for OPTIONS");if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${o}`);const s=Bi.cloneArray(a.extraHeaders),r=Bi.cloneObject(a.eventHandlers),d=a.contentType||"application/sdp";for(const _ in r)Object.prototype.hasOwnProperty.call(r,_)&&this.on(_,r[_]);s.push(`Content-Type: ${d}`),this._request=new Kg.OutgoingRequest(Yo.OPTIONS,t,this._ua,null,s),n&&(this._request.body=n);const h=new Yg(this._ua,this._request,{onRequestTimeout:()=>{this._onRequestTimeout()},onTransportError:()=>{this._onTransportError()},onReceiveResponse:_=>{this._receiveResponse(_)}});this._newOptions("local",this._request),h.send()}init_incoming(t){this._request=t,this._newOptions("remote",t),this._is_replied||(this._is_replied=!0,t.reply(200)),this._close()}accept(t={}){const n=Bi.cloneArray(t.extraHeaders),a=t.body;if(this._direction!=="incoming")throw new yf.NotSupportedError('"accept" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");this._is_replied=!0,this._request.reply(200,null,n,a)}reject(t={}){const n=t.status_code||480,a=t.reason_phrase,o=Bi.cloneArray(t.extraHeaders),s=t.body;if(this._direction!=="incoming")throw new yf.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(n<300||n>=700)throw new TypeError(`Invalid status_code: ${n}`);this._is_replied=!0,this._request.reply(n,a,o,s)}_receiveResponse(t){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):this._succeeded("remote",t);break;default:{const n=Bi.sipErrorCause(t.status_code);this._failed("remote",t,n);break}}}_onRequestTimeout(){this._closed||this._failed("system",null,Yo.causes.REQUEST_TIMEOUT)}_onTransportError(){this._closed||this._failed("system",null,Yo.causes.CONNECTION_ERROR)}_close(){this._closed=!0,this._ua.destroyMessage(this)}_newOptions(t,n){t==="remote"?(this._direction="incoming",this._local_identity=n.to,this._remote_identity=n.from):t==="local"&&(this._direction="outgoing",this._local_identity=n.from,this._remote_identity=n.to),this._ua.newOptions(this,{originator:t,message:this,request:n})}_failed(t,n,a){ra.debug("OPTIONS failed"),this._close(),ra.debug('emit "failed"'),this.emit("failed",{originator:t,response:n||null,cause:a})}_succeeded(t,n){ra.debug("OPTIONS succeeded"),this._close(),ra.debug('emit "succeeded"'),this.emit("succeeded",{originator:t,response:n})}},qu={};const zg=ut,Jo=Ct(),Xg=Zt(),Gi=new zg("Socket");qu.isSocket=c=>{if(Array.isArray(c))return!1;if(typeof c>"u")return Gi.warn("undefined JsSIP.Socket instance"),!1;try{if(!Jo.isString(c.url))throw Gi.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!Jo.isString(c.via_transport))throw Gi.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(Xg.parse(c.sip_uri,"SIP_URI")===-1)throw Gi.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch{return!1}try{["connect","disconnect","send"].forEach(t=>{if(!Jo.isFunction(c[t]))throw Gi.warn(`missing or invalid JsSIP.Socket method: ${t}`),new Error(`Missing or invalid JsSIP.Socket method: ${t}`)})}catch{return!1}return!0};const Qg=ut,Zg=qu,Cf=De,Ut=new Qg("Transport"),Vt={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 yh=class{constructor(t,n=Vt.recovery_options){Ut.debug("new()"),this.status=Vt.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(a){Ut.warn(`cannot use TextDecoder: ${a}`)}if(typeof t>"u")throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(a){if(!Zg.isSocket(a.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(a.weight&&!Number(a.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:a.socket,weight:a.weight||0,status:Vt.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=Vt.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=Vt.STATUS_DISCONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=()=>{},this.socket.ondisconnect=()=>{},this.socket.ondata=()=>{},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}send(t){if(Ut.debug("send()"),!this.isConnected())return Ut.warn("unable to send message, transport is not connected"),!1;const n=t.toString();return Ut.debug(`sending message:
|
116
116
|
|
117
117
|
${n}
|
118
118
|
`),this.socket.send(n)}isConnected(){return this.status===Vt.STATUS_CONNECTED}isConnecting(){return this.status===Vt.STATUS_CONNECTING}_reconnect(){this.recover_attempts+=1;let t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);t<this.recovery_options.min_interval?t=this.recovery_options.min_interval:t>this.recovery_options.max_interval&&(t=this.recovery_options.max_interval),Ut.debug(`reconnection attempt: ${this.recover_attempts}. next connection attempt in ${t} seconds`),this.recovery_timer=setTimeout(()=>{!this.close_requested&&!(this.isConnected()||this.isConnecting())&&(this._getSocket(),this.connect())},t*1e3)}_getSocket(){let t=[];if(this.sockets.forEach(a=>{a.status!==Vt.SOCKET_STATUS_ERROR&&(t.length===0?t.push(a):a.weight>t[0].weight?t=[a]:a.weight===t[0].weight&&t.push(a))}),t.length===0){this.sockets.forEach(a=>{a.status=Vt.SOCKET_STATUS_READY}),this._getSocket();return}const n=Math.floor(Math.random()*t.length);this.socket=t[n].socket}_onConnect(){this.recover_attempts=0,this.status=Vt.STATUS_CONNECTED,this.recovery_timer!==null&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}_onDisconnect(t,n,a){this.status=Vt.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:t,code:n,reason:a}),!this.close_requested&&(this.sockets.forEach(function(o){this.socket===o.socket&&(o.status=Vt.SOCKET_STATUS_ERROR)},this),this._reconnect(t))}_onData(t){if(t===`\r
|
@@ -122,17 +122,17 @@ ${t}
|
|
122
122
|
`)}else Ut.debug(`received text message:
|
123
123
|
|
124
124
|
${t}
|
125
|
-
`);this.ondata({transport:this,message:t})}};const eT=ze(yh);var
|
126
|
-
`);if(o===-1){ia.warn("parseMessage() | no CRLF found, not a SIP message");return}const s=c.substring(0,o);let r=
|
127
|
-
`,n),o===-1)return o;!c.substring(o+2,o+4).match(/(^\r\n)/)&&c.charAt(o+2).match(/(^\s+)/)?n=o+2:a=o}return a}function nT(c,t,n,a){let o;const s=t.indexOf(":",n),r=t.substring(n,s).trim(),d=t.substring(s+1,a).trim();switch(r.toLowerCase()){case"via":case"v":c.addHeader("via",d),c.getHeaders("via").length===1?(o=c.parseHeader("Via"),o&&(c.via=o,c.via_branch=o.branch)):o=0;break;case"from":case"f":c.setHeader("from",d),o=c.parseHeader("from"),o&&(c.from=o,c.from_tag=o.getParam("tag"));break;case"to":case"t":c.setHeader("to",d),o=c.parseHeader("to"),o&&(c.to=o,c.to_tag=o.getParam("tag"));break;case"record-route":if(o=
|
125
|
+
`);this.ondata({transport:this,message:t})}};const eT=ze(yh);var Ch={};const tT=ut,Au=Zt(),Ru=yt,ia=new tT("Parser");Ch.parseMessage=(c,t)=>{let n,a,o=c.indexOf(`\r
|
126
|
+
`);if(o===-1){ia.warn("parseMessage() | no CRLF found, not a SIP message");return}const s=c.substring(0,o);let r=Au.parse(s,"Request_Response");if(r===-1){ia.warn(`parseMessage() | error parsing first line of SIP message: "${s}"`);return}else r.status_code?(n=new Ru.IncomingResponse,n.status_code=r.status_code,n.reason_phrase=r.reason_phrase):(n=new Ru.IncomingRequest(t),n.method=r.method,n.ruri=r.uri);n.data=c;let d=o+2;for(;;){if(o=sT(c,d),o===-2){a=d+2;break}else if(o===-1){ia.warn("parseMessage() | malformed message");return}if(r=nT(n,c,d,o),r!==!0){ia.warn("parseMessage() |",r.error);return}d=o+2}if(n.hasHeader("content-length")){const h=n.getHeader("content-length");n.body=c.substr(a,h)}else n.body=c.substring(a);return n};function sT(c,t){let n=t,a=0,o=0;if(c.substring(n,n+2).match(/(^\r\n)/))return-2;for(;a===0;){if(o=c.indexOf(`\r
|
127
|
+
`,n),o===-1)return o;!c.substring(o+2,o+4).match(/(^\r\n)/)&&c.charAt(o+2).match(/(^\s+)/)?n=o+2:a=o}return a}function nT(c,t,n,a){let o;const s=t.indexOf(":",n),r=t.substring(n,s).trim(),d=t.substring(s+1,a).trim();switch(r.toLowerCase()){case"via":case"v":c.addHeader("via",d),c.getHeaders("via").length===1?(o=c.parseHeader("Via"),o&&(c.via=o,c.via_branch=o.branch)):o=0;break;case"from":case"f":c.setHeader("from",d),o=c.parseHeader("from"),o&&(c.from=o,c.from_tag=o.getParam("tag"));break;case"to":case"t":c.setHeader("to",d),o=c.parseHeader("to"),o&&(c.to=o,c.to_tag=o.getParam("tag"));break;case"record-route":if(o=Au.parse(d,"Record_Route"),o===-1)o=void 0;else for(const h of o)c.addHeader("record-route",d.substring(h.possition,h.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=h.parsed;break;case"call-id":case"i":c.setHeader("call-id",d),o=c.parseHeader("call-id"),o&&(c.call_id=d);break;case"contact":case"m":if(o=Au.parse(d,"Contact"),o===-1)o=void 0;else for(const h of o)c.addHeader("contact",d.substring(h.possition,h.offset)),c.headers.Contact[c.getHeaders("contact").length-1].parsed=h.parsed;break;case"content-length":case"l":c.setHeader("content-length",d),o=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",d),o=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",d),o=c.parseHeader("cseq"),o&&(c.cseq=o.value),c instanceof Ru.IncomingResponse&&(c.method=o.method);break;case"max-forwards":c.setHeader("max-forwards",d),o=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",d),o=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",d),o=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",d),o=c.parseHeader("session-expires"),o&&(c.session_expires=o.expires,c.session_expires_refresher=o.refresher);break;case"refer-to":case"r":c.setHeader("refer-to",d),o=c.parseHeader("refer-to"),o&&(c.refer_to=o);break;case"replaces":c.setHeader("replaces",d),o=c.parseHeader("replaces"),o&&(c.replaces=o);break;case"event":case"o":c.setHeader("event",d),o=c.parseHeader("event"),o&&(c.event=o);break;default:c.addHeader(r,d),o=0}return o===void 0?{error:`error parsing header "${r}"`}:!0}const rT=ut,Ah=De,Af=yt,Vu=Ct(),Bu=new rT("sanityCheck"),iT=[_T],lT=[oT,uT,cT,fT],aT=[hT,dT];let Fe,is,Rh;var Ih=(c,t,n)=>{Fe=c,is=t,Rh=n;for(const a of iT)if(a()===!1)return!1;if(Fe instanceof Af.IncomingRequest){for(const a of lT)if(a()===!1)return!1}else if(Fe instanceof Af.IncomingResponse){for(const a of aT)if(a()===!1)return!1}return!0};function oT(){if(Fe.s("to").uri.scheme!=="sip")return nl(416),!1}function uT(){if(!Fe.to_tag&&Fe.call_id.substr(0,5)===is.configuration.jssip_id)return nl(482),!1}function cT(){const c=Vu.str_utf8_length(Fe.body),t=Fe.getHeader("content-length");if(c<t)return nl(400),!1}function fT(){const c=Fe.from_tag,t=Fe.call_id,n=Fe.cseq;let a;if(!Fe.to_tag)if(Fe.method===Ah.INVITE){if(is._transactions.ist[Fe.via_branch])return!1;for(const o in is._transactions.ist)if(Object.prototype.hasOwnProperty.call(is._transactions.ist,o)&&(a=is._transactions.ist[o],a.request.from_tag===c&&a.request.call_id===t&&a.request.cseq===n))return nl(482),!1}else{if(is._transactions.nist[Fe.via_branch])return!1;for(const o in is._transactions.nist)if(Object.prototype.hasOwnProperty.call(is._transactions.nist,o)&&(a=is._transactions.nist[o],a.request.from_tag===c&&a.request.call_id===t&&a.request.cseq===n))return nl(482),!1}}function hT(){if(Fe.getHeaders("via").length>1)return Bu.debug("more than one Via header field present in the response, dropping the response"),!1}function dT(){const c=Vu.str_utf8_length(Fe.body),t=Fe.getHeader("content-length");if(c<t)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 t of c)if(!Fe.hasHeader(t))return Bu.debug(`missing mandatory header field : ${t}, dropping the response`),!1}function nl(c){const t=Fe.getHeaders("via");let n,a=`SIP/2.0 ${c} ${Ah.REASON_PHRASE[c]}\r
|
128
128
|
`;for(const o of t)a+=`Via: ${o}\r
|
129
129
|
`;n=Fe.getHeader("To"),Fe.to_tag||(n+=`;tag=${Vu.newTag()}`),a+=`To: ${n}\r
|
130
130
|
`,a+=`From: ${Fe.getHeader("From")}\r
|
131
131
|
`,a+=`Call-ID: ${Fe.call_id}\r
|
132
132
|
`,a+=`CSeq: ${Fe.cseq} ${Fe.method}\r
|
133
133
|
`,a+=`\r
|
134
|
-
`,Rh.send(a)}const pT=ze(Ih);var rl={};const hr=At(),An=De,zo=Zt(),Rf=ys(),Xo=qu,Qo=As;rl.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:An.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:An.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:An.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:`${hr.createRandomToken(12)}.invalid`};const la={mandatory:{sockets(c){const t=[];if(Xo.isSocket(c))t.push({socket:c});else if(Array.isArray(c)&&c.length)for(const n of c)Object.prototype.hasOwnProperty.call(n,"socket")&&Xo.isSocket(n.socket)?t.push(n):Xo.isSocket(n)&&t.push({socket:n});else return;return t},uri(c){/^sip:/i.test(c)||(c=`${An.SIP}:${c}`);const t=Rf.parse(c);if(t)return t.user?t:void 0}},optional:{authorization_user(c){if(zo.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(hr.isDecimal(c)){const t=Number(c);if(t>0)return t}},connection_recovery_min_interval(c){if(hr.isDecimal(c)){const t=Number(c);if(t>0)return t}},contact_uri(c){if(typeof c=="string"){const t=zo.parse(c,"SIP_URI");if(t!==-1)return t}},display_name(c){return c},instance_id(c){if(/^uuid:/i.test(c)&&(c=c.substr(5)),zo.parse(c,"uuid")!==-1)return c},no_answer_timeout(c){if(hr.isDecimal(c)){const t=Number(c);if(t>0)return t}},session_timers(c){if(typeof c=="boolean")return c},session_timers_refresh_method(c){if(typeof c=="string"&&(c=c.toUpperCase(),c===An.INVITE||c===An.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(hr.isDecimal(c)){const t=Number(c);if(t>0)return t}},registrar_server(c){/^sip:/i.test(c)||(c=`${An.SIP}:${c}`);const t=Rf.parse(c);if(t)return t.user?void 0:t},use_preloaded_route(c){if(typeof c=="boolean")return c},extra_headers(c){const t=[];if(Array.isArray(c)&&c.length)for(const n of c)typeof n=="string"&&t.push(n);else return;return t}}};rl.load=(c,t)=>{for(const n in la.mandatory)if(t.hasOwnProperty(n)){const a=t[n],o=la.mandatory[n](a);if(o!==void 0)c[n]=o;else throw new Qo.ConfigurationError(n,a)}else throw new Qo.ConfigurationError(n);for(const n in la.optional)if(t.hasOwnProperty(n)){const a=t[n];if(hr.isEmpty(a))continue;const o=la.optional[n](a);if(o!==void 0)c[n]=o;else throw new Qo.ConfigurationError(n,a)}};const mT=ft.EventEmitter,gT=ut,mt=De,TT=lg,If=Sh,bf=Bg,wf=Jg,Zo=Tr,vT=yh,aa=At(),ET=As,ST=ys(),yT=Ah,eu=yt,AT=Ih,tu=rl,qe=new gT("UA"),vt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};var bh=class extends mT{static get C(){return vt}constructor(t){if(qe.debug("new() [configuration:%o]",t),super(),this._cache={credentials:{}},this._configuration=Object.assign({},tu.settings),this._dynConfiguration={},this._dialogs={},this._applicants={},this._sessions={},this._transport=null,this._contact=null,this._status=vt.STATUS_INIT,this._error=null,this._transactions={nist:{},nict:{},ist:{},ict:{}},this._data={},this._closeTimer=null,t===void 0)throw new TypeError("Not enough arguments");try{this._loadConfig(t)}catch(n){throw this._status=vt.STATUS_NOT_READY,this._error=vt.CONFIGURATION_ERROR,n}this._registrator=new TT(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(t){qe.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(t)}registrator(){return this._registrator}isRegistered(){return this._registrator.registered}isConnected(){return this._transport.isConnected()}call(t,n){qe.debug("call()");const a=new If(this);return a.connect(t,n),a}sendMessage(t,n,a){qe.debug("sendMessage()");const o=new bf(this);return o.send(t,n,a),o}sendOptions(t,n,a){qe.debug("sendOptions()");const o=new wf(this);return o.send(t,n,a),o}terminateSessions(t){qe.debug("terminateSessions()");for(const n in this._sessions)this._sessions[n].isEnded()||this._sessions[n].terminate(t)}stop(){if(qe.debug("stop()"),this._dynConfiguration={},this._status===vt.STATUS_USER_CLOSED){qe.debug("UA already closed");return}this._registrator.close();const t=Object.keys(this._sessions).length;for(const a in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,a)){qe.debug(`closing session ${a}`);try{this._sessions[a].terminate()}catch{}}for(const a in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,a))try{this._applicants[a].close()}catch{}this._status=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&&t===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}normalizeTarget(t){return aa.normalizeTarget(t,this._configuration.hostport_params)}get(t){switch(t){case"authorization_user":return this._configuration.authorization_user;case"realm":return this._configuration.realm;case"ha1":return this._configuration.ha1;case"authorization_jwt":return this._configuration.authorization_jwt;default:qe.warn('get() | cannot get "%s" parameter in runtime',t);return}}set(t,n){switch(t){case"authorization_user":{this._configuration.authorization_user=String(n);break}case"password":{this._configuration.password=String(n);break}case"realm":{this._configuration.realm=String(n);break}case"ha1":{this._configuration.ha1=String(n),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(n);break}case"display_name":{this._configuration.display_name=n;break}default:return qe.warn('set() | cannot set "%s" parameter in runtime',t),!1}return!0}newTransaction(t){this._transactions[t.type][t.id]=t,this.emit("newTransaction",{transaction:t})}destroyTransaction(t){delete this._transactions[t.type][t.id],this.emit("transactionDestroyed",{transaction:t})}newDialog(t){this._dialogs[t.id]=t}destroyDialog(t){delete this._dialogs[t.id]}newMessage(t,n){this._applicants[t]=t,this.emit("newMessage",n)}newOptions(t,n){this._applicants[t]=t,this.emit("newOptions",n)}destroyMessage(t){delete this._applicants[t]}newRTCSession(t,n){this._sessions[t.id]=t,this.emit("newRTCSession",n)}destroyRTCSession(t){delete this._sessions[t.id]}registered(t){this.emit("registered",t)}unregistered(t){this.emit("unregistered",t)}registrationFailed(t){this.emit("registrationFailed",t)}receiveRequest(t){const n=t.method;if(t.ruri.user!==this._configuration.uri.user&&t.ruri.user!==this._contact.uri.user){qe.debug("Request-URI does not point to us"),t.method!==mt.ACK&&t.reply_sl(404);return}if(t.ruri.scheme===mt.SIPS){t.reply_sl(416);return}if(Zo.checkTransaction(this,t))return;if(n===mt.INVITE?new Zo.InviteServerTransaction(this,this._transport,t):n!==mt.ACK&&n!==mt.CANCEL&&new Zo.NonInviteServerTransaction(this,this._transport,t),n===mt.OPTIONS){if(this.listeners("newOptions").length===0){t.reply(200);return}new wf(this).init_incoming(t)}else if(n===mt.MESSAGE){if(this.listeners("newMessage").length===0){t.reply(405);return}new bf(this).init_incoming(t)}else if(n===mt.INVITE&&!t.to_tag&&this.listeners("newRTCSession").length===0){t.reply(405);return}let a,o;if(t.to_tag)a=this._findDialog(t.call_id,t.from_tag,t.to_tag),a?a.receiveRequest(t):n===mt.NOTIFY?(o=this._findSession(t),o?o.receiveRequest(t):(qe.debug("received NOTIFY request for a non existent subscription"),t.reply(481,"Subscription does not exist"))):n!==mt.ACK&&t.reply(481);else switch(n){case mt.INVITE:if(window.RTCPeerConnection)if(t.hasHeader("replaces")){const s=t.replaces;a=this._findDialog(s.call_id,s.from_tag,s.to_tag),a?(o=a.owner,o.isEnded()?t.reply(603):o.receiveRequest(t)):t.reply(481)}else o=new If(this),o.init_incoming(t);else qe.warn("INVITE received but WebRTC is not supported"),t.reply(488);break;case mt.BYE:t.reply(481);break;case mt.CANCEL:o=this._findSession(t),o?o.receiveRequest(t):qe.debug("received CANCEL request for a non existent session");break;case mt.ACK:break;case mt.NOTIFY:this.emit("sipEvent",{event:t.event,request:t}),t.reply(200);break;default:t.reply(405);break}}_findSession({call_id:t,from_tag:n,to_tag:a}){const o=t+n,s=this._sessions[o],r=t+a,d=this._sessions[r];return s||d||null}_findDialog(t,n,a){let o=t+n+a,s=this._dialogs[o];return s||(o=t+a+n,s=this._dialogs[o],s||null)}_loadConfig(t){try{tu.load(this._configuration,t)}catch(o){throw o}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=aa.newUUID()),this._configuration.jssip_id=aa.createRandomToken(5);const n=this._configuration.uri.clone();n.user=null,this._configuration.hostport_params=n.toString().replace(/^sip:/i,"");try{this._transport=new vT(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=CT.bind(this),this._transport.onconnect=RT.bind(this),this._transport.ondisconnect=IT.bind(this),this._transport.ondata=bT.bind(this)}catch(o){throw qe.warn(o),new ET.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){const o=this._configuration.uri.clone();o.user=null,o.clearParams(),o.clearHeaders(),this._configuration.registrar_server=o}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new ST("sip",aa.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(o={}){const s=o.anonymous||null,r=o.outbound||null;let d="<";return s?d+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":d+=this.pub_gruu||this.uri.toString(),r&&(s?!this.temp_gruu:!this.pub_gruu)&&(d+=";ob"),d+=">",d}};const a=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const o in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,o)&&(a.indexOf(o)!==-1?Object.defineProperty(this._configuration,o,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,o,{writable:!1,configurable:!1}));qe.debug("configuration parameters after validation:");for(const o in this._configuration)if(Object.prototype.hasOwnProperty.call(tu.settings,o))switch(o){case"uri":case"registrar_server":qe.debug(`- ${o}: ${this._configuration[o]}`);break;case"password":case"ha1":case"authorization_jwt":qe.debug(`- ${o}: NOT SHOWN`);break;default:qe.debug(`- ${o}: ${JSON.stringify(this._configuration[o])}`)}}};function CT(c){this.emit("connecting",c)}function RT(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 IT(c){const t=["nict","ict","nist","ist"];for(const n of t)for(const a in this._transactions[n])Object.prototype.hasOwnProperty.call(this._transactions[n],a)&&this._transactions[n][a].onTransportError();this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==vt.STATUS_USER_CLOSED&&(this._status=vt.STATUS_NOT_READY,this._error=vt.NETWORK_ERROR)}function bT(c){const t=c.transport;let n=c.message;if(n=yT.parseMessage(n,this),!!n&&!(this._status===vt.STATUS_USER_CLOSED&&n instanceof eu.IncomingRequest)&&AT(n,this,t)){if(n instanceof eu.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof eu.IncomingResponse){let a;switch(n.method){case mt.INVITE:a=this._transactions.ict[n.via_branch],a&&a.receiveResponse(n);break;case mt.ACK:break;default:a=this._transactions.nict[n.via_branch],a&&a.receiveResponse(n);break}}}}const wT=ze(bh);var _t=[];for(var su=0;su<256;++su)_t.push((su+256).toString(16).slice(1));function OT(c,t=0){return(_t[c[t+0]]+_t[c[t+1]]+_t[c[t+2]]+_t[c[t+3]]+"-"+_t[c[t+4]]+_t[c[t+5]]+"-"+_t[c[t+6]]+_t[c[t+7]]+"-"+_t[c[t+8]]+_t[c[t+9]]+"-"+_t[c[t+10]]+_t[c[t+11]]+_t[c[t+12]]+_t[c[t+13]]+_t[c[t+14]]+_t[c[t+15]]).toLowerCase()}var oa,DT=new Uint8Array(16);function NT(){if(!oa&&(oa=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!oa))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return oa(DT)}var UT=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Of={randomUUID:UT};function Df(c,t,n){if(Of.randomUUID&&!t&&!c)return Of.randomUUID();c=c||{};var a=c.random||(c.rng||NT)();if(a[6]=a[6]&15|64,a[8]=a[8]&63|128,t){n=n||0;for(var o=0;o<16;++o)t[n+o]=a[o];return t}return OT(a)}var ke=At();const Ts=ze(ke),nu=new Wa("Dialog"),Fs={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};class ua{static get C(){return Fs}constructor(t,n,a,o=Fs.STATUS_CONFIRMED){if(this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,n instanceof yt.IncomingResponse&&(o=n.status_code<200?Fs.STATUS_EARLY:Fs.STATUS_CONFIRMED),a==="UAS"){this._id={call_id:n.call_id,local_tag:n.to_tag,remote_tag:n.from_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri;let s=n.getHeaders("to")[0].split(";")[0];s=s.match(/<([^>]*)>/)[1],this._remote_target=s,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum}else if(a==="UAC"){this._id={call_id:n.call_id,local_tag:n.from_tag,remote_tag:n.to_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri;let s=n.getHeaders("to")[0].split(";")[0];s=s.match(/<([^>]*)>/)[1],this._remote_target=s,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null}this._ua.newDialog(this),nu.debug(`new ${a} dialog created with status ${this._state===Fs.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(t){this._local_seqnum=t}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(t){this._uac_pending_reply=t}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===Fs.STATUS_TERMINATED}update(t,n){this._state=Fs.STATUS_CONFIRMED,nu.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),n==="UAC"&&(this._route_set=t.getHeaders("record-route").reverse())}terminate(){nu.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Fs.STATUS_TERMINATED}sendRequest(t,n={}){const a=Ts.cloneArray(n.extraHeaders),o=Ts.cloneObject(n.eventHandlers),s=n.body||null,r=this._createRequest(t,a,s);return o.onAuthenticated=()=>{this._local_seqnum+=1},new hg(this,r,o).send(),r}receiveRequest(t){this._checkInDialogRequest(t)&&(t.method===L.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:t.method===L.INVITE&&(this._ack_seqnum=t.cseq),this._owner.receiveRequest(t))}_createRequest(t,n,a){n=Ts.cloneArray(n),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const o=t===L.CANCEL||t===L.ACK?this._local_seqnum:this._local_seqnum+=1;return new yt.OutgoingRequest(t,this._remote_target,this._ua,{cseq:o,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},n,a)}_checkInDialogRequest(t){if(!this._remote_seqnum)this._remote_seqnum=t.cseq;else if(t.cseq<this._remote_seqnum)if(t.method===L.ACK){if(this._ack_seqnum===null||t.cseq!==this._ack_seqnum)return!1}else return t.reply(500),!1;else t.cseq>this._remote_seqnum&&(this._remote_seqnum=t.cseq);if(t.method===L.INVITE||t.method===L.UPDATE&&t.body){if(this._uac_pending_reply===!0)t.reply(491);else if(this._uas_pending_reply===!0){const n=(Math.random()*10|0)+1;return t.reply(500,null,[`Retry-After:${n}`]),!1}else{this._uas_pending_reply=!0;const n=()=>{(t.server_transaction.state===Gt.C.STATUS_ACCEPTED||t.server_transaction.state===Gt.C.STATUS_COMPLETED||t.server_transaction.state===Gt.C.STATUS_TERMINATED)&&(t.server_transaction.removeListener("stateChanged",n),this._uas_pending_reply=!1)};t.server_transaction.on("stateChanged",n)}t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===Gt.C.STATUS_ACCEPTED&&(this._remote_target=t.parseHeader("contact").uri)})}else t.method===L.NOTIFY&&t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===Gt.C.STATUS_COMPLETED&&(this._remote_target=t.parseHeader("contact").uri)});return!0}}class PT{constructor(t,n){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=t,this.plugin=n,this.rtcpPeer=new RTCPeerConnection({iceServers:[]})}get memberInfo(){return{stream:this.stream,joinResult:this.joinResult,sender:this.handleId,type:"subscriber",name:this.info.display,state:this.state,id:this.handleId}}updateMemberState(t){var n;this.state={...this.state,...t||{}},(n=this.plugin)==null||n.session.emit("member:update",this.memberInfo)}updateMemberStateFromMessage(t){var s,r,d,h;const n=(r=(s=t==null?void 0:t.plugindata)==null?void 0:s.data)==null?void 0:r.newStatePublisher,o=((h=(d=t==null?void 0:t.plugindata)==null?void 0:d.data)==null?void 0:h.publisher_state).find(_=>_.id===n);this.updateMemberState(o==null?void 0:o.state)}hangup(){this.rtcpPeer&&(this.rtcpPeer.close(),this.rtcpPeer=null),this.stream&&this.stream.getTracks().forEach(t=>{t.stop()})}}class Qt{static canGetMediaDevices(){return!(!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices)}static async getDevices(t){return Qt.canGetMediaDevices()?(await navigator.mediaDevices.enumerateDevices()).filter(a=>a.kind===t):[]}static async getMicrophoneList(){return(await Qt.getDevices("audioinput")).map((n,a)=>({...n,deviceId:n.deviceId,label:n.label||`microphone ${a+1}`,kind:n.kind,groupId:n.groupId}))}static async getSpeakerList(){return(await Qt.getDevices("audiooutput")).map((n,a)=>({...n,deviceId:n.deviceId,label:n.label||`speaker ${a+1}`,kind:n.kind,groupId:n.groupId}))}static async getCameraList(){return(await Qt.getDevices("videoinput")).map((n,a)=>({...n,deviceId:n.deviceId,label:n.label||`camera ${a+1}`,kind:n.kind,groupId:n.groupId}))}static stopStreamTracks(t){t&&t.getTracks().forEach(n=>{n.stop()})}static async getMediaFromInputs({videoInput:t,audioInput:n}){let a,o;t==="default"?a=!0:t&&t!=="default"&&(a={deviceId:{exact:t}}),n==="default"?o=!0:n&&n!=="default"&&(o={deviceId:{exact:n}});const s={audio:o,video:a};return Qt.getUserMedia(s)}static async getUserMedia(t){return await navigator.mediaDevices.getUserMedia(t)}static async changeAudioOutput(t,n){if(!(!t||!n))if(typeof t.sinkId<"u")try{await t.setSinkId(n)}catch(a){let o=a;a.name==="SecurityError"&&(o=`You need to use HTTPS for selecting audio output device: ${a}`),console.error(o)}else console.warn("Browser does not support output device selection.")}static toggleAudioMute(t){const n=t.getAudioTracks();if(n.length!==0)return n.forEach(a=>{a.enabled=!a.enabled}),n[0].enabled}static toggleVideoMute(t){const n=t.getVideoTracks();if(n.length!==0)return n.forEach(a=>{a.enabled=!a.enabled}),n[0].enabled}static async getStream(t={video:!0,audio:!0}){try{const n=await navigator.mediaDevices.getUserMedia(t);let a=n.getTracks();return t.video?a=n.getVideoTracks():t.audio&&(a=n.getAudioTracks()),a.length===0?{stream:n,track:null}:{stream:n,track:a[0]}}catch(n){return console.warn(n),{stream:null,track:null}}}}var xT=ys();const In=ze(xT),Pt={LEAVE:"Leave",DETACH:"Detach",AUDIO_CHANGE:"AudioChange",VIDEO_CHANGE:"VideoChange",STATE:"State",ICE:"Ice",CONFIGURE:"Configure",TRICKLE:"Trickle",SUBSCRIBER:"Subscriber",PUBLISHER:"Publisher"},z=new Wa("JanusSession"),kT="/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},ca=["audio","video"];class Ha extends ft.EventEmitter{static get C(){return te}constructor(t){z.debug("new"),super(),this._id=null,this._ua=t,this._status=te.STATUS_NULL,this._dialog=null,this._earlyDialogs={},this._contact=null,this._from_tag=null,this._to_tag=null,this.lastTransaction=0,this._connection=null,this._connectionPromiseQueue=Promise.resolve(),this._request=null,this._is_canceled=!1,this._cancel_reason="",this._is_confirmed=!1,this._late_sdp=!1,this._rtcOfferConstraints=null,this._rtcAnswerConstraints=null,this._localMediaStream=null,this._localMediaStreamLocallyGenerated=!1,this._rtcReady=!0,this._iceReady=!1,this._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},this._direction=null,this._local_identity=null,this._remote_identity=null,this._start_time=null,this._end_time=null,this._audioMuted=!1,this._videoMuted=!1,this._localHold=!1,this._remoteHold=!1,this._sessionTimers={enabled:this._ua.configuration.session_timers,refreshMethod:this._ua.configuration.session_timers_refresh_method,defaultExpires:L.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._referSubscribers={},this._candidates=[],this.publishers=[],this.private_id=null,this.memberList={},this.myFeedList=[],this.display_name="",this.stunServers=[{urls:"stun:turn.voicenter.co",credential:"kxsjahnsdjns3eds23esd",username:"turn2es21e"}],this.opaque_id=this.generateOpaqueId(),this.screen_share_opaque_id=this.generateOpaqueId(),this._data={},this.isAudioOn=!0,this.isVideoOn=!0,this.mediaConstraints={}}get C(){return te}get causes(){return L.causes}get id(){return this._id}get connection(){return this._connection}get contact(){return this._contact}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}get start_time(){return this._start_time}get end_time(){return this._end_time}get data(){return this._data}set data(t){this._data=t}get status(){return this._status}isInProgress(){switch(this._status){case te.STATUS_NULL:case te.STATUS_INVITE_SENT:case te.STATUS_1XX_RECEIVED:case te.STATUS_INVITE_RECEIVED:case te.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case te.STATUS_ANSWERED:case te.STATUS_WAITING_FOR_ACK:case te.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case te.STATUS_CANCELED:case te.STATUS_TERMINATED:return!0;default:return!1}}isMuted(){return{audio:this._audioMuted,video:this._videoMuted}}isOnHold(){return{local:this._localHold,remote:this._remoteHold}}getPTypeHeader(t){return`PTYPE: ${t}`}generateOpaqueId(){return`videoroomtest-${Df().replace(/-/g,"").slice(0,12)}`}connect(t,n,a={},o){z.debug("connect()"),this.display_name=n;const s=t,r=ke.cloneObject(a.eventHandlers),d=ke.cloneArray(a.extraHeaders),h=ke.cloneObject(a.mediaConstraints,{audio:!0,video:!0});this.mediaConstraints={...h};const _=a.mediaStream||null,g=ke.cloneObject(a.pcConfig,{iceServers:[]}),T=a.rtcConstraints||null,E=a.rtcOfferConstraints||null;if(this._rtcOfferConstraints=E,this._rtcAnswerConstraints=a.rtcAnswerConstraints||null,this._data=a.data||this._data,t===void 0)throw new TypeError("Not enough arguments");if(this._status!==te.STATUS_NULL)throw new qs.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new qs.NotSupportedError("WebRTC not supported");if(t=this._ua.normalizeTarget(t),this.room_id=t.user,this.target=t,!t)throw new TypeError(`Invalid target: ${s}`);this._sessionTimers.enabled&&ke.isDecimal(a.sessionTimersExpires)&&(a.sessionTimersExpires>=L.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=a.sessionTimersExpires:this._sessionTimers.defaultExpires=L.SESSION_EXPIRES);for(const C in r)Object.prototype.hasOwnProperty.call(r,C)&&this.on(C,r[C]);this._from_tag=ke.newTag();const y=a.anonymous||!1,A={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:y,outbound:!0}),y?(A.from_display_name="Anonymous",A.from_uri=new In("sip","anonymous","anonymous.invalid"),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),d.push("Privacy: id")):a.fromUserName&&(A.from_uri=new In("sip",a.fromUserName,this._ua.configuration.uri.host),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),a.fromDisplayName&&(A.from_display_name=a.fromDisplayName),d.push(`Contact: ${this._contact}`),d.push("Content-Type: application/json"),this._sessionTimers.enabled&&d.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new yt.InitialOutgoingInviteRequest(t,this._ua,A,d),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(g,T),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,o&&o(this),this._newJanusSession("local",this._request),this._sendInitialRequest(h,E,_)}_overrideSenderTracks(t,n){t.getTracks().forEach(a=>{n.getSenders().forEach(async s=>{s.track.kind===a.kind&&(a.kind==="audio"&&!this.isAudioOn&&(a.enabled=!1),a.kind==="video"&&!this.isVideoOn&&(a.enabled=!1),await s.replaceTrack(a))})})}init_incoming(t,n){z.debug("init_incoming()");let a;const o=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;if(t.body&&o!=="application/sdp"){t.reply(415);return}if(this._status=te.STATUS_INVITE_RECEIVED,this._from_tag=t.from_tag,this._id=t.call_id+this._from_tag,this._request=t,this._contact=this._ua.contact.toString(),t.hasHeader("expires")&&(a=t.getHeader("expires")*1e3),t.to_tag=ke.newTag(),!this._createDialog(t,"UAS",!0)){t.reply(500,"Missing Contact header field");return}t.body?this._late_sdp=!1:this._late_sdp=!0,this._status=te.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{t.reply(408),this._failed("local",null,L.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),a&&(this._timers.expiresTimer=setTimeout(()=>{this._status===te.STATUS_WAITING_FOR_ANSWER&&(t.reply(487),this._failed("system",null,L.causes.EXPIRES))},a)),this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from,n&&n(this),this._newJanusSession("remote",t),this._status!==te.STATUS_TERMINATED&&(t.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(t={}){z.debug("answer()");const n=this._request,a=ke.cloneArray(t.extraHeaders),o=ke.cloneObject(t.mediaConstraints),s=t.mediaStream||null,r=ke.cloneObject(t.pcConfig,{iceServers:[]}),d=t.rtcConstraints||null,h=t.rtcAnswerConstraints||null,_=ke.cloneObject(t.rtcOfferConstraints);let g,T=!1,E=!1,y=!1,A=!1;if(this._rtcAnswerConstraints=h,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,this._direction!=="incoming")throw new qs.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==te.STATUS_WAITING_FOR_ANSWER)throw new qs.InvalidStateError(this._status);if(this._sessionTimers.enabled&&ke.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=L.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=L.SESSION_EXPIRES),this._status=te.STATUS_ANSWERED,!this._createDialog(n,"UAS")){n.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),a.unshift(`Contact: ${this._contact}`);const C=n.parseSDP();Array.isArray(C.media)||(C.media=[C.media]);for(const I of C.media)I.type==="audio"&&(T=!0,(!I.direction||I.direction==="sendrecv")&&(y=!0)),I.type==="video"&&(E=!0,(!I.direction||I.direction==="sendrecv")&&(A=!0));if(s&&o.audio===!1){g=s.getAudioTracks();for(const I of g)s.removeTrack(I)}if(s&&o.video===!1){g=s.getVideoTracks();for(const I of g)s.removeTrack(I)}!s&&o.audio===void 0&&(o.audio=y),!s&&o.video===void 0&&(o.video=A),!s&&!T&&!_.offerToReceiveAudio&&(o.audio=!1),!s&&!E&&!_.offerToReceiveVideo&&(o.video=!1),this._createRTCConnection(r,d),Promise.resolve().then(()=>{if(s)return s;if(o.audio||o.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(I=>{throw this._status===te.STATUS_TERMINATED?new Error("terminated"):(n.reply(480),this._failed("local",null,L.causes.USER_DENIED_MEDIA_ACCESS),z.warn('emit "getusermediafailed" [error:%o]',I),this.emit("getusermediafailed",I),new Error("getUserMedia() failed"))})}).then(I=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=I,I&&I.getTracks().forEach(H=>{this._connection.addTrack(H,I)})}).then(()=>{if(this._late_sdp)return;const I={originator:"remote",type:"offer",sdp:n.body};z.debug('emit "sdp"'),this.emit("sdp",I);const H=new RTCSessionDescription({type:"offer",sdp:I.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(H)).catch($=>{throw n.reply(488),this._failed("system",null,L.causes.WEBRTC_ERROR),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',$),this.emit("peerconnection:setremotedescriptionfailed",$),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(n),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",h).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(I=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,a),n.reply(200,null,a,I,()=>{this._status=te.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,I),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,L.causes.CONNECTION_ERROR)})}).catch(I=>{this._status!==te.STATUS_TERMINATED&&z.warn(I)})}terminate(t={}){z.debug("terminate()");const n=t.cause||L.causes.BYE,a=ke.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,d=t.reason_phrase;if(this._status===te.STATUS_TERMINATED)throw new qs.InvalidStateError(this._status);switch(this._status){case te.STATUS_NULL:case te.STATUS_INVITE_SENT:case te.STATUS_1XX_RECEIVED:if(z.debug("canceling session"),r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);r&&(d=d||L.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${d}"`),this._status===te.STATUS_NULL||this._status===te.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===te.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=te.STATUS_CANCELED,this._failed("local",null,L.causes.CANCELED);break;case te.STATUS_WAITING_FOR_ANSWER:case te.STATUS_ANSWERED:if(z.debug("rejecting session"),r=r||480,r<300||r>=700)throw new TypeError(`Invalid status_code: ${r}`);this._request.reply(r,d,a,o),this._failed("local",null,L.causes.REJECTED);break;case te.STATUS_WAITING_FOR_ACK:case te.STATUS_CONFIRMED:if(z.debug("terminating session"),d=t.reason_phrase||L.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);if(r&&a.push(`Reason: SIP ;cause=${r}; text="${d}"`),this._status===te.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Gt.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:_})=>{_===L.ACK&&(this.sendRequest(L.BYE,{extraHeaders:a,body:o}),h.terminate(),this.closeSession())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Gt.C.STATUS_TERMINATED&&(this.sendRequest(L.BYE,{extraHeaders:a,body:o}),h.terminate(),this.closeSession())}),this._ended("local",null,n),this._dialog=h,this._ua.newDialog(h)}else{const h={janus:"leave"},_=["Content-Type: application/json",this.getPTypeHeader(Pt.LEAVE)];this.sendRequest(L.BYE,{extraHeaders:_,body:JSON.stringify(h)}),this.closeSession(),this._ended("local",null,n)}}}configureMedia(t){this.isAudioOn=t.audio,this.isVideoOn=t.video}enableAudio(t){const n={janus:"message",body:{audio:t},handle_id:this.handle_id,session_id:this.session_id},a=["Content-Type: application/json",this.getPTypeHeader(Pt.AUDIO_CHANGE)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{o.status_code===200&&(this._ua.emit("changeAudioState",t),this.sendStateMessage({audio:t}))}}})}startAudio(){Qt.toggleAudioMute(this.stream),this._toggleMuteAudio(!1),this.enableAudio(!0),this.isAudioOn=!0}stopAudio(){Qt.toggleAudioMute(this.stream),this._toggleMuteAudio(!0),this.enableAudio(!1),this.isAudioOn=!1}enableVideo(t){const n={janus:"message",body:{video:t},handle_id:this.handle_id,session_id:this.session_id},a=["Content-Type: application/json",this.getPTypeHeader(Pt.VIDEO_CHANGE)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{o.status_code===200&&(this._ua.emit("changeVideoState",t),this.sendStateMessage({video:t}))}}})}startVideo(){Qt.toggleVideoMute(this.stream),this._toggleMuteVideo(!1),this.enableVideo(!0),this.isVideoOn=!0}stopVideo(){Qt.toggleVideoMute(this.stream),this._toggleMuteVideo(!0),this.enableVideo(!1),this.isVideoOn=!1}sendStateMessage(t){const n={janus:"message",body:{request:"state",data:t},handle_id:this.handle_id,session_id:this.session_id},a=["Content-Type: application/json",this.getPTypeHeader(Pt.STATE)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n)})}sendInfo(t,n,a={}){if(z.debug("sendInfo()"),this._status!==te.STATUS_CONFIRMED&&this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_1XX_RECEIVED)throw new qs.InvalidStateError(this._status);new yu(this).send(t,n,a)}mute(t={audio:!0,video:!1}){z.debug("mute()");let n=!1,a=!1;this._audioMuted===!1&&t.audio&&(n=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&t.video&&(a=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(n===!0||a===!0)&&this._onmute({audio:n,video:a})}unmute(t={audio:!0,video:!0}){z.debug("unmute()");let n=!1,a=!1;this._audioMuted===!0&&t.audio&&(n=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&t.video&&(a=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(n===!0||a===!0)&&this._onunmute({audio:n,video:a})}hold(t={},n){if(z.debug("hold()"),this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:L.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}unhold(t={},n){if(z.debug("unhold()"),this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:L.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}renegotiate(t={},n){z.debug("renegotiate()");const a=t.rtcOfferConstraints||null;if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const o={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:L.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}),!0}refer(t,n){z.debug("refer()");const a=t;if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${a}`);const o=new Ng(this);o.sendRefer(t,n);const s=o.id;return this._referSubscribers[s]=o,o.on("requestFailed",()=>{delete this._referSubscribers[s]}),o.on("accepted",()=>{delete this._referSubscribers[s]}),o.on("failed",()=>{delete this._referSubscribers[s]}),o}sendRequest(t,n){return z.debug("sendRequest()"),this._dialog.sendRequest(t,n)}receiveNotify(t){z.debug("receiveRequest()")}receiveRequest(t){if(z.debug("receiveRequest()"),t.method===L.CANCEL)(this._status===te.STATUS_WAITING_FOR_ANSWER||this._status===te.STATUS_ANSWERED)&&(this._status=te.STATUS_CANCELED,this._request.reply(487),this._failed("remote",t,L.causes.CANCELED));else switch(t.method){case L.ACK:if(this._status!==te.STATUS_WAITING_FOR_ACK)return;if(this._status=te.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!t.body){this.terminate({cause:L.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:t.body};z.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>{this._is_confirmed||this._confirmed("remote",t)}).catch(o=>{this.terminate({cause:L.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})}else this._is_confirmed||this._confirmed("remote",t);break;case L.BYE:this._status===te.STATUS_CONFIRMED||this._status===te.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,L.causes.BYE)):this._status===te.STATUS_INVITE_RECEIVED||this._status===te.STATUS_WAITING_FOR_ANSWER?(t.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",t,L.causes.BYE)):t.reply(403,"Wrong Status");break;case L.INVITE:this._status===te.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case L.INFO:if(this._status===te.STATUS_1XX_RECEIVED||this._status===te.STATUS_WAITING_FOR_ANSWER||this._status===te.STATUS_ANSWERED||this._status===te.STATUS_WAITING_FOR_ACK||this._status===te.STATUS_CONFIRMED){const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;n&&n.match(/^application\/dtmf-relay/i)?new Eg(this).init_incoming(t):n!==void 0?new yu(this).init_incoming(t):t.reply(415)}else t.reply(403,"Wrong Status");break;case L.UPDATE:this._status===te.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case L.REFER:this._status===te.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case L.NOTIFY:this._status===te.STATUS_CONFIRMED?this._receiveNotify(t):t.reply(403,"Wrong Status");break;default:t.reply(501)}}onTransportError(){z.warn("onTransportError()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.CONNECTION_ERROR,cause:L.causes.CONNECTION_ERROR})}onRequestTimeout(){z.warn("onRequestTimeout()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:L.causes.REQUEST_TIMEOUT,cause:L.causes.REQUEST_TIMEOUT})}onDialogError(){z.warn("onDialogError()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.DIALOG_ERROR,cause:L.causes.DIALOG_ERROR})}newDTMF(t){z.debug("newDTMF()"),this.emit("newDTMF",t)}newInfo(t){z.debug("newInfo()"),this.emit("newInfo",t)}_isReadyToReOffer(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(z.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(z.debug("_isReadyToReOffer() | session not established yet"),!1):(z.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}_close(){if(z.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(z.debug("close() | closing local MediaStream"),ke.closeMediaStream(this._localMediaStream)),this._status!==te.STATUS_TERMINATED){if(this._status=te.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(t){z.warn("close() | error closing the RTCPeerConnection: %o",t)}for(const t in this._timers)Object.prototype.hasOwnProperty.call(this._timers,t)&&clearTimeout(this._timers[t]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const t in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(const t in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,t)&&delete this._referSubscribers[t];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(t,n){let a=$i.T1;function o(){this._status===te.STATUS_WAITING_FOR_ACK&&(t.reply(200,null,[`Contact: ${this._contact}`],n),a<$i.T2&&(a=a*2,a>$i.T2&&(a=$i.T2)),this._timers.invite2xxTimer=setTimeout(o.bind(this),a))}this._timers.invite2xxTimer=setTimeout(o.bind(this),a)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===te.STATUS_WAITING_FOR_ACK&&(z.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(L.BYE),this._ended("remote",null,L.causes.NO_ACK))},$i.TIMER_H)}_createRTCConnection(t,n){this.stunServers,this._connection=new RTCPeerConnection(t,n),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:L.causes.RTP_TIMEOUT,status_code:408,reason_phrase:L.causes.RTP_TIMEOUT})});let a;const o=s=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||s.candidate&&(this._candidates.push(s.candidate),clearTimeout(a),a=setTimeout(()=>{this.lastTrickleReceived=!0,this.subscribeSent&&!this.isConfigureSent&&(this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream}),this._sendConfigureMessage({audio:!0,video:!0}).then(()=>{}))},500))};this._connection.onicecandidate=o,z.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(t,n){if(z.debug("createLocalDescription()"),t!=="offer"&&t!=="answer")throw new Error(`createLocalDescription() | invalid type "${t}"`);const a=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>t==="offer"?a.createOffer(n).catch(o=>(z.warn('emit "peerconnection:createofferfailed" [error:%o]',o),this.emit("peerconnection:createofferfailed",o),Promise.reject(o))):a.createAnswer(n).catch(o=>(z.warn('emit "peerconnection:createanswerfailed" [error:%o]',o),this.emit("peerconnection:createanswerfailed",o),Promise.reject(o)))).then(o=>(this.jsepOffer=o,a.setLocalDescription(o).catch(s=>(this._rtcReady=!0,z.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',s),this.emit("peerconnection:setlocaldescriptionfailed",s),Promise.reject(s))))).then(()=>{const o=n&&n.iceRestart;if(a.iceGatheringState==="complete"&&!o||a.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const s={originator:"local",type:t,sdp:a.localDescription.sdp};return z.debug('emit "sdp"'),this.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(s=>{let r=!1,d,h;this._iceReady=!1;const _=()=>{a.removeEventListener("icecandidate",d),a.removeEventListener("icegatheringstatechange",h),r=!0,this._rtcReady=!0,this._iceReady=!0;const g={originator:"local",type:t,sdp:a.localDescription.sdp};z.debug('emit "sdp"'),this.emit("sdp",g),s(g.sdp)};a.addEventListener("icecandidate",d=g=>{const T=g.candidate;T?this.emit("icecandidate",{candidate:T,ready:_}):r||_()}),a.addEventListener("icegatheringstatechange",h=()=>{a.iceGatheringState==="complete"&&!r&&_()})})})}_createDialog(t,n,a){const o=n==="UAS"?t.to_tag:t.from_tag,s=n==="UAS"?t.from_tag:t.to_tag,r=t.call_id+o+s;let d=this._earlyDialogs[r];if(a)return d?!0:(d=new ua(this,t,n,ua.C.STATUS_EARLY),d.error?(z.debug(d.error),this._failed("remote",t,L.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=d,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,d)return d.update(t,n),this._dialog=d,delete this._earlyDialogs[r],!0;const h=new ua(this,t,n);return h.error?(z.debug(h.error),this._failed("remote",t,L.causes.INTERNAL_ERROR),!1):(this._dialog=h,!0)}}_receiveReinvite(t){z.debug("receiveReinvite()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=ke.cloneArray(d.extraHeaders);if(this._status!==te.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("reinvite",a),o)return;if(this._late_sdp=!1,!t.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(d=>{r.call(this,d)}).catch(()=>{t.reply(500)});return}if(n!=="application/sdp"){z.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==te.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{z.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),this._late_sdp&&(d=this._mangleOffer(d)),t.reply(200,null,h,d,()=>{this._status=te.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(t,d),this._setACKTimer()}),typeof a.callback=="function"&&a.callback()}}_receiveUpdate(t){z.debug("receiveUpdate()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=ke.cloneArray(d.extraHeaders);if(this._status!==te.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("update",a),o)return;if(!t.body){r.call(this,null);return}if(n!=="application/sdp"){z.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==te.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{z.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),t.reply(200,null,h,d),typeof a.callback=="function"&&a.callback()}}_processInDialogSdpOffer(t){z.debug("_processInDialogSdpOffer()");const n=t.parseSDP();let a=!1;for(const r of n.media){if(ca.indexOf(r.type)===-1)continue;const d=r.direction||n.direction||"sendrecv";if(d==="sendonly"||d==="inactive")a=!0;else{a=!1;break}}const o={originator:"remote",type:"offer",sdp:t.body};z.debug('emit "sdp"'),this.emit("sdp",o);const s=new RTCSessionDescription({type:"offer",sdp:o.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(s).catch(r=>{throw t.reply(488),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',r),this.emit("peerconnection:setremotedescriptionfailed",r),r})}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&a===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&a===!0&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(r=>{throw t.reply(500),z.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',r),r})}).catch(r=>{z.warn("_processInDialogSdpOffer() failed [error: %o]",r)}),this._connectionPromiseQueue}_receiveRefer(t){if(z.debug("receiveRefer()"),!t.refer_to){z.debug("no Refer-To header field present in REFER"),t.reply(400);return}if(t.refer_to.uri.scheme!==L.SIP){z.debug("Refer-To header field points to a non-SIP URI scheme"),t.reply(416);return}t.reply(202);const n=new bg(this,t.cseq);z.debug('emit "refer"'),this.emit("refer",{request:t,accept:(s,r)=>{a.call(this,s,r)},reject:()=>{o.call(this)}});function a(s,r={}){if(s=typeof s=="function"?s:null,this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;const d=new Ha(this._ua);if(d.on("progress",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("accepted",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("_failed",({message:h,cause:_})=>{h?n.notify(h.status_code,h.reason_phrase):n.notify(487,_)}),t.refer_to.uri.hasHeader("replaces")){const h=decodeURIComponent(t.refer_to.uri.getHeader("replaces"));r.extraHeaders=ke.cloneArray(r.extraHeaders),r.extraHeaders.push(`Replaces: ${h}`)}d.connect(t.refer_to.uri.toAor(),r,s)}function o(){n.notify(603)}}_receiveNotify(t){switch(z.debug("receiveNotify()"),t.event||t.reply(400),t.event.event){case"refer":{let n,a;if(t.event.params&&t.event.params.id)n=t.event.params.id,a=this._referSubscribers[n];else if(Object.keys(this._referSubscribers).length===1)a=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{t.reply(400,"Missing event id parameter");return}if(!a){t.reply(481,"Subscription does not exist");return}a.receiveNotify(t),t.reply(200);break}default:t.reply(489)}}_receiveReplaces(t){z.debug("receiveReplaces()");function n(o){if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;const s=new Ha(this._ua);s.on("confirmed",()=>{this.terminate()}),s.init_incoming(t,o)}function a(){z.debug("Replaced INVITE rejected by the user"),t.reply(486)}this.emit("replaces",{request:t,accept:o=>{n.call(this,o)},reject:()=>{a.call(this)}})}_getNextTransactionId(){return(this.lastTransaction+1).toString()}_sendInitialRequest(t,n,a){this.ackSent=!1,this.publisherSubscribeSent=!1;const o=new sl(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});Promise.resolve().then(()=>{if(a)return a;if(t.audio||t.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(s=>{throw this._status===te.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,L.causes.USER_DENIED_MEDIA_ACCESS),z.warn('emit "getusermediafailed" [error:%o]',s),this.emit("getusermediafailed",s),s)})}).then(s=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=s,s&&s.getTracks().forEach(r=>{this._connection.addTrack(r,s)}),this._connecting(this._request),this._createLocalDescription("offer",n).catch(r=>{throw this._failed("local",null,L.causes.WEBRTC_ERROR),r})}).then(s=>{if(this._is_canceled||this._status===te.STATUS_TERMINATED)throw new Error("terminated");const r={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaque_id},d=JSON.stringify(r);this._request.body=d,this._status=te.STATUS_INVITE_SENT,z.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),o.send()}).catch(s=>{this._status!==te.STATUS_TERMINATED&&z.warn(s)})}async requestAudioAndVideoPermissions(){this.stream=await this.loadStream()}async setupMediaStream(){await this.requestAudioAndVideoPermissions(),await this.processPlugins()}async changeMediaConstraints(t){this.mediaConstraints={...t},await this.processPlugins(),this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream})}async loadStream(){const t={};this.isAudioOn?this.mediaConstraints.audio?t.audio=this.mediaConstraints.audio:t.audio=!0:t.audio=!1,this.isVideoOn?this.mediaConstraints.video?t.video=this.mediaConstraints.video:t.video=!0:t.video=!1;let n=null;try{n=await navigator.mediaDevices.getUserMedia(t)}catch{try{t.video=!1,n=await navigator.mediaDevices.getUserMedia(t)}catch{t.audio=!1,t.video=!1,n=await navigator.mediaDevices.getUserMedia(t)}}return n}addTracks(t){this._connection.getSenders().forEach(n=>{this._connection.removeTrack(n)}),t.forEach(n=>{this._connection.addTrack(n)})}getRecordFileName(){return kT+this.room_id+btoa(unescape(encodeURIComponent(this.displayName)))+Date.now()}async processIceCandidates(){for(let t=0;t<this.iceCandidates.length;t++)await this._connection.addIceCandidate(this.iceCandidates[t]);this.iceCandidates=[]}async _sendConfigureMessage(t){const n=this._candidates.map(r=>({janus:"trickle",candidate:r,handle_id:this.handle_id,session_id:this.session_id})),o={configure:{janus:"message",body:{request:"configure",record:!0,filename:this.getRecordFileName(),...t},jsep:this.jsepOffer,handle_id:this.handle_id,session_id:this.session_id},trickles:[...n]},s=["Content-Type: application/json",this.getPTypeHeader(Pt.ICE)];this.sendRequest(L.INFO,{extraHeaders:s,body:JSON.stringify(o),eventHandlers:{onSuccessResponse:async r=>{this.isConfigureSent=!0;const h=r.data.split(`\r
|
135
|
-
`),_=h[h.length-1],g=JSON.parse(_);await this._connection.setRemoteDescription(g.jsep),this._candidates=[]}}})}_sendMemberStartMessage(t,n){const a={janus:"message",body:{request:"start",room:this.room_id},handle_id:t.handleId,session_id:this.session_id,jsep:n},o=["Content-Type: application/json",this.getPTypeHeader(Pt.CONFIGURE)];this.sendRequest(L.INFO,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{s.status_code===200&&await t.rtcpPeer.setLocalDescription(n)}}})}_sendTrickleMessage(t){const a={trickles:[...t.map(s=>({janus:"trickle",candidate:s,handle_id:this.handle_id,session_id:this.session_id}))]},o=[this.getPTypeHeader(Pt.TRICKLE)];this.sendRequest(L.INFO,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{}}})}async _answerAttachedStream(t,n){let a=null;const o=async h=>{if(!t.rtcpPeer||t.loaded)return;{t.loaded=!0;const y={audio:!0,video:!0};await new Promise(A=>{setTimeout(A,100)}),a=await t.rtcpPeer.createAnswer(y),this._sendMemberStartMessage(t,a)}const _=h.streams[0].getAudioTracks(),g=h.streams[0].getVideoTracks(),T=[];_[0]&&T.push(_[0]),g[0]&&T.push(g[0]);const E=new MediaStream(T);t.stream=E,this._ua.emit("memberJoin",t.memberInfo)};let s,r=[];const d=h=>{t.rtcpPeer.signalingState!=="stable"&&t.rtcpPeer.signalingState!=="have-local-offer"||(r.push(h.candidate||null),clearTimeout(s),s=setTimeout(()=>{this._sendTrickleMessage(r)},500))};t.rtcpPeer=new RTCPeerConnection,t.rtcpPeer.ontrack=o,t.rtcpPeer.onicecandidate=d,t.rtcpPeer.sender=n.sender,await t.rtcpPeer.setRemoteDescription(n.jsep)}_sendJoinMemberRequest(t){const n={janus:"message",body:{request:"join",room:this.room_id,feed:t.info.id,ptype:"subscriber"},handle_id:t.handleId,session_id:this.session_id},a=[this.getPTypeHeader(Pt.SUBSCRIBER)];this.sendRequest(L.SUBSCRIBE,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{var s,r;if(o.status_code===200){const d=JSON.parse(o.body);(r=(s=d==null?void 0:d.plugindata)==null?void 0:s.data)!=null&&r.id&&await this._answerAttachedStream(t,d)}}}})}_attachMember(t){const n={janus:"attach",opaque_id:this.opaque_id,plugin:"janus.plugin.videoroom",session_id:this.session_id},a=[this.getPTypeHeader(Pt.SUBSCRIBER)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{if(o.status_code===200){const r=JSON.parse(o.body).data.id;t.handleId=r,this._sendJoinMemberRequest(t)}}}})}_detachMember(t){const n={janus:"detach",handle_id:t.handleId,session_id:this.session_id},a=[this.getPTypeHeader(Pt.SUBSCRIBER)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n)}),Qt.stopStreamTracks(t.memberInfo.stream),this._ua.emit("memberHangup",t.memberInfo)}receivePublishers(t){var a,o,s,r,d,h,_,g;const n={...this.memberList};(o=(a=t==null?void 0:t.plugindata)==null?void 0:a.data)==null||o.publishers.forEach(T=>{delete n[T.id],!this.memberList[T.id]&&!this.myFeedList.includes(T.id)&&T.clientID!==this.client_id&&(this.memberList[T.id]=new PT(T,this),this._attachMember(this.memberList[T.id]))}),((r=(s=t==null?void 0:t.plugindata)==null?void 0:s.data)==null?void 0:r.videoroom)==="synced"&&Object.keys(n).forEach(T=>{n[T].hangup(),delete this.memberList[T]}),this.publishers=(h=(d=t==null?void 0:t.plugindata)==null?void 0:d.data)==null?void 0:h.publishers,this.private_id=(g=(_=t==null?void 0:t.plugindata)==null?void 0:_.data)==null?void 0:g.private_id}receiveUnpublished(t){const n=this.memberList[t];n&&(n.hangup(),this._detachMember(n),delete this.memberList[t])}closeSession(){this.stream&&this.stream.getTracks().forEach(n=>{n.stop()}),Object.values(this.memberList).forEach(n=>{n.hangup(),this._detachMember(n)}),this._ua.emit("conferenceEnd",this.id)}async processPlugins(){const t=this._ua.processStreamPlugins;let n=await this.loadStream();for(const a of t)n=await a.process(n);this.stream.getTracks().forEach(a=>{this.stream.removeTrack(a),a.stop()}),n.getTracks().forEach(a=>{this.stream.addTrack(a)})}async resyncPlugins(t){const n=this._ua.processStreamPlugins.filter(a=>a.type===t);for(const a of n)a.running&&a.terminate();if(t==="video"){let a=await this.loadStream();for(const o of n)o.running&&(a=await o.start(a));this.stream.getTracks().forEach(o=>{this.stream.removeTrack(o),o.stop()}),a.getTracks().forEach(o=>{this.stream.addTrack(o)}),this._overrideSenderTracks(this.stream,this._connection),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream})}else{const a=this._ua.newStreamPlugins.find(d=>d.type===t);let s=a.getStream().clone();for(const d of n)d.running&&(s=await d.start(s));const r=a.getConnection();this._overrideSenderTracks(s,r),this._ua.emit("changePluginStream",{type:t,stream:s})}}stopProcessPlugins(t){const n=this._ua.processStreamPlugins.filter(a=>a.type===t);for(const a of n)a.running&&a.kill()}_receiveInviteResponse(t){if(z.debug("receiveInviteResponse()"),this._dialog&&t.status_code>=200&&t.status_code<=299&&!this.ackSent)if(this._dialog.id.call_id===t.call_id&&this._dialog.id.local_tag===t.from_tag&&this._dialog.id.remote_tag===t.to_tag){this.ackSent=!0,this.sendRequest(L.ACK);return}else{const n=new ua(this,t,"UAC");if(n.error!==void 0){z.debug(n.error);return}this.sendRequest(L.ACK),this.sendRequest(L.BYE);return}if(this.ackSent&&!this.publisherSubscribeSent){const n=JSON.parse(t.body);this.setupMediaStream().then(()=>{this.session_id=n.session_id,this.handle_id=n.data.id,this.client_id=Df();const a={janus:"message",body:{request:"join",room:this.room_id,ptype:"publisher",display:this.display_name,clientID:this.client_id,opaque_id:this.opaque_id},handle_id:this.handle_id},o=[this.getPTypeHeader(Pt.PUBLISHER)];this.sendRequest(L.SUBSCRIBE,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{var r,d,h,_;if(s.status_code===200){if(this.subscribeSent=!0,s.body)try{const g=JSON.parse(s.body)||{};((d=(r=g.plugindata)==null?void 0:r.data)==null?void 0:d.videoroom)==="joined"&&this.myFeedList.push(g.plugindata.data.id),(_=(h=g.plugindata)==null?void 0:h.data)!=null&&_.publishers&&this.receivePublishers(g)}catch(g){console.error(g)}this.lastTrickleReceived&&!this.isConfigureSent&&(this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream}),this._sendConfigureMessage({audio:!0,video:!0}).then(()=>{})),this._ua.emit("conferenceStart")}}}}),this.publisherSubscribeSent=!0})}if(this._is_canceled){t.status_code>=100&&t.status_code<200?this._request.cancel(this._cancel_reason):t.status_code>=200&&t.status_code<299&&this._acceptAndTerminate(t);return}if(!(this._status!==te.STATUS_INVITE_SENT&&this._status!==te.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(t.status_code):this._status=te.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(t.status_code):{if(!t.to_tag){z.debug("1xx response received without to tag");break}if(t.hasHeader("contact")&&!this._createDialog(t,"UAC",!0))break;if(this._status=te.STATUS_1XX_RECEIVED,!t.body){this._progress("remote",t);break}const n={originator:"remote",type:"answer",sdp:t.body};z.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>this._progress("remote",t)).catch(o=>{z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)});break}case/^2[0-9]{2}$/.test(t.status_code):{if(this._status=te.STATUS_CONFIRMED,!t.body){this._acceptAndTerminate(t,400,L.causes.MISSING_SDP),this._failed("remote",t,L.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(t,"UAC"))break;break}default:{const n=ke.sipErrorCause(t.status_code);this._failed("remote",t,n)}}}_sendReinvite(t={}){z.debug("sendReinvite()");const n=ke.cloneArray(t.extraHeaders),a=ke.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null;let s=!1;n.push(`Contact: ${this._contact}`),n.push("Content-Type: application/sdp"),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(h=>{h=this._mangleOffer(h);const _={originator:"local",type:"offer",sdp:h};z.debug('emit "sdp"'),this.emit("sdp",_),this.sendRequest(L.INVITE,{extraHeaders:n,body:h,eventHandlers:{onSuccessResponse:g=>{r.call(this,g),s=!0},onErrorResponse:g=>{d.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{d()});function r(h){if(this._status===te.STATUS_TERMINATED||(this.sendRequest(L.ACK),s))return;if(this._handleSessionTimersInIncomingResponse(h),h.body){if(!h.hasHeader("Content-Type")||h.getHeader("Content-Type").toLowerCase()!=="application/sdp"){d.call(this);return}}else{d.call(this);return}const _={originator:"remote",type:"answer",sdp:h.body};z.debug('emit "sdp"'),this.emit("sdp",_);const g=new RTCSessionDescription({type:"answer",sdp:_.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(g)).then(()=>{a.succeeded&&a.succeeded(h)}).catch(T=>{d.call(this),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function d(h){a.failed&&a.failed(h)}}_sendUpdate(t={}){z.debug("sendUpdate()");const n=ke.cloneArray(t.extraHeaders),a=ke.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null,s=t.sdpOffer||!1;let r=!1;n.push(`Contact: ${this._contact}`),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),s?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(_=>{_=this._mangleOffer(_);const g={originator:"local",type:"offer",sdp:_};z.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(L.UPDATE,{extraHeaders:n,body:_,eventHandlers:{onSuccessResponse:T=>{d.call(this,T),r=!0},onErrorResponse:T=>{h.call(this,T)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{h.call(this)})):this.sendRequest(L.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:_=>{d.call(this,_)},onErrorResponse:_=>{h.call(this,_)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function d(_){if(this._status!==te.STATUS_TERMINATED&&!r)if(this._handleSessionTimersInIncomingResponse(_),s){if(_.body){if(!_.hasHeader("Content-Type")||_.getHeader("Content-Type").toLowerCase()!=="application/sdp"){h.call(this);return}}else{h.call(this);return}const g={originator:"remote",type:"answer",sdp:_.body};z.debug('emit "sdp"'),this.emit("sdp",g);const T=new RTCSessionDescription({type:"answer",sdp:g.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(T)).then(()=>{a.succeeded&&a.succeeded(_)}).catch(E=>{h.call(this),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),this.emit("peerconnection:setremotedescriptionfailed",E)})}else a.succeeded&&a.succeeded(_)}function h(_){a.failed&&a.failed(_)}}_acceptAndTerminate(t,n,a){z.debug("acceptAndTerminate()");const o=[];n&&(a=a||L.REASON_PHRASE[n]||"",o.push(`Reason: SIP ;cause=${n}; text="${a}"`)),(this._dialog||this._createDialog(t,"UAC"))&&(this.sendRequest(L.ACK),this.sendRequest(L.BYE,{extraHeaders:o})),this._status=te.STATUS_TERMINATED}_mangleOffer(t){if(!this._localHold&&!this._remoteHold)return t;if(t=xt.parse(t),this._localHold&&!this._remoteHold){z.debug("mangleOffer() | me on hold, mangling offer");for(const n of t.media)ca.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="sendonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="sendonly")}else if(this._localHold&&this._remoteHold){z.debug("mangleOffer() | both on hold, mangling offer");for(const n of t.media)ca.indexOf(n.type)!==-1&&(n.direction="inactive")}else if(this._remoteHold){z.debug("mangleOffer() | remote on hold, mangling offer");for(const n of t.media)ca.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="recvonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="recvonly")}return xt.write(t)}_setLocalMediaStatus(){let t=!0,n=!0;(this._localHold||this._remoteHold)&&(t=!1,n=!1),this._audioMuted&&(t=!1),this._videoMuted&&(n=!1),this._toggleMuteAudio(!t),this._toggleMuteVideo(!n)}_handleSessionTimersInIncomingRequest(t,n){if(!this._sessionTimers.enabled)return;let a;t.session_expires&&t.session_expires>=L.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,a=t.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,a="uas"),n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${a}`),this._sessionTimers.refresher=a==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(t){if(!this._sessionTimers.enabled)return;let n;t.session_expires&&t.session_expires>=L.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,n=t.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uac"),this._sessionTimers.refresher=n==="uac",this._runSessionTimer()}_runSessionTimer(){const t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(()=>{this._status!==te.STATUS_TERMINATED&&this._isReadyToReOffer()&&(z.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===L.UPDATE?this._sendUpdate():this._sendReinvite())},t*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==te.STATUS_TERMINATED&&(z.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:L.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},t*1100)}_toggleMuteAudio(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="audio");for(const a of n)a.track.enabled=!t}_toggleMuteVideo(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="video");for(const a of n)a.track.enabled=!t}_newJanusSession(t,n){z.debug("newRTCSession()"),this._ua.newJanusSession(this,{originator:t,session:this,request:n})}_connecting(t){z.debug("session connecting"),z.debug('emit "connecting"'),this.emit("connecting",{request:t})}_progress(t,n){z.debug("session progress"),z.debug('emit "progress"'),this.emit("progress",{originator:t,response:n||null})}_accepted(t,n){z.debug("session accepted"),this._start_time=new Date,z.debug('emit "accepted"'),this.emit("accepted",{originator:t,response:n||null})}_confirmed(t,n){z.debug("session confirmed"),this._is_confirmed=!0,z.debug('emit "confirmed"'),this.emit("confirmed",{originator:t,ack:n||null})}_ended(t,n,a){z.debug("session ended"),this._end_time=new Date,this._close(),z.debug('emit "ended"'),this.emit("ended",{originator:t,message:n||null,cause:a})}_failed(t,n,a){z.debug("session failed"),z.debug('emit "_failed"'),this.emit("_failed",{originator:t,message:n||null,cause:a}),this._close(),z.debug('emit "failed"'),this.emit("failed",{originator:t,message:n||null,cause:a})}_onhold(t){z.debug("session onhold"),this._setLocalMediaStatus(),z.debug('emit "hold"'),this.emit("hold",{originator:t})}_onunhold(t){z.debug("session onunhold"),this._setLocalMediaStatus(),z.debug('emit "unhold"'),this.emit("unhold",{originator:t})}_onmute({audio:t,video:n}){z.debug("session onmute"),this._setLocalMediaStatus(),z.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}_onunmute({audio:t,video:n}){z.debug("session onunmute"),this._setLocalMediaStatus(),z.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}class cr{constructor(t){if(this.headers={},t.length>0){let n=!1;const a=t.split(`\r
|
134
|
+
`,Rh.send(a)}const pT=ze(Ih);var rl={};const hr=Ct(),Cn=De,zo=Zt(),Rf=ys(),Xo=qu,Qo=Cs;rl.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:Cn.UPDATE,session_timers_force_refresher:!1,no_answer_timeout:60,register:!0,register_expires:600,registrar_server:null,sockets:null,connection_recovery_max_interval:Cn.CONNECTION_RECOVERY_MAX_INTERVAL,connection_recovery_min_interval:Cn.CONNECTION_RECOVERY_MIN_INTERVAL,extra_headers:null,via_host:`${hr.createRandomToken(12)}.invalid`};const la={mandatory:{sockets(c){const t=[];if(Xo.isSocket(c))t.push({socket:c});else if(Array.isArray(c)&&c.length)for(const n of c)Object.prototype.hasOwnProperty.call(n,"socket")&&Xo.isSocket(n.socket)?t.push(n):Xo.isSocket(n)&&t.push({socket:n});else return;return t},uri(c){/^sip:/i.test(c)||(c=`${Cn.SIP}:${c}`);const t=Rf.parse(c);if(t)return t.user?t:void 0}},optional:{authorization_user(c){if(zo.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(hr.isDecimal(c)){const t=Number(c);if(t>0)return t}},connection_recovery_min_interval(c){if(hr.isDecimal(c)){const t=Number(c);if(t>0)return t}},contact_uri(c){if(typeof c=="string"){const t=zo.parse(c,"SIP_URI");if(t!==-1)return t}},display_name(c){return c},instance_id(c){if(/^uuid:/i.test(c)&&(c=c.substr(5)),zo.parse(c,"uuid")!==-1)return c},no_answer_timeout(c){if(hr.isDecimal(c)){const t=Number(c);if(t>0)return t}},session_timers(c){if(typeof c=="boolean")return c},session_timers_refresh_method(c){if(typeof c=="string"&&(c=c.toUpperCase(),c===Cn.INVITE||c===Cn.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(hr.isDecimal(c)){const t=Number(c);if(t>0)return t}},registrar_server(c){/^sip:/i.test(c)||(c=`${Cn.SIP}:${c}`);const t=Rf.parse(c);if(t)return t.user?void 0:t},use_preloaded_route(c){if(typeof c=="boolean")return c},extra_headers(c){const t=[];if(Array.isArray(c)&&c.length)for(const n of c)typeof n=="string"&&t.push(n);else return;return t}}};rl.load=(c,t)=>{for(const n in la.mandatory)if(t.hasOwnProperty(n)){const a=t[n],o=la.mandatory[n](a);if(o!==void 0)c[n]=o;else throw new Qo.ConfigurationError(n,a)}else throw new Qo.ConfigurationError(n);for(const n in la.optional)if(t.hasOwnProperty(n)){const a=t[n];if(hr.isEmpty(a))continue;const o=la.optional[n](a);if(o!==void 0)c[n]=o;else throw new Qo.ConfigurationError(n,a)}};const mT=ft.EventEmitter,gT=ut,mt=De,TT=lg,If=Sh,bf=Bg,wf=Jg,Zo=Tr,vT=yh,aa=Ct(),ET=Cs,ST=ys(),yT=Ch,eu=yt,CT=Ih,tu=rl,qe=new gT("UA"),vt={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2};var bh=class extends mT{static get C(){return vt}constructor(t){if(qe.debug("new() [configuration:%o]",t),super(),this._cache={credentials:{}},this._configuration=Object.assign({},tu.settings),this._dynConfiguration={},this._dialogs={},this._applicants={},this._sessions={},this._transport=null,this._contact=null,this._status=vt.STATUS_INIT,this._error=null,this._transactions={nist:{},nict:{},ist:{},ict:{}},this._data={},this._closeTimer=null,t===void 0)throw new TypeError("Not enough arguments");try{this._loadConfig(t)}catch(n){throw this._status=vt.STATUS_NOT_READY,this._error=vt.CONFIGURATION_ERROR,n}this._registrator=new TT(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(t){qe.debug("unregister()"),this._dynConfiguration.register=!1,this._registrator.unregister(t)}registrator(){return this._registrator}isRegistered(){return this._registrator.registered}isConnected(){return this._transport.isConnected()}call(t,n){qe.debug("call()");const a=new If(this);return a.connect(t,n),a}sendMessage(t,n,a){qe.debug("sendMessage()");const o=new bf(this);return o.send(t,n,a),o}sendOptions(t,n,a){qe.debug("sendOptions()");const o=new wf(this);return o.send(t,n,a),o}terminateSessions(t){qe.debug("terminateSessions()");for(const n in this._sessions)this._sessions[n].isEnded()||this._sessions[n].terminate(t)}stop(){if(qe.debug("stop()"),this._dynConfiguration={},this._status===vt.STATUS_USER_CLOSED){qe.debug("UA already closed");return}this._registrator.close();const t=Object.keys(this._sessions).length;for(const a in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,a)){qe.debug(`closing session ${a}`);try{this._sessions[a].terminate()}catch{}}for(const a in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,a))try{this._applicants[a].close()}catch{}this._status=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&&t===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}normalizeTarget(t){return aa.normalizeTarget(t,this._configuration.hostport_params)}get(t){switch(t){case"authorization_user":return this._configuration.authorization_user;case"realm":return this._configuration.realm;case"ha1":return this._configuration.ha1;case"authorization_jwt":return this._configuration.authorization_jwt;default:qe.warn('get() | cannot get "%s" parameter in runtime',t);return}}set(t,n){switch(t){case"authorization_user":{this._configuration.authorization_user=String(n);break}case"password":{this._configuration.password=String(n);break}case"realm":{this._configuration.realm=String(n);break}case"ha1":{this._configuration.ha1=String(n),this._configuration.password=null;break}case"authorization_jwt":{this._configuration.authorization_jwt=String(n);break}case"display_name":{this._configuration.display_name=n;break}default:return qe.warn('set() | cannot set "%s" parameter in runtime',t),!1}return!0}newTransaction(t){this._transactions[t.type][t.id]=t,this.emit("newTransaction",{transaction:t})}destroyTransaction(t){delete this._transactions[t.type][t.id],this.emit("transactionDestroyed",{transaction:t})}newDialog(t){this._dialogs[t.id]=t}destroyDialog(t){delete this._dialogs[t.id]}newMessage(t,n){this._applicants[t]=t,this.emit("newMessage",n)}newOptions(t,n){this._applicants[t]=t,this.emit("newOptions",n)}destroyMessage(t){delete this._applicants[t]}newRTCSession(t,n){this._sessions[t.id]=t,this.emit("newRTCSession",n)}destroyRTCSession(t){delete this._sessions[t.id]}registered(t){this.emit("registered",t)}unregistered(t){this.emit("unregistered",t)}registrationFailed(t){this.emit("registrationFailed",t)}receiveRequest(t){const n=t.method;if(t.ruri.user!==this._configuration.uri.user&&t.ruri.user!==this._contact.uri.user){qe.debug("Request-URI does not point to us"),t.method!==mt.ACK&&t.reply_sl(404);return}if(t.ruri.scheme===mt.SIPS){t.reply_sl(416);return}if(Zo.checkTransaction(this,t))return;if(n===mt.INVITE?new Zo.InviteServerTransaction(this,this._transport,t):n!==mt.ACK&&n!==mt.CANCEL&&new Zo.NonInviteServerTransaction(this,this._transport,t),n===mt.OPTIONS){if(this.listeners("newOptions").length===0){t.reply(200);return}new wf(this).init_incoming(t)}else if(n===mt.MESSAGE){if(this.listeners("newMessage").length===0){t.reply(405);return}new bf(this).init_incoming(t)}else if(n===mt.INVITE&&!t.to_tag&&this.listeners("newRTCSession").length===0){t.reply(405);return}let a,o;if(t.to_tag)a=this._findDialog(t.call_id,t.from_tag,t.to_tag),a?a.receiveRequest(t):n===mt.NOTIFY?(o=this._findSession(t),o?o.receiveRequest(t):(qe.debug("received NOTIFY request for a non existent subscription"),t.reply(481,"Subscription does not exist"))):n!==mt.ACK&&t.reply(481);else switch(n){case mt.INVITE:if(window.RTCPeerConnection)if(t.hasHeader("replaces")){const s=t.replaces;a=this._findDialog(s.call_id,s.from_tag,s.to_tag),a?(o=a.owner,o.isEnded()?t.reply(603):o.receiveRequest(t)):t.reply(481)}else o=new If(this),o.init_incoming(t);else qe.warn("INVITE received but WebRTC is not supported"),t.reply(488);break;case mt.BYE:t.reply(481);break;case mt.CANCEL:o=this._findSession(t),o?o.receiveRequest(t):qe.debug("received CANCEL request for a non existent session");break;case mt.ACK:break;case mt.NOTIFY:this.emit("sipEvent",{event:t.event,request:t}),t.reply(200);break;default:t.reply(405);break}}_findSession({call_id:t,from_tag:n,to_tag:a}){const o=t+n,s=this._sessions[o],r=t+a,d=this._sessions[r];return s||d||null}_findDialog(t,n,a){let o=t+n+a,s=this._dialogs[o];return s||(o=t+a+n,s=this._dialogs[o],s||null)}_loadConfig(t){try{tu.load(this._configuration,t)}catch(o){throw o}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=aa.newUUID()),this._configuration.jssip_id=aa.createRandomToken(5);const n=this._configuration.uri.clone();n.user=null,this._configuration.hostport_params=n.toString().replace(/^sip:/i,"");try{this._transport=new vT(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=AT.bind(this),this._transport.onconnect=RT.bind(this),this._transport.ondisconnect=IT.bind(this),this._transport.ondata=bT.bind(this)}catch(o){throw qe.warn(o),new ET.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){const o=this._configuration.uri.clone();o.user=null,o.clearParams(),o.clearHeaders(),this._configuration.registrar_server=o}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new ST("sip",aa.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(o={}){const s=o.anonymous||null,r=o.outbound||null;let d="<";return s?d+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":d+=this.pub_gruu||this.uri.toString(),r&&(s?!this.temp_gruu:!this.pub_gruu)&&(d+=";ob"),d+=">",d}};const a=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const o in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,o)&&(a.indexOf(o)!==-1?Object.defineProperty(this._configuration,o,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,o,{writable:!1,configurable:!1}));qe.debug("configuration parameters after validation:");for(const o in this._configuration)if(Object.prototype.hasOwnProperty.call(tu.settings,o))switch(o){case"uri":case"registrar_server":qe.debug(`- ${o}: ${this._configuration[o]}`);break;case"password":case"ha1":case"authorization_jwt":qe.debug(`- ${o}: NOT SHOWN`);break;default:qe.debug(`- ${o}: ${JSON.stringify(this._configuration[o])}`)}}};function AT(c){this.emit("connecting",c)}function RT(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 IT(c){const t=["nict","ict","nist","ist"];for(const n of t)for(const a in this._transactions[n])Object.prototype.hasOwnProperty.call(this._transactions[n],a)&&this._transactions[n][a].onTransportError();this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==vt.STATUS_USER_CLOSED&&(this._status=vt.STATUS_NOT_READY,this._error=vt.NETWORK_ERROR)}function bT(c){const t=c.transport;let n=c.message;if(n=yT.parseMessage(n,this),!!n&&!(this._status===vt.STATUS_USER_CLOSED&&n instanceof eu.IncomingRequest)&&CT(n,this,t)){if(n instanceof eu.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof eu.IncomingResponse){let a;switch(n.method){case mt.INVITE:a=this._transactions.ict[n.via_branch],a&&a.receiveResponse(n);break;case mt.ACK:break;default:a=this._transactions.nict[n.via_branch],a&&a.receiveResponse(n);break}}}}const wT=ze(bh);var _t=[];for(var su=0;su<256;++su)_t.push((su+256).toString(16).slice(1));function OT(c,t=0){return(_t[c[t+0]]+_t[c[t+1]]+_t[c[t+2]]+_t[c[t+3]]+"-"+_t[c[t+4]]+_t[c[t+5]]+"-"+_t[c[t+6]]+_t[c[t+7]]+"-"+_t[c[t+8]]+_t[c[t+9]]+"-"+_t[c[t+10]]+_t[c[t+11]]+_t[c[t+12]]+_t[c[t+13]]+_t[c[t+14]]+_t[c[t+15]]).toLowerCase()}var oa,DT=new Uint8Array(16);function NT(){if(!oa&&(oa=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!oa))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return oa(DT)}var UT=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Of={randomUUID:UT};function Df(c,t,n){if(Of.randomUUID&&!t&&!c)return Of.randomUUID();c=c||{};var a=c.random||(c.rng||NT)();if(a[6]=a[6]&15|64,a[8]=a[8]&63|128,t){n=n||0;for(var o=0;o<16;++o)t[n+o]=a[o];return t}return OT(a)}var ke=Ct();const Ts=ze(ke),nu=new Wa("Dialog"),Fs={STATUS_EARLY:1,STATUS_CONFIRMED:2,STATUS_TERMINATED:3};class ua{static get C(){return Fs}constructor(t,n,a,o=Fs.STATUS_CONFIRMED){if(this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,n instanceof yt.IncomingResponse&&(o=n.status_code<200?Fs.STATUS_EARLY:Fs.STATUS_CONFIRMED),a==="UAS"){this._id={call_id:n.call_id,local_tag:n.to_tag,remote_tag:n.from_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri;let s=n.getHeaders("to")[0].split(";")[0];s=s.match(/<([^>]*)>/)[1],this._remote_target=s,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum}else if(a==="UAC"){this._id={call_id:n.call_id,local_tag:n.from_tag,remote_tag:n.to_tag,toString(){return this.call_id+this.local_tag+this.remote_tag}},this._state=o,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri;let s=n.getHeaders("to")[0].split(";")[0];s=s.match(/<([^>]*)>/)[1],this._remote_target=s,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null}this._ua.newDialog(this),nu.debug(`new ${a} dialog created with status ${this._state===Fs.STATUS_EARLY?"EARLY":"CONFIRMED"}`)}get id(){return this._id}get local_seqnum(){return this._local_seqnum}set local_seqnum(t){this._local_seqnum=t}get owner(){return this._owner}get uac_pending_reply(){return this._uac_pending_reply}set uac_pending_reply(t){this._uac_pending_reply=t}get uas_pending_reply(){return this._uas_pending_reply}isTerminated(){return this._status===Fs.STATUS_TERMINATED}update(t,n){this._state=Fs.STATUS_CONFIRMED,nu.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`),n==="UAC"&&(this._route_set=t.getHeaders("record-route").reverse())}terminate(){nu.debug(`dialog ${this._id.toString()} deleted`),this._ua.destroyDialog(this),this._state=Fs.STATUS_TERMINATED}sendRequest(t,n={}){const a=Ts.cloneArray(n.extraHeaders),o=Ts.cloneObject(n.eventHandlers),s=n.body||null,r=this._createRequest(t,a,s);return o.onAuthenticated=()=>{this._local_seqnum+=1},new hg(this,r,o).send(),r}receiveRequest(t){this._checkInDialogRequest(t)&&(t.method===L.ACK&&this._ack_seqnum!==null?this._ack_seqnum=null:t.method===L.INVITE&&(this._ack_seqnum=t.cseq),this._owner.receiveRequest(t))}_createRequest(t,n,a){n=Ts.cloneArray(n),this._local_seqnum||(this._local_seqnum=Math.floor(Math.random()*1e4));const o=t===L.CANCEL||t===L.ACK?this._local_seqnum:this._local_seqnum+=1;return new yt.OutgoingRequest(t,this._remote_target,this._ua,{cseq:o,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},n,a)}_checkInDialogRequest(t){if(!this._remote_seqnum)this._remote_seqnum=t.cseq;else if(t.cseq<this._remote_seqnum)if(t.method===L.ACK){if(this._ack_seqnum===null||t.cseq!==this._ack_seqnum)return!1}else return t.reply(500),!1;else t.cseq>this._remote_seqnum&&(this._remote_seqnum=t.cseq);if(t.method===L.INVITE||t.method===L.UPDATE&&t.body){if(this._uac_pending_reply===!0)t.reply(491);else if(this._uas_pending_reply===!0){const n=(Math.random()*10|0)+1;return t.reply(500,null,[`Retry-After:${n}`]),!1}else{this._uas_pending_reply=!0;const n=()=>{(t.server_transaction.state===Gt.C.STATUS_ACCEPTED||t.server_transaction.state===Gt.C.STATUS_COMPLETED||t.server_transaction.state===Gt.C.STATUS_TERMINATED)&&(t.server_transaction.removeListener("stateChanged",n),this._uas_pending_reply=!1)};t.server_transaction.on("stateChanged",n)}t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===Gt.C.STATUS_ACCEPTED&&(this._remote_target=t.parseHeader("contact").uri)})}else t.method===L.NOTIFY&&t.hasHeader("contact")&&t.server_transaction.on("stateChanged",()=>{t.server_transaction.state===Gt.C.STATUS_COMPLETED&&(this._remote_target=t.parseHeader("contact").uri)});return!0}}class PT{constructor(t,n){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=t,this.plugin=n,this.rtcpPeer=new RTCPeerConnection({iceServers:[]})}get memberInfo(){return{stream:this.stream,joinResult:this.joinResult,sender:this.handleId,type:"subscriber",name:this.info.display,state:this.state,id:this.handleId}}updateMemberState(t){var n;this.state={...this.state,...t||{}},(n=this.plugin)==null||n.session.emit("member:update",this.memberInfo)}updateMemberStateFromMessage(t){var s,r,d,h;const n=(r=(s=t==null?void 0:t.plugindata)==null?void 0:s.data)==null?void 0:r.newStatePublisher,o=((h=(d=t==null?void 0:t.plugindata)==null?void 0:d.data)==null?void 0:h.publisher_state).find(_=>_.id===n);this.updateMemberState(o==null?void 0:o.state)}hangup(){this.rtcpPeer&&(this.rtcpPeer.close(),this.rtcpPeer=null),this.stream&&this.stream.getTracks().forEach(t=>{t.stop()})}}class Qt{static canGetMediaDevices(){return!(!navigator.mediaDevices||!navigator.mediaDevices.enumerateDevices)}static async getDevices(t){return Qt.canGetMediaDevices()?(await navigator.mediaDevices.enumerateDevices()).filter(a=>a.kind===t):[]}static async getMicrophoneList(){return(await Qt.getDevices("audioinput")).map((n,a)=>({...n,deviceId:n.deviceId,label:n.label||`microphone ${a+1}`,kind:n.kind,groupId:n.groupId}))}static async getSpeakerList(){return(await Qt.getDevices("audiooutput")).map((n,a)=>({...n,deviceId:n.deviceId,label:n.label||`speaker ${a+1}`,kind:n.kind,groupId:n.groupId}))}static async getCameraList(){return(await Qt.getDevices("videoinput")).map((n,a)=>({...n,deviceId:n.deviceId,label:n.label||`camera ${a+1}`,kind:n.kind,groupId:n.groupId}))}static stopStreamTracks(t){t&&t.getTracks().forEach(n=>{n.stop()})}static async getMediaFromInputs({videoInput:t,audioInput:n}){let a,o;t==="default"?a=!0:t&&t!=="default"&&(a={deviceId:{exact:t}}),n==="default"?o=!0:n&&n!=="default"&&(o={deviceId:{exact:n}});const s={audio:o,video:a};return Qt.getUserMedia(s)}static async getUserMedia(t){return await navigator.mediaDevices.getUserMedia(t)}static async changeAudioOutput(t,n){if(!(!t||!n))if(typeof t.sinkId<"u")try{await t.setSinkId(n)}catch(a){let o=a;a.name==="SecurityError"&&(o=`You need to use HTTPS for selecting audio output device: ${a}`),console.error(o)}else console.warn("Browser does not support output device selection.")}static toggleAudioMute(t){const n=t.getAudioTracks();if(n.length!==0)return n.forEach(a=>{a.enabled=!a.enabled}),n[0].enabled}static toggleVideoMute(t){const n=t.getVideoTracks();if(n.length!==0)return n.forEach(a=>{a.enabled=!a.enabled}),n[0].enabled}static async getStream(t={video:!0,audio:!0}){try{const n=await navigator.mediaDevices.getUserMedia(t);let a=n.getTracks();return t.video?a=n.getVideoTracks():t.audio&&(a=n.getAudioTracks()),a.length===0?{stream:n,track:null}:{stream:n,track:a[0]}}catch(n){return console.warn(n),{stream:null,track:null}}}}var xT=ys();const In=ze(xT),Pt={LEAVE:"Leave",DETACH:"Detach",AUDIO_CHANGE:"AudioChange",VIDEO_CHANGE:"VideoChange",STATE:"State",ICE:"Ice",CONFIGURE:"Configure",TRICKLE:"Trickle",SUBSCRIBER:"Subscriber",PUBLISHER:"Publisher"},z=new Wa("JanusSession"),kT="/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},ca=["audio","video"];class Ha extends ft.EventEmitter{static get C(){return te}constructor(t){z.debug("new"),super(),this._id=null,this._ua=t,this._status=te.STATUS_NULL,this._dialog=null,this._earlyDialogs={},this._contact=null,this._from_tag=null,this._to_tag=null,this.lastTransaction=0,this._connection=null,this._connectionPromiseQueue=Promise.resolve(),this._request=null,this._is_canceled=!1,this._cancel_reason="",this._is_confirmed=!1,this._late_sdp=!1,this._rtcOfferConstraints=null,this._rtcAnswerConstraints=null,this._localMediaStream=null,this._localMediaStreamLocallyGenerated=!1,this._rtcReady=!0,this._iceReady=!1,this._timers={ackTimer:null,expiresTimer:null,invite2xxTimer:null,userNoAnswerTimer:null},this._direction=null,this._local_identity=null,this._remote_identity=null,this._start_time=null,this._end_time=null,this._audioMuted=!1,this._videoMuted=!1,this._localHold=!1,this._remoteHold=!1,this._sessionTimers={enabled:this._ua.configuration.session_timers,refreshMethod:this._ua.configuration.session_timers_refresh_method,defaultExpires:L.SESSION_EXPIRES,currentExpires:null,running:!1,refresher:!1,timer:null},this._referSubscribers={},this._candidates=[],this.publishers=[],this.private_id=null,this.memberList={},this.myFeedList=[],this.display_name="",this.stunServers=[{urls:"stun:turn.voicenter.co",credential:"kxsjahnsdjns3eds23esd",username:"turn2es21e"}],this.opaque_id=this.generateOpaqueId(),this.screen_share_opaque_id=this.generateOpaqueId(),this._data={},this.isAudioOn=!0,this.isVideoOn=!0,this.mediaConstraints={}}get C(){return te}get causes(){return L.causes}get id(){return this._id}get connection(){return this._connection}get contact(){return this._contact}get direction(){return this._direction}get local_identity(){return this._local_identity}get remote_identity(){return this._remote_identity}get start_time(){return this._start_time}get end_time(){return this._end_time}get data(){return this._data}set data(t){this._data=t}get status(){return this._status}isInProgress(){switch(this._status){case te.STATUS_NULL:case te.STATUS_INVITE_SENT:case te.STATUS_1XX_RECEIVED:case te.STATUS_INVITE_RECEIVED:case te.STATUS_WAITING_FOR_ANSWER:return!0;default:return!1}}isEstablished(){switch(this._status){case te.STATUS_ANSWERED:case te.STATUS_WAITING_FOR_ACK:case te.STATUS_CONFIRMED:return!0;default:return!1}}isEnded(){switch(this._status){case te.STATUS_CANCELED:case te.STATUS_TERMINATED:return!0;default:return!1}}isMuted(){return{audio:this._audioMuted,video:this._videoMuted}}isOnHold(){return{local:this._localHold,remote:this._remoteHold}}getPTypeHeader(t){return`PTYPE: ${t}`}generateOpaqueId(){return`videoroomtest-${Df().replace(/-/g,"").slice(0,12)}`}connect(t,n,a={},o){z.debug("connect()"),this.display_name=n;const s=t,r=ke.cloneObject(a.eventHandlers),d=ke.cloneArray(a.extraHeaders),h=ke.cloneObject(a.mediaConstraints,{audio:!0,video:!0});this.mediaConstraints={...h};const _=a.mediaStream||null,g=ke.cloneObject(a.pcConfig,{iceServers:[]}),T=a.rtcConstraints||null,E=a.rtcOfferConstraints||null;if(this._rtcOfferConstraints=E,this._rtcAnswerConstraints=a.rtcAnswerConstraints||null,this._data=a.data||this._data,t===void 0)throw new TypeError("Not enough arguments");if(this._status!==te.STATUS_NULL)throw new qs.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new qs.NotSupportedError("WebRTC not supported");if(t=this._ua.normalizeTarget(t),this.room_id=t.user,this.target=t,!t)throw new TypeError(`Invalid target: ${s}`);this._sessionTimers.enabled&&ke.isDecimal(a.sessionTimersExpires)&&(a.sessionTimersExpires>=L.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=a.sessionTimersExpires:this._sessionTimers.defaultExpires=L.SESSION_EXPIRES);for(const A in r)Object.prototype.hasOwnProperty.call(r,A)&&this.on(A,r[A]);this._from_tag=ke.newTag();const y=a.anonymous||!1,C={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:y,outbound:!0}),y?(C.from_display_name="Anonymous",C.from_uri=new In("sip","anonymous","anonymous.invalid"),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`),d.push("Privacy: id")):a.fromUserName&&(C.from_uri=new In("sip",a.fromUserName,this._ua.configuration.uri.host),d.push(`P-Preferred-Identity: ${this._ua.configuration.uri.toString()}`)),a.fromDisplayName&&(C.from_display_name=a.fromDisplayName),d.push(`Contact: ${this._contact}`),d.push("Content-Type: application/json"),this._sessionTimers.enabled&&d.push(`Session-Expires: ${this._sessionTimers.defaultExpires}${this._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new yt.InitialOutgoingInviteRequest(t,this._ua,C,d),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(g,T),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,o&&o(this),this._newJanusSession("local",this._request),this._sendInitialRequest(h,E,_)}_overrideSenderTracks(t,n){t.getTracks().forEach(a=>{n.getSenders().forEach(async s=>{s.track.kind===a.kind&&(a.kind==="audio"&&!this.isAudioOn&&(a.enabled=!1),a.kind==="video"&&!this.isVideoOn&&(a.enabled=!1),await s.replaceTrack(a))})})}init_incoming(t,n){z.debug("init_incoming()");let a;const o=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;if(t.body&&o!=="application/sdp"){t.reply(415);return}if(this._status=te.STATUS_INVITE_RECEIVED,this._from_tag=t.from_tag,this._id=t.call_id+this._from_tag,this._request=t,this._contact=this._ua.contact.toString(),t.hasHeader("expires")&&(a=t.getHeader("expires")*1e3),t.to_tag=ke.newTag(),!this._createDialog(t,"UAS",!0)){t.reply(500,"Missing Contact header field");return}t.body?this._late_sdp=!1:this._late_sdp=!0,this._status=te.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{t.reply(408),this._failed("local",null,L.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),a&&(this._timers.expiresTimer=setTimeout(()=>{this._status===te.STATUS_WAITING_FOR_ANSWER&&(t.reply(487),this._failed("system",null,L.causes.EXPIRES))},a)),this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from,n&&n(this),this._newJanusSession("remote",t),this._status!==te.STATUS_TERMINATED&&(t.reply(180,null,[`Contact: ${this._contact}`]),this._progress("local",null))}answer(t={}){z.debug("answer()");const n=this._request,a=ke.cloneArray(t.extraHeaders),o=ke.cloneObject(t.mediaConstraints),s=t.mediaStream||null,r=ke.cloneObject(t.pcConfig,{iceServers:[]}),d=t.rtcConstraints||null,h=t.rtcAnswerConstraints||null,_=ke.cloneObject(t.rtcOfferConstraints);let g,T=!1,E=!1,y=!1,C=!1;if(this._rtcAnswerConstraints=h,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,this._direction!=="incoming")throw new qs.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==te.STATUS_WAITING_FOR_ANSWER)throw new qs.InvalidStateError(this._status);if(this._sessionTimers.enabled&&ke.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=L.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=L.SESSION_EXPIRES),this._status=te.STATUS_ANSWERED,!this._createDialog(n,"UAS")){n.reply(500,"Error creating dialog");return}clearTimeout(this._timers.userNoAnswerTimer),a.unshift(`Contact: ${this._contact}`);const A=n.parseSDP();Array.isArray(A.media)||(A.media=[A.media]);for(const I of A.media)I.type==="audio"&&(T=!0,(!I.direction||I.direction==="sendrecv")&&(y=!0)),I.type==="video"&&(E=!0,(!I.direction||I.direction==="sendrecv")&&(C=!0));if(s&&o.audio===!1){g=s.getAudioTracks();for(const I of g)s.removeTrack(I)}if(s&&o.video===!1){g=s.getVideoTracks();for(const I of g)s.removeTrack(I)}!s&&o.audio===void 0&&(o.audio=y),!s&&o.video===void 0&&(o.video=C),!s&&!T&&!_.offerToReceiveAudio&&(o.audio=!1),!s&&!E&&!_.offerToReceiveVideo&&(o.video=!1),this._createRTCConnection(r,d),Promise.resolve().then(()=>{if(s)return s;if(o.audio||o.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(I=>{throw this._status===te.STATUS_TERMINATED?new Error("terminated"):(n.reply(480),this._failed("local",null,L.causes.USER_DENIED_MEDIA_ACCESS),z.warn('emit "getusermediafailed" [error:%o]',I),this.emit("getusermediafailed",I),new Error("getUserMedia() failed"))})}).then(I=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._localMediaStream=I,I&&I.getTracks().forEach(H=>{this._connection.addTrack(H,I)})}).then(()=>{if(this._late_sdp)return;const I={originator:"remote",type:"offer",sdp:n.body};z.debug('emit "sdp"'),this.emit("sdp",I);const H=new RTCSessionDescription({type:"offer",sdp:I.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(H)).catch($=>{throw n.reply(488),this._failed("system",null,L.causes.WEBRTC_ERROR),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',$),this.emit("peerconnection:setremotedescriptionfailed",$),new Error("peerconnection.setRemoteDescription() failed")}),this._connectionPromiseQueue}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._connecting(n),this._late_sdp?this._createLocalDescription("offer",this._rtcOfferConstraints).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")}):this._createLocalDescription("answer",h).catch(()=>{throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(I=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._handleSessionTimersInIncomingRequest(n,a),n.reply(200,null,a,I,()=>{this._status=te.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(n,I),this._setACKTimer(),this._accepted("local")},()=>{this._failed("system",null,L.causes.CONNECTION_ERROR)})}).catch(I=>{this._status!==te.STATUS_TERMINATED&&z.warn(I)})}terminate(t={}){z.debug("terminate()");const n=t.cause||L.causes.BYE,a=ke.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,d=t.reason_phrase;if(this._status===te.STATUS_TERMINATED)throw new qs.InvalidStateError(this._status);switch(this._status){case te.STATUS_NULL:case te.STATUS_INVITE_SENT:case te.STATUS_1XX_RECEIVED:if(z.debug("canceling session"),r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);r&&(d=d||L.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${d}"`),this._status===te.STATUS_NULL||this._status===te.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===te.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=te.STATUS_CANCELED,this._failed("local",null,L.causes.CANCELED);break;case te.STATUS_WAITING_FOR_ANSWER:case te.STATUS_ANSWERED:if(z.debug("rejecting session"),r=r||480,r<300||r>=700)throw new TypeError(`Invalid status_code: ${r}`);this._request.reply(r,d,a,o),this._failed("local",null,L.causes.REJECTED);break;case te.STATUS_WAITING_FOR_ACK:case te.STATUS_CONFIRMED:if(z.debug("terminating session"),d=t.reason_phrase||L.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);if(r&&a.push(`Reason: SIP ;cause=${r}; text="${d}"`),this._status===te.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Gt.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:_})=>{_===L.ACK&&(this.sendRequest(L.BYE,{extraHeaders:a,body:o}),h.terminate(),this.closeSession())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Gt.C.STATUS_TERMINATED&&(this.sendRequest(L.BYE,{extraHeaders:a,body:o}),h.terminate(),this.closeSession())}),this._ended("local",null,n),this._dialog=h,this._ua.newDialog(h)}else{const h={janus:"leave"},_=["Content-Type: application/json",this.getPTypeHeader(Pt.LEAVE)];this.sendRequest(L.BYE,{extraHeaders:_,body:JSON.stringify(h)}),this.closeSession(),this._ended("local",null,n)}}}configureMedia(t){this.isAudioOn=t.audio,this.isVideoOn=t.video}enableAudio(t){const n={janus:"message",body:{audio:t},handle_id:this.handle_id,session_id:this.session_id},a=["Content-Type: application/json",this.getPTypeHeader(Pt.AUDIO_CHANGE)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{o.status_code===200&&(this._ua.emit("changeAudioState",t),this.sendStateMessage({audio:t}))}}})}startAudio(){Qt.toggleAudioMute(this.stream),this._toggleMuteAudio(!1),this.enableAudio(!0),this.isAudioOn=!0}stopAudio(){Qt.toggleAudioMute(this.stream),this._toggleMuteAudio(!0),this.enableAudio(!1),this.isAudioOn=!1}enableVideo(t){const n={janus:"message",body:{video:t},handle_id:this.handle_id,session_id:this.session_id},a=["Content-Type: application/json",this.getPTypeHeader(Pt.VIDEO_CHANGE)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{o.status_code===200&&(this._ua.emit("changeVideoState",t),this.sendStateMessage({video:t}))}}})}startVideo(){Qt.toggleVideoMute(this.stream),this._toggleMuteVideo(!1),this.enableVideo(!0),this.isVideoOn=!0}stopVideo(){Qt.toggleVideoMute(this.stream),this._toggleMuteVideo(!0),this.enableVideo(!1),this.isVideoOn=!1}sendStateMessage(t){const n={janus:"message",body:{request:"state",data:t},handle_id:this.handle_id,session_id:this.session_id},a=["Content-Type: application/json",this.getPTypeHeader(Pt.STATE)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n)})}sendInfo(t,n,a={}){if(z.debug("sendInfo()"),this._status!==te.STATUS_CONFIRMED&&this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_1XX_RECEIVED)throw new qs.InvalidStateError(this._status);new yu(this).send(t,n,a)}mute(t={audio:!0,video:!1}){z.debug("mute()");let n=!1,a=!1;this._audioMuted===!1&&t.audio&&(n=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),this._videoMuted===!1&&t.video&&(a=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),(n===!0||a===!0)&&this._onmute({audio:n,video:a})}unmute(t={audio:!0,video:!0}){z.debug("unmute()");let n=!1,a=!1;this._audioMuted===!0&&t.audio&&(n=!0,this._audioMuted=!1,this._localHold===!1&&this._toggleMuteAudio(!1)),this._videoMuted===!0&&t.video&&(a=!0,this._videoMuted=!1,this._localHold===!1&&this._toggleMuteVideo(!1)),(n===!0||a===!0)&&this._onunmute({audio:n,video:a})}hold(t={},n){if(z.debug("hold()"),this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||this._localHold===!0||!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:L.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}unhold(t={},n){if(z.debug("unhold()"),this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||this._localHold===!1||!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");const a={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:L.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:a,extraHeaders:t.extraHeaders}),!0}renegotiate(t={},n){z.debug("renegotiate()");const a=t.rtcOfferConstraints||null;if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED||!this._isReadyToReOffer())return!1;const o={succeeded:()=>{n&&n()},failed:()=>{this.terminate({cause:L.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:o,rtcOfferConstraints:a,extraHeaders:t.extraHeaders}),!0}refer(t,n){z.debug("refer()");const a=t;if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;if(t=this._ua.normalizeTarget(t),!t)throw new TypeError(`Invalid target: ${a}`);const o=new Ng(this);o.sendRefer(t,n);const s=o.id;return this._referSubscribers[s]=o,o.on("requestFailed",()=>{delete this._referSubscribers[s]}),o.on("accepted",()=>{delete this._referSubscribers[s]}),o.on("failed",()=>{delete this._referSubscribers[s]}),o}sendRequest(t,n){return z.debug("sendRequest()"),this._dialog.sendRequest(t,n)}receiveNotify(t){z.debug("receiveRequest()")}receiveRequest(t){if(z.debug("receiveRequest()"),t.method===L.CANCEL)(this._status===te.STATUS_WAITING_FOR_ANSWER||this._status===te.STATUS_ANSWERED)&&(this._status=te.STATUS_CANCELED,this._request.reply(487),this._failed("remote",t,L.causes.CANCELED));else switch(t.method){case L.ACK:if(this._status!==te.STATUS_WAITING_FOR_ACK)return;if(this._status=te.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!t.body){this.terminate({cause:L.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:t.body};z.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>{this._is_confirmed||this._confirmed("remote",t)}).catch(o=>{this.terminate({cause:L.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})}else this._is_confirmed||this._confirmed("remote",t);break;case L.BYE:this._status===te.STATUS_CONFIRMED||this._status===te.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,L.causes.BYE)):this._status===te.STATUS_INVITE_RECEIVED||this._status===te.STATUS_WAITING_FOR_ANSWER?(t.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",t,L.causes.BYE)):t.reply(403,"Wrong Status");break;case L.INVITE:this._status===te.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case L.INFO:if(this._status===te.STATUS_1XX_RECEIVED||this._status===te.STATUS_WAITING_FOR_ANSWER||this._status===te.STATUS_ANSWERED||this._status===te.STATUS_WAITING_FOR_ACK||this._status===te.STATUS_CONFIRMED){const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;n&&n.match(/^application\/dtmf-relay/i)?new Eg(this).init_incoming(t):n!==void 0?new yu(this).init_incoming(t):t.reply(415)}else t.reply(403,"Wrong Status");break;case L.UPDATE:this._status===te.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case L.REFER:this._status===te.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case L.NOTIFY:this._status===te.STATUS_CONFIRMED?this._receiveNotify(t):t.reply(403,"Wrong Status");break;default:t.reply(501)}}onTransportError(){z.warn("onTransportError()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.CONNECTION_ERROR,cause:L.causes.CONNECTION_ERROR})}onRequestTimeout(){z.warn("onRequestTimeout()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:L.causes.REQUEST_TIMEOUT,cause:L.causes.REQUEST_TIMEOUT})}onDialogError(){z.warn("onDialogError()"),this._status!==te.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.DIALOG_ERROR,cause:L.causes.DIALOG_ERROR})}newDTMF(t){z.debug("newDTMF()"),this.emit("newDTMF",t)}newInfo(t){z.debug("newInfo()"),this.emit("newInfo",t)}_isReadyToReOffer(){return this._rtcReady?this._dialog?this._dialog.uac_pending_reply===!0||this._dialog.uas_pending_reply===!0?(z.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):!0:(z.debug("_isReadyToReOffer() | session not established yet"),!1):(z.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}_close(){if(z.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(z.debug("close() | closing local MediaStream"),ke.closeMediaStream(this._localMediaStream)),this._status!==te.STATUS_TERMINATED){if(this._status=te.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(t){z.warn("close() | error closing the RTCPeerConnection: %o",t)}for(const t in this._timers)Object.prototype.hasOwnProperty.call(this._timers,t)&&clearTimeout(this._timers[t]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const t in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(const t in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,t)&&delete this._referSubscribers[t];this._ua.destroyRTCSession(this)}}_setInvite2xxTimer(t,n){let a=$i.T1;function o(){this._status===te.STATUS_WAITING_FOR_ACK&&(t.reply(200,null,[`Contact: ${this._contact}`],n),a<$i.T2&&(a=a*2,a>$i.T2&&(a=$i.T2)),this._timers.invite2xxTimer=setTimeout(o.bind(this),a))}this._timers.invite2xxTimer=setTimeout(o.bind(this),a)}_setACKTimer(){this._timers.ackTimer=setTimeout(()=>{this._status===te.STATUS_WAITING_FOR_ACK&&(z.debug("no ACK received, terminating the session"),clearTimeout(this._timers.invite2xxTimer),this.sendRequest(L.BYE),this._ended("remote",null,L.causes.NO_ACK))},$i.TIMER_H)}_createRTCConnection(t,n){this.stunServers,this._connection=new RTCPeerConnection(t,n),this._connection.addEventListener("iceconnectionstatechange",()=>{this._connection.iceConnectionState==="failed"&&this.terminate({cause:L.causes.RTP_TIMEOUT,status_code:408,reason_phrase:L.causes.RTP_TIMEOUT})});let a;const o=s=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||s.candidate&&(this._candidates.push(s.candidate),clearTimeout(a),a=setTimeout(()=>{this.lastTrickleReceived=!0,this.subscribeSent&&!this.isConfigureSent&&(this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream}),this._sendConfigureMessage({audio:!0,video:!0}).then(()=>{}))},500))};this._connection.onicecandidate=o,z.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}_createLocalDescription(t,n){if(z.debug("createLocalDescription()"),t!=="offer"&&t!=="answer")throw new Error(`createLocalDescription() | invalid type "${t}"`);const a=this._connection;return this._rtcReady=!1,Promise.resolve().then(()=>t==="offer"?a.createOffer(n).catch(o=>(z.warn('emit "peerconnection:createofferfailed" [error:%o]',o),this.emit("peerconnection:createofferfailed",o),Promise.reject(o))):a.createAnswer(n).catch(o=>(z.warn('emit "peerconnection:createanswerfailed" [error:%o]',o),this.emit("peerconnection:createanswerfailed",o),Promise.reject(o)))).then(o=>(this.jsepOffer=o,a.setLocalDescription(o).catch(s=>(this._rtcReady=!0,z.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',s),this.emit("peerconnection:setlocaldescriptionfailed",s),Promise.reject(s))))).then(()=>{const o=n&&n.iceRestart;if(a.iceGatheringState==="complete"&&!o||a.iceGatheringState==="gathering"&&this._iceReady){this._rtcReady=!0;const s={originator:"local",type:t,sdp:a.localDescription.sdp};return z.debug('emit "sdp"'),this.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(s=>{let r=!1,d,h;this._iceReady=!1;const _=()=>{a.removeEventListener("icecandidate",d),a.removeEventListener("icegatheringstatechange",h),r=!0,this._rtcReady=!0,this._iceReady=!0;const g={originator:"local",type:t,sdp:a.localDescription.sdp};z.debug('emit "sdp"'),this.emit("sdp",g),s(g.sdp)};a.addEventListener("icecandidate",d=g=>{const T=g.candidate;T?this.emit("icecandidate",{candidate:T,ready:_}):r||_()}),a.addEventListener("icegatheringstatechange",h=()=>{a.iceGatheringState==="complete"&&!r&&_()})})})}_createDialog(t,n,a){const o=n==="UAS"?t.to_tag:t.from_tag,s=n==="UAS"?t.from_tag:t.to_tag,r=t.call_id+o+s;let d=this._earlyDialogs[r];if(a)return d?!0:(d=new ua(this,t,n,ua.C.STATUS_EARLY),d.error?(z.debug(d.error),this._failed("remote",t,L.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=d,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,d)return d.update(t,n),this._dialog=d,delete this._earlyDialogs[r],!0;const h=new ua(this,t,n);return h.error?(z.debug(h.error),this._failed("remote",t,L.causes.INTERNAL_ERROR),!1):(this._dialog=h,!0)}}_receiveReinvite(t){z.debug("receiveReinvite()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=ke.cloneArray(d.extraHeaders);if(this._status!==te.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("reinvite",a),o)return;if(this._late_sdp=!1,!t.body){this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",this._rtcOfferConstraints)).then(d=>{r.call(this,d)}).catch(()=>{t.reply(500)});return}if(n!=="application/sdp"){z.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==te.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{z.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),this._late_sdp&&(d=this._mangleOffer(d)),t.reply(200,null,h,d,()=>{this._status=te.STATUS_WAITING_FOR_ACK,this._setInvite2xxTimer(t,d),this._setACKTimer()}),typeof a.callback=="function"&&a.callback()}}_receiveUpdate(t){z.debug("receiveUpdate()");const n=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0,a={request:t,callback:void 0,reject:s.bind(this)};let o=!1;function s(d={}){o=!0;const h=d.status_code||403,_=d.reason_phrase||"",g=ke.cloneArray(d.extraHeaders);if(this._status!==te.STATUS_CONFIRMED)return!1;if(h<300||h>=700)throw new TypeError(`Invalid status_code: ${h}`);t.reply(h,_,g)}if(this.emit("update",a),o)return;if(!t.body){r.call(this,null);return}if(n!=="application/sdp"){z.debug("invalid Content-Type"),t.reply(415);return}this._processInDialogSdpOffer(t).then(d=>{this._status!==te.STATUS_TERMINATED&&r.call(this,d)}).catch(d=>{z.warn(d)});function r(d){const h=[`Contact: ${this._contact}`];this._handleSessionTimersInIncomingRequest(t,h),t.reply(200,null,h,d),typeof a.callback=="function"&&a.callback()}}_processInDialogSdpOffer(t){z.debug("_processInDialogSdpOffer()");const n=t.parseSDP();let a=!1;for(const r of n.media){if(ca.indexOf(r.type)===-1)continue;const d=r.direction||n.direction||"sendrecv";if(d==="sendonly"||d==="inactive")a=!0;else{a=!1;break}}const o={originator:"remote",type:"offer",sdp:t.body};z.debug('emit "sdp"'),this.emit("sdp",o);const s=new RTCSessionDescription({type:"offer",sdp:o.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._connection.setRemoteDescription(s).catch(r=>{throw t.reply(488),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',r),this.emit("peerconnection:setremotedescriptionfailed",r),r})}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");this._remoteHold===!0&&a===!1?(this._remoteHold=!1,this._onunhold("remote")):this._remoteHold===!1&&a===!0&&(this._remoteHold=!0,this._onhold("remote"))}).then(()=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._createLocalDescription("answer",this._rtcAnswerConstraints).catch(r=>{throw t.reply(500),z.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',r),r})}).catch(r=>{z.warn("_processInDialogSdpOffer() failed [error: %o]",r)}),this._connectionPromiseQueue}_receiveRefer(t){if(z.debug("receiveRefer()"),!t.refer_to){z.debug("no Refer-To header field present in REFER"),t.reply(400);return}if(t.refer_to.uri.scheme!==L.SIP){z.debug("Refer-To header field points to a non-SIP URI scheme"),t.reply(416);return}t.reply(202);const n=new bg(this,t.cseq);z.debug('emit "refer"'),this.emit("refer",{request:t,accept:(s,r)=>{a.call(this,s,r)},reject:()=>{o.call(this)}});function a(s,r={}){if(s=typeof s=="function"?s:null,this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;const d=new Ha(this._ua);if(d.on("progress",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("accepted",({response:h})=>{n.notify(h.status_code,h.reason_phrase)}),d.on("_failed",({message:h,cause:_})=>{h?n.notify(h.status_code,h.reason_phrase):n.notify(487,_)}),t.refer_to.uri.hasHeader("replaces")){const h=decodeURIComponent(t.refer_to.uri.getHeader("replaces"));r.extraHeaders=ke.cloneArray(r.extraHeaders),r.extraHeaders.push(`Replaces: ${h}`)}d.connect(t.refer_to.uri.toAor(),r,s)}function o(){n.notify(603)}}_receiveNotify(t){switch(z.debug("receiveNotify()"),t.event||t.reply(400),t.event.event){case"refer":{let n,a;if(t.event.params&&t.event.params.id)n=t.event.params.id,a=this._referSubscribers[n];else if(Object.keys(this._referSubscribers).length===1)a=this._referSubscribers[Object.keys(this._referSubscribers)[0]];else{t.reply(400,"Missing event id parameter");return}if(!a){t.reply(481,"Subscription does not exist");return}a.receiveNotify(t),t.reply(200);break}default:t.reply(489)}}_receiveReplaces(t){z.debug("receiveReplaces()");function n(o){if(this._status!==te.STATUS_WAITING_FOR_ACK&&this._status!==te.STATUS_CONFIRMED)return!1;const s=new Ha(this._ua);s.on("confirmed",()=>{this.terminate()}),s.init_incoming(t,o)}function a(){z.debug("Replaced INVITE rejected by the user"),t.reply(486)}this.emit("replaces",{request:t,accept:o=>{n.call(this,o)},reject:()=>{a.call(this)}})}_getNextTransactionId(){return(this.lastTransaction+1).toString()}_sendInitialRequest(t,n,a){this.ackSent=!1,this.publisherSubscribeSent=!1;const o=new sl(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout()},onTransportError:()=>{this.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});Promise.resolve().then(()=>{if(a)return a;if(t.audio||t.video)return this._localMediaStreamLocallyGenerated=!0,this.loadStream().catch(s=>{throw this._status===te.STATUS_TERMINATED?new Error("terminated"):(this._failed("local",null,L.causes.USER_DENIED_MEDIA_ACCESS),z.warn('emit "getusermediafailed" [error:%o]',s),this.emit("getusermediafailed",s),s)})}).then(s=>{if(this._status===te.STATUS_TERMINATED)throw new Error("terminated");return this._localMediaStream=s,s&&s.getTracks().forEach(r=>{this._connection.addTrack(r,s)}),this._connecting(this._request),this._createLocalDescription("offer",n).catch(r=>{throw this._failed("local",null,L.causes.WEBRTC_ERROR),r})}).then(s=>{if(this._is_canceled||this._status===te.STATUS_TERMINATED)throw new Error("terminated");const r={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaque_id},d=JSON.stringify(r);this._request.body=d,this._status=te.STATUS_INVITE_SENT,z.debug('emit "sending" [request:%o]',this._request),this.emit("sending",{request:this._request}),o.send()}).catch(s=>{this._status!==te.STATUS_TERMINATED&&z.warn(s)})}async requestAudioAndVideoPermissions(){this.stream=await this.loadStream()}async setupMediaStream(){await this.requestAudioAndVideoPermissions(),await this.processPlugins()}async changeMediaConstraints(t){this.mediaConstraints={...t},await this.processPlugins(),this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream})}async loadStream(){const t={};this.isAudioOn?this.mediaConstraints.audio?t.audio=this.mediaConstraints.audio:t.audio=!0:t.audio=!1,this.isVideoOn?this.mediaConstraints.video?t.video=this.mediaConstraints.video:t.video=!0:t.video=!1;let n=null;try{n=await navigator.mediaDevices.getUserMedia(t)}catch{try{t.video=!1,n=await navigator.mediaDevices.getUserMedia(t)}catch{t.audio=!1,t.video=!1,n=await navigator.mediaDevices.getUserMedia(t)}}return n}addTracks(t){this._connection.getSenders().forEach(n=>{this._connection.removeTrack(n)}),t.forEach(n=>{this._connection.addTrack(n)})}getRecordFileName(){return kT+this.room_id+btoa(unescape(encodeURIComponent(this.displayName)))+Date.now()}async processIceCandidates(){for(let t=0;t<this.iceCandidates.length;t++)await this._connection.addIceCandidate(this.iceCandidates[t]);this.iceCandidates=[]}async _sendConfigureMessage(t){const n=this._candidates.map(r=>({janus:"trickle",candidate:r,handle_id:this.handle_id,session_id:this.session_id})),o={configure:{janus:"message",body:{request:"configure",record:!0,filename:this.getRecordFileName(),...t},jsep:this.jsepOffer,handle_id:this.handle_id,session_id:this.session_id},trickles:[...n]},s=["Content-Type: application/json",this.getPTypeHeader(Pt.ICE)];this.sendRequest(L.INFO,{extraHeaders:s,body:JSON.stringify(o),eventHandlers:{onSuccessResponse:async r=>{this.isConfigureSent=!0;const h=r.data.split(`\r
|
135
|
+
`),_=h[h.length-1],g=JSON.parse(_);await this._connection.setRemoteDescription(g.jsep),this._candidates=[]}}})}_sendMemberStartMessage(t,n){const a={janus:"message",body:{request:"start",room:this.room_id},handle_id:t.handleId,session_id:this.session_id,jsep:n},o=["Content-Type: application/json",this.getPTypeHeader(Pt.CONFIGURE)];this.sendRequest(L.INFO,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{s.status_code===200&&await t.rtcpPeer.setLocalDescription(n)}}})}_sendTrickleMessage(t){const a={trickles:[...t.map(s=>({janus:"trickle",candidate:s,handle_id:this.handle_id,session_id:this.session_id}))]},o=[this.getPTypeHeader(Pt.TRICKLE)];this.sendRequest(L.INFO,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{}}})}async _answerAttachedStream(t,n){let a=null;const o=async h=>{if(!t.rtcpPeer||t.loaded)return;{t.loaded=!0;const y={audio:!0,video:!0};await new Promise(C=>{setTimeout(C,100)}),a=await t.rtcpPeer.createAnswer(y),this._sendMemberStartMessage(t,a)}const _=h.streams[0].getAudioTracks(),g=h.streams[0].getVideoTracks(),T=[];_[0]&&T.push(_[0]),g[0]&&T.push(g[0]);const E=new MediaStream(T);t.stream=E,this._ua.emit("memberJoin",t.memberInfo)};let s,r=[];const d=h=>{t.rtcpPeer.signalingState!=="stable"&&t.rtcpPeer.signalingState!=="have-local-offer"||(r.push(h.candidate||null),clearTimeout(s),s=setTimeout(()=>{this._sendTrickleMessage(r)},500))};t.rtcpPeer=new RTCPeerConnection,t.rtcpPeer.ontrack=o,t.rtcpPeer.onicecandidate=d,t.rtcpPeer.sender=n.sender,await t.rtcpPeer.setRemoteDescription(n.jsep)}_sendJoinMemberRequest(t){const n={janus:"message",body:{request:"join",room:this.room_id,feed:t.info.id,ptype:"subscriber"},handle_id:t.handleId,session_id:this.session_id},a=[this.getPTypeHeader(Pt.SUBSCRIBER)];this.sendRequest(L.SUBSCRIBE,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{var s,r;if(o.status_code===200){const d=JSON.parse(o.body);(r=(s=d==null?void 0:d.plugindata)==null?void 0:s.data)!=null&&r.id&&await this._answerAttachedStream(t,d)}}}})}_attachMember(t){const n={janus:"attach",opaque_id:this.opaque_id,plugin:"janus.plugin.videoroom",session_id:this.session_id},a=[this.getPTypeHeader(Pt.SUBSCRIBER)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n),eventHandlers:{onSuccessResponse:async o=>{if(o.status_code===200){const r=JSON.parse(o.body).data.id;t.handleId=r,this._sendJoinMemberRequest(t)}}}})}_detachMember(t){const n={janus:"detach",handle_id:t.handleId,session_id:this.session_id},a=[this.getPTypeHeader(Pt.SUBSCRIBER)];this.sendRequest(L.INFO,{extraHeaders:a,body:JSON.stringify(n)}),Qt.stopStreamTracks(t.memberInfo.stream),this._ua.emit("memberHangup",t.memberInfo)}receivePublishers(t){var a,o,s,r,d,h,_,g;const n={...this.memberList};(o=(a=t==null?void 0:t.plugindata)==null?void 0:a.data)==null||o.publishers.forEach(T=>{delete n[T.id],!this.memberList[T.id]&&!this.myFeedList.includes(T.id)&&T.clientID!==this.client_id&&(this.memberList[T.id]=new PT(T,this),this._attachMember(this.memberList[T.id]))}),((r=(s=t==null?void 0:t.plugindata)==null?void 0:s.data)==null?void 0:r.videoroom)==="synced"&&Object.keys(n).forEach(T=>{n[T].hangup(),delete this.memberList[T]}),this.publishers=(h=(d=t==null?void 0:t.plugindata)==null?void 0:d.data)==null?void 0:h.publishers,this.private_id=(g=(_=t==null?void 0:t.plugindata)==null?void 0:_.data)==null?void 0:g.private_id}receiveUnpublished(t){const n=this.memberList[t];n&&(n.hangup(),this._detachMember(n),delete this.memberList[t])}closeSession(){this.stream&&this.stream.getTracks().forEach(n=>{n.stop()}),Object.values(this.memberList).forEach(n=>{n.hangup(),this._detachMember(n)}),this._ua.emit("conferenceEnd",this.id)}async processPlugins(){const t=this._ua.processStreamPlugins;let n=await this.loadStream();for(const a of t)n=await a.process(n);this.stream.getTracks().forEach(a=>{this.stream.removeTrack(a),a.stop()}),n.getTracks().forEach(a=>{this.stream.addTrack(a)})}async resyncPlugins(t){const n=this._ua.processStreamPlugins.filter(a=>a.type===t);for(const a of n)a.running&&a.terminate();if(t==="video"){let a=await this.loadStream();for(const o of n)o.running&&(a=await o.start(a));this.stream.getTracks().forEach(o=>{this.stream.removeTrack(o),o.stop()}),a.getTracks().forEach(o=>{this.stream.addTrack(o)}),this._overrideSenderTracks(this.stream,this._connection),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream})}else{const a=this._ua.newStreamPlugins.find(d=>d.type===t);let s=a.getStream().clone();for(const d of n)d.running&&(s=await d.start(s));const r=a.getConnection();this._overrideSenderTracks(s,r),this._ua.emit("changePluginStream",{type:t,stream:s})}}stopProcessPlugins(t){const n=this._ua.processStreamPlugins.filter(a=>a.type===t);for(const a of n)a.running&&a.kill()}_receiveInviteResponse(t){if(z.debug("receiveInviteResponse()"),this._dialog&&t.status_code>=200&&t.status_code<=299&&!this.ackSent)if(this._dialog.id.call_id===t.call_id&&this._dialog.id.local_tag===t.from_tag&&this._dialog.id.remote_tag===t.to_tag){this.ackSent=!0,this.sendRequest(L.ACK);return}else{const n=new ua(this,t,"UAC");if(n.error!==void 0){z.debug(n.error);return}this.sendRequest(L.ACK),this.sendRequest(L.BYE);return}if(this.ackSent&&!this.publisherSubscribeSent){const n=JSON.parse(t.body);this.setupMediaStream().then(()=>{this.session_id=n.session_id,this.handle_id=n.data.id,this.client_id=Df();const a={janus:"message",body:{request:"join",room:this.room_id,ptype:"publisher",display:this.display_name,clientID:this.client_id,opaque_id:this.opaque_id},handle_id:this.handle_id},o=[this.getPTypeHeader(Pt.PUBLISHER)];this.sendRequest(L.SUBSCRIBE,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{var r,d,h,_;if(s.status_code===200){if(this.subscribeSent=!0,s.body)try{const g=JSON.parse(s.body)||{};((d=(r=g.plugindata)==null?void 0:r.data)==null?void 0:d.videoroom)==="joined"&&this.myFeedList.push(g.plugindata.data.id),(_=(h=g.plugindata)==null?void 0:h.data)!=null&&_.publishers&&this.receivePublishers(g)}catch(g){console.error(g)}this.lastTrickleReceived&&!this.isConfigureSent&&(this.addTracks(this.stream.getTracks()),this._ua.emit("changeMainVideoStream",{name:this.display_name,stream:this.stream}),this._sendConfigureMessage({audio:!0,video:!0}).then(()=>{})),this._ua.emit("conferenceStart")}}}}),this.publisherSubscribeSent=!0})}if(this._is_canceled){t.status_code>=100&&t.status_code<200?this._request.cancel(this._cancel_reason):t.status_code>=200&&t.status_code<299&&this._acceptAndTerminate(t);return}if(!(this._status!==te.STATUS_INVITE_SENT&&this._status!==te.STATUS_1XX_RECEIVED))switch(!0){case/^100$/.test(t.status_code):this._status=te.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(t.status_code):{if(!t.to_tag){z.debug("1xx response received without to tag");break}if(t.hasHeader("contact")&&!this._createDialog(t,"UAC",!0))break;if(this._status=te.STATUS_1XX_RECEIVED,!t.body){this._progress("remote",t);break}const n={originator:"remote",type:"answer",sdp:t.body};z.debug('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>this._progress("remote",t)).catch(o=>{z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)});break}case/^2[0-9]{2}$/.test(t.status_code):{if(this._status=te.STATUS_CONFIRMED,!t.body){this._acceptAndTerminate(t,400,L.causes.MISSING_SDP),this._failed("remote",t,L.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(t,"UAC"))break;break}default:{const n=ke.sipErrorCause(t.status_code);this._failed("remote",t,n)}}}_sendReinvite(t={}){z.debug("sendReinvite()");const n=ke.cloneArray(t.extraHeaders),a=ke.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null;let s=!1;n.push(`Contact: ${this._contact}`),n.push("Content-Type: application/sdp"),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(h=>{h=this._mangleOffer(h);const _={originator:"local",type:"offer",sdp:h};z.debug('emit "sdp"'),this.emit("sdp",_),this.sendRequest(L.INVITE,{extraHeaders:n,body:h,eventHandlers:{onSuccessResponse:g=>{r.call(this,g),s=!0},onErrorResponse:g=>{d.call(this,g)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{d()});function r(h){if(this._status===te.STATUS_TERMINATED||(this.sendRequest(L.ACK),s))return;if(this._handleSessionTimersInIncomingResponse(h),h.body){if(!h.hasHeader("Content-Type")||h.getHeader("Content-Type").toLowerCase()!=="application/sdp"){d.call(this);return}}else{d.call(this);return}const _={originator:"remote",type:"answer",sdp:h.body};z.debug('emit "sdp"'),this.emit("sdp",_);const g=new RTCSessionDescription({type:"answer",sdp:_.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(g)).then(()=>{a.succeeded&&a.succeeded(h)}).catch(T=>{d.call(this),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',T),this.emit("peerconnection:setremotedescriptionfailed",T)})}function d(h){a.failed&&a.failed(h)}}_sendUpdate(t={}){z.debug("sendUpdate()");const n=ke.cloneArray(t.extraHeaders),a=ke.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null,s=t.sdpOffer||!1;let r=!1;n.push(`Contact: ${this._contact}`),this._sessionTimers.running&&n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${this._sessionTimers.refresher?"uac":"uas"}`),s?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._createLocalDescription("offer",o)).then(_=>{_=this._mangleOffer(_);const g={originator:"local",type:"offer",sdp:_};z.debug('emit "sdp"'),this.emit("sdp",g),this.sendRequest(L.UPDATE,{extraHeaders:n,body:_,eventHandlers:{onSuccessResponse:T=>{d.call(this,T),r=!0},onErrorResponse:T=>{h.call(this,T)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}})}).catch(()=>{h.call(this)})):this.sendRequest(L.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:_=>{d.call(this,_)},onErrorResponse:_=>{h.call(this,_)},onTransportError:()=>{this.onTransportError()},onRequestTimeout:()=>{this.onRequestTimeout()},onDialogError:()=>{this.onDialogError()}}});function d(_){if(this._status!==te.STATUS_TERMINATED&&!r)if(this._handleSessionTimersInIncomingResponse(_),s){if(_.body){if(!_.hasHeader("Content-Type")||_.getHeader("Content-Type").toLowerCase()!=="application/sdp"){h.call(this);return}}else{h.call(this);return}const g={originator:"remote",type:"answer",sdp:_.body};z.debug('emit "sdp"'),this.emit("sdp",g);const T=new RTCSessionDescription({type:"answer",sdp:g.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(T)).then(()=>{a.succeeded&&a.succeeded(_)}).catch(E=>{h.call(this),z.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',E),this.emit("peerconnection:setremotedescriptionfailed",E)})}else a.succeeded&&a.succeeded(_)}function h(_){a.failed&&a.failed(_)}}_acceptAndTerminate(t,n,a){z.debug("acceptAndTerminate()");const o=[];n&&(a=a||L.REASON_PHRASE[n]||"",o.push(`Reason: SIP ;cause=${n}; text="${a}"`)),(this._dialog||this._createDialog(t,"UAC"))&&(this.sendRequest(L.ACK),this.sendRequest(L.BYE,{extraHeaders:o})),this._status=te.STATUS_TERMINATED}_mangleOffer(t){if(!this._localHold&&!this._remoteHold)return t;if(t=xt.parse(t),this._localHold&&!this._remoteHold){z.debug("mangleOffer() | me on hold, mangling offer");for(const n of t.media)ca.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="sendonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="sendonly")}else if(this._localHold&&this._remoteHold){z.debug("mangleOffer() | both on hold, mangling offer");for(const n of t.media)ca.indexOf(n.type)!==-1&&(n.direction="inactive")}else if(this._remoteHold){z.debug("mangleOffer() | remote on hold, mangling offer");for(const n of t.media)ca.indexOf(n.type)!==-1&&(n.direction?n.direction==="sendrecv"?n.direction="recvonly":n.direction==="recvonly"&&(n.direction="inactive"):n.direction="recvonly")}return xt.write(t)}_setLocalMediaStatus(){let t=!0,n=!0;(this._localHold||this._remoteHold)&&(t=!1,n=!1),this._audioMuted&&(t=!1),this._videoMuted&&(n=!1),this._toggleMuteAudio(!t),this._toggleMuteVideo(!n)}_handleSessionTimersInIncomingRequest(t,n){if(!this._sessionTimers.enabled)return;let a;t.session_expires&&t.session_expires>=L.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,a=t.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,a="uas"),n.push(`Session-Expires: ${this._sessionTimers.currentExpires};refresher=${a}`),this._sessionTimers.refresher=a==="uas",this._runSessionTimer()}_handleSessionTimersInIncomingResponse(t){if(!this._sessionTimers.enabled)return;let n;t.session_expires&&t.session_expires>=L.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,n=t.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uac"),this._sessionTimers.refresher=n==="uac",this._runSessionTimer()}_runSessionTimer(){const t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(()=>{this._status!==te.STATUS_TERMINATED&&this._isReadyToReOffer()&&(z.debug("runSessionTimer() | sending session refresh request"),this._sessionTimers.refreshMethod===L.UPDATE?this._sendUpdate():this._sendReinvite())},t*500):this._sessionTimers.timer=setTimeout(()=>{this._status!==te.STATUS_TERMINATED&&(z.warn("runSessionTimer() | timer expired, terminating the session"),this.terminate({cause:L.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},t*1100)}_toggleMuteAudio(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="audio");for(const a of n)a.track.enabled=!t}_toggleMuteVideo(t){const n=this._connection.getSenders().filter(a=>a.track&&a.track.kind==="video");for(const a of n)a.track.enabled=!t}_newJanusSession(t,n){z.debug("newRTCSession()"),this._ua.newJanusSession(this,{originator:t,session:this,request:n})}_connecting(t){z.debug("session connecting"),z.debug('emit "connecting"'),this.emit("connecting",{request:t})}_progress(t,n){z.debug("session progress"),z.debug('emit "progress"'),this.emit("progress",{originator:t,response:n||null})}_accepted(t,n){z.debug("session accepted"),this._start_time=new Date,z.debug('emit "accepted"'),this.emit("accepted",{originator:t,response:n||null})}_confirmed(t,n){z.debug("session confirmed"),this._is_confirmed=!0,z.debug('emit "confirmed"'),this.emit("confirmed",{originator:t,ack:n||null})}_ended(t,n,a){z.debug("session ended"),this._end_time=new Date,this._close(),z.debug('emit "ended"'),this.emit("ended",{originator:t,message:n||null,cause:a})}_failed(t,n,a){z.debug("session failed"),z.debug('emit "_failed"'),this.emit("_failed",{originator:t,message:n||null,cause:a}),this._close(),z.debug('emit "failed"'),this.emit("failed",{originator:t,message:n||null,cause:a})}_onhold(t){z.debug("session onhold"),this._setLocalMediaStatus(),z.debug('emit "hold"'),this.emit("hold",{originator:t})}_onunhold(t){z.debug("session onunhold"),this._setLocalMediaStatus(),z.debug('emit "unhold"'),this.emit("unhold",{originator:t})}_onmute({audio:t,video:n}){z.debug("session onmute"),this._setLocalMediaStatus(),z.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}_onunmute({audio:t,video:n}){z.debug("session onunmute"),this._setLocalMediaStatus(),z.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}class cr{constructor(t){if(this.headers={},t.length>0){let n=!1;const a=t.split(`\r
|
136
136
|
`),o=a.shift().split(/\s/);this.protocol=o[0],this.ident=o[1],this.code=o.length>3?parseInt(o[2]):0,this.method=o.length>3?o[3]:o[2],this.body="";for(const s of a){if(s==`-------${this.ident}$`)break;if(s===""){n=!0;continue}if(s&&n)this.body+=`${s}\r
|
137
137
|
`;else{const r=s.split(": ");this.addHeader(r[0],r[1].trim())}}}else this.ident=ke.createRandomToken(12),this.protocol="MSRP"}addHeader(t,n){this.headers[t]=n}getHeader(t){return this.headers[t]}toString(){let t=`${this.protocol} ${this.ident} ${this.code} ${this.method}`.replaceAll(/null\s|undefined\s/ig,"")+`\r
|
138
138
|
`;for(const n in this.headers)t+=`${n}: ${this.headers[n]}\r
|
@@ -155,5 +155,5 @@ a=accept-types:text/plain text/html
|
|
155
155
|
a=path:${t.getHeader("Use-Path")} msrp://${this._ua._configuration.authorization_user}.${this._ua._configuration.realm}:2856/${this.auth_id};ws
|
156
156
|
`),this._newMSRPSession("local",this._request),this._id=this._request.call_id+this._from_tag,new sl(this._ua,this._request,{onRequestTimeout:()=>{this.onRequestTimeout(),console.log("to")},onTransportError:s=>{this.onTransportError(),console.log(s)},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s),s.status_code===200&&(s.parseSDP(!0),this._status=Re.STATUS_CONFIRMED,this.target_addr=s.sdp.media[0].invalid[1].value.replaceAll("path:","").split(" ").reverse(),this.status="active",this.emit("active"),this.emit("confirmed"))}}).send(),this._status=Re.STATUS_INVITE_SENT}terminate(t={}){const n=t.cause||L.causes.BYE,a=ke.cloneArray(t.extraHeaders),o=t.body;let s,r=t.status_code,d=t.reason_phrase;if(this._status===Re.STATUS_TERMINATED)throw new qs.InvalidStateError(this._status);switch(this.status="terminated",this._status){case Re.STATUS_NULL:case Re.STATUS_INVITE_SENT:case Re.STATUS_1XX_RECEIVED:if(r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);r&&(d=d||L.REASON_PHRASE[r]||"",s=`SIP ;cause=${r} ;text="${d}"`),this._status===Re.STATUS_NULL||this._status===Re.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=s):this._status===Re.STATUS_1XX_RECEIVED&&this._request.cancel(s),this._status=Re.STATUS_CANCELED,this._failed("local",null,L.causes.CANCELED);break;case Re.STATUS_WAITING_FOR_ANSWER:case Re.STATUS_ANSWERED:if(r=r||480,r<300||r>=700)throw new TypeError(`Invalid status_code: ${r}`);this._request.reply(r,d,a,o),this._failed("local",null,L.causes.REJECTED);break;case Re.STATUS_WAITING_FOR_ACK:case Re.STATUS_CONFIRMED:if(d=t.reason_phrase||L.REASON_PHRASE[r]||"",r&&(r<200||r>=700))throw new TypeError(`Invalid status_code: ${r}`);if(r&&a.push(`Reason: SIP ;cause=${r}; text="${d}"`),this._status===Re.STATUS_WAITING_FOR_ACK&&this._direction==="incoming"&&this._request.server_transaction.state!==Gt.C.STATUS_TERMINATED){const h=this._dialog;this.receiveRequest=({method:_})=>{_===L.ACK&&(this.sendRequest(L.BYE,{extraHeaders:a,body:o}),h.terminate())},this._request.server_transaction.on("stateChanged",()=>{this._request.server_transaction.state===Gt.C.STATUS_TERMINATED&&(this.sendRequest(L.BYE,{extraHeaders:a,body:o}),h.terminate())}),this._ended("local",null,n),this._dialog=h,this._ua.newDialog(h)}else this.sendRequest(L.BYE,{extraHeaders:a,body:o}),this._ended("local",null,n)}}sendRequest(t,n){return this._dialog.sendRequest(t,n)}authenticate(t){this.status="auth";let n=new cr("");n.method="AUTH",n.addHeader("To-Path",`msrp://${this._ua._configuration.realm}:2856;ws`),n.addHeader("From-Path",`msrp://${this.credentials.username}.${this.credentials.realm}:2856/${this.auth_id};ws`),t&&n.addHeader("Authorization",t.toString());let a=n.toString(),o=[];for(var s=0;s<a.length;s++)o.push(a.charCodeAt(s).toString(16));this._connection.send(n.toString())}onmessage(t){const n=new cr(t.data);if(this.status==="auth"&&n.code===401){const a=this.parseAuth(n.getHeader("WWW-Authenticate")),o=new Km(this.credentials);o.authenticate({method:"AUTH",ruri:`msrp://${this._ua._configuration.realm}:2856;ws`,body:null},a,ke.createRandomToken(12)),this.authenticate(o)}this.status==="auth"&&n.code===200&&this._direction==="outgoing"?(this.my_addr.push(n.getHeader("To-Path")),this.my_addr.push(n.getHeader("Use-Path")),this.status="active",this.inviteParty(n)):this.status==="auth"&&n.code===200&&this._direction==="incoming"?(this.my_addr.push(n.getHeader("To-Path")),this.my_addr.push(n.getHeader("Use-Path")),this.status="active",this.acceptParty(n),this.emit("confirmed")):n.method==="SEND"&&(this._sendOk(n),this._sendReport(n),n.direction="incoming",this.emit("newMessage",n),this._msgHistory.push(n),this.emit("msgHistoryUpdate",this._msgHistory)),n.code===480&&this._close()}onclose(){console.log("close")}onopen(){const t=new RTCPeerConnection({iceServers:[]});t.createDataChannel(""),t.createOffer().then(t.setLocalDescription.bind(t)),t.onicecandidate=n=>{if(!n||!n.candidate||!n.candidate.candidate)return;const a=/([0-9]{1,3}(\.[0-9]{1,3}){3})/,o=n.candidate.candidate.match(a);this.my_ip=o&&o[1],t.onicecandidate=()=>{},this.authenticate(null)}}onerror(t){console.log(t)}_receiveInviteResponse(t){if(console.log("resp0000000000000",t),this._dialog&&t.status_code>=200&&t.status_code<=299)if(console.log("200000000000000"),this._dialog.id.call_id===t.call_id&&this._dialog.id.local_tag===t.from_tag&&this._dialog.id.remote_tag===t.to_tag){this.sendRequest(L.ACK);return}else{const n=new ea(this,t,"UAC");if(n.error!==void 0){console.log(n.error);return}this.sendRequest(L.ACK),this.sendRequest(L.BYE);return}if(this._is_canceled){t.status_code>=100&&t.status_code<200?this._request.cancel(this._cancel_reason):t.status_code>=200&&t.status_code<299&&this._acceptAndTerminate(t);return}if(!(this._status!==Re.STATUS_INVITE_SENT&&this._status!==Re.STATUS_1XX_RECEIVED))switch(console.log("start Switch"),!0){case/^100$/.test(t.status_code):this._status=Re.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(t.status_code):{if(!t.to_tag){console.log("1xx response received without to tag");break}if(t.hasHeader("contact")&&!this._createDialog(t,"UAC",!0))break;if(this._status=Re.STATUS_1XX_RECEIVED,!t.body){this._progress("remote",t);break}const n={originator:"remote",type:"answer",sdp:t.body};console.log('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>this._progress("remote",t)).catch(o=>{console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)});break}case/^2[0-9]{2}$/.test(t.status_code):{if(console.log("maybe here???"),this._status=Re.STATUS_CONFIRMED,!t.body){this._acceptAndTerminate(t,400,L.causes.MISSING_SDP),console.log("failed 3"),this._failed("remote",t,L.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(t,"UAC"))break;const n={originator:"remote",type:"answer",sdp:t.body};console.log('emit "sdp"'),this.emit("sdp",n),new RTCSessionDescription({type:"answer",sdp:n.sdp}),this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>{if(this._connection.signalingState==="stable")return this._connection.createOffer(this._rtcOfferConstraints).then(a=>this._connection.setLocalDescription(a)).catch(a=>{this._acceptAndTerminate(t,500,a.toString()),console.log("failed 4"),this._failed("local",t,L.causes.WEBRTC_ERROR)})}).then(()=>{this._handleSessionTimersInIncomingResponse(t),this._accepted("remote",t),this.sendRequest(L.ACK),this._confirmed("local",null)});break}default:{const n=ke.sipErrorCause(t.status_code);console.log("failed 5"),this._failed("remote",t,n)}}}sendMSRP(t){const n=new cr("");n.method="SEND",n.addHeader("To-Path",`${this.my_addr[1]} ${this.target_addr[1]} ${this.target_addr[0]}`),n.addHeader("From-Path",`${this.my_addr[0]}`),n.addHeader("Message-ID",ke.createRandomToken(10)),n.addHeader("Byte-Range","1-25/25"),n.addHeader("Content-Type","text/plain"),n.addHeader("Success-Report","yes"),n.addHeader("Failure-Report","yes"),n.body=t;let a=n.toString();console.log(a);let o=[];for(var s=0;s<a.length;s++)o.push(a.charCodeAt(s).toString(16));console.log(o),this._connection.send(n.toString()),n.direction="outgoing",this.emit("newMessage",n),this._msgHistory.push(n),this.emit("msgHistoryUpdate",this._msgHistory)}_sendOk(t){let n=t.ident,a=t.getHeader("Message-ID"),o=new cr("");o.method="200 OK",o.addHeader("To-Path",`${this.my_addr[1]}`),o.addHeader("From-Path",`${this.my_addr[0]}`),o.addHeader("Message-ID",a),o.ident=n;let s=o.toString();console.log(s);let r=[];for(var d=0;d<s.length;d++)r.push(s.charCodeAt(d).toString(16));console.log(r),this._connection.send(o.toString())}_sendReport(t){let n=t.ident,a=t.getHeader("Message-ID"),o=new cr("");o.method="REPORT",o.addHeader("To-Path",`${t.getHeader("From-Path")}`),o.addHeader("From-Path",`${this.my_addr[0]}`),o.addHeader("Message-ID",a),o.addHeader("Byte-Range","1-25/25"),o.addHeader("Status","000 200 OK"),o.ident=n;let s=o.toString();console.log(s);let r=[];for(var d=0;d<s.length;d++)r.push(s.charCodeAt(d).toString(16));console.log(r),this._connection.send(o.toString())}parseAuth(t){const n={},a=t.replace("Digest","").split(",");for(const o of a){const s=o.trim().split("=");n[s[0]]=s[1].match('^"(.+)"$')[1]}return n}init_incoming(t,n){let a;const o=t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0;if(t.body&&o!=="application/sdp"){t.reply(415);return}if(this._status=Re.STATUS_INVITE_RECEIVED,this._from_tag=t.from_tag,this._id=t.call_id+this._from_tag,this._request=t,this._contact=this._ua.contact.toString(),t.hasHeader("expires")&&(a=t.getHeader("expires")*1e3),t.to_tag=ke.newTag(),!this._createDialog(t,"UAS",!0)){t.reply(500,"Missing Contact header field");return}t.body?this._late_sdp=!1:this._late_sdp=!0,this._status=Re.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(()=>{t.reply(408),console.log("failed 6"),this._failed("local",null,L.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),a&&(this._timers.expiresTimer=setTimeout(()=>{this._status===Re.STATUS_WAITING_FOR_ANSWER&&(t.reply(487),console.log("failed 7"),this._failed("system",null,L.causes.EXPIRES))},a)),this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from,n&&n(this),t.parseSDP(!0),this.target_addr=t.sdp.media[0].invalid[1].value.replaceAll("path:","").split(" ").reverse(),this._newMSRPSession("remote",t),this._status!==Re.STATUS_TERMINATED&&(t.reply(180,null,[`Contact: ${this._ua._contact}`]),this._progress("local",null))}_failed(t,n,a){this.emit("_failed",{originator:t,message:n||null,cause:a}),this._close(),this.emit("failed",{originator:t,message:n||null,cause:a})}_close(){if(console.log("CLOSE SESSION"),this._status!==Re.STATUS_TERMINATED){if(this._status=Re.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(t){console.log("close() | error closing the RTCPeerConnection: %o",t)}for(const t in this._timers)Object.prototype.hasOwnProperty.call(this._timers,t)&&clearTimeout(this._timers[t]);clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog);for(const t in this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(const t in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,t)&&delete this._referSubscribers[t];this._ua.destroyMSRPSession(this)}}_createDialog(t,n,a){const o=n==="UAS"?t.to_tag:t.from_tag,s=n==="UAS"?t.from_tag:t.to_tag,r=t.call_id+o+s;let d=this._earlyDialogs[r];if(a)return d?!0:(d=new ea(this,t,n,ea.C.STATUS_EARLY),d.error?(console.log("failed 8"),this._failed("remote",t,L.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[r]=d,!0));{if(this._from_tag=t.from_tag,this._to_tag=t.to_tag,d)return d.update(t,n),this._dialog=d,delete this._earlyDialogs[r],!0;const h=new ea(this,t,n);return h.error?(console.log("failed 9"),this._failed("remote",t,L.causes.INTERNAL_ERROR),!1):(this._dialog=h,!0)}}_newMSRPSession(t,n){this._ua.newMSRPSession(this,{originator:t,session:this,request:n})}_progress(t,n){this.emit("progress",{originator:t,response:n||null})}isEnded(){switch(this._status){case Re.STATUS_CANCELED:case Re.STATUS_TERMINATED:return!0;default:return!1}}_accepted(t,n){console.log("session accepted"),this._start_time=new Date,console.log('emit "accepted"'),this.emit("accepted",{originator:t,response:n||null})}_confirmed(t,n){console.log("session confirmed"),this._is_confirmed=!0,console.log('emit "confirmed"'),this.emit("confirmed",{originator:t,ack:n||null})}_ended(t,n,a){console.log("session ended"),this._end_time=new Date,this._close(),console.log('emit "ended"'),this.emit("ended",{originator:t,message:n||null,cause:a})}_handleSessionTimersInIncomingResponse(t){if(!this._sessionTimers.enabled)return;let n;t.session_expires&&t.session_expires>=L.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=t.session_expires,n=t.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uac"),this._sessionTimers.refresher=n==="uac",this._runSessionTimer()}receiveRequest(t){if(console.log("receiveRequest()"),t.method===L.CANCEL)(this._status===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",t,L.causes.CANCELED));else switch(t.method){case L.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(!t.body){this.terminate({cause:L.causes.MISSING_SDP,status_code:400});break}const n={originator:"remote",type:"answer",sdp:t.body};console.log('emit "sdp"'),this.emit("sdp",n);const a=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(()=>this._connection.setRemoteDescription(a)).then(()=>{this._is_confirmed||this._confirmed("remote",t)}).catch(o=>{this.terminate({cause:L.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),console.log('emit "peerconnection:setremotedescriptionfailed" [error:%o]',o),this.emit("peerconnection:setremotedescriptionfailed",o)})}else this._is_confirmed||this._confirmed("remote",t);break;case L.BYE:this._status===Re.STATUS_CONFIRMED||this._status===Re.STATUS_WAITING_FOR_ACK?(t.reply(200),this._ended("remote",t,L.causes.BYE)):this._status===Re.STATUS_INVITE_RECEIVED||this._status===Re.STATUS_WAITING_FOR_ANSWER?(t.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",t,L.causes.BYE)):t.reply(403,"Wrong Status");break;case L.INVITE:this._status===Re.STATUS_CONFIRMED?t.hasHeader("replaces")?this._receiveReplaces(t):this._receiveReinvite(t):t.reply(403,"Wrong Status");break;case L.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?(t.hasHeader("Content-Type")?t.getHeader("Content-Type").toLowerCase():void 0)!==void 0?new yu(this).init_incoming(t):t.reply(415):t.reply(403,"Wrong Status");break;case L.UPDATE:this._status===Re.STATUS_CONFIRMED?this._receiveUpdate(t):t.reply(403,"Wrong Status");break;case L.REFER:this._status===Re.STATUS_CONFIRMED?this._receiveRefer(t):t.reply(403,"Wrong Status");break;case L.NOTIFY:this._status===Re.STATUS_CONFIRMED?this._receiveNotify(t):t.reply(403,"Wrong Status");break;default:t.reply(501)}}onTransportError(){console.log("onTransportError()"),this._status!==Re.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.CONNECTION_ERROR,cause:L.causes.CONNECTION_ERROR})}onRequestTimeout(){console.log("onRequestTimeout()"),this._status!==Re.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:L.causes.REQUEST_TIMEOUT,cause:L.causes.REQUEST_TIMEOUT})}onDialogError(){console.log("onDialogError()"),this._status!==Re.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:L.causes.DIALOG_ERROR,cause:L.causes.DIALOG_ERROR})}}var MT=Zt();const Iu=ze(MT),fa=new Wa("Parser"),LT=(c,t)=>{let n,a,o=c.indexOf(`\r
|
157
157
|
`);if(o===-1){fa.warn("parseMessage() | no CRLF found, not a SIP message");return}const s=c.substring(0,o);let r=Iu.parse(s,"Request_Response");if(r===-1){fa.warn(`parseMessage() | error parsing first line of SIP message: "${s}"`);return}else r.status_code?(n=new pr.IncomingResponse,n.status_code=r.status_code,n.reason_phrase=r.reason_phrase):(n=new pr.IncomingRequest(t),n.method=r.method,n.ruri=r.uri);n.data=c;let d=o+2;for(;;){if(o=$T(c,d),o===-2){a=d+2;break}else if(o===-1){fa.warn("parseMessage() | malformed message");return}if(r=HT(n,c,d,o),r!==!0){fa.warn("parseMessage() |",r.error);return}d=o+2}if(n.hasHeader("content-length")){const h=n.getHeader("content-length");n.body=c.substr(a,h)}else n.body=c.substring(a);return n};function $T(c,t){let n=t,a=0,o=0;if(c.substring(n,n+2).match(/(^\r\n)/))return-2;for(;a===0;){if(o=c.indexOf(`\r
|
158
|
-
`,n),o===-1)return o;!c.substring(o+2,o+4).match(/(^\r\n)/)&&c.charAt(o+2).match(/(^\s+)/)?n=o+2:a=o}return a}function HT(c,t,n,a){let o;const s=t.indexOf(":",n),r=t.substring(n,s).trim(),d=t.substring(s+1,a).trim();switch(r.toLowerCase()){case"via":case"v":c.addHeader("via",d),c.getHeaders("via").length===1?(o=c.parseHeader("Via"),o&&(c.via=o,c.via_branch=o.branch)):o=0;break;case"from":case"f":c.setHeader("from",d),o=c.parseHeader("from"),o&&(c.from=o,c.from_tag=o.getParam("tag"));break;case"to":case"t":c.setHeader("to",d),o=c.parseHeader("to"),o&&(c.to=o,c.to_tag=o.getParam("tag"));break;case"record-route":if(o=Iu.parse(d,"Record_Route"),o===-1)o=void 0;else for(const h of o)c.addHeader("record-route",d.substring(h.possition,h.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=h.parsed;break;case"call-id":case"i":c.setHeader("call-id",d),o=c.parseHeader("call-id"),o&&(c.call_id=d);break;case"contact":case"m":if(o=Iu.parse(d,"Contact"),o===-1)o=void 0;else for(const h of o)c.addHeader("contact",d.substring(h.possition,h.offset)),c.headers.Contact[c.getHeaders("contact").length-1].parsed=h.parsed;break;case"content-length":case"l":c.setHeader("content-length",d),o=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",d),o=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",d),o=c.parseHeader("cseq"),o&&(c.cseq=o.value),c instanceof pr.IncomingResponse&&(c.method=o.method);break;case"max-forwards":c.setHeader("max-forwards",d),o=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",d),o=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",d),o=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",d),o=c.parseHeader("session-expires"),o&&(c.session_expires=o.expires,c.session_expires_refresher=o.refresher);break;case"refer-to":case"r":c.setHeader("refer-to",d),o=c.parseHeader("refer-to"),o&&(c.refer_to=o);break;case"replaces":c.setHeader("replaces",d),o=c.parseHeader("replaces"),o&&(c.replaces=o);break;case"event":case"o":c.setHeader("event",d),o=c.parseHeader("event"),o&&(c.event=o);break;default:c.addHeader(r,d),o=0}return o===void 0?{error:`error parsing header "${r}"`}:!0}const FT={parseMessage:LT},Wi=new Wa("Registrator"),ha=10;class jT{constructor(t,n){this._reg_id=1,this._ua=t,this._transport=n,this._registrar=t.configuration.registrar_server,this._expires=t.configuration.register_expires,this._call_id=Ts.createRandomToken(22),this._cseq=0,this._to_uri=t.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString();const a=this._contact.indexOf(">");if(a!==-1){const o=this._contact.slice(0,a)+this._contact.slice(a+1,this._contact.length);this._contact=o}this._extra_contact="",this._extraContactParams="",this._extra_contact+=";+sip.ice",this._extraHeaders=[],this._sipInstance=`"<urn:uuid:${this._ua.configuration.instance_id}>"`,this._extra_contact+=`;reg-id=${this._reg_id}`,this._extra_contact+=`;+sip.instance=${this._sipInstance}`}get registered(){return this._registered}setExtraHeaders(t){Array.isArray(t)||(t=[]),this._extraHeaders=t.slice()}setExtraContactParams(t){t instanceof Object||(t={}),this._extraContactParams="";for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)){const a=t[n];this._extraContactParams+=`;${n}`,a&&(this._extraContactParams+=`=${a}`)}}setExtraContactUriParams(t){t instanceof Object||(t={}),this._extraContactParams="";for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)){const a=t[n];this._extraContactParams+=`;${n}`,a&&(this._extraContactParams+=`=${a}`)}}register(){if(this._registering){Wi.debug("Register request in progress...");return}const t=this._extraHeaders.slice();t.push(`Contact: ${this._contact}${this._extraContactParams}>${this._extra_contact};expires=${this._expires}`),t.push(`Expires: ${this._expires}`);const n=new yt.OutgoingRequest(L.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),a=new sl(this._ua,n,{onRequestTimeout:()=>{this._registrationFailure(null,L.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,L.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:o=>{if(o.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):{if(this._registering=!1,!o.hasHeader("Contact")){Wi.debug("no Contact header in response to REGISTER, response ignored");break}const s=o.headers.Contact.reduce((_,g)=>_.concat(g.parsed),[]);let r=s.find(_=>this._sipInstance===_.getParam("+sip.instance")&&this._reg_id===parseInt(_.getParam("reg-id")));if(r||(r=s.find(_=>_.uri.user===this._ua.contact.uri.user)),!r){Wi.debug("no Contact header pointing to us, response ignored");break}let d=r.getParam("expires");!d&&o.hasHeader("expires")&&(d=o.getHeader("expires")),d||(d=this._expires),d=Number(d),d<ha&&(d=ha);const h=d>64?d*1e3/2+Math.floor((d/2-32)*1e3*Math.random()):d*1e3-5e3;this._registrationTimer=setTimeout(()=>{this._registrationTimer=null,this._ua.listeners("registrationExpiring").length===0?this.register():this._ua.emit("registrationExpiring")},h),r.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),this._registered||(this._registered=!0,this._ua.registered({response:o}));break}case/^423$/.test(o.status_code):{o.hasHeader("min-expires")?(this._expires=Number(o.getHeader("min-expires")),this._expires<ha&&(this._expires=ha),this.register()):(Wi.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(o,L.causes.SIP_FAILURE_CODE));break}default:{const s=Ts.sipErrorCause(o.status_code);this._registrationFailure(o,s)}}}});this._registering=!0,a.send()}unregister(t={}){if(!this._registered){Wi.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const n=this._extraHeaders.slice();t.all?n.push(`Contact: *${this._extraContactParams}`):n.push(`Contact: ${this._contact}${this._extraContactParams}>${this._extra_contact};expires=0`),n.push("Expires: 0");const a=new yt.OutgoingRequest(L.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new sl(this._ua,a,{onRequestTimeout:()=>{this._unregistered(null,L.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,L.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:s=>{switch(!0){case/^1[0-9]{2}$/.test(s.status_code):break;case/^2[0-9]{2}$/.test(s.status_code):this._unregistered(s);break;default:{const r=Ts.sipErrorCause(s.status_code);this._unregistered(s,r)}}}}).send()}close(){this._registered&&this.unregister()}onTransportClosed(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}_registrationFailure(t,n){this._registering=!1,this._ua.registrationFailed({response:t||null,cause:n}),this._registered&&(this._registered=!1,this._ua.unregistered({response:t||null,cause:n}))}_unregistered(t,n){this._registering=!1,this._registered=!1,this._ua.unregistered({response:t||null,cause:n||null})}}const tt=console,Vs={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},qT=wT;class VT extends qT{constructor(t){super(t),this._msrp_sessions=[],this._transactions={nist:{},nict:{},ist:{},ict:{}},this._janus_sessions=[],this.newStreamPlugins=[],this.processStreamPlugins=[],this._registrator=new jT(this)}call(t,n){return super.call(t,n)}joinVideoCall(t,n,a){tt.debug("call()");const o=new Ha(this);return o.configureMedia({audio:!0,video:!0}),o.connect(t,n,a),o}startScreenShare(){tt.debug("startScreenShare()");for(const t in this._janus_sessions)this._janus_sessions[t].connectScreenShare()}changeMediaConstraints(t){for(const n in this._janus_sessions)this._janus_sessions[n].changeMediaConstraints(t)}startBlur(){for(const t in this._janus_sessions)this._janus_sessions[t].connectBlur()}stopBlur(){for(const t in this._janus_sessions)this._janus_sessions[t].stopBlur()}_loadConfig(t){try{rl.load(this._configuration,t)}catch(s){throw s}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=Ts.newUUID());let n;typeof window<"u"&&typeof window.document<"u"?n=window==null?void 0:window.navigator.userAgent:typeof self<"u"&&self.navigator&&(n=self.navigator.userAgent),n+=" "+De.USER_AGENT,this._configuration.user_agent=t.overrideUserAgent&&typeof t.overrideUserAgent=="function"?t.overrideUserAgent(n):n,t.onTransportCallback&&typeof t.onTransportCallback=="function"&&(this.onTransportCallback=t.onTransportCallback),this._configuration.jssip_id=Ts.createRandomToken(5);const a=this._configuration.uri.clone();a.user=null,this._configuration.hostport_params=a.toString().replace(/^sip:/i,"");try{this._transport=new eT(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=BT.bind(this),this._transport.onconnect=GT.bind(this),this._transport.ondisconnect=WT.bind(this),this._transport.ondata=KT.bind(this)}catch(s){throw tt.warn(s),new qs.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){const s=this._configuration.uri.clone();s.user=null,s.clearParams(),s.clearHeaders(),this._configuration.registrar_server=s}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new In("sip",Ts.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(s={}){const r=s.anonymous||null,d=s.outbound||null;let h="<";return r?h+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":h+=this.pub_gruu||this.uri.toString(),d&&(r?!this.temp_gruu:!this.pub_gruu)&&(h+=";ob"),h+=">",h}};const o=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const s in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,s)&&(o.indexOf(s)!==-1?Object.defineProperty(this._configuration,s,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,s,{writable:!1,configurable:!1}));tt.debug("configuration parameters after validation:");for(const s in this._configuration)if(Object.prototype.hasOwnProperty.call(rl.settings,s))switch(s){case"uri":case"registrar_server":tt.debug(`- ${s}: ${this._configuration[s]}`);break;case"password":case"ha1":case"authorization_jwt":tt.debug(`- ${s}: NOT SHOWN`);break;default:tt.debug(`- ${s}: ${JSON.stringify(this._configuration[s])}`)}}newMSRPSession(t,n){t.on("msgHistoryUpdate",a=>{console.log(a)}),this._msrp_sessions[t.id]=t,this.emit("newMSRPSession",n)}newJanusSession(t,n){this._janus_sessions[t.id]=t,this.newStreamPlugins.forEach(a=>{a.setSession(t)}),this.processStreamPlugins.forEach(a=>{a.setSession(t)}),this.emit("newJanusSession",n)}kill(){}destroyMSRPSession(t){delete this._msrp_sessions[t.id]}destroyJanusSession(t){delete this._janus_sessions[t.id]}receiveRequest(t){var s,r,d,h;const n=t.method;if(t.ruri.user!==this._configuration.uri.user&&t.ruri.user!==this._contact.uri.user){tt.debug("Request-URI does not point to us"),t.method!==De.ACK&&t.reply_sl(404);return}if(t.ruri.scheme===De.SIPS){t.reply_sl(416);return}if(Gt.checkTransaction(this,t))return;if(n===De.INVITE?new Gt.InviteServerTransaction(this,this._transport,t):n!==De.ACK&&n!==De.CANCEL&&new Gt.NonInviteServerTransaction(this,this._transport,t),n===De.OPTIONS){if(this.listeners("newOptions").length===0){t.reply(200);return}new Qc.Options(this).init_incoming(t)}else if(n===De.MESSAGE){if(this.listeners("newMessage").length===0){t.reply(405);return}new Qc.Message(this).init_incoming(t)}else if(n===De.INVITE&&!t.to_tag&&this.listeners("newRTCSession").length===0){t.reply(405);return}let a,o;if(t.to_tag)if(a=this._findDialog(t.call_id,t.from_tag,t.to_tag),a)a.receiveRequest(t);else if(n===De.NOTIFY)if(o=this._findSession(t),o)o.receiveRequest(t);else{if(t.body)try{const _=JSON.parse(t.body)||{};(r=(s=_.plugindata)==null?void 0:s.data)!=null&&r.publishers&&Object.values(this._janus_sessions)[0].receivePublishers(_),(h=(d=_.plugindata)==null?void 0:d.data)!=null&&h.unpublished&&Object.values(this._janus_sessions)[0].receiveUnpublished(_.plugindata.data.unpublished)}catch(_){console.error(_)}t.reply(200)}else n!==De.ACK&&t.reply(481);else switch(n){case De.INVITE:if(window.RTCPeerConnection)if(t.hasHeader("replaces")){const _=t.replaces;a=this._findDialog(_.call_id,_.from_tag,_.to_tag),a?(o=a.owner,o.isEnded()?t.reply(603):o.receiveRequest(t)):t.reply(481)}else t.body.search(/MSRP/ig)>-1?(o=new ru(this),o.init_incoming(t)):t.body.search(/JANUS/ig)>-1||(o=new $g(this),o.init_incoming(t));else tt.warn("INVITE received but WebRTC is not supported"),t.reply(488);break;case De.BYE:t.reply(481);break;case De.CANCEL:o=this._findSession(t),o?o.receiveRequest(t):tt.debug("received CANCEL request for a non existent session");break;case De.ACK:break;case De.NOTIFY:this.emit("sipEvent",{event:t.event,request:t}),t.reply(200);break;default:t.reply(405);break}}startMSRP(t,n){tt.debug("startMSRP()",n);const a=new ru(this);return a.connect(t),a}startJanus(t,n){tt.debug("startJanus()",n);const a=new ru(this);return a.connect(t),a}terminateMSRPSessions(t){tt.debug("terminateSessions()");for(const n in this._msrp_sessions)this._msrp_sessions[n].isEnded()||this._msrp_sessions[n].terminate(t)}terminateJanusSessions(t){tt.debug("terminateSessions()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||this._janus_sessions[n].terminate(t)}enableJanusAudio(t){tt.debug("enableJanusAudio()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||(t?this._janus_sessions[n].startAudio():this._janus_sessions[n].stopAudio())}enableJanusVideo(t){tt.debug("enableJanusVideo()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||(t?this._janus_sessions[n].startVideo():this._janus_sessions[n].stopVideo())}terminateAllSessions(){for(const t in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,t)){tt.debug(`closing session ${t}`);try{this._sessions[t].terminate()}catch(n){console.error(n)}}}stop(t=!0){if(console.log("IN STOP"),tt.debug("stop()"),this._dynConfiguration={},this._status===Vs.STATUS_USER_CLOSED){tt.debug("UA already closed");return}this._registrator.close();const n=Object.keys(this._sessions).length;t&&this.terminateAllSessions();for(const o in this._msrp_sessions)if(Object.prototype.hasOwnProperty.call(this._msrp_sessions,o)){tt.debug(`closing session ${o}`);try{this._msrp_sessions[o].terminate()}catch(s){console.error(s)}}for(const o in this._janus_sessions)if(Object.prototype.hasOwnProperty.call(this._janus_sessions,o)){tt.debug(`closing session ${o}`);try{this._janus_sessions[o].terminate()}catch(s){console.error(s)}}for(const o in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,o))try{this._applicants[o].close()}catch(s){console.error(s)}this._status=Vs.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&&n===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}}function BT(c){this.emit("connecting",c)}function GT(c){this._status!==Vs.STATUS_USER_CLOSED&&(this._status=Vs.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function WT(c){const t=["nict","ict","nist","ist"];for(const n of t)for(const a in this._transactions[n])Object.prototype.hasOwnProperty.call(this._transactions[n],a)&&this._transactions[n][a].onTransportError();this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==Vs.STATUS_USER_CLOSED&&(this._status=Vs.STATUS_NOT_READY,this._error=Vs.NETWORK_ERROR)}function KT(c){const t=c.transport;let n=c.message;const a=n;if(n=FT.parseMessage(n,this),this.onTransportCallback&&typeof this.onTransportCallback=="function"&&this.onTransportCallback(n,a),!!n&&!(this._status===Vs.STATUS_USER_CLOSED&&n instanceof pr.IncomingRequest)&&pT(n,this,t)){if(n instanceof pr.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof pr.IncomingResponse){let o;switch(n.method){case De.INVITE:o=this._transactions.ict[n.via_branch],o&&o.receiveResponse(n);break;case De.ACK:break;default:o=this._transactions.nict[n.via_branch],o&&o.receiveResponse(n);break}}}}const YT=["roomId","_audioMuted","_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","_localHold","_videoMuted","status","start_time","_remote_identity","audioTag","isOnHold","localMuted","autoAnswer","putOnHoldTimestamp"],JT=["_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","status","start_time","_remote_identity","target_addr"];function Nf(c){const t={};return YT.forEach(n=>{c[n]!==void 0&&(t[n]=c[n])}),t.localHold=c._localHold,t}function Uf(c){const t={};return JT.forEach(n=>{c[n]!==void 0&&(t[n]=c[n])}),t}function Pf(c,t){const n=new AudioContext,a=n.createMediaStreamSource(c),o=n.createMediaStreamDestination(),s=n.createGain();return a.connect(s),s.connect(o),s.gain.value=t,o.stream}function zT(c,t,n,a){if(wh())return;const o=document.createElement("audio");o.id=t._id,o.className="audioTag",o.srcObject=c,o.setSinkId(n),o.volume=a,o.play(),t.audioTag=o}function XT(c){if(c&&typeof c.log=="function"&&typeof c.warn=="function"&&typeof c.error=="function")return!0}function wh(){return/Mobi|react-native|Android|iPhone/i.test(navigator.userAgent)}const QT=ut,ZT=Zt(),Dt=new QT("WebSocketInterface");var ev=class{constructor(t){Dt.debug('new() [url:"%s"]',t),this._url=t,this._sip_uri=null,this._via_transport=null,this._ws=null;const n=ZT.parse(t,"absoluteURI");if(n===-1)throw Dt.warn(`invalid WebSocket URI: ${t}`),new TypeError(`Invalid argument: ${t}`);if(n.scheme!=="wss"&&n.scheme!=="ws")throw Dt.warn(`invalid WebSocket URI scheme: ${n.scheme}`),new TypeError(`Invalid argument: ${t}`);this._sip_uri=`sip:${n.host}${n.port?`:${n.port}`:""};transport=ws`,this._via_transport=n.scheme.toUpperCase()}get via_transport(){return this._via_transport}set via_transport(t){this._via_transport=t.toUpperCase()}get sip_uri(){return this._sip_uri}get url(){return this._url}connect(){if(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(t){this._onError(t)}}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(t){return Dt.debug("send()"),this.isConnected()?(this._ws.send(t),!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:t,code:n,reason:a}){Dt.debug(`WebSocket ${this._url} closed`),t===!1&&Dt.debug("WebSocket abrupt disconnection"),this.ondisconnect(!t,n,a)}_onMessage({data:t}){Dt.debug("received WebSocket message"),this.ondata(t)}_onError(t){Dt.warn(`WebSocket ${this._url} error: `,t)}};const bu=Fa,tv=De,sv=As,nv=At(),rv=bh,iv=ys(),lv=$u(),av=Zt(),ov=ev,uv=gr("JsSIP");uv("version %s",bu.version);var cv={C:tv,Exceptions:sv,Utils:nv,UA:rv,URI:iv,NameAddrHeader:lv,WebSocketInterface:ov,Grammar:av,debug:gr,get name(){return bu.title},get version(){return bu.version}};const fv=ze(cv);function iu(c){return c<10?`0${c}`:`${c}`}function hv(c){let t=c.hours||0,n=c.minutes||0,a=c.seconds||0;a++,a===60&&(a=0,n++,n===60&&(n=0,t++));const o=`${iu(t)}:${iu(n)}:${iu(a)}`;return{seconds:a,minutes:n,hours:t,formatted:o}}var Ct={};Ct.forEach=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)if(o in c){const s=Promise.resolve(c[o]).then(r=>t.call(n||globalThis,r,o,c));a.push(s)}await Promise.all(a)};Ct.forEachSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)a in c&&await t.call(n||globalThis,await c[a],a,c)};Ct.map=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)o in c&&(a[o]=Promise.resolve(c[o]).then(s=>t.call(n||globalThis,s,o,c)));return Promise.all(a)};Ct.mapSeries=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)o in c&&(a[o]=await t.call(n||globalThis,await c[o],o,c));return a};Ct.find=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a();let s=1;for(let r=0;r<c.length;r++){const d=h=>{h?a(c[r]):s===c.length&&a(),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}});Ct.findSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(await t.call(n||globalThis,await c[a],a,c))return c[a]};Ct.findIndex=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a(-1);let s=1;for(let r=0;r<c.length;r++){const d=h=>{h?a(r):s===c.length&&a(-1),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}});Ct.findIndexSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(await t.call(n||globalThis,await c[a],a,c))return a};Ct.some=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a(!1);let s=1;for(let r=0;r<c.length;r++){if(!(r in c)){s++;continue}const d=h=>{h?a(!0):s===c.length&&a(!1),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}});Ct.someSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(a in c&&await t.call(n||globalThis,await c[a],a,c))return!0;return!1};Ct.every=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a(!0);let s=1;for(let r=0;r<c.length;r++){if(!(r in c)){s++;continue}const d=h=>{h?s===c.length&&a(!0):a(!1),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}});Ct.everySeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(a in c&&!await t.call(n||globalThis,await c[a],a,c))return!1;return!0};Ct.filter=(c,t,n)=>new Promise(async(a,o)=>{const s=[];for(let d=0;d<c.length;d++)d in c&&(s[d]=Promise.resolve(c[d]).then(h=>t.call(n||globalThis,h,d,c)).catch(o));const r=[];for(let d=0;d<s.length;d++)await s[d]&&r.push(await c[d]);a(r)});Ct.filterSeries=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)o in c&&await t.call(n||globalThis,await c[o],o,c)&&a.push(await c[o]);return a};Ct.reduce=async(c,t,n)=>{if(c.length===0&&n===void 0)throw TypeError("Reduce of empty array with no initial value");let a,o;for(n!==void 0?(o=n,a=0):(o=c[0],a=1),a;a<c.length;a++)a in c&&(o=await t(await o,await c[a],a,c));return o};var Oh={};(function(c){const t=Ct;Object.keys(t).forEach(n=>{const a=n.charAt(0).toUpperCase()+n.slice(1);c[`async${a}`]=async function(...o){return t[n](this,...o)}})})(Oh);const dv=Ct,_v=Oh;var pv=Object.assign(dv,{instanceMethods:_v});const Cn=new AudioContext,Xt={NEW_CALL:"new_call",CALL_CONFIRMED:"confirmed",CALL_FAILED:"failed",CALL_PROGRESS:"progress",CALL_ENDED:"ended"};var mv={exports:{}};(function(c){var t=function(n){var a=Object.prototype,o=a.hasOwnProperty,s=Object.defineProperty||function(ee,W,G){ee[W]=G.value},r,d=typeof Symbol=="function"?Symbol:{},h=d.iterator||"@@iterator",_=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 oe?W:oe,be=Object.create(ge.prototype),xe=new P(re||[]);return s(be,"_invoke",{value:J(ee,G,xe)}),be}n.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",$={};function oe(){}function N(){}function j(){}var Se={};T(Se,h,function(){return this});var ve=Object.getPrototypeOf,k=ve&&ve(ve(se([])));k&&k!==a&&o.call(k,h)&&(Se=k);var D=j.prototype=oe.prototype=Object.create(Se);N.prototype=j,s(D,"constructor",{value:j,configurable:!0}),s(j,"constructor",{value:N,configurable:!0}),N.displayName=T(j,g,"GeneratorFunction");function B(ee){["next","throw","return"].forEach(function(W){T(ee,W,function(G){return this._invoke(W,G)})})}n.isGeneratorFunction=function(ee){var W=typeof ee=="function"&&ee.constructor;return W?W===N||(W.displayName||W.name)==="GeneratorFunction":!1},n.mark=function(ee){return Object.setPrototypeOf?Object.setPrototypeOf(ee,j):(ee.__proto__=j,T(ee,g,"GeneratorFunction")),ee.prototype=Object.create(D),ee},n.awrap=function(ee){return{__await:ee}};function V(ee,W){function G(be,xe,Ce,le){var ye=y(ee[be],ee,xe);if(ye.type==="throw")le(ye.arg);else{var nt=ye.arg,at=nt.value;return at&&typeof at=="object"&&o.call(at,"__await")?W.resolve(at.__await).then(function(Ee){G("next",Ee,Ce,le)},function(Ee){G("throw",Ee,Ce,le)}):W.resolve(at).then(function(Ee){nt.value=Ee,Ce(nt)},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()}s(this,"_invoke",{value:ge})}B(V.prototype),T(V.prototype,_,function(){return this}),n.AsyncIterator=V,n.async=function(ee,W,G,re,ge){ge===void 0&&(ge=Promise);var be=new V(E(ee,W,G,re),ge);return n.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 st()}for(G.method=be,G.arg=xe;;){var Ce=G.delegate;if(Ce){var le=F(Ce,G);if(le){if(le===$)continue;return le}}if(G.method==="next")G.sent=G._sent=G.arg;else if(G.method==="throw"){if(re===A)throw re=H,G.arg;G.dispatchException(G.arg)}else G.method==="return"&&G.abrupt("return",G.arg);re=I;var ye=y(ee,W,G);if(ye.type==="normal"){if(re=G.done?H:C,ye.arg===$)continue;return{value:ye.arg,done:G.done}}else ye.type==="throw"&&(re=H,G.method="throw",G.arg=ye.arg)}}}function F(ee,W){var G=W.method,re=ee.iterator[G];if(re===r)return W.delegate=null,G==="throw"&&ee.iterator.return&&(W.method="return",W.arg=r,F(ee,W),W.method==="throw")||G!=="return"&&(W.method="throw",W.arg=new TypeError("The iterator does not provide a '"+G+"' method")),$;var ge=y(re,ee.iterator,W.arg);if(ge.type==="throw")return W.method="throw",W.arg=ge.arg,W.delegate=null,$;var be=ge.arg;if(!be)return W.method="throw",W.arg=new TypeError("iterator result is not an object"),W.delegate=null,$;if(be.done)W[ee.resultName]=be.value,W.next=ee.nextLoc,W.method!=="return"&&(W.method="next",W.arg=r);else return be;return W.delegate=null,$}B(D),T(D,g,"Generator"),T(D,h,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)}n.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[h];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(o.call(ee,G))return ge.value=ee[G],ge.done=!1,ge;return ge.value=r,ge.done=!0,ge};return re.next=re}}return{next:st}}n.values=se;function st(){return{value:r,done:!0}}return P.prototype={constructor:P,reset:function(ee){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(U),!ee)for(var W in this)W.charAt(0)==="t"&&o.call(this,W)&&!isNaN(+W.slice(1))&&(this[W]=r)},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=r),!!ye}for(var re=this.tryEntries.length-1;re>=0;--re){var ge=this.tryEntries[re],be=ge.completion;if(ge.tryLoc==="root")return G("end");if(ge.tryLoc<=this.prev){var xe=o.call(ge,"catchLoc"),Ce=o.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&&o.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,$):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),$},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),$}},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=r),$}},n}(c.exports);try{regeneratorRuntime=t}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}})(mv);var Dh={exports:{}};(function(c){(function(t,n){c.exports?c.exports=n():t.log=n()})(jh,function(){var t=function(){},n="undefined",a=typeof window!==n&&typeof window.navigator!==n&&/Trident\/|MSIE /.test(window.navigator.userAgent),o=["trace","debug","info","warn","error"];function s(C,I){var H=C[I];if(typeof H.bind=="function")return H.bind(C);try{return Function.prototype.bind.call(H,C)}catch{return function(){return Function.prototype.apply.apply(H,[C,arguments])}}}function r(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function d(C){return C==="debug"&&(C="log"),typeof console===n?!1:C==="trace"&&a?r:console[C]!==void 0?s(console,C):console.log!==void 0?s(console,"log"):t}function h(C,I){for(var H=0;H<o.length;H++){var $=o[H];this[$]=H<C?t:this.methodFactory($,C,I)}this.log=this.debug}function _(C,I,H){return function(){typeof console!==n&&(h.call(this,I,H),this[C].apply(this,arguments))}}function g(C,I,H){return d(C)||_.apply(this,arguments)}function T(C,I,H){var $=this,oe;I=I??"WARN";var N="loglevel";typeof C=="string"?N+=":"+C:typeof C=="symbol"&&(N=void 0);function j(D){var B=(o[D]||"silent").toUpperCase();if(!(typeof window===n||!N)){try{window.localStorage[N]=B;return}catch{}try{window.document.cookie=encodeURIComponent(N)+"="+B+";"}catch{}}}function Se(){var D;if(!(typeof window===n||!N)){try{D=window.localStorage[N]}catch{}if(typeof D===n)try{var B=window.document.cookie,V=B.indexOf(encodeURIComponent(N)+"=");V!==-1&&(D=/^([^;]+)/.exec(B.slice(V))[1])}catch{}return $.levels[D]===void 0&&(D=void 0),D}}function ve(){if(!(typeof window===n||!N)){try{window.localStorage.removeItem(N);return}catch{}try{window.document.cookie=encodeURIComponent(N)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}$.name=C,$.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},$.methodFactory=H||g,$.getLevel=function(){return oe},$.setLevel=function(D,B){if(typeof D=="string"&&$.levels[D.toUpperCase()]!==void 0&&(D=$.levels[D.toUpperCase()]),typeof D=="number"&&D>=0&&D<=$.levels.SILENT){if(oe=D,B!==!1&&j(D),h.call($,D,C),typeof console===n&&D<$.levels.SILENT)return"No console available for logging"}else throw"log.setLevel() called with invalid level: "+D},$.setDefaultLevel=function(D){I=D,Se()||$.setLevel(D,!1)},$.resetLevel=function(){$.setLevel(I,!1),ve()},$.enableAll=function(D){$.setLevel($.levels.TRACE,D)},$.disableAll=function(D){$.setLevel($.levels.SILENT,D)};var k=Se();k==null&&(k=I),$.setLevel(k,!1)}var E=new T,y={};E.getLogger=function(I){if(typeof I!="symbol"&&typeof I!="string"||I==="")throw new TypeError("You must supply a name when creating a logger.");var H=y[I];return H||(H=y[I]=new T(I,E.getLevel(),E.methodFactory)),H};var A=typeof window!==n?window.log:void 0;return E.noConflict=function(){return typeof window!==n&&window.log===E&&(window.log=A),E},E.getLoggers=function(){return y},E.default=E,E})})(Dh);var It=Dh.exports;const vs=()=>`${new Date().toISOString()} | metrics`,Es=(c,t,n)=>`${c} | ${t} | ${n}`;It.setDefaultLevel(It.levels.TRACE);const gv=c=>{It.info(Es(vs(),"log ",`set log level to ${c?"verbose":"info"}`)),It.setLevel(c?It.levels.TRACE:It.levels.INFO)},Tv=c=>{const t=[...Object.keys(It.levels)];t.includes(c)?(It.info(Es(vs(),"log ",`update log level to ${c.toLowerCase()}`)),It.setLevel(c)):It.warn(Es(vs(),"log ","Incorrect log level please choose one of "),t)},Pe=(c,t,n)=>{n?It.debug(Es(vs(),c,t),n):It.debug(Es(vs(),c,t))},lu=(c,t)=>{It.info(Es(vs(),c,t))},Rn=(c,t)=>{It.info(Es(vs(),c,t))},Oa=(c,t)=>{It.warn(Es(vs(),c,t))},dr=(c,t)=>{It.error(Es(vs(),c,t))};function vv(c){return Math.floor(Math.random()*c).toString()}function xf(c,t){let n=t;return c.forEach(a=>{n=n.replace(a,"")}),n}function Ev(c,t){let n="";for(let a=0;a<t;a+=1)n+=c[vv(c.length)];return n}function Sv({length:c=20,useLetters:t=!0,useNumbers:n=!0,includeSymbols:a=[],excludeSymbols:o=[]}={}){let s="abcdefghijklmnopqrstuvwxyz",r="0123456789",d=[],h=[],_=[];return t&&(o.length&&(s=xf(o,s)),h=s.split("")),n&&(o.length&&(r=xf(o,r)),_=r.split("")),d=[...h,..._,...a],Ev(d,c)}var yv=Sv;const Qi=ze(yv),Av=()=>"WebRTCMetrics",Cv=()=>"5.0.3",$e={INBOUND:"inbound",OUTBOUND:"outbound"},gs={IDLE:"idle",RUNNING:"running",MUTED:"muted"},Ki={NEW:"new",CHECKING:"checking",CONNECTED:"connected",COMPLETED:"completed",DISCONNECTED:"disconnected",FAILED:"failed",CLOSED:"closed"},Rv=()=>({...{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:[]}}),Nh={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},Uh={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},Ph={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},xh={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},Iv=c=>{const t={pname:"",call_id:"",user_id:"",timestamp:null,count:0,audio:{},video:{},network:{infrastructure:3,local_candidate_id:"",local_candidate_type:"",local_candidate_protocol:"",local_candidate_relay_protocol:"",remote_candidate_id:"",remote_candidate_type:"",remote_candidate_protocol:""},data:{total_KBytes_in:0,total_KBytes_out:0,delta_KBytes_in:0,delta_KBytes_out:0,delta_kbs_in:0,delta_kbs_out:0,delta_kbs_bandwidth_in:0,delta_kbs_bandwidth_out:0,delta_rtt_connectivity_ms:null,total_rtt_connectivity_ms:0,total_rtt_connectivity_measure:0},experimental:{time_to_measure_ms:0}};if(c){const n={...c,audio:{},video:{},data:{...c.data},network:{...c.network},experimental:{...c.experimental}};return Object.keys(c.audio).forEach(a=>{n.audio[a]={...c.audio[a]}}),Object.keys(c.video).forEach(a=>{n.video[a]={...c.video[a]}}),n}return{...t,audio:{},video:{},data:{...t.data},network:{...t.network},experimental:{...t.experimental}}},bv={refreshEvery:2e3,startAfter:0,stopAfter:-1,verbose:!1,pname:`p-${Qi()}`,cid:`c-${Qi()}`,uid:`u-${Qi()}`,record:!1,ticket:!0},zt={CANDIDATE_PAIR:"candidate-pair",CODEC:"codec",INBOUND_RTP:"inbound-rtp",LOCAL_CANDIDATE:"local-candidate",MEDIA_SOURCE:"media-source",OUTBOUND_RTP:"outbound-rtp",REMOTE_CANDIDATE:"remote-candidate",REMOTE_INBOUND_RTP:"remote-inbound-rtp",TRACK:"track"},q={AUDIO_LEVEL:"audioLevel",AVAILABLE_OUTGOING_BITRATE:"availableOutgoingBitrate",AVAILABLE_INCOMING_BITRATE:"availableIncomingBitrate",BYTES_RECEIVED:"bytesReceived",BYTES_SENT:"bytesSent",CANDIDATE_TYPE:"candidateType",CHANNELS:"channels",CLOCK_RATE:"clockRate",CODEC_ID:"codecId",CURRENT_ROUND_TRIP_TIME:"currentRoundTripTime",ROUND_TRIP_TIME:"roundTripTime",FRACTION_LOST:"fractionLost",FRAME_HEIGHT:"frameHeight",FRAME_WIDTH:"frameWidth",QUALITY_LIMITATION_REASON:"qualityLimitationReason",QUALITY_LIMITATION_DURATIONS:"qualityLimitationDurations",QUALITY_LIMITATION_RESOLUTION_CHANGES:"qualityLimitationResolutionChanges",ID:"id",JITTER:"jitter",KIND:"kind",MEDIA_TYPE:"mediaType",MIME_TYPE:"mimeType",LOCAL_CANDIDATE_ID:"localCandidateId",NETWORK_TYPE:"networkType",RELAY_PROTOCOL:"relayProtocol",NOMINATED:"nominated",PACKETS_LOST:"packetsLost",PACKETS_RECEIVED:"packetsReceived",PACKETS_SENT:"packetsSent",PROTOCOL:"protocol",PORT:"port",REMOTE_CANDIDATE_ID:"remoteCandidateId",REMOTE_SOURCE:"remoteSource",RESPONSES_RECEIVED:"responsesReceived",SDP_FMTP_LINE:"sdpFmtpLine",SSRC:"ssrc",SELECTED:"selected",STATE:"state",TIMESTAMP:"timestamp",TOTAL_ROUND_TRIP_TIME:"totalRoundTripTime",TOTAL_ROUND_TRIP_TIME_MEASUREMENTS:"roundTripTimeMeasurements",TYPE:"type",DECODER_IMPLEMENTATION:"decoderImplementation",ENCODER_IMPLEMENTATION:"encoderImplementation",FRAMES_DECODED:"framesDecoded",FRAMES_ENCODED:"framesEncoded",FRAMES_PER_SECOND:"framesPerSecond",TOTAL_DECODE_TIME:"totalDecodeTime",TOTAL_ENCODE_TIME:"totalEncodeTime",PLI:"pliCount",NACK:"nackCount"},x={SUCCEEDED:"succeeded",AUDIO:"audio",VIDEO:"video"},Yi={ETHERNET:0,CELLULAR_5G:2,WIFI:3,CELLULAR_4G:5,CELLULAR:10},au={ETHERNET:"ethernet",CELLULAR_4G:"cellular",WIFI:"wifi"},ne={AUDIO:"audio",VIDEO:"video",NETWORK:"network",DATA:"data"},ou="config ",wv=(c,t={},n)=>{const a={...n,...t};return t.pname||Oa(ou,`Argument [String] 'cfg.pname' for the peerConnection name or id is missing - use generated '${n.pname}'`),t.cid||Oa(ou,`Argument [String] 'cfg.cid' for the call name or id is missing - use generated '${n.cid}'`),t.uid||Oa(ou,`Argument [String] 'cfg.uid' for the user name or id is missing - use generated '${n.uid}'`),a.pc=c,a},Ov=(c={})=>{const t={...bv,...c};return t.name=Av(),t.version=Cv(),t},ml=(c,t,n,a=!1,o)=>{let s=c.map(r=>{if(!n)return r[t];if(!o)return r[t][n];const d=r[t][o];return d?d[n]:null});return s=s.filter(r=>a?Number.isFinite(r)&&r>0:Number.isFinite(r)),s.length===0?[]:s},Gs=c=>c.reduce((t,n)=>t+n,0)/c.length,Dv=()=>`probe-${Qi()}`,Nv=()=>`coltr-${Qi()}`,kf=c=>new Promise(t=>setTimeout(t,c)),wu=(c,t,n)=>{t?c.call(t,n):c(n)},Ke=(c,t,n,a)=>{const o=ml(c,t,n,!0,a);if(o.length===0)return null;const s=o.reduce((_,g)=>_+g,0)/o.length;return s===0?null:o.map(_=>Math.abs(s-_)).reduce((_,g)=>_+g,0)/o.length*100/s},Xe=(c,t,n,a=!1,o)=>{const s=ml(c,t,n,a,o);return s.length===0?null:s.reduce((r,d)=>r+d,0)/s.length},Sn=(c,t,n)=>ml(c,t,n).reduce((o,s)=>o+s,0),Ye=(c,t,n,a)=>{const o=ml(c,t,n,!0,a);return o.length===0?null:Math.min(...o)},Je=(c,t,n,a)=>{const o=ml(c,t,n,!1,a);return o.length===0?null:Math.max(...o)},gt=(c,t,n,a)=>{const o=c.slice().pop();if(!o)return null;if(!n)return o[t];if(!a)return o[t][n];const s=o[t][a];return s?s[n]:null},Uv=c=>c.slice().pop(),ct=(c,t,n)=>{if(!t)return null;const a={};let o=t[x.AUDIO][c];o||(o=n===$e.INBOUND?{...Nh}:{...Uh}),a[x.AUDIO]=o;let s=t[x.VIDEO][c];return s||(s=n===$e.INBOUND?{...Ph}:{...xh}),a[x.VIDEO]=s,a},Ji="exporter ",Pv="2.0",Mf=(c,t,n)=>{if(!c||c.length===0)return 0;const a=c[c.length-1];if(!a)return 0;const o=a[t][n];if(o){const s=o.total_rtt_ms_out,r=o.total_rtt_measure_out;return!r||!s?Xe(c,t,"delta_rtt_ms_out",!1,n):Number(s/r)}return null},xv=(c,t)=>{if(!c||c.length===0)return 0;const n=c[c.length-1];if(!n)return 0;const a=n[t].total_rtt_connectivity_ms,o=n[t].total_rtt_connectivity_measure;return!o||!a?Xe(c,t,"delta_rtt_connectivity_ms"):Number(a/o)},kv=c=>gt(c,"network","local_candidate_type")!=="relay"?`direct/${gt(c,"network","local_candidate_protocol")}`:`turn/${gt(c,"network","local_candidate_relay_protocol")}`,Mv=c=>{const t=gt(c,"network","remote_candidate_type"),n=gt(c,"network","remote_candidate_protocol");return t!=="relay"?`direct/${n}`:`turn/${n}`};class Lv{constructor(t){this._start=null,this._end=null,this._cfg=t,this._referenceReport=null,this._reports=[],this._events=[]}start(){lu(Ji,"start() - start exporter...");const t=new Date;return this._start=t.toJSON(),t}stop(){lu(Ji,"stop() - stop exporter...");const t=new Date;return this._end=t.toJSON(),t}saveReferenceReport(t){this._referenceReport=t}getReferenceReport(){return this._referenceReport}addReport(t){this._cfg.ticket&&(Pe(Ji,`addReport() - add report to exporter at ${t.timestamp}`),this._reports.push(t))}addCustomEvent(t){this._events.push(t)}reset(){lu(Ji,"resetReports() - reset reports"),this._reports=[],this._referenceReport=null,this._start=null,this._end=null}get ticket(){Pe(Ji,"ticket() - generate ticket");const t=gt(this._reports,"audio","total_packets_lost_in"),n=gt(this._reports,"audio","total_packets_in"),a=gt(this._reports,"video","total_packets_lost_in"),o=gt(this._reports,"video","total_packets_in"),s={},r=Uv(this._reports);return r&&(Object.keys(r[x.AUDIO]).forEach(d=>{const h=r[x.AUDIO][d];if(s[h.ssrc]={type:x.AUDIO,direction:h.direction},h.direction===$e.INBOUND){const _={avg:Xe(this._reports,x.AUDIO,"delta_jitter_ms_in",!1,d),min: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:Xe(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:Xe(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:Xe(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:Xe(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"}};s[d].jitter=_,s[d].mos=E,s[d].traffic=T,s[d].bitrate=g,s[d].loss=C}else{const _={avg:Xe(this._reports,x.AUDIO,"delta_jitter_ms_out",!1,d),min: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:Xe(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:Xe(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:Mf(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:Xe(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:Xe(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"}};s[d].jitter=_,s[d].rtt=E,s[d].traffic=T,s[d].bitrate=g,s[d].loss=C,s[d].mos=I}}),Object.keys(r[x.VIDEO]).forEach(d=>{const h=r[x.VIDEO][d];if(s[d]={type:x.VIDEO,direction:h.direction},h.direction===$e.INBOUND){const _={avg:Xe(this._reports,x.VIDEO,"delta_jitter_ms_in",!1,d),min: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:Xe(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:Xe(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"}};s[d].jitter=_,s[d].traffic=T,s[d].bitrate=g,s[d].loss=A}else{const _={avg:Xe(this._reports,x.VIDEO,"delta_jitter_ms_out",!1,d),min: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:Xe(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:Xe(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:Mf(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"}};s[d].jitter=_,s[d].rtt=E,s[d].traffic=T,s[d].bitrate=g,s[d].loss=C}})),{version:Pv,configuration:{frequency:this._cfg.refreshEvery},started:this._start,ended:this._end,ua:{agent:navigator.userAgent,pname:this._cfg.pname,user_id:this._cfg.uid},call:{call_id:this._cfg.cid,events:this._events},details:{count:this._reports.length,reports:this._cfg.record?this._reports:[],reference:this._referenceReport||null},ssrc:s,data:{rtt:{avg:xv(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((t/(t+n)*100||0)*100)/100}},video:{in:{avg:Math.round((a/(a+o)*100||0)*100)/100}},unit:{avg:"percent"}},bitrate:{in:{avg:Xe(this._reports,"data","delta_kbs_in"),min: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:Xe(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:Xe(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:Xe(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:kv(this._reports),remoteConnection:Mv(this._reports)}}}}updateConfig(t){this._cfg=t}getLastReport(){return this._reports.slice().pop()||null}getBeforeLastReport(){const t=this._reports.slice();return t.pop(),t.pop()||null}getReportsNumber(){return this._reports.length}}const js="extractor ",Lf=(c,t,n,a)=>{let o=!1;const s=a[t].total_rtt_ms_out,r=a[t].total_rtt_measure_out,d=n?n[t].total_rtt_ms_out:0,h=n?n[t].total_rtt_measure_out:0,_={rtt:null,totalRTT:s,totalRTTMeasurements:r};if(c[q.TIMESTAMP]===a[t].timestamp_out||!Object.prototype.hasOwnProperty.call(c,q.ROUND_TRIP_TIME)||Object.prototype.hasOwnProperty.call(c,q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS)&&(o=!0,Number(c[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])===0||Number(c[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-h===r))return _;const g=1e3*Number(c[q.ROUND_TRIP_TIME]);let T=s+g,E=r+1;return o&&(T=1e3*Number(c[q.TOTAL_ROUND_TRIP_TIME])-d,E=Number(c[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-h),{rtt:g,totalRTT:T,totalRTTMeasurements:E}},$v=(c,t,n,a)=>{if(!Object.prototype.hasOwnProperty.call(c,q.CURRENT_ROUND_TRIP_TIME))return{rtt:null,totalRTT:a[t].total_rtt_connectivity_ms,totalRTTMeasurements:a[t].total_rtt_connectivity_measure};const o=1e3*Number(c[q.CURRENT_ROUND_TRIP_TIME]);let s=a[t].total_rtt_connectivity_ms+o,r=a[t].total_rtt_connectivity_measure+1;return Object.prototype.hasOwnProperty.call(c,q.TOTAL_ROUND_TRIP_TIME)&&(s=1e3*Number(c[q.TOTAL_ROUND_TRIP_TIME])-(n?n[t].total_rtt_connectivity_ms:0)),Object.prototype.hasOwnProperty.call(c,q.RESPONSES_RECEIVED)&&(r=Number(c[q.RESPONSES_RECEIVED])-(n?n[t].total_rtt_connectivity_measure:0)),{rtt:o,totalRTT:s,totalRTTMeasurements:r}},da=(c,t,n)=>c[q.TIMESTAMP]===n[t].timestamp_out||!Object.prototype.hasOwnProperty.call(c,q.JITTER)?null:1e3*(Number(c[q.JITTER])||0),Hv=(c,t)=>{if(!Object.prototype.hasOwnProperty.call(c,q.FRAMES_DECODED)||!Object.prototype.hasOwnProperty.call(c,q.TOTAL_DECODE_TIME))return{delta_ms_decode_frame:t[x.VIDEO].delta_ms_decode_frame_in,frames_decoded:t[x.VIDEO].total_frames_decoded_in,total_decode_time:t[x.VIDEO].total_time_decoded_in};const n=c[q.FRAMES_DECODED],a=c[q.TOTAL_DECODE_TIME],o=a-t[x.VIDEO].total_time_decoded_in,s=n-t[x.VIDEO].total_frames_decoded_in;return{delta_ms_decode_frame:s>0?o*1e3/s:0,frames_decoded:n,total_decode_time:a}},Fv=(c,t)=>{if(!Object.prototype.hasOwnProperty.call(c,q.FRAMES_ENCODED)||!Object.prototype.hasOwnProperty.call(c,q.TOTAL_ENCODE_TIME))return{delta_ms_encode_frame:t[x.VIDEO].delta_ms_encode_frame_out,frames_encoded:t[x.VIDEO].total_frames_encoded_out,total_encode_time:t[x.VIDEO].total_time_encoded_out};const n=c[q.FRAMES_ENCODED],a=c[q.TOTAL_ENCODE_TIME],o=a-t[x.VIDEO].total_time_encoded_out,s=n-t[x.VIDEO].total_frames_encoded_out;return{delta_ms_encode_frame:s>0&&o?o*1e3/s:0,frames_encoded:n,total_encode_time:a}},$f=(c,t,n,a)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PACKETS_SENT)||!Object.prototype.hasOwnProperty.call(c,q.BYTES_SENT))return{packetsSent:n[t].total_packets_out,packetsLost:n[t].total_packets_lost_out,bytesSent:n[t].total_KBytes_out};const o=Number(c[q.PACKETS_SENT])||0-(a?a[t].total_packets_out:0),s=o-n[t].total_packets_out,r=Number(c[q.BYTES_SENT])/1024-(a?a[t].total_KBytes_out:0),d=r-n[t].total_KBytes_out,h=c[q.TIMESTAMP]||Date.now(),_=a?a.timestamp:null;let g=n.timestamp;!g&&_&&(g=_);const T=g?h-g:0,E=T>0?d*.008*1024/T*1e3:0;return{packetsSent:o,deltaPacketsSent:s,KBytesSent:r,deltaKBytesSent:d,kbsSent:E}},Hf=(c,t,n,a)=>{let o=n[t].total_packets_lost_out,s=0,r=0;return Object.prototype.hasOwnProperty.call(c,q.PACKETS_LOST)&&(o=Number(c[q.PACKETS_LOST])||0-(a?a[t].total_packets_lost_out:0),s=o-n[t].total_packets_lost_out),Object.prototype.hasOwnProperty.call(c,q.FRACTION_LOST)&&(r=Number(100*c[q.FRACTION_LOST])),{packetsLost:o,deltaPacketsLost:s,fractionLost:r}},Ff=(c,t,n,a)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PACKETS_RECEIVED)||!Object.prototype.hasOwnProperty.call(c,q.PACKETS_LOST)||!Object.prototype.hasOwnProperty.call(c,q.BYTES_RECEIVED))return{percent_packets_lost:n[t].percent_packets_lost_in,packetsReceived:n[t].total_packets_in,packetsLost:n[t].total_packets_lost_in,bytesReceived:n[t].total_KBytes_in};const o=Number(c[q.PACKETS_RECEIVED])||0-(a?a[t].total_packets_in:0),s=Number(c[q.PACKETS_LOST])||0-(a?a[t].total_packets_lost_in:0),r=s-n[t].total_packets_lost_in,d=o-n[t].total_packets_in,h=o!==n[t].total_packets_in?r*100/(r+d):0,_=Number(c[q.BYTES_RECEIVED])/1024-(a?a[t].total_KBytes_in:0),g=_-n[t].total_KBytes_in,T=c[q.TIMESTAMP]||Date.now(),E=a?a.timestamp:null;let y=n.timestamp;!y&&E&&(y=E);const A=y?T-y:0,C=A>0?g*.008*1024/A*1e3:0;return{percentPacketsLost:h,packetsReceived:o,deltaPacketsReceived:d,packetsLost:s,deltaPacketsLost:r,KBytesReceived:_,deltaKBytesReceived:g,kbsReceived:C}},jv=c=>c[q.CANDIDATE_TYPE]!=="relay"?"":c[q.RELAY_PROTOCOL]||"",qv=c=>{if(!Object.prototype.hasOwnProperty.call(c,q.NETWORK_TYPE))return Yi.WIFI;switch(c[q.NETWORK_TYPE]){case au.ETHERNET:return Yi.ETHERNET;case au.CELLULAR_4G:return Yi.CELLULAR_4G;case au.WIFI:return Yi.WIFI;default:return Yi.CELLULAR}},jf=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]},Vv=c=>{const t=Object.prototype.hasOwnProperty.call(c,q.QUALITY_LIMITATION_REASON)?c[q.QUALITY_LIMITATION_REASON]:null,n=Object.prototype.hasOwnProperty.call(c,q.QUALITY_LIMITATION_RESOLUTION_CHANGES)?c[q.QUALITY_LIMITATION_RESOLUTION_CHANGES]:null,a=Object.prototype.hasOwnProperty.call(c,q.QUALITY_LIMITATION_DURATIONS)?c[q.QUALITY_LIMITATION_DURATIONS]:null;return a&&Object.keys(a).forEach(o=>{a[o]>1e3&&(a[o]=Number(a[o]/1e3))}),{reason:t,durations:a,resolutionChanges:n}},Bv=(c,t,n)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PLI)||!Object.prototype.hasOwnProperty.call(c,q.NACK))return{pliCount:t.total_pli_sent_in,nackCount:t.total_nack_sent_in,deltaPliCount:0,deltaNackCount:0};const a=(c[q.PLI]||0)-(n?n[x.VIDEO].total_pli_sent_in:0),o=(c[q.NACK]||0)-(n?n[x.VIDEO].total_nack_sent_in:0);return{pliCount:a,nackCount:o,deltaPliCount:a-t[x.VIDEO].total_pli_sent_in,deltaNackCount:o-t[x.VIDEO].total_nack_sent_in}},Gv=(c,t,n)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PLI)||!Object.prototype.hasOwnProperty.call(c,q.NACK))return{pliCount:t.total_pli_received_out,nackCount:t.total_nack_received_out,deltaPliCount:0,deltaNackCount:0};const a=(c[q.PLI]||0)-(n?n[x.VIDEO].total_pli_received_out:0),o=(c[q.NACK]||0)-(n?n[x.VIDEO].total_nack_received_out:0);return{pliCount:a,nackCount:o,deltaPliCount:a-t[x.VIDEO].total_pli_received_out,deltaNackCount:o-t[x.VIDEO].total_nack_received_out}},Wv=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}),Kv=c=>({clock_rate:c[q.CLOCK_RATE]||null,mime_type:c[q.MIME_TYPE]||null}),Yv=(c,t,n)=>{const a=(c[q.BYTES_RECEIVED]||0)/1024-(n?n.data.total_KBytes_in:0),o=(c[q.BYTES_SENT]||0)/1024-(n?n.data.total_KBytes_out:0),s=c[q.TIMESTAMP]||Date.now(),r=a-t.data.total_KBytes_in,d=o-t.data.total_KBytes_out,h=n?n.timestamp:null;let _=t.timestamp;!_&&h&&(_=h);const g=_?s-_:0,T=g>0?r*.008*1024/g*1e3:0,E=g>0?d*.008*1024/g*1e3:0;return{total_KBytes_received:a,total_KBytes_sent:o,delta_KBytes_received:r,delta_KBytes_sent:d,kbs_speed_received:T,kbs_speed_sent:E}},Jv=c=>{const t=c[q.AVAILABLE_INCOMING_BITRATE]/1024||0,n=c[q.AVAILABLE_OUTGOING_BITRATE]/1024||0;return{kbs_incoming_bandwidth:t,kbs_outgoing_bandwidth:n}},zv=(c,t,n,a)=>{if(!c)return[];switch(c[q.TYPE]){case zt.CANDIDATE_PAIR:let o=!1;if(c[q.NOMINATED]&&c[q.STATE]===x.SUCCEEDED&&(o=!0,Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c),q.SELECTED in c&&!c[q.SELECTED]&&(o=!1)),o){const r=c[q.LOCAL_CANDIDATE_ID],d=c[q.REMOTE_CANDIDATE_ID],h=Yv(c,t,a),_=Jv(c),g=$v(c,"data",a,t);return[{type:ne.NETWORK,value:{local_candidate_id:r}},{type:ne.NETWORK,value:{remote_candidate_id:d}},{type:ne.DATA,value:{total_KBytes_in:h.total_KBytes_received}},{type:ne.DATA,value:{total_KBytes_out:h.total_KBytes_sent}},{type:ne.DATA,value:{delta_KBytes_in:h.delta_KBytes_received}},{type:ne.DATA,value:{delta_KBytes_out:h.delta_KBytes_sent}},{type:ne.DATA,value:{delta_kbs_in:h.kbs_speed_received}},{type:ne.DATA,value:{delta_kbs_out:h.kbs_speed_sent}},{type:ne.DATA,value:{delta_kbs_bandwidth_in:_.kbs_incoming_bandwidth}},{type:ne.DATA,value:{delta_kbs_bandwidth_out:_.kbs_outgoing_bandwidth}},{type:ne.DATA,value:{delta_rtt_connectivity_ms:g.rtt}},{type:ne.DATA,value:{total_rtt_connectivity_ms:g.totalRTT}},{type:ne.DATA,value:{total_rtt_connectivity_measure:g.totalRTTMeasurements}}]}break;case zt.LOCAL_CANDIDATE:if(c[q.ID]===t.network.local_candidate_id)return[{type:ne.NETWORK,value:{infrastructure:qv(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:jv(c)}}];break;case zt.REMOTE_CANDIDATE:if(c[q.ID]===t.network.remote_candidate_id)return[{type:ne.NETWORK,value:{remote_candidate_type:c[q.CANDIDATE_TYPE]||""}},{type:ne.NETWORK,value:{remote_candidate_protocol:c[q.PROTOCOL]||""}}];break;case zt.INBOUND_RTP:{Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const r=c[q.SSRC],d=ct(r,t,$e.INBOUND);d&&(d.timestamp=t.timestamp);const h=ct(r,a,$e.INBOUND);if(h&&(h.timestamp=a.timestamp),c[q.MEDIA_TYPE]===x.AUDIO){const _=Ff(c,x.AUDIO,d,h),g=da(c,x.AUDIO,d),T=c[q.CODEC_ID]||"";return[{ssrc:r,type:ne.AUDIO,value:{codec_id_in:T}},{ssrc:r,type:ne.AUDIO,value:{total_packets_in:_.packetsReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_in:_.deltaPacketsReceived}},{ssrc:r,type:ne.AUDIO,value:{total_packets_lost_in:_.packetsLost}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_lost_in:_.deltaPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{percent_packets_lost_in:_.percentPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{total_KBytes_in:_.KBytesReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_KBytes_in:_.deltaKBytesReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_kbs_in:_.kbsReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_jitter_ms_in:g}}]}if(c[q.MEDIA_TYPE]===x.VIDEO){const _=Hv(c,d),g=Ff(c,x.VIDEO,d,h),T=da(c,x.VIDEO,d),E=c[q.DECODER_IMPLEMENTATION]||null,y=c[q.CODEC_ID]||null,A=jf(c),C=Bv(c,d,h);return[{ssrc:r,type:ne.VIDEO,value:{codec_id_in:y}},{ssrc:r,type:ne.VIDEO,value:{total_packets_in:g.packetsReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_in:g.deltaPacketsReceived}},{ssrc:r,type:ne.VIDEO,value:{total_packets_lost_in:g.packetsLost}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_lost_in:g.deltaPacketsLost}},{ssrc:r,type:ne.VIDEO,value:{percent_packets_lost_in:g.percentPacketsLost}},{ssrc:r,type:ne.VIDEO,value:{total_KBytes_in:g.KBytesReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_KBytes_in:g.deltaKBytesReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_kbs_in:g.kbsReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_jitter_ms_in:T}},{ssrc:r,type:ne.VIDEO,value:{decoder_in:E}},{ssrc:r,type:ne.VIDEO,value:{delta_ms_decode_frame_in:_.delta_ms_decode_frame}},{ssrc:r,type:ne.VIDEO,value:{total_frames_decoded_in:_.frames_decoded}},{ssrc:r,type:ne.VIDEO,value:{total_time_decoded_in:_.total_decode_time}},{ssrc:r,type:ne.VIDEO,value:{total_nack_sent_in:C.nackCount}},{ssrc:r,type:ne.VIDEO,value:{delta_nack_sent_in:C.deltaNackCount}},{ssrc:r,type:ne.VIDEO,value:{total_pli_sent_in:C.pliCount}},{ssrc:r,type:ne.VIDEO,value:{delta_pli_sent_in:C.deltaPliCount}},{ssrc:r,type:ne.VIDEO,value:{size_in:A}}]}break}case zt.OUTBOUND_RTP:{Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const r=c[q.SSRC],d=ct(r,t,$e.OUTBOUND);d&&(d.timestamp=t.timestamp);const h=ct(r,a,$e.OUTBOUND);if(h&&(h.timestamp=a.timestamp),c[q.MEDIA_TYPE]===x.AUDIO){const _=c[q.CODEC_ID]||null,g=$f(c,x.AUDIO,d,h);return[{ssrc:r,type:ne.AUDIO,value:{codec_id_out:_}},{ssrc:r,type:ne.AUDIO,value:{total_packets_out:g.packetsSent}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_out:g.deltaPacketsSent}},{ssrc:r,type:ne.AUDIO,value:{total_KBytes_out:g.KBytesSent}},{ssrc:r,type:ne.AUDIO,value:{delta_KBytes_out:g.deltaKBytesSent}},{ssrc:r,type:ne.AUDIO,value:{delta_kbs_out:g.kbsSent}}]}if(c[q.MEDIA_TYPE]===x.VIDEO){const _=c[q.ENCODER_IMPLEMENTATION]||null,g=c[q.CODEC_ID]||null,T=Fv(c,d),E=jf(c),y=Vv(c),A=Gv(c,d,h),C=$f(c,x.VIDEO,d,h);return[{ssrc:r,type:ne.VIDEO,value:{codec_id_out:g}},{ssrc:r,type:ne.VIDEO,value:{total_packets_out:C.packetsSent}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_out:C.deltaPacketsSent}},{ssrc:r,type:ne.VIDEO,value:{total_KBytes_out:C.KBytesSent}},{ssrc:r,type:ne.VIDEO,value:{delta_KBytes_out:C.deltaKBytesSent}},{ssrc:r,type:ne.VIDEO,value:{delta_kbs_out:C.kbsSent}},{ssrc:r,type:ne.VIDEO,value:{encoder_out:_}},{ssrc:r,type:ne.VIDEO,value:{delta_ms_encode_frame_out:T.delta_ms_encode_frame}},{ssrc:r,type:ne.VIDEO,value:{total_frames_encoded_out:T.frames_encoded}},{ssrc:r,type:ne.VIDEO,value:{total_time_encoded_out:T.total_encode_time}},{ssrc:r,type:ne.VIDEO,value:{total_nack_received_out:A.nackCount}},{ssrc:r,type:ne.VIDEO,value:{delta_nack_received_out:A.deltaNackCount}},{ssrc:r,type:ne.VIDEO,value:{total_pli_received_out:A.pliCount}},{ssrc:r,type:ne.VIDEO,value:{delta_pli_received_out:A.deltaPliCount}},{ssrc:r,type:ne.VIDEO,value:{size_out:E}},{ssrc:r,type:ne.VIDEO,value:{limitation_out:y}}]}break}case zt.MEDIA_SOURCE:{Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);break}case zt.TRACK:{Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);break}case zt.CODEC:const s=[];return Object.keys(t[x.AUDIO]).forEach(r=>{const d=t[x.AUDIO][r];if(d.codec_id_in===c[q.ID]||d.codec_id_out===c[q.ID]){Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const h=Wv(c);c[q.ID]===d.codec_id_in?s.push({ssrc:d.ssrc,type:ne.AUDIO,value:{codec_in:h}}):s.push({ssrc:d.ssrc,type:ne.AUDIO,value:{codec_out:h}})}}),Object.keys(t[x.VIDEO]).forEach(r=>{const d=t[x.VIDEO][r];if(d.codec_id_in===c[q.ID]||d.codec_id_out===c[q.ID]){Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const h=Kv(c);c[q.ID]===d.codec_id_in?s.push({ssrc:d.ssrc,type:ne.VIDEO,value:{codec_in:h}}):s.push({ssrc:d.ssrc,type:ne.VIDEO,value:{codec_out:h}})}}),s;case zt.REMOTE_INBOUND_RTP:{Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const r=c[q.SSRC],d=ct(r,t,$e.OUTBOUND),h=ct(r,a,$e.OUTBOUND);if(c[q.KIND]===x.AUDIO){const _=Lf(c,x.AUDIO,h,d),g=da(c,x.AUDIO,d),T=Hf(c,x.AUDIO,d,h);return[{ssrc:r,type:ne.AUDIO,value:{delta_rtt_ms_out:_.rtt}},{ssrc:r,type:ne.AUDIO,value:{total_rtt_ms_out:_.totalRTT}},{ssrc:r,type:ne.AUDIO,value:{total_rtt_measure_out:_.totalRTTMeasurements}},{ssrc:r,type:ne.AUDIO,value:{delta_jitter_ms_out:g}},{ssrc:r,type:ne.AUDIO,value:{timestamp_out:c[q.TIMESTAMP]}},{ssrc:r,type:ne.AUDIO,value:{total_packets_lost_out:T.packetsLost}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_lost_out:T.deltaPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{percent_packets_lost_out:T.fractionLost}}]}if(c[q.KIND]===x.VIDEO){const _=Lf(c,x.VIDEO,h,d),g=da(c,x.VIDEO,d),T=Hf(c,x.VIDEO,d,h);return[{ssrc:r,type:ne.VIDEO,value:{delta_rtt_ms_out:_.rtt}},{ssrc:r,type:ne.VIDEO,value:{total_rtt_ms_out:_.totalRTT}},{ssrc:r,type:ne.VIDEO,value:{total_rtt_measure_out:_.totalRTTMeasurements}},{ssrc:r,type:ne.VIDEO,value:{delta_jitter_ms_out:g}},{ssrc:r,type:ne.VIDEO,value:{timestamp_out:c[q.TIMESTAMP]}},{ssrc:r,type:ne.VIDEO,value:{total_packets_lost_out:T.packetsLost}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_lost_out:T.deltaPacketsLost}},{ssrc:r,type:ne.VIDEO,value:{percent_packets_lost_out:T.fractionLost}}]}break}}return[]},Ya=c=>c<0?1:c>100?4.5:1+.035*c+7/1e6*c*(c-60)*(100-c),Xv=(c,t=x.AUDIO,n,a,o)=>{const s=ct(o,c,$e.INBOUND),r=ct(o,n,$e.INBOUND),d=ct(o,a,$e.INBOUND),h=[],_=[],g=s[t].percent_packets_lost_in,T=s[t].delta_jitter_ms_in,E=r&&r[t].delta_jitter_ms_in||null,y=d&&d[t].delta_jitter_ms_in||null,A=c.data.delta_rtt_connectivity_ms,C=n&&n.data.delta_rtt_connectivity_ms||null,I=a&&a.data.delta_rtt_connectivity_ms||null;A&&h.push(A),C&&h.push(C),I&&h.push(I),T&&_.push(T),n&&E&&_.push(E),a&&y&&_.push(y);const H=h.length>0?Gs(h):100,$=_.length>0?Gs(_):10,oe=93.2-g,N=.18*oe*oe-27.9*oe+1126.62,j=(H+$)/2,Se=j-177.3<0?0:1,ve=.024*j+.11*(j-177.3)*Se,k=N-ve;return Ya(k)},Qv=(c,t=x.AUDIO,n,a,o)=>{const s=ct(o,c,$e.OUTBOUND),r=ct(o,n,$e.OUTBOUND),d=ct(o,a,$e.OUTBOUND),h=[],_=[],g=s[t].percent_packets_lost_out,T=s[t].delta_rtt_ms_out,E=r&&r[t].delta_rtt_ms_out||null,y=d&&d[t].delta_rtt_ms_out||null,A=s[t].delta_jitter_ms_out,C=r&&r[t].delta_jitter_ms_out||null,I=d&&d[t].delta_jitter_ms_out||null,H=c.data.delta_rtt_connectivity_ms,$=n&&n.data.delta_rtt_connectivity_ms||null,oe=a&&a.data.delta_rtt_connectivity_ms||null;T?h.push(T):H&&h.push(H),E?h.push(E):$&&h.push($),y?h.push(y):oe&&h.push(oe),A&&_.push(A),n&&C&&_.push(C),a&&I&&_.push(I);const N=h.length>0?Gs(h):100,j=_.length>0?Gs(_):10,Se=93.2-g,ve=.18*Se*Se-27.9*Se+1126.62,k=(N+j)/2,D=k-177.3<0?0:1,B=.024*k+.11*(k-177.3)*D,V=ve-B;return Ya(V)},Zv=(c,t=x.AUDIO,n,a,o)=>{const s=ct(o,c,$e.INBOUND),r=ct(o,n,$e.INBOUND),d=ct(o,a,$e.INBOUND),h=[],_=[],g=s[t].percent_packets_lost_in/100,T=s[t].delta_jitter_ms_in,E=r&&r[t].delta_jitter_ms_in||null,y=d&&d[t].delta_jitter_ms_in||null,A=c.data.delta_rtt_connectivity_ms,C=n&&n.data.delta_rtt_connectivity_ms||null,I=a&&a.data.delta_rtt_connectivity_ms||null;A&&h.push(A),C&&h.push(C),I&&h.push(I),T&&_.push(T),r&&E&&_.push(E),d&&y&&_.push(y);const H=h.length>0?Gs(h):100,$=_.length>0?Gs(_):10,oe=0,N=19.8,j=29.7,Se=30,ve=(H+$)/2+Se,k=ve-177.3<0?0:1,D=.024*ve+.11*(ve-177.3)*k,V=93.2-(oe+N*Math.log(1+j*g)+D);return Ya(V)},eE=(c,t=x.AUDIO,n,a,o)=>{const s=ct(o,c,$e.OUTBOUND),r=ct(o,n,$e.OUTBOUND),d=ct(o,a,$e.OUTBOUND),h=[],_=[],g=s[t].percent_packets_lost_out/100,T=s[t].delta_rtt_ms_out,E=r&&r[t].delta_rtt_ms_out||null,y=d&&d[t].delta_rtt_ms_out||null,A=s[t].delta_jitter_ms_out,C=r&&r[t].delta_jitter_ms_out||null,I=d&&d[t].delta_jitter_ms_out||null,H=c.data.delta_rtt_connectivity_ms,$=n&&n.data.delta_rtt_connectivity_ms||null,oe=a&&a.data.delta_rtt_connectivity_ms||null;T?h.push(T):H&&h.push(H),E?h.push(E):$&&h.push($),y?h.push(y):oe&&h.push(oe),A&&_.push(A),r&&C&&_.push(C),d&&I&&_.push(I);const N=h.length>0?Gs(h):100,j=_.length>0?Gs(_):10,Se=0,ve=19.8,k=29.7,D=30,B=(N+j)/2+D,V=B-177.3<0?0:1,J=.024*B+.11*(B-177.3)*V,X=93.2-(Se+ve*Math.log(1+k*g)+J);return Ya(X)};class tE{constructor(t,n){this._callbacks={onreport:null,onticket:null},this._id=Nv(),this._moduleName=this._id,this._probeId=n,this._config=t,this._exporter=new Lv(t),this._state=gs.IDLE,this.registerToPCEvents(),Rn(this._moduleName,`new collector created for probe ${this._probeId}`)}analyze(t,n,a,o){const s=(h,_)=>h===x.AUDIO?_===zt.INBOUND_RTP?{...Nh}:{...Uh}:_===zt.INBOUND_RTP?{...Ph}:{...xh},r=Iv(n);r.pname=this._config.pname,r.call_id=this._config.cid,r.user_id=this._config.uid,r.count=n?n.count+1:1;let d=null;return t.forEach(h=>{!d&&h.timestamp&&(d=h.timestamp),zv(h,r,r.pname,o).forEach(g=>{if(g.value&&g.type)if(g.ssrc){let T=r[g.type][g.ssrc];T||(T=s(g.type,h.type),T.ssrc=g.ssrc,r[g.type][g.ssrc]=T),Object.keys(g.value).forEach(E=>{T[E]=g.value[E]})}else Object.keys(g.value).forEach(T=>{r[g.type][T]=g.value[T]})})}),r.timestamp=d,Object.keys(r[x.AUDIO]).forEach(h=>{const _=r[x.AUDIO][h];_.direction===$e.INBOUND?(_.mos_emodel_in=Xv(r,x.AUDIO,n,a,_.ssrc),_.mos_in=Zv(r,x.AUDIO,n,a,_.ssrc)):(_.mos_emodel_out=Qv(r,x.AUDIO,n,a,_.ssrc),_.mos_out=eE(r,x.AUDIO,n,a,_.ssrc))}),r}async takeReferenceStats(){return new Promise((t,n)=>{const a=Date.now();setTimeout(async()=>{try{const o=Date.now()-a,s=Date.now(),r=await this._config.pc.getStats(),d=this.analyze(r,null,null,null),h=Date.now();d.experimental.time_to_measure_ms=h-s,d.experimental.time_to_wait_ms=o,this._exporter.saveReferenceReport(d),Pe(this._moduleName,`got reference report for probe ${this._probeId}`),t()}catch(o){n(o)}},this._config.startAfter)})}async collectStats(){try{if(this._state!==gs.RUNNING||!this._config.pc)return Pe(this._moduleName,`report discarded (too late) for probe ${this._probeId}`),null;const t=Date.now(),n=await this._config.pc.getStats(),a=this.analyze(n,this._exporter.getLastReport(),this._exporter.getBeforeLastReport(),this._exporter.getReferenceReport()),o=Date.now();return a.experimental.time_to_measure_ms=o-t,this._exporter.addReport(a),Pe(this._moduleName,`got report for probe ${this._probeId}#${this._exporter.getReportsNumber()+1}`),this.fireOnReport(a),a}catch(t){return dr(this._moduleName,`got error ${t}`),null}}async start(){Pe(this._moduleName,"starting"),this.state=gs.RUNNING,this._startedTime=this._exporter.start(),Pe(this._moduleName,"started")}async mute(){this.state=gs.MUTED,Pe(this._moduleName,"muted")}async unmute(){this.state=gs.RUNNING,Pe(this._moduleName,"unmuted")}async stop(t){if(Pe(this._moduleName,`stopping${t?" by watchdog":""}...`),this._stoppedTime=this._exporter.stop(),this.state=gs.IDLE,this._config.ticket){const{ticket:n}=this._exporter;this.fireOnTicket(n)}this._exporter.reset(),Pe(this._moduleName,"stopped")}registerCallback(t,n,a){t in this._callbacks?(this._callbacks[t]={callback:n,context:a},Pe(this._moduleName,`registered callback '${t}'`)):dr(this._moduleName,`can't register callback for '${t}' - not found`)}unregisterCallback(t){t in this._callbacks?(this._callbacks[t]=null,delete this._callbacks[t],Pe(this._moduleName,`unregistered callback '${t}'`)):dr(this._moduleName,`can't unregister callback for '${t}' - not found`)}fireOnReport(t){this._callbacks.onreport&&wu(this._callbacks.onreport.callback,this._callbacks.onreport.context,t)}fireOnTicket(t){this._callbacks.onticket&&wu(this._callbacks.onticket.callback,this._callbacks.onticket.context,t)}updateConfig(t){this._config=t,this._exporter.updateConfig(t)}get state(){return this._state}set state(t){this._state=t,Pe(this._moduleName,`state changed to ${t}`)}addCustomEvent(t,n,a,o){this._exporter.addCustomEvent({at:typeof t=="object"?t.toJSON():t,category:n,name:a,description:o})}async registerToPCEvents(){const{pc:t}=this._config;if(navigator.mediaDevices.ondevicechange=async()=>{try{const n=await navigator.mediaDevices.enumerateDevices();this.addCustomEvent(new Date().toJSON(),"device",`${n.length} devices found`,"Media Devices state")}catch{dr(this._moduleName,"can't get devices")}},t){t.oniceconnectionstatechange=()=>{const a=t.iceConnectionState;a===Ki.CONNECTED||a===Ki.COMPLETED?this.addCustomEvent(new Date().toJSON(),"call",a,"ICE connection state"):a===Ki.DISCONNECTED||a===Ki.FAILED?this.addCustomEvent(new Date().toJSON(),"call",a,"ICE connection state"):a===Ki.CLOSED&&this.addCustomEvent(new Date().toJSON(),"call","ended","ICE connection state")},t.onicegatheringstatechange=()=>{const a=t.iceGatheringState;this.addCustomEvent(new Date().toJSON(),"call",a,"ICE gathering state")},t.ontrack=a=>{this.addCustomEvent(new Date().toJSON(),"call",`${a.track.kind}track`,"MediaStreamTrack received")},t.onnegotiationneeded=()=>{this.addCustomEvent(new Date().toJSON(),"call","negotiation","Media changed")};const n=t.getReceivers();if(n&&n.length>0){const a=n[0],{transport:o}=a;if(o){const{iceTransport:s}=o;s&&(s.onselectedcandidatepairchange=()=>{this.addCustomEvent(new Date().toJSON(),"call","transport","Candidates Pair changed")})}}}}}class sE{constructor(t){this._id=t.pname&&t.pname.substr(0,12).padEnd(12," ")||Dv(),this._moduleName=this._id,Rn(this._moduleName,"probe created"),this._config=t,this._collector=new tE(this._config,this._id)}set onreport(t){t?this._collector.registerCallback("onreport",t):this._collector.unregisterCallback("onreport")}set onticket(t){t?this._collector.registerCallback("onticket",t):this._collector.unregisterCallback("onticket")}get id(){return this._id}get pname(){return this._config.pname}get cid(){return this._config.cid}get uid(){return this._config.uid}get state(){return this._collector.state}set state(t){this._collector.state=t}addCustomEvent(t,n,a,o=new Date().toJSON()){this._collector.addCustomEvent(o,n,t,a)}get isRunning(){return this._collector.state===gs.RUNNING}get isIdle(){return this._collector.state===gs.IDLE}updateUserId(t){this._config.uid=t,this._collector.updateConfig(this._config)}updateCallId(t){this._config.cid=t,this._collector.updateConfig(this._config)}start(){if(!this.isIdle){Oa(this._moduleName,"probe is already running");return}this._collector.start()}stop(t=!1){this.isRunning&&this._collector.stop(t)}async takeReferenceStats(){return this._collector.takeReferenceStats()}async collectStats(){return this._collector.collectStats()}}const Rt="engine ";class nE{constructor(t){this._config=t,this._probes=[],this._startedTime=null,this._callbacks={onresult:null},Rn(Rt,`configured for probing every ${this._config.refreshEvery}ms`),Rn(Rt,`configured for starting after ${this._config.startAfter}ms`),Rn(Rt,`${!this._config.stopAfter||this._config.stopAfter!==-1?`configured for stopped after ${this._config.stopAfter}ms`:"configured for never stopped"}`),Pe(Rt,"engine initialized")}get probes(){return this._probes}get isRunning(){return this._probes.some(t=>t.isRunning)}get isIdle(){return this._probes.every(t=>t.isIdle)}addNewProbe(t,n){if(!t)throw new Error("undefined peer connection");const a=wv(t,n,this._config),o=new sE(a);return this._probes.push(o),Pe(Rt,`${this._probes.length} probes registered`),o}removeExistingProbe(t){if(!t)throw new Error("undefined probe");t.state===gs.RUNNING&&t.stop(),this._probes=this._probes.filter(n=>t.id!==n.id)}async start(){const t=()=>{this._probes.forEach(s=>s.start())},n=async()=>Promise.all(this._probes.map(s=>s.takeReferenceStats())),a=()=>this.isIdle?!1:!this._config.stopAfter||this._config.stopAfter<0?!0:Date.now()<this._startedTime+this._config.stopAfter,o=async()=>{const s=Rv(),r=this._probes.filter(d=>d.isRunning);for(const d of r){const h=await d.collectStats();h&&s.probes.push(h),Pe(Rt,`got probe ${d.id}`),await kf(0)}return s.delta_time_to_measure_probes_ms=Sn(s.probes,"experimental","time_to_measure_ms"),s.delta_KBytes_in=Sn(s.probes,"data","delta_KBytes_in"),s.delta_KBytes_out=Sn(s.probes,"data","delta_KBytes_out"),s.delta_kbs_in=Sn(s.probes,"data","delta_kbs_in"),s.delta_kbs_out=Sn(s.probes,"data","delta_kbs_out"),s.total_time_decoded_in=Sn(s.probes,"video","total_time_decoded_in"),s.total_time_encoded_out=Sn(s.probes,"video","total_time_encoded_out"),s};for(Pe(Rt,"starting to collect"),t(),Pe(Rt,"generating reference reports..."),await n(),Pe(Rt,"reference reports generated"),this._startedTime=Date.now();a();)if(Pe(Rt,`wait ${this._config.refreshEvery}ms before collecting`),await kf(this._config.refreshEvery),a()){Pe(Rt,"collecting...");const s=Date.now(),r=await o(),d=Date.now();r.delta_time_consumed_to_measure_ms=d-s,this.fireOnReports(r),Pe(Rt,"collected")}Pe(Rt,"reaching end of the collecting period..."),this.isRunning&&setTimeout(()=>{this.stop()},0)}stop(t){const n=a=>{this._probes.forEach(o=>{o.stop(a)})};Rn(Rt,"stop collecting"),n(t)}registerCallback(t,n,a){t in this._callbacks?(this._callbacks[t]={callback:n,context:a},Pe(Rt,`registered callback '${t}'`)):dr(Rt,`can't register callback for '${t}' - not found`)}unregisterCallback(t){t in this._callbacks?(this._callbacks[t]=null,delete this._callbacks[t],Pe(this._moduleName,`unregistered callback '${t}'`)):dr(this._moduleName,`can't unregister callback for '${t}' - not found`)}fireOnReports(t){this._callbacks.onresult&&t.probes.length>0&&wu(this._callbacks.onresult.callback,this._callbacks.onresult.context,t)}}const rE="interface ";class iE{constructor(t){this._config=Ov(t),Rn(rE,`welcome to ${this._config.name} version ${this._config.version}`),gv(this._config.verbose||!1),this._engine=new nE(this._config)}setupLogLevel(t){Tv(t)}get version(){return this._config.version}get name(){return this._config.name}get probes(){return this._engine.probes}createProbe(t,n){return this._engine.addNewProbe(t,n)}startAllProbes(){this._engine.start()}stopAllProbes(){this._engine.stop()}get running(){return this._engine.isRunning}get idle(){return this._engine.isIdle}removeProbe(t){this._engine.removeExistingProbe(t)}set onresult(t){t?this._engine.registerCallback("onresult",t):this._engine.unregisterCallback("onresult")}}function lE(c,t){return Object.keys(c).filter(n=>t.includes(n)).reduce((n,a)=>{const o=a;return{...n,[o]:c[o]}},{})}const aE=["mos_in","codec_in","delta_KBytes_in","delta_kbs_in","delta_jitter_ms_in","delta_packets_lost_in"];class oE{constructor(t){this.intervals={},this.emitInterval=t.emitInterval||200,this.onChangeFunction=t.onChangeFunction}start(t,n){t&&t.getTracks().length&&requestAnimationFrame(()=>this.beginCalculation(t,n))}stop(t){this.clearVolumeInterval(t)}clearVolumeInterval(t){clearInterval(this.intervals[t]),delete this.intervals[t]}clearAllIntervals(){Object.keys(this.intervals).forEach(t=>{clearInterval(this.intervals[t])}),this.intervals={}}beginCalculation(t,n){this.clearVolumeInterval(n);const a=Cn.createAnalyser(),o=Cn.createMediaStreamSource(t),s=Cn.createScriptProcessor(2048,1,1);a.smoothingTimeConstant=.8,a.fftSize=1024,o.connect(a),a.connect(s),s.connect(Cn.destination),this.intervals[n]=setInterval(()=>{const r=new Uint8Array(a.frequencyBinCount);a.getByteFrequencyData(r);let d=0;const h=r.length;for(let g=0;g<h;g++)d+=r[g];const _=d/h;this.onChangeFunction(n,_)},this.emitInterval)}}const _a={SELECTED_INPUT_DEVICE:"OpensipsJSInputDevice",SELECTED_OUTPUT_DEVICE:"OpensipsJSOutputDevice"},uE=0;class cE{constructor(t){this.isAutoAnswer=!1,this.muteWhenJoinEnabled=!1,this.isDNDEnabled=!1,this.isCallWaitingEnabled=!0,this.muted=!1,this.microphoneInputLevelValue=1,this.speakerVolumeValue=1,this.activeRooms={},this.activeCalls={},this.extendedCalls={},this.availableMediaDevices=[],this.selectedMediaDevices={input:"default",output:"default"},this.callStatus={},this.callTime={},this.callMetrics={},this.timeIntervals={},this.metricConfig={refreshEvery:1e3},this.activeStreamValue=null,this.initialStreamValue=null,this.context=t,this.context.on(this.context.newRTCSessionEventName,this.newRTCSessionCallback.bind(this)),this.VUMeter=new oE({onChangeFunction:this.emitVolumeChange.bind(this)}),this.initializeMediaDevices()}get sipOptions(){return{...this.context.options.sipOptions,mediaConstraints:this.getUserMediaConstraints}}get currentActiveRoomId(){return this.currentActiveRoomIdValue}set currentActiveRoomId(t){this.currentActiveRoomIdValue=t,this.context.emit("currentActiveRoomChanged",t)}get autoAnswer(){return this.isAutoAnswer}get callAddingInProgress(){return this.isCallAddingInProgress}set callAddingInProgress(t){this.isCallAddingInProgress=t,this.context.emit("callAddingInProgressChanged",t)}get muteWhenJoin(){return this.muteWhenJoinEnabled}get isDND(){return this.isDNDEnabled}get isCallWaiting(){return this.isCallWaitingEnabled}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 hasActiveAnsweredCalls(){return Object.values(this.activeRooms).filter(a=>!a.incomingInProgress).length>0}get getActiveRooms(){return this.activeRooms}get isMuted(){return this.muted}get getInputDeviceList(){return this.availableMediaDevices.filter(t=>t.kind==="audioinput")}get getOutputDeviceList(){return this.availableMediaDevices.filter(t=>t.kind==="audiooutput")}get getUserMediaConstraints(){return wh()?{video:!1,audio:!0}:{audio:{deviceId:{exact:this.selectedMediaDevices.input}},video:!1}}get selectedInputDevice(){return this.selectedMediaDevices.input}get selectedOutputDevice(){return this.selectedMediaDevices.output}get activeStream(){return this.activeStreamValue}setAvailableMediaDevices(t){this.availableMediaDevices=t,this.context.emit("changeAvailableDeviceList",t)}async updateDeviceList(){await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);const t=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(t)}async initializeMediaDevices(){const t=localStorage.getItem(_a.SELECTED_INPUT_DEVICE)||"default",n=localStorage.getItem(_a.SELECTED_OUTPUT_DEVICE)||"default";try{const a=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints),o=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(o),await this.setMicrophone(t),await this.setSpeaker(n),navigator.mediaDevices.addEventListener("devicechange",async()=>{const s=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(s)}),a.getTracks().forEach(s=>s.stop())}catch(a){console.error(a)}}setCallTime(t){const n={...t};delete n.callId,this.callTime={...this.callTime,[t.callId]:n},this.context.emit("changeCallTime",this.callTime)}removeCallTime(t){const n={...this.callTime};delete n[t],this.callTime={...n},this.context.emit("changeCallTime",this.callTime)}setTimeInterval(t,n){this.timeIntervals={...this.timeIntervals,[t]:n}}removeTimeInterval(t){const n={...this.timeIntervals};n[t]&&(clearInterval(n[t]),delete n[t],this.timeIntervals={...n})}stopCallTimer(t){this.removeTimeInterval(t),this.removeCallTime(t)}emitVolumeChange(t,n){this.context.emit("changeCallVolume",{callId:t,volume:n})}setMetricsConfig(t){this.metricConfig={...this.metricConfig,...t}}sendDTMF(t,n){if(!/^[A-D0-9]+$/g.test(n))throw new Error("Not allowed character in DTMF input");this.extendedCalls[t].sendDTMF(n)}setIsMuted(t){this.muted=t,this.context.emit("changeIsMuted",t)}processMute(t){const n=this.currentActiveRoomId;this.setIsMuted(t),this.initialStreamValue.getTracks().forEach(a=>a.enabled=!t),this.roomReconfigure(n)}mute(){this.processMute(!0)}unmute(){this.processMute(!1)}async processHold({callId:t,toHold:n,automatic:a}){const o=this.extendedCalls[t];o._automaticHold=a??!1,await new Promise(d=>{const h=()=>{o.putOnHoldTimestamp=n?Date.now():void 0,d()};n?o.hold({},h):o.unhold({},h)}),this.updateCall(o);const r=Object.values(this.extendedCalls).filter(d=>d.roomId===this.currentActiveRoomId&&(n?t!==d._id:!0));r.length>1&&await this.doConference(r)}holdCall(t,n=!1){return this.processHold({callId:t,automatic:n,toHold:!0})}unholdCall(t){return this.processHold({callId:t,toHold:!1})}cancelAllOutgoingUnanswered(){Object.values(this.getActiveCalls).filter(t=>t.direction==="outgoing"&&t.status===uE).forEach(t=>this.terminateCall(t._id))}answerCall(t){const n=this.extendedCalls[t];this.cancelAllOutgoingUnanswered(),n.answer(this.sipOptions),this.updateCall(n),this.setActiveRoom(n.roomId),n.connection.addEventListener("track",a=>{this.triggerAddStream(a,n)})}async moveCall(t,n){this.updateCallStatus({callId:t,isMoving:!0}),await this.processRoomChange({callId:t,roomId:n}),this.updateCallStatus({callId:t,isMoving:!1})}updateCall(t){this.activeCalls[t._id]=Nf(t),this.context.emit("changeActiveCalls",this.activeCalls)}updateRoom(t){const a={...this.activeRooms[t.roomId],...t};this.activeRooms={...this.activeRooms,[t.roomId]:{...a}},this.context.emit("updateRoom",{room:a,roomList:this.activeRooms})}hasAutoAnswerHeaders(t){const n=/answer-after=0/,o=t.request.getHeader("Call-Info");return o&&n.test(o)}addCall(t,n=!0){this.activeCalls={...this.activeCalls,[t._id]:Nf(t)},this.extendedCalls[t._id]=t,n&&this.context.emit("changeActiveCalls",this.activeCalls)}addCallStatus(t){this.callStatus={...this.callStatus,[t]:{isMoving:!1,isTransferring:!1,isMerging:!1,isTransferred:!1}},this.context.emit("changeCallStatus",this.callStatus)}updateCallStatus(t){const a={...{...this.callStatus[t.callId]}};t.isMoving!==void 0&&(a.isMoving=t.isMoving),t.isTransferring!==void 0&&(a.isTransferring=t.isTransferring),t.isMerging!==void 0&&(a.isMerging=t.isMerging),t.isTransferred!==void 0&&(a.isTransferred=t.isTransferred),this.callStatus={...this.callStatus,[t.callId]:{...a}},this.context.emit("changeCallStatus",this.callStatus)}removeCallStatus(t){const n={...this.callStatus};delete n[t],this.callStatus={...n},this.context.emit("changeCallStatus",this.callStatus)}addRoom(t){this.activeRooms={...this.activeRooms,[t.roomId]:t},this.context.emit("addRoom",{room:t,roomList:this.activeRooms})}getActiveStream(){const t=Pf(this.initialStreamValue,this.microphoneInputLevel*2);return t.getTracks().forEach(n=>n.enabled=!this.isMuted),this.setActiveStream(t),t}async setMicrophone(t){if(!this.getInputDeviceList.find(({deviceId:a})=>a===t)||(this.setSelectedInputDevice(t),Object.keys(this.getActiveCalls).length===0))return;await this.setupStream();const n=Object.values(this.extendedCalls).filter(a=>a.roomId===this.currentActiveRoomId);n.length===1?Object.values(n).forEach(async a=>{const o=this.getActiveStream();a.connection.getSenders()[0].replaceTrack(o.getTracks()[0]),this.updateCall(a)}):await this.doConference(n)}setActiveStream(t){this.activeStream&&this.stopVUMeter("origin"),this.setupVUMeter(t,"origin"),this.activeStreamValue=t,this.context.emit("changeActiveStream",t)}async setSpeaker(t){if(!this.getOutputDeviceList.find(({deviceId:o})=>o===t))return;this.setSelectedOutputDevice(t);const n=Object.values(this.extendedCalls);if(n.length===0)return;const a=n.filter(o=>o.roomId===this.currentActiveRoomId);a.length===1?n.forEach(o=>{var s;(s=o.audioTag)==null||s.setSinkId(t),this.updateCall(o)}):await this.doConference(a)}removeRoom(t){const n={...this.activeRooms},a={...n[t]};delete n[t],this.activeRooms={...n},this.context.emit("removeRoom",{room:a,roomList:this.activeRooms})}deleteRoomIfEmpty(t){t!==void 0&&Object.values(this.extendedCalls).filter(n=>n.roomId===t).length===0&&(this.removeRoom(t),this.currentActiveRoomId===t&&(this.currentActiveRoomId=void 0))}checkInitialized(){if(!this.context.initialized)throw new Error("[OpenSIPSJS] You must call `start` method first!")}muteReconfigure(t){this.muted?t.mute({audio:!0}):t.unmute({audio:!0})}async roomReconfigure(t){var a;if(t===void 0)return;const n=Object.values(this.extendedCalls).filter(o=>o.roomId===t);if(this.currentActiveRoomId===t?n.forEach(o=>{o.audioTag&&(this.muteReconfigure(o),o.audioTag.muted=!1,this.updateCall(o))}):n.forEach(o=>{o.audioTag&&(o.audioTag.muted=!0,this.updateCall(o))}),n.length===0)this.deleteRoomIfEmpty(t);else if(n.length===1&&this.currentActiveRoomId!==t)n[0].isOnHold().local||await this.holdCall(n[0].id,!0);else if(n.length===1&&this.currentActiveRoomId===t){if(n[0].isOnHold().local&&n[0]._automaticHold&&await this.unholdCall(n[0].id),n[0].connection&&((a=n[0].connection)!=null&&a.getSenders()[0])){const o=this.getActiveStream();await n[0].connection.getSenders()[0].replaceTrack(o.getTracks()[0]),this.muteReconfigure(n[0])}}else n.length>1&&await this.doConference(n)}async doConference(t){const n=[];t.forEach(a=>{a!=null&&a.connection.getReceivers().forEach(o=>{n.push(o.track)})}),await pv.forEach(t,async a=>{var r;if(a==null)return;const o=new MediaStream,s=Cn.createMediaStreamDestination();if(a.connection.getReceivers().forEach(d=>{n.forEach(h=>{o.addTrack(d.track),d.track.id!==h.id&&Cn.createMediaStreamSource(new MediaStream([h])).connect(s)})}),t[0].roomId===this.currentActiveRoomId){const d=this.getActiveStream();Cn.createMediaStreamSource(d).connect(s)}(r=a.connection)!=null&&r.getSenders()[0]&&(await a.connection.getSenders()[0].replaceTrack(s.stream.getTracks()[0]),this.muteReconfigure(a))})}processCallerMute(t,n){const a=this.extendedCalls[t];a&&a.connection.getReceivers().length&&(a.localMuted=n,a.connection.getReceivers().forEach(o=>{o.track.enabled=!n}),this.updateCall(a))}muteCaller(t){this.processCallerMute(t,!0)}unmuteCaller(t){this.processCallerMute(t,!1)}terminateCall(t){const n=this.extendedCalls[t];n._status===4?n.terminate({status_code:603,reason_phrase:"Decline"}):n._status!==8&&n.terminate()}transferCall(t,n){if(n.toString().length===0)return new Error("Target must be passed");const a=this.extendedCalls[t];if(!a._is_confirmed&&!a._is_canceled){const o=`sip:${n}@${this.context.sipDomain}`;a.terminate({status_code:302,reason_phrase:"Moved Temporarily",extraHeaders:[`Contact: ${o}`]});return}this.updateCallStatus({callId:t,isTransferring:!0,isTransferred:!1}),a.refer(`sip:${n}@${this.context.sipDomain}`,{eventHandlers:{requestSucceeded:()=>{this.updateCallStatus({callId:t,isTransferring:!1,isTransferred:!0})},requestFailed:()=>{this.updateCallStatus({callId:t,isTransferring:!1,isTransferred:!1})}}}),this.updateCall(a)}mergeCall(t){const n=Object.values(this.extendedCalls).filter(s=>s.roomId===t);if(n.length!==2)return;const a=n[0],o=n[1];!a||!o||(this.updateCallStatus({callId:a._id,isMerging:!0}),this.updateCallStatus({callId:o._id,isMerging:!0}),a.refer(o.remote_identity.uri.toString(),{replaces:o}),this.updateCall(a))}mergeCallByIds(t,n){const a=Object.values(this.extendedCalls).find(s=>s._id===t),o=Object.values(this.extendedCalls).find(s=>s._id===n);if(!a||!o)throw new Error("Call ID is not provided");this.updateCallStatus({callId:t,isMerging:!0}),this.updateCallStatus({callId:n,isMerging:!0}),a.refer(o.remote_identity.uri.toString(),{replaces:o}),this.updateCall(a)}setDND(t){this.isDNDEnabled=t,this.context.emit("changeIsDND",t)}setCallWaiting(t){this.isCallWaitingEnabled=t,this.context.emit("changeIsCallWaiting",t)}startCallTimer(t){this.removeTimeInterval(t);const n={callId:t,hours:0,minutes:0,seconds:0,formatted:""};this.setCallTime(n);const a=setInterval(()=>{const o={...this.callTime[t]},s=hv(o);this.setCallTime({callId:t,...s})},1e3);this.setTimeInterval(t,a)}async setActiveRoom(t){const n=this.currentActiveRoomId;t!==n&&(this.currentActiveRoomId=t,await this.roomReconfigure(n),await this.roomReconfigure(t))}getNewRoomId(){const t=Object.keys(this.activeRooms);return t.length===0?1:parseInt(t.sort()[t.length-1])+1}async setupCall(t){var _,g;const n=t.session;if(this.getActiveCalls[n.id]!==void 0)return;const o=this.getNewRoomId(),s={started:new Date,incomingInProgress:!1,roomId:o};n.direction==="incoming"?(this.context.logger.log("New incoming call from",(g=(_=n._remote_identity)==null?void 0:_._uri)==null?void 0:g._user),s.incomingInProgress=!0,this.context.subscribe(Xt.CALL_CONFIRMED,T=>{n.id===T.id&&(this.updateRoom({incomingInProgress:!1,roomId:o}),this.startCallTimer(n.id))}),this.context.subscribe(Xt.CALL_FAILED,T=>{n.id===T.id&&(this.updateRoom({incomingInProgress:!1,roomId:o}),this.deleteRoomIfEmpty(o))})):n.direction==="outgoing"&&(n.once("confirmed",()=>{this.startCallTimer(n.id)}),this.startCallTimer(n.id));const r=n,d=this.hasAutoAnswerHeaders(t),h=r.direction==="incoming"&&!this.hasActiveCalls&&(d||this.autoAnswer);r.roomId=o,r.localMuted=!1,r.autoAnswer=h,h?this.addCall(r,!1):this.addCall(r),this.addCallStatus(n.id),this.addRoom(s),h&&this.answerCall(r._id)}removeCall(t){const n={...this.activeCalls};delete n[t],this.activeCalls={...n};const a={...this.extendedCalls};delete a[t],this.extendedCalls={...a},this.context.emit("changeActiveCalls",this.activeCalls)}activeCallListRemove(t){var o;const n=this.extendedCalls[t._id];this.stopVUMeter("origin"),(o=n.connection)==null||o.getSenders().forEach(s=>{s.track.stop()});const a=n.roomId;this.removeCall(t._id),this.roomReconfigure(a)}shouldTerminateNewSession(t){if(t.session.direction==="outgoing")return!1;const a=!this.isCallWaiting&&this.hasActiveCalls;return this.isDND||a}async newRTCSessionCallback(t){const n=t.session;if(this.shouldTerminateNewSession(t)){n.terminate({status_code:486,reason_phrase:"Do Not Disturb"});return}if(this.context.triggerListener({listenerType:Xt.NEW_CALL,session:n,event:t}),n.on("ended",a=>{var s,r,d;this.stopVUMeter(n.id),this.context.logger.log("Session ended for",(r=(s=n._remote_identity)==null?void 0:s._uri)==null?void 0:r._user),this.context.triggerListener({listenerType:Xt.CALL_ENDED,session:n,event:a});const o=this.getActiveCalls[n.id];o&&this.activeCallListRemove(o),this.stopCallTimer(n.id),this.removeCallStatus(n.id),this.removeCallMetrics(n.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(d=this.initialStreamValue)==null||d.getTracks().forEach(h=>h.stop()),this.initialStreamValue=null),this.context.isWaitingForSessionHangup()&&!this.hasActiveAnsweredCalls&&this.context.stopSessionAfterWaiting()}),n.on("progress",a=>{var o,s;this.context.logger.log("Session in progress for",(s=(o=n._remote_identity)==null?void 0:o._uri)==null?void 0:s._user),this.context.triggerListener({listenerType:Xt.CALL_PROGRESS,session:n,event:a})}),n.on("failed",a=>{var s,r,d;this.stopVUMeter(n.id),this.context.logger.log("Session failed for",(r=(s=n._remote_identity)==null?void 0:s._uri)==null?void 0:r._user),this.context.triggerListener({listenerType:Xt.CALL_FAILED,session:n,event:a}),n.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0);const o=this.getActiveCalls[n.id];o&&this.activeCallListRemove(o),this.stopCallTimer(n.id),this.removeCallStatus(n.id),this.removeCallMetrics(n.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(d=this.initialStreamValue)==null||d.getTracks().forEach(h=>h.stop()),this.initialStreamValue=null),this.context.isWaitingForSessionHangup()&&!this.hasActiveAnsweredCalls&&this.context.stopSessionAfterWaiting()}),n.on("confirmed",a=>{var o,s;this.context.logger.log("Session confirmed for",(s=(o=n._remote_identity)==null?void 0:o._uri)==null?void 0:s._user),this.context.triggerListener({listenerType:Xt.CALL_CONFIRMED,session:n,event:a}),this.updateCall(n),n.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0)}),await this.setupCall(t),n.direction==="outgoing"){const a=this.getActiveCalls[n.id].roomId;this.setActiveRoom(a)}}setMuteWhenJoin(t){this.muteWhenJoinEnabled=t,this.context.emit("changeMuteWhenJoin",t)}setMicrophoneSensitivity(t){if(t<0||t>1)throw new Error("Value should be in range from 0 to 1!");this.microphoneInputLevelValue=t,this.roomReconfigure(this.currentActiveRoomId)}setSpeakerVolume(t){this.speakerVolumeValue=t,Object.values(this.extendedCalls).forEach(n=>{n.audioTag&&(n.audioTag.volume=t,this.updateCall(n))})}setAutoAnswer(t){this.isAutoAnswer=t}setSelectedInputDevice(t){localStorage.setItem(_a.SELECTED_INPUT_DEVICE,t),this.selectedMediaDevices.input=t,this.context.emit("changeActiveInputMediaDevice",t)}setSelectedOutputDevice(t){localStorage.setItem(_a.SELECTED_OUTPUT_DEVICE,t),this.selectedMediaDevices.output=t,this.context.emit("changeActiveOutputMediaDevice",t)}setCallMetrics(t){const n={...t};delete n.callId,this.callMetrics={...this.callMetrics,[t.callId]:n},this.context.emit("changeCallMetrics",this.callMetrics)}removeCallMetrics(t){const n={...this.callMetrics};delete n[t],this.callMetrics={...n},this.context.emit("changeCallMetrics",this.callMetrics)}getCallQuality(t){const n=new iE(this.metricConfig),a=n.createProbe(t.connection,{cid:t._id}),o=[];let s;a.onreport=r=>{Object.entries(r.audio).forEach(([_,g])=>{g.direction==="inbound"&&!o.includes(_)&&(o.push(_),s=_)});const d=r.audio[s];if(!d)return;const h=lE(d,aE);h.callId=t._id,this.setCallMetrics(h)},this.context.subscribe(Xt.CALL_ENDED,r=>{r._id===t._id&&n.stopAllProbes()}),n.startAllProbes()}setupVUMeter(t,n){this.VUMeter.start(t,n)}stopVUMeter(t){this.VUMeter.stop(t)}async setupStream(){const t=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);this.initialStreamValue&&(this.initialStreamValue.getTracks().forEach(n=>n.stop()),this.initialStreamValue=null),this.initialStreamValue=t}async triggerAddStream(t,n){this.setIsMuted(this.muteWhenJoin||this.isMuted),this.initialStreamValue||await this.setupStream();const a=Pf(this.initialStreamValue,this.microphoneInputLevel*2),o=this.isMuted||this.muteWhenJoin;a.getTracks().forEach(r=>r.enabled=!o),this.setActiveStream(a),await n.connection.getSenders()[0].replaceTrack(a.getTracks()[0]);const s=new MediaStream([t.track]);zT(s,n,this.selectedOutputDevice,this.speakerVolume),this.setupVUMeter(s,n._id),this.getCallQuality(n),this.updateCall(n)}initCall(t,n,a=!1){if(t.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${t}@${this.context.sipDomain}...`);const o=this.context.call(`sip:${t}@${this.context.sipDomain}`,this.sipOptions);if(this.callAddingInProgress=o.id,n&&this.currentActiveRoomId!==void 0&&(this.processRoomChange({callId:o.id,roomId:this.currentActiveRoomId}),a)){const s=Object.values(this.extendedCalls).filter(r=>r.roomId===this.currentActiveRoomId&&r._id!==o.id);for(const r of s)this.holdCall(r._id,!0)}o.connection.addEventListener("track",s=>{this.triggerAddStream(s,o)})}async processRoomChange({callId:t,roomId:n}){const a=this.extendedCalls[t].roomId;this.extendedCalls[t].roomId=n;const o=this.extendedCalls[t];return this.updateCall(o),await this.setActiveRoom(n),Promise.all([this.roomReconfigure(a),this.roomReconfigure(n)]).then(()=>{this.deleteRoomIfEmpty(a),this.deleteRoomIfEmpty(n)})}}class fE{constructor(t){this.context=t}get sipOptions(){return{...this.context.options.sipOptions}}initCall(t,n){if(t.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${t}@${this.context.sipDomain}...`),this.context.joinVideoCall(`sip:${t}@${this.context.sipDomain}`,n,this.sipOptions)}stop(t={}){this.context.terminateJanusSessions(t)}startAudio(){this.context.enableJanusAudio(!0)}stopAudio(){this.context.enableJanusAudio(!1)}startVideo(){this.context.enableJanusVideo(!0)}stopVideo(){this.context.enableJanusVideo(!1)}changeMediaConstraints(t){this.context.changeMediaConstraints(t)}startScreenShare(){this.context.startScreenShare()}startBlur(){this.context.startBlur()}stopBlur(){this.context.stopBlur()}}class hE{constructor(t){this.activeMessages={},this.extendedMessages={},this.msrpHistory={},this.context=t,this.context.on(this.context.newMSRPSessionEventName,this.newMSRPSessionCallback.bind(this.context))}get isMSRPInitializing(){return this.isMSRPInitializingValue}get getActiveMessages(){return this.activeMessages}msrpAnswer(t){const n=this.extendedMessages[t];this.updateMSRPSession(n)}updateMSRPSession(t){this.activeMessages[t._id]=Uf(t),this.context.emit("changeActiveMessages",this.activeMessages)}addMMSRPSession(t){this.activeMessages={...this.activeMessages,[t._id]:Uf(t)},this.extendedMessages[t._id]=t,this.context.emit("changeActiveMessages",this.activeMessages)}addMSRPMessage(t,n){const a=this.msrpHistory[n.id]||[];a.push(t),this.msrpHistory={...this.msrpHistory,[n.id]:[...a]},this.context.emit("newMSRPMessage",{message:t,session:n})}messageTerminate(t){const n=this.extendedMessages[t];n._status!==8&&n.terminate()}addMessageSession(t){if(!t._id||this.getActiveMessages[t._id]!==void 0)return;const a=t;this.addMMSRPSession(a)}triggerMSRPListener({listenerType:t,session:n,event:a}){const o=this.context.listenersList[t];!o||!o.length||o.forEach(s=>{s(n,a)})}removeMMSRPSession(t){const n={...this.activeMessages};delete n[t],this.activeMessages={...n};const a={...this.extendedMessages};delete a[t],this.extendedMessages={...a},this.context.emit("changeActiveMessages",this.activeMessages)}activeMessageListRemove(t){this.removeMMSRPSession(t._id)}newMSRPSessionCallback(t){const n=t.session;n.on("ended",a=>{this.triggerMSRPListener({listenerType:Xt.CALL_ENDED,session:n,event:a});const o=this.getActiveMessages[n.id];this.activeMessageListRemove(o)}),n.on("failed",a=>{this.triggerMSRPListener({listenerType:Xt.CALL_FAILED,session:n,event:a});const o=this.getActiveMessages[n.id];this.activeMessageListRemove(o)}),n.on("confirmed",a=>{this.triggerMSRPListener({listenerType:Xt.CALL_CONFIRMED,session:n,event:a}),this.updateMSRPSession(n)}),n.on("newMessage",a=>{this.addMSRPMessage(a,n)}),this.addMessageSession(n)}setIsMSRPInitializing(t){this.isMSRPInitializingValue=t,this.context.emit("isMSRPInitializingChanged",t)}initMSRP(t,n,a){if(t.length===0)return console.error("Target must be a valid string");const o=this.context.startMSRP(t,a);o.on("active",()=>{this.addMessageSession(o),o.sendMSRP(n),this.setIsMSRPInitializing(!1)}),this.setIsMSRPInitializing(!0)}sendMSRP(t,n){const a=this.extendedMessages[t];if(!a)throw new Error(`MSRP session with id ${t} doesn't exist!`);a.sendMSRP(n)}}const pa={AUDIO:"audio",VIDEO:"video",MSRP:"msrp"};class kh{constructor(t){this.opensips=null,this.session=null,this.name=null,this.name=t}setOpensips(t){this.opensips=t}setSession(t){this.session=t}kill(){this.opensips.kill(this.name)}}class Mh extends kh{constructor(t,n){super(t),this._candidates=[],this._subscribeSent=!1,this._configureSent=!1,this._lastTrickleReceived=!1,this.type=n}connect(t={}){this.opaqueId=this.session.generateOpaqueId();const n=ke.cloneArray(t.extraHeaders),a={from_tag:this.session._from_tag};t.fromUserName&&(a.from_uri=new In("sip",t.fromUserName,this.session._ua.configuration.uri.host),n.push(`P-Preferred-Identity: ${this.session._ua.configuration.uri.toString()}`)),t.fromDisplayName&&(a.from_display_name=t.fromDisplayName),n.push(`Contact: ${this.session._contact}`),n.push("Content-Type: application/json"),this.session._sessionTimers.enabled&&n.push(`Session-Expires: ${this.session._sessionTimers.defaultExpires}${this.session._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new yt.InitialOutgoingInviteRequest(this.session.target,this.session._ua,a,n),this._createRTCConnection(),this._sendInitialRequest()}getStream(){return this.stream}getConnection(){return this._connection}_createRTCConnection(){this._connection=new RTCPeerConnection({iceServers:[{urls:"stun:turn.voicenter.co",credential:"kxsjahnsdjns3eds23esd",username:"turn2es21e"}]});let t;this._connection.onicecandidate=n=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||n.candidate&&(this._candidates.push(n.candidate),clearTimeout(t),t=setTimeout(()=>{this._lastTrickleReceived=!0,this._subscribeSent&&!this._configureSent&&this._sendConfigureMessage({audio:!0,video:!0})},500))}}addTracks(t){t.forEach(n=>{this._connection.addTrack(n)})}async _sendInitialRequest(){const t=new sl(this.session._ua,this._request,{onRequestTimeout:()=>{this.session.onRequestTimeout()},onTransportError:()=>{this.session.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});if(await this.generateStream(),!this.stream||!this.stream.getTracks().length)return;this.addTracks(this.stream.getTracks());const n={audio:!1,video:!0};this.jsep_offer=await this._connection.createOffer(n),await this._connection.setLocalDescription(this.jsep_offer);const a={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaqueId},o=JSON.stringify(a);this._request.body=o,t.send()}_receiveInviteResponse(t){if(this._publisherSubscribeSent||!t.body)return;const n=JSON.parse(t.body);this.handleId=n.data.id;const a={janus:"message",body:{request:"join",room:this.session.room_id,ptype:"publisher",display:this.session.display_name+" (Screen Share)",opaque_id:this.opaqueId},handle_id:this.handleId},o=[this.session.getPTypeHeader(Pt.PUBLISHER)];this.session.sendRequest(L.SUBSCRIBE,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{var r,d,h,_;if(s.status_code===200){if(this._subscribeSent=!0,s.body)try{const g=JSON.parse(s.body)||{};((d=(r=g.plugindata)==null?void 0:r.data)==null?void 0:d.videoroom)==="joined"&&this.session.myFeedList.push(g.plugindata.data.id),(_=(h=g.plugindata)==null?void 0:h.data)!=null&&_.publishers&&this.session.receivePublishers(g)}catch(g){console.error(g)}this._lastTrickleReceived&&!this._configureSent&&this._sendConfigureMessage({audio:!0,video:!0})}}}}),this._publisherSubscribeSent=!0}async _sendConfigureMessage(t){const n=this._candidates.map(r=>({janus:"trickle",candidate:r,handle_id:this.handleId,session_id:this.session.session_id})),o={configure:{janus:"message",body:{request:"configure",record:!0,filename:this.session.getRecordFileName(),...t},jsep:this.jsep_offer,handle_id:this.handleId,session_id:this.session.session_id},trickles:[...n]},s=["Content-Type: application/json",this.session.getPTypeHeader(Pt.ICE)];this.session.sendRequest(L.INFO,{extraHeaders:s,body:JSON.stringify(o),eventHandlers:{onSuccessResponse:async r=>{this._configureSent=!0;const h=r.data.split(`\r
|
158
|
+
`,n),o===-1)return o;!c.substring(o+2,o+4).match(/(^\r\n)/)&&c.charAt(o+2).match(/(^\s+)/)?n=o+2:a=o}return a}function HT(c,t,n,a){let o;const s=t.indexOf(":",n),r=t.substring(n,s).trim(),d=t.substring(s+1,a).trim();switch(r.toLowerCase()){case"via":case"v":c.addHeader("via",d),c.getHeaders("via").length===1?(o=c.parseHeader("Via"),o&&(c.via=o,c.via_branch=o.branch)):o=0;break;case"from":case"f":c.setHeader("from",d),o=c.parseHeader("from"),o&&(c.from=o,c.from_tag=o.getParam("tag"));break;case"to":case"t":c.setHeader("to",d),o=c.parseHeader("to"),o&&(c.to=o,c.to_tag=o.getParam("tag"));break;case"record-route":if(o=Iu.parse(d,"Record_Route"),o===-1)o=void 0;else for(const h of o)c.addHeader("record-route",d.substring(h.possition,h.offset)),c.headers["Record-Route"][c.getHeaders("record-route").length-1].parsed=h.parsed;break;case"call-id":case"i":c.setHeader("call-id",d),o=c.parseHeader("call-id"),o&&(c.call_id=d);break;case"contact":case"m":if(o=Iu.parse(d,"Contact"),o===-1)o=void 0;else for(const h of o)c.addHeader("contact",d.substring(h.possition,h.offset)),c.headers.Contact[c.getHeaders("contact").length-1].parsed=h.parsed;break;case"content-length":case"l":c.setHeader("content-length",d),o=c.parseHeader("content-length");break;case"content-type":case"c":c.setHeader("content-type",d),o=c.parseHeader("content-type");break;case"cseq":c.setHeader("cseq",d),o=c.parseHeader("cseq"),o&&(c.cseq=o.value),c instanceof pr.IncomingResponse&&(c.method=o.method);break;case"max-forwards":c.setHeader("max-forwards",d),o=c.parseHeader("max-forwards");break;case"www-authenticate":c.setHeader("www-authenticate",d),o=c.parseHeader("www-authenticate");break;case"proxy-authenticate":c.setHeader("proxy-authenticate",d),o=c.parseHeader("proxy-authenticate");break;case"session-expires":case"x":c.setHeader("session-expires",d),o=c.parseHeader("session-expires"),o&&(c.session_expires=o.expires,c.session_expires_refresher=o.refresher);break;case"refer-to":case"r":c.setHeader("refer-to",d),o=c.parseHeader("refer-to"),o&&(c.refer_to=o);break;case"replaces":c.setHeader("replaces",d),o=c.parseHeader("replaces"),o&&(c.replaces=o);break;case"event":case"o":c.setHeader("event",d),o=c.parseHeader("event"),o&&(c.event=o);break;default:c.addHeader(r,d),o=0}return o===void 0?{error:`error parsing header "${r}"`}:!0}const FT={parseMessage:LT},Wi=new Wa("Registrator"),ha=10;class jT{constructor(t,n){this._reg_id=1,this._ua=t,this._transport=n,this._registrar=t.configuration.registrar_server,this._expires=t.configuration.register_expires,this._call_id=Ts.createRandomToken(22),this._cseq=0,this._to_uri=t.configuration.uri,this._registrationTimer=null,this._registering=!1,this._registered=!1,this._contact=this._ua.contact.toString();const a=this._contact.indexOf(">");if(a!==-1){const o=this._contact.slice(0,a)+this._contact.slice(a+1,this._contact.length);this._contact=o}this._extra_contact="",this._extraContactParams="",this._extra_contact+=";+sip.ice",this._extraHeaders=[],this._sipInstance=`"<urn:uuid:${this._ua.configuration.instance_id}>"`,this._extra_contact+=`;reg-id=${this._reg_id}`,this._extra_contact+=`;+sip.instance=${this._sipInstance}`}get registered(){return this._registered}setExtraHeaders(t){Array.isArray(t)||(t=[]),this._extraHeaders=t.slice()}setExtraContactParams(t){t instanceof Object||(t={}),this._extraContactParams="";for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)){const a=t[n];this._extraContactParams+=`;${n}`,a&&(this._extraContactParams+=`=${a}`)}}setExtraContactUriParams(t){t instanceof Object||(t={}),this._extraContactParams="";for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)){const a=t[n];this._extraContactParams+=`;${n}`,a&&(this._extraContactParams+=`=${a}`)}}register(){if(this._registering){Wi.debug("Register request in progress...");return}const t=this._extraHeaders.slice();t.push(`Contact: ${this._contact}${this._extraContactParams}>${this._extra_contact};expires=${this._expires}`),t.push(`Expires: ${this._expires}`);const n=new yt.OutgoingRequest(L.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),a=new sl(this._ua,n,{onRequestTimeout:()=>{this._registrationFailure(null,L.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._registrationFailure(null,L.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:o=>{if(o.cseq===this._cseq)switch(this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(o.status_code):break;case/^2[0-9]{2}$/.test(o.status_code):{if(this._registering=!1,!o.hasHeader("Contact")){Wi.debug("no Contact header in response to REGISTER, response ignored");break}const s=o.headers.Contact.reduce((_,g)=>_.concat(g.parsed),[]);let r=s.find(_=>this._sipInstance===_.getParam("+sip.instance")&&this._reg_id===parseInt(_.getParam("reg-id")));if(r||(r=s.find(_=>_.uri.user===this._ua.contact.uri.user)),!r){Wi.debug("no Contact header pointing to us, response ignored");break}let d=r.getParam("expires");!d&&o.hasHeader("expires")&&(d=o.getHeader("expires")),d||(d=this._expires),d=Number(d),d<ha&&(d=ha);const h=d>64?d*1e3/2+Math.floor((d/2-32)*1e3*Math.random()):d*1e3-5e3;this._registrationTimer=setTimeout(()=>{this._registrationTimer=null,this._ua.listeners("registrationExpiring").length===0?this.register():this._ua.emit("registrationExpiring")},h),r.hasParam("temp-gruu")&&(this._ua.contact.temp_gruu=r.getParam("temp-gruu").replace(/"/g,"")),r.hasParam("pub-gruu")&&(this._ua.contact.pub_gruu=r.getParam("pub-gruu").replace(/"/g,"")),this._registered||(this._registered=!0,this._ua.registered({response:o}));break}case/^423$/.test(o.status_code):{o.hasHeader("min-expires")?(this._expires=Number(o.getHeader("min-expires")),this._expires<ha&&(this._expires=ha),this.register()):(Wi.debug("423 response received for REGISTER without Min-Expires"),this._registrationFailure(o,L.causes.SIP_FAILURE_CODE));break}default:{const s=Ts.sipErrorCause(o.status_code);this._registrationFailure(o,s)}}}});this._registering=!0,a.send()}unregister(t={}){if(!this._registered){Wi.debug("already unregistered");return}this._registered=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);const n=this._extraHeaders.slice();t.all?n.push(`Contact: *${this._extraContactParams}`):n.push(`Contact: ${this._contact}${this._extraContactParams}>${this._extra_contact};expires=0`),n.push("Expires: 0");const a=new yt.OutgoingRequest(L.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new sl(this._ua,a,{onRequestTimeout:()=>{this._unregistered(null,L.causes.REQUEST_TIMEOUT)},onTransportError:()=>{this._unregistered(null,L.causes.CONNECTION_ERROR)},onAuthenticated:()=>{this._cseq+=1},onReceiveResponse:s=>{switch(!0){case/^1[0-9]{2}$/.test(s.status_code):break;case/^2[0-9]{2}$/.test(s.status_code):this._unregistered(s);break;default:{const r=Ts.sipErrorCause(s.status_code);this._unregistered(s,r)}}}}).send()}close(){this._registered&&this.unregister()}onTransportClosed(){this._registering=!1,this._registrationTimer!==null&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}_registrationFailure(t,n){this._registering=!1,this._ua.registrationFailed({response:t||null,cause:n}),this._registered&&(this._registered=!1,this._ua.unregistered({response:t||null,cause:n}))}_unregistered(t,n){this._registering=!1,this._registered=!1,this._ua.unregistered({response:t||null,cause:n||null})}}const tt=console,Vs={STATUS_INIT:0,STATUS_READY:1,STATUS_USER_CLOSED:2,STATUS_NOT_READY:3,CONFIGURATION_ERROR:1,NETWORK_ERROR:2},qT=wT;class VT extends qT{constructor(t){super(t),this._msrp_sessions=[],this._transactions={nist:{},nict:{},ist:{},ict:{}},this._janus_sessions=[],this.newStreamPlugins=[],this.processStreamPlugins=[],this._registrator=new jT(this)}call(t,n){return super.call(t,n)}joinVideoCall(t,n,a){tt.debug("call()");const o=new Ha(this);return o.configureMedia({audio:!0,video:!0}),o.connect(t,n,a),o}startScreenShare(){tt.debug("startScreenShare()");for(const t in this._janus_sessions)this._janus_sessions[t].connectScreenShare()}changeMediaConstraints(t){for(const n in this._janus_sessions)this._janus_sessions[n].changeMediaConstraints(t)}startBlur(){for(const t in this._janus_sessions)this._janus_sessions[t].connectBlur()}stopBlur(){for(const t in this._janus_sessions)this._janus_sessions[t].stopBlur()}_loadConfig(t){try{rl.load(this._configuration,t)}catch(s){throw s}this._configuration.display_name===0&&(this._configuration.display_name="0"),this._configuration.instance_id||(this._configuration.instance_id=Ts.newUUID());let n;typeof window<"u"&&typeof window.document<"u"?n=window==null?void 0:window.navigator.userAgent:typeof self<"u"&&self.navigator&&(n=self.navigator.userAgent),n+=" "+De.USER_AGENT,this._configuration.user_agent=t.overrideUserAgent&&typeof t.overrideUserAgent=="function"?t.overrideUserAgent(n):n,t.onTransportCallback&&typeof t.onTransportCallback=="function"&&(this.onTransportCallback=t.onTransportCallback),this._configuration.jssip_id=Ts.createRandomToken(5);const a=this._configuration.uri.clone();a.user=null,this._configuration.hostport_params=a.toString().replace(/^sip:/i,"");try{this._transport=new eT(this._configuration.sockets,{max_interval:this._configuration.connection_recovery_max_interval,min_interval:this._configuration.connection_recovery_min_interval}),this._transport.onconnecting=BT.bind(this),this._transport.onconnect=GT.bind(this),this._transport.ondisconnect=WT.bind(this),this._transport.ondata=KT.bind(this)}catch(s){throw tt.warn(s),new qs.ConfigurationError("sockets",this._configuration.sockets)}if(delete this._configuration.sockets,this._configuration.authorization_user||(this._configuration.authorization_user=this._configuration.uri.user),!this._configuration.registrar_server){const s=this._configuration.uri.clone();s.user=null,s.clearParams(),s.clearHeaders(),this._configuration.registrar_server=s}this._configuration.no_answer_timeout*=1e3,this._configuration.contact_uri?this._configuration.via_host=this._configuration.contact_uri.host:this._configuration.contact_uri=new In("sip",Ts.createRandomToken(8),this._configuration.via_host,null,{transport:"ws"}),this._contact={pub_gruu:null,temp_gruu:null,uri:this._configuration.contact_uri,toString(s={}){const r=s.anonymous||null,d=s.outbound||null;let h="<";return r?h+=this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":h+=this.pub_gruu||this.uri.toString(),d&&(r?!this.temp_gruu:!this.pub_gruu)&&(h+=";ob"),h+=">",h}};const o=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(const s in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,s)&&(o.indexOf(s)!==-1?Object.defineProperty(this._configuration,s,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,s,{writable:!1,configurable:!1}));tt.debug("configuration parameters after validation:");for(const s in this._configuration)if(Object.prototype.hasOwnProperty.call(rl.settings,s))switch(s){case"uri":case"registrar_server":tt.debug(`- ${s}: ${this._configuration[s]}`);break;case"password":case"ha1":case"authorization_jwt":tt.debug(`- ${s}: NOT SHOWN`);break;default:tt.debug(`- ${s}: ${JSON.stringify(this._configuration[s])}`)}}newMSRPSession(t,n){t.on("msgHistoryUpdate",a=>{console.log(a)}),this._msrp_sessions[t.id]=t,this.emit("newMSRPSession",n)}newJanusSession(t,n){this._janus_sessions[t.id]=t,this.newStreamPlugins.forEach(a=>{a.setSession(t)}),this.processStreamPlugins.forEach(a=>{a.setSession(t)}),this.emit("newJanusSession",n)}kill(){}destroyMSRPSession(t){delete this._msrp_sessions[t.id]}destroyJanusSession(t){delete this._janus_sessions[t.id]}receiveRequest(t){var s,r,d,h;const n=t.method;if(t.ruri.user!==this._configuration.uri.user&&t.ruri.user!==this._contact.uri.user){tt.debug("Request-URI does not point to us"),t.method!==De.ACK&&t.reply_sl(404);return}if(t.ruri.scheme===De.SIPS){t.reply_sl(416);return}if(Gt.checkTransaction(this,t))return;if(n===De.INVITE?new Gt.InviteServerTransaction(this,this._transport,t):n!==De.ACK&&n!==De.CANCEL&&new Gt.NonInviteServerTransaction(this,this._transport,t),n===De.OPTIONS){if(this.listeners("newOptions").length===0){t.reply(200);return}new Qc.Options(this).init_incoming(t)}else if(n===De.MESSAGE){if(this.listeners("newMessage").length===0){t.reply(405);return}new Qc.Message(this).init_incoming(t)}else if(n===De.INVITE&&!t.to_tag&&this.listeners("newRTCSession").length===0){t.reply(405);return}let a,o;if(t.to_tag)if(a=this._findDialog(t.call_id,t.from_tag,t.to_tag),a)a.receiveRequest(t);else if(n===De.NOTIFY)if(o=this._findSession(t),o)o.receiveRequest(t);else{if(t.body)try{const _=JSON.parse(t.body)||{};(r=(s=_.plugindata)==null?void 0:s.data)!=null&&r.publishers&&Object.values(this._janus_sessions)[0].receivePublishers(_),(h=(d=_.plugindata)==null?void 0:d.data)!=null&&h.unpublished&&Object.values(this._janus_sessions)[0].receiveUnpublished(_.plugindata.data.unpublished)}catch(_){console.error(_)}t.reply(200)}else n!==De.ACK&&t.reply(481);else switch(n){case De.INVITE:if(window.RTCPeerConnection)if(t.hasHeader("replaces")){const _=t.replaces;a=this._findDialog(_.call_id,_.from_tag,_.to_tag),a?(o=a.owner,o.isEnded()?t.reply(603):o.receiveRequest(t)):t.reply(481)}else t.body.search(/MSRP/ig)>-1?(o=new ru(this),o.init_incoming(t)):t.body.search(/JANUS/ig)>-1||(o=new $g(this),o.init_incoming(t));else tt.warn("INVITE received but WebRTC is not supported"),t.reply(488);break;case De.BYE:t.reply(481);break;case De.CANCEL:o=this._findSession(t),o?o.receiveRequest(t):tt.debug("received CANCEL request for a non existent session");break;case De.ACK:break;case De.NOTIFY:this.emit("sipEvent",{event:t.event,request:t}),t.reply(200);break;default:t.reply(405);break}}startMSRP(t,n){tt.debug("startMSRP()",n);const a=new ru(this);return a.connect(t),a}startJanus(t,n){tt.debug("startJanus()",n);const a=new ru(this);return a.connect(t),a}terminateMSRPSessions(t){tt.debug("terminateSessions()");for(const n in this._msrp_sessions)this._msrp_sessions[n].isEnded()||this._msrp_sessions[n].terminate(t)}terminateJanusSessions(t){tt.debug("terminateSessions()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||this._janus_sessions[n].terminate(t)}enableJanusAudio(t){tt.debug("enableJanusAudio()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||(t?this._janus_sessions[n].startAudio():this._janus_sessions[n].stopAudio())}enableJanusVideo(t){tt.debug("enableJanusVideo()");for(const n in this._janus_sessions)this._janus_sessions[n].isEnded()||(t?this._janus_sessions[n].startVideo():this._janus_sessions[n].stopVideo())}terminateAllSessions(){for(const t in this._sessions)if(Object.prototype.hasOwnProperty.call(this._sessions,t)){tt.debug(`closing session ${t}`);try{this._sessions[t].terminate()}catch(n){console.error(n)}}}stop(t=!0){if(tt.debug("stop()"),this._dynConfiguration={},this._status===Vs.STATUS_USER_CLOSED){tt.debug("UA already closed");return}this._registrator.close();const n=Object.keys(this._sessions).length;t&&this.terminateAllSessions();for(const o in this._msrp_sessions)if(Object.prototype.hasOwnProperty.call(this._msrp_sessions,o)){tt.debug(`closing session ${o}`);try{this._msrp_sessions[o].terminate()}catch(s){console.error(s)}}for(const o in this._janus_sessions)if(Object.prototype.hasOwnProperty.call(this._janus_sessions,o)){tt.debug(`closing session ${o}`);try{this._janus_sessions[o].terminate()}catch(s){console.error(s)}}for(const o in this._applicants)if(Object.prototype.hasOwnProperty.call(this._applicants,o))try{this._applicants[o].close()}catch(s){console.error(s)}this._status=Vs.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&&n===0?this._transport.disconnect():this._closeTimer=setTimeout(()=>{this._closeTimer=null,this._transport.disconnect()},2e3)}}function BT(c){this.emit("connecting",c)}function GT(c){this._status!==Vs.STATUS_USER_CLOSED&&(this._status=Vs.STATUS_READY,this._error=null,this.emit("connected",c),this._dynConfiguration.register&&this._registrator.register())}function WT(c){const t=["nict","ict","nist","ist"];for(const n of t)for(const a in this._transactions[n])Object.prototype.hasOwnProperty.call(this._transactions[n],a)&&this._transactions[n][a].onTransportError();this.emit("disconnected",c),this._registrator.onTransportClosed(),this._status!==Vs.STATUS_USER_CLOSED&&(this._status=Vs.STATUS_NOT_READY,this._error=Vs.NETWORK_ERROR)}function KT(c){const t=c.transport;let n=c.message;const a=n;if(n=FT.parseMessage(n,this),this.onTransportCallback&&typeof this.onTransportCallback=="function"&&this.onTransportCallback(n,a),!!n&&!(this._status===Vs.STATUS_USER_CLOSED&&n instanceof pr.IncomingRequest)&&pT(n,this,t)){if(n instanceof pr.IncomingRequest)n.transport=t,this.receiveRequest(n);else if(n instanceof pr.IncomingResponse){let o;switch(n.method){case De.INVITE:o=this._transactions.ict[n.via_branch],o&&o.receiveResponse(n);break;case De.ACK:break;default:o=this._transactions.nict[n.via_branch],o&&o.receiveResponse(n);break}}}}const YT=["roomId","_audioMuted","_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","_localHold","_videoMuted","status","start_time","_remote_identity","audioTag","isOnHold","localMuted","autoAnswer","putOnHoldTimestamp"],JT=["_cancel_reason","_contact","direction","_end_time","_eventsCount","_from_tag","_id","_is_canceled","_is_confirmed","_late_sdp","status","start_time","_remote_identity","target_addr"];function Nf(c){const t={};return YT.forEach(n=>{c[n]!==void 0&&(t[n]=c[n])}),t.localHold=c._localHold,t}function Uf(c){const t={};return JT.forEach(n=>{c[n]!==void 0&&(t[n]=c[n])}),t}function Pf(c,t){const n=new AudioContext,a=n.createMediaStreamSource(c),o=n.createMediaStreamDestination(),s=n.createGain();return a.connect(s),s.connect(o),s.gain.value=t,o.stream}function zT(c,t,n,a){if(wh())return;const o=document.createElement("audio");o.id=t._id,o.className="audioTag",o.srcObject=c,o.setSinkId(n),o.volume=a,o.play(),t.audioTag=o}function XT(c){if(c&&typeof c.log=="function"&&typeof c.warn=="function"&&typeof c.error=="function")return!0}function wh(){return/Mobi|react-native|Android|iPhone/i.test(navigator.userAgent)}const QT=ut,ZT=Zt(),Dt=new QT("WebSocketInterface");var ev=class{constructor(t){Dt.debug('new() [url:"%s"]',t),this._url=t,this._sip_uri=null,this._via_transport=null,this._ws=null;const n=ZT.parse(t,"absoluteURI");if(n===-1)throw Dt.warn(`invalid WebSocket URI: ${t}`),new TypeError(`Invalid argument: ${t}`);if(n.scheme!=="wss"&&n.scheme!=="ws")throw Dt.warn(`invalid WebSocket URI scheme: ${n.scheme}`),new TypeError(`Invalid argument: ${t}`);this._sip_uri=`sip:${n.host}${n.port?`:${n.port}`:""};transport=ws`,this._via_transport=n.scheme.toUpperCase()}get via_transport(){return this._via_transport}set via_transport(t){this._via_transport=t.toUpperCase()}get sip_uri(){return this._sip_uri}get url(){return this._url}connect(){if(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(t){this._onError(t)}}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(t){return Dt.debug("send()"),this.isConnected()?(this._ws.send(t),!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:t,code:n,reason:a}){Dt.debug(`WebSocket ${this._url} closed`),t===!1&&Dt.debug("WebSocket abrupt disconnection"),this.ondisconnect(!t,n,a)}_onMessage({data:t}){Dt.debug("received WebSocket message"),this.ondata(t)}_onError(t){Dt.warn(`WebSocket ${this._url} error: `,t)}};const bu=Fa,tv=De,sv=Cs,nv=Ct(),rv=bh,iv=ys(),lv=$u(),av=Zt(),ov=ev,uv=gr("JsSIP");uv("version %s",bu.version);var cv={C:tv,Exceptions:sv,Utils:nv,UA:rv,URI:iv,NameAddrHeader:lv,WebSocketInterface:ov,Grammar:av,debug:gr,get name(){return bu.title},get version(){return bu.version}};const fv=ze(cv);function iu(c){return c<10?`0${c}`:`${c}`}function hv(c){let t=c.hours||0,n=c.minutes||0,a=c.seconds||0;a++,a===60&&(a=0,n++,n===60&&(n=0,t++));const o=`${iu(t)}:${iu(n)}:${iu(a)}`;return{seconds:a,minutes:n,hours:t,formatted:o}}var At={};At.forEach=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)if(o in c){const s=Promise.resolve(c[o]).then(r=>t.call(n||globalThis,r,o,c));a.push(s)}await Promise.all(a)};At.forEachSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)a in c&&await t.call(n||globalThis,await c[a],a,c)};At.map=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)o in c&&(a[o]=Promise.resolve(c[o]).then(s=>t.call(n||globalThis,s,o,c)));return Promise.all(a)};At.mapSeries=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)o in c&&(a[o]=await t.call(n||globalThis,await c[o],o,c));return a};At.find=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a();let s=1;for(let r=0;r<c.length;r++){const d=h=>{h?a(c[r]):s===c.length&&a(),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}});At.findSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(await t.call(n||globalThis,await c[a],a,c))return c[a]};At.findIndex=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a(-1);let s=1;for(let r=0;r<c.length;r++){const d=h=>{h?a(r):s===c.length&&a(-1),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}});At.findIndexSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(await t.call(n||globalThis,await c[a],a,c))return a};At.some=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a(!1);let s=1;for(let r=0;r<c.length;r++){if(!(r in c)){s++;continue}const d=h=>{h?a(!0):s===c.length&&a(!1),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}});At.someSeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(a in c&&await t.call(n||globalThis,await c[a],a,c))return!0;return!1};At.every=(c,t,n)=>new Promise((a,o)=>{if(c.length===0)return a(!0);let s=1;for(let r=0;r<c.length;r++){if(!(r in c)){s++;continue}const d=h=>{h?s===c.length&&a(!0):a(!1),s++};Promise.resolve(c[r]).then(h=>t.call(n||globalThis,h,r,c)).then(d).catch(o)}});At.everySeries=async(c,t,n)=>{for(let a=0;a<c.length;a++)if(a in c&&!await t.call(n||globalThis,await c[a],a,c))return!1;return!0};At.filter=(c,t,n)=>new Promise(async(a,o)=>{const s=[];for(let d=0;d<c.length;d++)d in c&&(s[d]=Promise.resolve(c[d]).then(h=>t.call(n||globalThis,h,d,c)).catch(o));const r=[];for(let d=0;d<s.length;d++)await s[d]&&r.push(await c[d]);a(r)});At.filterSeries=async(c,t,n)=>{const a=[];for(let o=0;o<c.length;o++)o in c&&await t.call(n||globalThis,await c[o],o,c)&&a.push(await c[o]);return a};At.reduce=async(c,t,n)=>{if(c.length===0&&n===void 0)throw TypeError("Reduce of empty array with no initial value");let a,o;for(n!==void 0?(o=n,a=0):(o=c[0],a=1),a;a<c.length;a++)a in c&&(o=await t(await o,await c[a],a,c));return o};var Oh={};(function(c){const t=At;Object.keys(t).forEach(n=>{const a=n.charAt(0).toUpperCase()+n.slice(1);c[`async${a}`]=async function(...o){return t[n](this,...o)}})})(Oh);const dv=At,_v=Oh;var pv=Object.assign(dv,{instanceMethods:_v});const An=new AudioContext,Xt={NEW_CALL:"new_call",CALL_CONFIRMED:"confirmed",CALL_FAILED:"failed",CALL_PROGRESS:"progress",CALL_ENDED:"ended"};var mv={exports:{}};(function(c){var t=function(n){var a=Object.prototype,o=a.hasOwnProperty,s=Object.defineProperty||function(ee,W,G){ee[W]=G.value},r,d=typeof Symbol=="function"?Symbol:{},h=d.iterator||"@@iterator",_=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 oe?W:oe,be=Object.create(ge.prototype),xe=new P(re||[]);return s(be,"_invoke",{value:J(ee,G,xe)}),be}n.wrap=E;function y(ee,W,G){try{return{type:"normal",arg:ee.call(W,G)}}catch(re){return{type:"throw",arg:re}}}var C="suspendedStart",A="suspendedYield",I="executing",H="completed",$={};function oe(){}function N(){}function j(){}var Se={};T(Se,h,function(){return this});var ve=Object.getPrototypeOf,k=ve&&ve(ve(se([])));k&&k!==a&&o.call(k,h)&&(Se=k);var D=j.prototype=oe.prototype=Object.create(Se);N.prototype=j,s(D,"constructor",{value:j,configurable:!0}),s(j,"constructor",{value:N,configurable:!0}),N.displayName=T(j,g,"GeneratorFunction");function B(ee){["next","throw","return"].forEach(function(W){T(ee,W,function(G){return this._invoke(W,G)})})}n.isGeneratorFunction=function(ee){var W=typeof ee=="function"&&ee.constructor;return W?W===N||(W.displayName||W.name)==="GeneratorFunction":!1},n.mark=function(ee){return Object.setPrototypeOf?Object.setPrototypeOf(ee,j):(ee.__proto__=j,T(ee,g,"GeneratorFunction")),ee.prototype=Object.create(D),ee},n.awrap=function(ee){return{__await:ee}};function V(ee,W){function G(be,xe,Ae,le){var ye=y(ee[be],ee,xe);if(ye.type==="throw")le(ye.arg);else{var nt=ye.arg,at=nt.value;return at&&typeof at=="object"&&o.call(at,"__await")?W.resolve(at.__await).then(function(Ee){G("next",Ee,Ae,le)},function(Ee){G("throw",Ee,Ae,le)}):W.resolve(at).then(function(Ee){nt.value=Ee,Ae(nt)},function(Ee){return G("throw",Ee,Ae,le)})}}var re;function ge(be,xe){function Ae(){return new W(function(le,ye){G(be,xe,le,ye)})}return re=re?re.then(Ae,Ae):Ae()}s(this,"_invoke",{value:ge})}B(V.prototype),T(V.prototype,_,function(){return this}),n.AsyncIterator=V,n.async=function(ee,W,G,re,ge){ge===void 0&&(ge=Promise);var be=new V(E(ee,W,G,re),ge);return n.isGeneratorFunction(W)?be:be.next().then(function(xe){return xe.done?xe.value:be.next()})};function J(ee,W,G){var re=C;return function(be,xe){if(re===I)throw new Error("Generator is already running");if(re===H){if(be==="throw")throw xe;return st()}for(G.method=be,G.arg=xe;;){var Ae=G.delegate;if(Ae){var le=F(Ae,G);if(le){if(le===$)continue;return le}}if(G.method==="next")G.sent=G._sent=G.arg;else if(G.method==="throw"){if(re===C)throw re=H,G.arg;G.dispatchException(G.arg)}else G.method==="return"&&G.abrupt("return",G.arg);re=I;var ye=y(ee,W,G);if(ye.type==="normal"){if(re=G.done?H:A,ye.arg===$)continue;return{value:ye.arg,done:G.done}}else ye.type==="throw"&&(re=H,G.method="throw",G.arg=ye.arg)}}}function F(ee,W){var G=W.method,re=ee.iterator[G];if(re===r)return W.delegate=null,G==="throw"&&ee.iterator.return&&(W.method="return",W.arg=r,F(ee,W),W.method==="throw")||G!=="return"&&(W.method="throw",W.arg=new TypeError("The iterator does not provide a '"+G+"' method")),$;var ge=y(re,ee.iterator,W.arg);if(ge.type==="throw")return W.method="throw",W.arg=ge.arg,W.delegate=null,$;var be=ge.arg;if(!be)return W.method="throw",W.arg=new TypeError("iterator result is not an object"),W.delegate=null,$;if(be.done)W[ee.resultName]=be.value,W.next=ee.nextLoc,W.method!=="return"&&(W.method="next",W.arg=r);else return be;return W.delegate=null,$}B(D),T(D,g,"Generator"),T(D,h,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)}n.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[h];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(o.call(ee,G))return ge.value=ee[G],ge.done=!1,ge;return ge.value=r,ge.done=!0,ge};return re.next=re}}return{next:st}}n.values=se;function st(){return{value:r,done:!0}}return P.prototype={constructor:P,reset:function(ee){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(U),!ee)for(var W in this)W.charAt(0)==="t"&&o.call(this,W)&&!isNaN(+W.slice(1))&&(this[W]=r)},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=r),!!ye}for(var re=this.tryEntries.length-1;re>=0;--re){var ge=this.tryEntries[re],be=ge.completion;if(ge.tryLoc==="root")return G("end");if(ge.tryLoc<=this.prev){var xe=o.call(ge,"catchLoc"),Ae=o.call(ge,"finallyLoc");if(xe&&Ae){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(Ae){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&&o.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,$):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),$},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),$}},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=r),$}},n}(c.exports);try{regeneratorRuntime=t}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}})(mv);var Dh={exports:{}};(function(c){(function(t,n){c.exports?c.exports=n():t.log=n()})(jh,function(){var t=function(){},n="undefined",a=typeof window!==n&&typeof window.navigator!==n&&/Trident\/|MSIE /.test(window.navigator.userAgent),o=["trace","debug","info","warn","error"];function s(A,I){var H=A[I];if(typeof H.bind=="function")return H.bind(A);try{return Function.prototype.bind.call(H,A)}catch{return function(){return Function.prototype.apply.apply(H,[A,arguments])}}}function r(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function d(A){return A==="debug"&&(A="log"),typeof console===n?!1:A==="trace"&&a?r:console[A]!==void 0?s(console,A):console.log!==void 0?s(console,"log"):t}function h(A,I){for(var H=0;H<o.length;H++){var $=o[H];this[$]=H<A?t:this.methodFactory($,A,I)}this.log=this.debug}function _(A,I,H){return function(){typeof console!==n&&(h.call(this,I,H),this[A].apply(this,arguments))}}function g(A,I,H){return d(A)||_.apply(this,arguments)}function T(A,I,H){var $=this,oe;I=I??"WARN";var N="loglevel";typeof A=="string"?N+=":"+A:typeof A=="symbol"&&(N=void 0);function j(D){var B=(o[D]||"silent").toUpperCase();if(!(typeof window===n||!N)){try{window.localStorage[N]=B;return}catch{}try{window.document.cookie=encodeURIComponent(N)+"="+B+";"}catch{}}}function Se(){var D;if(!(typeof window===n||!N)){try{D=window.localStorage[N]}catch{}if(typeof D===n)try{var B=window.document.cookie,V=B.indexOf(encodeURIComponent(N)+"=");V!==-1&&(D=/^([^;]+)/.exec(B.slice(V))[1])}catch{}return $.levels[D]===void 0&&(D=void 0),D}}function ve(){if(!(typeof window===n||!N)){try{window.localStorage.removeItem(N);return}catch{}try{window.document.cookie=encodeURIComponent(N)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}$.name=A,$.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},$.methodFactory=H||g,$.getLevel=function(){return oe},$.setLevel=function(D,B){if(typeof D=="string"&&$.levels[D.toUpperCase()]!==void 0&&(D=$.levels[D.toUpperCase()]),typeof D=="number"&&D>=0&&D<=$.levels.SILENT){if(oe=D,B!==!1&&j(D),h.call($,D,A),typeof console===n&&D<$.levels.SILENT)return"No console available for logging"}else throw"log.setLevel() called with invalid level: "+D},$.setDefaultLevel=function(D){I=D,Se()||$.setLevel(D,!1)},$.resetLevel=function(){$.setLevel(I,!1),ve()},$.enableAll=function(D){$.setLevel($.levels.TRACE,D)},$.disableAll=function(D){$.setLevel($.levels.SILENT,D)};var k=Se();k==null&&(k=I),$.setLevel(k,!1)}var E=new T,y={};E.getLogger=function(I){if(typeof I!="symbol"&&typeof I!="string"||I==="")throw new TypeError("You must supply a name when creating a logger.");var H=y[I];return H||(H=y[I]=new T(I,E.getLevel(),E.methodFactory)),H};var C=typeof window!==n?window.log:void 0;return E.noConflict=function(){return typeof window!==n&&window.log===E&&(window.log=C),E},E.getLoggers=function(){return y},E.default=E,E})})(Dh);var It=Dh.exports;const vs=()=>`${new Date().toISOString()} | metrics`,Es=(c,t,n)=>`${c} | ${t} | ${n}`;It.setDefaultLevel(It.levels.TRACE);const gv=c=>{It.info(Es(vs(),"log ",`set log level to ${c?"verbose":"info"}`)),It.setLevel(c?It.levels.TRACE:It.levels.INFO)},Tv=c=>{const t=[...Object.keys(It.levels)];t.includes(c)?(It.info(Es(vs(),"log ",`update log level to ${c.toLowerCase()}`)),It.setLevel(c)):It.warn(Es(vs(),"log ","Incorrect log level please choose one of "),t)},Pe=(c,t,n)=>{n?It.debug(Es(vs(),c,t),n):It.debug(Es(vs(),c,t))},lu=(c,t)=>{It.info(Es(vs(),c,t))},Rn=(c,t)=>{It.info(Es(vs(),c,t))},Oa=(c,t)=>{It.warn(Es(vs(),c,t))},dr=(c,t)=>{It.error(Es(vs(),c,t))};function vv(c){return Math.floor(Math.random()*c).toString()}function xf(c,t){let n=t;return c.forEach(a=>{n=n.replace(a,"")}),n}function Ev(c,t){let n="";for(let a=0;a<t;a+=1)n+=c[vv(c.length)];return n}function Sv({length:c=20,useLetters:t=!0,useNumbers:n=!0,includeSymbols:a=[],excludeSymbols:o=[]}={}){let s="abcdefghijklmnopqrstuvwxyz",r="0123456789",d=[],h=[],_=[];return t&&(o.length&&(s=xf(o,s)),h=s.split("")),n&&(o.length&&(r=xf(o,r)),_=r.split("")),d=[...h,..._,...a],Ev(d,c)}var yv=Sv;const Qi=ze(yv),Cv=()=>"WebRTCMetrics",Av=()=>"5.0.3",$e={INBOUND:"inbound",OUTBOUND:"outbound"},gs={IDLE:"idle",RUNNING:"running",MUTED:"muted"},Ki={NEW:"new",CHECKING:"checking",CONNECTED:"connected",COMPLETED:"completed",DISCONNECTED:"disconnected",FAILED:"failed",CLOSED:"closed"},Rv=()=>({...{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:[]}}),Nh={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},Uh={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},Ph={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},xh={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},Iv=c=>{const t={pname:"",call_id:"",user_id:"",timestamp:null,count:0,audio:{},video:{},network:{infrastructure:3,local_candidate_id:"",local_candidate_type:"",local_candidate_protocol:"",local_candidate_relay_protocol:"",remote_candidate_id:"",remote_candidate_type:"",remote_candidate_protocol:""},data:{total_KBytes_in:0,total_KBytes_out:0,delta_KBytes_in:0,delta_KBytes_out:0,delta_kbs_in:0,delta_kbs_out:0,delta_kbs_bandwidth_in:0,delta_kbs_bandwidth_out:0,delta_rtt_connectivity_ms:null,total_rtt_connectivity_ms:0,total_rtt_connectivity_measure:0},experimental:{time_to_measure_ms:0}};if(c){const n={...c,audio:{},video:{},data:{...c.data},network:{...c.network},experimental:{...c.experimental}};return Object.keys(c.audio).forEach(a=>{n.audio[a]={...c.audio[a]}}),Object.keys(c.video).forEach(a=>{n.video[a]={...c.video[a]}}),n}return{...t,audio:{},video:{},data:{...t.data},network:{...t.network},experimental:{...t.experimental}}},bv={refreshEvery:2e3,startAfter:0,stopAfter:-1,verbose:!1,pname:`p-${Qi()}`,cid:`c-${Qi()}`,uid:`u-${Qi()}`,record:!1,ticket:!0},zt={CANDIDATE_PAIR:"candidate-pair",CODEC:"codec",INBOUND_RTP:"inbound-rtp",LOCAL_CANDIDATE:"local-candidate",MEDIA_SOURCE:"media-source",OUTBOUND_RTP:"outbound-rtp",REMOTE_CANDIDATE:"remote-candidate",REMOTE_INBOUND_RTP:"remote-inbound-rtp",TRACK:"track"},q={AUDIO_LEVEL:"audioLevel",AVAILABLE_OUTGOING_BITRATE:"availableOutgoingBitrate",AVAILABLE_INCOMING_BITRATE:"availableIncomingBitrate",BYTES_RECEIVED:"bytesReceived",BYTES_SENT:"bytesSent",CANDIDATE_TYPE:"candidateType",CHANNELS:"channels",CLOCK_RATE:"clockRate",CODEC_ID:"codecId",CURRENT_ROUND_TRIP_TIME:"currentRoundTripTime",ROUND_TRIP_TIME:"roundTripTime",FRACTION_LOST:"fractionLost",FRAME_HEIGHT:"frameHeight",FRAME_WIDTH:"frameWidth",QUALITY_LIMITATION_REASON:"qualityLimitationReason",QUALITY_LIMITATION_DURATIONS:"qualityLimitationDurations",QUALITY_LIMITATION_RESOLUTION_CHANGES:"qualityLimitationResolutionChanges",ID:"id",JITTER:"jitter",KIND:"kind",MEDIA_TYPE:"mediaType",MIME_TYPE:"mimeType",LOCAL_CANDIDATE_ID:"localCandidateId",NETWORK_TYPE:"networkType",RELAY_PROTOCOL:"relayProtocol",NOMINATED:"nominated",PACKETS_LOST:"packetsLost",PACKETS_RECEIVED:"packetsReceived",PACKETS_SENT:"packetsSent",PROTOCOL:"protocol",PORT:"port",REMOTE_CANDIDATE_ID:"remoteCandidateId",REMOTE_SOURCE:"remoteSource",RESPONSES_RECEIVED:"responsesReceived",SDP_FMTP_LINE:"sdpFmtpLine",SSRC:"ssrc",SELECTED:"selected",STATE:"state",TIMESTAMP:"timestamp",TOTAL_ROUND_TRIP_TIME:"totalRoundTripTime",TOTAL_ROUND_TRIP_TIME_MEASUREMENTS:"roundTripTimeMeasurements",TYPE:"type",DECODER_IMPLEMENTATION:"decoderImplementation",ENCODER_IMPLEMENTATION:"encoderImplementation",FRAMES_DECODED:"framesDecoded",FRAMES_ENCODED:"framesEncoded",FRAMES_PER_SECOND:"framesPerSecond",TOTAL_DECODE_TIME:"totalDecodeTime",TOTAL_ENCODE_TIME:"totalEncodeTime",PLI:"pliCount",NACK:"nackCount"},x={SUCCEEDED:"succeeded",AUDIO:"audio",VIDEO:"video"},Yi={ETHERNET:0,CELLULAR_5G:2,WIFI:3,CELLULAR_4G:5,CELLULAR:10},au={ETHERNET:"ethernet",CELLULAR_4G:"cellular",WIFI:"wifi"},ne={AUDIO:"audio",VIDEO:"video",NETWORK:"network",DATA:"data"},ou="config ",wv=(c,t={},n)=>{const a={...n,...t};return t.pname||Oa(ou,`Argument [String] 'cfg.pname' for the peerConnection name or id is missing - use generated '${n.pname}'`),t.cid||Oa(ou,`Argument [String] 'cfg.cid' for the call name or id is missing - use generated '${n.cid}'`),t.uid||Oa(ou,`Argument [String] 'cfg.uid' for the user name or id is missing - use generated '${n.uid}'`),a.pc=c,a},Ov=(c={})=>{const t={...bv,...c};return t.name=Cv(),t.version=Av(),t},ml=(c,t,n,a=!1,o)=>{let s=c.map(r=>{if(!n)return r[t];if(!o)return r[t][n];const d=r[t][o];return d?d[n]:null});return s=s.filter(r=>a?Number.isFinite(r)&&r>0:Number.isFinite(r)),s.length===0?[]:s},Gs=c=>c.reduce((t,n)=>t+n,0)/c.length,Dv=()=>`probe-${Qi()}`,Nv=()=>`coltr-${Qi()}`,kf=c=>new Promise(t=>setTimeout(t,c)),wu=(c,t,n)=>{t?c.call(t,n):c(n)},Ke=(c,t,n,a)=>{const o=ml(c,t,n,!0,a);if(o.length===0)return null;const s=o.reduce((_,g)=>_+g,0)/o.length;return s===0?null:o.map(_=>Math.abs(s-_)).reduce((_,g)=>_+g,0)/o.length*100/s},Xe=(c,t,n,a=!1,o)=>{const s=ml(c,t,n,a,o);return s.length===0?null:s.reduce((r,d)=>r+d,0)/s.length},Sn=(c,t,n)=>ml(c,t,n).reduce((o,s)=>o+s,0),Ye=(c,t,n,a)=>{const o=ml(c,t,n,!0,a);return o.length===0?null:Math.min(...o)},Je=(c,t,n,a)=>{const o=ml(c,t,n,!1,a);return o.length===0?null:Math.max(...o)},gt=(c,t,n,a)=>{const o=c.slice().pop();if(!o)return null;if(!n)return o[t];if(!a)return o[t][n];const s=o[t][a];return s?s[n]:null},Uv=c=>c.slice().pop(),ct=(c,t,n)=>{if(!t)return null;const a={};let o=t[x.AUDIO][c];o||(o=n===$e.INBOUND?{...Nh}:{...Uh}),a[x.AUDIO]=o;let s=t[x.VIDEO][c];return s||(s=n===$e.INBOUND?{...Ph}:{...xh}),a[x.VIDEO]=s,a},Ji="exporter ",Pv="2.0",Mf=(c,t,n)=>{if(!c||c.length===0)return 0;const a=c[c.length-1];if(!a)return 0;const o=a[t][n];if(o){const s=o.total_rtt_ms_out,r=o.total_rtt_measure_out;return!r||!s?Xe(c,t,"delta_rtt_ms_out",!1,n):Number(s/r)}return null},xv=(c,t)=>{if(!c||c.length===0)return 0;const n=c[c.length-1];if(!n)return 0;const a=n[t].total_rtt_connectivity_ms,o=n[t].total_rtt_connectivity_measure;return!o||!a?Xe(c,t,"delta_rtt_connectivity_ms"):Number(a/o)},kv=c=>gt(c,"network","local_candidate_type")!=="relay"?`direct/${gt(c,"network","local_candidate_protocol")}`:`turn/${gt(c,"network","local_candidate_relay_protocol")}`,Mv=c=>{const t=gt(c,"network","remote_candidate_type"),n=gt(c,"network","remote_candidate_protocol");return t!=="relay"?`direct/${n}`:`turn/${n}`};class Lv{constructor(t){this._start=null,this._end=null,this._cfg=t,this._referenceReport=null,this._reports=[],this._events=[]}start(){lu(Ji,"start() - start exporter...");const t=new Date;return this._start=t.toJSON(),t}stop(){lu(Ji,"stop() - stop exporter...");const t=new Date;return this._end=t.toJSON(),t}saveReferenceReport(t){this._referenceReport=t}getReferenceReport(){return this._referenceReport}addReport(t){this._cfg.ticket&&(Pe(Ji,`addReport() - add report to exporter at ${t.timestamp}`),this._reports.push(t))}addCustomEvent(t){this._events.push(t)}reset(){lu(Ji,"resetReports() - reset reports"),this._reports=[],this._referenceReport=null,this._start=null,this._end=null}get ticket(){Pe(Ji,"ticket() - generate ticket");const t=gt(this._reports,"audio","total_packets_lost_in"),n=gt(this._reports,"audio","total_packets_in"),a=gt(this._reports,"video","total_packets_lost_in"),o=gt(this._reports,"video","total_packets_in"),s={},r=Uv(this._reports);return r&&(Object.keys(r[x.AUDIO]).forEach(d=>{const h=r[x.AUDIO][d];if(s[h.ssrc]={type:x.AUDIO,direction:h.direction},h.direction===$e.INBOUND){const _={avg:Xe(this._reports,x.AUDIO,"delta_jitter_ms_in",!1,d),min: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:Xe(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:Xe(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:Xe(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:Xe(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),C=gt(this._reports,x.AUDIO,"total_packets_in",d),A={lost:y,avg:Math.round((y/(y+C)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[d].jitter=_,s[d].mos=E,s[d].traffic=T,s[d].bitrate=g,s[d].loss=A}else{const _={avg:Xe(this._reports,x.AUDIO,"delta_jitter_ms_out",!1,d),min: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:Xe(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:Xe(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:Mf(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),C=gt(this._reports,x.AUDIO,"total_packets_out",d),A={lost:y,avg:Math.round((y/(y+C)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}},I={emodel:{avg:Xe(this._reports,x.AUDIO,"mos_emodel_out",!1,d),min: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:Xe(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"}};s[d].jitter=_,s[d].rtt=E,s[d].traffic=T,s[d].bitrate=g,s[d].loss=A,s[d].mos=I}}),Object.keys(r[x.VIDEO]).forEach(d=>{const h=r[x.VIDEO][d];if(s[d]={type:x.VIDEO,direction:h.direction},h.direction===$e.INBOUND){const _={avg:Xe(this._reports,x.VIDEO,"delta_jitter_ms_in",!1,d),min: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:Xe(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:Xe(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),C={lost:E,avg:Math.round((E/(E+y)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[d].jitter=_,s[d].traffic=T,s[d].bitrate=g,s[d].loss=C}else{const _={avg:Xe(this._reports,x.VIDEO,"delta_jitter_ms_out",!1,d),min: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:Xe(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:Xe(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:Mf(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),C=gt(this._reports,x.VIDEO,"total_packets_out",d),A={lost:y,avg:Math.round((y/(y+C)*100||0)*100)/100,_unit:{avg:"percent",lost:"number"}};s[d].jitter=_,s[d].rtt=E,s[d].traffic=T,s[d].bitrate=g,s[d].loss=A}})),{version:Pv,configuration:{frequency:this._cfg.refreshEvery},started:this._start,ended:this._end,ua:{agent:navigator.userAgent,pname:this._cfg.pname,user_id:this._cfg.uid},call:{call_id:this._cfg.cid,events:this._events},details:{count:this._reports.length,reports:this._cfg.record?this._reports:[],reference:this._referenceReport||null},ssrc:s,data:{rtt:{avg:xv(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((t/(t+n)*100||0)*100)/100}},video:{in:{avg:Math.round((a/(a+o)*100||0)*100)/100}},unit:{avg:"percent"}},bitrate:{in:{avg:Xe(this._reports,"data","delta_kbs_in"),min: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:Xe(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:Xe(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:Xe(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:kv(this._reports),remoteConnection:Mv(this._reports)}}}}updateConfig(t){this._cfg=t}getLastReport(){return this._reports.slice().pop()||null}getBeforeLastReport(){const t=this._reports.slice();return t.pop(),t.pop()||null}getReportsNumber(){return this._reports.length}}const js="extractor ",Lf=(c,t,n,a)=>{let o=!1;const s=a[t].total_rtt_ms_out,r=a[t].total_rtt_measure_out,d=n?n[t].total_rtt_ms_out:0,h=n?n[t].total_rtt_measure_out:0,_={rtt:null,totalRTT:s,totalRTTMeasurements:r};if(c[q.TIMESTAMP]===a[t].timestamp_out||!Object.prototype.hasOwnProperty.call(c,q.ROUND_TRIP_TIME)||Object.prototype.hasOwnProperty.call(c,q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS)&&(o=!0,Number(c[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])===0||Number(c[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-h===r))return _;const g=1e3*Number(c[q.ROUND_TRIP_TIME]);let T=s+g,E=r+1;return o&&(T=1e3*Number(c[q.TOTAL_ROUND_TRIP_TIME])-d,E=Number(c[q.TOTAL_ROUND_TRIP_TIME_MEASUREMENTS])-h),{rtt:g,totalRTT:T,totalRTTMeasurements:E}},$v=(c,t,n,a)=>{if(!Object.prototype.hasOwnProperty.call(c,q.CURRENT_ROUND_TRIP_TIME))return{rtt:null,totalRTT:a[t].total_rtt_connectivity_ms,totalRTTMeasurements:a[t].total_rtt_connectivity_measure};const o=1e3*Number(c[q.CURRENT_ROUND_TRIP_TIME]);let s=a[t].total_rtt_connectivity_ms+o,r=a[t].total_rtt_connectivity_measure+1;return Object.prototype.hasOwnProperty.call(c,q.TOTAL_ROUND_TRIP_TIME)&&(s=1e3*Number(c[q.TOTAL_ROUND_TRIP_TIME])-(n?n[t].total_rtt_connectivity_ms:0)),Object.prototype.hasOwnProperty.call(c,q.RESPONSES_RECEIVED)&&(r=Number(c[q.RESPONSES_RECEIVED])-(n?n[t].total_rtt_connectivity_measure:0)),{rtt:o,totalRTT:s,totalRTTMeasurements:r}},da=(c,t,n)=>c[q.TIMESTAMP]===n[t].timestamp_out||!Object.prototype.hasOwnProperty.call(c,q.JITTER)?null:1e3*(Number(c[q.JITTER])||0),Hv=(c,t)=>{if(!Object.prototype.hasOwnProperty.call(c,q.FRAMES_DECODED)||!Object.prototype.hasOwnProperty.call(c,q.TOTAL_DECODE_TIME))return{delta_ms_decode_frame:t[x.VIDEO].delta_ms_decode_frame_in,frames_decoded:t[x.VIDEO].total_frames_decoded_in,total_decode_time:t[x.VIDEO].total_time_decoded_in};const n=c[q.FRAMES_DECODED],a=c[q.TOTAL_DECODE_TIME],o=a-t[x.VIDEO].total_time_decoded_in,s=n-t[x.VIDEO].total_frames_decoded_in;return{delta_ms_decode_frame:s>0?o*1e3/s:0,frames_decoded:n,total_decode_time:a}},Fv=(c,t)=>{if(!Object.prototype.hasOwnProperty.call(c,q.FRAMES_ENCODED)||!Object.prototype.hasOwnProperty.call(c,q.TOTAL_ENCODE_TIME))return{delta_ms_encode_frame:t[x.VIDEO].delta_ms_encode_frame_out,frames_encoded:t[x.VIDEO].total_frames_encoded_out,total_encode_time:t[x.VIDEO].total_time_encoded_out};const n=c[q.FRAMES_ENCODED],a=c[q.TOTAL_ENCODE_TIME],o=a-t[x.VIDEO].total_time_encoded_out,s=n-t[x.VIDEO].total_frames_encoded_out;return{delta_ms_encode_frame:s>0&&o?o*1e3/s:0,frames_encoded:n,total_encode_time:a}},$f=(c,t,n,a)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PACKETS_SENT)||!Object.prototype.hasOwnProperty.call(c,q.BYTES_SENT))return{packetsSent:n[t].total_packets_out,packetsLost:n[t].total_packets_lost_out,bytesSent:n[t].total_KBytes_out};const o=Number(c[q.PACKETS_SENT])||0-(a?a[t].total_packets_out:0),s=o-n[t].total_packets_out,r=Number(c[q.BYTES_SENT])/1024-(a?a[t].total_KBytes_out:0),d=r-n[t].total_KBytes_out,h=c[q.TIMESTAMP]||Date.now(),_=a?a.timestamp:null;let g=n.timestamp;!g&&_&&(g=_);const T=g?h-g:0,E=T>0?d*.008*1024/T*1e3:0;return{packetsSent:o,deltaPacketsSent:s,KBytesSent:r,deltaKBytesSent:d,kbsSent:E}},Hf=(c,t,n,a)=>{let o=n[t].total_packets_lost_out,s=0,r=0;return Object.prototype.hasOwnProperty.call(c,q.PACKETS_LOST)&&(o=Number(c[q.PACKETS_LOST])||0-(a?a[t].total_packets_lost_out:0),s=o-n[t].total_packets_lost_out),Object.prototype.hasOwnProperty.call(c,q.FRACTION_LOST)&&(r=Number(100*c[q.FRACTION_LOST])),{packetsLost:o,deltaPacketsLost:s,fractionLost:r}},Ff=(c,t,n,a)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PACKETS_RECEIVED)||!Object.prototype.hasOwnProperty.call(c,q.PACKETS_LOST)||!Object.prototype.hasOwnProperty.call(c,q.BYTES_RECEIVED))return{percent_packets_lost:n[t].percent_packets_lost_in,packetsReceived:n[t].total_packets_in,packetsLost:n[t].total_packets_lost_in,bytesReceived:n[t].total_KBytes_in};const o=Number(c[q.PACKETS_RECEIVED])||0-(a?a[t].total_packets_in:0),s=Number(c[q.PACKETS_LOST])||0-(a?a[t].total_packets_lost_in:0),r=s-n[t].total_packets_lost_in,d=o-n[t].total_packets_in,h=o!==n[t].total_packets_in?r*100/(r+d):0,_=Number(c[q.BYTES_RECEIVED])/1024-(a?a[t].total_KBytes_in:0),g=_-n[t].total_KBytes_in,T=c[q.TIMESTAMP]||Date.now(),E=a?a.timestamp:null;let y=n.timestamp;!y&&E&&(y=E);const C=y?T-y:0,A=C>0?g*.008*1024/C*1e3:0;return{percentPacketsLost:h,packetsReceived:o,deltaPacketsReceived:d,packetsLost:s,deltaPacketsLost:r,KBytesReceived:_,deltaKBytesReceived:g,kbsReceived:A}},jv=c=>c[q.CANDIDATE_TYPE]!=="relay"?"":c[q.RELAY_PROTOCOL]||"",qv=c=>{if(!Object.prototype.hasOwnProperty.call(c,q.NETWORK_TYPE))return Yi.WIFI;switch(c[q.NETWORK_TYPE]){case au.ETHERNET:return Yi.ETHERNET;case au.CELLULAR_4G:return Yi.CELLULAR_4G;case au.WIFI:return Yi.WIFI;default:return Yi.CELLULAR}},jf=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]},Vv=c=>{const t=Object.prototype.hasOwnProperty.call(c,q.QUALITY_LIMITATION_REASON)?c[q.QUALITY_LIMITATION_REASON]:null,n=Object.prototype.hasOwnProperty.call(c,q.QUALITY_LIMITATION_RESOLUTION_CHANGES)?c[q.QUALITY_LIMITATION_RESOLUTION_CHANGES]:null,a=Object.prototype.hasOwnProperty.call(c,q.QUALITY_LIMITATION_DURATIONS)?c[q.QUALITY_LIMITATION_DURATIONS]:null;return a&&Object.keys(a).forEach(o=>{a[o]>1e3&&(a[o]=Number(a[o]/1e3))}),{reason:t,durations:a,resolutionChanges:n}},Bv=(c,t,n)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PLI)||!Object.prototype.hasOwnProperty.call(c,q.NACK))return{pliCount:t.total_pli_sent_in,nackCount:t.total_nack_sent_in,deltaPliCount:0,deltaNackCount:0};const a=(c[q.PLI]||0)-(n?n[x.VIDEO].total_pli_sent_in:0),o=(c[q.NACK]||0)-(n?n[x.VIDEO].total_nack_sent_in:0);return{pliCount:a,nackCount:o,deltaPliCount:a-t[x.VIDEO].total_pli_sent_in,deltaNackCount:o-t[x.VIDEO].total_nack_sent_in}},Gv=(c,t,n)=>{if(!Object.prototype.hasOwnProperty.call(c,q.PLI)||!Object.prototype.hasOwnProperty.call(c,q.NACK))return{pliCount:t.total_pli_received_out,nackCount:t.total_nack_received_out,deltaPliCount:0,deltaNackCount:0};const a=(c[q.PLI]||0)-(n?n[x.VIDEO].total_pli_received_out:0),o=(c[q.NACK]||0)-(n?n[x.VIDEO].total_nack_received_out:0);return{pliCount:a,nackCount:o,deltaPliCount:a-t[x.VIDEO].total_pli_received_out,deltaNackCount:o-t[x.VIDEO].total_nack_received_out}},Wv=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}),Kv=c=>({clock_rate:c[q.CLOCK_RATE]||null,mime_type:c[q.MIME_TYPE]||null}),Yv=(c,t,n)=>{const a=(c[q.BYTES_RECEIVED]||0)/1024-(n?n.data.total_KBytes_in:0),o=(c[q.BYTES_SENT]||0)/1024-(n?n.data.total_KBytes_out:0),s=c[q.TIMESTAMP]||Date.now(),r=a-t.data.total_KBytes_in,d=o-t.data.total_KBytes_out,h=n?n.timestamp:null;let _=t.timestamp;!_&&h&&(_=h);const g=_?s-_:0,T=g>0?r*.008*1024/g*1e3:0,E=g>0?d*.008*1024/g*1e3:0;return{total_KBytes_received:a,total_KBytes_sent:o,delta_KBytes_received:r,delta_KBytes_sent:d,kbs_speed_received:T,kbs_speed_sent:E}},Jv=c=>{const t=c[q.AVAILABLE_INCOMING_BITRATE]/1024||0,n=c[q.AVAILABLE_OUTGOING_BITRATE]/1024||0;return{kbs_incoming_bandwidth:t,kbs_outgoing_bandwidth:n}},zv=(c,t,n,a)=>{if(!c)return[];switch(c[q.TYPE]){case zt.CANDIDATE_PAIR:let o=!1;if(c[q.NOMINATED]&&c[q.STATE]===x.SUCCEEDED&&(o=!0,Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c),q.SELECTED in c&&!c[q.SELECTED]&&(o=!1)),o){const r=c[q.LOCAL_CANDIDATE_ID],d=c[q.REMOTE_CANDIDATE_ID],h=Yv(c,t,a),_=Jv(c),g=$v(c,"data",a,t);return[{type:ne.NETWORK,value:{local_candidate_id:r}},{type:ne.NETWORK,value:{remote_candidate_id:d}},{type:ne.DATA,value:{total_KBytes_in:h.total_KBytes_received}},{type:ne.DATA,value:{total_KBytes_out:h.total_KBytes_sent}},{type:ne.DATA,value:{delta_KBytes_in:h.delta_KBytes_received}},{type:ne.DATA,value:{delta_KBytes_out:h.delta_KBytes_sent}},{type:ne.DATA,value:{delta_kbs_in:h.kbs_speed_received}},{type:ne.DATA,value:{delta_kbs_out:h.kbs_speed_sent}},{type:ne.DATA,value:{delta_kbs_bandwidth_in:_.kbs_incoming_bandwidth}},{type:ne.DATA,value:{delta_kbs_bandwidth_out:_.kbs_outgoing_bandwidth}},{type:ne.DATA,value:{delta_rtt_connectivity_ms:g.rtt}},{type:ne.DATA,value:{total_rtt_connectivity_ms:g.totalRTT}},{type:ne.DATA,value:{total_rtt_connectivity_measure:g.totalRTTMeasurements}}]}break;case zt.LOCAL_CANDIDATE:if(c[q.ID]===t.network.local_candidate_id)return[{type:ne.NETWORK,value:{infrastructure:qv(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:jv(c)}}];break;case zt.REMOTE_CANDIDATE:if(c[q.ID]===t.network.remote_candidate_id)return[{type:ne.NETWORK,value:{remote_candidate_type:c[q.CANDIDATE_TYPE]||""}},{type:ne.NETWORK,value:{remote_candidate_protocol:c[q.PROTOCOL]||""}}];break;case zt.INBOUND_RTP:{Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const r=c[q.SSRC],d=ct(r,t,$e.INBOUND);d&&(d.timestamp=t.timestamp);const h=ct(r,a,$e.INBOUND);if(h&&(h.timestamp=a.timestamp),c[q.MEDIA_TYPE]===x.AUDIO){const _=Ff(c,x.AUDIO,d,h),g=da(c,x.AUDIO,d),T=c[q.CODEC_ID]||"";return[{ssrc:r,type:ne.AUDIO,value:{codec_id_in:T}},{ssrc:r,type:ne.AUDIO,value:{total_packets_in:_.packetsReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_in:_.deltaPacketsReceived}},{ssrc:r,type:ne.AUDIO,value:{total_packets_lost_in:_.packetsLost}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_lost_in:_.deltaPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{percent_packets_lost_in:_.percentPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{total_KBytes_in:_.KBytesReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_KBytes_in:_.deltaKBytesReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_kbs_in:_.kbsReceived}},{ssrc:r,type:ne.AUDIO,value:{delta_jitter_ms_in:g}}]}if(c[q.MEDIA_TYPE]===x.VIDEO){const _=Hv(c,d),g=Ff(c,x.VIDEO,d,h),T=da(c,x.VIDEO,d),E=c[q.DECODER_IMPLEMENTATION]||null,y=c[q.CODEC_ID]||null,C=jf(c),A=Bv(c,d,h);return[{ssrc:r,type:ne.VIDEO,value:{codec_id_in:y}},{ssrc:r,type:ne.VIDEO,value:{total_packets_in:g.packetsReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_in:g.deltaPacketsReceived}},{ssrc:r,type:ne.VIDEO,value:{total_packets_lost_in:g.packetsLost}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_lost_in:g.deltaPacketsLost}},{ssrc:r,type:ne.VIDEO,value:{percent_packets_lost_in:g.percentPacketsLost}},{ssrc:r,type:ne.VIDEO,value:{total_KBytes_in:g.KBytesReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_KBytes_in:g.deltaKBytesReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_kbs_in:g.kbsReceived}},{ssrc:r,type:ne.VIDEO,value:{delta_jitter_ms_in:T}},{ssrc:r,type:ne.VIDEO,value:{decoder_in:E}},{ssrc:r,type:ne.VIDEO,value:{delta_ms_decode_frame_in:_.delta_ms_decode_frame}},{ssrc:r,type:ne.VIDEO,value:{total_frames_decoded_in:_.frames_decoded}},{ssrc:r,type:ne.VIDEO,value:{total_time_decoded_in:_.total_decode_time}},{ssrc:r,type:ne.VIDEO,value:{total_nack_sent_in:A.nackCount}},{ssrc:r,type:ne.VIDEO,value:{delta_nack_sent_in:A.deltaNackCount}},{ssrc:r,type:ne.VIDEO,value:{total_pli_sent_in:A.pliCount}},{ssrc:r,type:ne.VIDEO,value:{delta_pli_sent_in:A.deltaPliCount}},{ssrc:r,type:ne.VIDEO,value:{size_in:C}}]}break}case zt.OUTBOUND_RTP:{Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const r=c[q.SSRC],d=ct(r,t,$e.OUTBOUND);d&&(d.timestamp=t.timestamp);const h=ct(r,a,$e.OUTBOUND);if(h&&(h.timestamp=a.timestamp),c[q.MEDIA_TYPE]===x.AUDIO){const _=c[q.CODEC_ID]||null,g=$f(c,x.AUDIO,d,h);return[{ssrc:r,type:ne.AUDIO,value:{codec_id_out:_}},{ssrc:r,type:ne.AUDIO,value:{total_packets_out:g.packetsSent}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_out:g.deltaPacketsSent}},{ssrc:r,type:ne.AUDIO,value:{total_KBytes_out:g.KBytesSent}},{ssrc:r,type:ne.AUDIO,value:{delta_KBytes_out:g.deltaKBytesSent}},{ssrc:r,type:ne.AUDIO,value:{delta_kbs_out:g.kbsSent}}]}if(c[q.MEDIA_TYPE]===x.VIDEO){const _=c[q.ENCODER_IMPLEMENTATION]||null,g=c[q.CODEC_ID]||null,T=Fv(c,d),E=jf(c),y=Vv(c),C=Gv(c,d,h),A=$f(c,x.VIDEO,d,h);return[{ssrc:r,type:ne.VIDEO,value:{codec_id_out:g}},{ssrc:r,type:ne.VIDEO,value:{total_packets_out:A.packetsSent}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_out:A.deltaPacketsSent}},{ssrc:r,type:ne.VIDEO,value:{total_KBytes_out:A.KBytesSent}},{ssrc:r,type:ne.VIDEO,value:{delta_KBytes_out:A.deltaKBytesSent}},{ssrc:r,type:ne.VIDEO,value:{delta_kbs_out:A.kbsSent}},{ssrc:r,type:ne.VIDEO,value:{encoder_out:_}},{ssrc:r,type:ne.VIDEO,value:{delta_ms_encode_frame_out:T.delta_ms_encode_frame}},{ssrc:r,type:ne.VIDEO,value:{total_frames_encoded_out:T.frames_encoded}},{ssrc:r,type:ne.VIDEO,value:{total_time_encoded_out:T.total_encode_time}},{ssrc:r,type:ne.VIDEO,value:{total_nack_received_out:C.nackCount}},{ssrc:r,type:ne.VIDEO,value:{delta_nack_received_out:C.deltaNackCount}},{ssrc:r,type:ne.VIDEO,value:{total_pli_received_out:C.pliCount}},{ssrc:r,type:ne.VIDEO,value:{delta_pli_received_out:C.deltaPliCount}},{ssrc:r,type:ne.VIDEO,value:{size_out:E}},{ssrc:r,type:ne.VIDEO,value:{limitation_out:y}}]}break}case zt.MEDIA_SOURCE:{Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);break}case zt.TRACK:{Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);break}case zt.CODEC:const s=[];return Object.keys(t[x.AUDIO]).forEach(r=>{const d=t[x.AUDIO][r];if(d.codec_id_in===c[q.ID]||d.codec_id_out===c[q.ID]){Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const h=Wv(c);c[q.ID]===d.codec_id_in?s.push({ssrc:d.ssrc,type:ne.AUDIO,value:{codec_in:h}}):s.push({ssrc:d.ssrc,type:ne.AUDIO,value:{codec_out:h}})}}),Object.keys(t[x.VIDEO]).forEach(r=>{const d=t[x.VIDEO][r];if(d.codec_id_in===c[q.ID]||d.codec_id_out===c[q.ID]){Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const h=Kv(c);c[q.ID]===d.codec_id_in?s.push({ssrc:d.ssrc,type:ne.VIDEO,value:{codec_in:h}}):s.push({ssrc:d.ssrc,type:ne.VIDEO,value:{codec_out:h}})}}),s;case zt.REMOTE_INBOUND_RTP:{Pe(js,`analyze() - got stats ${c[q.TYPE]} for ${n}`,c);const r=c[q.SSRC],d=ct(r,t,$e.OUTBOUND),h=ct(r,a,$e.OUTBOUND);if(c[q.KIND]===x.AUDIO){const _=Lf(c,x.AUDIO,h,d),g=da(c,x.AUDIO,d),T=Hf(c,x.AUDIO,d,h);return[{ssrc:r,type:ne.AUDIO,value:{delta_rtt_ms_out:_.rtt}},{ssrc:r,type:ne.AUDIO,value:{total_rtt_ms_out:_.totalRTT}},{ssrc:r,type:ne.AUDIO,value:{total_rtt_measure_out:_.totalRTTMeasurements}},{ssrc:r,type:ne.AUDIO,value:{delta_jitter_ms_out:g}},{ssrc:r,type:ne.AUDIO,value:{timestamp_out:c[q.TIMESTAMP]}},{ssrc:r,type:ne.AUDIO,value:{total_packets_lost_out:T.packetsLost}},{ssrc:r,type:ne.AUDIO,value:{delta_packets_lost_out:T.deltaPacketsLost}},{ssrc:r,type:ne.AUDIO,value:{percent_packets_lost_out:T.fractionLost}}]}if(c[q.KIND]===x.VIDEO){const _=Lf(c,x.VIDEO,h,d),g=da(c,x.VIDEO,d),T=Hf(c,x.VIDEO,d,h);return[{ssrc:r,type:ne.VIDEO,value:{delta_rtt_ms_out:_.rtt}},{ssrc:r,type:ne.VIDEO,value:{total_rtt_ms_out:_.totalRTT}},{ssrc:r,type:ne.VIDEO,value:{total_rtt_measure_out:_.totalRTTMeasurements}},{ssrc:r,type:ne.VIDEO,value:{delta_jitter_ms_out:g}},{ssrc:r,type:ne.VIDEO,value:{timestamp_out:c[q.TIMESTAMP]}},{ssrc:r,type:ne.VIDEO,value:{total_packets_lost_out:T.packetsLost}},{ssrc:r,type:ne.VIDEO,value:{delta_packets_lost_out:T.deltaPacketsLost}},{ssrc:r,type:ne.VIDEO,value:{percent_packets_lost_out:T.fractionLost}}]}break}}return[]},Ya=c=>c<0?1:c>100?4.5:1+.035*c+7/1e6*c*(c-60)*(100-c),Xv=(c,t=x.AUDIO,n,a,o)=>{const s=ct(o,c,$e.INBOUND),r=ct(o,n,$e.INBOUND),d=ct(o,a,$e.INBOUND),h=[],_=[],g=s[t].percent_packets_lost_in,T=s[t].delta_jitter_ms_in,E=r&&r[t].delta_jitter_ms_in||null,y=d&&d[t].delta_jitter_ms_in||null,C=c.data.delta_rtt_connectivity_ms,A=n&&n.data.delta_rtt_connectivity_ms||null,I=a&&a.data.delta_rtt_connectivity_ms||null;C&&h.push(C),A&&h.push(A),I&&h.push(I),T&&_.push(T),n&&E&&_.push(E),a&&y&&_.push(y);const H=h.length>0?Gs(h):100,$=_.length>0?Gs(_):10,oe=93.2-g,N=.18*oe*oe-27.9*oe+1126.62,j=(H+$)/2,Se=j-177.3<0?0:1,ve=.024*j+.11*(j-177.3)*Se,k=N-ve;return Ya(k)},Qv=(c,t=x.AUDIO,n,a,o)=>{const s=ct(o,c,$e.OUTBOUND),r=ct(o,n,$e.OUTBOUND),d=ct(o,a,$e.OUTBOUND),h=[],_=[],g=s[t].percent_packets_lost_out,T=s[t].delta_rtt_ms_out,E=r&&r[t].delta_rtt_ms_out||null,y=d&&d[t].delta_rtt_ms_out||null,C=s[t].delta_jitter_ms_out,A=r&&r[t].delta_jitter_ms_out||null,I=d&&d[t].delta_jitter_ms_out||null,H=c.data.delta_rtt_connectivity_ms,$=n&&n.data.delta_rtt_connectivity_ms||null,oe=a&&a.data.delta_rtt_connectivity_ms||null;T?h.push(T):H&&h.push(H),E?h.push(E):$&&h.push($),y?h.push(y):oe&&h.push(oe),C&&_.push(C),n&&A&&_.push(A),a&&I&&_.push(I);const N=h.length>0?Gs(h):100,j=_.length>0?Gs(_):10,Se=93.2-g,ve=.18*Se*Se-27.9*Se+1126.62,k=(N+j)/2,D=k-177.3<0?0:1,B=.024*k+.11*(k-177.3)*D,V=ve-B;return Ya(V)},Zv=(c,t=x.AUDIO,n,a,o)=>{const s=ct(o,c,$e.INBOUND),r=ct(o,n,$e.INBOUND),d=ct(o,a,$e.INBOUND),h=[],_=[],g=s[t].percent_packets_lost_in/100,T=s[t].delta_jitter_ms_in,E=r&&r[t].delta_jitter_ms_in||null,y=d&&d[t].delta_jitter_ms_in||null,C=c.data.delta_rtt_connectivity_ms,A=n&&n.data.delta_rtt_connectivity_ms||null,I=a&&a.data.delta_rtt_connectivity_ms||null;C&&h.push(C),A&&h.push(A),I&&h.push(I),T&&_.push(T),r&&E&&_.push(E),d&&y&&_.push(y);const H=h.length>0?Gs(h):100,$=_.length>0?Gs(_):10,oe=0,N=19.8,j=29.7,Se=30,ve=(H+$)/2+Se,k=ve-177.3<0?0:1,D=.024*ve+.11*(ve-177.3)*k,V=93.2-(oe+N*Math.log(1+j*g)+D);return Ya(V)},eE=(c,t=x.AUDIO,n,a,o)=>{const s=ct(o,c,$e.OUTBOUND),r=ct(o,n,$e.OUTBOUND),d=ct(o,a,$e.OUTBOUND),h=[],_=[],g=s[t].percent_packets_lost_out/100,T=s[t].delta_rtt_ms_out,E=r&&r[t].delta_rtt_ms_out||null,y=d&&d[t].delta_rtt_ms_out||null,C=s[t].delta_jitter_ms_out,A=r&&r[t].delta_jitter_ms_out||null,I=d&&d[t].delta_jitter_ms_out||null,H=c.data.delta_rtt_connectivity_ms,$=n&&n.data.delta_rtt_connectivity_ms||null,oe=a&&a.data.delta_rtt_connectivity_ms||null;T?h.push(T):H&&h.push(H),E?h.push(E):$&&h.push($),y?h.push(y):oe&&h.push(oe),C&&_.push(C),r&&A&&_.push(A),d&&I&&_.push(I);const N=h.length>0?Gs(h):100,j=_.length>0?Gs(_):10,Se=0,ve=19.8,k=29.7,D=30,B=(N+j)/2+D,V=B-177.3<0?0:1,J=.024*B+.11*(B-177.3)*V,X=93.2-(Se+ve*Math.log(1+k*g)+J);return Ya(X)};class tE{constructor(t,n){this._callbacks={onreport:null,onticket:null},this._id=Nv(),this._moduleName=this._id,this._probeId=n,this._config=t,this._exporter=new Lv(t),this._state=gs.IDLE,this.registerToPCEvents(),Rn(this._moduleName,`new collector created for probe ${this._probeId}`)}analyze(t,n,a,o){const s=(h,_)=>h===x.AUDIO?_===zt.INBOUND_RTP?{...Nh}:{...Uh}:_===zt.INBOUND_RTP?{...Ph}:{...xh},r=Iv(n);r.pname=this._config.pname,r.call_id=this._config.cid,r.user_id=this._config.uid,r.count=n?n.count+1:1;let d=null;return t.forEach(h=>{!d&&h.timestamp&&(d=h.timestamp),zv(h,r,r.pname,o).forEach(g=>{if(g.value&&g.type)if(g.ssrc){let T=r[g.type][g.ssrc];T||(T=s(g.type,h.type),T.ssrc=g.ssrc,r[g.type][g.ssrc]=T),Object.keys(g.value).forEach(E=>{T[E]=g.value[E]})}else Object.keys(g.value).forEach(T=>{r[g.type][T]=g.value[T]})})}),r.timestamp=d,Object.keys(r[x.AUDIO]).forEach(h=>{const _=r[x.AUDIO][h];_.direction===$e.INBOUND?(_.mos_emodel_in=Xv(r,x.AUDIO,n,a,_.ssrc),_.mos_in=Zv(r,x.AUDIO,n,a,_.ssrc)):(_.mos_emodel_out=Qv(r,x.AUDIO,n,a,_.ssrc),_.mos_out=eE(r,x.AUDIO,n,a,_.ssrc))}),r}async takeReferenceStats(){return new Promise((t,n)=>{const a=Date.now();setTimeout(async()=>{try{const o=Date.now()-a,s=Date.now(),r=await this._config.pc.getStats(),d=this.analyze(r,null,null,null),h=Date.now();d.experimental.time_to_measure_ms=h-s,d.experimental.time_to_wait_ms=o,this._exporter.saveReferenceReport(d),Pe(this._moduleName,`got reference report for probe ${this._probeId}`),t()}catch(o){n(o)}},this._config.startAfter)})}async collectStats(){try{if(this._state!==gs.RUNNING||!this._config.pc)return Pe(this._moduleName,`report discarded (too late) for probe ${this._probeId}`),null;const t=Date.now(),n=await this._config.pc.getStats(),a=this.analyze(n,this._exporter.getLastReport(),this._exporter.getBeforeLastReport(),this._exporter.getReferenceReport()),o=Date.now();return a.experimental.time_to_measure_ms=o-t,this._exporter.addReport(a),Pe(this._moduleName,`got report for probe ${this._probeId}#${this._exporter.getReportsNumber()+1}`),this.fireOnReport(a),a}catch(t){return dr(this._moduleName,`got error ${t}`),null}}async start(){Pe(this._moduleName,"starting"),this.state=gs.RUNNING,this._startedTime=this._exporter.start(),Pe(this._moduleName,"started")}async mute(){this.state=gs.MUTED,Pe(this._moduleName,"muted")}async unmute(){this.state=gs.RUNNING,Pe(this._moduleName,"unmuted")}async stop(t){if(Pe(this._moduleName,`stopping${t?" by watchdog":""}...`),this._stoppedTime=this._exporter.stop(),this.state=gs.IDLE,this._config.ticket){const{ticket:n}=this._exporter;this.fireOnTicket(n)}this._exporter.reset(),Pe(this._moduleName,"stopped")}registerCallback(t,n,a){t in this._callbacks?(this._callbacks[t]={callback:n,context:a},Pe(this._moduleName,`registered callback '${t}'`)):dr(this._moduleName,`can't register callback for '${t}' - not found`)}unregisterCallback(t){t in this._callbacks?(this._callbacks[t]=null,delete this._callbacks[t],Pe(this._moduleName,`unregistered callback '${t}'`)):dr(this._moduleName,`can't unregister callback for '${t}' - not found`)}fireOnReport(t){this._callbacks.onreport&&wu(this._callbacks.onreport.callback,this._callbacks.onreport.context,t)}fireOnTicket(t){this._callbacks.onticket&&wu(this._callbacks.onticket.callback,this._callbacks.onticket.context,t)}updateConfig(t){this._config=t,this._exporter.updateConfig(t)}get state(){return this._state}set state(t){this._state=t,Pe(this._moduleName,`state changed to ${t}`)}addCustomEvent(t,n,a,o){this._exporter.addCustomEvent({at:typeof t=="object"?t.toJSON():t,category:n,name:a,description:o})}async registerToPCEvents(){const{pc:t}=this._config;if(navigator.mediaDevices.ondevicechange=async()=>{try{const n=await navigator.mediaDevices.enumerateDevices();this.addCustomEvent(new Date().toJSON(),"device",`${n.length} devices found`,"Media Devices state")}catch{dr(this._moduleName,"can't get devices")}},t){t.oniceconnectionstatechange=()=>{const a=t.iceConnectionState;a===Ki.CONNECTED||a===Ki.COMPLETED?this.addCustomEvent(new Date().toJSON(),"call",a,"ICE connection state"):a===Ki.DISCONNECTED||a===Ki.FAILED?this.addCustomEvent(new Date().toJSON(),"call",a,"ICE connection state"):a===Ki.CLOSED&&this.addCustomEvent(new Date().toJSON(),"call","ended","ICE connection state")},t.onicegatheringstatechange=()=>{const a=t.iceGatheringState;this.addCustomEvent(new Date().toJSON(),"call",a,"ICE gathering state")},t.ontrack=a=>{this.addCustomEvent(new Date().toJSON(),"call",`${a.track.kind}track`,"MediaStreamTrack received")},t.onnegotiationneeded=()=>{this.addCustomEvent(new Date().toJSON(),"call","negotiation","Media changed")};const n=t.getReceivers();if(n&&n.length>0){const a=n[0],{transport:o}=a;if(o){const{iceTransport:s}=o;s&&(s.onselectedcandidatepairchange=()=>{this.addCustomEvent(new Date().toJSON(),"call","transport","Candidates Pair changed")})}}}}}class sE{constructor(t){this._id=t.pname&&t.pname.substr(0,12).padEnd(12," ")||Dv(),this._moduleName=this._id,Rn(this._moduleName,"probe created"),this._config=t,this._collector=new tE(this._config,this._id)}set onreport(t){t?this._collector.registerCallback("onreport",t):this._collector.unregisterCallback("onreport")}set onticket(t){t?this._collector.registerCallback("onticket",t):this._collector.unregisterCallback("onticket")}get id(){return this._id}get pname(){return this._config.pname}get cid(){return this._config.cid}get uid(){return this._config.uid}get state(){return this._collector.state}set state(t){this._collector.state=t}addCustomEvent(t,n,a,o=new Date().toJSON()){this._collector.addCustomEvent(o,n,t,a)}get isRunning(){return this._collector.state===gs.RUNNING}get isIdle(){return this._collector.state===gs.IDLE}updateUserId(t){this._config.uid=t,this._collector.updateConfig(this._config)}updateCallId(t){this._config.cid=t,this._collector.updateConfig(this._config)}start(){if(!this.isIdle){Oa(this._moduleName,"probe is already running");return}this._collector.start()}stop(t=!1){this.isRunning&&this._collector.stop(t)}async takeReferenceStats(){return this._collector.takeReferenceStats()}async collectStats(){return this._collector.collectStats()}}const Rt="engine ";class nE{constructor(t){this._config=t,this._probes=[],this._startedTime=null,this._callbacks={onresult:null},Rn(Rt,`configured for probing every ${this._config.refreshEvery}ms`),Rn(Rt,`configured for starting after ${this._config.startAfter}ms`),Rn(Rt,`${!this._config.stopAfter||this._config.stopAfter!==-1?`configured for stopped after ${this._config.stopAfter}ms`:"configured for never stopped"}`),Pe(Rt,"engine initialized")}get probes(){return this._probes}get isRunning(){return this._probes.some(t=>t.isRunning)}get isIdle(){return this._probes.every(t=>t.isIdle)}addNewProbe(t,n){if(!t)throw new Error("undefined peer connection");const a=wv(t,n,this._config),o=new sE(a);return this._probes.push(o),Pe(Rt,`${this._probes.length} probes registered`),o}removeExistingProbe(t){if(!t)throw new Error("undefined probe");t.state===gs.RUNNING&&t.stop(),this._probes=this._probes.filter(n=>t.id!==n.id)}async start(){const t=()=>{this._probes.forEach(s=>s.start())},n=async()=>Promise.all(this._probes.map(s=>s.takeReferenceStats())),a=()=>this.isIdle?!1:!this._config.stopAfter||this._config.stopAfter<0?!0:Date.now()<this._startedTime+this._config.stopAfter,o=async()=>{const s=Rv(),r=this._probes.filter(d=>d.isRunning);for(const d of r){const h=await d.collectStats();h&&s.probes.push(h),Pe(Rt,`got probe ${d.id}`),await kf(0)}return s.delta_time_to_measure_probes_ms=Sn(s.probes,"experimental","time_to_measure_ms"),s.delta_KBytes_in=Sn(s.probes,"data","delta_KBytes_in"),s.delta_KBytes_out=Sn(s.probes,"data","delta_KBytes_out"),s.delta_kbs_in=Sn(s.probes,"data","delta_kbs_in"),s.delta_kbs_out=Sn(s.probes,"data","delta_kbs_out"),s.total_time_decoded_in=Sn(s.probes,"video","total_time_decoded_in"),s.total_time_encoded_out=Sn(s.probes,"video","total_time_encoded_out"),s};for(Pe(Rt,"starting to collect"),t(),Pe(Rt,"generating reference reports..."),await n(),Pe(Rt,"reference reports generated"),this._startedTime=Date.now();a();)if(Pe(Rt,`wait ${this._config.refreshEvery}ms before collecting`),await kf(this._config.refreshEvery),a()){Pe(Rt,"collecting...");const s=Date.now(),r=await o(),d=Date.now();r.delta_time_consumed_to_measure_ms=d-s,this.fireOnReports(r),Pe(Rt,"collected")}Pe(Rt,"reaching end of the collecting period..."),this.isRunning&&setTimeout(()=>{this.stop()},0)}stop(t){const n=a=>{this._probes.forEach(o=>{o.stop(a)})};Rn(Rt,"stop collecting"),n(t)}registerCallback(t,n,a){t in this._callbacks?(this._callbacks[t]={callback:n,context:a},Pe(Rt,`registered callback '${t}'`)):dr(Rt,`can't register callback for '${t}' - not found`)}unregisterCallback(t){t in this._callbacks?(this._callbacks[t]=null,delete this._callbacks[t],Pe(this._moduleName,`unregistered callback '${t}'`)):dr(this._moduleName,`can't unregister callback for '${t}' - not found`)}fireOnReports(t){this._callbacks.onresult&&t.probes.length>0&&wu(this._callbacks.onresult.callback,this._callbacks.onresult.context,t)}}const rE="interface ";class iE{constructor(t){this._config=Ov(t),Rn(rE,`welcome to ${this._config.name} version ${this._config.version}`),gv(this._config.verbose||!1),this._engine=new nE(this._config)}setupLogLevel(t){Tv(t)}get version(){return this._config.version}get name(){return this._config.name}get probes(){return this._engine.probes}createProbe(t,n){return this._engine.addNewProbe(t,n)}startAllProbes(){this._engine.start()}stopAllProbes(){this._engine.stop()}get running(){return this._engine.isRunning}get idle(){return this._engine.isIdle}removeProbe(t){this._engine.removeExistingProbe(t)}set onresult(t){t?this._engine.registerCallback("onresult",t):this._engine.unregisterCallback("onresult")}}function lE(c,t){return Object.keys(c).filter(n=>t.includes(n)).reduce((n,a)=>{const o=a;return{...n,[o]:c[o]}},{})}const aE=["mos_in","codec_in","delta_KBytes_in","delta_kbs_in","delta_jitter_ms_in","delta_packets_lost_in"];class oE{constructor(t){this.intervals={},this.emitInterval=t.emitInterval||200,this.onChangeFunction=t.onChangeFunction}start(t,n){t&&t.getTracks().length&&requestAnimationFrame(()=>this.beginCalculation(t,n))}stop(t){this.clearVolumeInterval(t)}clearVolumeInterval(t){clearInterval(this.intervals[t]),delete this.intervals[t]}clearAllIntervals(){Object.keys(this.intervals).forEach(t=>{clearInterval(this.intervals[t])}),this.intervals={}}beginCalculation(t,n){this.clearVolumeInterval(n);const a=An.createAnalyser(),o=An.createMediaStreamSource(t),s=An.createScriptProcessor(2048,1,1);a.smoothingTimeConstant=.8,a.fftSize=1024,o.connect(a),a.connect(s),s.connect(An.destination),this.intervals[n]=setInterval(()=>{const r=new Uint8Array(a.frequencyBinCount);a.getByteFrequencyData(r);let d=0;const h=r.length;for(let g=0;g<h;g++)d+=r[g];const _=d/h;this.onChangeFunction(n,_)},this.emitInterval)}}const _a={SELECTED_INPUT_DEVICE:"OpensipsJSInputDevice",SELECTED_OUTPUT_DEVICE:"OpensipsJSOutputDevice"},uE=0;class cE{constructor(t){this.isAutoAnswer=!1,this.muteWhenJoinEnabled=!1,this.isDNDEnabled=!1,this.isCallWaitingEnabled=!0,this.muted=!1,this.microphoneInputLevelValue=1,this.speakerVolumeValue=1,this.activeRooms={},this.activeCalls={},this.extendedCalls={},this.availableMediaDevices=[],this.selectedMediaDevices={input:"default",output:"default"},this.callStatus={},this.callTime={},this.callMetrics={},this.timeIntervals={},this.metricConfig={refreshEvery:1e3},this.activeStreamValue=null,this.initialStreamValue=null,this.context=t,this.context.on(this.context.newRTCSessionEventName,this.newRTCSessionCallback.bind(this)),this.VUMeter=new oE({onChangeFunction:this.emitVolumeChange.bind(this)}),this.initializeMediaDevices()}get sipOptions(){return{...this.context.options.sipOptions,mediaConstraints:this.getUserMediaConstraints}}get currentActiveRoomId(){return this.currentActiveRoomIdValue}set currentActiveRoomId(t){this.currentActiveRoomIdValue=t,this.context.emit("currentActiveRoomChanged",t)}get autoAnswer(){return this.isAutoAnswer}get callAddingInProgress(){return this.isCallAddingInProgress}set callAddingInProgress(t){this.isCallAddingInProgress=t,this.context.emit("callAddingInProgressChanged",t)}get muteWhenJoin(){return this.muteWhenJoinEnabled}get isDND(){return this.isDNDEnabled}get isCallWaiting(){return this.isCallWaitingEnabled}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 hasActiveAnsweredCalls(){return Object.values(this.activeRooms).filter(a=>!a.incomingInProgress).length>0}get getActiveRooms(){return this.activeRooms}get isMuted(){return this.muted}get getInputDeviceList(){return this.availableMediaDevices.filter(t=>t.kind==="audioinput")}get getOutputDeviceList(){return this.availableMediaDevices.filter(t=>t.kind==="audiooutput")}get getUserMediaConstraints(){return wh()?{video:!1,audio:!0}:{audio:{deviceId:{exact:this.selectedMediaDevices.input}},video:!1}}get selectedInputDevice(){return this.selectedMediaDevices.input}get selectedOutputDevice(){return this.selectedMediaDevices.output}get activeStream(){return this.activeStreamValue}setAvailableMediaDevices(t){this.availableMediaDevices=t,this.context.emit("changeAvailableDeviceList",t)}async updateDeviceList(){await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);const t=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(t)}async initializeMediaDevices(){const t=localStorage.getItem(_a.SELECTED_INPUT_DEVICE)||"default",n=localStorage.getItem(_a.SELECTED_OUTPUT_DEVICE)||"default";try{const a=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints),o=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(o),await this.setMicrophone(t),await this.setSpeaker(n),navigator.mediaDevices.addEventListener("devicechange",async()=>{const s=await navigator.mediaDevices.enumerateDevices();this.setAvailableMediaDevices(s)}),a.getTracks().forEach(s=>s.stop())}catch(a){console.error(a)}}setCallTime(t){const n={...t};delete n.callId,this.callTime={...this.callTime,[t.callId]:n},this.context.emit("changeCallTime",this.callTime)}removeCallTime(t){const n={...this.callTime};delete n[t],this.callTime={...n},this.context.emit("changeCallTime",this.callTime)}setTimeInterval(t,n){this.timeIntervals={...this.timeIntervals,[t]:n}}removeTimeInterval(t){const n={...this.timeIntervals};n[t]&&(clearInterval(n[t]),delete n[t],this.timeIntervals={...n})}stopCallTimer(t){this.removeTimeInterval(t),this.removeCallTime(t)}emitVolumeChange(t,n){this.context.emit("changeCallVolume",{callId:t,volume:n})}setMetricsConfig(t){this.metricConfig={...this.metricConfig,...t}}sendDTMF(t,n){if(!/^[A-D0-9]+$/g.test(n))throw new Error("Not allowed character in DTMF input");this.extendedCalls[t].sendDTMF(n)}setIsMuted(t){this.muted=t,this.context.emit("changeIsMuted",t)}processMute(t){const n=this.currentActiveRoomId;this.setIsMuted(t),this.initialStreamValue.getTracks().forEach(a=>a.enabled=!t),this.roomReconfigure(n)}mute(){this.processMute(!0)}unmute(){this.processMute(!1)}async processHold({callId:t,toHold:n,automatic:a}){const o=this.extendedCalls[t];o._automaticHold=a??!1,await new Promise(d=>{const h=()=>{o.putOnHoldTimestamp=n?Date.now():void 0,d()};n?o.hold({},h):o.unhold({},h)}),this.updateCall(o);const r=Object.values(this.extendedCalls).filter(d=>d.roomId===this.currentActiveRoomId&&(n?t!==d._id:!0));r.length>1&&await this.doConference(r)}holdCall(t,n=!1){return this.processHold({callId:t,automatic:n,toHold:!0})}unholdCall(t){return this.processHold({callId:t,toHold:!1})}cancelAllOutgoingUnanswered(){Object.values(this.getActiveCalls).filter(t=>t.direction==="outgoing"&&t.status===uE).forEach(t=>this.terminateCall(t._id))}answerCall(t){const n=this.extendedCalls[t];this.cancelAllOutgoingUnanswered(),n.answer(this.sipOptions),this.updateCall(n),this.setActiveRoom(n.roomId),n.connection.addEventListener("track",a=>{this.triggerAddStream(a,n)})}async moveCall(t,n){this.updateCallStatus({callId:t,isMoving:!0}),await this.processRoomChange({callId:t,roomId:n}),this.updateCallStatus({callId:t,isMoving:!1})}updateCall(t){this.activeCalls[t._id]=Nf(t),this.context.emit("changeActiveCalls",this.activeCalls)}updateRoom(t){const a={...this.activeRooms[t.roomId],...t};this.activeRooms={...this.activeRooms,[t.roomId]:{...a}},this.context.emit("updateRoom",{room:a,roomList:this.activeRooms})}hasAutoAnswerHeaders(t){const n=/answer-after=0/,o=t.request.getHeader("Call-Info");return o&&n.test(o)}addCall(t,n=!0){this.activeCalls={...this.activeCalls,[t._id]:Nf(t)},this.extendedCalls[t._id]=t,n&&this.context.emit("changeActiveCalls",this.activeCalls)}addCallStatus(t){this.callStatus={...this.callStatus,[t]:{isMoving:!1,isTransferring:!1,isMerging:!1,isTransferred:!1}},this.context.emit("changeCallStatus",this.callStatus)}updateCallStatus(t){const a={...{...this.callStatus[t.callId]}};t.isMoving!==void 0&&(a.isMoving=t.isMoving),t.isTransferring!==void 0&&(a.isTransferring=t.isTransferring),t.isMerging!==void 0&&(a.isMerging=t.isMerging),t.isTransferred!==void 0&&(a.isTransferred=t.isTransferred),this.callStatus={...this.callStatus,[t.callId]:{...a}},this.context.emit("changeCallStatus",this.callStatus)}removeCallStatus(t){const n={...this.callStatus};delete n[t],this.callStatus={...n},this.context.emit("changeCallStatus",this.callStatus)}addRoom(t){this.activeRooms={...this.activeRooms,[t.roomId]:t},this.context.emit("addRoom",{room:t,roomList:this.activeRooms})}getActiveStream(){const t=Pf(this.initialStreamValue,this.microphoneInputLevel*2);return t.getTracks().forEach(n=>n.enabled=!this.isMuted),this.setActiveStream(t),t}async setMicrophone(t){if(!this.getInputDeviceList.find(({deviceId:a})=>a===t)||(this.setSelectedInputDevice(t),Object.keys(this.getActiveCalls).length===0))return;await this.setupStream();const n=Object.values(this.extendedCalls).filter(a=>a.roomId===this.currentActiveRoomId);n.length===1?Object.values(n).forEach(async a=>{const o=this.getActiveStream();a.connection.getSenders()[0].replaceTrack(o.getTracks()[0]),this.updateCall(a)}):await this.doConference(n)}setActiveStream(t){this.activeStream&&this.stopVUMeter("origin"),this.setupVUMeter(t,"origin"),this.activeStreamValue=t,this.context.emit("changeActiveStream",t)}async setSpeaker(t){if(!this.getOutputDeviceList.find(({deviceId:o})=>o===t))return;this.setSelectedOutputDevice(t);const n=Object.values(this.extendedCalls);if(n.length===0)return;const a=n.filter(o=>o.roomId===this.currentActiveRoomId);a.length===1?n.forEach(o=>{var s;(s=o.audioTag)==null||s.setSinkId(t),this.updateCall(o)}):await this.doConference(a)}removeRoom(t){const n={...this.activeRooms},a={...n[t]};delete n[t],this.activeRooms={...n},this.context.emit("removeRoom",{room:a,roomList:this.activeRooms})}deleteRoomIfEmpty(t){t!==void 0&&Object.values(this.extendedCalls).filter(n=>n.roomId===t).length===0&&(this.removeRoom(t),this.currentActiveRoomId===t&&(this.currentActiveRoomId=void 0))}checkInitialized(){if(!this.context.initialized)throw new Error("[OpenSIPSJS] You must call `start` method first!")}muteReconfigure(t){this.muted?t.mute({audio:!0}):t.unmute({audio:!0})}async roomReconfigure(t){var a;if(t===void 0)return;const n=Object.values(this.extendedCalls).filter(o=>o.roomId===t);if(this.currentActiveRoomId===t?n.forEach(o=>{o.audioTag&&(this.muteReconfigure(o),o.audioTag.muted=!1,this.updateCall(o))}):n.forEach(o=>{o.audioTag&&(o.audioTag.muted=!0,this.updateCall(o))}),n.length===0)this.deleteRoomIfEmpty(t);else if(n.length===1&&this.currentActiveRoomId!==t)n[0].isOnHold().local||await this.holdCall(n[0].id,!0);else if(n.length===1&&this.currentActiveRoomId===t){if(n[0].isOnHold().local&&n[0]._automaticHold&&await this.unholdCall(n[0].id),n[0].connection&&((a=n[0].connection)!=null&&a.getSenders()[0])){const o=this.getActiveStream();await n[0].connection.getSenders()[0].replaceTrack(o.getTracks()[0]),this.muteReconfigure(n[0])}}else n.length>1&&await this.doConference(n)}async doConference(t){const n=[];t.forEach(a=>{a!=null&&a.connection.getReceivers().forEach(o=>{n.push(o.track)})}),await pv.forEach(t,async a=>{var r;if(a==null)return;const o=new MediaStream,s=An.createMediaStreamDestination();if(a.connection.getReceivers().forEach(d=>{n.forEach(h=>{o.addTrack(d.track),d.track.id!==h.id&&An.createMediaStreamSource(new MediaStream([h])).connect(s)})}),t[0].roomId===this.currentActiveRoomId){const d=this.getActiveStream();An.createMediaStreamSource(d).connect(s)}(r=a.connection)!=null&&r.getSenders()[0]&&(await a.connection.getSenders()[0].replaceTrack(s.stream.getTracks()[0]),this.muteReconfigure(a))})}processCallerMute(t,n){const a=this.extendedCalls[t];a&&a.connection.getReceivers().length&&(a.localMuted=n,a.connection.getReceivers().forEach(o=>{o.track.enabled=!n}),this.updateCall(a))}muteCaller(t){this.processCallerMute(t,!0)}unmuteCaller(t){this.processCallerMute(t,!1)}terminateCall(t){const n=this.extendedCalls[t];n._status===4?n.terminate({status_code:603,reason_phrase:"Decline"}):n._status!==8&&n.terminate()}transferCall(t,n){if(n.toString().length===0)return new Error("Target must be passed");const a=this.extendedCalls[t];if(!a._is_confirmed&&!a._is_canceled){const o=`sip:${n}@${this.context.sipDomain}`;a.terminate({status_code:302,reason_phrase:"Moved Temporarily",extraHeaders:[`Contact: ${o}`]});return}this.updateCallStatus({callId:t,isTransferring:!0,isTransferred:!1}),a.refer(`sip:${n}@${this.context.sipDomain}`,{eventHandlers:{requestSucceeded:()=>{this.updateCallStatus({callId:t,isTransferring:!1,isTransferred:!0})},requestFailed:()=>{this.updateCallStatus({callId:t,isTransferring:!1,isTransferred:!1})}}}),this.updateCall(a)}mergeCall(t){const n=Object.values(this.extendedCalls).filter(s=>s.roomId===t);if(n.length!==2)return;const a=n[0],o=n[1];!a||!o||(this.updateCallStatus({callId:a._id,isMerging:!0}),this.updateCallStatus({callId:o._id,isMerging:!0}),a.refer(o.remote_identity.uri.toString(),{replaces:o}),this.updateCall(a))}mergeCallByIds(t,n){const a=Object.values(this.extendedCalls).find(s=>s._id===t),o=Object.values(this.extendedCalls).find(s=>s._id===n);if(!a||!o)throw new Error("Call ID is not provided");this.updateCallStatus({callId:t,isMerging:!0}),this.updateCallStatus({callId:n,isMerging:!0}),a.refer(o.remote_identity.uri.toString(),{replaces:o}),this.updateCall(a)}setDND(t){this.isDNDEnabled=t,this.context.emit("changeIsDND",t)}setCallWaiting(t){this.isCallWaitingEnabled=t,this.context.emit("changeIsCallWaiting",t)}startCallTimer(t){this.removeTimeInterval(t);const n={callId:t,hours:0,minutes:0,seconds:0,formatted:""};this.setCallTime(n);const a=setInterval(()=>{const o={...this.callTime[t]},s=hv(o);this.setCallTime({callId:t,...s})},1e3);this.setTimeInterval(t,a)}async setActiveRoom(t){const n=this.currentActiveRoomId;t!==n&&(this.currentActiveRoomId=t,await this.roomReconfigure(n),await this.roomReconfigure(t))}getNewRoomId(){const t=Object.keys(this.activeRooms);return t.length===0?1:parseInt(t.sort()[t.length-1])+1}async setupCall(t){var _,g;const n=t.session;if(this.getActiveCalls[n.id]!==void 0)return;const o=this.getNewRoomId(),s={started:new Date,incomingInProgress:!1,roomId:o};n.direction==="incoming"?(this.context.logger.log("New incoming call from",(g=(_=n._remote_identity)==null?void 0:_._uri)==null?void 0:g._user),s.incomingInProgress=!0,this.context.subscribe(Xt.CALL_CONFIRMED,T=>{n.id===T.id&&(this.updateRoom({incomingInProgress:!1,roomId:o}),this.startCallTimer(n.id))}),this.context.subscribe(Xt.CALL_FAILED,T=>{n.id===T.id&&(this.updateRoom({incomingInProgress:!1,roomId:o}),this.deleteRoomIfEmpty(o))})):n.direction==="outgoing"&&(n.once("confirmed",()=>{this.startCallTimer(n.id)}),this.startCallTimer(n.id));const r=n,d=this.hasAutoAnswerHeaders(t),h=r.direction==="incoming"&&!this.hasActiveCalls&&(d||this.autoAnswer);r.roomId=o,r.localMuted=!1,r.autoAnswer=h,h?this.addCall(r,!1):this.addCall(r),this.addCallStatus(n.id),this.addRoom(s),h&&this.answerCall(r._id)}removeCall(t){const n={...this.activeCalls};delete n[t],this.activeCalls={...n};const a={...this.extendedCalls};delete a[t],this.extendedCalls={...a},this.context.emit("changeActiveCalls",this.activeCalls)}activeCallListRemove(t){var o;const n=this.extendedCalls[t._id];this.stopVUMeter("origin"),(o=n.connection)==null||o.getSenders().forEach(s=>{s.track.stop()});const a=n.roomId;this.removeCall(t._id),this.roomReconfigure(a)}shouldTerminateNewSession(t){if(t.session.direction==="outgoing")return!1;const a=!this.isCallWaiting&&this.hasActiveCalls;return this.isDND||a}async newRTCSessionCallback(t){const n=t.session;if(this.shouldTerminateNewSession(t)){n.terminate({status_code:486,reason_phrase:"Do Not Disturb"});return}if(this.context.triggerListener({listenerType:Xt.NEW_CALL,session:n,event:t}),n.on("ended",a=>{var s,r,d;this.stopVUMeter(n.id),this.context.logger.log("Session ended for",(r=(s=n._remote_identity)==null?void 0:s._uri)==null?void 0:r._user),this.context.triggerListener({listenerType:Xt.CALL_ENDED,session:n,event:a});const o=this.getActiveCalls[n.id];o&&this.activeCallListRemove(o),this.stopCallTimer(n.id),this.removeCallStatus(n.id),this.removeCallMetrics(n.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(d=this.initialStreamValue)==null||d.getTracks().forEach(h=>h.stop()),this.initialStreamValue=null),this.context.isWaitingForSessionHangup()&&!this.hasActiveAnsweredCalls&&this.context.stopSessionAfterWaiting()}),n.on("progress",a=>{var o,s;this.context.logger.log("Session in progress for",(s=(o=n._remote_identity)==null?void 0:o._uri)==null?void 0:s._user),this.context.triggerListener({listenerType:Xt.CALL_PROGRESS,session:n,event:a})}),n.on("failed",a=>{var s,r,d;this.stopVUMeter(n.id),this.context.logger.log("Session failed for",(r=(s=n._remote_identity)==null?void 0:s._uri)==null?void 0:r._user),this.context.triggerListener({listenerType:Xt.CALL_FAILED,session:n,event:a}),n.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0);const o=this.getActiveCalls[n.id];o&&this.activeCallListRemove(o),this.stopCallTimer(n.id),this.removeCallStatus(n.id),this.removeCallMetrics(n.id),Object.keys(this.extendedCalls).length||(this.setIsMuted(!1),(d=this.initialStreamValue)==null||d.getTracks().forEach(h=>h.stop()),this.initialStreamValue=null),this.context.isWaitingForSessionHangup()&&!this.hasActiveAnsweredCalls&&this.context.stopSessionAfterWaiting()}),n.on("confirmed",a=>{var o,s;this.context.logger.log("Session confirmed for",(s=(o=n._remote_identity)==null?void 0:o._uri)==null?void 0:s._user),this.context.triggerListener({listenerType:Xt.CALL_CONFIRMED,session:n,event:a}),this.updateCall(n),n.id===this.callAddingInProgress&&(this.callAddingInProgress=void 0)}),await this.setupCall(t),n.direction==="outgoing"){const a=this.getActiveCalls[n.id].roomId;this.setActiveRoom(a)}}setMuteWhenJoin(t){this.muteWhenJoinEnabled=t,this.context.emit("changeMuteWhenJoin",t)}setMicrophoneSensitivity(t){if(t<0||t>1)throw new Error("Value should be in range from 0 to 1!");this.microphoneInputLevelValue=t,this.roomReconfigure(this.currentActiveRoomId)}setSpeakerVolume(t){this.speakerVolumeValue=t,Object.values(this.extendedCalls).forEach(n=>{n.audioTag&&(n.audioTag.volume=t,this.updateCall(n))})}setAutoAnswer(t){this.isAutoAnswer=t}setSelectedInputDevice(t){localStorage.setItem(_a.SELECTED_INPUT_DEVICE,t),this.selectedMediaDevices.input=t,this.context.emit("changeActiveInputMediaDevice",t)}setSelectedOutputDevice(t){localStorage.setItem(_a.SELECTED_OUTPUT_DEVICE,t),this.selectedMediaDevices.output=t,this.context.emit("changeActiveOutputMediaDevice",t)}setCallMetrics(t){const n={...t};delete n.callId,this.callMetrics={...this.callMetrics,[t.callId]:n},this.context.emit("changeCallMetrics",this.callMetrics)}removeCallMetrics(t){const n={...this.callMetrics};delete n[t],this.callMetrics={...n},this.context.emit("changeCallMetrics",this.callMetrics)}getCallQuality(t){const n=new iE(this.metricConfig),a=n.createProbe(t.connection,{cid:t._id}),o=[];let s;a.onreport=r=>{Object.entries(r.audio).forEach(([_,g])=>{g.direction==="inbound"&&!o.includes(_)&&(o.push(_),s=_)});const d=r.audio[s];if(!d)return;const h=lE(d,aE);h.callId=t._id,this.setCallMetrics(h)},this.context.subscribe(Xt.CALL_ENDED,r=>{r._id===t._id&&n.stopAllProbes()}),n.startAllProbes()}setupVUMeter(t,n){this.VUMeter.start(t,n)}stopVUMeter(t){this.VUMeter.stop(t)}async setupStream(){const t=await navigator.mediaDevices.getUserMedia(this.getUserMediaConstraints);this.initialStreamValue&&(this.initialStreamValue.getTracks().forEach(n=>n.stop()),this.initialStreamValue=null),this.initialStreamValue=t}async triggerAddStream(t,n){this.setIsMuted(this.muteWhenJoin||this.isMuted),this.initialStreamValue||await this.setupStream();const a=Pf(this.initialStreamValue,this.microphoneInputLevel*2),o=this.isMuted||this.muteWhenJoin;a.getTracks().forEach(r=>r.enabled=!o),this.setActiveStream(a),await n.connection.getSenders()[0].replaceTrack(a.getTracks()[0]);const s=new MediaStream([t.track]);zT(s,n,this.selectedOutputDevice,this.speakerVolume),this.setupVUMeter(s,n._id),this.getCallQuality(n),this.updateCall(n)}initCall(t,n,a=!1){if(t.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${t}@${this.context.sipDomain}...`);const o=this.context.call(`sip:${t}@${this.context.sipDomain}`,this.sipOptions);if(this.callAddingInProgress=o.id,n&&this.currentActiveRoomId!==void 0&&(this.processRoomChange({callId:o.id,roomId:this.currentActiveRoomId}),a)){const s=Object.values(this.extendedCalls).filter(r=>r.roomId===this.currentActiveRoomId&&r._id!==o.id);for(const r of s)this.holdCall(r._id,!0)}o.connection.addEventListener("track",s=>{this.triggerAddStream(s,o)})}async processRoomChange({callId:t,roomId:n}){const a=this.extendedCalls[t].roomId;this.extendedCalls[t].roomId=n;const o=this.extendedCalls[t];return this.updateCall(o),await this.setActiveRoom(n),Promise.all([this.roomReconfigure(a),this.roomReconfigure(n)]).then(()=>{this.deleteRoomIfEmpty(a),this.deleteRoomIfEmpty(n)})}}class fE{constructor(t){this.context=t}get sipOptions(){return{...this.context.options.sipOptions}}initCall(t,n){if(t.length===0)return console.error("Target must be a valid string");this.context.logger.log(`Calling sip:${t}@${this.context.sipDomain}...`),this.context.joinVideoCall(`sip:${t}@${this.context.sipDomain}`,n,this.sipOptions)}stop(t={}){this.context.terminateJanusSessions(t)}startAudio(){this.context.enableJanusAudio(!0)}stopAudio(){this.context.enableJanusAudio(!1)}startVideo(){this.context.enableJanusVideo(!0)}stopVideo(){this.context.enableJanusVideo(!1)}changeMediaConstraints(t){this.context.changeMediaConstraints(t)}startScreenShare(){this.context.startScreenShare()}startBlur(){this.context.startBlur()}stopBlur(){this.context.stopBlur()}}class hE{constructor(t){this.activeMessages={},this.extendedMessages={},this.msrpHistory={},this.context=t,this.context.on(this.context.newMSRPSessionEventName,this.newMSRPSessionCallback.bind(this.context))}get isMSRPInitializing(){return this.isMSRPInitializingValue}get getActiveMessages(){return this.activeMessages}msrpAnswer(t){const n=this.extendedMessages[t];this.updateMSRPSession(n)}updateMSRPSession(t){this.activeMessages[t._id]=Uf(t),this.context.emit("changeActiveMessages",this.activeMessages)}addMMSRPSession(t){this.activeMessages={...this.activeMessages,[t._id]:Uf(t)},this.extendedMessages[t._id]=t,this.context.emit("changeActiveMessages",this.activeMessages)}addMSRPMessage(t,n){const a=this.msrpHistory[n.id]||[];a.push(t),this.msrpHistory={...this.msrpHistory,[n.id]:[...a]},this.context.emit("newMSRPMessage",{message:t,session:n})}messageTerminate(t){const n=this.extendedMessages[t];n._status!==8&&n.terminate()}addMessageSession(t){if(!t._id||this.getActiveMessages[t._id]!==void 0)return;const a=t;this.addMMSRPSession(a)}triggerMSRPListener({listenerType:t,session:n,event:a}){const o=this.context.listenersList[t];!o||!o.length||o.forEach(s=>{s(n,a)})}removeMMSRPSession(t){const n={...this.activeMessages};delete n[t],this.activeMessages={...n};const a={...this.extendedMessages};delete a[t],this.extendedMessages={...a},this.context.emit("changeActiveMessages",this.activeMessages)}activeMessageListRemove(t){this.removeMMSRPSession(t._id)}newMSRPSessionCallback(t){const n=t.session;n.on("ended",a=>{this.triggerMSRPListener({listenerType:Xt.CALL_ENDED,session:n,event:a});const o=this.getActiveMessages[n.id];this.activeMessageListRemove(o)}),n.on("failed",a=>{this.triggerMSRPListener({listenerType:Xt.CALL_FAILED,session:n,event:a});const o=this.getActiveMessages[n.id];this.activeMessageListRemove(o)}),n.on("confirmed",a=>{this.triggerMSRPListener({listenerType:Xt.CALL_CONFIRMED,session:n,event:a}),this.updateMSRPSession(n)}),n.on("newMessage",a=>{this.addMSRPMessage(a,n)}),this.addMessageSession(n)}setIsMSRPInitializing(t){this.isMSRPInitializingValue=t,this.context.emit("isMSRPInitializingChanged",t)}initMSRP(t,n,a){if(t.length===0)return console.error("Target must be a valid string");const o=this.context.startMSRP(t,a);o.on("active",()=>{this.addMessageSession(o),o.sendMSRP(n),this.setIsMSRPInitializing(!1)}),this.setIsMSRPInitializing(!0)}sendMSRP(t,n){const a=this.extendedMessages[t];if(!a)throw new Error(`MSRP session with id ${t} doesn't exist!`);a.sendMSRP(n)}}const pa={AUDIO:"audio",VIDEO:"video",MSRP:"msrp"};class kh{constructor(t){this.opensips=null,this.session=null,this.name=null,this.name=t}setOpensips(t){this.opensips=t}setSession(t){this.session=t}kill(){this.opensips.kill(this.name)}}class Mh extends kh{constructor(t,n){super(t),this._candidates=[],this._subscribeSent=!1,this._configureSent=!1,this._lastTrickleReceived=!1,this.type=n}connect(t={}){this.opaqueId=this.session.generateOpaqueId();const n=ke.cloneArray(t.extraHeaders),a={from_tag:this.session._from_tag};t.fromUserName&&(a.from_uri=new In("sip",t.fromUserName,this.session._ua.configuration.uri.host),n.push(`P-Preferred-Identity: ${this.session._ua.configuration.uri.toString()}`)),t.fromDisplayName&&(a.from_display_name=t.fromDisplayName),n.push(`Contact: ${this.session._contact}`),n.push("Content-Type: application/json"),this.session._sessionTimers.enabled&&n.push(`Session-Expires: ${this.session._sessionTimers.defaultExpires}${this.session._ua.configuration.session_timers_force_refresher?";refresher=uac":""}`),this._request=new yt.InitialOutgoingInviteRequest(this.session.target,this.session._ua,a,n),this._createRTCConnection(),this._sendInitialRequest()}getStream(){return this.stream}getConnection(){return this._connection}_createRTCConnection(){this._connection=new RTCPeerConnection({iceServers:[{urls:"stun:turn.voicenter.co",credential:"kxsjahnsdjns3eds23esd",username:"turn2es21e"}]});let t;this._connection.onicecandidate=n=>{this._connection.signalingState!=="stable"&&this._connection.signalingState!=="have-local-offer"||n.candidate&&(this._candidates.push(n.candidate),clearTimeout(t),t=setTimeout(()=>{this._lastTrickleReceived=!0,this._subscribeSent&&!this._configureSent&&this._sendConfigureMessage({audio:!0,video:!0})},500))}}addTracks(t){t.forEach(n=>{this._connection.addTrack(n)})}async _sendInitialRequest(){const t=new sl(this.session._ua,this._request,{onRequestTimeout:()=>{this.session.onRequestTimeout()},onTransportError:()=>{this.session.onTransportError()},onAuthenticated:s=>{this._request=s},onReceiveResponse:s=>{this._receiveInviteResponse(s)}});if(await this.generateStream(),!this.stream||!this.stream.getTracks().length)return;this.addTracks(this.stream.getTracks());const n={audio:!1,video:!0};this.jsep_offer=await this._connection.createOffer(n),await this._connection.setLocalDescription(this.jsep_offer);const a={janus:"attach",plugin:"janus.plugin.videoroom",opaque_id:this.opaqueId},o=JSON.stringify(a);this._request.body=o,t.send()}_receiveInviteResponse(t){if(this._publisherSubscribeSent||!t.body)return;const n=JSON.parse(t.body);this.handleId=n.data.id;const a={janus:"message",body:{request:"join",room:this.session.room_id,ptype:"publisher",display:this.session.display_name+" (Screen Share)",opaque_id:this.opaqueId},handle_id:this.handleId},o=[this.session.getPTypeHeader(Pt.PUBLISHER)];this.session.sendRequest(L.SUBSCRIBE,{extraHeaders:o,body:JSON.stringify(a),eventHandlers:{onSuccessResponse:async s=>{var r,d,h,_;if(s.status_code===200){if(this._subscribeSent=!0,s.body)try{const g=JSON.parse(s.body)||{};((d=(r=g.plugindata)==null?void 0:r.data)==null?void 0:d.videoroom)==="joined"&&this.session.myFeedList.push(g.plugindata.data.id),(_=(h=g.plugindata)==null?void 0:h.data)!=null&&_.publishers&&this.session.receivePublishers(g)}catch(g){console.error(g)}this._lastTrickleReceived&&!this._configureSent&&this._sendConfigureMessage({audio:!0,video:!0})}}}}),this._publisherSubscribeSent=!0}async _sendConfigureMessage(t){const n=this._candidates.map(r=>({janus:"trickle",candidate:r,handle_id:this.handleId,session_id:this.session.session_id})),o={configure:{janus:"message",body:{request:"configure",record:!0,filename:this.session.getRecordFileName(),...t},jsep:this.jsep_offer,handle_id:this.handleId,session_id:this.session.session_id},trickles:[...n]},s=["Content-Type: application/json",this.session.getPTypeHeader(Pt.ICE)];this.session.sendRequest(L.INFO,{extraHeaders:s,body:JSON.stringify(o),eventHandlers:{onSuccessResponse:async r=>{this._configureSent=!0;const h=r.data.split(`\r
|
159
159
|
`),_=h[h.length-1],g=JSON.parse(_);await this._connection.setRemoteDescription(g.jsep),this._candidates=[]}}})}_sendDetach(){const t={janus:"detach",handle_id:this.handleId,session_id:this.session.session_id},n=[this.session.getPTypeHeader(Pt.DETACH)];this.session.sendRequest(L.INFO,{extraHeaders:n,body:JSON.stringify(t)}),this.session._ua.emit("pluginDetach",this.name)}async stopMedia(){this._connection&&(this._connection.close(),this._connection=null),this.stream&&(this.stream=null)}async stop(){await this.session.stopProcessPlugins(this.type);const t=this._connection.getSenders();t.forEach(n=>{const a=n.track;a&&a.stop()}),t.forEach(n=>{this._connection.removeTrack(n)}),await this.stopMedia(),this._sendDetach()}async generateStream(){throw new Error("generateStream method is not implemented")}}class Lh extends kh{constructor(t,n,a={}){super(t),this.stream=null,this.running=!1,this.immediate=!1,this.type="video",this.immediate=a.immediate||!1,this.type=n}start(t){return t}stop(){throw new Error("stop method is not implemented")}async process(t){if(this.immediate){const n=await this.start(t);return this.running=!0,n}return t}async connect(){this.running=!0,await this.session.resyncPlugins(this.type)}terminate(){this.stop()}async kill(){this.stop(),this.running=!1,await this.session.resyncPlugins(this.type)}}class dE extends VT{constructor(t,n){if(!t.modules.length)throw new Error("options.modules should include at least 1 module");const a={...t.configuration,sockets:t.socketInterfaces.map(o=>new fv.WebSocketInterface(o))};super(a),this.initialized=!1,this.connected=!1,this.logger=console,this.newRTCSessionEventName="newRTCSession",this.registeredEventName="registered",this.unregisteredEventName="unregistered",this.disconnectedEventName="disconnected",this.connectedEventName="connected",this.newMSRPSessionEventName="newMSRPSession",this.isReconnecting=!1,this.activeConnection=!1,this.waitingForSessionHangup=!1,this.waitingForSessionTimeout=null,this.audio=null,this.msrp=null,this.video=null,this.listenersList={},this.modules=[],t.pnExtraHeaders&&Object.keys(t.pnExtraHeaders).length&&this.registrator().setExtraContactUriParams(t.pnExtraHeaders),this.options=t,this.modules=t.modules,n&&XT(n)&&(this.logger=n)}isWaitingForSessionHangup(){return this.waitingForSessionHangup}stopSessionAfterWaiting(){this.setInitialized(!1),this.waitingForSessionHangup=!1,clearTimeout(this.waitingForSessionTimeout),this.waitingForSessionTimeout=null,this.activeConnection&&setTimeout(this.start.bind(this),5e3)}get hasActiveSessions(){return this.modules.includes(pa.AUDIO)?this.audio.hasActiveAnsweredCalls:!1}on(t,n){return super.on(t,n)}off(t,n){return super.off(t,n)}emit(t,n){return super.emit(t,n)}get sipDomain(){return this.options.sipDomain}use(t){if(this.newStreamPlugins.find(n=>n.name===t.name)||this.processStreamPlugins.find(n=>n.name===t.name))throw new Error(`Plugin with name ${t.name} already exists`);if(t instanceof Mh)t.setOpensips(this),this.newStreamPlugins.push(t);else if(t instanceof Lh)t.setOpensips(this),this.processStreamPlugins.push(t);else throw new Error("Wrong plugin instance")}getPlugin(t){return this.newStreamPlugins.find(n=>n.name===t)||this.processStreamPlugins.find(n=>n.name===t)}begin(){if(this.isConnected()){console.error("Connection is already established");return}return this.modules.includes(pa.AUDIO)&&(this.audio=new cE(this)),this.modules.includes(pa.MSRP)&&(this.msrp=new hE(this)),this.modules.includes(pa.VIDEO)&&(this.video=new fE(this)),this.on(this.registeredEventName,()=>{this.logger.log("Successfully registered to",this.options.socketInterfaces[0]),this.setInitialized(!0)}),this.on(this.unregisteredEventName,()=>{this.logger.log("Unregistered from",this.options.socketInterfaces[0]),this.setInitialized(!1)}),this.on(this.connectedEventName,()=>{this.logger.log("Connected to",this.options.socketInterfaces[0]),this.setConnected(!0),this.setReconnecting(!1),this.activeConnection=!0,this.waitingForSessionHangup=!1}),this.on(this.disconnectedEventName,()=>{this.setConnected(!1),!this.isReconnecting&&(this.setReconnecting(!0),this.logger.log("Disconnected from",this.options.socketInterfaces[0]),this.logger.log("Reconnecting to",this.options.socketInterfaces[0]),this.hasActiveSessions?(this.waitingForSessionHangup=!0,this.stop(!1),this.waitingForSessionTimeout=setTimeout(()=>{this.terminateAllSessions(),this.setInitialized(!1),this.waitingForSessionHangup=!1,this.activeConnection&&setTimeout(this.start.bind(this),5e3)},12e5)):(this.stop(),this.setInitialized(!1),this.activeConnection&&setTimeout(this.start.bind(this),5e3)))}),this.logger.log("Connecting to",this.options.socketInterfaces[0]),this.start(),this}disconnect(){this.activeConnection=!1,this.stop()}subscribe(t,n){const o=!this.listenersList[t]||!this.listenersList[t].length?[n]:[...this.listenersList[t],n];this.listenersList={...this.listenersList,[t]:o}}removeIListener(t){const n={...this.listenersList};delete n[t],this.listenersList={...n}}triggerListener({listenerType:t,session:n,event:a}){const o=this.listenersList[t];!o||!o.length||o.forEach(s=>{s(n,a)})}setInitialized(t){this.initialized=t,this.emit("ready",t)}setConnected(t){this.connected=t,this.emit("connection",t)}setReconnecting(t){this.isReconnecting=t,this.emit("reconnecting",t)}}exports.BaseNewStreamPlugin=Mh;exports.BaseProcessStreamPlugin=Lh;exports.default=dE;
|